1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.sun.syndication.io;
18
19 import com.sun.syndication.io.FeedException;
20 import com.sun.syndication.io.WireFeedInput;
21 import com.sun.syndication.feed.synd.SyndFeed;
22 import com.sun.syndication.feed.synd.SyndFeedI;
23 import org.jdom.Document;
24 import org.xml.sax.InputSource;
25
26 import java.io.File;
27 import java.io.FileNotFoundException;
28 import java.io.InputStream;
29 import java.io.Reader;
30 import java.io.IOException;
31
32 /***
33 * Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument)
34 * into an SyndFeed.
35 * <p>
36 * It delegates to a WireFeedInput to handle all feed types.
37 * <p>
38 * @author Alejandro Abdelnur
39 *
40 */
41 public class SyndFeedInput {
42 private WireFeedInput _feedInput;
43
44 /***
45 * Creates a SyndFeedInput instance with input validation turned off.
46 * <p>
47 *
48 */
49 public SyndFeedInput() {
50 this(false);
51 }
52
53 /***
54 * Creates a SyndFeedInput instance.
55 * <p>
56 * @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen)
57 *
58 */
59 public SyndFeedInput(boolean validate) {
60 _feedInput = new WireFeedInput(validate);
61 }
62
63 /***
64 * Builds SyndFeed from a file.
65 * <p>
66 * @param file file to read to create the SyndFeed.
67 * @return the SyndFeed read from the file.
68 * @throws FileNotFoundException thrown if the file could not be found.
69 * @throws IOException thrown if there is problem reading the file.
70 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
71 * @throws FeedException if the feed could not be parsed
72 *
73 */
74 public SyndFeedI build(File file) throws FileNotFoundException,IOException,IllegalArgumentException,FeedException {
75 return new SyndFeed(_feedInput.build(file));
76 }
77
78 /***
79 * Builds SyndFeed from an InputStream.
80 * <p>
81 * @param is InputStream to read to create the SyndFeed.
82 * @return the SyndFeed read from the InputStream.
83 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
84 * @throws FeedException if the feed could not be parsed
85 *
86 */
87 public SyndFeedI build(InputStream is) throws IllegalArgumentException,FeedException {
88 return new SyndFeed(_feedInput.build(is));
89 }
90
91 /***
92 * Builds SyndFeed from an Reader.
93 * <p>
94 * @param reader Reader to read to create the SyndFeed.
95 * @return the SyndFeed read from the Reader.
96 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
97 * @throws FeedException if the feed could not be parsed
98 *
99 */
100 public SyndFeedI build(Reader reader) throws IllegalArgumentException,FeedException {
101 return new SyndFeed(_feedInput.build(reader));
102 }
103
104 /***
105 * Builds SyndFeed from an W3C SAX InputSource.
106 * <p>
107 * @param is W3C SAX InputSource to read to create the SyndFeed.
108 * @return the SyndFeed read from the W3C SAX InputSource.
109 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
110 * @throws FeedException if the feed could not be parsed
111 *
112 */
113 public SyndFeedI build(InputSource is) throws IllegalArgumentException,FeedException {
114 return new SyndFeed(_feedInput.build(is));
115 }
116
117 /***
118 * Builds SyndFeed from an W3C DOM document.
119 * <p>
120 * @param document W3C DOM document to read to create the SyndFeed.
121 * @return the SyndFeed read from the W3C DOM document.
122 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
123 * @throws FeedException if the feed could not be parsed
124 *
125 */
126 public SyndFeedI build(org.w3c.dom.Document document) throws IllegalArgumentException,FeedException {
127 return new SyndFeed(_feedInput.build(document));
128 }
129
130 /***
131 * Builds SyndFeed from an JDOM document.
132 * <p>
133 * @param document JDOM document to read to create the SyndFeed.
134 * @return the SyndFeed read from the JDOM document.
135 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
136 * @throws FeedException if the feed could not be parsed
137 *
138 */
139 public SyndFeedI build(Document document) throws IllegalArgumentException,FeedException {
140 return new SyndFeed(_feedInput.build(document));
141 }
142
143 }