You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/05/02 00:23:34 UTC
svn commit: r398712 [11/32] - in /incubator/roller/trunk/src/org/apache: ./
roller/ roller/business/ roller/business/hibernate/
roller/business/referrers/ roller/business/runnable/
roller/business/search/ roller/business/search/operations/ roller/busin...
Added: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryData.java Mon May 1 15:23:02 2006
@@ -0,0 +1,1213 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+
+package org.apache.roller.pojos;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.Roller;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.UserManager;
+import org.apache.roller.model.WeblogManager;
+import org.apache.roller.util.DateUtil;
+import org.apache.roller.util.Utilities;
+
+/**
+ * Represents a Weblog Entry.
+ *
+ * @author David M Johnson
+ *
+ * @ejb:bean name="WeblogEntryData"
+ * @struts.form include-all="true"
+ * @hibernate.class lazy="false" table="weblogentry"
+ * @hibernate.cache usage="read-write"
+ */
+public class WeblogEntryData extends PersistentObject implements Serializable
+{
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(WeblogEntryData.class);
+
+ public static final long serialVersionUID = 2341505386843044125L;
+
+ public static final String DRAFT = "DRAFT";
+ public static final String PENDING = "PENDING";
+ public static final String PUBLISHED = "PUBLISHED";
+
+ // Simple properies
+ private String id = null;
+ private String title = null;
+ private String link = null;
+ private String summary = null;
+ private String text = null;
+ private String contentType = null;
+ private String contentSrc = null;
+ private String anchor = null;
+ private Timestamp pubTime = null;
+ private Timestamp updateTime = null;
+ private String plugins = null;
+ private Boolean allowComments = Boolean.TRUE;
+ private Integer commentDays = new Integer(7);
+ private Boolean rightToLeft = Boolean.FALSE;
+ private Boolean pinnedToMain = Boolean.FALSE;
+ private String status = DRAFT;
+
+ // Associated objects
+ private UserData creator = null;
+ private WebsiteData website = null;
+ private WeblogCategoryData category = null;
+
+ // Collection of name/value entry attributes
+ private Map attMap = new HashMap();
+ private Set attSet = new TreeSet();
+
+ //----------------------------------------------------------- Construction
+
+ public WeblogEntryData()
+ {
+ }
+
+ public WeblogEntryData(
+ java.lang.String id,
+ WeblogCategoryData category,
+ WebsiteData website,
+ UserData creator,
+ String title,
+ String link,
+ String text,
+ String anchor,
+ Timestamp pubTime,
+ Timestamp updateTime,
+ String status)
+ {
+ this.id = id;
+ this.category = category;
+ this.website = website;
+ this.creator = creator;
+ this.title = title;
+ this.link = link;
+ this.text = text;
+ this.anchor = anchor;
+ this.pubTime = pubTime;
+ this.updateTime = updateTime;
+ this.status = status;
+ }
+
+ public WeblogEntryData(WeblogEntryData otherData)
+ {
+ this.setData(otherData);
+ }
+
+ //---------------------------------------------------------- Initializaion
+
+ /**
+ * Setter is needed in RollerImpl.storePersistentObject()
+ */
+ public void setData(org.apache.roller.pojos.PersistentObject otherData)
+ {
+ WeblogEntryData other = (WeblogEntryData)otherData;
+
+ this.id = other.getId();
+ this.category = other.getCategory();
+ this.website = other.getWebsite();
+ this.creator = other.getCreator();
+ this.title = other.getTitle();
+ this.link = other.getLink();
+ this.text = other.getText();
+ this.anchor = other.getAnchor();
+ this.pubTime = other.getPubTime();
+ this.updateTime = other.getUpdateTime();
+ this.status = other.getStatus();
+ this.plugins = other.getPlugins();
+ this.allowComments = other.getAllowComments();
+ this.commentDays = other.getCommentDays();
+ this.rightToLeft = other.getRightToLeft();
+ this.pinnedToMain = other.getPinnedToMain();
+ }
+
+ //------------------------------------------------------ Simple properties
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.id column="id" generator-class="uuid.hex" unsaved-value="null"
+ */
+ public java.lang.String getId()
+ {
+ return this.id;
+ }
+
+ /** @ejb:persistent-field */
+ public void setId(java.lang.String id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="pojo"
+ * @ejb:persistent-field
+ * @hibernate.many-to-one column="categoryid" cascade="none" not-null="true"
+ */
+ public org.apache.roller.pojos.WeblogCategoryData getCategory()
+ {
+ return this.category;
+ }
+
+ /** @ejb:persistent-field */
+ public void setCategory(org.apache.roller.pojos.WeblogCategoryData category)
+ {
+ this.category = category;
+ }
+
+ /**
+ * Set weblog category via weblog category ID.
+ * @param id Weblog category ID.
+ */
+ public void setCategoryId(String id) throws RollerException
+ {
+ WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
+ setCategory(wmgr.getWeblogCategory(id));
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="pojo"
+ * @ejb:persistent-field
+ * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
+ */
+ public WebsiteData getWebsite()
+ {
+ return this.website;
+ }
+
+ /** @ejb:persistent-field */
+ public void setWebsite(WebsiteData website)
+ {
+ this.website = website;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.many-to-one column="userid" cascade="none" not-null="true"
+ */
+ public UserData getCreator()
+ {
+ return this.creator;
+ }
+
+ /** @ejb:persistent-field */
+ public void setCreator(UserData creator)
+ {
+ this.creator = creator;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="title" non-null="true" unique="false"
+ */
+ public java.lang.String getTitle()
+ {
+ return this.title;
+ }
+
+ /** @ejb:persistent-field */
+ public void setTitle(java.lang.String title)
+ {
+ this.title = title;
+ }
+
+ /**
+ * Get summary for weblog entry (maps to RSS description and Atom summary).
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="summary" non-null="false" unique="false"
+ */
+ public String getSummary() {
+ return summary;
+ }
+
+ /**
+ * Set summary for weblog entry (maps to RSS description and Atom summary).
+ * @ejb:persistent-field
+ */
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+
+ /**
+ * Get content text for weblog entry (maps to RSS content:encoded and Atom content).
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="text" non-null="true" unique="false"
+ */
+ public java.lang.String getText()
+ {
+ return this.text;
+ }
+
+ /**
+ * Set content text for weblog entry (maps to RSS content:encoded and Atom content).
+ * @ejb:persistent-field
+ */
+ public void setText(java.lang.String text)
+ {
+ this.text = text;
+ }
+
+ /**
+ * Get content type (text, html, xhtml or a MIME content type)
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="content_type" non-null="false" unique="false"
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * Set content type (text, html, xhtml or a MIME content type)
+ * @ejb:persistent-field
+ */
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ /**
+ * Get URL for out-of-line content.
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="content_src" non-null="false" unique="false"
+ */
+ public String getContentSrc() {
+ return contentSrc;
+ }
+
+ /**
+ * Set URL for out-of-line content.
+ * @ejb:persistent-field
+ */
+ public void setContentSrc(String contentSrc) {
+ this.contentSrc = contentSrc;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="anchor" non-null="true" unique="false"
+ */
+ public java.lang.String getAnchor()
+ {
+ return this.anchor;
+ }
+
+ /** @ejb:persistent-field */
+ public void setAnchor(java.lang.String anchor)
+ {
+ this.anchor = anchor;
+ }
+
+ //-------------------------------------------------------------------------
+ /**
+ * Map attributes as set because XDoclet 1.2b4 map support is broken.
+ *
+ * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.EntryAttributeData"
+ * @ejb:persistent-field
+ * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all-delete-orphan"
+ * @hibernate.collection-key column="entryid" type="String"
+ * @hibernate.collection-one-to-many class="org.apache.roller.pojos.EntryAttributeData"
+ */
+ public Set getEntryAttributes()
+ {
+ return attSet;
+ }
+ /** @ejb:persistent-field */
+ public void setEntryAttributes(Set attSet)
+ {
+ this.attSet = attSet;
+
+ // copy set to map
+ if (attSet != null)
+ {
+ this.attSet = attSet;
+ this.attMap = new HashMap();
+ Iterator iter = this.attSet.iterator();
+ while (iter.hasNext())
+ {
+ EntryAttributeData att = (EntryAttributeData)iter.next();
+ attMap.put(att.getName(), att);
+ }
+ }
+ else
+ {
+ this.attSet = new TreeSet();
+ this.attMap = new HashMap();
+ }
+ }
+
+
+ /**
+ * Would be named getEntryAttribute, but that would set off XDoclet
+ *
+ * @roller.wrapPojoMethod type="simple"
+ */
+ public String findEntryAttribute(String name)
+ {
+ EntryAttributeData att = ((EntryAttributeData)attMap.get(name));
+ return (att != null) ? att.getValue() : null;
+ }
+
+
+ public void putEntryAttribute(String name, String value) throws Exception
+ {
+ EntryAttributeData att = (EntryAttributeData)attMap.get(name);
+ if (att == null)
+ {
+ att = new EntryAttributeData();
+ att.setEntry(this);
+ att.setName(name);
+ att.setValue(value);
+ attMap.put(name, att);
+ attSet.add(att);
+ }
+ else
+ {
+ att.setValue(value);
+ }
+ }
+ public void removeEntryAttribute(String name) throws RollerException
+ {
+ EntryAttributeData att = (EntryAttributeData)attMap.get(name);
+ if (att != null)
+ {
+ attMap.remove(att);
+ attSet.remove(att);
+ }
+ }
+ //-------------------------------------------------------------------------
+
+ /**
+ * <p>Publish time is the time that an entry is to be (or was) made available
+ * for viewing by newsfeed readers and visitors to the Roller site.</p>
+ *
+ * <p>Roller stores time using the timeZone of the server itself. When
+ * times are displayed in a user's weblog they must be translated
+ * to the user's timeZone.</p>
+ *
+ * <p>NOTE: Times are stored using the SQL TIMESTAMP datatype, which on
+ * MySQL has only a one-second resolution.</p>
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="pubtime" non-null="true" unique="false"
+ */
+ public java.sql.Timestamp getPubTime()
+ {
+ return this.pubTime;
+ }
+
+ /** @ejb:persistent-field */
+ public void setPubTime(java.sql.Timestamp pubTime)
+ {
+ this.pubTime = pubTime;
+ }
+
+ /**
+ * <p>Update time is the last time that an weblog entry was saved in the
+ * Roller weblog editor or via web services API (XML-RPC or Atom).</p>
+ *
+ * <p>Roller stores time using the timeZone of the server itself. When
+ * times are displayed in a user's weblog they must be translated
+ * to the user's timeZone.</p>
+ *
+ * <p>NOTE: Times are stored using the SQL TIMESTAMP datatype, which on
+ * MySQL has only a one-second resolution.</p>
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="updatetime" non-null="true" unique="false"
+ */
+ public java.sql.Timestamp getUpdateTime()
+ {
+ return this.updateTime;
+ }
+
+ /** @ejb:persistent-field */
+ public void setUpdateTime(java.sql.Timestamp updateTime)
+ {
+ this.updateTime = updateTime;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="status" non-null="true" unique="false"
+ */
+ public String getStatus()
+ {
+ return this.status;
+ }
+
+ /** @ejb:persistent-field */
+ public void setStatus(String status)
+ {
+ this.status = status;
+ }
+
+ /**
+ * Some weblog entries are about one specific link.
+ * @return Returns the link.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="link" non-null="false" unique="false"
+ */
+ public java.lang.String getLink()
+ {
+ return link;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @param link The link to set.
+ */
+ public void setLink(java.lang.String link)
+ {
+ this.link = link;
+ }
+
+ /**
+ * Comma-delimited list of this entry's Plugins.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="plugins" non-null="false" unique="false"
+ */
+ public java.lang.String getPlugins()
+ {
+ return plugins;
+ }
+
+ /** @ejb:persistent-field */
+ public void setPlugins(java.lang.String string)
+ {
+ plugins = string;
+ }
+
+
+ /**
+ * True if comments are allowed on this weblog entry.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="allowcomments" non-null="true" unique="false"
+ */
+ public Boolean getAllowComments() {
+ return allowComments;
+ }
+ /**
+ * True if comments are allowed on this weblog entry.
+ * @ejb:persistent-field
+ */
+ public void setAllowComments(Boolean allowComments) {
+ this.allowComments = allowComments;
+ }
+
+ /**
+ * Number of days after pubTime that comments should be allowed, or 0 for no limit.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="commentdays" non-null="true" unique="false"
+ */
+ public Integer getCommentDays() {
+ return commentDays;
+ }
+ /**
+ * Number of days after pubTime that comments should be allowed, or 0 for no limit.
+ * @ejb:persistent-field
+ */
+ public void setCommentDays(Integer commentDays) {
+ this.commentDays = commentDays;
+ }
+
+ /**
+ * True if this entry should be rendered right to left.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="righttoleft" non-null="true" unique="false"
+ */
+ public Boolean getRightToLeft() {
+ return rightToLeft;
+ }
+ /**
+ * True if this entry should be rendered right to left.
+ * @ejb:persistent-field
+ */
+ public void setRightToLeft(Boolean rightToLeft) {
+ this.rightToLeft = rightToLeft;
+ }
+
+ /**
+ * True if story should be pinned to the top of the Roller site main blog.
+ * @return Returns the pinned.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="pinnedtomain" non-null="true" unique="false"
+ */
+ public Boolean getPinnedToMain()
+ {
+ return pinnedToMain;
+ }
+ /**
+ * True if story should be pinned to the top of the Roller site main blog.
+ * @param pinnedToMain The pinned to set.
+ *
+ * @ejb:persistent-field
+ */
+ public void setPinnedToMain(Boolean pinnedToMain)
+ {
+ this.pinnedToMain = pinnedToMain;
+ }
+
+ //------------------------------------------------------------------------
+
+ /**
+ * True if comments are still allowed on this entry considering the
+ * allowComments and commentDays fields.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ */
+ public boolean getCommentsStillAllowed()
+ {
+ if(DRAFT.equals(this.status) || PENDING.equals(this.status))
+ return false;
+
+ boolean ret = false;
+ if (getAllowComments() == null || getAllowComments().booleanValue())
+ {
+ if (getCommentDays() == null || getCommentDays().intValue() == 0)
+ {
+ ret = true;
+ }
+ else
+ {
+ Calendar expireCal = Calendar.getInstance(
+ getWebsite().getLocaleInstance());
+ expireCal.setTime(getPubTime());
+ expireCal.add(Calendar.DATE, getCommentDays().intValue());
+ Date expireDay = expireCal.getTime();
+ Date today = new Date();
+ if (today.before(expireDay))
+ {
+ ret = true;
+ }
+ }
+ }
+ return ret;
+ }
+ public void setCommentsStillAllowed(boolean ignored) {
+ // no-op
+ }
+
+
+ //------------------------------------------------------------------------
+
+ /**
+ * Format the publish time of this weblog entry using the specified pattern.
+ * See java.text.SimpleDateFormat for more information on this format.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @see java.text.SimpleDateFormat
+ * @return Publish time formatted according to pattern.
+ */
+ public String formatPubTime(String pattern)
+ {
+ try
+ {
+ SimpleDateFormat format = new SimpleDateFormat(pattern,
+ this.getWebsite().getLocaleInstance());
+
+ return format.format(getPubTime());
+ }
+ catch (RuntimeException e)
+ {
+ mLogger.error("Unexpected exception", e);
+ }
+
+ return "ERROR: formatting date";
+ }
+
+ //------------------------------------------------------------------------
+
+ /**
+ * Format the update time of this weblog entry using the specified pattern.
+ * See java.text.SimpleDateFormat for more information on this format.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @see java.text.SimpleDateFormat
+ * @return Update time formatted according to pattern.
+ */
+ public String formatUpdateTime(String pattern)
+ {
+ try
+ {
+ SimpleDateFormat format = new SimpleDateFormat(pattern);
+
+ return format.format(getUpdateTime());
+ }
+ catch (RuntimeException e)
+ {
+ mLogger.error("Unexpected exception", e);
+ }
+
+ return "ERROR: formatting date";
+ }
+
+ //------------------------------------------------------------------------
+
+ /**
+ * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.CommentData"
+ */
+ public List getComments() {
+ return getComments(true, true);
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.CommentData"
+ */
+ public List getComments(boolean ignoreSpam, boolean approvedOnly) {
+ List list = new ArrayList();
+ try {
+ WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
+ return wmgr.getComments(
+ getWebsite(),
+ this,
+ null, // search String
+ null, // startDate
+ null, // endDate
+ null, // pending
+ approvedOnly ? Boolean.TRUE : null, // approved
+ ignoreSpam ? Boolean.FALSE : null, // spam
+ false, // we want chrono order
+ 0, // offset
+ -1); // no limit
+ } catch (RollerException alreadyLogged) {}
+ return list;
+ }
+
+ //------------------------------------------------------------------------
+
+ /**
+ * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.RefererData"
+ */
+ public List getReferers()
+ {
+ List referers = null;
+ try {
+ referers = RollerFactory.getRoller().getRefererManager().getReferersToEntry(getId());
+ } catch (RollerException e) {
+ mLogger.error("Unexpected exception", e);
+ }
+ return referers;
+ }
+
+ //------------------------------------------------------------------------
+
+ /**
+ * @param entry
+ * @param url
+ * @param title
+ * @param excerpt
+ * @param blogName
+ */
+ /* moved to trackback servlet -- Allen G
+ public void addTrackback(
+ String url, String title, String excerpt, String blogName)
+ throws RollerException
+ {
+ String modTitle = blogName + ": " + title;
+ if (modTitle.length() >= 250)
+ {
+ modTitle = modTitle.substring(0, 257);
+ modTitle += "...";
+ }
+
+ // Track trackbacks as comments
+ CommentData comment = new CommentData();
+ comment.setContent("[Trackback] "+excerpt);
+ comment.setName(blogName);
+ comment.setUrl(url);
+ comment.setWeblogEntry(this);
+ comment.setNotify(Boolean.FALSE);
+ comment.setPostTime(new Timestamp(new Date().getTime()));
+ comment.save();
+
+ // Alternative: treat trackbacks as referers
+ //RefererData ref = new RefererData();
+ //ref.setWebsite(getWebsite());
+ //ref.setWeblogEntry(this);
+ //ref.setRequestUrl("(trackback)");
+ //ref.setRefererUrl(url);
+ //ref.setTitle(modTitle);
+ //ref.setExcerpt(excerpt);
+ //ref.setVisible(Boolean.TRUE);
+ //ref.setDayHits(new Integer(0));
+ //ref.setTotalHits(new Integer(0));
+ //ref.setDuplicate(Boolean.FALSE);
+ //ref.setDateString(formatPubTime("yyyyMMdd"));
+ //mRoller.getRefererManager().storeReferer(ref);
+ }
+ */
+
+ /**
+ * Convenience method for getPermalink(category)
+ * where no category is necessary.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @return
+ */
+ public String getPermaLink()
+ {
+ String lAnchor = this.getAnchor();
+
+ try
+ {
+ lAnchor = URLEncoder.encode(anchor, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // go with the "no encoding" version
+ }
+
+ WebsiteData website = this.getWebsite();
+ String plink = "/page/" + website.getHandle() +
+ "?entry=" + lAnchor;
+
+ return plink;
+ }
+
+ /**
+ * Get the "relative" URL to this entry. Proper use of this will
+ * require prepending the baseURL (either the full root
+ * [http://server.com/context] or at least the context
+ * [/context]) in order to generate a functional link.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @param category The category name to insert into the permalink.
+ * @return String
+ */
+ public String getPermaLink(String categoryPath)
+ {
+ // i don't really understand the purpose of this method since
+ // WeblogEntryData.getPermaLink() is only meant to point to this entry
+
+ return this.getPermaLink();
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ */
+ public String getCommentsLink()
+ {
+ String dayString = DateUtil.format8chars(this.getPubTime());
+ String lAnchor = this.getAnchor();
+ try
+ {
+ lAnchor = URLEncoder.encode(anchor, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // go with the "no encoding" version
+ }
+ String clink = "/page/" + this.getWebsite().getHandle() + "?anchor=" + lAnchor;
+ return clink;
+ }
+ /** to please XDoclet */
+ public void setCommentsLink(String ignored) {}
+
+ /**
+ * Return the Title of this post, or the first 255 characters of the
+ * entry's text.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @return String
+ */
+ public String getDisplayTitle()
+ {
+ if ( getTitle()==null || getTitle().trim().equals("") )
+ {
+ return StringUtils.left(Utilities.removeHTML(text),255);
+ }
+ return Utilities.removeHTML(getTitle());
+ }
+
+ //------------------------------------------------------------------------
+
+ public String toString()
+ {
+ StringBuffer str = new StringBuffer("{");
+
+ str.append("id=" + id + " " +
+ "category=" + category + " " +
+ "title=" + title + " " +
+ "text=" + text + " " +
+ "anchor=" + anchor + " " +
+ "pubTime=" + pubTime + " " +
+ "updateTime=" + updateTime + " " +
+ "status=" + status + " " +
+ "plugins=" + plugins);
+ str.append('}');
+
+ return (str.toString());
+ }
+
+ //------------------------------------------------------------------------
+
+ public boolean equals(Object pOther)
+ {
+ if (pOther instanceof WeblogEntryData)
+ {
+ WeblogEntryData lTest = (WeblogEntryData) pOther;
+ boolean lEquals = true;
+
+ if (this.id == null)
+ {
+ lEquals = lEquals && (lTest.getId() == null);
+ }
+ else
+ {
+ lEquals = lEquals && this.id.equals(lTest.getId());
+ }
+
+ if (this.category == null)
+ {
+ lEquals = lEquals && (lTest.getCategory() == null);
+ }
+ else
+ {
+ lEquals = lEquals && this.category.equals(lTest.getCategory());
+ }
+
+ if (this.website == null)
+ {
+ lEquals = lEquals && (lTest.getWebsite() == null);
+ }
+ else
+ {
+ lEquals = lEquals && this.website.equals(lTest.getWebsite());
+ }
+
+ if (this.title == null)
+ {
+ lEquals = lEquals && (lTest.getTitle() == null);
+ }
+ else
+ {
+ lEquals = lEquals && this.title.equals(lTest.getTitle());
+ }
+
+ if (this.text == null)
+ {
+ lEquals = lEquals && (lTest.getText() == null);
+ }
+ else
+ {
+ lEquals = lEquals && this.text.equals(lTest.getText());
+ }
+
+ if (this.anchor == null)
+ {
+ lEquals = lEquals && (lTest.getAnchor() == null);
+ }
+ else
+ {
+ lEquals = lEquals && this.anchor.equals(lTest.getAnchor());
+ }
+
+ if (this.pubTime == null)
+ {
+ lEquals = lEquals && (lTest.getPubTime() == null);
+ }
+ else
+ {
+ lEquals = lEquals && this.pubTime.equals(lTest.getPubTime());
+ }
+
+ if (this.updateTime == null)
+ {
+ lEquals = lEquals && (lTest.getUpdateTime() == null);
+ }
+ else
+ {
+ lEquals = lEquals &&
+ this.updateTime.equals(lTest.getUpdateTime());
+ }
+
+ if (this.status == null)
+ {
+ lEquals = lEquals && (lTest.getStatus() == null);
+ }
+ else
+ {
+ lEquals = lEquals &&
+ this.status.equals(lTest.getStatus());
+ }
+
+ if (this.plugins == null)
+ {
+ lEquals = lEquals && (lTest.getPlugins() == null);
+ }
+ else
+ {
+ lEquals = lEquals &&
+ this.plugins.equals(lTest.getPlugins());
+ }
+
+
+ return lEquals;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ //------------------------------------------------------------------------
+
+ public int hashCode()
+ {
+ int result = 17;
+ result = (37 * result) +
+ ((this.id != null) ? this.id.hashCode() : 0);
+ result = (37 * result) +
+ ((this.category != null) ? this.category.hashCode() : 0);
+ result = (37 * result) +
+ ((this.website != null) ? this.website.hashCode() : 0);
+ result = (37 * result) +
+ ((this.title != null) ? this.title.hashCode() : 0);
+ result = (37 * result) +
+ ((this.text != null) ? this.text.hashCode() : 0);
+ result = (37 * result) +
+ ((this.anchor != null) ? this.anchor.hashCode() : 0);
+ result = (37 * result) +
+ ((this.pubTime != null) ? this.pubTime.hashCode() : 0);
+ result = (37 * result) +
+ ((this.updateTime != null) ? this.updateTime.hashCode() : 0);
+ result = (37 * result) +
+ ((this.status != null) ? this.status.hashCode() : 0);
+ result = (37 * result) +
+ ((this.plugins != null) ? this.plugins.hashCode() : 0);
+
+ return result;
+ }
+
+ /**
+ * Return RSS 09x style description (escaped HTML version of entry text)
+ *
+ * @roller.wrapPojoMethod type="simple"
+ */
+ public String getRss09xDescription()
+ {
+ return getRss09xDescription(-1);
+ }
+
+ /**
+ * Return RSS 09x style description (escaped HTML version of entry text)
+ *
+ * @roller.wrapPojoMethod type="simple"
+ */
+ public String getRss09xDescription(int maxLength)
+ {
+ String ret = Utilities.escapeHTML(text);
+ if (maxLength != -1 && ret.length() > maxLength)
+ {
+ ret = ret.substring(0,maxLength-3)+"...";
+ }
+ return ret;
+ }
+
+ /** Create anchor for weblog entry, based on title or text */
+ protected String createAnchor() throws RollerException
+ {
+ return RollerFactory.getRoller().getWeblogManager().createAnchor(this);
+ }
+
+ /** Create anchor for weblog entry, based on title or text */
+ public String createAnchorBase()
+ {
+ // Use title or text for base anchor
+ String base = getTitle();
+ if (base == null || base.trim().equals(""))
+ {
+ base = getText();
+ }
+ if (base != null && !base.trim().equals(""))
+ {
+ base = Utilities.replaceNonAlphanumeric(base, ' ');
+
+ // Use only the first 4 words
+ StringTokenizer toker = new StringTokenizer(base);
+ String tmp = null;
+ int count = 0;
+ while (toker.hasMoreTokens() && count < 5)
+ {
+ String s = toker.nextToken();
+ s = s.toLowerCase();
+ tmp = (tmp == null) ? s : tmp + "_" + s;
+ count++;
+ }
+ base = tmp;
+ }
+ // No title or text, so instead we will use the items date
+ // in YYYYMMDD format as the base anchor
+ else
+ {
+ base = DateUtil.format8chars(getPubTime());
+ }
+
+ return base;
+ }
+
+ /**
+ * A no-op.
+ * TODO: fix formbean generation so this is not needed.
+ * @param string
+ */
+ public void setPermaLink(String string)
+ {
+ }
+
+ /**
+ * A no-op.
+ * TODO: fix formbean generation so this is not needed.
+ * @param string
+ */
+ public void setDisplayTitle(String string)
+ {
+ }
+
+ /**
+ * A no-op.
+ * TODO: fix formbean generation so this is not needed.
+ * @param string
+ */
+ public void setRss09xDescription(String string)
+ {
+ }
+
+
+ /**
+ * Convenience method to transform mPlugins to a List
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @return
+ */
+ public List getPluginsList()
+ {
+ if (plugins != null)
+ {
+ return Arrays.asList( StringUtils.split(plugins, ",") );
+ }
+ return new ArrayList();
+ }
+
+ /**
+ * Set creator by user id (for use in form's copyTo method)
+ * @param creatorId
+ */
+ public void setCreatorId(String creatorId) throws RollerException
+ {
+ UserManager umgr = RollerFactory.getRoller().getUserManager();
+ setCreator(umgr.getUser(creatorId));
+ }
+
+ /** Convenience method for checking status */
+ public boolean isDraft()
+ {
+ return status.equals(DRAFT);
+ }
+ /** no-op: needed only to satisfy XDoclet, use setStatus() instead */
+ public void setDraft(boolean value)
+ {
+ }
+
+ /** Convenience method for checking status */
+ public boolean isPending()
+ {
+ return status.equals(PENDING);
+ }
+ /** no-op: needed only to satisfy XDoclet, use setStatus() instead */
+ public void setPending(boolean value)
+ {
+ }
+
+ /** Convenience method for checking status */
+ public boolean isPublished()
+ {
+ return status.equals(PUBLISHED);
+ }
+ /** no-op: needed only to satisfy XDoclet, use setStatus() instead */
+ public void setPublished(boolean value)
+ {
+ }
+
+
+ /**
+ * Determine if the specified user has permissions to edit this entry.
+ */
+ public boolean hasWritePermissions(UserData user) throws RollerException {
+
+ // global admins can hack whatever they want
+ if(user.hasRole("admin")) {
+ return true;
+ }
+
+ boolean author = getWebsite().hasUserPermissions(
+ user, (short)(PermissionsData.AUTHOR));
+ boolean limited = getWebsite().hasUserPermissions(
+ user, (short)(PermissionsData.LIMITED));
+
+ if (author || (limited && isDraft()) || (limited && isPending())) {
+ return true;
+ }
+
+ return false;
+ }
+
+}
Added: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryWrapperComparator.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryWrapperComparator.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryWrapperComparator.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogEntryWrapperComparator.java Mon May 1 15:23:02 2006
@@ -0,0 +1,18 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+
package org.apache.roller.pojos;
import java.io.Serializable;
import java.util.Comparator;
import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
/**
* Sorts WeblogEntryData objects in reverse chronological order
* (most recently published entries first). If they happen to
* have the same pubTime, then sort alphabetically by title.
*
* @author lance.lavandowska
*/
public class WeblogEntryWrapperComparator implements Comparator, Serializable
{
static final long serialVersionUID = -9067148992322255150L;
public int compare(Object val1, Object val2)
throws ClassCastException
{
WeblogEntryDataWrapper entry1 = (WeblogEntryDataWrapper)val1;
WeblogEntryDataWrapper entry2 = (WeblogEntryDataWrapper)val2;
long pubTime1 = entry1.getPubTime().getTime();
long pubTime2 = entry2.getPubTime().getTime();
if (pubTime1 > pubTime2)
{
return -1;
}
else if (pubTime1 < pubTime2)
{
return 1;
}
// if pubTimes are the same, return
// results of String.compareTo() on Title
return entry1.getTitle().compareTo(entry2.getTitle());
}
}
\ No newline at end of file
Added: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTemplate.java Mon May 1 15:23:02 2006
@@ -0,0 +1,341 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.roller.pojos;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.Roller;
+import org.apache.roller.model.RollerFactory;
+
+
+
+/**
+ * Pojo that represents a single user defined template page.
+ *
+ * This template is different from the generic template because it also
+ * contains a reference to the website it is part of.
+ *
+ * @author David M Johnson
+ *
+ * @ejb:bean name="WeblogTemplate"
+ * @struts.form include-all="true"
+ * @hibernate.class lazy="false" table="webpage"
+ * @hibernate.cache usage="read-write"
+ */
+public class WeblogTemplate extends PersistentObject
+ implements Serializable, Template
+{
+ public static final long serialVersionUID = -613737191638263428L;
+
+ public static final String DEFAULT_PAGE = "Weblog";
+
+ private static Set requiredTemplates = null;
+
+ static {
+ requiredTemplates = new HashSet();
+ requiredTemplates.add("Weblog");
+ requiredTemplates.add("_day");
+ requiredTemplates.add("_css");
+ requiredTemplates.add("_decorator");
+ }
+
+ private java.lang.String id;
+ private java.lang.String name;
+ private java.lang.String description;
+ private java.lang.String link;
+ private java.lang.String contents;
+ private java.util.Date lastModified;
+
+ private WebsiteData mWebsite = null;
+
+ public WeblogTemplate()
+ {
+ }
+
+ public WeblogTemplate(
+ java.lang.String id,
+ WebsiteData website,
+ java.lang.String name,
+ java.lang.String description,
+ java.lang.String link,
+ java.lang.String template,
+ java.util.Date updateTime )
+ {
+ this.id = id;
+ this.mWebsite = website;
+ this.name = name;
+ this.description = description;
+ this.link = link;
+ this.contents = template;
+ this.lastModified = (Date)updateTime.clone();
+ }
+
+ public WeblogTemplate( WeblogTemplate otherData )
+ {
+ setData(otherData);
+ }
+
+
+ /**
+ * Determine if this WeblogTemplate is required or not.
+ */
+ public boolean isRequired() {
+ /*
+ * this is kind of hacky right now, but it's like that so we can be
+ * reasonably flexible while we migrate old blogs which may have some
+ * pretty strange customizations.
+ *
+ * my main goal starting now is to prevent further deviations from the
+ * standardized templates as we move forward.
+ *
+ * eventually, the required flag should probably be stored in the db
+ * and possibly applicable to any template.
+ */
+ return (requiredTemplates.contains(this.name) || "Weblog".equals(this.link));
+ }
+
+
+ public void setRequired(boolean req) {
+ // this is an absurd workaround for our struts formbean generation stuff
+ }
+
+
+ /**
+ * @ejb:persistent-field
+ * @hibernate.id column="id"
+ * generator-class="uuid.hex" unsaved-value="null"
+ */
+ public java.lang.String getId()
+ {
+ return this.id;
+ }
+ /** @ejb:persistent-field */
+ public void setId( java.lang.String id )
+ {
+ this.id = id;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
+ */
+ public WebsiteData getWebsite()
+ {
+ return this.mWebsite;
+ }
+ /** @ejb:persistent-field */
+ public void setWebsite( WebsiteData website )
+ {
+ this.mWebsite = website;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @hibernate.property column="name" non-null="true" unique="false"
+ */
+ public java.lang.String getName()
+ {
+ return this.name;
+ }
+ /** @ejb:persistent-field */
+ public void setName( java.lang.String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * Description
+ * @ejb:persistent-field
+ * @hibernate.property column="description" non-null="true" unique="false"
+ */
+ public java.lang.String getDescription()
+ {
+ return this.description;
+ }
+ /** @ejb:persistent-field */
+ public void setDescription( java.lang.String description )
+ {
+ this.description = description;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @hibernate.property column="link" non-null="true" unique="false"
+ */
+ public java.lang.String getLink()
+ {
+ return this.link;
+ }
+ /** @ejb:persistent-field */
+ public void setLink( java.lang.String link )
+ {
+ this.link = link;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @hibernate.property column="template" non-null="true" unique="false"
+ */
+ public java.lang.String getContents()
+ {
+ return this.contents;
+ }
+ /** @ejb:persistent-field */
+ public void setContents( java.lang.String template )
+ {
+ this.contents = template;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @hibernate.property column="updatetime" non-null="true" unique="false"
+ */
+ public java.util.Date getLastModified()
+ {
+ return (Date)this.lastModified.clone();
+ }
+ /** @ejb:persistent-field */
+ public void setLastModified(final java.util.Date newtime )
+ {
+ if (newtime != null)
+ {
+ lastModified = (Date)newtime.clone();
+ }
+ else
+ {
+ lastModified = null;
+ }
+ }
+
+ public String toString()
+ {
+ StringBuffer str = new StringBuffer("{");
+
+ str.append("id=" + id + " " + "name=" + name + " " + "description="
+ + description + " " + "link=" + link + " " + "template=" + contents
+ + " " + "updateTime=" + lastModified);
+ str.append('}');
+
+ return(str.toString());
+ }
+
+ public boolean equals( Object pOther )
+ {
+ if( pOther instanceof WeblogTemplate )
+ {
+ WeblogTemplate lTest = (WeblogTemplate) pOther;
+ boolean lEquals = true;
+
+ if( this.id == null )
+ {
+ lEquals = lEquals && ( lTest.getId() == null );
+ }
+ else
+ {
+ lEquals = lEquals && this.id.equals( lTest.getId() );
+ }
+ if( this.mWebsite == null )
+ {
+ lEquals = lEquals && ( lTest.getWebsite() == null );
+ }
+ else
+ {
+ lEquals = lEquals && this.mWebsite.equals( lTest.getWebsite() );
+ }
+ if( this.name == null )
+ {
+ lEquals = lEquals && ( lTest.getName() == null );
+ }
+ else
+ {
+ lEquals = lEquals && this.name.equals( lTest.getName() );
+ }
+ if( this.description == null )
+ {
+ lEquals = lEquals && ( lTest.getDescription() == null );
+ }
+ else
+ {
+ lEquals = lEquals && this.description.equals( lTest.getDescription() );
+ }
+ if( this.link == null )
+ {
+ lEquals = lEquals && ( lTest.getLink() == null );
+ }
+ else
+ {
+ lEquals = lEquals && this.link.equals( lTest.getLink() );
+ }
+ if( this.contents == null )
+ {
+ lEquals = lEquals && ( lTest.getContents() == null );
+ }
+ else
+ {
+ lEquals = lEquals && this.contents.equals( lTest.getContents() );
+ }
+ if( this.lastModified == null )
+ {
+ lEquals = lEquals && ( lTest.getLastModified() == null );
+ }
+ else
+ {
+ lEquals = lEquals && this.lastModified.equals( lTest.getLastModified() );
+ }
+
+ return lEquals;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ int result = 17;
+ result = 37*result + ((this.id != null) ? this.id.hashCode() : 0);
+ result = 37*result + ((this.mWebsite != null) ? this.mWebsite.hashCode() : 0);
+ result = 37*result + ((this.name != null) ? this.name.hashCode() : 0);
+ result = 37*result + ((this.description != null) ? this.description.hashCode() : 0);
+ result = 37*result + ((this.link != null) ? this.link.hashCode() : 0);
+ result = 37*result + ((this.contents != null) ? this.contents.hashCode() : 0);
+ result = 37*result + ((this.lastModified != null) ? this.lastModified.hashCode() : 0);
+ return result;
+ }
+
+ /**
+ * Setter is needed in RollerImpl.storePersistentObject()
+ */
+ public void setData( org.apache.roller.pojos.PersistentObject otherData )
+ {
+ WeblogTemplate other = (WeblogTemplate)otherData;
+ this.mWebsite = other.getWebsite();
+ this.id = other.getId();
+ this.name = other.getName();
+ this.description = other.getDescription();
+ this.link = other.getLink();
+ this.contents = other.getContents();
+ this.lastModified = other.getLastModified()!=null ? (Date)other.getLastModified().clone() : null;
+ }
+
+
+}
Added: incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java Mon May 1 15:23:02 2006
@@ -0,0 +1,988 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.roller.pojos;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+import org.apache.commons.lang.StringUtils;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.util.PojoUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.ThemeNotFoundException;
+import org.apache.roller.config.RollerRuntimeConfig;
+import org.apache.roller.model.ThemeManager;
+import org.apache.roller.model.UserManager;
+
+
+/**
+ * Website has many-to-many association with users. Website has one-to-many and
+ * one-direction associations with weblog entries, weblog categories, folders and
+ * other objects. Use UserManager to create, fetch, update and retreive websites.
+ *
+ * @author David M Johnson
+ *
+ * @ejb:bean name="WebsiteData"
+ * @struts.form include-all="true"
+ * @hibernate.class lazy="false" table="website"
+ * @hibernate.cache usage="read-write"
+ */
+public class WebsiteData extends org.apache.roller.pojos.PersistentObject
+ implements java.io.Serializable {
+ public static final long serialVersionUID = 206437645033737127L;
+
+ private static Log mLogger = LogFactory.getLog(WebsiteData.class);
+
+ // Simple properties
+ private String id = null;
+ private String handle = null;
+ private String name = null;
+ private String description = null;
+ private String defaultPageId = "dummy";
+ private String weblogDayPageId = "dummy";
+ private Boolean enableBloggerApi = Boolean.TRUE;
+ private String editorPage = null;
+ private String blacklist = null;
+ private Boolean allowComments = Boolean.TRUE;
+ private Boolean emailComments = Boolean.FALSE;
+ private String emailFromAddress = null;
+ private String emailAddress = null;
+ private String editorTheme = null;
+ private String locale = null;
+ private String timeZone = null;
+ private String defaultPlugins = null;
+ private Boolean enabled = Boolean.TRUE;
+ private Boolean active = Boolean.TRUE;
+ private Date dateCreated = new java.util.Date();
+ private Boolean defaultAllowComments = Boolean.TRUE;
+ private int defaultCommentDays = 0;
+ private Boolean moderateComments = Boolean.FALSE;
+ private int entryDisplayCount = 15;
+
+ // Associated objects
+ private UserData creator = null; // TODO: decide if website.user is needed
+ private List permissions = new ArrayList();
+ private WeblogCategoryData bloggerCategory = null;
+ private WeblogCategoryData defaultCategory = null;
+
+ public WebsiteData() {
+ }
+
+ public WebsiteData(
+ String handle,
+ UserData creator,
+ String name,
+ String desc,
+ String email,
+ String emailFrom,
+ String editorTheme,
+ String locale,
+ String timeZone) {
+
+ this.handle = handle;
+ this.creator = creator;
+ this.name = name;
+ this.description = desc;
+ this.emailAddress = email;
+ this.emailFromAddress = emailFrom;
+ this.editorTheme = editorTheme;
+ this.locale = locale;
+ this.timeZone = timeZone;
+ }
+
+ public WebsiteData(WebsiteData otherData) {
+ this.setData(otherData);
+ }
+
+ /**
+ * @hibernate.bag lazy="true" inverse="true" cascade="delete"
+ * @hibernate.collection-key column="website_id"
+ * @hibernate.collection-one-to-many
+ * class="org.apache.roller.pojos.PermissionsData"
+ */
+ public List getPermissions() {
+ return permissions;
+ }
+ public void setPermissions(List perms) {
+ permissions = perms;
+ }
+ /**
+ * Remove permission from collection.
+ */
+ public void removePermission(PermissionsData perms) {
+ permissions.remove(perms);
+ }
+
+ /**
+ * Lookup the default page for this website.
+ */
+ public Template getDefaultPage() throws RollerException {
+
+ Template template = null;
+
+ // first check if this user has selected a theme
+ // if so then return the themes Weblog template
+ if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+ try {
+ ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+ Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+
+ // this is a bit iffy :/
+ // we assume that all theme use "Weblog" for a default template
+ template = usersTheme.getTemplate("Weblog");
+
+ } catch(ThemeNotFoundException tnfe) {
+ // i sure hope not!
+ mLogger.error(tnfe);
+ }
+ }
+
+ // if we didn't get the Template from a theme then look in the db
+ if(template == null) {
+ UserManager userMgr = RollerFactory.getRoller().getUserManager();
+ template = userMgr.getPage(this.defaultPageId);
+ }
+
+ if(template != null)
+ mLogger.debug("returning default template id ["+template.getId()+"]");
+
+ return template;
+ }
+
+
+ /**
+ * Lookup a Template for this website by id.
+ */
+ public Template getPageById(String id) throws RollerException {
+
+ if(id == null)
+ return null;
+
+ Template template = null;
+
+ // first check if this user has selected a theme
+ // if so then return the proper theme template
+ if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+
+ // we don't actually expect to get lookups for theme pages by id
+ // but we have to be thorough and check anyways
+ String[] split = id.split(":", 2);
+
+ // only continue if this looks like a theme id
+ // and the theme name matches this users current theme
+ if(split.length == 2 && split[0].equals(this.editorTheme)) {
+ try {
+ ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+ Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+ template = usersTheme.getTemplate(split[1]);
+
+ } catch(ThemeNotFoundException tnfe) {
+ // i sure hope not!
+ mLogger.error(tnfe);
+ }
+ }
+
+ }
+
+ // if we didn't get the Template from a theme then look in the db
+ if(template == null) {
+ UserManager userMgr = RollerFactory.getRoller().getUserManager();
+ template = userMgr.getPageByName(this, name);
+ }
+
+ return template;
+ }
+
+
+ /**
+ * Lookup a Template for this website by name.
+ */
+ public Template getPageByName(String name) throws RollerException {
+
+ if(name == null)
+ return null;
+
+ mLogger.debug("looking up template ["+name+"]");
+
+ Template template = null;
+
+ // first check if this user has selected a theme
+ // if so then return the proper theme template
+ if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+
+ try {
+ ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+ Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+ template = usersTheme.getTemplate(name);
+
+ } catch(ThemeNotFoundException tnfe) {
+ // i sure hope not!
+ mLogger.error(tnfe);
+ }
+
+ }
+
+ // if we didn't get the Template from a theme then look in the db
+ if(template == null) {
+ UserManager userMgr = RollerFactory.getRoller().getUserManager();
+ template = userMgr.getPageByName(this, name);
+ }
+
+ if(template != null)
+ mLogger.debug("returning template ["+template.getId()+"]");
+
+ return template;
+ }
+
+
+ /**
+ * Lookup a template for this website by link.
+ */
+ public Template getPageByLink(String link) throws RollerException {
+
+ if(link == null)
+ return null;
+
+ mLogger.debug("looking up template ["+link+"]");
+
+ Template template = null;
+
+ // first check if this user has selected a theme
+ // if so then return the proper theme template
+ if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+
+ try {
+ ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+ Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+ template = usersTheme.getTemplateByLink(link);
+
+ } catch(ThemeNotFoundException tnfe) {
+ // i sure hope not!
+ mLogger.error(tnfe);
+ }
+
+ }
+
+ // if we didn't get the Template from a theme then look in the db
+ if(template == null) {
+ UserManager userMgr = RollerFactory.getRoller().getUserManager();
+ template = userMgr.getPageByLink(this, link);
+ }
+
+ if(template != null)
+ mLogger.debug("returning template ["+template.getId()+"]");
+
+ return template;
+ }
+
+
+ /**
+ * Get a list of all pages that are part of this website.
+ */
+ public List getPages() {
+
+ Map pages = new HashMap();
+
+ // first get the pages from the db
+ try {
+ Template template = null;
+ UserManager userMgr = RollerFactory.getRoller().getUserManager();
+ Iterator dbPages = userMgr.getPages(this).iterator();
+ while(dbPages.hasNext()) {
+ template = (Template) dbPages.next();
+ pages.put(template.getName(), template);
+ }
+ } catch(Exception e) {
+ // db error
+ mLogger.error(e);
+ }
+
+
+ // now get theme pages if needed and put them in place of db pages
+ if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+ try {
+ Template template = null;
+ ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+ Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+ Iterator themePages = usersTheme.getTemplates().iterator();
+ while(themePages.hasNext()) {
+ template = (Template) themePages.next();
+
+ // note that this will put theme pages over custom
+ // pages in the pages list, which is what we want
+ pages.put(template.getName(), template);
+ }
+ } catch(Exception e) {
+ // how??
+ mLogger.error(e);
+ }
+ }
+
+ return new ArrayList(pages.values());
+ }
+
+
+ /**
+ * Id of the Website.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.id column="id"
+ * generator-class="uuid.hex" unsaved-value="null"
+ */
+ public String getId() {
+ return this.id;
+ }
+
+ /** @ejb:persistent-field */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Short URL safe string that uniquely identifies the website.
+ * @ejb:persistent-field
+ * @hibernate.property column="handle" non-null="true" unique="true"
+ * @roller.wrapPojoMethod type="simple"
+ */
+ public String getHandle() {
+ return this.handle;
+ }
+
+ /** @ejb:persistent-field */
+ public void setHandle(String handle) {
+ this.handle = handle;
+ }
+
+ /**
+ * Name of the Website.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="name" non-null="true" unique="false"
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /** @ejb:persistent-field */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Description
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="description" non-null="true" unique="false"
+ */
+ public String getDescription() {
+ return this.description;
+ }
+
+ /** @ejb:persistent-field */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Original creator of website
+ *
+ * @roller.wrapPojoMethod type="pojo"
+ * @ejb:persistent-field
+ * @hibernate.many-to-one column="userid" cascade="none" not-null="true"
+ */
+ public org.apache.roller.pojos.UserData getCreator() {
+ return creator;
+ }
+
+ /** @ejb:persistent-field */
+ public void setCreator( org.apache.roller.pojos.UserData ud ) {
+ creator = ud;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="defaultpageid" non-null="true" unique="false"
+ */
+ public String getDefaultPageId() {
+ return this.defaultPageId;
+ }
+
+ /**
+ * @ejb:persistent-field
+ */
+ public void setDefaultPageId(String defaultPageId) {
+ this.defaultPageId = defaultPageId;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @deprecated
+ * @ejb:persistent-field
+ * @hibernate.property column="weblogdayid" non-null="true" unique="false"
+ */
+ public String getWeblogDayPageId() {
+ return this.weblogDayPageId;
+ }
+
+ /**
+ * @deprecated
+ * @ejb:persistent-field
+ */
+ public void setWeblogDayPageId(String weblogDayPageId) {
+ this.weblogDayPageId = weblogDayPageId;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="enablebloggerapi" non-null="true" unique="false"
+ */
+ public Boolean getEnableBloggerApi() {
+ return this.enableBloggerApi;
+ }
+
+ /** @ejb:persistent-field */
+ public void setEnableBloggerApi(Boolean enableBloggerApi) {
+ this.enableBloggerApi = enableBloggerApi;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.many-to-one column="bloggercatid" non-null="false"
+ */
+ public WeblogCategoryData getBloggerCategory() {
+ return bloggerCategory;
+ }
+
+ /** @ejb:persistent-field */
+ public void setBloggerCategory(WeblogCategoryData bloggerCategory) {
+ this.bloggerCategory = bloggerCategory;
+ }
+
+ /**
+ * By default,the default category for a weblog is the root and all macros
+ * work with the top level categories that are immediately under the root.
+ * Setting a different default category allows you to partition your weblog.
+ *
+ * @roller.wrapPojoMethod type="pojo"
+ * @ejb:persistent-field
+ * @hibernate.many-to-one column="defaultcatid" non-null="false"
+ */
+ public WeblogCategoryData getDefaultCategory() {
+ return defaultCategory;
+ }
+
+ /** @ejb:persistent-field */
+ public void setDefaultCategory(WeblogCategoryData defaultCategory) {
+ this.defaultCategory = defaultCategory;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="editorpage" non-null="true" unique="false"
+ */
+ public String getEditorPage() {
+ return this.editorPage;
+ }
+
+ /** @ejb:persistent-field */
+ public void setEditorPage(String editorPage) {
+ this.editorPage = editorPage;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="blacklist" non-null="true" unique="false"
+ */
+ public String getBlacklist() {
+ return this.blacklist;
+ }
+
+ /** @ejb:persistent-field */
+ public void setBlacklist(String blacklist) {
+ this.blacklist = blacklist;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="allowcomments" non-null="true" unique="false"
+ */
+ public Boolean getAllowComments() {
+ return this.allowComments;
+ }
+
+ /** @ejb:persistent-field */
+ public void setAllowComments(Boolean allowComments) {
+ this.allowComments = allowComments;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="defaultallowcomments" non-null="true" unique="false"
+ */
+ public Boolean getDefaultAllowComments() {
+ return defaultAllowComments;
+ }
+
+ /** @ejb:persistent-field */
+ public void setDefaultAllowComments(Boolean defaultAllowComments) {
+ this.defaultAllowComments = defaultAllowComments;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="defaultcommentdays" non-null="true" unique="false"
+ */
+ public int getDefaultCommentDays() {
+ return defaultCommentDays;
+ }
+
+ /** @ejb:persistent-field */
+ public void setDefaultCommentDays(int defaultCommentDays) {
+ this.defaultCommentDays = defaultCommentDays;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="commentmod" non-null="true" unique="false"
+ */
+ public Boolean getModerateComments() {
+ return moderateComments;
+ }
+
+ /** @ejb:persistent-field */
+ public void setModerateComments(Boolean moderateComments) {
+ this.moderateComments = moderateComments;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="emailcomments" non-null="true" unique="false"
+ */
+ public Boolean getEmailComments() {
+ return this.emailComments;
+ }
+
+ /** @ejb:persistent-field */
+ public void setEmailComments(Boolean emailComments) {
+ this.emailComments = emailComments;
+ }
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="emailfromaddress" non-null="true" unique="false"
+ */
+ public String getEmailFromAddress() {
+ return this.emailFromAddress;
+ }
+
+ /** @ejb:persistent-field */
+ public void setEmailFromAddress(String emailFromAddress) {
+ this.emailFromAddress = emailFromAddress;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @roller.wrapPojoMethod type="simple"
+ * @hibernate.property column="emailaddress" non-null="true" unique="false"
+ */
+ public String getEmailAddress() {
+ return this.emailAddress;
+ }
+
+ /** @ejb:persistent-field */
+ public void setEmailAddress(String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+
+ /**
+ * EditorTheme of the Website.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="editortheme" non-null="true" unique="false"
+ */
+ public String getEditorTheme() {
+ return this.editorTheme;
+ }
+
+ /** @ejb:persistent-field */
+ public void setEditorTheme(String editorTheme) {
+ this.editorTheme = editorTheme;
+ }
+
+ /**
+ * Locale of the Website.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="locale" non-null="true" unique="false"
+ */
+ public String getLocale() {
+ return this.locale;
+ }
+
+ /** @ejb:persistent-field */
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * Timezone of the Website.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="timeZone" non-null="true" unique="false"
+ */
+ public String getTimeZone() {
+ return this.timeZone;
+ }
+
+ /** @ejb:persistent-field */
+ public void setTimeZone(String timeZone) {
+ this.timeZone = timeZone;
+ }
+
+ /**
+ * @ejb:persistent-field
+ * @hibernate.property column="datecreated" non-null="true" unique="false"
+ */
+ public Date getDateCreated() {
+ if (dateCreated == null) {
+ return null;
+ } else {
+ return (Date)dateCreated.clone();
+ }
+ }
+ /** @ejb:persistent-field */
+ public void setDateCreated(final Date date) {
+ if (date != null) {
+ dateCreated = (Date)date.clone();
+ } else {
+ dateCreated = null;
+ }
+ }
+
+ /**
+ * Comma-delimited list of user's default Plugins.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="defaultplugins" non-null="false" unique="false"
+ */
+ public String getDefaultPlugins() {
+ return defaultPlugins;
+ }
+
+ /** @ejb:persistent-field */
+ public void setDefaultPlugins(String string) {
+ defaultPlugins = string;
+ }
+
+ public String toString() {
+ StringBuffer str = new StringBuffer("{");
+
+ str.append("id=" + id + " " + "name=" + name + " " + "description=" +
+ description + " " +
+ "defaultPageId=" + defaultPageId + " " +
+ "weblogDayPageId=" + weblogDayPageId + " " +
+ "enableBloggerApi=" + enableBloggerApi + " " +
+ "bloggerCategory=" + bloggerCategory + " " +
+ "defaultCategory=" + defaultCategory + " " +
+ "editorPage=" + editorPage + " " +
+ "blacklist=" + blacklist + " " +
+ "allowComments=" + allowComments + " " +
+ "emailAddress=" + emailAddress + " " +
+ "emailComments=" + emailComments + " " +
+ "emailFromAddress=" + emailFromAddress + " " +
+ "editorTheme=" + editorTheme + " " +
+ "locale=" + locale + " " +
+ "timeZone=" + timeZone + " " +
+ "defaultPlugins=" + defaultPlugins);
+ str.append('}');
+
+ return (str.toString());
+ }
+
+ public boolean equals(Object pOther) {
+ if (pOther instanceof WebsiteData) {
+ WebsiteData lTest = (WebsiteData) pOther;
+ boolean lEquals = true;
+ lEquals = PojoUtil.equals(lEquals, this.getId(), lTest.getId());
+ lEquals = PojoUtil.equals(lEquals, this.getName(), lTest.getName());
+ lEquals = PojoUtil.equals(lEquals, this.getDescription(), lTest.getDescription());
+ lEquals = PojoUtil.equals(lEquals, this.getCreator(), lTest.getCreator());
+ lEquals = PojoUtil.equals(lEquals, this.getDefaultPageId(), lTest.getDefaultPageId());
+ lEquals = PojoUtil.equals(lEquals, this.getWeblogDayPageId(), lTest.getWeblogDayPageId());
+ lEquals = PojoUtil.equals(lEquals, this.getEnableBloggerApi(), lTest.getEnableBloggerApi());
+ lEquals = PojoUtil.equals(lEquals, this.getBloggerCategory(), lTest.getBloggerCategory());
+ lEquals = PojoUtil.equals(lEquals, this.getDefaultCategory(), lTest.getDefaultCategory());
+ lEquals = PojoUtil.equals(lEquals, this.getEditorPage(), lTest.getEditorPage());
+ lEquals = PojoUtil.equals(lEquals, this.getBlacklist(), lTest.getBlacklist());
+ lEquals = PojoUtil.equals(lEquals, this.getAllowComments(), lTest.getAllowComments());
+ lEquals = PojoUtil.equals(lEquals, this.getEmailComments(), lTest.getEmailComments());
+ lEquals = PojoUtil.equals(lEquals, this.getEmailAddress(), lTest.getEmailAddress());
+ lEquals = PojoUtil.equals(lEquals, this.getEmailFromAddress(), lTest.getEmailFromAddress());
+ lEquals = PojoUtil.equals(lEquals, this.getEditorTheme(), lTest.getEditorTheme());
+ lEquals = PojoUtil.equals(lEquals, this.getLocale(), lTest.getLocale());
+ lEquals = PojoUtil.equals(lEquals, this.getTimeZone(), lTest.getTimeZone());
+ lEquals = PojoUtil.equals(lEquals, this.getDefaultPlugins(), lTest.getDefaultPlugins());
+ return lEquals;
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ int result = 17;
+ result = PojoUtil.addHashCode(result, this.id);
+ result = PojoUtil.addHashCode(result, this.name);
+ result = PojoUtil.addHashCode(result, this.description);
+ result = PojoUtil.addHashCode(result, this.creator);
+ result = PojoUtil.addHashCode(result, this.defaultPageId);
+ result = PojoUtil.addHashCode(result, this.weblogDayPageId);
+ result = PojoUtil.addHashCode(result, this.enableBloggerApi);
+ //result = PojoUtil.addHashCode(result, this.bloggerCategory);
+ //result = PojoUtil.addHashCode(result, this.defaultCategory);
+ result = PojoUtil.addHashCode(result, this.editorPage);
+ result = PojoUtil.addHashCode(result, this.blacklist);
+ result = PojoUtil.addHashCode(result, this.allowComments);
+ result = PojoUtil.addHashCode(result, this.emailComments);
+ result = PojoUtil.addHashCode(result, this.emailAddress);
+ result = PojoUtil.addHashCode(result, this.emailFromAddress);
+ result = PojoUtil.addHashCode(result, this.editorTheme);
+ result = PojoUtil.addHashCode(result, this.locale);
+ result = PojoUtil.addHashCode(result, this.timeZone);
+ result = PojoUtil.addHashCode(result, this.defaultPlugins);
+
+ return result;
+ }
+
+ /**
+ * Setter is needed in RollerImpl.storePersistentObject()
+ */
+ public void setData(org.apache.roller.pojos.PersistentObject otherData) {
+ WebsiteData other = (WebsiteData)otherData;
+
+ this.id = other.getId();
+ this.name = other.getName();
+ this.handle = other.getHandle();
+ this.description = other.getDescription();
+ this.creator = other.getCreator();
+ this.defaultPageId = other.getDefaultPageId();
+ this.weblogDayPageId = other.getWeblogDayPageId();
+ this.enableBloggerApi = other.getEnableBloggerApi();
+ this.bloggerCategory = other.getBloggerCategory();
+ this.defaultCategory = other.getDefaultCategory();
+ this.editorPage = other.getEditorPage();
+ this.blacklist = other.getBlacklist();
+ this.allowComments = other.getAllowComments();
+ this.emailComments = other.getEmailComments();
+ this.emailAddress = other.getEmailAddress();
+ this.emailFromAddress = other.getEmailFromAddress();
+ this.editorTheme = other.getEditorTheme();
+ this.locale = other.getLocale();
+ this.timeZone = other.getTimeZone();
+ this.defaultPlugins = other.getDefaultPlugins();
+ this.enabled = other.getEnabled();
+ this.dateCreated = other.getDateCreated();
+ this.entryDisplayCount = other.getEntryDisplayCount();
+ }
+
+ /**
+ * Parse locale value and instantiate a Locale object,
+ * otherwise return default Locale.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @return Locale
+ */
+ public Locale getLocaleInstance() {
+ if (locale != null) {
+ String[] localeStr = StringUtils.split(locale,"_");
+ if (localeStr.length == 1) {
+ if (localeStr[0] == null) localeStr[0] = "";
+ return new Locale(localeStr[0]);
+ } else if (localeStr.length == 2) {
+ if (localeStr[0] == null) localeStr[0] = "";
+ if (localeStr[1] == null) localeStr[1] = "";
+ return new Locale(localeStr[0], localeStr[1]);
+ } else if (localeStr.length == 3) {
+ if (localeStr[0] == null) localeStr[0] = "";
+ if (localeStr[1] == null) localeStr[1] = "";
+ if (localeStr[2] == null) localeStr[2] = "";
+ return new Locale(localeStr[0], localeStr[1], localeStr[2]);
+ }
+ }
+ return Locale.getDefault();
+ }
+
+ /**
+ * Return TimeZone instance for value of timeZone,
+ * otherwise return system default instance.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @return TimeZone
+ */
+ public TimeZone getTimeZoneInstance() {
+ if (timeZone == null) {
+ if (TimeZone.getDefault() != null) {
+ this.setTimeZone( TimeZone.getDefault().getID() );
+ } else {
+ this.setTimeZone("America/New_York");
+ }
+ }
+ return TimeZone.getTimeZone(timeZone);
+ }
+
+
+ /**
+ * Returns true if user has all permissions specified by mask.
+ */
+ public boolean hasUserPermissions(UserData user, short mask) {
+ // look for user in website's permissions
+ PermissionsData userPerms = null;
+ Iterator iter = getPermissions().iterator();
+ while (iter.hasNext()) {
+ PermissionsData perms = (PermissionsData) iter.next();
+ if (perms.getUser().getId().equals(user.getId())) {
+ userPerms = perms;
+ break;
+ }
+ }
+ // if we found one, does it satisfy the mask?
+ if (userPerms != null && !userPerms.isPending()) {
+ if (userPerms != null && (userPerms.getPermissionMask() & mask) == mask) {
+ return true;
+ }
+ }
+ // otherwise, check to see if user is a global admin
+ if (user != null && user.hasRole("admin")) return true;
+ return false;
+ }
+
+ /** Get number of users associated with website */
+ public int getUserCount() {
+ return getPermissions().size();
+ }
+
+ /** No-op needed to please XDoclet generated code */
+ private int userCount = 0;
+ public void setUserCount(int userCount) {
+ // no-op
+ }
+
+ public int getAdminUserCount() {
+ int count = 0;
+ PermissionsData userPerms = null;
+ Iterator iter = getPermissions().iterator();
+ while (iter.hasNext()) {
+ PermissionsData perms = (PermissionsData) iter.next();
+ if (perms.getPermissionMask() == PermissionsData.ADMIN) {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ /** No-op needed to please XDoclet generated code */
+ private int adminUserCount = 0;
+ public void setAdminUserCount(int adminUserCount) {
+ // no-op
+ }
+
+
+ /**
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="displaycnt" not-null="true"
+ */
+ public int getEntryDisplayCount() {
+ return entryDisplayCount;
+ }
+
+ /**
+ * @ejb:persistent-field
+ */
+ public void setEntryDisplayCount(int entryDisplayCount) {
+ this.entryDisplayCount = entryDisplayCount;
+ }
+
+ /**
+ * Set to FALSE to completely disable and hide this weblog from public view.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="isenabled" non-null="true" unique="false"
+ */
+ public Boolean getEnabled() {
+ return this.enabled;
+ }
+
+ /** @ejb:persistent-field */
+ public void setEnabled(Boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ /**
+ * Set to FALSE to exclude this weblog from community areas such as the
+ * front page and the planet page.
+ *
+ * @roller.wrapPojoMethod type="simple"
+ * @ejb:persistent-field
+ * @hibernate.property column="isactive" not-null="true"
+ */
+ public Boolean getActive() {
+ return active;
+ }
+
+ public void setActive(Boolean active) {
+ this.active = active;
+ }
+
+ /**
+ * Returns true if comment moderation is required by website or config.
+ */
+ public boolean getCommentModerationRequired() {
+ return (getModerateComments().booleanValue()
+ || RollerRuntimeConfig.getBooleanProperty("users.moderation.required"));
+ }
+
+ /** No-op */
+ public void setCommentModerationRequired(boolean modRequired) {}
+}
+
Added: incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteDisplayData.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteDisplayData.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteDisplayData.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteDisplayData.java Mon May 1 15:23:02 2006
@@ -0,0 +1,120 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Apr 15, 2003
+ */
+package org.apache.roller.pojos;
+
+
+/**
+ * For most popular website display on Roller main page.
+ * The id property is the website's name.
+ *
+ * @author David M Johnson
+ *
+ * @ejb:bean name="WebsiteDisplayData"
+ * @struts.form include-all="true"
+ */
+public class WebsiteDisplayData extends PersistentObject {
+ static final long serialVersionUID = 5264701383470813687L;
+
+ private String mId;
+ private String mWebsiteName = null;
+ private String mWebsiteHandle = null;
+ private Integer mHits = new Integer(0);
+
+ /**
+ *
+ */
+ public WebsiteDisplayData() {
+ super();
+ }
+
+ /**
+ *
+ */
+ public WebsiteDisplayData(
+ String id,
+ String websiteName,
+ String websiteHandle,
+ Integer hits) {
+ super();
+ mId = id;
+ mWebsiteName = websiteName;
+ mWebsiteHandle = websiteHandle;
+ mHits = hits;
+ }
+
+ /**
+ * No-op.
+ * @see org.apache.roller.pojos.PersistentObject#setData(org.apache.roller.pojos.PersistentObject)
+ */
+ public void setData(PersistentObject vo) {
+ }
+
+ /**
+ * @ejb:persistent-field
+ */
+ public String getId() {
+ return mId;
+ }
+
+ /**
+ * @see org.apache.roller.pojos.PersistentObject#setId(java.lang.String)
+ */
+ public void setId(String id) {
+ mId = id;
+ }
+
+ /**
+ * @ejb:persistent-field
+ */
+ public Integer getHits() {
+ return mHits;
+ }
+
+ /**
+ * @param integer
+ */
+ public void setHits(Integer integer) {
+ mHits = integer;
+ }
+
+
+ /**
+ * @return Returns the title.
+ */
+ public String getWebsiteName() {
+ return mWebsiteName;
+ }
+
+ /**
+ * @param title The title to set.
+ */
+ public void setWebsiteName(String name) {
+ mWebsiteName = name;
+ }
+
+ public String getWebsiteHandle() {
+ return mWebsiteHandle;
+ }
+
+ public void setWebsiteHandle(String mWebsiteHandle) {
+ this.mWebsiteHandle = mWebsiteHandle;
+ }
+}