Home » struts-2.1.8.1-src » org.apache » struts2 » sitegraph » model » [javadoc | source]

    1   /*
    2    * $Id: Graph.java 651946 2008-04-27 13:41:38Z apetrelli $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   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           // write out the header
   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           // render all the subgraphs
   55           for (Iterator iterator = subGraphs.iterator(); iterator.hasNext();) {
   56               SubGraph subGraph = (SubGraph) iterator.next();
   57               subGraph.render(new IndentWriter(writer));
   58           }
   59   
   60           // render all the nodes
   61           for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
   62               SiteGraphNode siteGraphNode = (SiteGraphNode) iterator.next();
   63               siteGraphNode.render(writer);
   64           }
   65   
   66           // finally, render the links
   67           for (Iterator iterator = links.iterator(); iterator.hasNext();) {
   68               Link link = (Link) iterator.next();
   69               link.render(writer);
   70           }
   71   
   72           // and now the footer
   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               // not absolute, so use the reference node
   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   }

Home » struts-2.1.8.1-src » org.apache » struts2 » sitegraph » model » [javadoc | source]