Search in sources :

Example 1 with MetadataTag

use of net.sourceforge.plantuml.png.MetadataTag in project plantuml-server by plantuml.

the class PlantUmlServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    request.setCharacterEncoding("UTF-8");
    String text = request.getParameter("text");
    String metadata = request.getParameter("metadata");
    if (metadata != null) {
        InputStream img = null;
        try {
            img = getImage(new URL(metadata));
            MetadataTag metadataTag = new MetadataTag(img, "plantuml");
            String data = metadataTag.getData();
            if (data != null) {
                text = data;
            }
        } finally {
            if (img != null) {
                img.close();
            }
        }
    }
    try {
        text = getTextFromUrl(request, text);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // no Text form has been submitted
    if (text == null || text.trim().isEmpty()) {
        redirectNow(request, response, DEFAULT_ENCODED_TEXT);
        return;
    }
    final String encoded = getTranscoder().encode(text);
    request.setAttribute("decoded", text);
    request.setAttribute("encoded", encoded);
    // check if an image map is necessary
    if (text != null && PlantumlUtils.hasCMapData(text)) {
        request.setAttribute("mapneeded", Boolean.TRUE);
    }
    // forward to index.jsp
    final RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
    dispatcher.forward(request, response);
}
Also used : InputStream(java.io.InputStream) MetadataTag(net.sourceforge.plantuml.png.MetadataTag) URL(java.net.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 2 with MetadataTag

use of net.sourceforge.plantuml.png.MetadataTag in project jqa-core-framework by buschmais.

the class ExecutablesTest method plantuml.

@Test
void plantuml() throws Exception {
    RuleSet ruleSet = RuleSetTestHelper.readRuleSet("/executables.adoc", RuleConfiguration.DEFAULT);
    Concept concept = verifyConceptExecutable(ruleSet, "test:PlantUML", SourceExecutable.class, StructuralNode.class, "plantuml");
    StructuralNode abstractBlock = (StructuralNode) concept.getExecutable().getSource();
    String imagesDirectoryAttribute = (String) abstractBlock.getDocument().getAttributes().get(AsciidoctorFactory.ATTRIBUTE_IMAGES_OUT_DIR);
    assertThat(imagesDirectoryAttribute, notNullValue());
    File imagesOutDir = new File(imagesDirectoryAttribute);
    assertThat(imagesOutDir.exists(), equalTo(true));
    String fileName = (String) abstractBlock.getAttributes().get("target");
    assertThat(fileName, notNullValue());
    File diagramFile = new File(imagesOutDir, fileName);
    assertThat("Expected file " + diagramFile + " does not exist.", diagramFile.exists(), equalTo(true));
    String diagramMetadata = new MetadataTag(diagramFile, "plantuml").getData();
    assertThat(diagramMetadata, containsString("@startuml"));
    assertThat(diagramMetadata, containsString("@enduml"));
}
Also used : StructuralNode(org.asciidoctor.ast.StructuralNode) MetadataTag(net.sourceforge.plantuml.png.MetadataTag) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

MetadataTag (net.sourceforge.plantuml.png.MetadataTag)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletException (javax.servlet.ServletException)1 StructuralNode (org.asciidoctor.ast.StructuralNode)1 Test (org.junit.jupiter.api.Test)1