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.Category;
020: import com.sun.syndication.feed.rss.Channel;
021: import com.sun.syndication.feed.rss.Guid;
022: import com.sun.syndication.feed.rss.Item;
023: import org.jdom.Element;
024:
025: import java.util.List;
026:
027: /**
028: * Feed Generator for RSS 2.0
029: * <p/>
030: *
031: * @author Elaine Chien
032: *
033: */
034:
035: public class RSS20Generator extends RSS094Generator {
036:
037: public RSS20Generator() {
038: this ("rss_2.0", "2.0");
039: }
040:
041: protected RSS20Generator(String feedType, String version) {
042: super (feedType, version);
043: }
044:
045: protected void populateChannel(Channel channel, Element eChannel) {
046: super .populateChannel(channel, eChannel);
047:
048: String generator = channel.getGenerator();
049: if (generator != null) {
050: eChannel.addContent(generateSimpleElement("generator",
051: generator));
052: }
053:
054: int ttl = channel.getTtl();
055: if (ttl > -1) {
056: eChannel.addContent(generateSimpleElement("ttl", String
057: .valueOf(ttl)));
058: }
059:
060: List categories = channel.getCategories();
061: for (int i = 0; i < categories.size(); i++) {
062: eChannel
063: .addContent(generateCategoryElement((Category) categories
064: .get(i)));
065: }
066:
067: }
068:
069: public void populateItem(Item item, Element eItem, int index) {
070: super .populateItem(item, eItem, index);
071:
072: Element eDescription = eItem.getChild("description",
073: getFeedNamespace());
074: if (eDescription != null)
075: eDescription.removeAttribute("type");
076:
077: String author = item.getAuthor();
078: if (author != null) {
079: eItem.addContent(generateSimpleElement("author", author));
080: }
081:
082: String comments = item.getComments();
083: if (comments != null) {
084: eItem
085: .addContent(generateSimpleElement("comments",
086: comments));
087: }
088:
089: Guid guid = item.getGuid();
090: if (guid != null) {
091: Element eGuid = generateSimpleElement("guid", guid
092: .getValue());
093: if (!guid.isPermaLink()) {
094: eGuid.setAttribute("isPermaLink", "false");
095: }
096: eItem.addContent(eGuid);
097: }
098: }
099:
100: }
|