trackback.java

### File Source: trackback.java

             /*
        P/P   *  Method: net.sourceforge.pebble.domain.TrackBack__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.api.event.trackback.TrackBackEvent;
        35
        36  import java.util.Date;
        37
        38  /**
        39   * Represents a MovableType TrackBack - see
        40   * http://www.movabletype.org/docs/mttrackback.html for more information.
        41   *
        42   * @author    Simon Brown
        43   */
        44  public class TrackBack extends Response {
        45
        46    /** the excerpt */
        47    private String excerpt;
        48
        49    /** the url */
        50    private String url;
        51
        52    /** the blog name */
        53    private String blogName;
        54
        55    /**
        56     * Creates a new TrackBack with the specified properties.
        57     *
        58     * @param title       the title of the entry
        59     * @param excerpt     the excerpt of the entry
        60     * @param url         the url (permalink) of the entry
        61     * @param blogName    the name of the blog
        62     * @param ipAddress   the IP address of the author
        63     * @param date        the date that this TrackBack was left
        64     * @param state       the stats of this TrackBack
        65     * @param blogEntry   the owning blog entry
        66     */
        67    TrackBack(String title, String excerpt, String url, String blogName, String ipAddress, Date date, State state, BlogEntry blogEntry) {
                 /*
        P/P       *  Method: void net.sourceforge.pebble.domain.TrackBack(String, String, String, String, String, Date, State, BlogEntry)
                  *
                  *  Preconditions:
                  *    (soft) blogEntry != null
                  *
                  *  Postconditions:
                  *    this.blogEntry == blogEntry
                  *    (soft) this.blogEntry != null
                  *    this.blogName == One-of{blogName, &""}
                  *    this.blogName != null
                  *    init'ed(this.date)
                  *    this.events == &new ArrayList(Content#1)
                  *    init'ed(this.eventsEnabled)
                  *    this.excerpt == One-of{excerpt, &""}
                  *    this.excerpt != null
                  *    this.ipAddress == One-of{null, ipAddress}
                  *    ...
                  */
        68      super(title, ipAddress, date, state, blogEntry);
        69
        70      setExcerpt(excerpt);
        71      setUrl(url);
        72      setBlogName(blogName);
        73    }
        74
        75    /**
        76     * Gets the title of the blog entry for this trackback.
        77     *
        78     * @return  the title as a String
        79     */
        80    public String getTitle() {
                 /*
        P/P       *  Method: String getTitle()
                  *
                  *  Preconditions:
                  *    init'ed(this.title)
                  *    (soft) init'ed(this.url)
                  *
                  *  Postconditions:
                  *    return_value == One-of{this.title, this.url}
                  *    (soft) init'ed(return_value)
                  *
                  *  Test Vectors:
                  *    this.title: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:length(...)@81: {0}, {1..232-1}
                  */
        81      if (title != null && title.length() > 0) {
        82        return title;
        83      } else {
        84        return url;
        85      }
        86    }
        87
        88    /**
        89     * Gets the excerpt of the blog entry for this trackback.
        90     *
        91     * @return  return the excerpt as a String
        92     */
        93    public String getExcerpt() {
                 /*
        P/P       *  Method: String getExcerpt()
                  *
                  *  Preconditions:
                  *    init'ed(this.excerpt)
                  *
                  *  Postconditions:
                  *    return_value == this.excerpt
                  *    init'ed(return_value)
                  */
        94      return excerpt;
        95    }
        96
        97    /**
        98     * Sets the excerpt of the blog entry for this trackback.
        99     *
       100     * @param   excerpt   the excerpt as a String
       101     */
       102    public void setExcerpt(String excerpt) {
                 /*
        P/P       *  Method: void setExcerpt(String)
                  *
                  *  Postconditions:
                  *    this.excerpt == One-of{excerpt, &""}
                  *    this.excerpt != null
                  *
                  *  Test Vectors:
                  *    excerpt: Addr_Set{null}, Inverse{null}
                  */
       103      if (excerpt != null) {
       104        this.excerpt = excerpt;
       105      } else {
       106        this.excerpt = "";
       107      }
       108    }
       109
       110    /**
       111     * Gets the content of this response.
       112     *
       113     * @return a String
       114     */
       115    public String getContent() {
                 /*
        P/P       *  Method: String getContent()
                  *
                  *  Preconditions:
                  *    init'ed(this.excerpt)
                  *
                  *  Postconditions:
                  *    return_value == this.excerpt
                  *    init'ed(return_value)
                  */
       116      return getExcerpt();
       117    }
       118
       119    /**
       120     * Gets the url (permalink) of the blog entry for this trackback.
       121     *
       122     * @return  return the url as a String
       123     */
       124    public String getUrl() {
                 /*
        P/P       *  Method: String getUrl()
                  *
                  *  Preconditions:
                  *    init'ed(this.url)
                  *
                  *  Postconditions:
                  *    return_value == this.url
                  *    init'ed(return_value)
                  */
       125      return url;
       126    }
       127
       128    /**
       129     * Gets the link to the source of this response.
       130     *
       131     * @return a String
       132     */
       133    public String getSourceLink() {
                 /*
        P/P       *  Method: String getSourceLink()
                  *
                  *  Preconditions:
                  *    init'ed(this.url)
                  *
                  *  Postconditions:
                  *    return_value == this.url
                  *    init'ed(return_value)
                  */
       134      return getUrl();
       135    }
       136
       137    /**
       138     * Sets the url (permalink) of the blog entry for this trackback.
       139     *
       140     * @param url   the url as a String
       141     */
       142    public void setUrl(String url) {
                 /*
        P/P       *  Method: void setUrl(String)
                  *
                  *  Postconditions:
                  *    this.url == url
                  *    init'ed(this.url)
                  */
       143      this.url = url;
       144    }
       145
       146    /**
       147     * Gets the name of the blog for this trackback.
       148     *
       149     * @return  return the name as a String
       150     */
       151    public String getBlogName() {
                 /*
        P/P       *  Method: String getBlogName()
                  *
                  *  Preconditions:
                  *    init'ed(this.blogName)
                  *
                  *  Postconditions:
                  *    return_value == this.blogName
                  *    init'ed(return_value)
                  */
       152      return blogName;
       153    }
       154
       155    /**
       156     * Gets the name of the source of this response.
       157     *
       158     * @return a String
       159     */
       160    public String getSourceName() {
                 /*
        P/P       *  Method: String getSourceName()
                  *
                  *  Preconditions:
                  *    init'ed(this.blogName)
                  *
                  *  Postconditions:
                  *    return_value == this.blogName
                  *    init'ed(return_value)
                  */
       161      return getBlogName();
       162    }
       163
       164    /**
       165     * Sets the name of the blog for this trackback.
       166     *
       167     * @param   blogName    the name as a String
       168     */
       169    public void setBlogName(String blogName) {
                 /*
        P/P       *  Method: void setBlogName(String)
                  *
                  *  Postconditions:
                  *    this.blogName == One-of{blogName, &""}
                  *    this.blogName != null
                  *
                  *  Test Vectors:
                  *    blogName: Addr_Set{null}, Inverse{null}
                  */
       170      if (blogName != null) {
       171        this.blogName = blogName;
       172      } else {
       173        this.blogName = "";
       174      }
       175    }
       176
       177    /**
       178     * Gets the permalink for this TrackBack.
       179     *
       180     * @return  a URL as a String
       181     */
       182    public String getPermalink() {
                 /*
        P/P       *  Method: String getPermalink()
                  *
                  *  Preconditions:
                  *    init'ed(this.blogEntry)
                  *    (soft) init'ed(this.blogEntry.permalink)
                  *    (soft) this.blogEntry.blog != null
                  *    (soft) this.date != null
                  *
                  *  Postconditions:
                  *    return_value != null
                  *
                  *  Preconditions:
                  *    (soft) net/sourceforge/pebble/domain/BlogManager.instance != null
                  *
                  *  Postconditions:
                  *    init'ed(this.blogEntry.permalink)
                  *
                  *  Preconditions:
                  *    (soft) init'ed(net/sourceforge/pebble/domain/BlogManager.instance.multiBlog)
                  *    (soft) init'ed(this.blogEntry.blog.id)
                  *    (soft) this.blogEntry.blog.permalinkProvider != null
                  *
                  *  Test Vectors:
                  *    this.blogEntry: Addr_Set{null}, Inverse{null}
                  */
       183      if (blogEntry != null) {
       184        return blogEntry.getLocalPermalink() + "#trackback" + getId();
       185      } else {
       186        return "";
       187      }
       188    }
       189
       190    /**
       191     * Creates and returns a copy of this object.
       192     *
       193     * @return a clone of this instance.
       194     * @see Cloneable
       195     */
       196    public Object clone() {
                 /*
        P/P       *  Method: Object clone()
                  *
                  *  Preconditions:
                  *    (soft) this.blogEntry != null
                  *
                  *  Postconditions:
                  *    (soft) return_value.blogEntry != null
                  *
                  *  Preconditions:
                  *    init'ed(this.blogName)
                  *    init'ed(this.date)
                  *    init'ed(this.excerpt)
                  *    init'ed(this.ipAddress)
                  *    init'ed(this.state)
                  *    init'ed(this.title)
                  *    init'ed(this.url)
                  *
                  *  Postconditions:
                  *    return_value == &new TrackBack(clone#1)
                  *    new ArrayList(Content#1) num objects == 1
                  *    new ArrayList(Content#3) num objects == 1
                  *    new PropertyChangeSupport(Content#2) num objects == 1
                  *    new TrackBack(clone#1) num objects == 1
                  *    return_value.blogEntry == this.blogEntry
                  *    return_value.blogName == One-of{this.blogName, &""}
                  *    return_value.blogName != null
                  *    init'ed(return_value.date)
                  *    return_value.events == &new ArrayList(Content#1)
                  *    ...
                  */
       197      TrackBack trackBack = new TrackBack(title, excerpt, url, blogName, ipAddress, date, getState(), blogEntry);
       198      return trackBack;
       199    }
       200
       201    /**
       202     * Sets the state of this TrackBack.
       203     */
       204    void setState(State state) {
                 /*
        P/P       *  Method: void setState(State)
                  *
                  *  Preconditions:
                  *    init'ed(this.eventsEnabled)
                  *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
                  *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
                  *    (soft) this.blogEntry != null
                  *    (soft) this.state != null
                  *    (soft) init'ed(this.state.name)
                  *
                  *  Test Vectors:
                  *    this.eventsEnabled: {0}, {1}
                  */
       205      State previousState = getState();
       206      super.setState(state);
       207
       208      if (areEventsEnabled()) {
       209        if (isApproved() && previousState != State.APPROVED) {
       210          blogEntry.addEvent(new TrackBackEvent(this, TrackBackEvent.TRACKBACK_APPROVED));
       211        } else if (isRejected() && previousState != State.REJECTED) {
       212          blogEntry.addEvent(new TrackBackEvent(this, TrackBackEvent.TRACKBACK_REJECTED));
       213        }
       214      }
       215    }
       216
       217  }

SofCheck Inspector Build Version : 2.22510

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