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.Guid;
023: import com.sun.syndication.feed.rss.Item;
024: import com.sun.syndication.feed.synd.SyndEntry;
025: import com.sun.syndication.feed.synd.SyndFeed;
026: import com.sun.syndication.feed.synd.SyndPerson;
027:
028: import java.util.ArrayList;
029: import java.util.HashSet;
030: import java.util.List;
031: import java.util.Set;
032:
033: /**
034: */
035: public class ConverterForRSS094 extends ConverterForRSS093 {
036:
037: public ConverterForRSS094() {
038: this ("rss_0.94");
039: }
040:
041: protected ConverterForRSS094(String type) {
042: super (type);
043: }
044:
045: public void copyInto(WireFeed feed, SyndFeed syndFeed) {
046: Channel channel = (Channel) feed;
047: super .copyInto(channel, syndFeed);
048: List cats = channel.getCategories(); //c
049: if (cats.size() > 0) {
050: Set s = new HashSet(); // using a set to remove duplicates
051: s.addAll(createSyndCategories(cats)); // feed native categories (as syndcat)
052: s.addAll(syndFeed.getCategories()); // DC subjects (as syndcat)
053: syndFeed.setCategories(new ArrayList(s));
054: }
055: }
056:
057: protected SyndEntry createSyndEntry(Item item) {
058: SyndEntry syndEntry = super .createSyndEntry(item);
059:
060: // adding native feed author to DC creators list
061: String author = item.getAuthor();
062: if (author != null) {
063: List creators = ((DCModule) syndEntry
064: .getModule(DCModule.URI)).getCreators();
065: if (!creators.contains(author)) {
066: Set s = new HashSet(); // using a set to remove duplicates
067: s.addAll(creators); // DC creators
068: s.add(author); // feed native author
069: creators.clear();
070: creators.addAll(s);
071: }
072: }
073:
074: Guid guid = item.getGuid();
075: if (guid != null) {
076: syndEntry.setUri(guid.getValue());
077: if (item.getLink() == null && guid.isPermaLink()) {
078: syndEntry.setLink(guid.getValue());
079: }
080: } else {
081: syndEntry.setUri(item.getLink());
082: }
083: return syndEntry;
084: }
085:
086: protected WireFeed createRealFeed(String type, SyndFeed syndFeed) {
087: Channel channel = (Channel) super
088: .createRealFeed(type, syndFeed);
089: List cats = syndFeed.getCategories(); //c
090: if (cats.size() > 0) {
091: channel.setCategories(createRSSCategories(cats));
092: }
093: return channel;
094: }
095:
096: protected Item createRSSItem(SyndEntry sEntry) {
097: Item item = super .createRSSItem(sEntry);
098: if (sEntry.getAuthors() != null
099: && sEntry.getAuthors().size() > 0) {
100: SyndPerson author = (SyndPerson) sEntry.getAuthors().get(0);
101: item.setAuthor(author.getEmail());
102: }
103:
104: Guid guid = null;
105: String uri = sEntry.getUri();
106: if (uri != null) {
107: guid = new Guid();
108: guid.setPermaLink(false);
109: guid.setValue(uri);
110: } else {
111: String link = sEntry.getLink();
112: if (link != null) {
113: guid = new Guid();
114: guid.setPermaLink(true);
115: guid.setValue(link);
116: }
117: }
118: item.setGuid(guid);
119:
120: return item;
121: }
122:
123: }
|