File Source: content.java

         /* 
    P/P   *  Method: void net.sourceforge.pebble.domain.Content$1(Content)
          */
     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.PebbleEvent;
    35  import net.sourceforge.pebble.util.StringUtils;
    36  
    37  import java.beans.PropertyChangeEvent;
    38  import java.beans.PropertyChangeListener;
    39  import java.beans.PropertyChangeSupport;
    40  import java.io.Serializable;
    41  import java.util.ArrayList;
    42  import java.util.List;
    43  
    44  /**
    45   * Superclass for blog entries, comments and TrackBacks.
    46   *
    47   * @author    Simon Brown
    48   */
    49  public abstract class Content implements Permalinkable, Cloneable, Serializable {
    50  
    51    /** the state of the object */
    52    private State state;
    53  
    54    /** flag to indicate whether events are enabled */
    55    private boolean eventsEnabled = false;
    56  
    57    /** the class responsible for managing property change events */
    58    protected transient PropertyChangeSupport propertyChangeSupport;
    59  
    60    /** the collection of properties that have changed since the last store */
           /* 
    P/P     *  Method: ArrayList access$0(Content)
            * 
            *  Preconditions:
            *    Param_0 != null
            *    init'ed(Param_0.propertyChangeEvents)
            * 
            *  Postconditions:
            *    return_value == Param_0.propertyChangeEvents
            *    init'ed(return_value)
            */
    61    private transient ArrayList propertyChangeEvents;
    62  
    63    /** the collection of PebbleEvent instances that have been initiated */
    64    private transient List<PebbleEvent> events = new ArrayList<PebbleEvent>();
    65  
    66    /**
    67     * Default, no args constructor.
    68     */
           /* 
    P/P     *  Method: void net.sourceforge.pebble.domain.Content()
            * 
            *  Postconditions:
            *    this.events == &new ArrayList(Content#1)
            *    init'ed(this.eventsEnabled)
            *    this.propertyChangeEvents == &new ArrayList(Content#3)
            *    this.propertyChangeSupport == &new PropertyChangeSupport(Content#2)
            *    new ArrayList(Content#1) num objects == 1
            *    new ArrayList(Content#3) num objects == 1
            *    new PropertyChangeSupport(Content#2) num objects == 1
            */
    69    public Content() {
    70      this.propertyChangeSupport = new PropertyChangeSupport(this);
    71      this.propertyChangeEvents = new ArrayList();
    72      this.propertyChangeSupport.addPropertyChangeListener(new PropertyChangeListener() {
    73        public void propertyChange(PropertyChangeEvent event) {
                 /* 
    P/P           *  Method: void propertyChange(PropertyChangeEvent)
                  * 
                  *  Preconditions:
                  *    init'ed(this.eventsEnabled)
                  *    (soft) event != null
                  *    (soft) this.propertyChangeEvents != null
                  * 
                  *  Test Vectors:
                  *    this.eventsEnabled: {0}, {1}
                  *    java.beans.PropertyChangeEvent:getNewValue(...)@76: Addr_Set{null}, Inverse{null}
                  *    java.beans.PropertyChangeEvent:getOldValue(...)@75: Addr_Set{null}, Inverse{null}
                  *    java.lang.Object:equals(...)@78: {0}, {1}
                  */
    74          if (areEventsEnabled()) {
    75            Object oldValue = event.getOldValue();
    76            Object newValue = event.getNewValue();
    77            if ((oldValue == null && newValue == null) ||
    78                (oldValue != null && newValue != null && oldValue.equals(newValue))) {
    79              return;
    80            } else {
    81              Content.this.propertyChangeEvents.add(event);
    82            }
    83          }
    84        }
    85      });
    86    }
    87  
    88    /**
    89     * Gets the content of this response.
    90     *
    91     * @return  a String
    92     */
    93    public abstract String getContent();
    94  
    95    /**
    96     * Gets the content of this response, truncated and without HTML tags.
    97     *
    98     * @return    the content of this response as a String
    99     */
   100    public String getTruncatedContent() {
             /* 
    P/P       *  Method: String getTruncatedContent()
              * 
              *  Preconditions:
              *    (soft) init'ed(this.body)
              *    (soft) init'ed(this.excerpt)
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   101      return StringUtils.truncate(getContent());
   102    }
   103  
   104    /**
   105     * Gets the state of this comment.
   106     *
   107     * @return  a State instance (APPROVED, REJECTED or PENDING)
   108     */
   109    public State getState() {
             /* 
    P/P       *  Method: State getState()
              * 
              *  Preconditions:
              *    init'ed(this.state)
              * 
              *  Postconditions:
              *    return_value == this.state
              *    init'ed(return_value)
              */
   110      return this.state;
   111    }
   112  
   113    /**
   114     * Sets the state of this comment.
   115     */
   116    void setState(State state) {
             /* 
    P/P       *  Method: void setState(State)
              * 
              *  Postconditions:
              *    this.state == state
              *    init'ed(this.state)
              */
   117      this.state = state;
   118    }
   119  
   120    /**
   121     * Sets whether events are enabled.
   122     *
   123     * @param b   true to enable events, false otherwise
   124     */
   125    void setEventsEnabled(boolean b) {
             /* 
    P/P       *  Method: void setEventsEnabled(bool)
              * 
              *  Postconditions:
              *    this.eventsEnabled == b
              *    init'ed(this.eventsEnabled)
              */
   126      this.eventsEnabled = b;
   127    }
   128  
   129    /**
   130     * Determines whether events are enabled.
   131     *
   132     * @return  true if events are enabled, false otherwise
   133     */
   134    boolean areEventsEnabled() {
             /* 
    P/P       *  Method: bool areEventsEnabled()
              * 
              *  Preconditions:
              *    init'ed(this.eventsEnabled)
              * 
              *  Postconditions:
              *    return_value == this.eventsEnabled
              *    init'ed(return_value)
              */
   135      return this.eventsEnabled;
   136    }
   137  
   138    /**
   139     * Clears existing property change events.
   140     */
   141    public void clearPropertyChangeEvents() {
             /* 
    P/P       *  Method: void clearPropertyChangeEvents()
              * 
              *  Postconditions:
              *    this.propertyChangeEvents == &new ArrayList(clearPropertyChangeEvents#1)
              *    new ArrayList(clearPropertyChangeEvents#1) num objects == 1
              */
   142      this.propertyChangeEvents = new ArrayList();
   143    }
   144  
   145    /**
   146     * Determines whether this class has had properties changed since it
   147     * was last persisted.
   148     *
   149     * @return  true if properties have changed, false otherwise
   150     */
   151    public boolean isDirty() {
             /* 
    P/P       *  Method: bool isDirty()
              * 
              *  Preconditions:
              *    this.propertyChangeEvents != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   152      return !propertyChangeEvents.isEmpty();
   153    }
   154  
   155    /**
   156     * Gets the list of property change events.
   157     *
   158     * @return  a List of PropertyChangeEvent instances
   159     */
   160    public List getPropertyChangeEvents() {
             /* 
    P/P       *  Method: List getPropertyChangeEvents()
              * 
              *  Preconditions:
              *    this.propertyChangeEvents != null
              * 
              *  Postconditions:
              *    return_value != null
              */
   161      return (List)propertyChangeEvents.clone();
   162    }
   163  
   164    /**
   165     * Adds an event to the list.
   166     *
   167     * @param event   a PebbleEvent instance
   168     */
   169    synchronized void addEvent(PebbleEvent event) {
             /* 
    P/P       *  Method: void addEvent(PebbleEvent)
              * 
              *  Preconditions:
              *    this.events != null
              */
   170      events.add(event);
   171    }
   172  
   173    /**
   174     * Inserts an event to the list into the front of the list.
   175     *
   176     * @param event   a PebbleEvent instance
   177     */
   178    synchronized void insertEvent(PebbleEvent event) {
             /* 
    P/P       *  Method: void insertEvent(PebbleEvent)
              * 
              *  Preconditions:
              *    this.events != null
              */
   179      events.add(0, event);
   180    }
   181  
   182    /**
   183     * Determines whether this object has outstanding events.
   184     *
   185     * @return    true if events are outstanding, false otherwise
   186     */
   187    public synchronized boolean hasEvents() {
             /* 
    P/P       *  Method: bool hasEvents()
              * 
              *  Preconditions:
              *    this.events != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   188      return !events.isEmpty();
   189    }
   190  
   191    /**
   192     * Gets the next event to be handled.
   193     *
   194     * @return  a PebbleEvent instance, or null if no more events
   195     */
   196    public synchronized PebbleEvent nextEvent() {
             /* 
    P/P       *  Method: PebbleEvent nextEvent()
              * 
              *  Preconditions:
              *    this.events != null
              * 
              *  Postconditions:
              *    init'ed(return_value)
              */
   197      if (hasEvents()) {
   198        return events.remove(0);
   199      } else {
   200        return null;
   201      }
   202    }
   203  
   204    synchronized void clearEvents() {
             /* 
    P/P       *  Method: void clearEvents()
              * 
              *  Postconditions:
              *    this.events == &new ArrayList(clearEvents#1)
              *    new ArrayList(clearEvents#1) num objects == 1
              */
   205      events = new ArrayList<PebbleEvent>();
   206    }
   207  
   208    public synchronized List<PebbleEvent> getEvents() {
             /* 
    P/P       *  Method: List getEvents()
              * 
              *  Preconditions:
              *    init'ed(this.events)
              * 
              *  Postconditions:
              *    return_value == &new ArrayList(getEvents#1)
              *    new ArrayList(getEvents#1) num objects == 1
              */
   209      return new ArrayList<PebbleEvent>(events);
   210    }
   211  
   212  }








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