View Javadoc

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  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    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      super();
37      setUrl(url);
38      setLength(length);
39      setMimeType(mimeType);
40      setValue(value);
41    }
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      if(_url != null){
49        return new URI(_url.trim());
50      }
51      return null;
52    }
53    
54    /***
55     * Parse length attribute into a {@link Long} and returns it.
56     * @return 
57     */
58    public Long getLengthAsLong() {
59      if(_length != null){
60        return Long.parseLong(_length);
61      }
62      return null;
63    }
64    
65    public String getUrl() {
66      return _url;
67    }
68    public Enclosure setUrl(String url) {
69      _url = url;
70      return this;
71    }
72    public String getLength() {
73      return _length;
74    }
75    public Enclosure setLength(String length) {
76      _length = length;
77      return this;
78    }
79    public String getMimeType() {
80      return _mimeType;
81    }
82    public Enclosure setMimeType(String mimeType) {
83      _mimeType = mimeType;
84      return this;
85    }
86    public String getValue() {
87      return _value;
88    }
89    public Enclosure setValue(String value) {
90      _value = value;
91      return this;
92    }
93    @Override
94    public void validate(FeedFormat format) throws ValidationException {
95      if(format == FeedFormat.ATOM10){
96        return;//no support
97      }
98      ValidationUtils.validateNotNull("Encloure: All fields in the enclosure object should be not null", _length, _mimeType, _url, _value);
99    }
100 }