001: /*
002: * Copyright 2004 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */
017: package com.sun.syndication.io.impl;
018:
019: import com.sun.syndication.feed.WireFeed;
020: import com.sun.syndication.feed.rss.Category;
021: import com.sun.syndication.feed.rss.Channel;
022: import com.sun.syndication.feed.rss.Cloud;
023: import com.sun.syndication.feed.rss.Description;
024: import com.sun.syndication.feed.rss.Enclosure;
025: import com.sun.syndication.feed.rss.Item;
026: import com.sun.syndication.feed.rss.Source;
027: import org.jdom.Element;
028:
029: import java.util.ArrayList;
030: import java.util.List;
031:
032: /**
033: */
034: public class RSS092Parser extends RSS091UserlandParser {
035:
036: public RSS092Parser() {
037: this ("rss_0.92");
038: }
039:
040: protected RSS092Parser(String type) {
041: super (type);
042: }
043:
044: protected String getRSSVersion() {
045: return "0.92";
046: }
047:
048: protected WireFeed parseChannel(Element rssRoot) {
049: Channel channel = (Channel) super .parseChannel(rssRoot);
050:
051: Element eChannel = rssRoot.getChild("channel",
052: getRSSNamespace());
053: Element eCloud = eChannel.getChild("cloud", getRSSNamespace());
054: if (eCloud != null) {
055: Cloud cloud = new Cloud();
056: String att = eCloud.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
057: if (att != null) {
058: cloud.setDomain(att);
059: }
060: att = eCloud.getAttributeValue("port");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
061: if (att != null) {
062: cloud.setPort(Integer.parseInt(att.trim()));
063: }
064: att = eCloud.getAttributeValue("path");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
065: if (att != null) {
066: cloud.setPath(att);
067: }
068: att = eCloud.getAttributeValue("registerProcedure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
069: if (att != null) {
070: cloud.setRegisterProcedure(att);
071: }
072: att = eCloud.getAttributeValue("protocol");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
073: if (att != null) {
074: cloud.setProtocol(att);
075: }
076: channel.setCloud(cloud);
077: }
078: return channel;
079: }
080:
081: protected Item parseItem(Element rssRoot, Element eItem) {
082: Item item = super .parseItem(rssRoot, eItem);
083:
084: Element e = eItem.getChild("source", getRSSNamespace());
085: if (e != null) {
086: Source source = new Source();
087: String url = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
088: source.setUrl(url);
089: source.setValue(e.getText());
090: item.setSource(source);
091: }
092:
093: // 0.92 allows one enclosure occurrence, 0.93 multiple
094: // just saving to write some code.
095: List eEnclosures = eItem.getChildren("enclosure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
096: if (eEnclosures.size() > 0) {
097: List enclosures = new ArrayList();
098: for (int i = 0; i < eEnclosures.size(); i++) {
099: e = (Element) eEnclosures.get(i);
100:
101: Enclosure enclosure = new Enclosure();
102: String att = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
103: if (att != null) {
104: enclosure.setUrl(att);
105: }
106: att = e.getAttributeValue("length");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
107: if (att != null && att.trim().length() > 0) {
108: enclosure.setLength(Long.parseLong(att.trim()));
109: }
110: att = e.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
111: if (att != null) {
112: enclosure.setType(att);
113: }
114: enclosures.add(enclosure);
115: }
116: item.setEnclosures(enclosures);
117: }
118:
119: List eCats = eItem.getChildren("category");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
120: item.setCategories(parseCategories(eCats));
121:
122: return item;
123: }
124:
125: protected List parseCategories(List eCats) {
126: List cats = null;
127: if (eCats.size() > 0) {
128: cats = new ArrayList();
129: for (int i = 0; i < eCats.size(); i++) {
130: Category cat = new Category();
131: Element e = (Element) eCats.get(i);
132: String att = e.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
133: if (att != null) {
134: cat.setDomain(att);
135: }
136: cat.setValue(e.getText());
137: cats.add(cat);
138: }
139: }
140: return cats;
141: }
142:
143: protected Description parseItemDescription(Element rssRoot,
144: Element eDesc) {
145: Description desc = super .parseItemDescription(rssRoot, eDesc);
146: desc.setType("text/html");
147: return desc;
148: }
149:
150: }
|