staticpage.java

### File Source: staticpage.java

             /*
        P/P   *  Method: net.sourceforge.pebble.domain.StaticPage__static_init
              */
         1  /*
         2   * Copyright (c) 2003-2006, Simon Brown
         3   * All rights reserved.
         4   *
         5   * Redistribution and use in source and binary forms, with or without
         6   * modification, are permitted provided that the following conditions are met:
         7   *
         8   *   - Redistributions of source code must retain the above copyright
         9   *     notice, this list of conditions and the following disclaimer.
        10   *
        11   *   - Redistributions in binary form must reproduce the above copyright
        12   *     notice, this list of conditions and the following disclaimer in
        13   *     the documentation and/or other materials provided with the
        14   *     distribution.
        15   *
        16   *   - Neither the name of Pebble nor the names of its contributors may
        17   *     be used to endorse or promote products derived from this software
        18   *     without specific prior written permission.
        19   *
        20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
        24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        30   * POSSIBILITY OF SUCH DAMAGE.
        31   */
        32  package net.sourceforge.pebble.domain;
        33
        34  import net.sourceforge.pebble.util.StringUtils;
        35  import net.sourceforge.pebble.web.validation.ValidationContext;
        36
        37  import java.util.ArrayList;
        38  import java.util.Collections;
        39  import java.util.List;
        40
        41  /**
        42   * Represents a page.
        43   *
        44   * @author Simon Brown
        45   */
        46  public class StaticPage extends PageBasedContent {
        47
        48  	public static final String TEMPLATE_PROPERTY = "template";
        49
        50    /** the name of the page */
        51    private String name;
        52
        53    /** the name of the template **/
        54    private String template = TEMPLATE_PROPERTY;
        55
        56    /**
        57     * Creates a new blog entry.
        58     *
        59     * @param blog    the owning Blog
        60     */
        61    public StaticPage(Blog blog) {
                 /*
        P/P       *  Method: void net.sourceforge.pebble.domain.StaticPage(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)
                  *    ...
                  */
        62      super(blog);
        63      setPublished(true);
        64    }
        65
        66    public String getName() {
                 /*
        P/P       *  Method: String getName()
                  *
                  *  Preconditions:
                  *    init'ed(this.name)
                  *
                  *  Postconditions:
                  *    return_value == this.name
                  *    init'ed(return_value)
                  */
        67      return name;
        68    }
        69
        70    public void setName(String name) {
                 /*
        P/P       *  Method: void setName(String)
                  *
                  *  Postconditions:
                  *    init'ed(this.name)
                  */
        71      this.name = StringUtils.transformHTML(name);
        72    }
        73
        74    /**
        75     * Gets a list of all tags.
        76     *
        77     * @return  a List of tags
        78     */
        79    public List<Tag> getAllTags() {
                 /*
        P/P       *  Method: List getAllTags()
                  *
                  *  Preconditions:
                  *    init'ed(this.tagsAsList)
                  *
                  *  Postconditions:
                  *    return_value == &new ArrayList(getAllTags#1)
                  *    new ArrayList(getAllTags#1) num objects == 1
                  */
        80      List<Tag> list = new ArrayList<Tag>(getTagsAsList());
        81      Collections.sort(list);
        82
        83      return list;
        84    }
        85
        86    /**
        87     * Gets a permalink for this blog entry that is local to the blog. In other
        88     * words, it doesn't take into account the original permalink for
        89     * aggregated content.
        90     *
        91     * @return an absolute URL as a String
        92     */
        93    public String getLocalPermalink() {
                 /*
        P/P       *  Method: String getLocalPermalink()
                  *
                  *  Preconditions:
                  *    this.blog != null
                  *    init'ed(this.name)
                  *
                  *  Postconditions:
                  *    return_value != null
                  *
                  *  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)
                  */
        94      return getBlog().getUrl() + "pages/" + name + ".html";
        95    }
        96
        97    public void validate(ValidationContext context) {
        98  	// TODO: localize
                 /*
        P/P       *  Method: void validate(ValidationContext)
                  *
                  *  Preconditions:
                  *    this.blog != null
                  *    init'ed(this.name)
                  *    (soft) context != null
                  *    (soft) init'ed(this.id)
                  *
                  *  Test Vectors:
                  *    this.name: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:equals(...)@106: {1}, {0}
                  *    java.lang.String:length(...)@99: {1..232-1}, {0}
                  *    java.lang.String:matches(...)@101: {1}, {0}
                  *    java.util.Map:get(...)@208: Addr_Set{null}, Inverse{null}
                  *
                  *  Preconditions:
                  *    this.blog.staticPageIndex != null
                  *    this.blog.staticPageIndex.index != null
                  */
        99      if (name == null || name.length() == 0) {
       100        context.addError("Name cannot be empty");
       101      } else if (!name.matches("[\\w_/-]+")) {
       102        context.addError("Name \"" + StringUtils.transformHTML(name) + "\" must contain only A-Za-z0-9_-/");
       103      }
       104
       105      String id = getBlog().getStaticPageIndex().getStaticPage(name);
       106      if (id != null && !id.equals(getId())) {
       107        context.addError("A page with the name \"" + name + "\" already exists");
       108      }
       109    }
       110
       111    public String getGuid() {
                 /*
        P/P       *  Method: String getGuid()
                  *
                  *  Preconditions:
                  *    this.blog != null
                  *    init'ed(this.id)
                  *
                  *  Postconditions:
                  *    return_value != null
                  *
                  *  Preconditions:
                  *    init'ed(this.blog.id)
                  */
       112      return "page/" + getBlog().getId() + "/" + getId();
       113    }
       114
       115    public void setTemplate(String newTemplate) {
                 /*
        P/P       *  Method: void setTemplate(String)
                  *
                  *  Preconditions:
                  *    init'ed(this.template)
                  *    this.propertyChangeSupport != null
                  *
                  *  Postconditions:
                  *    this.template == newTemplate
                  *    init'ed(this.template)
                  */
       116      propertyChangeSupport.firePropertyChange(TEMPLATE_PROPERTY, template, newTemplate);
       117      this.template = newTemplate;
       118    }
       119
       120    public String getTemplate() {
                 /*
        P/P       *  Method: String getTemplate()
                  *
                  *  Preconditions:
                  *    init'ed(this.template)
                  *
                  *  Postconditions:
                  *    return_value == this.template
                  *    init'ed(return_value)
                  */
       121      return template;
       122    }
       123
       124    /**
       125     * Indicates whether some other object is "equal to" this one.
       126     *
       127     * @param o   the reference object with which to compare.
       128     * @return <code>true</code> if this object is the same as the obj
       129     *         argument; <code>false</code> otherwise.
       130     * @see #hashCode()
       131     * @see java.util.Hashtable
       132     */
       133    public boolean equals(Object o) {
                 /*
        P/P       *  Method: bool equals(Object)
                  *
                  *  Preconditions:
                  *    (soft) o.blog != null
                  *    (soft) init'ed(o.id)
                  *    (soft) this.blog != null
                  *    (soft) init'ed(this.id)
                  *
                  *  Postconditions:
                  *    init'ed(return_value)
                  *
                  *  Test Vectors:
                  *    this == o: {0}, {1}
                  *
                  *  Preconditions:
                  *    (soft) init'ed(o.blog.id)
                  *    (soft) init'ed(this.blog.id)
                  */
       134      if (this == o) {
       135        return true;
       136      }
       137
       138      if (!(o instanceof StaticPage)) {
       139        return false;
       140      }
       141
       142      StaticPage staticPage = (StaticPage)o;
       143      return getGuid().equals(staticPage.getGuid());
       144    }
       145
       146    /**
       147     * Creates and returns a copy of this object.
       148     *
       149     * @return a clone of this instance.
       150     * @see Cloneable
       151     */
       152    public Object clone() {
                 /*
        P/P       *  Method: Object clone()
                  *
                  *  Preconditions:
                  *    init'ed(this.author)
                  *    init'ed(this.blog)
                  *    init'ed(this.body)
                  *    this.date != null
                  *    init'ed(this.lockedBy)
                  *    init'ed(this.name)
                  *    init'ed(this.originalPermalink)
                  *    init'ed(this.persistent)
                  *    init'ed(this.state)
                  *    init'ed(this.subtitle)
                  *    ...
                  *
                  *  Postconditions:
                  *    return_value == &new StaticPage(clone#1)
                  *    new ArrayList(Content#1) num objects == 1
                  *    new ArrayList(Content#3) num objects == 1
                  *    new ArrayList(parse#1) num objects == 1
                  *    new Date(PageBasedContent#2) num objects == 1
                  *    new LinkedList(PageBasedContent#1) num objects == 1
                  *    new PropertyChangeSupport(Content#2) num objects == 1
                  *    new StaticPage(clone#1) num objects == 1
                  *    init'ed(return_value.author)
                  *    return_value.blog == this.blog
                  *    ...
                  */
       153      StaticPage page = new StaticPage(getBlog());
       154      page.setEventsEnabled(false);
       155      page.setPersistent(isPersistent());
       156      page.setTitle(getTitle());
       157      page.setSubtitle(getSubtitle());
       158      page.setBody(getBody());
       159      page.setDate(getDate());
       160      page.setState(getState());
       161      page.setAuthor(getAuthor());
       162      page.setOriginalPermalink(getOriginalPermalink());
       163      page.setName(getName());
       164      page.setTags(getTags());
       165      page.setLockedBy(getLockedBy());
       166      page.setTemplate(getTemplate());
       167
       168      return page;
       169    }
       170
       171  }

SofCheck Inspector Build Version : 2.22510

staticpage.java | 2010-Jun-25 19:40:32
staticpage.class | 2010-Jul-19 20:23:40