1 package yarfraw.core.datamodel; 2 3 import java.util.Locale; 4 5 import yarfraw.utils.ValidationUtils; 6 7 8 /*** 9 * <li>Rss 2.0 and Rss 1.0 - the <link> element. The href field will be used as the text 10 * content of the <link> element. 11 * </li> 12 * <li>Atom 1.0 - 13 * The "atom:link" element defines a reference from an entry or feed to a Web resource. 14 * This specification assigns no meaning to the content (if any) of this element. 15 * <br/> 16 * Please note that in an Atom feed, there is no elements for 'enclosure' (@see {@link Enclosure}) objects. 17 * You can, however, add enclosure object to an Atom feed using this class. 18 * </li> 19 * @author jliang 20 * 21 */ 22 public class Link extends AbstractBaseObject{ 23 private static final long serialVersionUID = 20070927L; 24 private String _href; 25 private String _rel; 26 private String _type; 27 private String _hreflang; 28 private String _title; 29 private Integer _length; 30 31 public Link(){} 32 33 public Link(String href) { 34 _href = href; 35 } 36 public Link(String href, String rel, String type, String hreflang, 37 String title, Integer length) { 38 super(); 39 _href = href; 40 _rel = rel; 41 _type = type; 42 _hreflang = hreflang; 43 _title = title; 44 _length = length; 45 } 46 47 /*** 48 * <li>Rss 1.0 & Rss 2.0 - text content of the <link> element </li> 49 * <li>Atom 1.0 - 50 * The "href" attribute contains the link's IRI. atom:link elements MUST have a href attribute, whose value MUST be a IRI reference [RFC3987]. 51 * </li> 52 */ 53 public String getHref() { 54 return _href; 55 } 56 /*** 57 * <li>Rss 1.0 & Rss 2.0 - text content of the <link> element </li> 58 * <li>Atom 1.0 - 59 * The "href" attribute contains the link's IRI. atom:link elements MUST have a href attribute, whose value MUST be a IRI reference [RFC3987]. 60 * </li> 61 */ 62 public Link setHref(String href) { 63 _href = href; 64 return this; 65 } 66 /*** 67 * <b>Atom 1.0 only </b> <br/> 68 * atom:link elements MAY have a "rel" attribute that indicates the link relation type. If the "rel" attribute is not present, the link element MUST be interpreted as if the link relation type is "alternate". 69 */ 70 public String getRel() { 71 return _rel; 72 } 73 /*** 74 * <b>Atom 1.0 only </b> <br/> 75 * atom:link elements MAY have a "rel" attribute that indicates the link relation type. If the "rel" attribute is not present, the link element MUST be interpreted as if the link relation type is "alternate". 76 */ 77 public Link setRel(String rel) { 78 _rel = rel; 79 return this; 80 } 81 /*** 82 * <b>Atom 1.0 only </b> <br/> 83 * On the link element, the "type" attribute's value is an advisory media type; it is a hint about the type of the representation that is expected to be returned when the value of the href attribute is dereferenced. Note that the type attribute does not override the actual media type returned with the representation. Link elements MAY have a type attribute, whose value MUST conform to the syntax of a MIME media type [MIMEREG]. 84 */ 85 public String getType() { 86 return _type; 87 } 88 /*** 89 * <b>Atom 1.0 only </b> <br/> 90 * On the link element, the "type" attribute's value is an advisory media type; it is a hint about the type of the representation that is expected to be returned when the value of the href attribute is dereferenced. Note that the type attribute does not override the actual media type returned with the representation. Link elements MAY have a type attribute, whose value MUST conform to the syntax of a MIME media type [MIMEREG]. 91 */ 92 public Link setType(String type) { 93 _type = type; 94 return this; 95 } 96 /*** 97 * <b>Atom 1.0 only </b> <br/> 98 * The "hreflang" attribute's content describes the language of the resource pointed to by the href attribute. When used together with the rel="alternate", it implies a translated version of the entry. Link elements MAY have an hreflang attribute, whose value MUST be a language tag [RFC3066]. 99 */ 100 public String getHreflang() { 101 return _hreflang; 102 } 103 /*** 104 * <b>Atom 1.0 only </b> <br/> 105 * The "hreflang" attribute's content describes the language of the resource pointed to by the href attribute. When used together with the rel="alternate", it implies a translated version of the entry. Link elements MAY have an hreflang attribute, whose value MUST be a language tag [RFC3066]. 106 */ 107 public Link setHreflang(String hreflang) { 108 _hreflang = hreflang; 109 return this; 110 } 111 112 /*** 113 * <b>Atom 1.0 only </b> <br/> 114 * The "hreflang" attribute's content describes the language of the resource pointed to by the href attribute. When used together with the rel="alternate", it implies a translated version of the entry. Link elements MAY have an hreflang attribute, whose value MUST be a language tag [RFC3066]. 115 */ 116 public Link setHreflang(Locale hreflang) { 117 _hreflang = hreflang.getLanguage(); 118 return this; 119 } 120 /*** 121 * <b>Atom 1.0 only </b> <br/> 122 * The "title" attribute conveys human-readable information about the link. The content of the "title" attribute is Language-Sensitive. Link elements MAY have a title attribute. 123 */ 124 public String getTitle() { 125 return _title; 126 } 127 /*** 128 * <b>Atom 1.0 only </b> <br/> 129 * The "title" attribute conveys human-readable information about the link. The content of the "title" attribute is Language-Sensitive. Link elements MAY have a title attribute. 130 */ 131 public Link setTitle(String title) { 132 _title = title; 133 return this; 134 } 135 /*** 136 * <b>Atom 1.0 only </b> <br/> 137 * The "length" attribute indicates an advisory length of the linked content in octets; it is a hint about the content length of the representation returned when the IRI in the href attribute is mapped to a URI and dereferenced. Note that the length attribute does not override the actual content length of the representation as reported by the underlying protocol. Link elements MAY have a length attribute. 138 */ 139 public Integer getLength() { 140 return _length; 141 } 142 /*** 143 * <b>Atom 1.0 only </b> <br/> 144 * The "length" attribute indicates an advisory length of the linked content in octets; it is a hint about the content length of the representation returned when the IRI in the href attribute is mapped to a URI and dereferenced. Note that the length attribute does not override the actual content length of the representation as reported by the underlying protocol. Link elements MAY have a length attribute. 145 */ 146 public Link setLength(Integer length) { 147 _length = length; 148 return this; 149 } 150 151 152 /*** 153 * <b>Atom 1.0 only</b><br/> 154 * Any element defined by this specification MAY have an xml:base attribute 155 * [W3C.REC-xmlbase-20010627]. When xml:base is used in an Atom Document, 156 * it serves the function described in section 5.1.1 of [RFC3986], establishing 157 * the base URI (or IRI) for resolving any relative references found within the 158 * effective scope of the xml:base attribute. 159 * @param base 160 * @return 161 */ 162 public Link setBase(String base) { 163 _base = base; 164 return this; 165 } 166 167 /*** 168 * <li>Rss 2.0 - <language> element. 169 * The language the channel is written in. This allows aggregators to group 170 * all Italian language sites, for example, on a single page. A list of allowable 171 * values for this element, as provided by Netscape, is here. You may also use values 172 * defined by the W3C. 173 * Only <channel> support this element.</li> 174 * <li>Rss 1.0 - <dc:language> element. A language of the intellectual content of the resource. 175 * Only <channel> and <item> support this element. </li> 176 * <li>Atom 1.0 - 'lang' attribute</li> 177 * <br/> 178 * Note: for Rss 2.0 and Rss 1.0, only <channel> and <item> 179 * @param lang 180 * @return 181 */ 182 public Link setLang(Locale lang) { 183 _lang = lang.getLanguage(); 184 return this; 185 } 186 /*** 187 * <li>Rss 2.0 - <language> element. 188 * The language the channel is written in. This allows aggregators to group 189 * all Italian language sites, for example, on a single page. A list of allowable 190 * values for this element, as provided by Netscape, is here. You may also use values 191 * defined by the W3C. 192 * Only <channel> support this element.</li> 193 * <li>Rss 1.0 - <dc:language> element. A language of the intellectual content of the resource. 194 * Only <channel> and <item> support this element. </li> 195 * <li>Atom 1.0 - 'lang' attribute</li> 196 * <br/> 197 * Note: for Rss 2.0 and Rss 1.0, only <channel> and <item> 198 * @param lang 199 * @return 200 */ 201 public Link setLang(String lang) { 202 _lang = lang; 203 return this; 204 } 205 206 @Override 207 public void validate(FeedFormat format) throws ValidationException { 208 ValidationUtils.validateNotNull("href is required", _href); 209 ValidationUtils.validateUri("href should be an valid uri", _href); 210 } 211 }