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