You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by jr...@apache.org on 2010/04/19 23:03:38 UTC
svn commit: r935746 - in /incubator/wink/trunk:
wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/rss/
wink-common/src/main/java/org/apache/wink/common/model/rss/
wink-common/src/test/java/org/apache/wink/common/model/rss/ wink...
Author: jramos
Date: Mon Apr 19 21:03:37 2010
New Revision: 935746
URL: http://svn.apache.org/viewvc?rev=935746&view=rev
Log:
Commit Shiva's code to map the RSS Object model to the Syndication model minus the wink-providers change
Added:
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/rss/
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/rss/RssFeedSyndFeedProvider.java
incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssFeedToSyndFeedTest.java
incubator/wink/trunk/wink-examples/client/ReadRSS-client/src/main/java/org/apache/wink/example/ReadRssAsSyndFeed.java
Modified:
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssCategory.java
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssChannel.java
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssEnclosure.java
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssFeed.java
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssItem.java
Added: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/rss/RssFeedSyndFeedProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/rss/RssFeedSyndFeedProvider.java?rev=935746&view=auto
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/rss/RssFeedSyndFeedProvider.java (added)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/rss/RssFeedSyndFeedProvider.java Mon Apr 19 21:03:37 2010
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+
+package org.apache.wink.common.internal.providers.entity.rss;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.wink.common.internal.providers.entity.xml.JAXBXmlProvider;
+import org.apache.wink.common.model.rss.RssFeed;
+import org.apache.wink.common.model.synd.SyndFeed;
+
+@Provider
+@Consumes( {MediaType.TEXT_XML, MediaType.APPLICATION_XML})
+@Produces( {MediaType.TEXT_XML, MediaType.APPLICATION_XML})
+public class RssFeedSyndFeedProvider extends JAXBXmlProvider {
+
+ @Override
+ public boolean isReadable(Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ return type == SyndFeed.class;
+ }
+
+ @Override
+ public Object readFrom(Class<Object> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders,
+ InputStream entityStream) throws IOException, WebApplicationException {
+ RssFeed rssFeed =
+ (RssFeed)super.readFrom((Class)RssFeed.class,
+ genericType,
+ annotations,
+ mediaType,
+ httpHeaders,
+ entityStream);
+ SyndFeed syndFeed = new SyndFeed();
+ syndFeed = rssFeed.toSynd(syndFeed);
+ return syndFeed;
+ }
+
+ @Override
+ public void writeTo(Object t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ RssFeed rssFeed = new RssFeed((SyndFeed)t);
+ super.writeTo(rssFeed,
+ RssFeed.class,
+ genericType,
+ annotations,
+ mediaType,
+ httpHeaders,
+ entityStream);
+ }
+}
Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssCategory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssCategory.java?rev=935746&r1=935745&r2=935746&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssCategory.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssCategory.java Mon Apr 19 21:03:37 2010
@@ -23,7 +23,6 @@
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.07.20 at 10:55:05 AM IST
//
-
package org.apache.wink.common.model.rss;
import javax.xml.bind.annotation.XmlAccessType;
@@ -32,6 +31,8 @@ import javax.xml.bind.annotation.XmlAttr
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
+import org.apache.wink.common.model.synd.SyndCategory;
+
/**
* <p>
* Java class for "category" element of <a
@@ -82,6 +83,31 @@ public class RssCategory {
@XmlAttribute
protected String domain;
+ public RssCategory() {
+ }
+
+ public RssCategory(SyndCategory syndCategory) {
+ if (syndCategory.getLabel() != null) {
+ setContent(syndCategory.getLabel());
+ }
+ if (syndCategory.getScheme() != null) {
+ setDomain(syndCategory.getScheme());
+ }
+ }
+
+ public SyndCategory toSynd(SyndCategory syndCategory) {
+ if (syndCategory == null) {
+ return syndCategory;
+ }
+ if (getContent() != null) {
+ syndCategory.setLabel(getContent());
+ }
+ if (getDomain() != null) {
+ syndCategory.setScheme(getDomain());
+ }
+ return syndCategory;
+ }
+
/**
* Gets the value of the content property.
*
Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssChannel.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssChannel.java?rev=935746&r1=935745&r2=935746&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssChannel.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssChannel.java Mon Apr 19 21:03:37 2010
@@ -23,11 +23,14 @@
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.07.20 at 10:55:05 AM IST
//
-
package org.apache.wink.common.model.rss;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
@@ -35,6 +38,18 @@ import javax.xml.bind.annotation.XmlElem
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
+import org.apache.wink.common.internal.i18n.Messages;
+import org.apache.wink.common.model.synd.SyndCategory;
+import org.apache.wink.common.model.synd.SyndEntry;
+import org.apache.wink.common.model.synd.SyndFeed;
+import org.apache.wink.common.model.synd.SyndGenerator;
+import org.apache.wink.common.model.synd.SyndLink;
+import org.apache.wink.common.model.synd.SyndPerson;
+import org.apache.wink.common.model.synd.SyndText;
+import org.apache.wink.common.model.synd.SyndTextType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* <p>
* Java class for "channel" element of <a
@@ -263,6 +278,118 @@ public class RssChannel {
protected List<Object> any;
protected List<RssItem> item;
+ private static String RSS_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss z";
+ private static final Logger logger = LoggerFactory.getLogger(RssChannel.class);
+
+ public RssChannel() {
+ }
+
+ public RssChannel(SyndFeed syndFeed) {
+ if (syndFeed == null) {
+ return;
+ }
+ if (syndFeed.getTitle() != null && syndFeed.getTitle().getValue() != null) {
+ setTitle(syndFeed.getTitle().getValue());
+ }
+ SyndLink link = syndFeed.getLink("alternate");
+ if (link != null && link.getHref() != null) {
+ setLink(link.getHref());
+ }
+ if (syndFeed.getSubtitle() != null && syndFeed.getSubtitle().getValue() != null) {
+ setDescription(syndFeed.getSubtitle().getValue());
+ }
+ if (syndFeed.getLang() != null) {
+ setLanguage(syndFeed.getLang());
+ }
+ if (syndFeed.getRights() != null && syndFeed.getRights().getValue() != null) {
+ setCopyright(syndFeed.getRights().getValue());
+ }
+ if (syndFeed.getAuthors().size() > 0) {
+ SyndPerson author = syndFeed.getAuthors().get(0);
+ if (author.getEmail() != null) {
+ setManagingEditor(author.getEmail());
+ }
+ }
+ if (syndFeed.getUpdated() != null) {
+ setLastBuildDate(convertJavaDateToRssDate(syndFeed.getUpdated()));
+ }
+ getCategories().clear();
+ for (SyndCategory syndCategory : syndFeed.getCategories()) {
+ getCategories().add(new RssCategory(syndCategory));
+ }
+ if (syndFeed.getGenerator() != null && syndFeed.getGenerator().getValue() != null) {
+ setGenerator(syndFeed.getGenerator().getValue());
+ }
+ if (syndFeed.getLogo() != null) {
+ RssImage rssImage = new RssImage();
+ rssImage.setUrl(syndFeed.getLogo());
+ // http://www.rssboard.org/rss-specification mentions that, in
+ // practice the image <title> and <link> should have the same value
+ // as the channel's <title> and <link>.
+ rssImage.setTitle(getTitle());
+ rssImage.setLink(getLink());
+ setImage(rssImage);
+ }
+ getItems().clear();
+ for (SyndEntry syndEntry : syndFeed.getEntries()) {
+ RssItem rssItem = new RssItem(syndEntry);
+ getItems().add(rssItem);
+ }
+ }
+
+ public SyndFeed toSynd(SyndFeed syndFeed) {
+ if (syndFeed == null) {
+ return syndFeed;
+ }
+ if (getTitle() != null) {
+ syndFeed.setTitle(new SyndText(getTitle(), SyndTextType.text));
+ }
+ if (getLink() != null) {
+ SyndLink syndLink = new SyndLink();
+ syndLink.setHref(getLink());
+ syndLink.setRel("alternate");
+ syndFeed.getLinks().add(syndLink);
+ }
+ if (getDescription() != null) {
+ syndFeed.setSubtitle(new SyndText(getDescription(), SyndTextType.text));
+ }
+ if (getLanguage() != null) {
+ syndFeed.setLang(getLanguage());
+ }
+ if (getCopyright() != null) {
+ syndFeed.setRights(new SyndText(getCopyright()));
+ }
+ if (getManagingEditor() != null) {
+ SyndPerson syndAuthor = new SyndPerson();
+ String authorEmail = getManagingEditor();
+ syndAuthor.setEmail(authorEmail);
+ syndAuthor.setName(authorEmail.substring(0, authorEmail.indexOf("@")));
+ syndFeed.getAuthors().add(syndAuthor);
+ }
+ if (getLastBuildDate() != null) {
+ syndFeed.setUpdated(convertRssDateToJavaDate(getLastBuildDate()));
+ }
+ syndFeed.getCategories().clear();
+ for (RssCategory rssCategory : getCategories()) {
+ SyndCategory syndCategory = new SyndCategory();
+ syndCategory = rssCategory.toSynd(syndCategory);
+ syndFeed.getCategories().add(syndCategory);
+ }
+ if (getGenerator() != null) {
+ syndFeed.setGenerator(new SyndGenerator(getGenerator()));
+ }
+ if (getImage() != null && getImage().getUrl() != null) {
+ syndFeed.setLogo(getImage().getUrl());
+ }
+ syndFeed.getEntries().clear();
+ for (RssItem rssItem : getItems()) {
+ SyndEntry syndEntry = new SyndEntry();
+ syndEntry = rssItem.toSynd(syndEntry);
+ syndFeed.getEntries().add(syndEntry);
+ }
+ return syndFeed;
+ }
+
/**
* Gets the value of the title property.
*
@@ -657,4 +784,18 @@ public class RssChannel {
return this.item;
}
+ public static String convertJavaDateToRssDate(Date javaDate) {
+ SimpleDateFormat format = new SimpleDateFormat(RSS_DATE_FORMAT);
+ return format.format(javaDate);
+ }
+
+ public static Date convertRssDateToJavaDate(String rssDate) {
+ SimpleDateFormat format = new SimpleDateFormat(RSS_DATE_FORMAT);
+ try {
+ return format.parse(rssDate);
+ } catch (ParseException e) {
+ logger.error(Messages.getMessage("listExceptionDuringClassProcessing"), e);
+ }
+ return null;
+ }
}
Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssEnclosure.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssEnclosure.java?rev=935746&r1=935745&r2=935746&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssEnclosure.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssEnclosure.java Mon Apr 19 21:03:37 2010
@@ -23,7 +23,6 @@
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.07.20 at 10:55:05 AM IST
//
-
package org.apache.wink.common.model.rss;
import javax.xml.bind.annotation.XmlAccessType;
@@ -31,6 +30,8 @@ import javax.xml.bind.annotation.XmlAcce
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
+import org.apache.wink.common.model.synd.SyndLink;
+
/**
* <p>
* Java class for "enclosure" element of <a
@@ -82,6 +83,26 @@ public class RssEnclosure {
@XmlAttribute(required = true)
protected String type;
+ public RssEnclosure() {
+ }
+
+ public RssEnclosure(SyndLink syndLink) {
+ setType(syndLink.getType());
+ setUrl(syndLink.getHref());
+ setLength(syndLink.getLength());
+ }
+
+ public SyndLink toSynd(SyndLink syndLink) {
+ if (syndLink == null) {
+ return syndLink;
+ }
+ syndLink.setRel("enclosure");
+ syndLink.setType(getType());
+ syndLink.setLength(getLength());
+ syndLink.setHref(getUrl());
+ return syndLink;
+ }
+
/**
* Gets the value of the url property.
*
Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssFeed.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssFeed.java?rev=935746&r1=935745&r2=935746&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssFeed.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssFeed.java Mon Apr 19 21:03:37 2010
@@ -33,6 +33,8 @@ import javax.xml.bind.annotation.XmlElem
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
+import org.apache.wink.common.model.synd.SyndFeed;
+
/**
* <p>
* Java class for "rss" element of <a
@@ -71,6 +73,22 @@ import javax.xml.bind.annotation.XmlType
@XmlRootElement(name = "rss")
public class RssFeed {
+ public RssFeed() {
+ }
+
+ public RssFeed(SyndFeed syndFeed) {
+ setChannel(new RssChannel(syndFeed));
+ setVersion("2.0");
+ }
+
+ public SyndFeed toSynd(SyndFeed syndFeed) {
+ if (syndFeed == null) {
+ return syndFeed;
+ }
+ syndFeed = getChannel().toSynd(syndFeed);
+ return syndFeed;
+ }
+
@XmlElement(required = true)
protected RssChannel channel;
@XmlAttribute(required = true)
Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssItem.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssItem.java?rev=935746&r1=935745&r2=935746&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssItem.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/model/rss/RssItem.java Mon Apr 19 21:03:37 2010
@@ -23,11 +23,11 @@
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2009.07.20 at 10:55:05 AM IST
//
-
package org.apache.wink.common.model.rss;
import java.util.ArrayList;
import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
@@ -35,6 +35,13 @@ import javax.xml.bind.annotation.XmlElem
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
+import org.apache.wink.common.model.synd.SyndCategory;
+import org.apache.wink.common.model.synd.SyndEntry;
+import org.apache.wink.common.model.synd.SyndLink;
+import org.apache.wink.common.model.synd.SyndPerson;
+import org.apache.wink.common.model.synd.SyndText;
+import org.apache.wink.common.model.synd.SyndTextType;
+
/**
* <p>
* Java class for "item" element of <a
@@ -169,6 +176,87 @@ public class RssItem {
@XmlAnyElement(lax = true)
protected List<Object> any;
+ public RssItem() {
+ }
+
+ public RssItem(SyndEntry syndEntry) {
+ if (syndEntry.getTitle() != null && syndEntry.getTitle().getValue() != null) {
+ setTitle(syndEntry.getTitle().getValue());
+ }
+ SyndLink link = syndEntry.getLink("alternate");
+ if (link != null && link.getHref() != null) {
+ setLink(link.getHref());
+ }
+ if (syndEntry.getSummary() != null && syndEntry.getSummary().getValue() != null) {
+ setDescription(syndEntry.getSummary().getValue());
+ }
+ if (syndEntry.getAuthors().size() > 0) {
+ SyndPerson syndAuthor = syndEntry.getAuthors().get(0);
+ if (syndAuthor.getEmail() != null) {
+ setAuthor(syndAuthor.getEmail());
+ }
+ }
+ getCategories().clear();
+ for (SyndCategory syndCategory : syndEntry.getCategories()) {
+ getCategories().add(new RssCategory(syndCategory));
+ }
+ link = syndEntry.getLink("enclosure");
+ if (link != null) {
+ setEnclosure(new RssEnclosure(link));
+ }
+ if (syndEntry.getId() != null) {
+ RssGuid rssGuid = new RssGuid();
+ rssGuid.setContent(syndEntry.getId());
+ setGuid(rssGuid);
+ }
+ if (syndEntry.getPublished() != null) {
+ setPubDate(RssChannel.convertJavaDateToRssDate(syndEntry.getPublished()));
+ }
+ }
+
+ public SyndEntry toSynd(SyndEntry syndEntry) {
+ if (syndEntry == null) {
+ return syndEntry;
+ }
+ if (getTitle() != null) {
+ syndEntry.setTitle(new SyndText(getTitle(), SyndTextType.text));
+ }
+ if (getLink() != null) {
+ SyndLink syndLink = new SyndLink();
+ syndLink.setHref(getLink());
+ syndLink.setRel("alternate");
+ syndEntry.getLinks().add(syndLink);
+ }
+ if (getDescription() != null) {
+ syndEntry.setSummary(new SyndText(getDescription()));
+ }
+ if (getAuthor() != null) {
+ SyndPerson syndAuthor = new SyndPerson();
+ String authorEmail = getAuthor();
+ syndAuthor.setEmail(authorEmail);
+ syndAuthor.setName(authorEmail.substring(0, authorEmail.indexOf("@")));
+ syndEntry.getAuthors().add(syndAuthor);
+ }
+ syndEntry.getCategories().clear();
+ for (RssCategory rssCategory : getCategories()) {
+ SyndCategory syndCategory = new SyndCategory();
+ syndCategory = rssCategory.toSynd(syndCategory);
+ syndEntry.getCategories().add(syndCategory);
+ }
+ if (getEnclosure() != null) {
+ SyndLink syndEnclosureLink = new SyndLink();
+ syndEnclosureLink = getEnclosure().toSynd(syndEnclosureLink);
+ syndEntry.getLinks().add(syndEnclosureLink);
+ }
+ if (getGuid() != null) {
+ syndEntry.setId(getGuid().getContent());
+ }
+ if (getPubDate() != null) {
+ syndEntry.setPublished(RssChannel.convertRssDateToJavaDate(getPubDate()));
+ }
+ return syndEntry;
+ }
+
/**
* Gets the value of the title property.
*
Added: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssFeedToSyndFeedTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssFeedToSyndFeedTest.java?rev=935746&view=auto
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssFeedToSyndFeedTest.java (added)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/model/rss/RssFeedToSyndFeedTest.java Mon Apr 19 21:03:37 2010
@@ -0,0 +1,354 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+
+package org.apache.wink.common.model.rss;
+
+import java.io.StringReader;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.common.internal.utils.JAXBUtils;
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.common.model.atom.AtomFeed;
+import org.apache.wink.common.model.synd.SyndEntry;
+import org.apache.wink.common.model.synd.SyndFeed;
+
+public class RssFeedToSyndFeedTest extends TestCase {
+ // References: http://www.rssboard.org/files/rss-2.0-sample.xml and
+ // http://www.rssboard.org/files/sample-rss-2.xml
+
+ private static final String FEED_TITLE = "Liftoff News";
+ private static final String FEED_LINK = "http://liftoff.msfc.nasa.gov/";
+ private static final String FEED_DESCRIPTION = "Liftoff to Space Exploration.";
+ private static final String FEED_LANGUAGE = "en-us";
+ private static final String FEED_COPYRIGHT = "Copyright 2002, Spartanburg Herald-Journal";
+ private static final String FEED_EDITOR = "editor@example.com";
+ private static final String FEED_LASTBUILDDATE = "Tue, 10 Jun 2003 09:41:01 GMT";
+ private static final String FEED_LASTBUILDDATE_ATOM = "2003-06-10T09:41:01Z";
+ private static final String FEED_CTG1_DOMAIN = "http://www.fool.com/cusips";
+ private static final String FEED_CTG1_VALUE = "MSFT";
+ private static final String FEED_CTG2_DOMAIN = "http://www.fool.com/musips";
+ private static final String FEED_CTG2_VALUE = "MOTO";
+ private static final String FEED_GENERATOR = "Weblog Editor 2.0";
+ private static final String FEED_IMAGE_URL = "http://liftoff.msfc.nasa.gov/news.gif";
+
+ private static final String ITEM_TITLE = "Star City";
+ private static final String ITEM_LINK = "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp";
+ private static final String ITEM_DESCRIPTION = "How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's Star City.";
+ private static final String ITEM_AUTHOR = "author1@rssboard.org";
+ private static final String ITEM_ENCLOSURE_URL = "http://www.scripting.com/mp3s/weatherReportSuite.mp3";
+ private static final String ITEM_ENCLOSURE_LENGTH = "12216320";
+ private static final String ITEM_ENCLOSURE_TYPE = "audio/mpeg";
+ private static final String ITEM_GUID = "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573";
+ private static final String ITEM_PUBDATE = "Tue, 03 Jun 2003 09:39:21 GMT";
+ private static final String ITEM_PUBDATE_ATOM = "2003-06-03T09:39:21Z";
+
+ private static final String RSS_FEED =
+ "<?xml version=\"1.0\"?>" + "<rss version=\"2.0\">\n"
+ + " <channel>\n"
+ + " <title>" + FEED_TITLE + "</title>\n"
+ + " <link>" + FEED_LINK + "</link>\n"
+ + " <description>" + FEED_DESCRIPTION + "</description>\n"
+ + " <language>"+ FEED_LANGUAGE + "</language>\n"
+ + " <copyright>" + FEED_COPYRIGHT + "</copyright>\n"
+ + " <managingEditor>" + FEED_EDITOR + "</managingEditor>\n"
+ + " <webMaster>webmaster@example.com</webMaster>\n"
+ + " <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>\n"
+ + " <lastBuildDate>" + FEED_LASTBUILDDATE + "</lastBuildDate>\n"
+ + " <category domain=\"" + FEED_CTG1_DOMAIN + "\">" + FEED_CTG1_VALUE + "</category>\n"
+ + " <category domain=\"" + FEED_CTG2_DOMAIN + "\">" + FEED_CTG2_VALUE + "</category>\n"
+ + " <generator>" + FEED_GENERATOR + "</generator>\n"
+ + " <image>\n"
+ + " <url>" + FEED_IMAGE_URL + "</url>\n"
+ + " <title>Litoff News</title>\n"
+ + " <link>http://liftoff.msfc.nasa.gov/</link>\n"
+ + " <width>100</width>\n"
+ + " <height>100</height>\n"
+ + " <description>News</description>\n"
+ + " </image>\n"
+ + " <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n"
+ + " <item>\n"
+ + " <title>" + ITEM_TITLE + "</title>\n"
+ + " <link>" + ITEM_LINK + "</link>\n"
+ + " <description>" + ITEM_DESCRIPTION + "</description>\n"
+ + " <author>" + ITEM_AUTHOR + "</author>\n"
+ + " <category domain=\"" + FEED_CTG1_DOMAIN + "\">" + FEED_CTG1_VALUE + "</category>\n"
+ + " <category domain=\"" + FEED_CTG2_DOMAIN + "\">" + FEED_CTG2_VALUE + "</category>\n"
+ + " <enclosure url=\"" + ITEM_ENCLOSURE_URL + "\" length=\"" + ITEM_ENCLOSURE_LENGTH + "\" type=\"" + ITEM_ENCLOSURE_TYPE + "\" />\n"
+ + " <guid>" + ITEM_GUID + "</guid>\n"
+ + " <pubDate>" + ITEM_PUBDATE + "</pubDate>\n"
+ + " </item>\n"
+ + " <item>\n"
+ + " <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a &lt;a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm"&gt;partial eclipse of the Sun&lt;/a&gt; on Saturday, May 31st.</description>\n"
+ + " <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid>\n"
+ + " <pubDate>Fri, 30 May 2003 11:06:42 GMT</pubDate>\n"
+ + " </item>\n"
+ + " <item>\n"
+ + " <title>The Engine That Does More</title>\n"
+ + " <link>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</link>\n"
+ + " <description>Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that.</description>\n"
+ + " <guid>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</guid>\n"
+ + " <pubDate>Tue, 27 May 2003 08:37:32 GMT</pubDate>\n"
+ + " </item>\n"
+ + " <item>\n"
+ + " <title>Astronauts' Dirty Laundry</title>\n"
+ + " <link>http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp</link>\n"
+ + " <description>Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.</description>\n"
+ + " <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid>\n"
+ + " <pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate>\n"
+ + " </item>\n"
+ + " </channel>\n"
+ + "</rss>\n";
+
+ private static final String ATOM_FEED = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ + "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:ns2=\"http://a9.com/-/spec/opensearch/1.1/\" xmlns:ns3=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" + FEED_LANGUAGE + "\">\n"
+ + " <title type=\"text\">" + FEED_TITLE + "</title>\n"
+ + " <link href=\"" + FEED_LINK + "\" rel=\"alternate\" />\n"
+ + " <subtitle type=\"text\">" + FEED_DESCRIPTION + "</subtitle>\n"
+ + " <rights type=\"text\">" + FEED_COPYRIGHT + "</rights>\n"
+ + " <author>\n"
+ + " <email>" + FEED_EDITOR + "</email>\n"
+ + " <name>editor</name>\n"
+ + " </author>\n"
+ + " <updated>" + FEED_LASTBUILDDATE_ATOM + "</updated>\n"
+ + " <category label=\"" + FEED_CTG1_VALUE + "\" scheme=\"" + FEED_CTG1_DOMAIN + "\"/>\n"
+ + " <category label=\"" + FEED_CTG2_VALUE + "\" scheme=\"" + FEED_CTG2_DOMAIN + "\"/>\n"
+ + " <generator>" + FEED_GENERATOR + "</generator>\n"
+ + " <logo>" + FEED_IMAGE_URL + "</logo>\n"
+ + " <entry>\n"
+ + " <title type=\"text\">" + ITEM_TITLE + "</title>\n"
+ + " <link href=\"" + ITEM_LINK + "\" rel=\"alternate\"/>\n"
+ + " <summary type=\"text\">" + ITEM_DESCRIPTION + "</summary>\n"
+ + " <author>\n"
+ + " <email>" + ITEM_AUTHOR + "</email>\n"
+ + " <name>author1</name>\n"
+ + " </author>\n"
+ + " <category label=\"" + FEED_CTG1_VALUE + "\" scheme=\"" + FEED_CTG1_DOMAIN + "\"/>\n"
+ + " <category label=\"" + FEED_CTG2_VALUE + "\" scheme=\"" + FEED_CTG2_DOMAIN + "\"/>\n"
+ + " <link href=\"" + ITEM_ENCLOSURE_URL + "\" type=\"" + ITEM_ENCLOSURE_TYPE + "\" rel=\"enclosure\" length=\"" + ITEM_ENCLOSURE_LENGTH + "\"/>\n"
+ + " <id>" + ITEM_GUID + "</id>\n"
+ + " <published>" + ITEM_PUBDATE_ATOM + "</published>\n"
+ + " </entry>\n"
+ + " <entry>\n"
+ + " <id>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</id>\n"
+ + " <summary type=\"text\">Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a <a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm">partial eclipse of the Sun</a> on Saturday, May 31st.</summary>\n"
+ + " <published>2003-05-30T16:36:42.000+05:30</published>\n"
+ + " </entry>\n"
+ + " <entry>\n"
+ + " <id>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</id>\n"
+ + " <title type=\"text\">The Engine That Does More</title>\n"
+ + " <summary type=\"text\">Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly. The proposed VASIMR engine would do that.</summary>\n"
+ + " <published>2003-05-27T14:07:32.000+05:30</published>\n"
+ + " <link href=\"http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp\" rel=\"alternate\"/>\n"
+ + " </entry>\n"
+ + " <entry>\n"
+ + " <id>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</id>\n"
+ + " <title type=\"text\">Astronauts' Dirty Laundry</title>\n"
+ + " <summary type=\"text\">Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.</summary>\n"
+ + " <published>2003-05-20T14:26:02.000+05:30</published>\n"
+ + " <link href=\"http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp\" rel=\"alternate\"/>\n"
+ + " </entry>\n"
+ + "</feed>\n";
+
+ private static JAXBContext ctx;
+
+ static {
+ try {
+ ctx = JAXBContext.newInstance(RssFeed.class, RssChannel.class, RssItem.class, AtomFeed.class, AtomEntry.class);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void testRssFeedToSyndFeed() throws JAXBException {
+ Unmarshaller u = JAXBUtils.createUnmarshaller(ctx);
+ Object element = u.unmarshal(new StringReader(RSS_FEED));
+ assertNotNull(element);
+ if (element instanceof JAXBElement<?>) {
+ element = ((JAXBElement<?>)element).getValue();
+ }
+ assertTrue(element instanceof RssFeed);
+ RssFeed rssFeed = (RssFeed)element;
+ assertNotNull(rssFeed);
+
+ // Convert RssFeed into SyndFeed
+ SyndFeed syndFeed = new SyndFeed();
+ syndFeed = rssFeed.toSynd(syndFeed);
+ assertNotNull(syndFeed);
+
+ assertNotNull(syndFeed.getTitle());
+ assertEquals(FEED_TITLE, syndFeed.getTitle().getValue());
+
+ assertNotNull(syndFeed.getLink("alternate"));
+ assertEquals(FEED_LINK, syndFeed.getLink("alternate").getHref());
+
+ assertNotNull(syndFeed.getSubtitle());
+ assertEquals(FEED_DESCRIPTION, syndFeed.getSubtitle().getValue());
+
+ assertNotNull(syndFeed.getLang());
+ assertEquals(FEED_LANGUAGE, syndFeed.getLang());
+
+ assertNotNull(syndFeed.getRights());
+ assertEquals(FEED_COPYRIGHT, syndFeed.getRights().getValue());
+
+ assertTrue(syndFeed.getAuthors().size() > 0);
+ assertEquals(FEED_EDITOR, syndFeed.getAuthors().get(0).getEmail());
+
+ assertNotNull(syndFeed.getUpdated());
+ assertEquals(RssChannel.convertRssDateToJavaDate(FEED_LASTBUILDDATE), syndFeed.getUpdated());
+
+ assertTrue(syndFeed.getCategories().size() == 2);
+ assertEquals(FEED_CTG1_DOMAIN, syndFeed.getCategories().get(0).getScheme());
+ assertEquals(FEED_CTG1_VALUE, syndFeed.getCategories().get(0).getLabel());
+ assertEquals(FEED_CTG2_DOMAIN, syndFeed.getCategories().get(1).getScheme());
+ assertEquals(FEED_CTG2_VALUE, syndFeed.getCategories().get(1).getLabel());
+
+ assertNotNull(syndFeed.getGenerator());
+ assertEquals(FEED_GENERATOR, syndFeed.getGenerator().getValue());
+
+ assertNotNull(syndFeed.getLogo());
+ assertEquals(FEED_IMAGE_URL, syndFeed.getLogo());
+
+ assertTrue(syndFeed.getEntries().size() > 0);
+ SyndEntry syndEntry = syndFeed.getEntries().get(0);
+ assertNotNull(syndEntry);
+
+ assertNotNull(syndEntry.getTitle());
+ assertEquals(ITEM_TITLE, syndEntry.getTitle().getValue());
+
+ assertNotNull(syndEntry.getLink("alternate"));
+ assertEquals(ITEM_LINK, syndEntry.getLink("alternate").getHref());
+
+ assertNotNull(syndEntry.getSummary());
+ assertEquals(ITEM_DESCRIPTION, syndEntry.getSummary().getValue());
+
+ assertTrue(syndEntry.getAuthors().size() > 0);
+ assertEquals(ITEM_AUTHOR, syndEntry.getAuthors().get(0).getEmail());
+
+ assertTrue(syndEntry.getCategories().size() == 2);
+ assertEquals(FEED_CTG1_DOMAIN, syndEntry.getCategories().get(0).getScheme());
+ assertEquals(FEED_CTG1_VALUE, syndEntry.getCategories().get(0).getLabel());
+ assertEquals(FEED_CTG2_DOMAIN, syndEntry.getCategories().get(1).getScheme());
+ assertEquals(FEED_CTG2_VALUE, syndEntry.getCategories().get(1).getLabel());
+
+ assertNotNull(syndEntry.getLink("enclosure"));
+ assertEquals(ITEM_ENCLOSURE_URL, syndEntry.getLink("enclosure").getHref());
+ assertEquals(ITEM_ENCLOSURE_LENGTH, syndEntry.getLink("enclosure").getLength());
+ assertEquals(ITEM_ENCLOSURE_TYPE, syndEntry.getLink("enclosure").getType());
+
+ assertNotNull(syndEntry.getId());
+ assertEquals(ITEM_GUID, syndEntry.getId());
+
+ assertNotNull(syndEntry.getPublished());
+ assertEquals(RssChannel.convertRssDateToJavaDate(ITEM_PUBDATE), syndEntry.getPublished());
+ }
+
+ public void testSyndFeedToRss() throws JAXBException {
+ Unmarshaller u = JAXBUtils.createUnmarshaller(ctx);
+ Object element = u.unmarshal(new StringReader(ATOM_FEED));
+ assertNotNull(element);
+ if (element instanceof JAXBElement<?>) {
+ element = ((JAXBElement<?>)element).getValue();
+ }
+ assertTrue(element instanceof AtomFeed);
+ SyndFeed syndFeed1 = new SyndFeed();
+ syndFeed1 = ((AtomFeed)element).toSynd(syndFeed1);
+ assertNotNull(syndFeed1);
+
+ // Convert SyndFeed into RssFeed
+ RssFeed rssFeed1 = new RssFeed(syndFeed1);
+ RssChannel rssChannel = rssFeed1.getChannel();
+ assertNotNull(rssChannel);
+
+ assertNotNull(rssChannel.getTitle());
+ assertEquals(FEED_TITLE, rssChannel.getTitle());
+
+ assertNotNull(rssChannel.getLink());
+ assertEquals(FEED_LINK, rssChannel.getLink());
+
+ assertNotNull(rssChannel.getDescription());
+ assertEquals(FEED_DESCRIPTION, rssChannel.getDescription());
+
+ assertNotNull(rssChannel.getLanguage());
+ assertEquals(FEED_LANGUAGE, rssChannel.getLanguage());
+
+ assertNotNull(rssChannel.getCopyright());
+ assertEquals(FEED_COPYRIGHT, rssChannel.getCopyright());
+
+ assertNotNull(rssChannel.getManagingEditor());
+ assertEquals(FEED_EDITOR, rssChannel.getManagingEditor());
+
+ assertNotNull(rssChannel.getLastBuildDate());
+ assertEquals(RssChannel.convertRssDateToJavaDate(FEED_LASTBUILDDATE), RssChannel
+ .convertRssDateToJavaDate(rssChannel.getLastBuildDate()));
+
+ assertTrue(rssChannel.getCategories().size() == 2);
+ assertEquals(FEED_CTG1_DOMAIN, rssChannel.getCategories().get(0).getDomain());
+ assertEquals(FEED_CTG1_VALUE, rssChannel.getCategories().get(0).getContent());
+ assertEquals(FEED_CTG2_DOMAIN, rssChannel.getCategories().get(1).getDomain());
+ assertEquals(FEED_CTG2_VALUE, rssChannel.getCategories().get(1).getContent());
+
+ assertNotNull(rssChannel.getGenerator());
+ assertEquals(FEED_GENERATOR, rssChannel.getGenerator());
+
+ assertNotNull(rssChannel.getImage());
+ assertNotNull(rssChannel.getImage().getUrl());
+ assertEquals(FEED_IMAGE_URL, rssChannel.getImage().getUrl());
+
+ assertTrue(rssChannel.getItems().size() > 0);
+ RssItem rssItem = rssChannel.getItems().get(0);
+ assertNotNull(rssItem);
+
+ assertNotNull(rssItem.getTitle());
+ assertEquals(ITEM_TITLE, rssItem.getTitle());
+
+ assertNotNull(rssItem.getLink());
+ assertEquals(ITEM_LINK, rssItem.getLink());
+
+ assertNotNull(rssItem.getDescription());
+ assertEquals(ITEM_DESCRIPTION, rssItem.getDescription());
+
+ assertNotNull(rssItem.getAuthor());
+ assertEquals(ITEM_AUTHOR, rssItem.getAuthor());
+
+ assertTrue(rssItem.getCategories().size() == 2);
+ assertEquals(FEED_CTG1_DOMAIN, rssItem.getCategories().get(0).getDomain());
+ assertEquals(FEED_CTG1_VALUE, rssItem.getCategories().get(0).getContent());
+ assertEquals(FEED_CTG2_DOMAIN, rssItem.getCategories().get(1).getDomain());
+ assertEquals(FEED_CTG2_VALUE, rssItem.getCategories().get(1).getContent());
+
+ assertNotNull(rssItem.getEnclosure());
+ assertEquals(ITEM_ENCLOSURE_URL, rssItem.getEnclosure().getUrl());
+ assertEquals(ITEM_ENCLOSURE_LENGTH, rssItem.getEnclosure().getLength());
+ assertEquals(ITEM_ENCLOSURE_TYPE, rssItem.getEnclosure().getType());
+
+ assertNotNull(rssItem.getGuid());
+ assertEquals(ITEM_GUID, rssItem.getGuid().getContent());
+
+ assertNotNull(rssItem.getPubDate());
+ assertEquals(RssChannel.convertRssDateToJavaDate(ITEM_PUBDATE), RssChannel
+ .convertRssDateToJavaDate(rssItem.getPubDate()));
+ }
+}
Added: incubator/wink/trunk/wink-examples/client/ReadRSS-client/src/main/java/org/apache/wink/example/ReadRssAsSyndFeed.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-examples/client/ReadRSS-client/src/main/java/org/apache/wink/example/ReadRssAsSyndFeed.java?rev=935746&view=auto
==============================================================================
--- incubator/wink/trunk/wink-examples/client/ReadRSS-client/src/main/java/org/apache/wink/example/ReadRssAsSyndFeed.java (added)
+++ incubator/wink/trunk/wink-examples/client/ReadRSS-client/src/main/java/org/apache/wink/example/ReadRssAsSyndFeed.java Mon Apr 19 21:03:37 2010
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+package org.apache.wink.example;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
+
+import org.apache.wink.client.Resource;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.common.internal.model.ModelUtils;
+import org.apache.wink.common.model.atom.AtomFeed;
+import org.apache.wink.common.model.atom.ObjectFactory;
+import org.apache.wink.common.model.rss.RssFeed;
+import org.apache.wink.common.model.synd.SyndEntry;
+import org.apache.wink.common.model.synd.SyndFeed;
+
+/**
+ * This is an example of reading an RSS Feed using SyndFeed APIs. (Mapping RSS
+ * into Syndication Object Model)
+ */
+public class ReadRssAsSyndFeed {
+
+ public static void main(String[] args) {
+ try {
+ // create the rest client instance
+ RestClient restClient = new RestClient();
+
+ // create the resource instance to interact with
+ String rss_url = "http://www.rssboard.org/files/rss-2.0-sample.xml";
+ Resource feedResource = restClient.resource(rss_url);
+
+ // perform a GET on the resource. The resource will be returned as an Rss object
+ RssFeed rssFeed = feedResource.accept(MediaType.APPLICATION_XML_TYPE).get(RssFeed.class);
+
+ // Map RSS into SyndFeed
+ SyndFeed syndFeed = new SyndFeed();
+ syndFeed = rssFeed.toSynd(syndFeed);
+
+ // Now access RSS using SyndFeed APIs
+ if (syndFeed.getTitle() != null) {
+ System.out.println("Title = " + syndFeed.getTitle().getValue());
+ }
+ if (syndFeed.getSubtitle() != null) {
+ System.out.println("Descritpion = " + syndFeed.getSubtitle().getValue());
+ }
+ if (syndFeed.getLink("alternate") != null) {
+ System.out.println("Link = " + syndFeed.getLink("alternate").getHref());
+ }
+ int itemCount = 0;
+ for (SyndEntry syndEntry : syndFeed.getEntries()) {
+ System.out.println("Item " + ++itemCount + ":");
+ if (syndEntry.getTitle() != null) {
+ System.out.println("\tTitle = " + syndEntry.getTitle().getValue());
+ }
+ if (syndEntry.getSummary() != null) {
+ System.out.println("\tDescription = " + syndEntry.getSummary().getValue());
+ }
+ if (syndEntry.getLink("alternate") != null) {
+ System.out.println("\tLink = " + syndEntry.getLink("alternate").getHref());
+ }
+ }
+
+ System.out.println("\nComplete XML contents (mapped into SyndFeed / Atom format):");
+ Marshaller m = AtomFeed.getMarshaller();
+ JAXBElement<AtomFeed> element =
+ (new ObjectFactory()).createFeed(new AtomFeed(syndFeed));
+ try {
+ ModelUtils.marshal(m, element, System.out);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}