Source Code Cross Referenced for WireFeedOutput.java in  » RSS-RDF » Rome » com » sun » syndication » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » Rome » com.sun.syndication.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.WireFeed;
020:        import com.sun.syndication.io.impl.FeedGenerators;
021:        import org.jdom.Document;
022:        import org.jdom.JDOMException;
023:        import org.jdom.output.DOMOutputter;
024:        import org.jdom.output.Format;
025:        import org.jdom.output.XMLOutputter;
026:
027:        import java.io.IOException;
028:        import java.io.Writer;
029:        import java.io.File;
030:        import java.io.FileWriter;
031:        import java.util.List;
032:
033:        /**
034:         * Generates an XML document (String, File, OutputStream, Writer, W3C DOM document or JDOM document)
035:         * out of an WireFeed (RSS/Atom).
036:         * <p>
037:         * It generates all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and
038:         * Atom 0.3 feeds. Generators are plugable (they must implement the ModuleParser interface).
039:         * <p>
040:         * @author Alejandro Abdelnur
041:         *
042:         */
043:        public class WireFeedOutput {
044:            private final static FeedGenerators GENERATORS = new FeedGenerators();
045:
046:            /**
047:             * Returns the list of supported output feed types.
048:             * <p>
049:             * @see WireFeed for details on the format of these strings.
050:             * <p>
051:             * @return a list of String elements with the supported output feed types.
052:             *
053:             */
054:            public static List getSupportedFeedTypes() {
055:                return GENERATORS.getSupportedFeedTypes();
056:            }
057:
058:            /**
059:             * Creates a FeedOuput instance.
060:             * <p>
061:             *
062:             */
063:            public WireFeedOutput() {
064:            }
065:
066:            /**
067:             * Creates a String with the XML representation for the given WireFeed.
068:             * <p>
069:             * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
070:             * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
071:             * the feed encoding property.
072:             * <p>
073:             * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
074:             * <p>
075:             * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
076:             *        the type given to the FeedOuptut constructor.
077:             * @return a String with the XML representation for the given WireFeed.
078:             * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
079:             * @throws FeedException thrown if the XML representation for the feed could not be created.
080:             *
081:             */
082:            public String outputString(WireFeed feed)
083:                    throws IllegalArgumentException, FeedException {
084:                Document doc = outputJDom(feed);
085:                String encoding = feed.getEncoding();
086:                Format format = Format.getPrettyFormat();
087:                if (encoding != null) {
088:                    format.setEncoding(encoding);
089:                }
090:                XMLOutputter outputter = new XMLOutputter(format);
091:                return outputter.outputString(doc);
092:            }
093:
094:            /**
095:             * Creates a File containing with the XML representation for the given WireFeed.
096:             * <p>
097:             * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform
098:             * default charset encoding is used to write the feed to the file. It is the responsibility
099:             * of the developer to ensure the feed encoding is set to the platform charset encoding.
100:             * <p>
101:             * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
102:             * <p>
103:             * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
104:             *        the type given to the FeedOuptut constructor.
105:             * @param file the file where to write the XML representation for the given WireFeed.
106:             * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
107:             * @throws IOException thrown if there was some problem writing to the File.
108:             * @throws FeedException thrown if the XML representation for the feed could not be created.
109:             *
110:             */
111:            public void output(WireFeed feed, File file)
112:                    throws IllegalArgumentException, IOException, FeedException {
113:                Writer writer = new FileWriter(file);
114:                output(feed, writer);
115:                writer.close();
116:            }
117:
118:            /**
119:             * Writes to an Writer the XML representation for the given WireFeed.
120:             * <p>
121:             * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
122:             * of the developer to ensure the Writer instance is using the same charset encoding.
123:             * <p>
124:             * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
125:             * <p>
126:             * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
127:             *        the type given to the FeedOuptut constructor.
128:             * @param writer Writer to write the XML representation for the given WireFeed.
129:             * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
130:             * @throws IOException thrown if there was some problem writing to the Writer.
131:             * @throws FeedException thrown if the XML representation for the feed could not be created.
132:             *
133:             */
134:            public void output(WireFeed feed, Writer writer)
135:                    throws IllegalArgumentException, IOException, FeedException {
136:                Document doc = outputJDom(feed);
137:                String encoding = feed.getEncoding();
138:                Format format = Format.getPrettyFormat();
139:                if (encoding != null) {
140:                    format.setEncoding(encoding);
141:                }
142:                XMLOutputter outputter = new XMLOutputter(format);
143:                outputter.output(doc, writer);
144:            }
145:
146:            /**
147:             * Creates a W3C DOM document for the given WireFeed.
148:             * <p>
149:             * This method does not use the feed encoding property.
150:             * <p>
151:             * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
152:             * <p>
153:             * @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must match
154:             *        the type given to the FeedOuptut constructor.
155:             * @return the W3C DOM document for the given WireFeed.
156:             * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
157:             * @throws FeedException thrown if the W3C DOM document for the feed could not be created.
158:             *
159:             */
160:            public org.w3c.dom.Document outputW3CDom(WireFeed feed)
161:                    throws IllegalArgumentException, FeedException {
162:                Document doc = outputJDom(feed);
163:                DOMOutputter outputter = new DOMOutputter();
164:                try {
165:                    return outputter.output(doc);
166:                } catch (JDOMException jdomEx) {
167:                    throw new FeedException("Could not create DOM", jdomEx);
168:                }
169:            }
170:
171:            /**
172:             * Creates a JDOM document for the given WireFeed.
173:             * <p>
174:             * This method does not use the feed encoding property.
175:             * <p>
176:             * NOTE: All other output methods delegate to this method.
177:             * <p>
178:             * @param feed Abstract feed to create JDOM document from. The type of the WireFeed must match
179:             *        the type given to the FeedOuptut constructor.
180:             * @return the JDOM document for the given WireFeed.
181:             * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
182:             * @throws FeedException thrown if the JDOM document for the feed could not be created.
183:             *
184:             */
185:            public Document outputJDom(WireFeed feed)
186:                    throws IllegalArgumentException, FeedException {
187:                String type = feed.getFeedType();
188:                WireFeedGenerator generator = GENERATORS.getGenerator(type);
189:                if (generator == null) {
190:                    throw new IllegalArgumentException("Invalid feed type ["
191:                            + type + "]");
192:                }
193:
194:                if (!generator.getType().equals(type)) {
195:                    throw new IllegalArgumentException("WireFeedOutput type["
196:                            + type + "] and WireFeed type [" + type
197:                            + "] don't match");
198:                }
199:                return generator.generate(feed);
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.