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.module.impl.ModuleUtils;
021: import com.sun.syndication.feed.rss.Channel;
022: import com.sun.syndication.feed.rss.Image;
023: import com.sun.syndication.feed.rss.Item;
024: import com.sun.syndication.feed.synd.SyndFeed;
025: import com.sun.syndication.feed.synd.Converter;
026: import com.sun.syndication.feed.synd.SyndEntry;
027: import com.sun.syndication.feed.synd.SyndImage;
028: import com.sun.syndication.feed.synd.SyndImageImpl;
029: import com.sun.syndication.feed.synd.SyndEntryImpl;
030:
031: import java.util.ArrayList;
032: import java.util.List;
033:
034: /**
035: */
036: public class ConverterForRSS090 implements Converter {
037: private String _type;
038:
039: public ConverterForRSS090() {
040: this ("rss_0.9");
041: }
042:
043: protected ConverterForRSS090(String type) {
044: _type = type;
045: }
046:
047: public String getType() {
048: return _type;
049: }
050:
051: public void copyInto(WireFeed feed, SyndFeed syndFeed) {
052: syndFeed
053: .setModules(ModuleUtils.cloneModules(feed.getModules()));
054: if (((List) feed.getForeignMarkup()).size() > 0) {
055: syndFeed.setForeignMarkup(feed.getForeignMarkup());
056: }
057: syndFeed.setEncoding(feed.getEncoding());
058: Channel channel = (Channel) feed;
059: syndFeed.setTitle(channel.getTitle());
060: syndFeed.setLink(channel.getLink());
061: syndFeed.setDescription(channel.getDescription());
062:
063: Image image = channel.getImage();
064: if (image != null) {
065: syndFeed.setImage(createSyndImage(image));
066: }
067:
068: List items = channel.getItems();
069: if (items != null) {
070: syndFeed.setEntries(createSyndEntries(items));
071: }
072: }
073:
074: protected SyndImage createSyndImage(Image rssImage) {
075: SyndImage syndImage = new SyndImageImpl();
076: syndImage.setTitle(rssImage.getTitle());
077: syndImage.setUrl(rssImage.getUrl());
078: syndImage.setLink(rssImage.getLink());
079: return syndImage;
080: }
081:
082: protected List createSyndEntries(List rssItems) {
083: List syndEntries = new ArrayList();
084: for (int i = 0; i < rssItems.size(); i++) {
085: syndEntries.add(createSyndEntry((Item) rssItems.get(i)));
086: }
087: return syndEntries;
088: }
089:
090: protected SyndEntry createSyndEntry(Item item) {
091: SyndEntry syndEntry = new SyndEntryImpl();
092:
093: syndEntry.setModules(ModuleUtils
094: .cloneModules(item.getModules()));
095:
096: if (((List) item.getForeignMarkup()).size() > 0) {
097: syndEntry.setForeignMarkup(item.getForeignMarkup());
098: }
099:
100: syndEntry.setUri(item.getUri());
101: syndEntry.setLink(item.getLink());
102: syndEntry.setTitle(item.getTitle());
103: syndEntry.setLink(item.getLink());
104: return syndEntry;
105: }
106:
107: public WireFeed createRealFeed(SyndFeed syndFeed) {
108: return createRealFeed(getType(), syndFeed);
109: }
110:
111: protected WireFeed createRealFeed(String type, SyndFeed syndFeed) {
112: Channel channel = new Channel(type);
113: channel.setModules(ModuleUtils.cloneModules(syndFeed
114: .getModules()));
115:
116: channel.setEncoding(syndFeed.getEncoding());
117:
118: channel.setTitle(syndFeed.getTitle());
119: channel.setLink(syndFeed.getLink());
120: channel.setDescription(syndFeed.getDescription());
121: SyndImage sImage = syndFeed.getImage();
122: if (sImage != null) {
123: channel.setImage(createRSSImage(sImage));
124: }
125:
126: List sEntries = syndFeed.getEntries();
127: if (sEntries != null) {
128: channel.setItems(createRSSItems(sEntries));
129: }
130: return channel;
131: }
132:
133: protected Image createRSSImage(SyndImage sImage) {
134: Image image = new Image();
135: image.setTitle(sImage.getTitle());
136: image.setUrl(sImage.getUrl());
137: image.setLink(sImage.getLink());
138: return image;
139: }
140:
141: protected List createRSSItems(List sEntries) {
142: List list = new ArrayList();
143: for (int i = 0; i < sEntries.size(); i++) {
144: list.add(createRSSItem((SyndEntry) sEntries.get(i)));
145: }
146: return list;
147: }
148:
149: protected Item createRSSItem(SyndEntry sEntry) {
150: Item item = new Item();
151: item.setModules(ModuleUtils.cloneModules(sEntry.getModules()));
152: item.setTitle(sEntry.getTitle());
153: item.setLink(sEntry.getLink());
154: return item;
155: }
156:
157: }
|