001 /******************************************************************************* 002 * Copyright (c) 2005 Gabriel Handford. 003 * All rights reserved. 004 * 005 * Contributors: 006 * Gabriel Handford - 007 *******************************************************************************/ 008 package net.sf.tacos.services.impl; 009 010 import java.util.ArrayList; 011 import java.util.Arrays; 012 import java.util.List; 013 014 import net.sf.tacos.services.PageInfo; 015 016 import org.apache.commons.lang.builder.ToStringBuilder; 017 import org.apache.commons.lang.builder.ToStringStyle; 018 019 /** 020 * This class describes a tapestry page. 021 * 022 * @author Gabriel Handford 023 */ 024 public class PageInfoImpl implements PageInfo { 025 026 private String name; 027 private String path; 028 private String desc; 029 private String perm; 030 private PageInfo parent; 031 private List children; 032 private boolean isNavigable; 033 034 /** 035 * Create a tapestry page descriptor. 036 * @param name The page name. 037 * @param desc The page description. 038 * @param perm The page permission (access code needed to access the page). 039 * @param children List of chile pages. 040 * @param isNavigable Whether or not page should be included in the navigation. 041 */ 042 public PageInfoImpl(String name, String desc, 043 String perm, List children, boolean isNavigable) { 044 this.name = name; 045 this.desc = desc; 046 this.perm = perm; 047 this.children = children; 048 this.isNavigable = isNavigable; 049 } 050 051 /** 052 * @return The description 053 */ 054 public String getDesc() { 055 return desc; 056 } 057 058 /** 059 * @return The page name 060 */ 061 public String getName() { 062 return name; 063 } 064 065 /** 066 * @return The permission access code 067 */ 068 public String getPermission() { 069 return perm; 070 } 071 072 /** 073 * @return Returns the parent. 074 */ 075 public PageInfo getParent() { 076 return parent; 077 } 078 079 /** 080 * Set the parent. 081 * @param parent The parent. 082 */ 083 public void setParent(PageInfo parent) { 084 this.parent = parent; 085 } 086 087 /** 088 * 089 * {@inheritDoc} 090 */ 091 public void addChild(PageInfo child) 092 { 093 children.add(child); 094 } 095 096 /** 097 * Check whether this page should be included in any page listings. 098 * @return True if this page should be included in any page listings, false otherwise 099 */ 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 }