1 18 19 package org.apache.roller.pojos; 20 21 import java.io.Serializable ; 22 import java.util.Date ; 23 import java.util.HashSet ; 24 import java.util.Set ; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.roller.RollerException; 28 29 40 public class WeblogTemplate extends PersistentObject 41 implements Serializable , Template { 42 43 public static final long serialVersionUID = -613737191638263428L; 44 public static final String DEFAULT_PAGE = "Weblog"; 45 46 private static Log log = LogFactory.getLog(WeblogTemplate.class); 47 private static Set requiredTemplates = null; 48 49 private String id = null; 50 private String name = null; 51 private String description = null; 52 private String link = null; 53 private String contents = null; 54 private Date lastModified = null; 55 private String templateLanguage = null; 56 private boolean hidden = false; 57 private boolean navbar = false; 58 private String decoratorName = null; 59 60 private WebsiteData weblog = null; 61 62 63 static { 64 requiredTemplates = new HashSet (); 65 requiredTemplates.add("Weblog"); 66 requiredTemplates.add("_day"); 67 requiredTemplates.add("_css"); 68 requiredTemplates.add("_decorator"); 69 } 70 71 public WeblogTemplate() {} 72 73 public WeblogTemplate( 74 java.lang.String id, 75 WebsiteData website, 76 java.lang.String name, 77 java.lang.String description, 78 java.lang.String link, 79 java.lang.String template, 80 java.util.Date updateTime, 81 String tempLang, 82 boolean hid, 83 boolean navbar, 84 String decorator) { 85 this.id = id; 86 this.weblog = website; 87 this.name = name; 88 this.description = description; 89 this.link = link; 90 this.contents = template; 91 this.lastModified = (Date )updateTime.clone(); 92 this.templateLanguage = tempLang; 93 this.hidden = hid; 94 this.navbar = navbar; 95 this.decoratorName = decorator; 96 } 97 98 public WeblogTemplate( WeblogTemplate otherData ) { 99 setData(otherData); 100 } 101 102 103 public Template getDecorator() { 104 if(decoratorName != null && !id.equals(decoratorName)) { 105 try { 106 return weblog.getPageByName(decoratorName); 107 } catch (RollerException ex) { 108 log.error("Error getting decorator["+decoratorName+"] "+ 109 "for template "+id); 110 } 111 } 112 return null; 113 } 114 115 116 121 public java.lang.String getId() { 122 return this.id; 123 } 124 125 126 public void setId( java.lang.String id ) { 127 this.id = id; 128 } 129 130 131 135 public WebsiteData getWebsite() { 136 return this.weblog; 137 } 138 139 140 public void setWebsite( WebsiteData website ) { 141 this.weblog = website; 142 } 143 144 145 149 public java.lang.String getName() { 150 return this.name; 151 } 152 153 154 public void setName( java.lang.String name ) { 155 this.name = name; 156 } 157 158 159 164 public java.lang.String getDescription() { 165 return this.description; 166 } 167 168 169 public void setDescription( java.lang.String description ) { 170 this.description = description; 171 } 172 173 174 178 public java.lang.String getLink() { 179 return this.link; 180 } 181 182 183 public void setLink( java.lang.String link ) { 184 this.link = link; 185 } 186 187 188 192 public java.lang.String getContents() { 193 return this.contents; 194 } 195 196 197 public void setContents( java.lang.String template ) { 198 this.contents = template; 199 } 200 201 202 206 public java.util.Date getLastModified() { 207 return (Date )this.lastModified.clone(); 208 } 209 210 211 public void setLastModified(final java.util.Date newtime ) { 212 if (newtime != null) { 213 lastModified = (Date )newtime.clone(); 214 } else { 215 lastModified = null; 216 } 217 } 218 219 220 224 public String getTemplateLanguage() { 225 return templateLanguage; 226 } 227 228 229 public void setTemplateLanguage(String templateLanguage) { 230 this.templateLanguage = templateLanguage; 231 } 232 233 234 238 public boolean isNavbar() { 239 return navbar; 240 } 241 242 243 public void setNavbar(boolean navbar) { 244 this.navbar = navbar; 245 } 246 247 251 public boolean isHidden() { 252 return hidden; 253 } 254 255 256 public void setHidden(boolean isHidden) { 257 this.hidden = isHidden; 258 } 259 260 264 public String getDecoratorName() { 265 return decoratorName; 266 } 267 268 269 public void setDecoratorName(String decorator) { 270 this.decoratorName = decorator; 271 } 272 273 274 277 public boolean isRequired() { 278 289 return (requiredTemplates.contains(this.name) || "Weblog".equals(this.link)); 290 } 291 292 293 public void setRequired(boolean req) { 294 } 296 297 298 public String toString() { 299 StringBuffer str = new StringBuffer ("{"); 300 301 str.append("id=" + id + " " + "name=" + name + " " + "description=" 302 + description + " " + "link=" + link + " " + "template=" + contents 303 + " " + "updateTime=" + lastModified); 304 str.append('}'); 305 306 return(str.toString()); 307 } 308 309 310 public boolean equals( Object pOther ) { 311 if( pOther instanceof WeblogTemplate ) { 312 WeblogTemplate lTest = (WeblogTemplate) pOther; 313 boolean lEquals = true; 314 315 if( this.id == null ) { 316 lEquals = lEquals && ( lTest.getId() == null ); 317 } else { 318 lEquals = lEquals && this.id.equals( lTest.getId() ); 319 } 320 if( this.weblog == null ) { 321 lEquals = lEquals && ( lTest.getWebsite() == null ); 322 } else { 323 lEquals = lEquals && this.weblog.equals( lTest.getWebsite() ); 324 } 325 if( this.name == null ) { 326 lEquals = lEquals && ( lTest.getName() == null ); 327 } else { 328 lEquals = lEquals && this.name.equals( lTest.getName() ); 329 } 330 if( this.description == null ) { 331 lEquals = lEquals && ( lTest.getDescription() == null ); 332 } else { 333 lEquals = lEquals && this.description.equals( lTest.getDescription() ); 334 } 335 if( this.link == null ) { 336 lEquals = lEquals && ( lTest.getLink() == null ); 337 } else { 338 lEquals = lEquals && this.link.equals( lTest.getLink() ); 339 } 340 if( this.contents == null ) { 341 lEquals = lEquals && ( lTest.getContents() == null ); 342 } else { 343 lEquals = lEquals && this.contents.equals( lTest.getContents() ); 344 } 345 if( this.lastModified == null ) { 346 lEquals = lEquals && ( lTest.getLastModified() == null ); 347 } else { 348 lEquals = lEquals && this.lastModified.equals( lTest.getLastModified() ); 349 } 350 351 return lEquals; 352 } else { 353 return false; 354 } 355 } 356 357 358 public int hashCode() { 359 int result = 17; 360 result = 37*result + ((this.id != null) ? this.id.hashCode() : 0); 361 result = 37*result + ((this.weblog != null) ? this.weblog.hashCode() : 0); 362 result = 37*result + ((this.name != null) ? this.name.hashCode() : 0); 363 result = 37*result + ((this.description != null) ? this.description.hashCode() : 0); 364 result = 37*result + ((this.link != null) ? this.link.hashCode() : 0); 365 result = 37*result + ((this.contents != null) ? this.contents.hashCode() : 0); 366 result = 37*result + ((this.lastModified != null) ? this.lastModified.hashCode() : 0); 367 return result; 368 } 369 370 371 374 public void setData( org.apache.roller.pojos.PersistentObject otherData ) { 375 WeblogTemplate other = (WeblogTemplate)otherData; 376 this.weblog = other.getWebsite(); 377 this.id = other.getId(); 378 this.name = other.getName(); 379 this.description = other.getDescription(); 380 this.link = other.getLink(); 381 this.navbar = other.isNavbar(); 382 this.contents = other.getContents(); 383 this.lastModified = other.getLastModified()!=null ? (Date )other.getLastModified().clone() : null; 384 this.templateLanguage = other.getTemplateLanguage(); 385 this.hidden = other.isHidden(); 386 this.decoratorName = other.getDecoratorName(); 387 } 388 389 } 390 | Popular Tags |