Source Code Cross Referenced for RSS091UserlandParser.java in  » RSS-RDF » Rome » com » sun » syndication » io » impl » 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.impl 
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.impl;
018:
019:        import com.sun.syndication.feed.WireFeed;
020:        import com.sun.syndication.feed.rss.Channel;
021:        import com.sun.syndication.feed.rss.Content;
022:        import com.sun.syndication.feed.rss.Description;
023:        import com.sun.syndication.feed.rss.Image;
024:        import com.sun.syndication.feed.rss.Item;
025:        import org.jdom.Attribute;
026:        import org.jdom.Document;
027:        import org.jdom.Element;
028:        import org.jdom.Namespace;
029:
030:        import java.util.*;
031:
032:        /**
033:         */
034:        public class RSS091UserlandParser extends RSS090Parser {
035:
036:            public RSS091UserlandParser() {
037:                this ("rss_0.91U");
038:            }
039:
040:            protected RSS091UserlandParser(String type) {
041:                super (type);
042:            }
043:
044:            public boolean isMyType(Document document) {
045:                boolean ok;
046:                Element rssRoot = document.getRootElement();
047:                ok = rssRoot.getName().equals("rss");
048:                if (ok) {
049:                    ok = false;
050:                    Attribute version = rssRoot.getAttribute("version");
051:                    if (version != null) {
052:                        ok = version.getValue().equals(getRSSVersion());
053:                    }
054:                }
055:                return ok;
056:            }
057:
058:            protected String getRSSVersion() {
059:                return "0.91";
060:            }
061:
062:            protected Namespace getRSSNamespace() {
063:                return Namespace.getNamespace("");
064:            }
065:
066:            /**
067:             * To be overriden by RSS 0.91 Netscape and RSS 0.94
068:             */
069:            protected boolean isHourFormat24(Element rssRoot) {
070:                return true;
071:            }
072:
073:            /**
074:             * Parses the root element of an RSS document into a Channel bean.
075:             * <p/>
076:             * It first invokes super.parseChannel and then parses and injects the following
077:             * properties if present: language, pubDate, rating and copyright.
078:             * <p/>
079:             *
080:             * @param rssRoot the root element of the RSS document to parse.
081:             * @return the parsed Channel bean.
082:             */
083:            protected WireFeed parseChannel(Element rssRoot) {
084:                Channel channel = (Channel) super .parseChannel(rssRoot);
085:
086:                Element eChannel = rssRoot.getChild("channel",
087:                        getRSSNamespace());
088:
089:                Element e = eChannel.getChild("language", getRSSNamespace());
090:                if (e != null) {
091:                    channel.setLanguage(e.getText());
092:                }
093:                e = eChannel.getChild("rating", getRSSNamespace());
094:                if (e != null) {
095:                    channel.setRating(e.getText());
096:                }
097:                e = eChannel.getChild("copyright", getRSSNamespace());
098:                if (e != null) {
099:                    channel.setCopyright(e.getText());
100:                }
101:                e = eChannel.getChild("pubDate", getRSSNamespace());
102:                if (e != null) {
103:                    channel.setPubDate(DateParser.parseDate(e.getText()));
104:                }
105:                e = eChannel.getChild("lastBuildDate", getRSSNamespace());
106:                if (e != null) {
107:                    channel.setLastBuildDate(DateParser.parseDate(e.getText()));
108:                }
109:                e = eChannel.getChild("docs", getRSSNamespace());
110:                if (e != null) {
111:                    channel.setDocs(e.getText());
112:                }
113:                e = eChannel.getChild("docs", getRSSNamespace());
114:                if (e != null) {
115:                    channel.setDocs(e.getText());
116:                }
117:                e = eChannel.getChild("managingEditor", getRSSNamespace());
118:                if (e != null) {
119:                    channel.setManagingEditor(e.getText());
120:                }
121:                e = eChannel.getChild("webMaster", getRSSNamespace());
122:                if (e != null) {
123:                    channel.setWebMaster(e.getText());
124:                }
125:                e = eChannel.getChild("skipHours");
126:                if (e != null) {
127:                    List skipHours = new ArrayList();
128:                    List eHours = e.getChildren("hour", getRSSNamespace());
129:                    for (int i = 0; i < eHours.size(); i++) {
130:                        Element eHour = (Element) eHours.get(i);
131:                        skipHours.add(new Integer(eHour.getText().trim()));
132:                    }
133:                    channel.setSkipHours(skipHours);
134:                }
135:
136:                e = eChannel.getChild("skipDays");
137:                if (e != null) {
138:                    List skipDays = new ArrayList();
139:                    List eDays = e.getChildren("day", getRSSNamespace());
140:                    for (int i = 0; i < eDays.size(); i++) {
141:                        Element eDay = (Element) eDays.get(i);
142:                        skipDays.add(eDay.getText().trim());
143:                    }
144:                    channel.setSkipDays(skipDays);
145:                }
146:                return channel;
147:            }
148:
149:            /**
150:             * Parses the root element of an RSS document looking for  image information.
151:             * <p/>
152:             * It first invokes super.parseImage and then parses and injects the following
153:             * properties if present: url, link, width, height and description.
154:             * <p/>
155:             *
156:             * @param rssRoot the root element of the RSS document to parse for image information.
157:             * @return the parsed RSSImage bean.
158:             */
159:            protected Image parseImage(Element rssRoot) {
160:                Image image = super .parseImage(rssRoot);
161:                if (image != null) {
162:                    Element eImage = getImage(rssRoot);
163:                    Element e = eImage.getChild("width", getRSSNamespace());
164:                    if (e != null) {
165:                        image.setWidth(Integer.parseInt(e.getText().trim()));
166:                    }
167:                    e = eImage.getChild("height", getRSSNamespace());
168:                    if (e != null) {
169:                        image.setHeight(Integer.parseInt(e.getText().trim()));
170:                    }
171:                    e = eImage.getChild("description", getRSSNamespace());
172:                    if (e != null) {
173:                        image.setDescription(e.getText());
174:                    }
175:                }
176:                return image;
177:            }
178:
179:            /**
180:             * It looks for the 'item' elements under the 'channel' elemment.
181:             */
182:            protected List getItems(Element rssRoot) {
183:                Element eChannel = rssRoot.getChild("channel",
184:                        getRSSNamespace());
185:                return (eChannel != null) ? eChannel.getChildren("item",
186:                        getRSSNamespace()) : Collections.EMPTY_LIST;
187:            }
188:
189:            /**
190:             * It looks for the 'image' elements under the 'channel' elemment.
191:             */
192:            protected Element getImage(Element rssRoot) {
193:                Element eChannel = rssRoot.getChild("channel",
194:                        getRSSNamespace());
195:                return (eChannel != null) ? eChannel.getChild("image",
196:                        getRSSNamespace()) : null;
197:            }
198:
199:            /**
200:             * To be overriden by RSS 0.91 Netscape parser
201:             */
202:            protected String getTextInputLabel() {
203:                return "textInput";
204:            }
205:
206:            /**
207:             * It looks for the 'textinput' elements under the 'channel' elemment.
208:             */
209:            protected Element getTextInput(Element rssRoot) {
210:                String elementName = getTextInputLabel();
211:                Element eChannel = rssRoot.getChild("channel",
212:                        getRSSNamespace());
213:                return (eChannel != null) ? eChannel.getChild(elementName,
214:                        getRSSNamespace()) : null;
215:            }
216:
217:            /**
218:             * Parses an item element of an RSS document looking for item information.
219:             * <p/>
220:             * It first invokes super.parseItem and then parses and injects the description property if present.
221:             * <p/>
222:             *
223:             * @param rssRoot the root element of the RSS document in case it's needed for context.
224:             * @param eItem the item element to parse.
225:             * @return the parsed RSSItem bean.
226:             */
227:            protected Item parseItem(Element rssRoot, Element eItem) {
228:                Item item = super .parseItem(rssRoot, eItem);
229:                Element e = eItem.getChild("description", getRSSNamespace());
230:                if (e != null) {
231:                    item.setDescription(parseItemDescription(rssRoot, e));
232:                }
233:                Element ce = eItem.getChild("encoded", getContentNamespace());
234:                if (ce != null) {
235:                    Content content = new Content();
236:                    content.setType(Content.HTML);
237:                    content.setValue(ce.getText());
238:                    item.setContent(content);
239:                }
240:                return item;
241:            }
242:
243:            protected Description parseItemDescription(Element rssRoot,
244:                    Element eDesc) {
245:                Description desc = new Description();
246:                desc.setType("text/plain");
247:                desc.setValue(eDesc.getText());
248:                return desc;
249:            }
250:
251:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.