001: /*
002: * Copyright 2004 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */
017: package com.sun.syndication.io;
018:
019: import com.sun.syndication.feed.synd.SyndFeed;
020: import org.jdom.Document;
021:
022: import java.io.File;
023: import java.io.IOException;
024: import java.io.Writer;
025:
026: /**
027: * Generates an XML document (String, File, OutputStream, Writer, W3C DOM document or JDOM document)
028: * out of an SyndFeedImpl..
029: * <p>
030: * It delegates to a WireFeedOutput to generate all feed types.
031: * <p>
032: * @author Alejandro Abdelnur
033: *
034: */
035: public class SyndFeedOutput {
036: private WireFeedOutput _feedOutput;
037:
038: /**
039: * Creates a SyndFeedOutput instance.
040: * <p>
041: *
042: */
043: public SyndFeedOutput() {
044: _feedOutput = new WireFeedOutput();
045: }
046:
047: /**
048: * Creates a String with the XML representation for the given SyndFeedImpl.
049: * <p>
050: * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
051: * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
052: * the feed encoding property.
053: * <p>
054: * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match
055: * the type given to the FeedOuptut constructor.
056: * @return a String with the XML representation for the given SyndFeedImpl.
057: * @throws FeedException thrown if the XML representation for the feed could not be created.
058: *
059: */
060: public String outputString(SyndFeed feed) throws FeedException {
061: return _feedOutput.outputString(feed.createWireFeed());
062: }
063:
064: /**
065: * Creates a File containing with the XML representation for the given SyndFeedImpl.
066: * <p>
067: * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform
068: * default charset encoding is used to write the feed to the file. It is the responsibility
069: * of the developer to ensure the feed encoding is set to the platform charset encoding.
070: * <p>
071: * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match
072: * the type given to the FeedOuptut constructor.
073: * @param file the file where to write the XML representation for the given SyndFeedImpl.
074: * @throws IOException thrown if there was some problem writing to the File.
075: * @throws FeedException thrown if the XML representation for the feed could not be created.
076: *
077: */
078: public void output(SyndFeed feed, File file) throws IOException,
079: FeedException {
080: _feedOutput.output(feed.createWireFeed(), file);
081: }
082:
083: /**
084: * Writes to an Writer the XML representation for the given SyndFeedImpl.
085: * <p>
086: * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
087: * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
088: * the feed encoding property.
089: * <p>
090: * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match
091: * the type given to the FeedOuptut constructor.
092: * @param writer Writer to write the XML representation for the given SyndFeedImpl.
093: * @throws IOException thrown if there was some problem writing to the Writer.
094: * @throws FeedException thrown if the XML representation for the feed could not be created.
095: *
096: */
097: public void output(SyndFeed feed, Writer writer)
098: throws IOException, FeedException {
099: _feedOutput.output(feed.createWireFeed(), writer);
100: }
101:
102: /**
103: * Creates a W3C DOM document for the given SyndFeedImpl.
104: * <p>
105: * This method does not use the feed encoding property.
106: * <p>
107: * @param feed Abstract feed to create W3C DOM document from. The type of the SyndFeedImpl must match
108: * the type given to the FeedOuptut constructor.
109: * @return the W3C DOM document for the given SyndFeedImpl.
110: * @throws FeedException thrown if the W3C DOM document for the feed could not be created.
111: *
112: */
113: public org.w3c.dom.Document outputW3CDom(SyndFeed feed)
114: throws FeedException {
115: return _feedOutput.outputW3CDom(feed.createWireFeed());
116: }
117:
118: /**
119: * Creates a JDOM document for the given SyndFeedImpl.
120: * <p>
121: * This method does not use the feed encoding property.
122: * <p>
123: * @param feed Abstract feed to create JDOM document from. The type of the SyndFeedImpl must match
124: * the type given to the FeedOuptut constructor.
125: * @return the JDOM document for the given SyndFeedImpl.
126: * @throws FeedException thrown if the JDOM document for the feed could not be created.
127: *
128: */
129: public Document outputJDom(SyndFeed feed) throws FeedException {
130: return _feedOutput.outputJDom(feed.createWireFeed());
131: }
132:
133: }
|