1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.sitegraph.model;
19
20 import java.io.IOException;
21 import java.util.Iterator;
22 import java.util.LinkedHashMap;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.TreeSet;
26
27 /***
28 */
29 public class Graph extends SubGraph {
30 private Set links;
31 public static Map nodeMap = new LinkedHashMap();
32
33 public Graph() {
34 super("");
35 this.links = new TreeSet();
36 }
37
38 public void addLink(Link link) {
39 links.add(link);
40 }
41
42 public void render(IndentWriter writer) throws IOException {
43
44 writer.write("digraph mygraph {", true);
45 writer.write("fontsize=10;");
46 writer.write("fontname=helvetica;");
47 writer.write("node [fontsize=10, fontname=helvetica, style=filled, shape=rectangle]");
48 writer.write("edge [fontsize=10, fontname=helvetica]");
49
50
51 for (Iterator iterator = subGraphs.iterator(); iterator.hasNext();) {
52 SubGraph subGraph = (SubGraph) iterator.next();
53 subGraph.render(new IndentWriter(writer));
54 }
55
56
57 for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
58 SiteGraphNode siteGraphNode = (SiteGraphNode) iterator.next();
59 siteGraphNode.render(writer);
60 }
61
62
63 for (Iterator iterator = links.iterator(); iterator.hasNext();) {
64 Link link = (Link) iterator.next();
65 link.render(writer);
66 }
67
68
69 writer.write("}", true);
70 }
71
72 public SiteGraphNode findNode(String location, SiteGraphNode ref) {
73 if (location.startsWith("/")) {
74 location = location.substring(1);
75 } else {
76
77 String prefix = null;
78 if (ref.getParent() != null) {
79 prefix = ref.getParent().getPrefix();
80 location = prefix + "_" + location;
81 }
82 }
83
84 location = location.replaceAll("[//./////-//$//{//}]", "_");
85
86 return (SiteGraphNode) nodeMap.get(location);
87 }
88 }