KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > syndication > io > impl > SyModuleGenerator


1 /*
2  * Copyright 2004 Sun Microsystems, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Collections JavaDoc;
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 JavaDoc SY_URI = "http://purl.org/rss/1.0/modules/syndication/";
40     private static final Namespace SY_NS = Namespace.getNamespace("sy", SY_URI);
41
42     private static final Set JavaDoc NAMESPACES;
43
44     static {
45         Set JavaDoc nss = new HashSet JavaDoc();
46         nss.add(SY_NS);
47         NAMESPACES = Collections.unmodifiableSet(nss);
48     }
49
50     public String JavaDoc getNamespaceUri() {
51         return SY_URI;
52     }
53
54     /**
55      * Returns a set with all the URIs (JDOM Namespace elements) this module generator uses.
56      * <p/>
57      * It is used by the the feed generators to add their namespace definition in
58      * the root element of the generated document (forward-missing of Java 5.0 Generics).
59      * <p/>
60      *
61      * @return a set with all the URIs (JDOM Namespace elements) this module generator uses.
62      */

63     public Set JavaDoc getNamespaces() {
64         return NAMESPACES;
65     }
66
67     public void generate(Module module, Element element) {
68
69         SyModule syModule = (SyModule)module;
70
71         Element updatePeriodElement = new Element("updatePeriod", SY_NS);
72         updatePeriodElement.addContent(syModule.getUpdatePeriod().toString());
73         element.addContent(updatePeriodElement);
74
75         Element updateFrequencyElement = new Element("updateFrequency", SY_NS);
76         updateFrequencyElement.addContent(String.valueOf(syModule.getUpdateFrequency()));
77         element.addContent(updateFrequencyElement);
78
79         Element updateBaseElement = new Element("updateBase", SY_NS);
80         updateBaseElement.addContent(DateParser.formatW3CDateTime(syModule.getUpdateBase()));
81         element.addContent(updateBaseElement);
82     }
83 }
84
Popular Tags