Coverage Report - net.sourceforge.pebble.domain.TrackBack
 
Classes in this File Line Coverage Branch Coverage Complexity
TrackBack
94%
36/38
85%
17/20
1.8
 
 1  
 /*
 2  
  * Copyright (c) 2003-2011, 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) {
 68  308
     super(title, ipAddress, date, state, blogEntry);
 69  
 
 70  308
     setExcerpt(excerpt);
 71  308
     setUrl(url);
 72  308
     setBlogName(blogName);
 73  308
   }
 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() {
 81  268
     if (title != null && title.length() > 0) {
 82  260
       return title;
 83  
     } else {
 84  8
       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() {
 94  180
     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) {
 103  364
     if (excerpt != null) {
 104  360
       this.excerpt = excerpt;
 105  
     } else {
 106  4
       this.excerpt = "";
 107  
     }
 108  364
   }
 109  
 
 110  
   /**
 111  
    * Gets the content of this response.
 112  
    *
 113  
    * @return a String
 114  
    */
 115  
   public String getContent() {
 116  120
     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() {
 125  112
     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() {
 134  92
     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) {
 143  316
     this.url = url;
 144  316
   }
 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() {
 152  172
     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() {
 161  92
     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) {
 170  324
     if (blogName != null) {
 171  320
       this.blogName = blogName;
 172  
     } else {
 173  4
       this.blogName = "";
 174  
     }
 175  324
   }
 176  
 
 177  
   /**
 178  
    * Gets the permalink for this TrackBack.
 179  
    *
 180  
    * @return  a URL as a String
 181  
    */
 182  
   public String getPermalink() {
 183  4
     if (blogEntry != null) {
 184  4
       return blogEntry.getLocalPermalink() + "#trackback" + getId();
 185  
     } else {
 186  0
       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() {
 197  20
     TrackBack trackBack = new TrackBack(title, excerpt, url, blogName, ipAddress, date, getState(), blogEntry);
 198  20
     return trackBack;
 199  
   }
 200  
 
 201  
   /**
 202  
    * Sets the state of this TrackBack.
 203  
    */
 204  
   void setState(State state) {
 205  444
     State previousState = getState();
 206  444
     super.setState(state);
 207  
 
 208  444
     if (areEventsEnabled()) {
 209  20
       if (isApproved() && previousState != State.APPROVED) {
 210  4
         blogEntry.addEvent(new TrackBackEvent(this, TrackBackEvent.TRACKBACK_APPROVED));
 211  16
       } else if (isRejected() && previousState != State.REJECTED) {
 212  4
         blogEntry.addEvent(new TrackBackEvent(this, TrackBackEvent.TRACKBACK_REJECTED));
 213  
       }
 214  
     }
 215  444
   }
 216  
 
 217  
   @Override
 218  
   public boolean isHasEmail() {
 219  0
     return false;
 220  
   }
 221  
 }