| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| Generator |
|
| 0.0;0 |
| 1 | package yarfraw.core.datamodel; |
|
| 2 | ||
| 3 | import java.util.HashMap; |
|
| 4 | import java.util.Locale; |
|
| 5 | import java.util.Map; |
|
| 6 | ||
| 7 | import javax.xml.namespace.QName; |
|
| 8 | ||
| 9 | import yarfraw.utils.ValidationUtils; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * <li>Rss 1.0 - Not supported, this is ignored.</li> |
|
| 13 | * <li>Rss 2.0 - <generator> A string indicating the program used to generate the channel. |
|
| 14 | * </li> |
|
| 15 | * <li>Atom 1.0 - <generator> |
|
| 16 | * The "atom:generator" element's content identifies the agent used to generate a feed, for debugging and other purposes. |
|
| 17 | * </li> |
|
| 18 | * @author jliang |
|
| 19 | * |
|
| 20 | */ |
|
| 21 | 99 | public class Generator extends AbstractBaseObject{ |
| 22 | private static final long serialVersionUID = 20070927L; |
|
| 23 | private String _value; |
|
| 24 | private String _uri; |
|
| 25 | private String _version; |
|
| 26 | ||
| 27 | 168 | public Generator(String generatorValue){ |
| 28 | 168 | _value = generatorValue; |
| 29 | 168 | } |
| 30 | /** |
|
| 31 | * <li>Rss 1.0 - Not supported.</li> |
|
| 32 | * <li>Rss 2.0 - the text content of the <generator> |
|
| 33 | * </li> |
|
| 34 | * <li>Atom 1.0 - |
|
| 35 | * The content of this element, when present, MUST be a string that is a |
|
| 36 | * human-readable name for the generating agent. The escaped versions of |
|
| 37 | * characters such as "&" and ">" represent those characters, not markup. |
|
| 38 | * </li> |
|
| 39 | * @return |
|
| 40 | */ |
|
| 41 | public String getValue() { |
|
| 42 | 36 | return _value; |
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * <li>Rss 1.0 - Not supported.</li> |
|
| 47 | * <li>Rss 2.0 - the text content of the <generator> |
|
| 48 | * </li> |
|
| 49 | * <li>Atom 1.0 - |
|
| 50 | * The content of this element, when present, MUST be a string that is a |
|
| 51 | * human-readable name for the generating agent. The escaped versions of |
|
| 52 | * characters such as "&" and ">" represent those characters, not markup. |
|
| 53 | * </li> |
|
| 54 | * @param value |
|
| 55 | */ |
|
| 56 | public Generator setValue(String value) { |
|
| 57 | 0 | _value = value; |
| 58 | 0 | return this; |
| 59 | } |
|
| 60 | ||
| 61 | ||
| 62 | /** |
|
| 63 | * <li>Rss 1.0 - Not supported.</li> |
|
| 64 | * <li>Rss 2.0 - - Not supported. |
|
| 65 | * </li> |
|
| 66 | * <li>Atom 1.0 - |
|
| 67 | * The atom:generator element MAY have a "uri" attribute whose value MUST be |
|
| 68 | * an IRI reference [RFC3987]. When dereferenced, the resulting URI |
|
| 69 | * (mapped from an IRI, if necessary) SHOULD produce a representation that is relevant to that agent. |
|
| 70 | * </li> |
|
| 71 | * @return |
|
| 72 | */ |
|
| 73 | public String getUri() { |
|
| 74 | 12 | return _uri; |
| 75 | } |
|
| 76 | ||
| 77 | /** |
|
| 78 | * <li>Rss 1.0 - Not supported.</li> |
|
| 79 | * <li>Rss 2.0 - - Not supported. |
|
| 80 | * </li> |
|
| 81 | * <li>Atom 1.0 - |
|
| 82 | * The atom:generator element MAY have a "uri" attribute whose value MUST be |
|
| 83 | * an IRI reference [RFC3987]. When dereferenced, the resulting URI |
|
| 84 | * (mapped from an IRI, if necessary) SHOULD produce a representation that is relevant to that agent. |
|
| 85 | * </li> |
|
| 86 | * @param uri |
|
| 87 | * @return |
|
| 88 | */ |
|
| 89 | public Generator setUri(String uri) { |
|
| 90 | 36 | _uri = uri; |
| 91 | 36 | return this; |
| 92 | } |
|
| 93 | ||
| 94 | ||
| 95 | /** |
|
| 96 | * <li>Rss 1.0 - Not supported.</li> |
|
| 97 | * <li>Rss 2.0 - - Not supported. |
|
| 98 | * </li> |
|
| 99 | * <li>Atom 1.0 - |
|
| 100 | * The atom:generator element MAY have a "version" attribute that indicates the version of the generating agent. |
|
| 101 | * </li> |
|
| 102 | * @return |
|
| 103 | */ |
|
| 104 | public String getVersion() { |
|
| 105 | 12 | return _version; |
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * <li>Rss 1.0 - Not supported.</li> |
|
| 110 | * <li>Rss 2.0 - - Not supported. |
|
| 111 | * </li> |
|
| 112 | * <li>Atom 1.0 - |
|
| 113 | * The atom:generator element MAY have a "version" attribute that indicates the version of the generating agent. |
|
| 114 | * </li> |
|
| 115 | * @param version |
|
| 116 | */ |
|
| 117 | public Generator setVersion(String version) { |
|
| 118 | 36 | _version = version; |
| 119 | 36 | return this; |
| 120 | } |
|
| 121 | ////////////////////////Common setters/////////////////////// |
|
| 122 | /** |
|
| 123 | * Any other attribute that is not in the RSS 2.0 specs. |
|
| 124 | */ |
|
| 125 | public Generator setOtherAttributes(Map<QName, String> otherAttributes) { |
|
| 126 | 6 | _otherAttributes = otherAttributes; |
| 127 | 6 | return this; |
| 128 | } |
|
| 129 | /** |
|
| 130 | * Add an attribute that is not in the RSS 2.0 specs. |
|
| 131 | */ |
|
| 132 | public Generator addOtherAttributes(QName namespace, String attribute) { |
|
| 133 | 6 | if(_otherAttributes == null){ |
| 134 | 3 | _otherAttributes = new HashMap<QName, String>(); |
| 135 | } |
|
| 136 | 6 | _otherAttributes.put(namespace, attribute); |
| 137 | 6 | return this; |
| 138 | } |
|
| 139 | ||
| 140 | ||
| 141 | /** |
|
| 142 | * <b>Atom 1.0 only</b><br/> |
|
| 143 | * Any element defined by this specification MAY have an xml:base attribute |
|
| 144 | * [W3C.REC-xmlbase-20010627]. When xml:base is used in an Atom Document, |
|
| 145 | * it serves the function described in section 5.1.1 of [RFC3986], establishing |
|
| 146 | * the base URI (or IRI) for resolving any relative references found within the |
|
| 147 | * effective scope of the xml:base attribute. |
|
| 148 | * @param base |
|
| 149 | * @return |
|
| 150 | */ |
|
| 151 | public Generator setBase(String base) { |
|
| 152 | 27 | _base = base; |
| 153 | 27 | return this; |
| 154 | } |
|
| 155 | /** |
|
| 156 | * <li>Rss 2.0 - <language> element. |
|
| 157 | * The language the channel is written in. This allows aggregators to group |
|
| 158 | * all Italian language sites, for example, on a single page. A list of allowable |
|
| 159 | * values for this element, as provided by Netscape, is here. You may also use values |
|
| 160 | * defined by the W3C. |
|
| 161 | * Only <channel> support this element.</li> |
|
| 162 | * <li>Rss 1.0 - <dc:language> element. A language of the intellectual content of the resource. |
|
| 163 | * Only <channel> and <item> support this element. </li> |
|
| 164 | * <li>Atom 1.0 - 'lang' attribute</li> |
|
| 165 | * <br/> |
|
| 166 | * Note: for Rss 2.0 and Rss 1.0, only <channel> and <item> |
|
| 167 | * @param lang |
|
| 168 | * @return |
|
| 169 | */ |
|
| 170 | public Generator setLang(String lang) { |
|
| 171 | 27 | _lang = lang; |
| 172 | 27 | return this; |
| 173 | } |
|
| 174 | /** |
|
| 175 | * <li>Rss 2.0 - <language> element. |
|
| 176 | * The language the channel is written in. This allows aggregators to group |
|
| 177 | * all Italian language sites, for example, on a single page. A list of allowable |
|
| 178 | * values for this element, as provided by Netscape, is here. You may also use values |
|
| 179 | * defined by the W3C. |
|
| 180 | * Only <channel> support this element.</li> |
|
| 181 | * <li>Rss 1.0 - <dc:language> element. A language of the intellectual content of the resource. |
|
| 182 | * Only <channel> and <item> support this element. </li> |
|
| 183 | * <li>Atom 1.0 - 'lang' attribute</li> |
|
| 184 | * <br/> |
|
| 185 | * Note: for Rss 2.0 and Rss 1.0, only <channel> and <item> |
|
| 186 | * @param lang |
|
| 187 | * @return |
|
| 188 | */ |
|
| 189 | public Generator setLang(Locale lang) { |
|
| 190 | 0 | _lang = lang.getLanguage(); |
| 191 | 0 | return this; |
| 192 | } |
|
| 193 | ////////////////////////Common setters/////////////////////// |
|
| 194 | @Override |
|
| 195 | public void validate(FeedFormat format) throws ValidationException { |
|
| 196 | 6 | if(format == FeedFormat.RSS10){ |
| 197 | 0 | return; |
| 198 | } |
|
| 199 | 6 | ValidationUtils.validateNotNull("[Generator] Value should not be null", _value); |
| 200 | 6 | ValidationUtils.validateUri("[Generator] uri should be an valid uri", _uri); |
| 201 | 6 | } |
| 202 | ||
| 203 | } |