01: package com.sun.syndication.io.impl;
02:
03: import com.sun.syndication.io.WireFeedGenerator;
04: import org.jdom.Element;
05: import org.jdom.Namespace;
06:
07: import java.util.HashSet;
08: import java.util.Iterator;
09: import java.util.List;
10: import java.util.Set;
11:
12: /**
13: * @author Alejandro Abdelnur
14: */
15: public abstract class BaseWireFeedGenerator implements
16: WireFeedGenerator {
17:
18: /**
19: * [TYPE].feed.ModuleParser.classes= [className] ...
20: *
21: */
22: private static final String FEED_MODULE_GENERATORS_POSFIX_KEY = ".feed.ModuleGenerator.classes";
23:
24: /**
25: * [TYPE].item.ModuleParser.classes= [className] ...
26: *
27: */
28: private static final String ITEM_MODULE_GENERATORS_POSFIX_KEY = ".item.ModuleGenerator.classes";
29:
30: private String _type;
31: private ModuleGenerators _feedModuleGenerators;
32: private ModuleGenerators _itemModuleGenerators;
33: private Namespace[] _allModuleNamespaces;
34:
35: protected BaseWireFeedGenerator(String type) {
36: _type = type;
37: _feedModuleGenerators = new ModuleGenerators(type
38: + FEED_MODULE_GENERATORS_POSFIX_KEY, this );
39: _itemModuleGenerators = new ModuleGenerators(type
40: + ITEM_MODULE_GENERATORS_POSFIX_KEY, this );
41: Set allModuleNamespaces = new HashSet();
42: Iterator i = _feedModuleGenerators.getAllNamespaces()
43: .iterator();
44: while (i.hasNext()) {
45: allModuleNamespaces.add(i.next());
46: }
47: i = _itemModuleGenerators.getAllNamespaces().iterator();
48: while (i.hasNext()) {
49: allModuleNamespaces.add(i.next());
50: }
51: _allModuleNamespaces = new Namespace[allModuleNamespaces.size()];
52: allModuleNamespaces.toArray(_allModuleNamespaces);
53: }
54:
55: public String getType() {
56: return _type;
57: }
58:
59: protected void generateModuleNamespaceDefs(Element root) {
60: for (int i = 0; i < _allModuleNamespaces.length; i++) {
61: root.addNamespaceDeclaration(_allModuleNamespaces[i]);
62: }
63: }
64:
65: protected void generateFeedModules(List modules, Element feed) {
66: _feedModuleGenerators.generateModules(modules, feed);
67: }
68:
69: public void generateItemModules(List modules, Element item) {
70: _itemModuleGenerators.generateModules(modules, item);
71: }
72:
73: protected void generateForeignMarkup(Element e, List foreignMarkup) {
74: if (foreignMarkup != null) {
75: Iterator elems = (Iterator) foreignMarkup.iterator();
76: while (elems.hasNext()) {
77: Element elem = (Element) elems.next();
78: e.addContent(elem);
79: }
80: }
81: }
82: }
|