View Javadoc

1   /*
2    * $Id: SiteGraphNode.java 454251 2006-10-09 02:10:57Z husted $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.sitegraph.model;
19  
20  import java.io.IOException;
21  
22  /***
23   */
24  public abstract class SiteGraphNode implements Render, Comparable {
25      private String name;
26      private SubGraph parent;
27  
28      public SiteGraphNode(String name) {
29          this.name = name;
30      }
31  
32      public SubGraph getParent() {
33          return parent;
34      }
35  
36      public void setParent(SubGraph parent) {
37          this.parent = parent;
38      }
39  
40      public void render(IndentWriter writer) throws IOException {
41          writer.write(getFullName() + " [label=\"" + name + "\",color=\"" + getColor() + "\"];");
42      }
43  
44      public String getFullName() {
45          String prefix = "";
46          if (parent != null) {
47              String parentPrefix = parent.getPrefix();
48              if (!parentPrefix.equals("")) {
49                  prefix = parentPrefix + "_";
50              }
51          }
52          return prefix + cleanName();
53      }
54  
55      private String cleanName() {
56          return name.replaceAll("[//./////-//$//{//}]", "_");
57      }
58  
59      public abstract String getColor();
60  
61      public int compareTo(Object o) {
62          return name.compareTo(((SiteGraphNode) o).name);
63      }
64  }