plantuml.jarをクラスパスに追加すれば、
PlantUMLを簡単に他のコードに統合することができます。
図の説明が
String
に格納されている場合、
SourceStringReader
クラスを使って何らかのPNGファイルを生成することができます。
import net.sourceforge.plantuml.SourceStringReader;
OutputStream png = ...;
String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";
SourceStringReader reader = new SourceStringReader(source);
// Write the first image to "png"
String desc = reader.outputImage(png).getDescription();
// Return a null string if no generation
ダイアグラムの記述を
File
として持っている場合は、
SourceFileReader
を使用してPNGファイルを生成します。
File source = ...;
SourceFileReader reader = new SourceFileReader(source);
List<GeneratedImage> list = reader.getGeneratedImages();
// Generated files
File png = list.get(0).getPngFile();
ダイアグラムの記述を
String
として持っている場合は、
SourceStringReader
を使用してSVGファイルを生成します。
String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";
SourceStringReader reader = new SourceStringReader(source);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Write the first image to "os"
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
os.close();
// The XML is stored into svg
final String svg = new String(os.toByteArray(), Charset.forName("UTF-8"));