View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2005 Gabriel Handford.
3    * All rights reserved.
4    *
5    * Contributors:
6    *    Gabriel Handford -
7    *******************************************************************************/
8   package net.sf.tacos.services.impl;
9   
10  import java.util.ArrayList;
11  import java.util.Arrays;
12  import java.util.List;
13  
14  import net.sf.tacos.services.PageInfo;
15  
16  import org.apache.commons.lang.builder.ToStringBuilder;
17  import org.apache.commons.lang.builder.ToStringStyle;
18  
19  /**
20   * This class describes a tapestry page.
21   *
22   * @author Gabriel Handford
23   */
24  public class PageInfoImpl implements PageInfo {
25  
26      private String name;
27      private String path;
28      private String desc;
29      private String perm;
30      private PageInfo parent;
31      private List children;
32      private boolean isNavigable;
33  
34      /**
35       * Create a tapestry page descriptor.
36       * @param name The page name.
37       * @param desc The page description.
38       * @param perm The page permission (access code needed to access the page).
39       * @param children List of chile pages.
40       * @param isNavigable Whether or not page should be included in the navigation.
41       */
42      public PageInfoImpl(String name, String desc, 
43              String perm, List children, boolean isNavigable) {
44          this.name = name;
45          this.desc = desc;
46          this.perm = perm;
47          this.children = children;
48          this.isNavigable = isNavigable;
49      }
50  
51      /**
52       * @return The description
53       */
54      public String getDesc() {
55          return desc;
56      }
57  
58      /**
59       * @return The page name
60       */
61      public String getName() {
62          return name;
63      }
64  
65      /**
66       * @return The permission access code
67       */
68      public String getPermission() {
69          return perm;
70      }
71  
72      /**
73       * @return Returns the parent.
74       */
75      public PageInfo getParent() {
76          return parent;
77      }
78  
79      /**
80       * Set the parent.
81       * @param parent The parent.
82       */
83      public void setParent(PageInfo parent) {
84          this.parent = parent;
85      }
86  
87      /**
88       * 
89       * {@inheritDoc}
90       */
91      public void addChild(PageInfo child)
92      {
93          children.add(child);
94      }
95      
96      /**
97       * Check whether this page should be included in any page listings.
98       * @return True if this page should be included in any page listings, false otherwise
99       */
100     public boolean isNavigable() { return isNavigable; }
101     
102     /**
103      * Get the children.
104      * @return children
105      */
106     public List getChildrenNames() {
107         if (children == null) return Arrays.asList(new Object[0]);
108         List list = new ArrayList(children.size());
109         for(int i = 0; i < children.size(); i++)
110             list.add(((PageInfo)children.get(i)).getName());
111         return list;
112     }
113 
114     /**
115      * @see java.lang.Object#toString()
116      */
117     public String toString() {
118         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
119             .append("name", this.name)
120             .append("desc", this.desc)
121             .append("perm", this.perm)
122             .append("parent", (this.parent != null ? parent.getName() : "none"))
123             .append("isNavigable", this.isNavigable)
124             .toString();
125     }
126 }