Coverage Report - yarfraw.core.datamodel.Enclosure
 
Classes in this File Line Coverage Branch Coverage Complexity
Enclosure
70% 
33% 
0
 
 1  
 package yarfraw.core.datamodel;
 2  
 
 3  
 import java.net.URI;
 4  
 import java.net.URISyntaxException;
 5  
 
 6  
 import yarfraw.utils.ValidationUtils;
 7  
 
 8  
 /**
 9  
  * <b>This is only used by Rss 2.0.</b>
 10  
  * <br/>
 11  
  * Describes a media object that is attached to the item.
 12  
  * 
 13  
  * It has three required attributes. url says where the enclosure is located, length says how big it is in bytes, and type says what its type is, a standard MIME type.
 14  
  * <br/>
 15  
  * The url must be an http url.
 16  
  * <br/>
 17  
  * example: &lt;enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />
 18  
  * @author jliang
 19  
  *
 20  
  */
 21  0
 public class Enclosure extends AbstractBaseObject{
 22  
   private static final long serialVersionUID = 20070927L;
 23  
   private String _url;
 24  
   private String _length;
 25  
   private String _mimeType;
 26  
   private String _value;
 27  
   
 28  0
   public Enclosure(){}
 29  
 
 30  
   
 31  
   /**
 32  
    * It has three required attributes. url says where the enclosure is located, length says how big it is in bytes, and type says what its type is, a standard MIME type.
 33  
    * @throws URISyntaxException 
 34  
    */  
 35  
   public Enclosure(String url, String length, String mimeType, String value){
 36  441
     super();
 37  441
     setUrl(url);
 38  441
     setLength(length);
 39  441
     setMimeType(mimeType);
 40  441
     setValue(value);
 41  441
   }
 42  
   /**
 43  
    * Parse field Url to a {@link URI} object and returns it. 
 44  
    * @return field Url as a {@link URI} object.
 45  
    * @throws URISyntaxException
 46  
    */
 47  
   public URI getUrlAsUri() throws URISyntaxException{
 48  0
     if(_url != null){
 49  0
       return new URI(_url.trim());
 50  
     }
 51  0
     return null;
 52  
   }
 53  
   
 54  
   /**
 55  
    * Parse length attribute into a {@link Long} and returns it.
 56  
    * @return 
 57  
    */
 58  
   public Long getLengthAsLong() {
 59  0
     if(_length != null){
 60  0
       return Long.parseLong(_length);
 61  
     }
 62  0
     return null;
 63  
   }
 64  
   
 65  
   public String getUrl() {
 66  3
     return _url;
 67  
   }
 68  
   public Enclosure setUrl(String url) {
 69  441
     _url = url;
 70  441
     return this;
 71  
   }
 72  
   public String getLength() {
 73  3
     return _length;
 74  
   }
 75  
   public Enclosure setLength(String length) {
 76  441
     _length = length;
 77  441
     return this;
 78  
   }
 79  
   public String getMimeType() {
 80  3
     return _mimeType;
 81  
   }
 82  
   public Enclosure setMimeType(String mimeType) {
 83  441
     _mimeType = mimeType;
 84  441
     return this;
 85  
   }
 86  
   public String getValue() {
 87  3
     return _value;
 88  
   }
 89  
   public Enclosure setValue(String value) {
 90  441
     _value = value;
 91  441
     return this;
 92  
   }
 93  
   @Override
 94  
   public void validate(FeedFormat format) throws ValidationException {
 95  3
     if(format == FeedFormat.ATOM10){
 96  0
       return;//no support
 97  
     }
 98  3
     ValidationUtils.validateNotNull("Encloure: All fields in the enclosure object should be not null", _length, _mimeType, _url, _value);
 99  3
   }
 100  
 }