KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > util > rome > ContentModuleGenerator


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 org.apache.roller.util.rome;
18
19 import java.util.Collections JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import org.jdom.Element;
24 import org.jdom.Namespace;
25
26 import com.sun.syndication.feed.module.Module;
27 import com.sun.syndication.io.ModuleGenerator;
28
29 public class ContentModuleGenerator implements ModuleGenerator {
30     private static final Namespace CONTENT_NS =
31         Namespace.getNamespace(ContentModule.URI);
32
33     public String JavaDoc getNamespaceUri() {
34         return ContentModule.URI;
35     }
36
37     private static final Set JavaDoc NAMESPACES;
38
39     static {
40         Set JavaDoc nss = new HashSet JavaDoc();
41         nss.add(CONTENT_NS);
42         NAMESPACES = Collections.unmodifiableSet(nss);
43     }
44
45     public Set JavaDoc getNamespaces() {
46         return NAMESPACES;
47     }
48
49     public void generate(Module module, Element element) {
50         ContentModule fm = (ContentModule)module;
51         if (fm.getEncoded() != null) {
52             element.addContent(generateSimpleElement("encoding", fm.getEncoded()));
53         }
54     }
55
56     protected Element generateSimpleElement(String JavaDoc name, String JavaDoc value) {
57         Element element = new Element(name, CONTENT_NS);
58         element.addContent(value);
59         return element;
60     }
61
62 }
63
Popular Tags