Coverage Report - yarfraw.core.datamodel.CategorySubject
 
Classes in this File Line Coverage Branch Coverage Complexity
CategorySubject
100% 
100% 
0
 
 1  
 package yarfraw.core.datamodel;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.util.ArrayList;
 5  
 import java.util.HashMap;
 6  
 import java.util.List;
 7  
 import java.util.Locale;
 8  
 import java.util.Map;
 9  
 
 10  
 import javax.xml.namespace.QName;
 11  
 import javax.xml.parsers.ParserConfigurationException;
 12  
 
 13  
 import org.w3c.dom.Element;
 14  
 import org.xml.sax.SAXException;
 15  
 
 16  
 import yarfraw.utils.ValidationUtils;
 17  
 import yarfraw.utils.XMLUtils;
 18  
 
 19  
 /**
 20  
  * <li>Rss 2.0 - the &lt;category> element</li>
 21  
  * <li>Rss 1.0 - the &lt;dc:subject> element</li>
 22  
  * <li>Atom 1.0 - the &lt;category> element</li>
 23  
  * 
 24  
  * <p>
 25  
  * Rss 2.0:  http://cyber.law.harvard.edu/rss/rss.html#syndic8 <br/>
 26  
  * Rss 1.0:  http://dublincore.org/documents/1999/07/02/dces/ - 'Dublin Core'
 27  
  * Atom 1.0: http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html#rfc.section.4.2.2
 28  
  * <p/>
 29  
  * @author jliang
 30  
  *
 31  
  */
 32  4519
 public class CategorySubject extends AbstractBaseObject{
 33  
   /**
 34  
    * 
 35  
    */
 36  
   private static final long serialVersionUID = 20070927L;
 37  
   private String _categoryOrSubjectOrTerm;
 38  
   private String _domainOrScheme;
 39  
   private String _label;
 40  3994
   public CategorySubject() {}
 41  
   
 42  
   /**
 43  
    * This value is only used by Atom 1.0, it is ignored by other {@link FeedFormat}.
 44  
    * <br/>
 45  
    * The "label" attribute provides a human-readable label for display in end-user applications. 
 46  
    * The content of the "label" attribute is Language-Sensitive. 
 47  
    * The escaped versions of characters such as "&" and ">" represent those characters, not markup. 
 48  
    * Category elements MAY have a "label" attribute.
 49  
    * @return label value
 50  
    */
 51  
   public String getLabel() {
 52  12
     return _label;
 53  
   }
 54  
   /**
 55  
    * This value is only used by Atom 1.0, it is ignored by other {@link FeedFormat}.
 56  
    * <br/>
 57  
    * The "label" attribute provides a human-readable label for display in end-user applications. 
 58  
    * The content of the "label" attribute is Language-Sensitive. 
 59  
    * The escaped versions of characters such as "&" and ">" represent those characters, not markup. 
 60  
    * Category elements MAY have a "label" attribute.
 61  
    *  
 62  
    * @param label label value
 63  
    * @return this
 64  
    */
 65  
   public CategorySubject setLabel(String label) {
 66  78
     _label = label;
 67  78
     return this;
 68  
   }
 69  
 
 70  
   /**
 71  
    * Creates a new category object.
 72  
    * 
 73  
    * @param categoryOrSubjectOrTerm
 74  
    * <li>Rss 2.0 - text value of the &ltcategory> element</li>
 75  
    * <li>Rss 1.0 - text value of the &ltdc:subject> element</li>
 76  
    * <li>Atom 1.0 - text value of the &ltcategory> element</li> 
 77  
    */
 78  
   public CategorySubject(String categoryOrSubjectOrTerm) {
 79  246
     super();
 80  246
     _categoryOrSubjectOrTerm = categoryOrSubjectOrTerm;
 81  246
   }
 82  
   
 83  
   /**
 84  
    * <li>Rss 2.0 - Specify one or more categories that the channel belongs to. </li>
 85  
    * <li>Rss 1.0 - The topic of the content of the resource. </li>
 86  
    * <li>Atom 1.0 - The "term" attribute is a string that identifies the category to which the entry or feed belongs. Category elements MUST have a "term" attribute. </li>
 87  
    * @return <li>Rss 2.0 - text value of the &ltcategory> element</li>
 88  
    * <li>Rss 1.0 - text value of the &ltdc:subject> element</li>
 89  
    * <li>Atom 1.0 - text value of the &ltcategory> element</li>
 90  
    */
 91  
   public String getCategoryOrSubjectOrTerm() {
 92  75
     return _categoryOrSubjectOrTerm;
 93  
   }
 94  
   /**
 95  
    * <li>Rss 2.0 - Specify one or more categories that the channel belongs to. </li>
 96  
    * <li>Rss 1.0 - The topic of the content of the resource. </li>
 97  
    * <li>Atom 1.0 - The "term" attribute is a string that identifies the category to which the entry or feed belongs. Category elements MUST have a "term" attribute. </li>
 98  
    * @param categoryOrSubjectOrTerm <li>Rss 2.0 - text value of the &ltcategory> element</li>
 99  
    * <li>Rss 1.0 - text value of the &ltdc:subject> element</li>
 100  
    * <li>Atom 1.0 - text value of the &ltcategory> element</li>
 101  
    * @return this
 102  
    */
 103  
   public CategorySubject setCategoryOrSubjectOrTerm(String categoryOrSubjectOrTerm) {
 104  3991
     _categoryOrSubjectOrTerm = categoryOrSubjectOrTerm;
 105  3991
     return this;
 106  
   }
 107  
   /**
 108  
    * <li> Rss 2.0 - 
 109  
    * a string that identifies a categorization taxonomy. 
 110  
    * <br/>
 111  
    * The value of the element is a forward-slash-separated string that identifies 
 112  
    * a hierarchic location in the indicated taxonomy. Processors may establish 
 113  
    * conventions for the interpretation of categories. Two examples are provided below:
 114  
    * <br/>
 115  
    * &lt;category>Grateful Dead&lt;/category>
 116  
    * <br/>
 117  
    * &lt;category domain="http://www.fool.com/cusips">MSFT&lt;/category>
 118  
    * </li>
 119  
    * <li> Atom 1.0 - 
 120  
    * The "scheme" attribute is an IRI that identifies a categorization scheme. Category elements MAY have a "scheme" attribute.
 121  
    * </li>
 122  
    * <li> Rss 1.0 - 
 123  
    * Not supported by Rss 1.0.
 124  
    * </li>  
 125  
    */
 126  
   public String getDomainOrScheme() {
 127  36
     return _domainOrScheme;
 128  
   }
 129  
   /**
 130  
    * <li> Rss 2.0 - 
 131  
    * a string that identifies a categorization taxonomy. 
 132  
    * <br/>
 133  
    * The value of the element is a forward-slash-separated string that identifies 
 134  
    * a hierarchic location in the indicated taxonomy. Processors may establish 
 135  
    * conventions for the interpretation of categories. Two examples are provided below:
 136  
    * <br/>
 137  
    * &lt;category>Grateful Dead&lt;/category>
 138  
    * <br/>
 139  
    * &lt;category domain="http://www.fool.com/cusips">MSFT&lt;/category>
 140  
    * </li>
 141  
    * <li> Atom 1.0 - 
 142  
    * The "scheme" attribute is an IRI that identifies a categorization scheme. Category elements MAY have a "scheme" attribute.
 143  
    * </li>
 144  
    * <li> Rss 1.0 - 
 145  
    * Not supported by Rss 1.0.
 146  
    * </li>  
 147  
    * @param domainOrScheme - the value of the attribute
 148  
    * @return this
 149  
    */
 150  
   public CategorySubject setDomainOrScheme(String domainOrScheme) {
 151  4024
     _domainOrScheme = domainOrScheme;
 152  4024
     return this;
 153  
   }
 154  
   
 155  
   
 156  
   ////////////////////////Common setters///////////////////////
 157  
   /**
 158  
    * Any other attribute that is not in the RSS 2.0 specs.
 159  
    */
 160  
   public CategorySubject setOtherAttributes(Map<QName, String> otherAttributes) {
 161  6
     _otherAttributes = otherAttributes;
 162  6
     return this;
 163  
   }
 164  
   /**
 165  
    * Add an attribute that is not in the RSS 2.0 specs.
 166  
    */
 167  
   public CategorySubject addOtherAttributes(QName namespace, String attribute) {
 168  6
     if(_otherAttributes == null){
 169  3
       _otherAttributes = new HashMap<QName, String>();
 170  
     }
 171  6
     _otherAttributes.put(namespace, attribute);
 172  6
     return this;
 173  
   }
 174  
   
 175  
   /**
 176  
    * Other additional elements that are not in the Rss specs.<br/>
 177  
    * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
 178  
    */
 179  
   public CategorySubject setOtherElements(List<Element> otherElements) {
 180  6
     _otherElements = otherElements;
 181  6
     return this;
 182  
   }
 183  
   /**
 184  
    * Add an element that is not specified in the Rss specs.<br/>
 185  
    * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
 186  
    * @param element - any element
 187  
    */
 188  
   public CategorySubject addOtherElement(Element element){
 189  6
     if(_otherElements == null){
 190  3
       _otherElements = new ArrayList<Element>();
 191  
     }
 192  6
     _otherElements.add(element);
 193  6
     return this;
 194  
   }
 195  
   
 196  
   /**
 197  
    * Add an element that is not specified in the Rss specs.<br/>
 198  
    * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
 199  
    * 
 200  
    * @param xmlString - any element
 201  
    * @throws ParserConfigurationException 
 202  
    * @throws IOException 
 203  
    * @throws SAXException 
 204  
    */
 205  
   public CategorySubject addOtherElement(String xmlString) throws SAXException, IOException, ParserConfigurationException{
 206  3
     return addOtherElement(XMLUtils.parseXml(xmlString, false, false).getDocumentElement());
 207  
   }
 208  
   
 209  
   /**
 210  
    * <b>Atom 1.0 only</b><br/>
 211  
    * Any element defined by this specification MAY have an xml:base attribute 
 212  
    * [W3C.REC-xmlbase-20010627]. When xml:base is used in an Atom Document, 
 213  
    * it serves the function described in section 5.1.1 of [RFC3986], establishing 
 214  
    * the base URI (or IRI) for resolving any relative references found within the 
 215  
    * effective scope of the xml:base attribute.
 216  
    * @param base
 217  
    * @return
 218  
    */
 219  
   public CategorySubject setBase(String base) {
 220  78
     _base = base;
 221  78
     return this;
 222  
   }
 223  
   /**
 224  
    * <li>Rss 2.0 - &lt;language> element. 
 225  
    * The language the channel is written in. This allows aggregators to group 
 226  
    * all Italian language sites, for example, on a single page. A list of allowable 
 227  
    * values for this element, as provided by Netscape, is here. You may also use values 
 228  
    * defined by the W3C.
 229  
    * Only &lt;channel> support this element.</li>
 230  
    * <li>Rss 1.0 - &lt;dc:language> element. A language of the intellectual content of the resource.
 231  
    * Only &lt;channel> and &lt;item> support this element. </li>
 232  
    * <li>Atom 1.0 - 'lang' attribute</li>
 233  
    * <br/>
 234  
    * Note: for Rss 2.0 and Rss 1.0, only &lt;channel> and &lt;item>
 235  
    * @param lang
 236  
    * @return
 237  
    */
 238  
   public CategorySubject setLang(String lang) {
 239  81
     _lang = lang;
 240  81
     return this;
 241  
   }
 242  
   
 243  
   /**
 244  
    * <li>Rss 2.0 - &lt;language> element. 
 245  
    * The language the channel is written in. This allows aggregators to group 
 246  
    * all Italian language sites, for example, on a single page. A list of allowable 
 247  
    * values for this element, as provided by Netscape, is here. You may also use values 
 248  
    * defined by the W3C.
 249  
    * Only &lt;channel> support this element.</li>
 250  
    * <li>Rss 1.0 - &lt;dc:language> element. A language of the intellectual content of the resource.
 251  
    * Only &lt;channel> and &lt;item> support this element. </li>
 252  
    * <li>Atom 1.0 - 'lang' attribute</li>
 253  
    * <br/>
 254  
    * Note: for Rss 2.0 and Rss 1.0, only &lt;channel> and &lt;item>
 255  
    * @param lang
 256  
    * @return
 257  
    */
 258  
   public CategorySubject setLang(Locale lang) {
 259  3
     setLang(lang.getLanguage());
 260  3
     return this;
 261  
   }
 262  
   /**
 263  
    * <b>Rss 1.0 only</b><br/>
 264  
    * @param resource
 265  
    * @return
 266  
    */
 267  
   public CategorySubject setResource(String resource) {
 268  3
     _resource = resource;
 269  3
     return this;
 270  
   }
 271  
   /**
 272  
    * <b>Rss 1.0 only</b><br/>
 273  
    * @param about
 274  
    * @return
 275  
    */
 276  
   public CategorySubject setAbout(String about) {
 277  3
     _about = about;
 278  3
     return this;
 279  
   }
 280  
   ////////////////////////Common setters///////////////////////
 281  
   
 282  
   @Override
 283  
   public void validate(FeedFormat format) throws ValidationException {
 284  24
     ValidationUtils.validateNotNull(_categoryOrSubjectOrTerm, "Category: Category value should not be null");
 285  24
   }
 286  
 }