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.rss.Description;
020: import com.sun.syndication.feed.rss.Item;
021: import com.sun.syndication.feed.rss.Channel;
022: import com.sun.syndication.io.FeedException;
023: import org.jdom.Element;
024: import org.jdom.Namespace;
025:
026: import java.util.List;
027:
028: /**
029: * Feed Generator for RSS 1.0
030: * <p/>
031: *
032: * @author Elaine Chien
033: *
034: */
035:
036: public class RSS10Generator extends RSS090Generator {
037:
038: private static final String RSS_URI = "http://purl.org/rss/1.0/";
039: private static final Namespace RSS_NS = Namespace
040: .getNamespace(RSS_URI);
041:
042: public RSS10Generator() {
043: super ("rss_1.0");
044: }
045:
046: protected RSS10Generator(String feedType) {
047: super (feedType);
048: }
049:
050: protected Namespace getFeedNamespace() {
051: return RSS_NS;
052: }
053:
054: protected void populateChannel(Channel channel, Element eChannel) {
055: super .populateChannel(channel, eChannel);
056: if (channel.getUri() != null) {
057: eChannel.setAttribute("about", channel.getUri(),
058: getRDFNamespace());
059: }
060: List items = channel.getItems();
061: if (items.size() > 0) {
062: Element eItems = new Element("items", getFeedNamespace());
063: Element eSeq = new Element("Seq", getRDFNamespace());
064: for (int i = 0; i < items.size(); i++) {
065: Item item = (Item) items.get(i);
066: Element eLi = new Element("li", getRDFNamespace());
067: String link = item.getLink();
068: if (link != null) {
069: eLi.setAttribute("resource", link);
070: }
071: eSeq.addContent(eLi);
072: }
073: eItems.addContent(eSeq);
074: eChannel.addContent(eItems);
075: }
076: }
077:
078: protected void populateItem(Item item, Element eItem, int index) {
079: super .populateItem(item, eItem, index);
080: String link = item.getLink();
081: String uri = item.getUri();
082:
083: if (uri != null) {
084: eItem.setAttribute("about", uri, getRDFNamespace());
085: } else if (link != null) {
086: eItem.setAttribute("about", link, getRDFNamespace());
087: }
088:
089: Description description = item.getDescription();
090: if (description != null) {
091: eItem.addContent(generateSimpleElement("description",
092: description.getValue()));
093: }
094: if (item.getModule(getContentNamespace().getURI()) == null
095: && item.getContent() != null) {
096: Element elem = new Element("encoded", getContentNamespace());
097: elem.addContent(item.getContent().getValue());
098: eItem.addContent(elem);
099: }
100: }
101:
102: protected void checkChannelConstraints(Element eChannel)
103: throws FeedException {
104: checkNotNullAndLength(eChannel, "title", 0, -1);
105: checkNotNullAndLength(eChannel, "description", 0, -1);
106: checkNotNullAndLength(eChannel, "link", 0, -1);
107: }
108:
109: protected void checkImageConstraints(Element eImage)
110: throws FeedException {
111: checkNotNullAndLength(eImage, "title", 0, -1);
112: checkNotNullAndLength(eImage, "url", 0, -1);
113: checkNotNullAndLength(eImage, "link", 0, -1);
114: }
115:
116: protected void checkTextInputConstraints(Element eTextInput)
117: throws FeedException {
118: checkNotNullAndLength(eTextInput, "title", 0, -1);
119: checkNotNullAndLength(eTextInput, "description", 0, -1);
120: checkNotNullAndLength(eTextInput, "name", 0, -1);
121: checkNotNullAndLength(eTextInput, "link", 0, -1);
122: }
123:
124: protected void checkItemsConstraints(Element parent)
125: throws FeedException {
126: }
127:
128: protected void checkItemConstraints(Element eItem)
129: throws FeedException {
130: checkNotNullAndLength(eItem, "title", 0, -1);
131: checkNotNullAndLength(eItem, "link", 0, -1);
132: }
133:
134: }
|