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