Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package edg;
import java.io.File;
import java.util.List;
import java.util.Map;
import edg.config.Config;
import edg.graph.EDG;
import edg.graph.EdgeInfo;
import edg.graph.Node;
import misc.Misc;
import misc.util.Flusher;
public class PdfFactory
{
private static final Config config = Config.getConfig();
private static File getTempDotFile()
{
final String temporaryPath = PdfFactory.config.getTemporaryPath();
int temporaryPathIndex = 0;
while (true)
{
final String extraDotPath = temporaryPathIndex++ > 0 ? temporaryPathIndex + "" : "";
final String temporaryDotPath = temporaryPath + "temp" + extraDotPath + ".dot";
final File temporatyDotFile = new File(temporaryDotPath);
if (!temporatyDotFile.exists())
return temporatyDotFile;
}
}
public static void createPdf(File outputFile, EDG edg)
{
PdfFactory.createPdf(outputFile, edg, null, null, null);
}
public static void createPdf(File outputFile, EDG edg, Map<EdgeInfo.Type, Boolean> edgeFlags)
{
PdfFactory.createPdf(outputFile, edg, null, null, edgeFlags);
}
public static void createPdf(File outputFile, EDG edg, Node slicingCriterion, List<Node> slice)
{
PdfFactory.createPdf(outputFile, edg, slicingCriterion, slice, null);
}
public static void createPdf(File outputFile, EDG edg, Node slicingCriterion, List<Node> slice, Map<EdgeInfo.Type, Boolean> edgeFlags)
{
final File dotOutputFile = PdfFactory.getTempDotFile();
DotFactory.createDot(dotOutputFile, edg, slicingCriterion, slice, edgeFlags);
PdfFactory.createPdf(outputFile, dotOutputFile);
Misc.delete(dotOutputFile);
}
public static void createPdf(File outputFile, File dotFile)
{
try
{
final String dotPath = dotFile.getAbsolutePath();
final String outputPath = outputFile.getAbsolutePath();
final String command = "dot -Tpdf \"" + dotPath + "\" > \"" + outputPath + "\"";
final String path = "PATH=/usr/local/bin:" + System.getenv("PATH");
final Runtime runtime = Runtime.getRuntime();
final Process process = runtime.exec(new String[] { "/bin/sh", "-c", command }, new String[] { path }, null);
new Flusher(process).start();
process.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
}
}
private PdfFactory()
{
}
}