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.io.WireFeedParser;
20: import org.jdom.Document;
21: import java.util.List;
22:
23: /**
24: * Parses an XML document (JDOM Document) into a Feed.
25: * <p>
26: * It accepts all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and
27: * Atom 0.3 feeds.
28: * <p>
29: * The WireFeedParser is a liberal parser.
30: * <p>
31: * WireFeedParser instances are thread safe.
32: * <p>
33: * Parsers for a specific type must extend this class and register in the parser list.
34: * (Right now registration is hardcoded in the WireFeedParser constructor).
35: * <p>
36: * @author Alejandro Abdelnur
37: *
38: */
39: public class FeedParsers extends PluginManager {
40:
41: /**
42: * WireFeedParser.classes= [className] ...
43: *
44: */
45: public static final String FEED_PARSERS_KEY = "WireFeedParser.classes";
46:
47: /**
48: * Creates a parser instance.
49: * <p>
50: *
51: */
52: public FeedParsers() {
53: super (FEED_PARSERS_KEY);
54: }
55:
56: public List getSupportedFeedTypes() {
57: return getKeys();
58: }
59:
60: /**
61: * Finds the real parser type for the given document feed.
62: * <p>
63: * @param document document feed to find the parser for.
64: * @return the parser for the given document or <b>null</b> if there is no parser for that document.
65: *
66: */
67: public WireFeedParser getParserFor(Document document) {
68: List parsers = getPlugins();
69: WireFeedParser parser = null;
70: for (int i = 0; parser == null && i < parsers.size(); i++) {
71: parser = (WireFeedParser) parsers.get(i);
72: if (!parser.isMyType(document)) {
73: parser = null;
74: }
75: }
76: return parser;
77: }
78:
79: protected String getKey(Object obj) {
80: return ((WireFeedParser) obj).getType();
81: }
82:
83: }
|