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.Map;
8
9 import javax.xml.namespace.QName;
10 import javax.xml.parsers.ParserConfigurationException;
11
12 import org.w3c.dom.Element;
13 import org.xml.sax.SAXException;
14
15 import yarfraw.utils.ValidationUtils;
16 import yarfraw.utils.XMLUtils;
17 /***
18 * <b><TextInput> element of Rss 1.0 and Rss 2.0. This is ignored by Atom 1.0</b>
19 * <br/>
20 * <li> Rss 2.0 -
21 *A channel may optionally contain a <textInput> sub-element, which contains four required sub-elements.<br/>
22 *<title> -- The label of the Submit button in the text input area.<br/>
23 *<description> -- Explains the text input area.<br/>
24 *<name> -- The name of the text object in the text input area.<br/>
25 *<link> -- The URI of the CGI script that processes text input requests.<br/>
26 *The purpose of the <textInput> element is something of a mystery. You can use it to specify a search engine box. Or to allow a reader to provide feedback. Most aggregators ignore it.<br/>
27 *</li>
28 *<li> Rss 1.0 -
29 * The textinput element affords a method for submitting form data to an arbitrary URL -- usually located at the parent website.
30 * The form processor at the receiving end only is assumed to handle the HTTP GET method.
31 * The field is typically used as a search box or subscription form -- among others.
32 * While this is of some use when RSS documents are rendered as channels (see MNN) and accompanied by human readable title
33 * and description, the ambiguity in automatic determination of meaning of this overloaded element renders it otherwise not
34 * particularly useful. RSS 1.0 therefore suggests either deprecation or augmentation with some form of resource discovery of
35 * this element in future versions while maintaining it for backward compatibility with RSS 0.9.
36 * {textinput_uri} must be unique with respect to any other rdf:about attributes in the RSS document and is a URI which identifies the textinput. {textinput_uri}
37 * should be identical to the value of the <link> sub-element of the <textinput> element, if possible.
38 *</li>
39 *
40 * @author jliang
41 *
42 */
43 public class TextInput extends AbstractBaseObject{
44 private static final long serialVersionUID = 20070927L;
45 private String _title;
46 private String _description;
47 private String _name;
48 private String _link;
49 public TextInput(){}
50
51 /***
52 *A channel may optionally contain a <textInput> sub-element, which contains four required sub-elements.<br/>
53 *<title> -- The label of the Submit button in the text input area.<br/>
54 *<description> -- Explains the text input area.<br/>
55 *<name> -- The name of the text object in the text input area.<br/>
56 *<link> -- The URI of the CGI script that processes text input requests.<br/>
57 *The purpose of the <textInput> element is something of a mystery. You can use it to specify a search engine box. Or to allow a reader to provide feedback. Most aggregators ignore it.<br/>
58 * @throws URISyntaxException
59 * if <code>link</code> is an invalid URI
60 *
61 */
62 public TextInput(String title, String description, String name, String link){
63 _title = title;
64 _description = description;
65 _name = name;
66 setLink(link);
67 }
68 /***
69 * The label of the Submit button in the text input area.<br/>
70 */
71 public String getTitle() {
72 return _title;
73 }
74 /***
75 * The label of the Submit button in the text input area.<br/>
76 */
77 public TextInput setTitle(String title) {
78 _title = title;
79 return this;
80 }
81 /***
82 * Explains the text input area.<br/>
83 */
84 public String getDescription() {
85 return _description;
86 }
87 /***
88 * Explains the text input area.<br/>
89 */
90 public TextInput setDescription(String description) {
91 _description = description;
92 return this;
93 }
94 /***
95 *The name of the text object in the text input area.<br/>
96 */
97 public String getName() {
98 return _name;
99 }
100 /***
101 *The name of the text object in the text input area.<br/>
102 */
103 public TextInput setName(String name) {
104 _name = name;
105 return this;
106 }
107 /***
108 *The URI of the CGI script that processes text input requests.<br/>
109 */
110 public String getLink() {
111 return _link;
112 }
113 /***
114 *The URI of the CGI script that processes text input requests.<br/>
115 */
116 public TextInput setLink(String link) {
117 _link = link;
118 return this;
119 }
120
121 /***
122 * <b>Rss 1.0 only</b><br/>
123 * @param resource
124 * @return
125 */
126 public TextInput setResource(String resource) {
127 _resource = resource;
128 return this;
129 }
130 /***
131 * <b>Rss 1.0 only</b><br/>
132 * @param about
133 * @return
134 */
135 public TextInput setAbout(String about) {
136 _about = about;
137 return this;
138 }
139
140
141 /***
142 * Any other attribute that is not in the RSS 2.0 specs.
143 */
144 public TextInput setOtherAttributes(Map<QName, String> otherAttributes) {
145 _otherAttributes = otherAttributes;
146 return this;
147 }
148 /***
149 * Add an attribute that is not in the RSS 2.0 specs.
150 */
151 public TextInput addOtherAttributes(QName namespace, String attribute) {
152 if(_otherAttributes == null){
153 _otherAttributes = new HashMap<QName, String>();
154 }
155 _otherAttributes.put(namespace, attribute);
156 return this;
157 }
158
159 /***
160 * Other additional elements that are not in the Rss specs.<br/>
161 * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
162 */
163 public TextInput setOtherElements(List<Element> otherElements) {
164 _otherElements = otherElements;
165 return this;
166 }
167 /***
168 * Add an element that is not specified in the Rss specs.<br/>
169 * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
170 * @param element - any element
171 */
172 public TextInput addOtherElement(Element element){
173 if(_otherElements == null){
174 _otherElements = new ArrayList<Element>();
175 }
176 _otherElements.add(element);
177 return this;
178 }
179
180 /***
181 * Add an element that is not specified in the Rss specs.<br/>
182 * **Note** The element should not have an empty namespace to avoid collision with the specs elements.
183 *
184 * @param xmlString - any element
185 * @throws ParserConfigurationException
186 * @throws IOException
187 * @throws SAXException
188 */
189 public TextInput addOtherElement(String xmlString) throws SAXException, IOException, ParserConfigurationException{
190 return addOtherElement(XMLUtils.parseXml(xmlString, false, false).getDocumentElement());
191 }
192
193
194
195
196 @Override
197 public void validate(FeedFormat format) throws ValidationException {
198 if(format == FeedFormat.ATOM10)
199 return;
200
201 if(format == FeedFormat.RSS20){
202 ValidationUtils.validateNotNull("Image: All required fields in the Image object should be not null", _title, _link, _description, _name);
203 ValidationUtils.validateUri("link is not a valid URI", _link);
204 }
205
206 if(format == FeedFormat.RSS10){
207 ValidationUtils.validateNotNull("[Textinput] about is required", getAbout());
208 }
209 }
210 }