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