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.Channel;
021: import com.sun.syndication.feed.rss.Description;
022: import com.sun.syndication.feed.rss.Guid;
023: import com.sun.syndication.feed.rss.Item;
024: import org.jdom.Element;
025:
026: import java.util.List;
027:
028: /**
029: */
030: public class RSS094Parser extends RSS093Parser {
031:
032: public RSS094Parser() {
033: this ("rss_0.94");
034: }
035:
036: protected RSS094Parser(String type) {
037: super (type);
038: }
039:
040: protected String getRSSVersion() {
041: return "0.94";
042: }
043:
044: protected WireFeed parseChannel(Element rssRoot) {
045: Channel channel = (Channel) super .parseChannel(rssRoot);
046: Element eChannel = rssRoot.getChild("channel",
047: getRSSNamespace());
048:
049: List eCats = eChannel
050: .getChildren("category", getRSSNamespace());
051: channel.setCategories(parseCategories(eCats));
052:
053: Element eTtl = eChannel.getChild("ttl", getRSSNamespace());
054: if (eTtl != null && eTtl.getText() != null) {
055: Integer ttlValue = null;
056: try {
057: ttlValue = new Integer(eTtl.getText());
058: } catch (NumberFormatException nfe) {
059: ; //let it go by
060: }
061: if (ttlValue != null) {
062: channel.setTtl(ttlValue.intValue());
063: }
064: }
065:
066: return channel;
067: }
068:
069: public Item parseItem(Element rssRoot, Element eItem) {
070: Item item = super .parseItem(rssRoot, eItem);
071: item.setExpirationDate(null);
072:
073: Element e = eItem.getChild("author", getRSSNamespace());
074: if (e != null) {
075: item.setAuthor(e.getText());
076: }
077:
078: e = eItem.getChild("guid", getRSSNamespace());
079: if (e != null) {
080: Guid guid = new Guid();
081: String att = e.getAttributeValue("isPermaLink");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
082: if (att != null) {
083: guid.setPermaLink(att.equalsIgnoreCase("true"));
084: }
085: guid.setValue(e.getText());
086: item.setGuid(guid);
087: }
088:
089: e = eItem.getChild("comments", getRSSNamespace());
090: if (e != null) {
091: item.setComments(e.getText());
092: }
093:
094: return item;
095: }
096:
097: protected Description parseItemDescription(Element rssRoot,
098: Element eDesc) {
099: Description desc = super .parseItemDescription(rssRoot, eDesc);
100: String att = eDesc.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
101: if (att == null) {
102: att = "text/html";
103: }
104: desc.setType(att);
105: return desc;
106: }
107:
108: }
|