1 48 49 package org.jpublish.page; 50 51 import java.util.HashMap ; 52 import java.util.List ; 53 import java.util.Locale ; 54 import java.util.Map ; 55 56 import org.apache.commons.logging.Log; 57 import org.apache.commons.logging.LogFactory; 58 import org.jpublish.RequestContext; 59 import org.jpublish.util.Property; 60 61 72 73 public class Page { 74 75 private Log log = LogFactory.getLog(Page.class); 76 77 private PageInstance pageInstance = null; 78 79 private Map properties = new HashMap (); 80 private String templateName = null; 81 private String viewRendererName = null; 82 private Locale locale = Locale.getDefault(); 83 private String encoding = null; 84 private String pageType = null; 85 private String pageName = null; 86 private String pageParent = null; 87 88 93 94 public Page(PageInstance pageInstance) { 95 this.pageInstance = pageInstance; 96 } 97 98 103 104 public String getPath() { 105 if (pageName != null || pageType != null || pageParent != null) { 106 StringBuffer tempPath = new StringBuffer (); 107 String pageParent = getPageParent(); 108 log.debug("Page parent: " + pageParent); 109 if (!pageParent.equals("")) { 110 tempPath.append(pageParent); 111 tempPath.append("/"); 112 } 113 String pageName = getPageName(); 114 log.debug("Page name: " + pageName); 115 tempPath.append(pageName); 116 tempPath.append("."); 117 tempPath.append(getPageType()); 118 log.debug("Generated path: " + tempPath); 119 return tempPath.toString(); 120 } else { 121 return pageInstance.getPath(); 122 } 123 } 124 125 130 131 public String getPageName() { 132 if (pageName != null) { 133 return pageName; 134 } else { 135 return pageInstance.getPageName(); 136 } 137 } 138 139 144 145 public void setPageName(String pageName) { 146 this.pageName = pageName; 147 } 148 149 155 156 public String getPageType() { 157 if (pageType == null) { 158 return pageInstance.getPageType(); 159 } else { 160 return pageType; 161 } 162 } 163 164 169 170 public void setPageType(String pageType) { 171 this.pageType = pageType; 172 } 173 174 179 180 public String getPageParent() { 181 if (pageParent != null) { 182 return pageParent; 183 } else { 184 return pageInstance.getPageParent(); 185 } 186 } 187 188 193 194 public void setPageParent(String pageParent) { 195 this.pageParent = pageParent; 196 } 197 198 203 204 public PageInstance getPageInstance() { 205 return pageInstance; 206 } 207 208 213 214 public String getFullTemplateName() { 215 return getTemplateName() + "." + getPageType(); 216 } 217 218 224 225 public String getTemplateName() { 226 if (templateName == null) { 227 templateName = pageInstance.getTemplateName(); 228 } 229 return templateName; 230 } 231 232 238 239 public void setTemplateName(String templateName) { 240 this.templateName = templateName; 241 } 242 243 248 249 public String getViewRendererName() { 250 log.debug("getViewRendererName()"); 251 if (viewRendererName == null) { 252 log.debug("Setting view renderer name to page instance value"); 253 viewRendererName = pageInstance.getViewRendererName(); 254 if (log.isDebugEnabled()) { 255 log.debug("View renderer name = " + viewRendererName); 256 } 257 } 258 return viewRendererName; 259 } 260 261 266 267 public void setViewRendererName(String viewRendererName) { 268 this.viewRendererName = viewRendererName; 269 } 270 271 277 278 public List getPageActions() { 279 return pageInstance.getPageActions(); 280 } 281 282 288 289 public String getProperty(String name) { 290 return getProperty(name, getLocale()); 291 } 292 293 303 304 public String getProperty(String name, Locale locale) { 305 Property property = (Property) properties.get(name); 306 if (property == null) { 307 String value = pageInstance.getProperty(name, locale); 308 if (value != null) { 309 setProperty(name, value, locale); 310 return value; 311 } 312 } 313 314 if (property == null) { 315 return null; 316 } else { 317 return property.getValue(locale); 318 } 319 } 320 321 329 330 public String get(String name) { 331 return getProperty(name); 332 } 333 334 340 341 public void setProperty(String name, String value) { 342 setProperty(name, value, getLocale()); 343 } 344 345 352 353 public void setProperty(String name, String value, Locale locale) { 354 Property property = (Property) properties.get(name); 355 if (property == null) { 356 property = new Property(name); 358 properties.put(name, property); 359 } 360 property.setValue(value, locale); 361 } 362 363 368 369 public Locale getLocale() { 370 return locale; 371 } 372 373 379 380 public void setLocale(Locale locale) { 381 if (locale == null) { 382 locale = Locale.getDefault(); 383 } 384 this.locale = locale; 385 } 386 387 393 394 public String getEncoding() { 395 if (encoding == null) { 396 encoding = pageInstance.getEncoding(); 397 } 398 return encoding; 399 } 400 401 406 407 public void setEncoding(String encoding) { 408 this.encoding = encoding; 409 } 410 411 416 417 public void executeActions(RequestContext context) { 418 pageInstance.executeActions(context); 419 } 420 421 } 422 | Popular Tags |