@Test public void testMathSVGGeneration() throws IOException { HTTPHeaders h = new HTTPHeaders(); h.putValue(HTTPHeader.CONTENT_TYPE, MimeType.TEXT_PLAIN_UTF8); h.putValue(HTTPHeader.ACCEPT, MimeType.SVG); ResponseData responseData = new PlantUML().generate(new Request( URI.create("/plantuml"), h, PLANTUML_MATH_INPUT.getBytes(Charsets.UTF8) )); Assert.assertIsSVG(responseData); }
@Override public ResponseData generate(Request request) throws IOException { File graphviz; String pathToGraphViz = request.headers.getValue("X-Graphviz"); if (pathToGraphViz != null) { File graphvizParam = new File(pathToGraphViz); if (graphvizParam.canExecute()) { graphviz = graphvizParam; } else { throw new IOException("GraphViz 'dot' tool at '" + pathToGraphViz + "' is not executable"); } } else { graphviz = null; } MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } FileFormatOption fileFormat; if (format.equals(MimeType.PNG)) { fileFormat = new FileFormatOption(FileFormat.PNG); } else if (format.equals(MimeType.SVG)) { fileFormat = new FileFormatOption(FileFormat.SVG); } else if (format.equals(MimeType.TEXT_PLAIN_UTF8)) { fileFormat = new FileFormatOption(FileFormat.UTXT); } else if (format.equals(MimeType.TEXT_PLAIN)) { fileFormat = new FileFormatOption(FileFormat.ATXT); format = MimeType.parse(MimeType.TEXT_PLAIN.toString() + ";charset=" + Charset.defaultCharset().name().toLowerCase()); } else { throw new IOException("Unsupported output format: " + format); } Option option = new Option(); String plantUmlConfig = request.headers.getValue("X-PlantUML-Config"); if (plantUmlConfig != null) { option.initConfig(plantUmlConfig); } option.setFileFormatOption(fileFormat); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); synchronized (this) { try { SET_DOT_EXE.invoke(SET_DOT_EXE_INSTANCE, graphviz != null ? graphviz.getAbsolutePath() : null); } catch (IllegalAccessException | InvocationTargetException e) { throw new IOException(e); } BlockUmlBuilder builder = new BlockUmlBuilder( option.getConfig(), "UTF-8", Defines.createEmpty(), new StringReader(request.asString()), FileSystem.getInstance().getCurrentDir(), "<input>" ); List<BlockUml> blocks = builder.getBlockUmls(); if (blocks.size() == 0) { throw new IOException("No @startuml found"); } else { for (BlockUml b : blocks) { Diagram system = b.getDiagram(); if (system instanceof PSystemError) { system.exportDiagram(byteArrayOutputStream, 0, new FileFormatOption(FileFormat.UTXT)); String error = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); throw new IOException(error); } if (system.getNbImages() > 0) { system.exportDiagram(byteArrayOutputStream, 0, fileFormat); break; } } } } return new ResponseData( format, byteArrayOutputStream.toByteArray() ); }
PlantUML implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { File graphviz; String pathToGraphViz = request.headers.getValue("X-Graphviz"); if (pathToGraphViz != null) { File graphvizParam = new File(pathToGraphViz); if (graphvizParam.canExecute()) { graphviz = graphvizParam; } else { throw new IOException("GraphViz 'dot' tool at '" + pathToGraphViz + "' is not executable"); } } else { graphviz = null; } MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } FileFormatOption fileFormat; if (format.equals(MimeType.PNG)) { fileFormat = new FileFormatOption(FileFormat.PNG); } else if (format.equals(MimeType.SVG)) { fileFormat = new FileFormatOption(FileFormat.SVG); } else if (format.equals(MimeType.TEXT_PLAIN_UTF8)) { fileFormat = new FileFormatOption(FileFormat.UTXT); } else if (format.equals(MimeType.TEXT_PLAIN)) { fileFormat = new FileFormatOption(FileFormat.ATXT); format = MimeType.parse(MimeType.TEXT_PLAIN.toString() + ";charset=" + Charset.defaultCharset().name().toLowerCase()); } else { throw new IOException("Unsupported output format: " + format); } Option option = new Option(); String plantUmlConfig = request.headers.getValue("X-PlantUML-Config"); if (plantUmlConfig != null) { option.initConfig(plantUmlConfig); } option.setFileFormatOption(fileFormat); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); synchronized (this) { try { SET_DOT_EXE.invoke(SET_DOT_EXE_INSTANCE, graphviz != null ? graphviz.getAbsolutePath() : null); } catch (IllegalAccessException | InvocationTargetException e) { throw new IOException(e); } BlockUmlBuilder builder = new BlockUmlBuilder( option.getConfig(), "UTF-8", Defines.createEmpty(), new StringReader(request.asString()), FileSystem.getInstance().getCurrentDir(), "<input>" ); List<BlockUml> blocks = builder.getBlockUmls(); if (blocks.size() == 0) { throw new IOException("No @startuml found"); } else { for (BlockUml b : blocks) { Diagram system = b.getDiagram(); if (system instanceof PSystemError) { system.exportDiagram(byteArrayOutputStream, 0, new FileFormatOption(FileFormat.UTXT)); String error = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); throw new IOException(error); } if (system.getNbImages() > 0) { system.exportDiagram(byteArrayOutputStream, 0, fileFormat); break; } } } } return new ResponseData( format, byteArrayOutputStream.toByteArray() ); } }
PlantUML implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { File graphviz; String pathToGraphViz = request.headers.getValue("X-Graphviz"); if (pathToGraphViz != null) { File graphvizParam = new File(pathToGraphViz); if (graphvizParam.canExecute()) { graphviz = graphvizParam; } else { throw new IOException("GraphViz 'dot' tool at '" + pathToGraphViz + "' is not executable"); } } else { graphviz = null; } MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } FileFormatOption fileFormat; if (format.equals(MimeType.PNG)) { fileFormat = new FileFormatOption(FileFormat.PNG); } else if (format.equals(MimeType.SVG)) { fileFormat = new FileFormatOption(FileFormat.SVG); } else if (format.equals(MimeType.TEXT_PLAIN_UTF8)) { fileFormat = new FileFormatOption(FileFormat.UTXT); } else if (format.equals(MimeType.TEXT_PLAIN)) { fileFormat = new FileFormatOption(FileFormat.ATXT); format = MimeType.parse(MimeType.TEXT_PLAIN.toString() + ";charset=" + Charset.defaultCharset().name().toLowerCase()); } else { throw new IOException("Unsupported output format: " + format); } Option option = new Option(); String plantUmlConfig = request.headers.getValue("X-PlantUML-Config"); if (plantUmlConfig != null) { option.initConfig(plantUmlConfig); } option.setFileFormatOption(fileFormat); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); synchronized (this) { try { SET_DOT_EXE.invoke(SET_DOT_EXE_INSTANCE, graphviz != null ? graphviz.getAbsolutePath() : null); } catch (IllegalAccessException | InvocationTargetException e) { throw new IOException(e); } BlockUmlBuilder builder = new BlockUmlBuilder( option.getConfig(), "UTF-8", Defines.createEmpty(), new StringReader(request.asString()), FileSystem.getInstance().getCurrentDir(), "<input>" ); List<BlockUml> blocks = builder.getBlockUmls(); if (blocks.size() == 0) { throw new IOException("No @startuml found"); } else { for (BlockUml b : blocks) { Diagram system = b.getDiagram(); if (system instanceof PSystemError) { system.exportDiagram(byteArrayOutputStream, 0, new FileFormatOption(FileFormat.UTXT)); String error = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); throw new IOException(error); } if (system.getNbImages() > 0) { system.exportDiagram(byteArrayOutputStream, 0, fileFormat); break; } } } } return new ResponseData( format, byteArrayOutputStream.toByteArray() ); }  }
PlantUML implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { File graphviz; String pathToGraphViz = request.headers.getValue("X-Graphviz"); if (pathToGraphViz != null) { File graphvizParam = new File(pathToGraphViz); if (graphvizParam.canExecute()) { graphviz = graphvizParam; } else { throw new IOException("GraphViz 'dot' tool at '" + pathToGraphViz + "' is not executable"); } } else { graphviz = null; } MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } FileFormatOption fileFormat; if (format.equals(MimeType.PNG)) { fileFormat = new FileFormatOption(FileFormat.PNG); } else if (format.equals(MimeType.SVG)) { fileFormat = new FileFormatOption(FileFormat.SVG); } else if (format.equals(MimeType.TEXT_PLAIN_UTF8)) { fileFormat = new FileFormatOption(FileFormat.UTXT); } else if (format.equals(MimeType.TEXT_PLAIN)) { fileFormat = new FileFormatOption(FileFormat.ATXT); format = MimeType.parse(MimeType.TEXT_PLAIN.toString() + ";charset=" + Charset.defaultCharset().name().toLowerCase()); } else { throw new IOException("Unsupported output format: " + format); } Option option = new Option(); String plantUmlConfig = request.headers.getValue("X-PlantUML-Config"); if (plantUmlConfig != null) { option.initConfig(plantUmlConfig); } option.setFileFormatOption(fileFormat); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); synchronized (this) { try { SET_DOT_EXE.invoke(SET_DOT_EXE_INSTANCE, graphviz != null ? graphviz.getAbsolutePath() : null); } catch (IllegalAccessException | InvocationTargetException e) { throw new IOException(e); } BlockUmlBuilder builder = new BlockUmlBuilder( option.getConfig(), "UTF-8", Defines.createEmpty(), new StringReader(request.asString()), FileSystem.getInstance().getCurrentDir(), "<input>" ); List<BlockUml> blocks = builder.getBlockUmls(); if (blocks.size() == 0) { throw new IOException("No @startuml found"); } else { for (BlockUml b : blocks) { Diagram system = b.getDiagram(); if (system instanceof PSystemError) { system.exportDiagram(byteArrayOutputStream, 0, new FileFormatOption(FileFormat.UTXT)); String error = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); throw new IOException(error); } if (system.getNbImages() > 0) { system.exportDiagram(byteArrayOutputStream, 0, fileFormat); break; } } } } return new ResponseData( format, byteArrayOutputStream.toByteArray() ); }  @Override String getName(); @Override ResponseData generate(Request request); }
PlantUML implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { File graphviz; String pathToGraphViz = request.headers.getValue("X-Graphviz"); if (pathToGraphViz != null) { File graphvizParam = new File(pathToGraphViz); if (graphvizParam.canExecute()) { graphviz = graphvizParam; } else { throw new IOException("GraphViz 'dot' tool at '" + pathToGraphViz + "' is not executable"); } } else { graphviz = null; } MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } FileFormatOption fileFormat; if (format.equals(MimeType.PNG)) { fileFormat = new FileFormatOption(FileFormat.PNG); } else if (format.equals(MimeType.SVG)) { fileFormat = new FileFormatOption(FileFormat.SVG); } else if (format.equals(MimeType.TEXT_PLAIN_UTF8)) { fileFormat = new FileFormatOption(FileFormat.UTXT); } else if (format.equals(MimeType.TEXT_PLAIN)) { fileFormat = new FileFormatOption(FileFormat.ATXT); format = MimeType.parse(MimeType.TEXT_PLAIN.toString() + ";charset=" + Charset.defaultCharset().name().toLowerCase()); } else { throw new IOException("Unsupported output format: " + format); } Option option = new Option(); String plantUmlConfig = request.headers.getValue("X-PlantUML-Config"); if (plantUmlConfig != null) { option.initConfig(plantUmlConfig); } option.setFileFormatOption(fileFormat); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); synchronized (this) { try { SET_DOT_EXE.invoke(SET_DOT_EXE_INSTANCE, graphviz != null ? graphviz.getAbsolutePath() : null); } catch (IllegalAccessException | InvocationTargetException e) { throw new IOException(e); } BlockUmlBuilder builder = new BlockUmlBuilder( option.getConfig(), "UTF-8", Defines.createEmpty(), new StringReader(request.asString()), FileSystem.getInstance().getCurrentDir(), "<input>" ); List<BlockUml> blocks = builder.getBlockUmls(); if (blocks.size() == 0) { throw new IOException("No @startuml found"); } else { for (BlockUml b : blocks) { Diagram system = b.getDiagram(); if (system instanceof PSystemError) { system.exportDiagram(byteArrayOutputStream, 0, new FileFormatOption(FileFormat.UTXT)); String error = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); throw new IOException(error); } if (system.getNbImages() > 0) { system.exportDiagram(byteArrayOutputStream, 0, fileFormat); break; } } } } return new ResponseData( format, byteArrayOutputStream.toByteArray() ); }  @Override String getName(); @Override ResponseData generate(Request request);  }