01: package com.sun.syndication.io.impl;
02:
03: import com.sun.syndication.feed.WireFeed;
04: import com.sun.syndication.feed.module.Extendable;
05: import com.sun.syndication.io.WireFeedParser;
06: import java.util.ArrayList;
07: import java.util.Iterator;
08: import org.jdom.Element;
09:
10: import java.util.List;
11: import org.jdom.Namespace;
12:
13: /**
14: * @author Alejandro Abdelnur
15: */
16: public abstract class BaseWireFeedParser implements WireFeedParser {
17: /**
18: * [TYPE].feed.ModuleParser.classes= [className] ...
19: *
20: */
21: private static final String FEED_MODULE_PARSERS_POSFIX_KEY = ".feed.ModuleParser.classes";
22:
23: /**
24: * [TYPE].item.ModuleParser.classes= [className] ...
25: *
26: */
27: private static final String ITEM_MODULE_PARSERS_POSFIX_KEY = ".item.ModuleParser.classes";
28:
29: private String _type;
30: private ModuleParsers _feedModuleParsers;
31: private ModuleParsers _itemModuleParsers;
32:
33: protected BaseWireFeedParser(String type) {
34: _type = type;
35: _feedModuleParsers = new ModuleParsers(type
36: + FEED_MODULE_PARSERS_POSFIX_KEY, this );
37: _itemModuleParsers = new ModuleParsers(type
38: + ITEM_MODULE_PARSERS_POSFIX_KEY, this );
39: }
40:
41: /**
42: * Returns the type of feed the parser handles.
43: * <p>
44: * @see WireFeed for details on the format of this string.
45: * <p>
46: * @return the type of feed the parser handles.
47: *
48: */
49: public String getType() {
50: return _type;
51: }
52:
53: protected List parseFeedModules(Element feedElement) {
54: return _feedModuleParsers.parseModules(feedElement);
55: }
56:
57: protected List parseItemModules(Element itemElement) {
58: return _itemModuleParsers.parseModules(itemElement);
59: }
60:
61: protected List extractForeignMarkup(Element e, Extendable ext,
62: Namespace basens) {
63: ArrayList foreignMarkup = new ArrayList();
64: Iterator children = e.getChildren().iterator();
65: while (children.hasNext()) {
66: Element elem = (Element) children.next();
67: if (
68: // if elemet not in the RSS namespace
69: !basens.equals(elem.getNamespace())
70: // and elem was not handled by a module
71: && null == ext.getModule(elem.getNamespaceURI())) {
72:
73: // save it as foreign markup,
74: // but we can't detach it while we're iterating
75: foreignMarkup.add(elem.clone());
76: }
77: }
78: // Now we can detach the foreign markup elements
79: Iterator fm = foreignMarkup.iterator();
80: while (fm.hasNext()) {
81: Element elem = (Element) fm.next();
82: elem.detach();
83: }
84: return foreignMarkup;
85: }
86: }
|