net.sourceforge.plantuml.SourceStringReader Java Examples

The following examples show how to use net.sourceforge.plantuml.SourceStringReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImgGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
public void generateUMLStateMachine(Path messagesImgPath, PathManager fileSystemManager, StateMachineType stateMachine,
    STErrorListener errorListener) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  final NoIndentWriter writer = new NoIndentWriter(stringWriter);

  final ST stStates = stGroup.getInstanceOf("stateMachine");
  stStates.add("stateMachine", stateMachine);
  stStates.write(writer, errorListener);

  final String umlString = stringWriter.toString();

  final SourceStringReader reader = new SourceStringReader(umlString);
  final Path path = messagesImgPath.resolve(String.format("%s.png", stateMachine.getName()));
  final OutputStream out = fileSystemManager.getOutputStream(path);
  reader.generateImage(out);
  out.flush();
}
 
Example #2
Source File: ImgGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
public void generateUMLSequence(Path messagesImgPath, PathManager fileSystemManager, MessageType message, FlowType flow,
    List<ResponseType> responseList, STErrorListener errorListener) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  final NoIndentWriter writer = new NoIndentWriter(stringWriter);

  final ST stSequence = stGroup.getInstanceOf("sequence");
  stSequence.add("message", message);
  stSequence.add("flow", flow);
  stSequence.write(writer, errorListener);
  generateResponses(responseList, writer, errorListener);
  final ST stEnd = stGroup.getInstanceOf("sequenceEnd");
  stEnd.add("message", message);
  stEnd.write(writer, errorListener);

  final String umlString = stringWriter.toString();

  final SourceStringReader reader = new SourceStringReader(umlString);
  final Path path = messagesImgPath.resolve(String.format("%s-%s.png", message.getName(), message.getScenario()));
  final OutputStream out = fileSystemManager.getOutputStream(path);
  reader.generateImage(out);
  out.flush();
}
 
Example #3
Source File: PlantUmlVerbatimSerializer.java    From protostuff-compiler with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(VerbatimNode node, Printer printer) {
    Type type = Type.getByName(node.getType());

    String formatted = type.wrap(node.getText());
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SourceStringReader reader = new SourceStringReader(formatted);
    String desc;
    try {
        desc = reader.generateImage(baos, type.getFormatOption());
    } catch (IOException e) {
        throw new GeneratorException("Could not generate uml for node " + node, e);
    }
    final String rendered = type.render(baos.toByteArray(), desc);
    printer.print(rendered);
}
 
Example #4
Source File: AbstractPlUmlEditor.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nullable
@UiThread
private String renderPageAsAscII() {
  final String theText = this.preprocessEditorText(this.editor.getText());

  final SourceStringReader reader = new SourceStringReader(theText, "UTF-8");
  final int totalPages = Math.max(countNewPages(theText), reader.getBlocks().size());

  final int imageIndex = Math.max(1, Math.min(this.pageNumberToRender, totalPages));

  final ByteArrayOutputStream utfBuffer = new ByteArrayOutputStream();

  try {
    final DiagramDescription description = reader
        .outputImage(utfBuffer, imageIndex - 1, new FileFormatOption(FileFormat.ATXT, false));
    final String result = new String(utfBuffer.toByteArray(), StandardCharsets.UTF_8);
    if (result.contains("java.lang.UnsupportedOperationException: ATXT")) {
      throw new UnsupportedOperationException("ATXT is not supported for the diagram");
    }
    return result;
  } catch (Exception ex) {
    logger.error("Can't export ASCII image", ex);
    return null;
  }
}
 
Example #5
Source File: SequenceDiagramGenerator.java    From yatspec with Apache License 2.0 6 votes vote down vote up
private String createSvg(String plantUmlMarkup) {
    SourceStringReader reader = new SourceStringReader(plantUmlMarkup);
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        reader.generateImage(os, new FileFormatOption(SVG));
        os.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return new String(os.toByteArray());
}
 
Example #6
Source File: AbstractPlUmlEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public boolean isSyntaxCorrect(@Nonnull final String text) {
  boolean result = false;
  final SourceStringReader reader = new SourceStringReader(text);
  reader.getBlocks();
  try {
    final Diagram system = reader.getBlocks().get(0).getDiagram();
    if (!(system instanceof PSystemError)) {
      result = true;
    }
  } catch (Exception ex) {
    logger.warn("Detected exception in syntax check : " + ex.getMessage());
    result = false;
  }
  return result;
}
 
Example #7
Source File: DiagramGenerator.java    From Ratel with Apache License 2.0 5 votes vote down vote up
private void storeDiagram(String source, String fileName) throws IOException, FileNotFoundException {
    SourceStringReader reader = new SourceStringReader(source);
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    // Write the first image to "os"
    reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
    os.close();
    FileOutputStream fos = new FileOutputStream(fileName);

    reader.generateImage(fos, new FileFormatOption(FileFormat.PNG));
    fos.close();
}
 
Example #8
Source File: Uml.java    From umlbot with GNU General Public License v3.0 5 votes vote down vote up
Object imgs(Request request, Response response) throws Exception {
	return request.params("encoded").map(Trial.of(transcoder()::decode))
			.map(t -> t.either(SourceStringReader::new, ex -> {
				LOG.fatal(ex.getMessage(), ex);
				return null;
			}))
			.map(v -> response.type("image/png").render(v,
					Renderer.ofStream((m, os) -> m.generateImage(os, new FileFormatOption(FileFormat.PNG, false)))))
			.orElse(404);
}