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.DCModule;
021: import com.sun.syndication.feed.rss.Channel;
022: import com.sun.syndication.feed.rss.Content;
023: import com.sun.syndication.feed.rss.Description;
024: import com.sun.syndication.feed.rss.Image;
025: import com.sun.syndication.feed.rss.Item;
026: import com.sun.syndication.feed.synd.SyndFeed;
027: import com.sun.syndication.feed.synd.SyndContent;
028: import com.sun.syndication.feed.synd.SyndEntry;
029: import com.sun.syndication.feed.synd.SyndImage;
030: import com.sun.syndication.feed.synd.SyndContentImpl;
031: import com.sun.syndication.feed.synd.SyndPerson;
032:
033: import java.util.*;
034:
035: /**
036: */
037: public class ConverterForRSS091Userland extends ConverterForRSS090 {
038:
039: public ConverterForRSS091Userland() {
040: this ("rss_0.91U");
041: }
042:
043: protected ConverterForRSS091Userland(String type) {
044: super (type);
045: }
046:
047: public void copyInto(WireFeed feed, SyndFeed syndFeed) {
048: Channel channel = (Channel) feed;
049: super .copyInto(channel, syndFeed);
050: syndFeed.setLanguage(channel.getLanguage()); //c
051: syndFeed.setCopyright(channel.getCopyright()); //c
052: Date pubDate = channel.getPubDate();
053: if (pubDate != null) {
054: syndFeed.setPublishedDate(pubDate); //c
055: } else if (channel.getLastBuildDate() != null) {
056: syndFeed.setPublishedDate(channel.getLastBuildDate()); //c
057: }
058:
059: String author = channel.getManagingEditor();
060: if (author != null) {
061: List creators = ((DCModule) syndFeed
062: .getModule(DCModule.URI)).getCreators();
063: if (!creators.contains(author)) {
064: Set s = new HashSet(); // using a set to remove duplicates
065: s.addAll(creators); // DC creators
066: s.add(author); // feed native author
067: creators.clear();
068: creators.addAll(s);
069: }
070: }
071:
072: }
073:
074: protected SyndImage createSyndImage(Image rssImage) {
075: SyndImage syndImage = super .createSyndImage(rssImage);
076: syndImage.setDescription(rssImage.getDescription());
077: return syndImage;
078: }
079:
080: // for rss -> synd
081: // rss.content -> synd.content
082: // rss.description -> synd.description
083:
084: protected SyndEntry createSyndEntry(Item item) {
085: SyndEntry syndEntry = super .createSyndEntry(item);
086: Description desc = item.getDescription();
087: if (desc != null) {
088: SyndContent descContent = new SyndContentImpl();
089: descContent.setType(desc.getType());
090: descContent.setValue(desc.getValue());
091: syndEntry.setDescription(descContent);
092: }
093: Content cont = item.getContent();
094: if (cont != null) {
095: SyndContent content = new SyndContentImpl();
096: content.setType(cont.getType());
097: content.setValue(cont.getValue());
098: List syndContents = new ArrayList();
099: syndContents.add(content);
100: syndEntry.setContents(syndContents);
101: }
102: return syndEntry;
103: }
104:
105: protected WireFeed createRealFeed(String type, SyndFeed syndFeed) {
106: Channel channel = (Channel) super
107: .createRealFeed(type, syndFeed);
108: channel.setLanguage(syndFeed.getLanguage()); //c
109: channel.setCopyright(syndFeed.getCopyright()); //c
110: channel.setPubDate(syndFeed.getPublishedDate()); //c
111: if (syndFeed.getAuthors() != null
112: && syndFeed.getAuthors().size() > 0) {
113: SyndPerson author = (SyndPerson) syndFeed.getAuthors().get(
114: 0);
115: channel.setManagingEditor(author.getName());
116: }
117: return channel;
118: }
119:
120: protected Image createRSSImage(SyndImage sImage) {
121: Image image = super .createRSSImage(sImage);
122: image.setDescription(sImage.getDescription());
123: return image;
124: }
125:
126: // for synd -> rss
127: // synd.content -> rss.content
128: // synd.description -> rss.description
129:
130: protected Item createRSSItem(SyndEntry sEntry) {
131: Item item = super .createRSSItem(sEntry);
132:
133: SyndContent sContent = sEntry.getDescription();
134: if (sContent != null) {
135: item.setDescription(createItemDescription(sContent));
136: }
137: List contents = sEntry.getContents();
138: if (contents != null && contents.size() > 0) {
139: SyndContent syndContent = (SyndContent) contents.get(0);
140: Content cont = new Content();
141: cont.setValue(syndContent.getValue());
142: cont.setType(syndContent.getType());
143: item.setContent(cont);
144: }
145: return item;
146: }
147:
148: protected Description createItemDescription(SyndContent sContent) {
149: Description desc = new Description();
150: desc.setValue(sContent.getValue());
151: desc.setType(sContent.getType());
152: return desc;
153: }
154:
155: }
|