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.feed.synd.impl;
018:
019: import com.sun.syndication.feed.WireFeed;
020: import com.sun.syndication.feed.rss.Channel;
021: import com.sun.syndication.feed.rss.Content;
022: import com.sun.syndication.feed.rss.Description;
023: import com.sun.syndication.feed.rss.Item;
024: import com.sun.syndication.feed.synd.SyndContent;
025: import com.sun.syndication.feed.synd.SyndContentImpl;
026: import com.sun.syndication.feed.synd.SyndEntry;
027: import com.sun.syndication.feed.synd.SyndFeed;
028: import java.util.ArrayList;
029: import java.util.List;
030:
031: /**
032: */
033: public class ConverterForRSS10 extends ConverterForRSS090 {
034:
035: public ConverterForRSS10() {
036: this ("rss_1.0");
037: }
038:
039: protected ConverterForRSS10(String type) {
040: super (type);
041: }
042:
043: public void copyInto(WireFeed feed, SyndFeed syndFeed) {
044: Channel channel = (Channel) feed;
045: super .copyInto(channel, syndFeed);
046: if (channel.getUri() != null) {
047: syndFeed.setUri(channel.getUri());
048: } else {
049: // if URI is not set use the value for link
050: syndFeed.setUri(channel.getLink());
051: }
052: }
053:
054: // for rss -> synd
055: // rss.content -> synd.content
056: // rss.description -> synd.description
057:
058: protected SyndEntry createSyndEntry(Item item) {
059: SyndEntry syndEntry = super .createSyndEntry(item);
060:
061: Description desc = item.getDescription();
062: if (desc != null) {
063: SyndContent descContent = new SyndContentImpl();
064: descContent.setType(desc.getType());
065: descContent.setValue(desc.getValue());
066: syndEntry.setDescription(descContent);
067: }
068: Content cont = item.getContent();
069: if (cont != null) {
070: SyndContent contContent = new SyndContentImpl();
071: contContent.setType(cont.getType());
072: contContent.setValue(cont.getValue());
073: List contents = new ArrayList();
074: contents.add(contContent);
075: syndEntry.setContents(contents);
076: }
077:
078: return syndEntry;
079: }
080:
081: protected WireFeed createRealFeed(String type, SyndFeed syndFeed) {
082: Channel channel = (Channel) super
083: .createRealFeed(type, syndFeed);
084: if (syndFeed.getUri() != null) {
085: channel.setUri(syndFeed.getUri());
086: } else {
087: // if URI is not set use the value for link
088: channel.setUri(syndFeed.getLink());
089: }
090:
091: return channel;
092: }
093:
094: // for synd -> rss
095: // synd.content -> rss.content
096: // synd.description -> rss.description
097:
098: protected Item createRSSItem(SyndEntry sEntry) {
099: Item item = super .createRSSItem(sEntry);
100:
101: SyndContent desc = sEntry.getDescription();
102: if (desc != null) {
103: item.setDescription(createItemDescription(desc));
104: }
105: List contents = sEntry.getContents();
106: if (contents != null && contents.size() > 0) {
107: item.setContent(createItemContent((SyndContent) contents
108: .get(0)));
109: }
110:
111: String uri = sEntry.getUri();
112: if (uri != null) {
113: item.setUri(uri);
114: }
115:
116: return item;
117: }
118:
119: protected Description createItemDescription(SyndContent sContent) {
120: Description desc = new Description();
121: desc.setValue(sContent.getValue());
122: desc.setType(sContent.getType());
123: return desc;
124: }
125:
126: protected Content createItemContent(SyndContent sContent) {
127: Content cont = new Content();
128: cont.setValue(sContent.getValue());
129: cont.setType(sContent.getType());
130: return cont;
131: }
132:
133: }
|