SyndCategories added to copyFrom on feed and entry (fixes #131)
This commit is contained in:
parent
5b62039b17
commit
a157bac8dc
6 changed files with 129 additions and 1 deletions
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
package com.sun.syndication.feed.synd;
|
||||
|
||||
import com.sun.syndication.feed.CopyFrom;
|
||||
|
||||
/**
|
||||
* Bean interface for categories of SyndFeedImpl feeds and entries.
|
||||
* <p>
|
||||
|
@ -24,7 +26,7 @@ package com.sun.syndication.feed.synd;
|
|||
* @author Alejandro Abdelnur
|
||||
*
|
||||
*/
|
||||
public interface SyndCategory extends Cloneable {
|
||||
public interface SyndCategory extends Cloneable, CopyFrom<SyndCategory> {
|
||||
/**
|
||||
* Returns the category name.
|
||||
* <p>
|
||||
|
|
|
@ -20,8 +20,13 @@ package com.sun.syndication.feed.synd;
|
|||
import java.io.Serializable;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.syndication.feed.CopyFrom;
|
||||
import com.sun.syndication.feed.impl.CopyFromHelper;
|
||||
import com.sun.syndication.feed.impl.ObjectBean;
|
||||
import com.sun.syndication.feed.module.DCSubject;
|
||||
import com.sun.syndication.feed.module.DCSubjectImpl;
|
||||
|
@ -175,6 +180,26 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
|
|||
subject.setTaxonomyUri(taxonomyUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends CopyFrom<SyndCategory>> getInterface() {
|
||||
return SyndCategory.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyFrom(final CopyFrom<? extends SyndCategory> obj) {
|
||||
COPY_FROM_HELPER.copy(this, obj);
|
||||
}
|
||||
|
||||
private static final CopyFromHelper COPY_FROM_HELPER;
|
||||
|
||||
static {
|
||||
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
|
||||
basePropInterfaceMap.put("name", String.class);
|
||||
basePropInterfaceMap.put("taxonomyUri", String.class);
|
||||
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = Collections.emptyMap();
|
||||
COPY_FROM_HELPER = new CopyFromHelper(SyndCategory.class, basePropInterfaceMap, basePropClassImplMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -512,10 +512,12 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
|
|||
basePropInterfaceMap.put("contents", SyndContent.class);
|
||||
basePropInterfaceMap.put("enclosures", SyndEnclosure.class);
|
||||
basePropInterfaceMap.put("modules", Module.class);
|
||||
basePropInterfaceMap.put("categories", SyndCategory.class);
|
||||
|
||||
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom<?>>, Class<?>>();
|
||||
basePropClassImplMap.put(SyndContent.class, SyndContentImpl.class);
|
||||
basePropClassImplMap.put(SyndEnclosure.class, SyndEnclosureImpl.class);
|
||||
basePropClassImplMap.put(SyndCategory.class, SyndCategoryImpl.class);
|
||||
basePropClassImplMap.put(DCModule.class, DCModuleImpl.class);
|
||||
basePropClassImplMap.put(SyModule.class, SyModuleImpl.class);
|
||||
|
||||
|
|
|
@ -812,10 +812,12 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
|
|||
basePropInterfaceMap.put("image", SyndImage.class);
|
||||
basePropInterfaceMap.put("entries", SyndEntry.class);
|
||||
basePropInterfaceMap.put("modules", Module.class);
|
||||
basePropInterfaceMap.put("categories", SyndCategory.class);
|
||||
|
||||
final Map<Class<? extends CopyFrom<?>>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom<?>>, Class<?>>();
|
||||
basePropClassImplMap.put(SyndEntry.class, SyndEntryImpl.class);
|
||||
basePropClassImplMap.put(SyndImage.class, SyndImageImpl.class);
|
||||
basePropClassImplMap.put(SyndCategory.class, SyndCategoryImpl.class);
|
||||
basePropClassImplMap.put(DCModule.class, DCModuleImpl.class);
|
||||
basePropClassImplMap.put(SyModule.class, SyModuleImpl.class);
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.sun.syndication.unittest.issues;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.syndication.feed.synd.SyndCategory;
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
import com.sun.syndication.feed.synd.SyndEntryImpl;
|
||||
import com.sun.syndication.feed.synd.SyndFeed;
|
||||
import com.sun.syndication.feed.synd.SyndFeedImpl;
|
||||
import com.sun.syndication.unittest.FeedTest;
|
||||
|
||||
/**
|
||||
* Test for #131: SyndFeedImpl copyFrom method does not copy Entry Categories.
|
||||
* @author Martin Kurz
|
||||
*
|
||||
*/
|
||||
public class Issue131Test extends FeedTest {
|
||||
|
||||
public Issue131Test() {
|
||||
super("issue131-rss.xml");
|
||||
}
|
||||
|
||||
public void testOriginalCategories() throws Exception {
|
||||
checkFeed(getCachedSyndFeed());
|
||||
}
|
||||
|
||||
public void testCopiedFeedCategories() throws Exception {
|
||||
final SyndFeed copiedFeed = new SyndFeedImpl();
|
||||
copiedFeed.copyFrom(getCachedSyndFeed());
|
||||
checkFeed(copiedFeed);
|
||||
}
|
||||
|
||||
public void testCopiedFeedEntryCategories() throws Exception {
|
||||
for (final SyndEntry entry : getCachedSyndFeed().getEntries()) {
|
||||
final SyndEntry copiedEntry = new SyndEntryImpl();
|
||||
copiedEntry.copyFrom(entry);
|
||||
checkEntryCategories(copiedEntry.getCategories());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFeed(final SyndFeed feed) {
|
||||
checkFeedCategories(feed.getCategories());
|
||||
for (final SyndEntry entry : feed.getEntries()) {
|
||||
checkEntryCategories(entry.getCategories());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFeedCategories(final List<SyndCategory> categories) {
|
||||
assertNotNull(categories);
|
||||
assertEquals(2, categories.size());
|
||||
checkCategory(categories.get(0), "Channel Category 1");
|
||||
checkCategory(categories.get(1), "Channel Category 2");
|
||||
}
|
||||
|
||||
private void checkEntryCategories(final List<SyndCategory> categories) {
|
||||
assertNotNull(categories);
|
||||
assertEquals(2, categories.size());
|
||||
checkCategory(categories.get(0), "Entry Category 1");
|
||||
checkCategory(categories.get(1), "Entry Category 2");
|
||||
}
|
||||
|
||||
private void checkCategory(final SyndCategory category, final String expectedName) {
|
||||
assertNotNull(category);
|
||||
assertEquals("http://somewhere.org/taxonomy", category.getTaxonomyUri());
|
||||
assertEquals(expectedName, category.getName());
|
||||
}
|
||||
}
|
30
src/test/resources/issue131-rss.xml
Normal file
30
src/test/resources/issue131-rss.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>Testing</title>
|
||||
<link>http://feeds.somewhere.org/</link>
|
||||
<description>A dumb test feed file</description>
|
||||
<language>en-us</language>
|
||||
<copyright>Copyright (c) 200xx by nobody</copyright>
|
||||
<pubDate>Wed, 03 Sep 2008 00:00:00 EST</pubDate>
|
||||
<lastBuildDate>Wed, 03 Sep 2008 17:07:40 EST</lastBuildDate>
|
||||
<image>
|
||||
<title>Test Image</title>
|
||||
<url>http://feeds.somewhere.org/feedImg.gif</url>
|
||||
<link>http://feeds.somewhere.org</link>
|
||||
<width>125</width>
|
||||
<height>45</height>
|
||||
<description>Test Feed Image</description>
|
||||
</image>
|
||||
<category domain="http://somewhere.org/taxonomy">Channel Category 1</category>
|
||||
<category domain="http://somewhere.org/taxonomy">Channel Category 2</category>
|
||||
<item>
|
||||
<title>Entry 1</title>
|
||||
<category domain="http://somewhere.org/taxonomy">Entry Category 1</category>
|
||||
<category domain="http://somewhere.org/taxonomy">Entry Category 2</category>
|
||||
<link>http://feeds.somewhere.org/index.jsp?id=2043</link>
|
||||
<description>Entry 1 Description</description>
|
||||
<pubDate>Wed, 03 Sep 2008 17:03:03 EST</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in a new issue