1 24 package org.riotfamily.pages; 25 26 import java.util.Collection ; 27 import java.util.Date ; 28 import java.util.LinkedList ; 29 import java.util.Locale ; 30 import java.util.Map ; 31 32 import org.riotfamily.components.ComponentVersion; 33 import org.riotfamily.components.VersionContainer; 34 35 36 41 public class Page { 42 43 private Long id; 44 45 private PageNode node; 46 47 private Locale locale; 48 49 private String pathComponent; 50 51 private boolean hidden; 52 53 private boolean folder; 54 55 private String path; 56 57 private boolean wildcardInPath; 58 59 private boolean published; 60 61 private Date creationDate; 62 63 private VersionContainer versionContainer; 64 65 public Page() { 66 } 67 68 public Page(String pathComponent, Locale locale) { 69 this.pathComponent = pathComponent; 70 this.locale = locale; 71 } 72 73 public Long getId() { 74 return this.id; 75 } 76 77 public void setId(Long id) { 78 this.id = id; 79 } 80 81 public PageNode getNode() { 82 return this.node; 83 } 84 85 public void setNode(PageNode node) { 86 this.node = node; 87 } 88 89 public Locale getLocale() { 90 return this.locale; 91 } 92 93 public void setLocale(Locale locale) { 94 this.locale = locale; 95 } 96 97 public Date getCreationDate() { 98 return creationDate; 99 } 100 101 public void setCreationDate(Date creationDate) { 102 this.creationDate = creationDate; 103 } 104 105 public String getPathComponent() { 106 return pathComponent; 107 } 108 109 public void setPathComponent(String pathComponent) { 110 this.pathComponent = pathComponent; 111 } 112 113 public boolean isHidden() { 114 return this.hidden; 115 } 116 117 public void setHidden(boolean hidden) { 118 this.hidden = hidden; 119 } 120 121 125 public boolean isFolder() { 126 return this.folder; 127 } 128 129 public void setFolder(boolean folder) { 130 this.folder = folder; 131 } 132 133 public String getPath() { 134 if (path == null) { 135 path = buildPath(); 136 } 137 return path; 138 } 139 140 public void setPath(String path) { 141 this.path = path; 142 } 143 144 public boolean isWildcard() { 145 return pathComponent.indexOf("@{") != -1; 146 } 147 148 public boolean isWildcardInPath() { 149 return this.wildcardInPath; 150 } 151 152 public void setWildcardInPath(boolean wildcardInPath) { 153 this.wildcardInPath = wildcardInPath; 154 } 155 156 public String buildPath() { 157 StringBuffer path = new StringBuffer (); 158 wildcardInPath = false; 159 Page page = this; 160 while (page != null) { 161 path.insert(0, page.getPathComponent()); 162 path.insert(0, '/'); 163 wildcardInPath |= page.isWildcard(); 164 page = page.getParentPage(); 165 } 166 return path.toString(); 167 } 168 169 public Page getParentPage() { 170 PageNode parentNode = node.getParent(); 171 if (parentNode == null) { 172 return null; 173 } 174 return parentNode.getPage(locale); 175 } 176 177 public Collection getChildPages() { 178 return node.getChildPages(locale); 179 } 180 181 public Collection getChildPages(Locale fallbackLocale) { 182 return node.getChildPages(locale, fallbackLocale); 183 } 184 185 public Collection getAncestors() { 186 LinkedList pages = new LinkedList (); 187 Page page = this; 188 while (page != null) { 189 pages.addFirst(page); 190 page = page.getParentPage(); 191 } 192 return pages; 193 } 194 195 public void addChildPage(Page child) { 196 child.setLocale(locale); 197 node.addChildNode(new PageNode(child)); 198 } 199 200 public String getHandlerName() { 201 return node.getHandlerName(); 202 } 203 204 public VersionContainer getVersionContainer() { 205 if (versionContainer == null) { 206 versionContainer = new VersionContainer(); 207 ComponentVersion version = new ComponentVersion(Page.class.getName()); 208 versionContainer.setLiveVersion(version); 209 } 210 return versionContainer; 211 } 212 213 public void setVersionContainer(VersionContainer versionContainer) { 214 this.versionContainer = versionContainer; 215 } 216 217 public Map getProperties(boolean preview) { 218 if (preview) { 219 return getVersionContainer().getLatestVersion().getProperties(); 220 } 221 ComponentVersion version = getVersionContainer().getLiveVersion(); 222 return version != null ? version.getProperties() : null; 223 } 224 225 public String getProperty(String key, boolean preview) { 226 ComponentVersion version = preview 227 ? getVersionContainer().getLatestVersion() 228 : getVersionContainer().getLiveVersion(); 229 230 return version != null ? version.getProperty(key) : null; 231 } 232 233 public boolean isDirty() { 234 return getVersionContainer().isDirty(); 235 } 236 237 public boolean isPublished() { 238 return this.published; 239 } 240 241 public void setPublished(boolean published) { 242 this.published = published; 243 } 244 245 public boolean isEnabled() { 246 return published && getNode().getSite().isLocaleEnabled(locale); 247 } 248 249 public String toString() { 250 return locale + ":" + path; 251 } 252 253 public boolean equals(Object o) { 254 if (o instanceof Page) { 255 Page page = (Page) o; 256 if (id == null) { 257 return this == o; 258 } 259 return id.equals(page.getId()); 260 } 261 return false; 262 } 263 264 public int hashCode() { 265 return id != null ? id.hashCode() : 0; 266 } 267 268 } 269 | Popular Tags |