Source Code Cross Referenced for EntrySerializer.java in  » Portal » Open-Portal » com » sun » portal » app » blog » 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 » Portal » Open Portal » com.sun.portal.app.blog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved.
003:         *
004:         * Sun Microsystems, Inc. has intellectual property rights relating to
005:         * technology embodied in the product that is described in this document.
006:         * In particular, and without limitation, these intellectual property
007:         * rights may include one or more of the U.S. patents listed at
008:         * http://www.sun.com/patents and one or more additional patents or
009:         * pending patent applications in the U.S. and in other countries.
010:         *
011:         * U.S. Government Rights - Commercial software. Government users are subject
012:         * to the Sun Microsystems, Inc. standard license agreement and applicable
013:         * provisions of the FAR and its supplements. Use is subject to license terms.
014:         * This distribution may include materials developed by third parties.
015:         * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
016:         * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
017:         */
018:        package com.sun.portal.app.blog;
019:
020:        import com.sun.syndication.feed.atom.Entry;
021:        import com.sun.syndication.feed.atom.Feed;
022:        import com.sun.syndication.io.FeedException;
023:        import com.sun.syndication.io.WireFeedOutput;
024:        import com.sun.syndication.io.WireFeedInput;
025:        import java.io.ByteArrayInputStream;
026:        import java.io.IOException;
027:        import java.io.InputStream;
028:        import java.io.StringWriter;
029:        import java.util.Collections;
030:        import java.util.List;
031:        import org.jdom.input.SAXBuilder;
032:        import org.jdom.Document;
033:        import org.jdom.Element;
034:        import org.jdom.output.Format;
035:        import org.jdom.output.XMLOutputter;
036:        import org.jdom.JDOMException;
037:
038:        public class EntrySerializer {
039:            private static final String FEED_TYPE = "atom_1.0";
040:
041:            /**
042:             * Serialize a ROME feed.
043:             * Utility method to make up for ROME shortcoming:
044:             * ROME can only serialize entire feeds, not individual elements
045:             *
046:             * We'd be better off if the APP protocol just used feeds, always, and not
047:             * individual entries is some cases.
048:             */
049:            public static String toString(Entry entry)
050:                    throws IllegalArgumentException, FeedException, IOException {
051:                // Build a feed containing only the entry
052:                List entries = Collections.singletonList(entry);
053:                Feed feed = new Feed();
054:                feed.setFeedType("atom_1.0");
055:                feed.setEntries(entries);
056:
057:                // Get Rome to output feed as a JDOM document
058:                WireFeedOutput wireFeedOutput = new WireFeedOutput();
059:                Document feedDoc = wireFeedOutput.outputJDom(feed);
060:
061:                // Grab entry element from feed and get JDOM to serialize it
062:                Element entryElement = (Element) feedDoc.getRootElement()
063:                        .getChildren().get(0);
064:                XMLOutputter outputter = new XMLOutputter();
065:                outputter.setFormat(Format.getPrettyFormat());
066:
067:                StringWriter sw = new StringWriter();
068:                outputter.output(entryElement, sw);
069:                String serializedForm = sw.toString();
070:
071:                return serializedForm;
072:            }
073:
074:            public static InputStream toInputStream(Entry entry)
075:                    throws IllegalArgumentException, FeedException, IOException {
076:                String serializedForm = toString(entry);
077:                InputStream is = new ByteArrayInputStream(serializedForm
078:                        .getBytes("UTF-8"));
079:
080:                return is;
081:            }
082:
083:            public static Entry toEntry(InputStream is) throws JDOMException,
084:                    IOException, IllegalArgumentException, FeedException {
085:                // Parse entry into JDOM tree
086:                SAXBuilder builder = new SAXBuilder();
087:                Document entryDoc = builder.build(is);
088:                Element fetchedEntryElement = entryDoc.getRootElement();
089:                fetchedEntryElement.detach();
090:
091:                // Put entry into a JDOM document with 'feed' root so that Rome can handle it
092:                Feed feed = new Feed();
093:                feed.setFeedType(FEED_TYPE);
094:                WireFeedOutput wireFeedOutput = new WireFeedOutput();
095:                Document feedDoc = wireFeedOutput.outputJDom(feed);
096:                feedDoc.getRootElement().addContent(fetchedEntryElement);
097:
098:                WireFeedInput input = new WireFeedInput();
099:                Feed parsedFeed = (Feed) input.build(feedDoc);
100:
101:                return (Entry) parsedFeed.getEntries().get(0);
102:            }
103:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.