01: /*
02: * Copyright 2004 Sun Microsystems, Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: *
16: */
17: package com.sun.syndication.io.impl;
18:
19: import com.sun.syndication.feed.module.Module;
20: import com.sun.syndication.feed.module.SyModule;
21: import com.sun.syndication.io.ModuleGenerator;
22: import org.jdom.Element;
23: import org.jdom.Namespace;
24:
25: import java.util.Set;
26: import java.util.HashSet;
27: import java.util.Collections;
28:
29: /**
30: * Feed Generator for SY ModuleImpl
31: * <p/>
32: *
33: * @author Elaine Chien
34: *
35: */
36:
37: public class SyModuleGenerator implements ModuleGenerator {
38:
39: private static final String SY_URI = "http://purl.org/rss/1.0/modules/syndication/";
40: private static final Namespace SY_NS = Namespace.getNamespace("sy",
41: SY_URI);
42:
43: private static final Set NAMESPACES;
44:
45: static {
46: Set nss = new HashSet();
47: nss.add(SY_NS);
48: NAMESPACES = Collections.unmodifiableSet(nss);
49: }
50:
51: public String getNamespaceUri() {
52: return SY_URI;
53: }
54:
55: /**
56: * Returns a set with all the URIs (JDOM Namespace elements) this module generator uses.
57: * <p/>
58: * It is used by the the feed generators to add their namespace definition in
59: * the root element of the generated document (forward-missing of Java 5.0 Generics).
60: * <p/>
61: *
62: * @return a set with all the URIs (JDOM Namespace elements) this module generator uses.
63: */
64: public Set getNamespaces() {
65: return NAMESPACES;
66: }
67:
68: public void generate(Module module, Element element) {
69:
70: SyModule syModule = (SyModule) module;
71:
72: Element updatePeriodElement = new Element("updatePeriod", SY_NS);
73: updatePeriodElement.addContent(syModule.getUpdatePeriod()
74: .toString());
75: element.addContent(updatePeriodElement);
76:
77: Element updateFrequencyElement = new Element("updateFrequency",
78: SY_NS);
79: updateFrequencyElement.addContent(String.valueOf(syModule
80: .getUpdateFrequency()));
81: element.addContent(updateFrequencyElement);
82:
83: Element updateBaseElement = new Element("updateBase", SY_NS);
84: updateBaseElement.addContent(DateParser
85: .formatW3CDateTime(syModule.getUpdateBase()));
86: element.addContent(updateBaseElement);
87: }
88: }
|