KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > pojos > WeblogTemplate


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.pojos;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.Date JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Set JavaDoc;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.roller.RollerException;
28
29 /**
30  * Pojo that represents a single user defined template page.
31  *
32  * This template is different from the generic template because it also
33  * contains a reference to the website it is part of.
34  *
35  * @ejb:bean name="WeblogTemplate"
36  * @struts.form include-all="true"
37  * @hibernate.class lazy="false" table="webpage"
38  * @hibernate.cache usage="read-write"
39  */

40 public class WeblogTemplate extends PersistentObject
41         implements Serializable JavaDoc, Template {
42     
43     public static final long serialVersionUID = -613737191638263428L;
44     public static final String JavaDoc DEFAULT_PAGE = "Weblog";
45     
46     private static Log log = LogFactory.getLog(WeblogTemplate.class);
47     private static Set JavaDoc requiredTemplates = null;
48     
49     private String JavaDoc id = null;
50     private String JavaDoc name = null;
51     private String JavaDoc description = null;
52     private String JavaDoc link = null;
53     private String JavaDoc contents = null;
54     private Date JavaDoc lastModified = null;
55     private String JavaDoc templateLanguage = null;
56     private boolean hidden = false;
57     private boolean navbar = false;
58     private String JavaDoc decoratorName = null;
59     
60     private WebsiteData weblog = null;
61     
62     
63     static {
64         requiredTemplates = new HashSet JavaDoc();
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 JavaDoc id,
75             WebsiteData website,
76             java.lang.String JavaDoc name,
77             java.lang.String JavaDoc description,
78             java.lang.String JavaDoc link,
79             java.lang.String JavaDoc template,
80             java.util.Date JavaDoc updateTime,
81             String JavaDoc tempLang,
82             boolean hid,
83             boolean navbar,
84             String JavaDoc 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 JavaDoc)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     /**
117      * @ejb:persistent-field
118      * @hibernate.id column="id"
119      * generator-class="uuid.hex" unsaved-value="null"
120      */

121     public java.lang.String JavaDoc getId() {
122         return this.id;
123     }
124     
125     /** @ejb:persistent-field */
126     public void setId( java.lang.String JavaDoc id ) {
127         this.id = id;
128     }
129     
130     
131     /**
132      * @ejb:persistent-field
133      * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
134      */

135     public WebsiteData getWebsite() {
136         return this.weblog;
137     }
138     
139     /** @ejb:persistent-field */
140     public void setWebsite( WebsiteData website ) {
141         this.weblog = website;
142     }
143     
144     
145     /**
146      * @ejb:persistent-field
147      * @hibernate.property column="name" non-null="true" unique="false"
148      */

149     public java.lang.String JavaDoc getName() {
150         return this.name;
151     }
152     
153     /** @ejb:persistent-field */
154     public void setName( java.lang.String JavaDoc name ) {
155         this.name = name;
156     }
157     
158     
159     /**
160      * Description
161      * @ejb:persistent-field
162      * @hibernate.property column="description" non-null="true" unique="false"
163      */

164     public java.lang.String JavaDoc getDescription() {
165         return this.description;
166     }
167     
168     /** @ejb:persistent-field */
169     public void setDescription( java.lang.String JavaDoc description ) {
170         this.description = description;
171     }
172     
173     
174     /**
175      * @ejb:persistent-field
176      * @hibernate.property column="link" non-null="true" unique="false"
177      */

178     public java.lang.String JavaDoc getLink() {
179         return this.link;
180     }
181     
182     /** @ejb:persistent-field */
183     public void setLink( java.lang.String JavaDoc link ) {
184         this.link = link;
185     }
186     
187     
188     /**
189      * @ejb:persistent-field
190      * @hibernate.property column="template" non-null="true" unique="false"
191      */

192     public java.lang.String JavaDoc getContents() {
193         return this.contents;
194     }
195     
196     /** @ejb:persistent-field */
197     public void setContents( java.lang.String JavaDoc template ) {
198         this.contents = template;
199     }
200     
201     
202     /**
203      * @ejb:persistent-field
204      * @hibernate.property column="updatetime" non-null="true" unique="false"
205      */

206     public java.util.Date JavaDoc getLastModified() {
207         return (Date JavaDoc)this.lastModified.clone();
208     }
209     
210     /** @ejb:persistent-field */
211     public void setLastModified(final java.util.Date JavaDoc newtime ) {
212         if (newtime != null) {
213             lastModified = (Date JavaDoc)newtime.clone();
214         } else {
215             lastModified = null;
216         }
217     }
218     
219     
220     /**
221      * @ejb:persistent-field
222      * @hibernate.property column="templatelang" non-null="true" unique="false"
223      */

224     public String JavaDoc getTemplateLanguage() {
225         return templateLanguage;
226     }
227
228     /** @ejb:persistent-field */
229     public void setTemplateLanguage(String JavaDoc templateLanguage) {
230         this.templateLanguage = templateLanguage;
231     }
232     
233     
234     /**
235      * @ejb:persistent-field
236      * @hibernate.property column="navbar" non-null="true" unique="false"
237      */

238     public boolean isNavbar() {
239         return navbar;
240     }
241
242     /** @ejb:persistent-field */
243     public void setNavbar(boolean navbar) {
244         this.navbar = navbar;
245     }
246     
247     /**
248      * @ejb:persistent-field
249      * @hibernate.property column="hidden" non-null="true" unique="false"
250      */

251     public boolean isHidden() {
252         return hidden;
253     }
254
255     /** @ejb:persistent-field */
256     public void setHidden(boolean isHidden) {
257         this.hidden = isHidden;
258     }
259         
260     /**
261      * @ejb:persistent-field
262      * @hibernate.property column="decorator" non-null="false" unique="false"
263      */

264     public String JavaDoc getDecoratorName() {
265         return decoratorName;
266     }
267
268     /** @ejb:persistent-field */
269     public void setDecoratorName(String JavaDoc decorator) {
270         this.decoratorName = decorator;
271     }
272     
273     
274     /**
275      * Determine if this WeblogTemplate is required or not.
276      */

277     public boolean isRequired() {
278        /*
279         * this is kind of hacky right now, but it's like that so we can be
280         * reasonably flexible while we migrate old blogs which may have some
281         * pretty strange customizations.
282         *
283         * my main goal starting now is to prevent further deviations from the
284         * standardized templates as we move forward.
285         *
286         * eventually, the required flag should probably be stored in the db
287         * and possibly applicable to any template.
288         */

289         return (requiredTemplates.contains(this.name) || "Weblog".equals(this.link));
290     }
291     
292     
293     public void setRequired(boolean req) {
294         // this is an absurd workaround for our struts formbean generation stuff
295
}
296     
297     
298     public String JavaDoc toString() {
299         StringBuffer JavaDoc str = new StringBuffer JavaDoc("{");
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 JavaDoc 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     /**
372      * Setter is needed in RollerImpl.storePersistentObject()
373      */

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 JavaDoc)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