Source Code Cross Referenced for DCModuleParser.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.module.DCModuleImpl;
020:        import com.sun.syndication.feed.module.DCSubjectImpl;
021:        import com.sun.syndication.feed.module.Module;
022:        import com.sun.syndication.feed.module.DCModule;
023:        import com.sun.syndication.feed.module.DCSubject;
024:        import com.sun.syndication.io.ModuleParser;
025:        import com.sun.syndication.io.WireFeedParser;
026:        import org.jdom.Attribute;
027:        import org.jdom.Element;
028:        import org.jdom.Namespace;
029:
030:        import java.util.ArrayList;
031:        import java.util.Iterator;
032:        import java.util.List;
033:
034:        /**
035:         * Parser for the Dublin Core module.
036:         */
037:        public class DCModuleParser implements  ModuleParser {
038:
039:            private static final String RDF_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
040:            private static final String TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/";
041:
042:            private static final Namespace DC_NS = Namespace
043:                    .getNamespace(DCModule.URI);
044:            private static final Namespace RDF_NS = Namespace
045:                    .getNamespace(RDF_URI);
046:            private static final Namespace TAXO_NS = Namespace
047:                    .getNamespace(TAXO_URI);
048:
049:            public final String getNamespaceUri() {
050:                return DCModule.URI;
051:            }
052:
053:            private final Namespace getDCNamespace() {
054:                return DC_NS;
055:            }
056:
057:            private final Namespace getRDFNamespace() {
058:                return RDF_NS;
059:            }
060:
061:            private final Namespace getTaxonomyNamespace() {
062:                return TAXO_NS;
063:            }
064:
065:            /**
066:             * Parse an element tree and return the module found in it.
067:             * <p>
068:             * @param dcRoot the root element containing the module elements.
069:             * @return the module parsed from the element tree, <i>null</i> if none.
070:             */
071:            public Module parse(Element dcRoot) {
072:                boolean foundSomething = false;
073:                DCModule dcm = new DCModuleImpl();
074:
075:                List eList = dcRoot.getChildren("title", getDCNamespace());
076:                if (eList.size() > 0) {
077:                    foundSomething = true;
078:                    dcm.setTitles(parseElementList(eList));
079:                }
080:                eList = dcRoot.getChildren("creator", getDCNamespace());
081:                if (eList.size() > 0) {
082:                    foundSomething = true;
083:                    dcm.setCreators(parseElementList(eList));
084:                }
085:                eList = dcRoot.getChildren("subject", getDCNamespace());
086:                if (eList.size() > 0) {
087:                    foundSomething = true;
088:                    dcm.setSubjects(parseSubjects(eList));
089:                }
090:                eList = dcRoot.getChildren("description", getDCNamespace());
091:                if (eList.size() > 0) {
092:                    foundSomething = true;
093:                    dcm.setDescriptions(parseElementList(eList));
094:                }
095:                eList = dcRoot.getChildren("publisher", getDCNamespace());
096:                if (eList.size() > 0) {
097:                    foundSomething = true;
098:                    dcm.setPublishers(parseElementList(eList));
099:                }
100:                eList = dcRoot.getChildren("contributor", getDCNamespace());
101:                if (eList.size() > 0) {
102:                    foundSomething = true;
103:                    dcm.setContributors(parseElementList(eList));
104:                }
105:                eList = dcRoot.getChildren("date", getDCNamespace());
106:                if (eList.size() > 0) {
107:                    foundSomething = true;
108:                    dcm.setDates(parseElementListDate(eList));
109:                }
110:                eList = dcRoot.getChildren("type", getDCNamespace());
111:                if (eList.size() > 0) {
112:                    foundSomething = true;
113:                    dcm.setTypes(parseElementList(eList));
114:                }
115:                eList = dcRoot.getChildren("format", getDCNamespace());
116:                if (eList.size() > 0) {
117:                    foundSomething = true;
118:                    dcm.setFormats(parseElementList(eList));
119:                }
120:                eList = dcRoot.getChildren("identifier", getDCNamespace());
121:                if (eList.size() > 0) {
122:                    foundSomething = true;
123:                    dcm.setIdentifiers(parseElementList(eList));
124:                }
125:                eList = dcRoot.getChildren("source", getDCNamespace());
126:                if (eList.size() > 0) {
127:                    foundSomething = true;
128:                    dcm.setSources(parseElementList(eList));
129:                }
130:                eList = dcRoot.getChildren("language", getDCNamespace());
131:                if (eList.size() > 0) {
132:                    foundSomething = true;
133:                    dcm.setLanguages(parseElementList(eList));
134:                }
135:                eList = dcRoot.getChildren("relation", getDCNamespace());
136:                if (eList.size() > 0) {
137:                    foundSomething = true;
138:                    dcm.setRelations(parseElementList(eList));
139:                }
140:                eList = dcRoot.getChildren("coverage", getDCNamespace());
141:                if (eList.size() > 0) {
142:                    foundSomething = true;
143:                    dcm.setCoverages(parseElementList(eList));
144:                }
145:                eList = dcRoot.getChildren("rights", getDCNamespace());
146:                if (eList.size() > 0) {
147:                    foundSomething = true;
148:                    dcm.setRightsList(parseElementList(eList));
149:                }
150:
151:                return (foundSomething) ? dcm : null;
152:            }
153:
154:            /**
155:             * Utility method to parse a taxonomy from an element.
156:             * <p>
157:             * @param desc the taxonomy description element.
158:             * @return the string contained in the resource of the element.
159:             */
160:            protected final String getTaxonomy(Element desc) {
161:                String d = null;
162:                Element taxo = desc.getChild("topic", getTaxonomyNamespace());
163:                if (taxo != null) {
164:                    Attribute a = taxo.getAttribute("resource",
165:                            getRDFNamespace());
166:                    if (a != null) {
167:                        d = a.getValue();
168:                    }
169:                }
170:                return d;
171:            }
172:
173:            /**
174:             * Utility method to parse a list of subjects out of a list of elements.
175:             * <p>
176:             * @param eList the element list to parse.
177:             * @return a list of subjects parsed from the elements.
178:             */
179:            protected final List parseSubjects(List eList) {
180:                List subjects = new ArrayList();
181:                for (Iterator i = eList.iterator(); i.hasNext();) {
182:                    Element eSubject = (Element) i.next();
183:                    Element eDesc = eSubject.getChild("Description",
184:                            getRDFNamespace());
185:                    if (eDesc != null) {
186:                        String taxonomy = getTaxonomy(eDesc);
187:                        List eValues = eDesc.getChildren("value",
188:                                getRDFNamespace());
189:                        for (Iterator v = eValues.iterator(); v.hasNext();) {
190:                            Element eValue = (Element) v.next();
191:                            DCSubject subject = new DCSubjectImpl();
192:                            subject.setTaxonomyUri(taxonomy);
193:                            subject.setValue(eValue.getText());
194:                            subjects.add(subject);
195:                        }
196:                    } else {
197:                        DCSubject subject = new DCSubjectImpl();
198:                        subject.setValue(eSubject.getText());
199:                        subjects.add(subject);
200:                    }
201:                }
202:
203:                return subjects;
204:            }
205:
206:            /**
207:             * Utility method to parse a list of strings out of a list of elements.
208:             * <p>
209:             * @param eList the list of elements to parse.
210:             * @return the list of strings
211:             */
212:            protected final List parseElementList(List eList) {
213:                List values = new ArrayList();
214:                for (Iterator i = eList.iterator(); i.hasNext();) {
215:                    Element e = (Element) i.next();
216:                    values.add(e.getText());
217:                }
218:
219:                return values;
220:            }
221:
222:            /**
223:             * Utility method to parse a list of dates out of a list of elements.
224:             * <p>
225:             * @param eList the list of elements to parse.
226:             * @return the list of dates.
227:             */
228:            protected final List parseElementListDate(List eList) {
229:                List values = new ArrayList();
230:                for (Iterator i = eList.iterator(); i.hasNext();) {
231:                    Element e = (Element) i.next();
232:                    values.add(DateParser.parseDate(e.getText()));
233:                }
234:
235:                return values;
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.