Skip to content

Commit

Permalink
Update plant uml extension to generate svg
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanusta committed Feb 17, 2015
1 parent cdac24a commit 3d0d28c
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/main/java/com/kodcu/service/extension/PlantUmlService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PlantUmlService {
public void plantUml(String uml, String type, String fileName) {
Objects.requireNonNull(fileName);

if (!fileName.endsWith(".png") && !"ascii".equalsIgnoreCase(type))
if (!fileName.endsWith(".png") && !fileName.endsWith(".svg"))
return;

String defaultScale = "\nskinparam dpi 300\n";
Expand All @@ -52,47 +52,43 @@ public void plantUml(String uml, String type, String fileName) {
uml = uml.replaceFirst("@startuml", "@startuml" + defaultScale);
}

SourceStringReader reader = new SourceStringReader(uml);

try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
Integer cacheHit = current.getCache().get(fileName);

if ("ascii".equalsIgnoreCase(type)) {
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.ATXT));
int hashCode = (fileName + type + uml).hashCode();

if (Objects.nonNull(cacheHit))
if (hashCode == cacheHit)
return;
}
// default: png
else {

if (!current.currentPath().isPresent())
controller.saveDoc();
SourceStringReader reader = new SourceStringReader(uml);

Path path = current.currentPath().get().getParent();
Path umlPath = path.resolve("images/").resolve(fileName);
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {

if (!current.currentPath().isPresent())
controller.saveDoc();

Integer cacheHit = current.getCache().get(fileName);
Path path = current.currentPath().get().getParent();
Path umlPath = path.resolve("images/").resolve(fileName);

int hashCode = (fileName + type + uml).hashCode();
if (Objects.isNull(cacheHit) || hashCode != cacheHit) {
FileFormat fileType = fileName.endsWith(".svg") ? FileFormat.SVG : FileFormat.PNG;

threadService.runTaskLater(() -> {
try {
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.PNG));
threadService.runTaskLater(() -> {
try {
String desc = reader.generateImage(os, new FileFormatOption(fileType));

Files.createDirectories(path.resolve("images"));
Files.createDirectories(path.resolve("images"));

IOHelper.writeToFile(umlPath, os.toByteArray(), CREATE, WRITE, TRUNCATE_EXISTING);
IOHelper.writeToFile(umlPath, os.toByteArray(), CREATE, WRITE, TRUNCATE_EXISTING);

controller.getLastRenderedChangeListener()
.changed(null, controller.getLastRendered().getValue(), controller.getLastRendered().getValue());
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
});
controller.getLastRenderedChangeListener()
.changed(null, controller.getLastRendered().getValue(), controller.getLastRendered().getValue());
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
});


current.getCache().put(fileName, hashCode);
}
current.getCache().put(fileName, hashCode);

} catch (IOException e) {
logger.info(e.getMessage(), e);
Expand Down

0 comments on commit 3d0d28c

Please sign in to comment.