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