KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > syndication > io > SyndFeedInput


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.feed.synd.SyndFeed;
20 import com.sun.syndication.feed.synd.SyndFeedImpl;
21 import org.jdom.Document;
22 import org.xml.sax.InputSource JavaDoc;
23
24 import java.io.File JavaDoc;
25 import java.io.FileNotFoundException JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.Reader JavaDoc;
28
29 /**
30  * Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument)
31  * into an SyndFeedImpl.
32  * <p>
33  * It delegates to a WireFeedInput to handle all feed types.
34  * <p>
35  * @author Alejandro Abdelnur
36  *
37  */

38 public class SyndFeedInput {
39     private WireFeedInput _feedInput;
40
41     /**
42      * Creates a SyndFeedInput instance with input validation turned off.
43      * <p>
44      *
45      */

46     public SyndFeedInput() {
47         this(false);
48     }
49
50     /**
51      * Creates a SyndFeedInput instance.
52      * <p>
53      * @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen)
54      *
55      */

56     public SyndFeedInput(boolean validate) {
57         _feedInput = new WireFeedInput(validate);
58     }
59
60     /**
61      * Enables XML healing in the WiredFeedInput instance.
62      * <p>
63      * Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog.
64      * <p>
65      * Healing resolves HTML entities (from literal to code number) in the reader.
66      * <p>
67      * The healing is done only with the build(File) and build(Reader) signatures.
68      * <p>
69      * By default is TRUE.
70      * <p>
71      * @param heals TRUE enables stream healing, FALSE disables it.
72      *
73      */

74     public void setXmlHealerOn(boolean heals) {
75         _feedInput.setXmlHealerOn(heals);
76     }
77
78     /**
79      * Indicates if the WiredFeedInput instance will XML heal (if necessary) the character stream.
80      * <p>
81      * Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog.
82      * <p>
83      * Healing resolves HTML entities (from literal to code number) in the reader.
84      * <p>
85      * The healing is done only with the build(File) and build(Reader) signatures.
86      * <p>
87      * By default is TRUE.
88      * <p>
89      * @return TRUE if healing is enabled, FALSE if not.
90      *
91      */

92     public boolean getXmlHealerOn() {
93         return _feedInput.getXmlHealerOn();
94     }
95
96
97     /**
98      * Builds SyndFeedImpl from a file.
99      * <p>
100      * @param file file to read to create the SyndFeedImpl.
101      * @return the SyndFeedImpl read from the file.
102      * @throws FileNotFoundException thrown if the file could not be found.
103      * @throws IOException thrown if there is problem reading the file.
104      * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
105      * @throws FeedException if the feed could not be parsed
106      *
107      */

108     public SyndFeed build(File JavaDoc file) throws FileNotFoundException JavaDoc,IOException JavaDoc,IllegalArgumentException JavaDoc,FeedException {
109         return new SyndFeedImpl(_feedInput.build(file));
110     }
111
112     /**
113      * Builds SyndFeedImpl from an Reader.
114      * <p>
115      * @param reader Reader to read to create the SyndFeedImpl.
116      * @return the SyndFeedImpl read from the Reader.
117      * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
118      * @throws FeedException if the feed could not be parsed
119      *
120      */

121     public SyndFeed build(Reader JavaDoc reader) throws IllegalArgumentException JavaDoc,FeedException {
122         return new SyndFeedImpl(_feedInput.build(reader));
123     }
124
125     /**
126      * Builds SyndFeedImpl from an W3C SAX InputSource.
127      * <p>
128      * @param is W3C SAX InputSource to read to create the SyndFeedImpl.
129      * @return the SyndFeedImpl read from the W3C SAX InputSource.
130      * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
131      * @throws FeedException if the feed could not be parsed
132      *
133      */

134     public SyndFeed build(InputSource JavaDoc is) throws IllegalArgumentException JavaDoc,FeedException {
135         return new SyndFeedImpl(_feedInput.build(is));
136     }
137
138     /**
139      * Builds SyndFeedImpl from an W3C DOM document.
140      * <p>
141      * @param document W3C DOM document to read to create the SyndFeedImpl.
142      * @return the SyndFeedImpl read from the W3C DOM document.
143      * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
144      * @throws FeedException if the feed could not be parsed
145      *
146      */

147     public SyndFeed build(org.w3c.dom.Document JavaDoc document) throws IllegalArgumentException JavaDoc,FeedException {
148         return new SyndFeedImpl(_feedInput.build(document));
149     }
150
151     /**
152      * Builds SyndFeedImpl from an JDOM document.
153      * <p>
154      * @param document JDOM document to read to create the SyndFeedImpl.
155      * @return the SyndFeedImpl read from the JDOM document.
156      * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
157      * @throws FeedException if the feed could not be parsed
158      *
159      */

160     public SyndFeed build(Document document) throws IllegalArgumentException JavaDoc,FeedException {
161         return new SyndFeedImpl(_feedInput.build(document));
162     }
163
164 }
165
Popular Tags