01: package com.opensymphony.webwork.sitegraph.model;
02:
03: import java.io.IOException;
04: import java.util.*;
05:
06: /**
07: * User: plightbo
08: * Date: Jun 26, 2005
09: * Time: 4:58:30 PM
10: */
11: public class Graph extends SubGraph {
12: private Set links;
13: public static Map nodeMap = new LinkedHashMap();
14:
15: public Graph() {
16: super ("");
17: this .links = new TreeSet();
18: }
19:
20: public void addLink(Link link) {
21: links.add(link);
22: }
23:
24: public void render(IndentWriter writer) throws IOException {
25: // write out the header
26: writer.write("digraph mygraph {", true);
27: writer.write("fontsize=10;");
28: writer.write("fontname=helvetica;");
29: writer
30: .write("node [fontsize=10, fontname=helvetica, style=filled, shape=rectangle]");
31: writer.write("edge [fontsize=10, fontname=helvetica]");
32:
33: // render all the subgraphs
34: for (Iterator iterator = subGraphs.iterator(); iterator
35: .hasNext();) {
36: SubGraph subGraph = (SubGraph) iterator.next();
37: subGraph.render(new IndentWriter(writer));
38: }
39:
40: // render all the nodes
41: for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
42: SiteGraphNode siteGraphNode = (SiteGraphNode) iterator
43: .next();
44: siteGraphNode.render(writer);
45: }
46:
47: // finally, render the links
48: for (Iterator iterator = links.iterator(); iterator.hasNext();) {
49: Link link = (Link) iterator.next();
50: link.render(writer);
51: }
52:
53: // and now the footer
54: writer.write("}", true);
55: }
56:
57: public SiteGraphNode findNode(String location, SiteGraphNode ref) {
58: if (location.startsWith("/")) {
59: location = location.substring(1);
60: } else {
61: // not absolute, so use the reference node
62: String prefix = null;
63: if (ref.getParent() != null) {
64: prefix = ref.getParent().getPrefix();
65: location = prefix + "_" + location;
66: }
67: }
68:
69: location = location.replaceAll("[\\.\\/\\-\\$\\{\\}]", "_");
70:
71: return (SiteGraphNode) nodeMap.get(location);
72: }
73: }
|