Coverage Report - yarfraw.core.datamodel.Content
 
Classes in this File Line Coverage Branch Coverage Complexity
Content
79% 
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.XMLUtils;
 17  
 /**
 18  
  * <li>Rss 2.0 -
 19  
  * This is not officially supported, but if there's a &lt;content:encoded /> element under &lt;Item>,
 20  
  * the content of the encoded element will be mapped to this class. The type will always be 'text' in this case.
 21  
  * </li>
 22  
  * <li>Rss 1.0 -
 23  
  * This is not officially supported, but if there's a &lt;content:encoded /> element under &lt;Item>,
 24  
  * the content of the encoded element will be mapped to this class. The type will always be 'text' in this case.
 25  
  * </li>
 26  
  * <li> Atom 1.0 - 
 27  
  * Data model of the 'atom:content' element in Atom 1.0 specs.<br/>
 28  
  * http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html#atomContent
 29  
  * <br/>
 30  
  * If the content is XHTML, the xhtml elements can be found at the 'otherElements' list. <br/>
 31  
  * </li>
 32  
  * @author jliang
 33  
  *
 34  
  */
 35  606
 public class Content extends AbstractBaseObject{
 36  
   private static final long serialVersionUID = 20070927L;
 37  
   private List<String> _contentText;
 38  
   private String _type;
 39  
   private String _src;
 40  
   
 41  276
   public Content() {}
 42  
 
 43  0
   public Content(String contentText) {
 44  0
     _contentText = new ArrayList<String>();
 45  0
     _contentText.add(contentText);
 46  0
     _type = "text";
 47  0
   }
 48  
   /**
 49  
    * Any text content.
 50  
    */
 51  
   public Content addContentText(String contentText){
 52  243
     _contentText = _contentText != null ? _contentText : new ArrayList<String>();
 53  243
     _contentText.add(contentText);
 54  243
     return this;
 55  
   }
 56  
   /**
 57  
    * Any text content.
 58  
    */
 59  
   public List<String> getContentText() {
 60  69
     return _contentText;
 61  
   }
 62  
   /**
 63  
    * Any text content.
 64  
    */
 65  
   public Content setContentText(List<String> contentText) {
 66  0
     _contentText = contentText;
 67  0
     return this;
 68  
   }
 69  
   
 70  
   /**
 71  
    * <b>Atom 1.0 only </b> 
 72  
    * <br/>
 73  
    * atom:content MAY have a "src" attribute, whose value MUST be an IRI reference [RFC3987]. If the "src" attribute is present, atom:content MUST be empty. Atom Processors MAY use the IRI to retrieve the content, and MAY chose to ignore remote content or present it in a different manner than local content.
 74  
    * <p/>
 75  
    * If the "src" attribute is present, the "type" attribute SHOULD be provided and MUST be a MIME media type [MIMEREG], rather than "text", "html", or "xhtml". The value is advisory; that is to say, when the corresponding URI (mapped from an IRI, if necessary), is dereferenced, if the server providing that content also provides a media type, the server-provided media type is authoritative.
 76  
    */
 77  
   public String getSrc(){
 78  39
     return _src;
 79  
   }
 80  
   /**
 81  
    * <b>Atom 1.0 only </b> 
 82  
    * <br/>
 83  
    * atom:content MAY have a "src" attribute, whose value MUST be an IRI reference [RFC3987]. If the "src" attribute is present, atom:content MUST be empty. Atom Processors MAY use the IRI to retrieve the content, and MAY chose to ignore remote content or present it in a different manner than local content.
 84  
    * <p/>
 85  
    * If the "src" attribute is present, the "type" attribute SHOULD be provided and MUST be a MIME media type [MIMEREG], rather than "text", "html", or "xhtml". The value is advisory; that is to say, when the corresponding URI (mapped from an IRI, if necessary), is dereferenced, if the server providing that content also provides a media type, the server-provided media type is authoritative.
 86  
    */  
 87  
   public Content setSrc(String src) {
 88  264
     _src = src;
 89  264
     return this;
 90  
   }
 91  
   /**
 92  
    * <b>Atom 1.0 only </b> 
 93  
    * <br/>
 94  
    * On the atom:content element, the value of the "type" attribute MAY be one of "text", "html", or "xhtml". Failing that, it MUST conform to the syntax of a MIME media type, but MUST NOT be a composite type (see Section 4.2.6 of [MIMEREG]). If the type attribute is not provided, Atom Processors MUST behave as though it were present with a value of "text".
 95  
    * 
 96  
    */  
 97  
   public String getType() {
 98  39
     return _type;
 99  
   }
 100  
   /**
 101  
    * <b>Atom 1.0 only </b> 
 102  
    * <br/>
 103  
    * On the atom:content element, the value of the "type" attribute MAY be one of "text", "html", or "xhtml". Failing that, it MUST conform to the syntax of a MIME media type, but MUST NOT be a composite type (see Section 4.2.6 of [MIMEREG]). If the type attribute is not provided, Atom Processors MUST behave as though it were present with a value of "text".
 104  
    */  
 105  
   public Content setType(String type) {
 106  270
     _type = type;
 107  270
     return this;
 108  
   }
 109  
   ////////////////////////Common setters///////////////////////
 110  
   /**
 111  
    * Any other attribute that is not in the RSS 2.0 specs.
 112  
    */
 113  
   public Content setOtherAttributes(Map<QName, String> otherAttributes) {
 114  6
     _otherAttributes = otherAttributes;
 115  6
     return this;
 116  
   }
 117  
   /**
 118  
    * Add an attribute that is not in the RSS 2.0 specs.
 119  
    */
 120  
   public Content addOtherAttributes(QName namespace, String attribute) {
 121  9
     if(_otherAttributes == null){
 122  3
       _otherAttributes = new HashMap<QName, String>();
 123  
     }
 124  9
     _otherAttributes.put(namespace, attribute);
 125  9
     return this;
 126  
   }
 127  
   
 128  
   /**
 129  
    * Other additional elements that are not in the Rss specs.<br/>
 130  
    * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
 131  
    */
 132  
   public Content setOtherElements(List<Element> otherElements) {
 133  6
     _otherElements = otherElements;
 134  6
     return this;
 135  
   }
 136  
   /**
 137  
    * Add an element that is not specified in the Rss specs.<br/>
 138  
    * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
 139  
    * @param element - any element
 140  
    */
 141  
   public Content addOtherElement(Element element){
 142  15
     if(_otherElements == null){
 143  3
       _otherElements = new ArrayList<Element>();
 144  
     }
 145  15
     _otherElements.add(element);
 146  15
     return this;
 147  
   }
 148  
   
 149  
   /**
 150  
    * Add an element that is not specified in the Rss specs.<br/>
 151  
    * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
 152  
    * 
 153  
    * @param xmlString - any element
 154  
    * @throws ParserConfigurationException 
 155  
    * @throws IOException 
 156  
    * @throws SAXException 
 157  
    */
 158  
   public Content addOtherElement(String xmlString) throws SAXException, IOException, ParserConfigurationException{
 159  9
     return addOtherElement(XMLUtils.parseXml(xmlString, false, false).getDocumentElement());
 160  
   }
 161  
   
 162  
 
 163  
   /**
 164  
    * <b>Atom 1.0 only</b><br/>
 165  
    * Any element defined by this specification MAY have an xml:base attribute 
 166  
    * [W3C.REC-xmlbase-20010627]. When xml:base is used in an Atom Document, 
 167  
    * it serves the function described in section 5.1.1 of [RFC3986], establishing 
 168  
    * the base URI (or IRI) for resolving any relative references found within the 
 169  
    * effective scope of the xml:base attribute.
 170  
    * @param base
 171  
    * @return
 172  
    */
 173  
   public Content setBase(String base) {
 174  270
     _base = base;
 175  270
     return this;
 176  
   }
 177  
   /**
 178  
    * <li>Rss 2.0 - &lt;language> element. 
 179  
    * The language the channel is written in. This allows aggregators to group 
 180  
    * all Italian language sites, for example, on a single page. A list of allowable 
 181  
    * values for this element, as provided by Netscape, is here. You may also use values 
 182  
    * defined by the W3C.
 183  
    * Only &lt;channel> support this element.</li>
 184  
    * <li>Rss 1.0 - &lt;dc:language> element. A language of the intellectual content of the resource.
 185  
    * Only &lt;channel> and &lt;item> support this element. </li>
 186  
    * <li>Atom 1.0 - 'lang' attribute</li>
 187  
    * <br/>
 188  
    * Note: for Rss 2.0 and Rss 1.0, only &lt;channel> and &lt;item>
 189  
    * @param lang
 190  
    * @return
 191  
    */
 192  
   public Content setLang(String lang) {
 193  264
     _lang = lang;
 194  264
     return this;
 195  
   }
 196  
   /**
 197  
    * <li>Rss 2.0 - &lt;language> element. 
 198  
    * The language the channel is written in. This allows aggregators to group 
 199  
    * all Italian language sites, for example, on a single page. A list of allowable 
 200  
    * values for this element, as provided by Netscape, is here. You may also use values 
 201  
    * defined by the W3C.
 202  
    * Only &lt;channel> support this element.</li>
 203  
    * <li>Rss 1.0 - &lt;dc:language> element. A language of the intellectual content of the resource.
 204  
    * Only &lt;channel> and &lt;item> support this element. </li>
 205  
    * <li>Atom 1.0 - 'lang' attribute</li>
 206  
    * <br/>
 207  
    * Note: for Rss 2.0 and Rss 1.0, only &lt;channel> and &lt;item>
 208  
    * @param lang
 209  
    * @return
 210  
    */
 211  
   public Content setLang(Locale lang) {
 212  9
     _lang = lang.getLanguage();
 213  9
     return this;
 214  
   }
 215  
   ////////////////////////Common setters///////////////////////
 216  
   
 217  
   @Override
 218  
   public void validate(FeedFormat format) throws ValidationException {
 219  
     // TODO Auto-generated method stub
 220  
     
 221  0
   }
 222  
   
 223  
 }