001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.pojos;
020:
021: import java.io.Serializable;
022: import java.util.Date;
023: import java.util.HashSet;
024: import java.util.Set;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.roller.RollerException;
028:
029: /**
030: * Pojo that represents a single user defined template page.
031: *
032: * This template is different from the generic template because it also
033: * contains a reference to the website it is part of.
034: *
035: * @ejb:bean name="WeblogTemplate"
036: * @struts.form include-all="true"
037: * @hibernate.class lazy="false" table="webpage"
038: * @hibernate.cache usage="read-write"
039: */
040: public class WeblogTemplate extends PersistentObject implements
041: Serializable, Template {
042:
043: public static final long serialVersionUID = -613737191638263428L;
044: public static final String DEFAULT_PAGE = "Weblog";
045:
046: private static Log log = LogFactory.getLog(WeblogTemplate.class);
047: private static Set requiredTemplates = null;
048:
049: private String id = null;
050: private String name = null;
051: private String description = null;
052: private String link = null;
053: private String contents = null;
054: private Date lastModified = null;
055: private String templateLanguage = null;
056: private boolean hidden = false;
057: private boolean navbar = false;
058: private String decoratorName = null;
059:
060: private WebsiteData weblog = null;
061:
062: static {
063: requiredTemplates = new HashSet();
064: requiredTemplates.add("Weblog");
065: requiredTemplates.add("_day");
066: requiredTemplates.add("_css");
067: requiredTemplates.add("_decorator");
068: }
069:
070: public WeblogTemplate() {
071: }
072:
073: public WeblogTemplate(java.lang.String id, WebsiteData website,
074: java.lang.String name, java.lang.String description,
075: java.lang.String link, java.lang.String template,
076: java.util.Date updateTime, String tempLang, boolean hid,
077: boolean navbar, String decorator) {
078: this .id = id;
079: this .weblog = website;
080: this .name = name;
081: this .description = description;
082: this .link = link;
083: this .contents = template;
084: this .lastModified = (Date) updateTime.clone();
085: this .templateLanguage = tempLang;
086: this .hidden = hid;
087: this .navbar = navbar;
088: this .decoratorName = decorator;
089: }
090:
091: public WeblogTemplate(WeblogTemplate otherData) {
092: setData(otherData);
093: }
094:
095: public Template getDecorator() {
096: if (decoratorName != null && !id.equals(decoratorName)) {
097: try {
098: return weblog.getPageByName(decoratorName);
099: } catch (RollerException ex) {
100: log.error("Error getting decorator[" + decoratorName
101: + "] " + "for template " + id);
102: }
103: }
104: return null;
105: }
106:
107: /**
108: * @ejb:persistent-field
109: * @hibernate.id column="id"
110: * generator-class="uuid.hex" unsaved-value="null"
111: */
112: public java.lang.String getId() {
113: return this .id;
114: }
115:
116: /** @ejb:persistent-field */
117: public void setId(java.lang.String id) {
118: this .id = id;
119: }
120:
121: /**
122: * @ejb:persistent-field
123: * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
124: */
125: public WebsiteData getWebsite() {
126: return this .weblog;
127: }
128:
129: /** @ejb:persistent-field */
130: public void setWebsite(WebsiteData website) {
131: this .weblog = website;
132: }
133:
134: /**
135: * @ejb:persistent-field
136: * @hibernate.property column="name" non-null="true" unique="false"
137: */
138: public java.lang.String getName() {
139: return this .name;
140: }
141:
142: /** @ejb:persistent-field */
143: public void setName(java.lang.String name) {
144: this .name = name;
145: }
146:
147: /**
148: * Description
149: * @ejb:persistent-field
150: * @hibernate.property column="description" non-null="true" unique="false"
151: */
152: public java.lang.String getDescription() {
153: return this .description;
154: }
155:
156: /** @ejb:persistent-field */
157: public void setDescription(java.lang.String description) {
158: this .description = description;
159: }
160:
161: /**
162: * @ejb:persistent-field
163: * @hibernate.property column="link" non-null="true" unique="false"
164: */
165: public java.lang.String getLink() {
166: return this .link;
167: }
168:
169: /** @ejb:persistent-field */
170: public void setLink(java.lang.String link) {
171: this .link = link;
172: }
173:
174: /**
175: * @ejb:persistent-field
176: * @hibernate.property column="template" non-null="true" unique="false"
177: */
178: public java.lang.String getContents() {
179: return this .contents;
180: }
181:
182: /** @ejb:persistent-field */
183: public void setContents(java.lang.String template) {
184: this .contents = template;
185: }
186:
187: /**
188: * @ejb:persistent-field
189: * @hibernate.property column="updatetime" non-null="true" unique="false"
190: */
191: public java.util.Date getLastModified() {
192: return (Date) this .lastModified.clone();
193: }
194:
195: /** @ejb:persistent-field */
196: public void setLastModified(final java.util.Date newtime) {
197: if (newtime != null) {
198: lastModified = (Date) newtime.clone();
199: } else {
200: lastModified = null;
201: }
202: }
203:
204: /**
205: * @ejb:persistent-field
206: * @hibernate.property column="templatelang" non-null="true" unique="false"
207: */
208: public String getTemplateLanguage() {
209: return templateLanguage;
210: }
211:
212: /** @ejb:persistent-field */
213: public void setTemplateLanguage(String templateLanguage) {
214: this .templateLanguage = templateLanguage;
215: }
216:
217: /**
218: * @ejb:persistent-field
219: * @hibernate.property column="navbar" non-null="true" unique="false"
220: */
221: public boolean isNavbar() {
222: return navbar;
223: }
224:
225: /** @ejb:persistent-field */
226: public void setNavbar(boolean navbar) {
227: this .navbar = navbar;
228: }
229:
230: /**
231: * @ejb:persistent-field
232: * @hibernate.property column="hidden" non-null="true" unique="false"
233: */
234: public boolean isHidden() {
235: return hidden;
236: }
237:
238: /** @ejb:persistent-field */
239: public void setHidden(boolean isHidden) {
240: this .hidden = isHidden;
241: }
242:
243: /**
244: * @ejb:persistent-field
245: * @hibernate.property column="decorator" non-null="false" unique="false"
246: */
247: public String getDecoratorName() {
248: return decoratorName;
249: }
250:
251: /** @ejb:persistent-field */
252: public void setDecoratorName(String decorator) {
253: this .decoratorName = decorator;
254: }
255:
256: /**
257: * Determine if this WeblogTemplate is required or not.
258: */
259: public boolean isRequired() {
260: /*
261: * this is kind of hacky right now, but it's like that so we can be
262: * reasonably flexible while we migrate old blogs which may have some
263: * pretty strange customizations.
264: *
265: * my main goal starting now is to prevent further deviations from the
266: * standardized templates as we move forward.
267: *
268: * eventually, the required flag should probably be stored in the db
269: * and possibly applicable to any template.
270: */
271: return (requiredTemplates.contains(this .name) || "Weblog"
272: .equals(this .link));
273: }
274:
275: public void setRequired(boolean req) {
276: // this is an absurd workaround for our struts formbean generation stuff
277: }
278:
279: public String toString() {
280: StringBuffer str = new StringBuffer("{");
281:
282: str.append("id=" + id + " " + "name=" + name + " "
283: + "description=" + description + " " + "link=" + link
284: + " " + "template=" + contents + " " + "updateTime="
285: + lastModified);
286: str.append('}');
287:
288: return (str.toString());
289: }
290:
291: public boolean equals(Object pOther) {
292: if (pOther instanceof WeblogTemplate) {
293: WeblogTemplate lTest = (WeblogTemplate) pOther;
294: boolean lEquals = true;
295:
296: if (this .id == null) {
297: lEquals = lEquals && (lTest.getId() == null);
298: } else {
299: lEquals = lEquals && this .id.equals(lTest.getId());
300: }
301: if (this .weblog == null) {
302: lEquals = lEquals && (lTest.getWebsite() == null);
303: } else {
304: lEquals = lEquals
305: && this .weblog.equals(lTest.getWebsite());
306: }
307: if (this .name == null) {
308: lEquals = lEquals && (lTest.getName() == null);
309: } else {
310: lEquals = lEquals && this .name.equals(lTest.getName());
311: }
312: if (this .description == null) {
313: lEquals = lEquals && (lTest.getDescription() == null);
314: } else {
315: lEquals = lEquals
316: && this .description.equals(lTest
317: .getDescription());
318: }
319: if (this .link == null) {
320: lEquals = lEquals && (lTest.getLink() == null);
321: } else {
322: lEquals = lEquals && this .link.equals(lTest.getLink());
323: }
324: if (this .contents == null) {
325: lEquals = lEquals && (lTest.getContents() == null);
326: } else {
327: lEquals = lEquals
328: && this .contents.equals(lTest.getContents());
329: }
330: if (this .lastModified == null) {
331: lEquals = lEquals && (lTest.getLastModified() == null);
332: } else {
333: lEquals = lEquals
334: && this .lastModified.equals(lTest
335: .getLastModified());
336: }
337:
338: return lEquals;
339: } else {
340: return false;
341: }
342: }
343:
344: public int hashCode() {
345: int result = 17;
346: result = 37 * result
347: + ((this .id != null) ? this .id.hashCode() : 0);
348: result = 37 * result
349: + ((this .weblog != null) ? this .weblog.hashCode() : 0);
350: result = 37 * result
351: + ((this .name != null) ? this .name.hashCode() : 0);
352: result = 37
353: * result
354: + ((this .description != null) ? this .description
355: .hashCode() : 0);
356: result = 37 * result
357: + ((this .link != null) ? this .link.hashCode() : 0);
358: result = 37
359: * result
360: + ((this .contents != null) ? this .contents.hashCode()
361: : 0);
362: result = 37
363: * result
364: + ((this .lastModified != null) ? this .lastModified
365: .hashCode() : 0);
366: return result;
367: }
368:
369: /**
370: * Setter is needed in RollerImpl.storePersistentObject()
371: */
372: public void setData(
373: org.apache.roller.pojos.PersistentObject otherData) {
374: WeblogTemplate other = (WeblogTemplate) otherData;
375: this .weblog = other.getWebsite();
376: this .id = other.getId();
377: this .name = other.getName();
378: this .description = other.getDescription();
379: this .link = other.getLink();
380: this .navbar = other.isNavbar();
381: this .contents = other.getContents();
382: this .lastModified = other.getLastModified() != null ? (Date) other
383: .getLastModified().clone()
384: : null;
385: this.templateLanguage = other.getTemplateLanguage();
386: this.hidden = other.isHidden();
387: this.decoratorName = other.getDecoratorName();
388: }
389:
390: }
|