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.FeedOutput;
21  import com.sun.syndication.feed.synd.SyndFeedI;
22  import org.jdom.Document;
23  
24  import java.io.IOException;
25  import java.io.OutputStream;
26  import java.io.Writer;
27  import java.io.File;
28  
29  /***
30   * Generates an XML document (String, File, OutputStream, Writer, W3C DOM document or JDOM document)
31   * out of an SyndFeed..
32   * <p>
33   * It delegates to a FeedOutput to generate all feed types.
34   * <p>
35   * @author Alejandro Abdelnur
36   *
37   */
38  public class SyndOutput {
39      private String _type;
40      private FeedOutput _feedOutput;
41  
42      /***
43       * Creates a SyndOutput instace for a given feed type.
44       * <p>
45       * @param type the type of feed to generate.
46       *
47       */
48      public SyndOutput(String type) {
49          _type = type;
50          _feedOutput = new FeedOutput(type);
51      }
52  
53      /***
54       * Creates a String with the XML representation for the given SyndFeed.
55       * <p>
56       * @param feed Abstract feed to create XML representation from. The type of the SyndFeed must match
57       *        the type given to the FeedOuptut constructor.
58       * @return a String with the XML representation for the given SyndFeed.
59       * @throws FeedException thrown if the XML representation for the feed could not be created.
60       *
61       */
62      public String outputString(SyndFeedI feed) throws FeedException {
63          return _feedOutput.outputString(feed.createRealFeed(_type));
64      }
65  
66      /***
67       * Creates a File containing with the XML representation for the given SyndFeed.
68       * <p>
69       * @param feed Abstract feed to create XML representation from. The type of the SyndFeed must match
70       *        the type given to the FeedOuptut constructor.
71       * @param file the file where to write the XML representation for the given SyndFeed.
72       * @throws IOException thrown if there was some problem writing to the File.
73       * @throws FeedException thrown if the XML representation for the feed could not be created.
74       *
75       */
76      public void output(SyndFeedI feed,File file) throws IOException, FeedException {
77          _feedOutput.output(feed.createRealFeed(_type),file);
78      }
79  
80      /***
81       * Writes to an OutputStream the XML representation for the given SyndFeed.
82       * <p>
83       * @param feed Abstract feed to create XML representation from. The type of the SyndFeed must match
84       *        the type given to the FeedOuptut constructor.
85       * @param os OutputStream to write the XML representation for the given SyndFeed.
86       * @throws IOException thrown if there was some problem writing to the OutputStream.
87       * @throws FeedException thrown if the XML representation for the feed could not be created.
88       *
89       */
90      public void output(SyndFeedI feed,OutputStream os) throws IOException, FeedException {
91          _feedOutput.output(feed.createRealFeed(_type),os);
92      }
93  
94      /***
95       * Writes to an Writer the XML representation for the given SyndFeed.
96       * <p>
97       * @param feed Abstract feed to create XML representation from. The type of the SyndFeed must match
98       *        the type given to the FeedOuptut constructor.
99       * @param writer Writer to write the XML representation for the given SyndFeed.
100      * @throws IOException thrown if there was some problem writing to the Writer.
101      * @throws FeedException thrown if the XML representation for the feed could not be created.
102      *
103      */
104     public void output(SyndFeedI feed,Writer writer) throws IOException, FeedException {
105         _feedOutput.output(feed.createRealFeed(_type),writer);
106     }
107 
108     /***
109      * Creates a W3C DOM document for the given SyndFeed.
110      * <p>
111      * @param feed Abstract feed to create W3C DOM document from. The type of the SyndFeed must match
112      *        the type given to the FeedOuptut constructor.
113      * @return the W3C DOM document for the given SyndFeed.
114      * @throws FeedException thrown if the W3C DOM document for the feed could not be created.
115      *
116      */
117     public org.w3c.dom.Document ouptutW3CDom(SyndFeedI feed) throws FeedException {
118         return _feedOutput.ouptutW3CDom(feed.createRealFeed(_type));
119     }
120 
121     /***
122      * Creates a JDOM document for the given SyndFeed.
123      * <p>
124      * @param feed Abstract feed to create JDOM document from. The type of the SyndFeed must match
125      *        the type given to the FeedOuptut constructor.
126      * @return the JDOM document for the given SyndFeed.
127      * @throws FeedException thrown if the JDOM document for the feed could not be created.
128      *
129      */
130     public Document outputJDom(SyndFeedI feed) throws FeedException {
131         return _feedOutput.outputJDom(feed.createRealFeed(_type));
132     }
133 
134 }