File Source: pagebasedcontent.java

     1  package net.sourceforge.pebble.domain;
     2  
     3  import net.sourceforge.pebble.PebbleContext;
     4  import net.sourceforge.pebble.security.PebbleUserDetails;
     5  import net.sourceforge.pebble.security.SecurityRealm;
     6  import net.sourceforge.pebble.security.SecurityRealmException;
     7  import net.sourceforge.pebble.util.StringUtils;
     8  
     9  import org.apache.commons.logging.Log;
    10  import org.apache.commons.logging.LogFactory;
    11  
    12  import java.util.*;
    13  
    14  /**
    15   * The superclass for blog entries and pages.
    16   *
    17   * @author Simon Brown
    18   */
    19  public abstract class PageBasedContent extends Content {
    20  
           /* 
    P/P     *  Method: net.sourceforge.pebble.domain.PageBasedContent__static_init
            * 
            *  Postconditions:
            *    init'ed(log)
            */
    21    private static final Log log = LogFactory.getLog(PageBasedContent.class);
    22  
    23    public static final String TITLE_PROPERTY = "title";
    24    public static final String SUBTITLE_PROPERTY = "subtitle";
    25    public static final String BODY_PROPERTY = "body";
    26    public static final String AUTHOR_PROPERTY = "author";
    27    public static final String DATE_PROPERTY = "date";
    28    public static final String ORIGINAL_PERMALINK_PROPERTY = "originalPermalink";
    29    public static final String TAGS_PROPERTY = "tags";
    30  
    31    /**
    32     * the id
    33     */
    34    private String id;
    35  
    36    /**
    37     * the title
    38     */
    39    private String title = "";
    40  
    41    /**
    42     * the subtitle
    43     */
    44    private String subtitle = "";
    45  
    46    /**
    47     * the body
    48     */
    49    private String body = "";
    50  
    51    /**
    52     * the date that the content was created
    53     */
    54    private Date date;
    55  
    56    /**
    57     * the author of the blog entry
    58     */
    59    private String author = "";
    60  
    61    /** the enriched user details */
    62    private PebbleUserDetails user;
    63  
    64    /**
    65     * the alternative permalink for this blog entry
    66     */
    67    private String originalPermalink;
    68  
    69    /** the list of tags for this blog entry */
    70    private String tags = "";
    71  
    72    /** the List of tags for this blog entry */
    73    private List<Tag> tagsAsList = new LinkedList<Tag>();
    74  
    75    /** the tags, comma separated */
    76    private String tagsAsCommaSeparated = "";
    77  
    78    /** the owning blog */
    79    private Blog blog;
    80  
    81    private boolean persistent = false;
    82    private String lockedBy = null;
    83  
    84    /**
    85     * Creates a new blog entry.
    86     *
    87     * @param blog    the owning Blog
    88     */
           /* 
    P/P     *  Method: void net.sourceforge.pebble.domain.PageBasedContent(Blog)
            * 
            *  Postconditions:
            *    this.author == &""
            *    this.body == &""
            *    this.subtitle == &""
            *    this.tags == &""
            *    this.tagsAsCommaSeparated == &""
            *    this.title == &""
            *    this.blog == blog
            *    init'ed(this.blog)
            *    init'ed(this.date)
            *    this.events == &new ArrayList(Content#1)
            *    ...
            */
    89    public PageBasedContent(Blog blog) {
    90      this.blog = blog;
    91      setDate(new Date());
    92    }
    93  
    94    /**
    95     * Gets the unique id of this blog entry.
    96     *
    97     * @return the id as a String
    98     */
    99    public String getId() {
             /* 
    P/P       *  Method: String getId()
              * 
              *  Preconditions:
              *    init'ed(this.id)
              * 
              *  Postconditions:
              *    return_value == this.id
              *    init'ed(return_value)
              */
   100      return id;
   101    }
   102  
   103    /**
   104     * Gets the title of this blog entry.
   105     *
   106     * @return the title as a String
   107     */
   108    public String getTitle() {
             /* 
    P/P       *  Method: String getTitle()
              * 
              *  Preconditions:
              *    init'ed(this.title)
              * 
              *  Postconditions:
              *    return_value == this.title
              *    init'ed(return_value)
              */
   109      return title;
   110    }
   111  
   112    /**
   113     * Sets the title of this blog entry.
   114     *
   115     * @param newTitle  the title as a String
   116     */
   117    public void setTitle(String newTitle) {
        	 /* 
    P/P 	  *  Method: void setTitle(String)
        	  * 
        	  *  Preconditions:
        	  *    init'ed(this.title)
        	  *    this.propertyChangeSupport != null
        	  * 
        	  *  Postconditions:
        	  *    this.title == newTitle
        	  *    init'ed(this.title)
        	  */
   118  	newTitle = newTitle;
   119      propertyChangeSupport.firePropertyChange(TITLE_PROPERTY, title, newTitle);
   120      this.title = newTitle;
   121    }
   122  
   123    /**
   124     * Gets the subtitle of this blog entry.
   125     *
   126     * @return the subtitle as a String
   127     */
   128    public String getSubtitle() {
             /* 
    P/P       *  Method: String getSubtitle()
              * 
              *  Preconditions:
              *    init'ed(this.subtitle)
              * 
              *  Postconditions:
              *    return_value == this.subtitle
              *    init'ed(return_value)
              */
   129      return subtitle;
   130    }
   131  
   132    /**
   133     * Sets the subtitle of this blog entry.
   134     *
   135     * @param newSubtitle  the subtitle as a String
   136     */
   137    public void setSubtitle(String newSubtitle) {
   138  	//newSubtitle = StringUtils.transformHTML(newSubtitle);
             /* 
    P/P       *  Method: void setSubtitle(String)
              * 
              *  Preconditions:
              *    init'ed(this.subtitle)
              *    this.propertyChangeSupport != null
              * 
              *  Postconditions:
              *    this.subtitle == newSubtitle
              *    init'ed(this.subtitle)
              */
   139      propertyChangeSupport.firePropertyChange(SUBTITLE_PROPERTY, subtitle, newSubtitle);
   140      this.subtitle = newSubtitle;
   141    }
   142  
   143    /**
   144     * Gets the body of this blog entry.
   145     *
   146     * @return the body as a String
   147     */
   148    public String getBody() {
             /* 
    P/P       *  Method: String getBody()
              * 
              *  Preconditions:
              *    init'ed(this.body)
              * 
              *  Postconditions:
              *    return_value == this.body
              *    init'ed(return_value)
              */
   149      return body;
   150    }
   151  
   152    /**
   153     * Gets the content of this response.
   154     *
   155     * @return a String
   156     */
   157    public String getContent() {
             /* 
    P/P       *  Method: String getContent()
              * 
              *  Preconditions:
              *    init'ed(this.body)
              * 
              *  Postconditions:
              *    return_value == this.body
              *    init'ed(return_value)
              */
   158      return body;
   159    }
   160  
   161    /**
   162     * Sets the body of this blog entry.
   163     *
   164     * @param newBody the body as a String
   165     */
   166    public void setBody(String newBody) {
             /* 
    P/P       *  Method: void setBody(String)
              * 
              *  Preconditions:
              *    init'ed(this.body)
              *    this.propertyChangeSupport != null
              * 
              *  Postconditions:
              *    this.body == newBody
              *    init'ed(this.body)
              */
   167      propertyChangeSupport.firePropertyChange(BODY_PROPERTY, body, newBody);
   168      this.body = newBody;
   169    }
   170  
   171    /**
   172     * Gets the date that this blog entry was created.
   173     *
   174     * @return a java.util.Date instance
   175     */
   176    public Date getDate() {
             /* 
    P/P       *  Method: Date getDate()
              * 
              *  Preconditions:
              *    init'ed(this.date)
              * 
              *  Postconditions:
              *    return_value == this.date
              *    init'ed(return_value)
              */
   177      return date;
   178    }
   179  
   180    /**
   181     * Gets the date that this blog entry was last updated.
   182     *
   183     * @return  a Date instance representing the time of the last comment/TrackBack
   184     */
   185    public Date getLastModified() {
             /* 
    P/P       *  Method: Date getLastModified()
              * 
              *  Preconditions:
              *    init'ed(this.date)
              * 
              *  Postconditions:
              *    return_value == this.date
              *    init'ed(return_value)
              */
   186      return date;
   187    }
   188  
   189    /**
   190     * Sets the date that this blog entry was created.
   191     *
   192     * @param newDate a java.util.Date instance
   193     */
   194    public void setDate(Date newDate) {
             /* 
    P/P       *  Method: void setDate(Date)
              * 
              *  Preconditions:
              *    newDate != null
              *    init'ed(this.date)
              *    this.propertyChangeSupport != null
              * 
              *  Postconditions:
              *    this.date == newDate
              *    this.date != null
              *    this.id != null
              */
   195      propertyChangeSupport.firePropertyChange(DATE_PROPERTY, date, newDate);
   196      this.date = newDate;
   197      this.id = "" + this.date.getTime();
   198    }
   199  
   200    /**
   201     * Gets the author of this blog entry.
   202     *
   203     * @return the author as a String
   204     */
   205    public String getAuthor() {
             /* 
    P/P       *  Method: String getAuthor()
              * 
              *  Preconditions:
              *    init'ed(this.author)
              * 
              *  Postconditions:
              *    return_value == this.author
              *    init'ed(return_value)
              */
   206      return author;
   207    }
   208  
   209    /**
   210     * Gets full user details about the author including name, email-address, etc.
   211     *
   212     * @return  a PebbleUserDetails instance
   213     */
   214    public PebbleUserDetails getUser() {
             /* 
    P/P       *  Method: PebbleUserDetails getUser()
              * 
              *  Preconditions:
              *    (soft) init'ed(this.author)
              * 
              *  Presumptions:
              *    net.sourceforge.pebble.PebbleContext:getConfiguration(...).securityRealm@216 != null
              *    net.sourceforge.pebble.PebbleContext:getConfiguration(...)@216 != null
              *    net.sourceforge.pebble.PebbleContext:getInstance(...)@216 != null
              * 
              *  Preconditions:
              *    init'ed(this.user)
              * 
              *  Presumptions:
              *    org.apache.commons.logging.LogFactory:getLog(...)@21 != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              *    this.user == return_value
              * 
              *  Test Vectors:
              *    this.user: Inverse{null}, Addr_Set{null}
              */
   215      if (this.user == null) {
   216        SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
   217        try {
   218          this.user = realm.getUser(getAuthor());
   219        } catch (SecurityRealmException e) {
   220          log.error("Exception encountered", e);
   221        }
   222      }
   223  
   224      return this.user;
   225    }
   226  
   227    /**
   228     * Sets the author of this blog entry.
   229     *
   230     * @param newAuthor the author as a String
   231     */
   232    public void setAuthor(String newAuthor) {
             /* 
    P/P       *  Method: void setAuthor(String)
              * 
              *  Postconditions:
              *    init'ed(this.author)
              */
   233      this.author = StringUtils.transformHTML(newAuthor);
   234    }
   235  
   236    /**
   237     * Gets the tags associated with this category.
   238     *
   239     * @return  a list of tags
   240     */
   241    public String getTags() {
             /* 
    P/P       *  Method: String getTags()
              * 
              *  Preconditions:
              *    init'ed(this.tags)
              * 
              *  Postconditions:
              *    return_value == this.tags
              *    init'ed(return_value)
              */
   242      return this.tags;
   243    }
   244  
   245    /**
   246     * Gets the tags associated with this category, as a List.
   247     *
   248     * @return  a List of tags
   249     */
   250    public List<Tag> getTagsAsList() {
             /* 
    P/P       *  Method: List getTagsAsList()
              * 
              *  Preconditions:
              *    init'ed(this.tagsAsList)
              * 
              *  Postconditions:
              *    return_value == this.tagsAsList
              *    init'ed(return_value)
              */
   251      return this.tagsAsList;
   252    }
   253  
   254    /**
   255     * Gets a list of all tags, as a comma separated string.
   256     *
   257     * @return    a comma separated String of tags
   258     */
   259    public String getTagsAsCommaSeparated() {
             /* 
    P/P       *  Method: String getTagsAsCommaSeparated()
              * 
              *  Preconditions:
              *    init'ed(this.tagsAsCommaSeparated)
              * 
              *  Postconditions:
              *    return_value == this.tagsAsCommaSeparated
              *    init'ed(return_value)
              */
   260      return this.tagsAsCommaSeparated;
   261    }
   262  
   263    /**
   264     * Gets a list of all tags.
   265     *
   266     * @return  a List of tags
   267     */
   268    public abstract List<Tag> getAllTags();
   269  
   270    /**
   271     * Sets the set of tags associated with this category.
   272     *
   273     * @param newTags    a set of tags
   274     */
   275    public void setTags(String newTags) {
             /* 
    P/P       *  Method: void setTags(String)
              * 
              *  Preconditions:
              *    init'ed(this.tags)
              *    init'ed(this.blog)
              *    this.propertyChangeSupport != null
              * 
              *  Postconditions:
              *    init'ed(this.tags)
              *    this.tagsAsCommaSeparated != null
              *    this.tagsAsList == &new ArrayList(parse#1)
              *    new ArrayList(parse#1) num objects == 1
              * 
              *  Test Vectors:
              *    newTags: Addr_Set{null}, Inverse{null}
              *    java.lang.String:indexOf(...)@276: {-231..-1}, {0..232-1}
              */
   276      if (newTags != null && newTags.indexOf(",") > -1) {
   277        // if the tags have been comma separated, convert them to
   278        // whitespace separated by
   279        // - remove whitespace
   280        // - convert commas to whitespace
   281        newTags = newTags.replaceAll(" ", "").replaceAll(",", " ");
   282      }
   283      propertyChangeSupport.firePropertyChange(TAGS_PROPERTY, tags, newTags);
   284      this.tags = newTags;
   285      this.tagsAsList = Tag.parse(getBlog(), tags);
   286      this.tagsAsCommaSeparated = Tag.format(getAllTags());
   287    }
   288  
   289    /**
   290     * Determines whether this blog entry has been aggregated from another
   291     * source. An aggregated blog entry will have a specified permalink.
   292     *
   293     * @return true if this blog entry has been aggegrated, false otherwise
   294     */
   295    public boolean isAggregated() {
             /* 
    P/P       *  Method: bool isAggregated()
              * 
              *  Preconditions:
              *    init'ed(this.originalPermalink)
              * 
              *  Postconditions:
              *    init'ed(return_value)
              * 
              *  Test Vectors:
              *    this.originalPermalink: Addr_Set{null}, Inverse{null}
              */
   296      return (originalPermalink != null);
   297    }
   298  
   299    /**
   300     * Gets the alternative permalink for this blog entry.
   301     *
   302     * @return an absolute URL as a String
   303     */
   304    public String getOriginalPermalink() {
             /* 
    P/P       *  Method: String getOriginalPermalink()
              * 
              *  Preconditions:
              *    init'ed(this.originalPermalink)
              * 
              *  Postconditions:
              *    return_value == this.originalPermalink
              *    init'ed(return_value)
              */
   305      return this.originalPermalink;
   306    }
   307  
   308    /**
   309     * Sets the alternative permalink for this blog entry.
   310     *
   311     * @param newPermalink an absolute URL as a String
   312     */
   313    public void setOriginalPermalink(String newPermalink) {
        	 /* 
    P/P 	  *  Method: void setOriginalPermalink(String)
        	  * 
        	  *  Preconditions:
        	  *    init'ed(this.originalPermalink)
        	  *    this.propertyChangeSupport != null
        	  * 
        	  *  Postconditions:
        	  *    init'ed(this.originalPermalink)
        	  * 
        	  *  Test Vectors:
        	  *    java.lang.String:length(...)@315: {1..232-1}, {0}
        	  *    net.sourceforge.pebble.util.StringUtils:transformHTML(...)@314: Addr_Set{null}, Inverse{null}
        	  */
   314  	newPermalink = StringUtils.transformHTML(newPermalink);
   315      if (newPermalink == null || newPermalink.length() == 0) {
   316        propertyChangeSupport.firePropertyChange(ORIGINAL_PERMALINK_PROPERTY, originalPermalink, null);
   317        this.originalPermalink = null;
   318      } else {
   319        propertyChangeSupport.firePropertyChange(ORIGINAL_PERMALINK_PROPERTY, originalPermalink, newPermalink);
   320        this.originalPermalink = newPermalink;
   321      }
   322    }
   323  
   324    /**
   325     * Gets a permalink for this blog entry.
   326     *
   327     * @return an absolute URL as a String
   328     */
   329    public String getPermalink() {
             /* 
    P/P       *  Method: String getPermalink()
              * 
              *  Preconditions:
              *    (soft) net/sourceforge/pebble/domain/BlogManager.instance != null
              *    (soft) init'ed(net/sourceforge/pebble/domain/BlogManager.instance.multiBlog)
              *    (soft) init'ed(this.blog.id)
              *    init'ed(this.originalPermalink)
              *    (soft) this.blog != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              *    possibly_updated(this.permalink)
              * 
              *  Test Vectors:
              *    this.originalPermalink: Addr_Set{null}, Inverse{null}
              */
   330      if (isAggregated()) {
   331        return getOriginalPermalink();
   332      } else {
   333        return getLocalPermalink();
   334      }
   335    }
   336  
   337    /**
   338     * Gets a permalink for this blog entry that is local to the blog. In other
   339     * words, it doesn't take into account the original permalink for
   340     * aggregated content.
   341     *
   342     * @return an absolute URL as a String
   343     */
   344    public abstract String getLocalPermalink();
   345  
   346    /**
   347     * Helper method to get the owning Blog instance.
   348     *
   349     * @return the overall owning Blog instance
   350     */
   351    public Blog getBlog() {
             /* 
    P/P       *  Method: Blog getBlog()
              * 
              *  Preconditions:
              *    init'ed(this.blog)
              * 
              *  Postconditions:
              *    return_value == this.blog
              *    init'ed(return_value)
              */
   352      return this.blog;
   353    }
   354  
   355    /**
   356     * Gets a string representation of this object.
   357     *
   358     * @return  a String
   359     */
   360    public String toString() {
             /* 
    P/P       *  Method: String toString()
              * 
              *  Preconditions:
              *    init'ed(this.blog.id)
              *    this.blog != null
              *    init'ed(this.title)
              * 
              *  Postconditions:
              *    return_value != null
              */
   361      return getBlog().getId() + "/" + getTitle();
   362    }
   363  
   364    public boolean isPersistent() {
             /* 
    P/P       *  Method: bool isPersistent()
              * 
              *  Preconditions:
              *    init'ed(this.persistent)
              * 
              *  Postconditions:
              *    return_value == this.persistent
              *    init'ed(return_value)
              */
   365      return persistent;
   366    }
   367  
   368    public void setPersistent(boolean persistent) {
             /* 
    P/P       *  Method: void setPersistent(bool)
              * 
              *  Postconditions:
              *    this.persistent == persistent
              *    init'ed(this.persistent)
              */
   369      this.persistent = persistent;
   370    }
   371  
   372    /**
   373     * Determines whether this content is published.
   374     *
   375     * @return  true if the state is published, false otherwise
   376     */
   377    public boolean isPublished() {
             /* 
    P/P       *  Method: bool isPublished()
              * 
              *  Preconditions:
              *    this.state != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name != null
              *    (soft) init'ed(this.state.name)
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   378      return getState().equals(State.PUBLISHED);
   379    }
   380  
   381    /**
   382     * Determines whether this content is unpublished.
   383     *
   384     * @return  true if the state is unpublished, false otherwise
   385     */
   386    public boolean isUnpublished() {
             /* 
    P/P       *  Method: bool isUnpublished()
              * 
              *  Preconditions:
              *    this.state != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#4).name != null
              *    (soft) init'ed(this.state.name)
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   387      return getState().equals(State.UNPUBLISHED);
   388    }
   389  
   390    /**
   391     * Sets the state of this content.
   392     *
   393     * @param published   true if this content is published, false if unpublished
   394     */
   395    public void setPublished(boolean published) {
             /* 
    P/P       *  Method: void setPublished(bool)
              * 
              *  Postconditions:
              *    this.state == One-of{&net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5), old this.state, &net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#4)}
              * 
              *  Test Vectors:
              *    published: {0}, {1}
              */
   396      if (published) {
   397        setState(State.PUBLISHED);
   398      } else {
   399        setState(State.UNPUBLISHED);
   400      }
   401    }
   402  
   403    public String getLockedBy() {
             /* 
    P/P       *  Method: String getLockedBy()
              * 
              *  Preconditions:
              *    init'ed(this.lockedBy)
              * 
              *  Postconditions:
              *    return_value == this.lockedBy
              *    init'ed(return_value)
              */
   404      return lockedBy;
   405    }
   406  
   407    public void setLockedBy(String lockedBy) {
             /* 
    P/P       *  Method: void setLockedBy(String)
              * 
              *  Postconditions:
              *    this.lockedBy == lockedBy
              *    init'ed(this.lockedBy)
              */
   408      this.lockedBy = lockedBy;
   409    }
   410  
   411  }








SofCheck Inspector Build Version : 2.22510
pagebasedcontent.java 2010-Jun-25 19:40:32
pagebasedcontent.class 2010-Jul-19 20:23:40