forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXml2Svg.java
More file actions
61 lines (53 loc) · 1.48 KB
/
Xml2Svg.java
File metadata and controls
61 lines (53 loc) · 1.48 KB
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
package com.mxgraph.examples;
import java.io.IOException;
import javax.swing.JFrame;
import org.w3c.dom.Document;
import com.mxgraph.canvas.mxICanvas;
import com.mxgraph.canvas.mxSvgCanvas;
import com.mxgraph.io.mxCodec;
import com.mxgraph.util.mxCellRenderer;
import com.mxgraph.util.mxCellRenderer.CanvasFactory;
import com.mxgraph.util.mxDomUtils;
import com.mxgraph.util.mxUtils;
import com.mxgraph.util.mxXmlUtils;
import com.mxgraph.view.mxGraph;
/**
* Usage: Xml2Svg infile outfile where infile is the path to the input XML file
* (with an mxGraphModel) and outfile is the path to the output SVG file.
*/
public class Xml2Svg extends JFrame
{
public static void main(String[] args)
{
if (args.length < 2)
{
System.out.println("Usage: Xml2Svg infile outfile");
}
else
{
try
{
mxGraph graph = new mxGraph();
// Parses XML into graph
Document doc = mxXmlUtils.parseXml(mxUtils.readFile(args[0]));
mxCodec codec = new mxCodec(doc);
codec.decode(doc.getDocumentElement(), graph.getModel());
// Renders graph to SVG
mxSvgCanvas canvas = (mxSvgCanvas) mxCellRenderer.drawCells(graph,
null, 1, null, new CanvasFactory()
{
public mxICanvas createCanvas(int width, int height)
{
return new mxSvgCanvas(mxDomUtils
.createSvgDocument(width, height));
}
});
mxUtils.writeFile(mxXmlUtils.getXml(canvas.getDocument()), args[1]);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}