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 <content:encoded /> element under <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 <content:encoded /> element under <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 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 public Content() {}
42
43 public Content(String contentText) {
44 _contentText = new ArrayList<String>();
45 _contentText.add(contentText);
46 _type = "text";
47 }
48 /***
49 * Any text content.
50 */
51 public Content addContentText(String contentText){
52 _contentText = _contentText != null ? _contentText : new ArrayList<String>();
53 _contentText.add(contentText);
54 return this;
55 }
56 /***
57 * Any text content.
58 */
59 public List<String> getContentText() {
60 return _contentText;
61 }
62 /***
63 * Any text content.
64 */
65 public Content setContentText(List<String> contentText) {
66 _contentText = contentText;
67 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 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 _src = src;
89 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 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 _type = type;
107 return this;
108 }
109
110 /***
111 * Any other attribute that is not in the RSS 2.0 specs.
112 */
113 public Content setOtherAttributes(Map<QName, String> otherAttributes) {
114 _otherAttributes = otherAttributes;
115 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 if(_otherAttributes == null){
122 _otherAttributes = new HashMap<QName, String>();
123 }
124 _otherAttributes.put(namespace, attribute);
125 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 _otherElements = otherElements;
134 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 if(_otherElements == null){
143 _otherElements = new ArrayList<Element>();
144 }
145 _otherElements.add(element);
146 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 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 _base = base;
175 return this;
176 }
177 /***
178 * <li>Rss 2.0 - <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 <channel> support this element.</li>
184 * <li>Rss 1.0 - <dc:language> element. A language of the intellectual content of the resource.
185 * Only <channel> and <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 <channel> and <item>
189 * @param lang
190 * @return
191 */
192 public Content setLang(String lang) {
193 _lang = lang;
194 return this;
195 }
196 /***
197 * <li>Rss 2.0 - <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 <channel> support this element.</li>
203 * <li>Rss 1.0 - <dc:language> element. A language of the intellectual content of the resource.
204 * Only <channel> and <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 <channel> and <item>
208 * @param lang
209 * @return
210 */
211 public Content setLang(Locale lang) {
212 _lang = lang.getLanguage();
213 return this;
214 }
215
216
217 @Override
218 public void validate(FeedFormat format) throws ValidationException {
219
220
221 }
222
223 }