View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.SyndFeedImpl;
22  import com.sun.syndication.feed.synd.SyndFeed;
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.Reader;
29  import java.io.IOException;
30  
31  /***
32   * Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument)
33   * into an SyndFeedImpl.
34   * <p>
35   * It delegates to a WireFeedInput to handle all feed types.
36   * <p>
37   * @author Alejandro Abdelnur
38   *
39   */
40  public class SyndFeedInput {
41      private WireFeedInput _feedInput;
42  
43      /***
44       * Creates a SyndFeedInput instance with input validation turned off.
45       * <p>
46       *
47       */
48      public SyndFeedInput() {
49          this(false);
50      }
51  
52      /***
53       * Creates a SyndFeedInput instance.
54       * <p>
55       * @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen)
56       *
57       */
58      public SyndFeedInput(boolean validate) {
59          _feedInput = new WireFeedInput(validate);
60      }
61  
62      /***
63       * Builds SyndFeedImpl from a file.
64       * <p>
65       * @param file file to read to create the SyndFeedImpl.
66       * @return the SyndFeedImpl read from the file.
67       * @throws FileNotFoundException thrown if the file could not be found.
68       * @throws IOException thrown if there is problem reading the file.
69       * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
70       * @throws FeedException if the feed could not be parsed
71       *
72       */
73      public SyndFeed build(File file) throws FileNotFoundException,IOException,IllegalArgumentException,FeedException {
74          return new SyndFeedImpl(_feedInput.build(file));
75      }
76  
77      /***
78       * Builds SyndFeedImpl from an Reader.
79       * <p>
80       * @param reader Reader to read to create the SyndFeedImpl.
81       * @return the SyndFeedImpl read from the Reader.
82       * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
83       * @throws FeedException if the feed could not be parsed
84       *
85       */
86      public SyndFeed build(Reader reader) throws IllegalArgumentException,FeedException {
87          return new SyndFeedImpl(_feedInput.build(reader));
88      }
89  
90      /***
91       * Builds SyndFeedImpl from an W3C SAX InputSource.
92       * <p>
93       * @param is W3C SAX InputSource to read to create the SyndFeedImpl.
94       * @return the SyndFeedImpl read from the W3C SAX InputSource.
95       * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
96       * @throws FeedException if the feed could not be parsed
97       *
98       */
99      public SyndFeed build(InputSource is) throws IllegalArgumentException,FeedException {
100         return new SyndFeedImpl(_feedInput.build(is));
101     }
102 
103     /***
104      * Builds SyndFeedImpl from an W3C DOM document.
105      * <p>
106      * @param document W3C DOM document to read to create the SyndFeedImpl.
107      * @return the SyndFeedImpl read from the W3C DOM document.
108      * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
109      * @throws FeedException if the feed could not be parsed
110      *
111      */
112     public SyndFeed build(org.w3c.dom.Document document) throws IllegalArgumentException,FeedException {
113         return new SyndFeedImpl(_feedInput.build(document));
114     }
115 
116     /***
117      * Builds SyndFeedImpl from an JDOM document.
118      * <p>
119      * @param document JDOM document to read to create the SyndFeedImpl.
120      * @return the SyndFeedImpl read from the JDOM document.
121      * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
122      * @throws FeedException if the feed could not be parsed
123      *
124      */
125     public SyndFeed build(Document document) throws IllegalArgumentException,FeedException {
126         return new SyndFeedImpl(_feedInput.build(document));
127     }
128 
129 }