Source Code Cross Referenced for DCModuleGenerator.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.Module;
020:        import com.sun.syndication.feed.module.DCModule;
021:        import com.sun.syndication.feed.module.DCSubject;
022:        import com.sun.syndication.io.ModuleGenerator;
023:        import org.jdom.Attribute;
024:        import org.jdom.Element;
025:        import org.jdom.Namespace;
026:
027:        import java.util.ArrayList;
028:        import java.util.Date;
029:        import java.util.Iterator;
030:        import java.util.List;
031:        import java.util.Set;
032:        import java.util.HashSet;
033:        import java.util.Collections;
034:
035:        /**
036:         * Feed Generator for DublinCore Module.
037:         * <p/>
038:         *
039:         * @author Elaine Chien
040:         *
041:         */
042:        public class DCModuleGenerator implements  ModuleGenerator {
043:
044:            private static final String DC_URI = "http://purl.org/dc/elements/1.1/";
045:            private static final String TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/";
046:            private static final String RDF_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
047:
048:            private static final Namespace DC_NS = Namespace.getNamespace("dc",
049:                    DC_URI);
050:            private static final Namespace TAXO_NS = Namespace.getNamespace(
051:                    "taxo", TAXO_URI);
052:            private static final Namespace RDF_NS = Namespace.getNamespace(
053:                    "rdf", RDF_URI);
054:
055:            private static final Set NAMESPACES;
056:
057:            static {
058:                Set nss = new HashSet();
059:                nss.add(DC_NS);
060:                nss.add(TAXO_NS);
061:                nss.add(RDF_NS);
062:                NAMESPACES = Collections.unmodifiableSet(nss);
063:            }
064:
065:            public final String getNamespaceUri() {
066:                return DC_URI;
067:            }
068:
069:            private final Namespace getDCNamespace() {
070:                return DC_NS;
071:            }
072:
073:            private final Namespace getRDFNamespace() {
074:                return RDF_NS;
075:            }
076:
077:            private final Namespace getTaxonomyNamespace() {
078:                return TAXO_NS;
079:            }
080:
081:            /**
082:             * Returns a set with all the URIs (JDOM Namespace elements) this module
083:             * generator uses.
084:             * <p/>
085:             * It is used by the the feed generators to add their namespace definition
086:             * in the root element of the generated document (forward-missing of
087:             * Java 5.0 Generics).
088:             * <p/>
089:             *
090:             * @return a set with all the URIs this module generator uses.
091:             */
092:            public final Set getNamespaces() {
093:                return NAMESPACES;
094:            }
095:
096:            /**
097:             * Populate an element tree with elements for a module.
098:             * <p>
099:             * @param module the module to populate from.
100:             * @param element the root element to attach child elements to.
101:             */
102:            public final void generate(Module module, Element element) {
103:                DCModule dcModule = (DCModule) module;
104:
105:                if (dcModule.getTitle() != null) {
106:                    element.addContent(generateSimpleElementList("title",
107:                            dcModule.getTitles()));
108:                }
109:                if (dcModule.getCreator() != null) {
110:                    element.addContent(generateSimpleElementList("creator",
111:                            dcModule.getCreators()));
112:                }
113:                List subjects = dcModule.getSubjects();
114:                for (int i = 0; i < subjects.size(); i++) {
115:                    element
116:                            .addContent(generateSubjectElement((DCSubject) subjects
117:                                    .get(i)));
118:                }
119:                if (dcModule.getDescription() != null) {
120:                    element.addContent(generateSimpleElementList("description",
121:                            dcModule.getDescriptions()));
122:                }
123:                if (dcModule.getPublisher() != null) {
124:                    element.addContent(generateSimpleElementList("publisher",
125:                            dcModule.getPublishers()));
126:                }
127:                if (dcModule.getContributors() != null) {
128:                    element.addContent(generateSimpleElementList("contributor",
129:                            dcModule.getContributors()));
130:                }
131:                if (dcModule.getDate() != null) {
132:                    for (Iterator i = dcModule.getDates().iterator(); i
133:                            .hasNext();) {
134:                        element.addContent(generateSimpleElement("date",
135:                                DateParser.formatW3CDateTime((Date) i.next())));
136:                    }
137:                }
138:                if (dcModule.getType() != null) {
139:                    element.addContent(generateSimpleElementList("type",
140:                            dcModule.getTypes()));
141:                }
142:                if (dcModule.getFormat() != null) {
143:                    element.addContent(generateSimpleElementList("format",
144:                            dcModule.getFormats()));
145:                }
146:                if (dcModule.getIdentifier() != null) {
147:                    element.addContent(generateSimpleElementList("identifier",
148:                            dcModule.getIdentifiers()));
149:                }
150:                if (dcModule.getSource() != null) {
151:                    element.addContent(generateSimpleElementList("source",
152:                            dcModule.getSources()));
153:                }
154:                if (dcModule.getLanguage() != null) {
155:                    element.addContent(generateSimpleElementList("language",
156:                            dcModule.getLanguages()));
157:                }
158:                if (dcModule.getRelation() != null) {
159:                    element.addContent(generateSimpleElementList("relation",
160:                            dcModule.getRelations()));
161:                }
162:                if (dcModule.getCoverage() != null) {
163:                    element.addContent(generateSimpleElementList("coverage",
164:                            dcModule.getCoverages()));
165:                }
166:                if (dcModule.getRights() != null) {
167:                    element.addContent(generateSimpleElementList("rights",
168:                            dcModule.getRightsList()));
169:                }
170:            }
171:
172:            /**
173:             * Utility method to generate an element for a subject.
174:             * <p>
175:             * @param subject the subject to generate an element for.
176:             * @return the element for the subject.
177:             */
178:            protected final Element generateSubjectElement(DCSubject subject) {
179:                Element subjectElement = new Element("subject",
180:                        getDCNamespace());
181:
182:                if (subject.getTaxonomyUri() != null) {
183:                    Element descriptionElement = new Element("Description",
184:                            getRDFNamespace());
185:                    Element topicElement = new Element("topic",
186:                            getTaxonomyNamespace());
187:                    Attribute resourceAttribute = new Attribute("resource",
188:                            subject.getTaxonomyUri(), getRDFNamespace());
189:                    topicElement.setAttribute(resourceAttribute);
190:                    descriptionElement.addContent(topicElement);
191:
192:                    if (subject.getValue() != null) {
193:                        Element valueElement = new Element("value",
194:                                getRDFNamespace());
195:                        valueElement.addContent(subject.getValue());
196:                        descriptionElement.addContent(valueElement);
197:                    }
198:                    subjectElement.addContent(descriptionElement);
199:                } else {
200:                    subjectElement.addContent(subject.getValue());
201:                }
202:                return subjectElement;
203:            }
204:
205:            /**
206:             * Utility method to generate a single element containing a string.
207:             * <p>
208:             * @param name the name of the elment to generate.
209:             * @param value the value of the text in the element.
210:             * @return the element generated.
211:             */
212:            protected final Element generateSimpleElement(String name,
213:                    String value) {
214:                Element element = new Element(name, getDCNamespace());
215:                element.addContent(value);
216:
217:                return element;
218:            }
219:
220:            /**
221:             * Utility method to generate a list of simple elements.
222:             * <p>
223:             * @param name the name of the element list to generate.
224:             * @param value the list of values for the elements.
225:             * @return a list of Elements created.
226:             */
227:            protected final List generateSimpleElementList(String name,
228:                    List value) {
229:                List elements = new ArrayList();
230:                for (Iterator i = value.iterator(); i.hasNext();) {
231:                    elements
232:                            .add(generateSimpleElement(name, (String) i.next()));
233:                }
234:
235:                return elements;
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.