use of net.sourceforge.plantuml.SourceStringReader in project markdown-doclet by Abnaxos.
the class UmlTagRenderer method render.
@Override
public void render(Tag tag, StringBuilder target, MarkdownDoclet doclet) {
if (config == null) {
if (doclet.getOptions().getPlantUmlConfigFile() != null) {
try {
config = Collections.singletonList(Files.toString(doclet.getOptions().getPlantUmlConfigFile(), doclet.getOptions().getEncoding()));
} catch (IOException e) {
doclet.printError("Error loading PlantUML configuration file " + doclet.getOptions().getPlantUmlConfigFile() + ": " + e.getLocalizedMessage());
}
} else {
config = Collections.emptyList();
}
}
String packageName;
if (tag.holder() instanceof ProgramElementDoc) {
packageName = ((ProgramElementDoc) tag.holder()).containingPackage().name();
} else if (tag.holder() instanceof PackageDoc) {
packageName = ((PackageDoc) (tag.holder())).name();
} else if (tag.holder() instanceof RootDoc) {
packageName = null;
} else {
doclet.printError(tag.position(), "Cannot handle tag for holder " + tag.holder());
return;
}
String source = tag.text().trim();
int pos = CharMatcher.WHITESPACE.indexIn(source);
if (pos < 0) {
doclet.printError(tag.position(), "Invalid @startuml tag: Expected filename and PlantUML source");
return;
}
String fileName = source.substring(0, pos);
source = "@startuml " + fileName + "\n" + source.substring(pos).trim() + "\n@enduml";
File outputFile;
if (packageName == null) {
outputFile = doclet.getOptions().getDestinationDir();
} else {
outputFile = new File(doclet.getOptions().getDestinationDir(), packageName.replace(".", File.separator));
}
outputFile.mkdirs();
outputFile = new File(outputFile, fileName.replace("/", File.separator));
doclet.printNotice("Generating UML diagram " + outputFile);
// render
SourceStringReader reader = new SourceStringReader(new Defines(), source, config);
try {
reader.generateImage(outputFile);
} catch (IOException e) {
doclet.printError(tag.position(), "Error generating UML image " + outputFile + ": " + e.getLocalizedMessage());
}
}
use of net.sourceforge.plantuml.SourceStringReader in project plantuml-server by plantuml.
the class OldProxyServlet method handleImageProxy.
private void handleImageProxy(HttpServletResponse response, String num, String source) throws IOException {
SourceStringReader reader = new SourceStringReader(getSource(source));
int n = num == null ? 0 : Integer.parseInt(num);
reader.generateImage(response.getOutputStream(), n, new FileFormatOption(getOutputFormat(), false));
}
use of net.sourceforge.plantuml.SourceStringReader in project plantuml-server by plantuml.
the class DiagramResponse method sendCheck.
void sendCheck(String uml) throws IOException {
response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml);
DiagramDescription desc = reader.outputImage(new NullOutputStream(), new FileFormatOption(FileFormat.PNG, false));
PrintWriter httpOut = response.getWriter();
httpOut.print(desc.getDescription());
}
use of net.sourceforge.plantuml.SourceStringReader in project ArTEMiS by ls1intum.
the class PlantUmlResource method generatePng.
/**
* Generate PNG diagram for given PlantUML commands
*
* @param plantuml PlantUML command(s)
* @return ResponseEntity PNG stream
* @throws IOException
*/
@GetMapping(value = "/plantuml/png")
public ResponseEntity<byte[]> generatePng(@RequestParam("plantuml") String plantuml) throws IOException {
// Create PNG output stream
ByteArrayOutputStream png = new ByteArrayOutputStream();
// Create input stream reader
SourceStringReader reader = new SourceStringReader(plantuml);
// Create PNG
String dest = reader.generateImage(png);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.IMAGE_PNG);
return new ResponseEntity(png.toByteArray(), responseHeaders, HttpStatus.OK);
}
use of net.sourceforge.plantuml.SourceStringReader in project markdown-doclet by Abnaxos.
the class DocCommentProcessor method generateUmlDiagrams.
/**
* Generates all PlantUML diagrams in the given `PsiDocComment`. It returns a Map of
* file names and the URLs where the image for that file has been saved to. Use this
* URL for the `<img>` tag.
*
* @param docComment The `PsiDocComment`.
*
* @return A map mapping the file names to the image URLs.
*
* @see TempFileManager#saveTempFile(byte[], String)
*/
private Map<String, URL> generateUmlDiagrams(PsiDocComment docComment) {
TempFileManager tempFiles = Plugin.tempFileManager();
Map<String, URL> urls = null;
for (PsiDocTag tag : docComment.getTags()) {
if (tag instanceof PsiInlineDocTag) {
continue;
} else if (tag.getName().equals("uml") || tag.getName().equals("startuml")) {
if (urls == null) {
urls = new HashMap<>();
}
String text = stripLead(tag.getText());
text = stripFirstWord(text)[1];
String[] stripped = stripFirstWord(text);
String fileName = stripped[0];
text = stripped[1];
String plantUml = "@startuml " + fileName + "\n" + "skinparam backgroundColor transparent\n" + text + "\n@enduml";
Plugin.print("UML Diagram Source", plantUml);
ByteArrayOutputStream image = new ByteArrayOutputStream();
try {
new SourceStringReader(plantUml).generateImage(image);
} catch (IOException e) {
LOG.error("Error generating UML", e, fileName, String.valueOf(docComment.toString()), String.valueOf(docComment.getContainingFile()));
}
try {
urls.put(fileName, tempFiles.saveTempFile(image.toByteArray(), "png"));
} catch (IOException e) {
LOG.error("Error generating UML", e, fileName, String.valueOf(docComment.toString()), String.valueOf(docComment.getContainingFile()));
}
}
}
return MoreObjects.firstNonNull(urls, Collections.<String, URL>emptyMap());
}
Aggregations