diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java index 05efa10f1..d2c4e0419 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java @@ -16,6 +16,7 @@ */ package com.rometools.modules.itunes.io; +import com.rometools.modules.itunes.types.Subcategory; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -75,9 +76,9 @@ public void generate(final Module module, final Element element) { final Element category = generateSimpleElement("category", ""); category.setAttribute("text", cat.getName()); - if (cat.getSubcategory() != null) { + for (Subcategory subcategory : cat.getSubcategories()) { final Element subcat = generateSimpleElement("category", ""); - subcat.setAttribute("text", cat.getSubcategory().getName()); + subcat.setAttribute("text", subcategory.getName()); category.addContent(subcat); } diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java index d8a66abde..7c3917d65 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java @@ -87,14 +87,17 @@ public com.rometools.rome.feed.module.Module parse(final Element element, final final Category cat = new Category(); cat.setName(category.getAttribute("text").getValue().trim()); - final Element subcategory = category.getChild("category", ns); - - if (subcategory != null && subcategory.getAttribute("text") != null) { - final Subcategory subcat = new Subcategory(); - subcat.setName(subcategory.getAttribute("text").getValue().trim()); - cat.setSubcategory(subcat); + final List subCategories = category.getChildren("category", ns); + + for (Element subCategory : subCategories) { + if (subCategory.getAttribute("text") != null) { + final Subcategory subcat = new Subcategory(); + subcat.setName(subCategory.getAttribute("text").getValue().trim()); + cat.addSubcategory(subcat); + } } + feedInfo.getCategories().add(cat); } } diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/types/Category.java b/rome-modules/src/main/java/com/rometools/modules/itunes/types/Category.java index d59e5f8d8..21dce09e8 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/types/Category.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/types/Category.java @@ -16,7 +16,10 @@ */ package com.rometools.modules.itunes.types; +import com.rometools.utils.Lists; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; /** * This Category information. Basically a name and an optional Subcategory. Categories are defined @@ -26,7 +29,7 @@ public class Category implements Serializable { private static final long serialVersionUID = 1L; private String name; - private Subcategory subcategory; + private List subcategories = new ArrayList(); public Category() { } @@ -64,7 +67,16 @@ public void setName(final String name) { * @return Returns the Subcategory object for this category */ public Subcategory getSubcategory() { - return subcategory; + return subcategories.isEmpty() ? null : subcategories.get(0); + } + + /** + * Returns the list of subcategories under this category + * + * @return List of subcategories + */ + public List getSubcategories() { + return subcategories; } /** @@ -73,7 +85,15 @@ public Subcategory getSubcategory() { * @param subcategory Sets the Subcategory object for this category */ public void setSubcategory(final Subcategory subcategory) { - this.subcategory = subcategory; + subcategories = Lists.create(subcategory); + } + + public void setSubcategories(final List subcategories) { + this.subcategories = subcategories; + } + + public void addSubcategory(final Subcategory subcategory) { + this.subcategories.add(subcategory); } /** @@ -85,10 +105,7 @@ public void setSubcategory(final Subcategory subcategory) { public Object clone() { final Category c = new Category(); c.setName(getName()); - - if (getSubcategory() != null) { - c.setSubcategory((Subcategory) getSubcategory().clone()); - } + c.setSubcategories(getSubcategories()); return c; } @@ -97,8 +114,8 @@ public Object clone() { public String toString() { final StringBuffer sb = new StringBuffer(getName()); - if (getSubcategory() != null) { - sb.append(" -> " + getSubcategory().toString()); + for (Subcategory subcategory : getSubcategories()) { + sb.append(" -> " + subcategory.toString()); } return sb.toString(); diff --git a/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java b/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java index 9d8b07af4..f35bbc791 100644 --- a/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java +++ b/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java @@ -76,7 +76,7 @@ public void testGetNamespaceUri() { * Test of parse method, of class com.totsp.xml.syndication.itunes.ITunesParser. */ public void testParse() throws Exception { - File feed = new File(getTestFile("xml/leshow.xml")); + File feed = new File(getTestFile("itunes/leshow.xml")); final SyndFeedInput input = new SyndFeedInput(); SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL())); @@ -86,7 +86,14 @@ public void testParse() throws Exception { assertEquals("owner", "Harry Shearer", feedInfo.getOwnerName()); assertEquals("email", "", feedInfo.getOwnerEmailAddress()); assertEquals("image", "http://a1.phobos.apple.com/Music/y2005/m06/d26/h21/mcdrrifv.jpg", feedInfo.getImage().toExternalForm()); - assertEquals("category", "Comedy", feedInfo.getCategories().get(0).getName()); + assertEquals("category1", "Comedy", feedInfo.getCategories().get(0).getName()); + assertEquals("category2", + "Arts & Entertainment", + feedInfo.getCategories().get(1).getName()); + assertEquals( + "subCategory", + "Entertainment", + feedInfo.getCategories().get(1).getSubcategories().get(0).getName()); assertEquals( "summary", "A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer.", diff --git a/rome-modules/src/test/resources/itunes/leshow.xml b/rome-modules/src/test/resources/itunes/leshow.xml index 961909705..13a757c66 100644 --- a/rome-modules/src/test/resources/itunes/leshow.xml +++ b/rome-modules/src/test/resources/itunes/leshow.xml @@ -8,187 +8,178 @@ An hour's worth of Harry Shearer A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer. serial + yes + http://example.org en - - KCRW 2005 - + + KCRW 2005 + Harry Shearer KCRW's Le Show - - - Comedy - - + Comedy - - - - + + + + + + le Show + Harry Shearer + + + + + http://66.186.18.80/podcast/mp3/ls/ls050731le_Show.mp3 + + Sun, 31 Jul 2005 16:00:00 GMT + + + + Comedy + + - - - - - - - - le Show - Harry Shearer - - - - - http://66.186.18.80/podcast/mp3/ls/ls050731le_Show.mp3 - - Sun, 31 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - + + + + - - - - - - no - - 46:34 - - - 1 - 1 - full - - - - - le Show - Harry Shearer - - - - - - - - http://66.186.18.80/podcast/mp3/ls/ls050724le_Show.mp3 - - Sun, 24 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - + + + + + + no + + 46:34 + + + 1 + 1 + full + + + + + le Show + Harry Shearer + + + + + + + + http://66.186.18.80/podcast/mp3/ls/ls050724le_Show.mp3 + + Sun, 24 Jul 2005 16:00:00 GMT + + + + Comedy + + - - - - - - no - - 44:00 - - - 1 - 2 - trailer - - - - - le Show - Harry Shearer - - - - - - - - http://66.186.18.80/podcast/mp3/ls/ls050717le_Show.mp3 - - Sun, 17 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - + + + + - - - - - - no - - 48:33 - - - 1 - 2 - bonus - - - - - le Show - Harry Shearer - - - - - http://66.186.18.80/podcast/mp3/ls/ls050710le_Show.mp3 - - Sun, 10 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - + + + + + + no + + 44:00 + + + 1 + 2 + trailer + + + + + le Show + Harry Shearer + + + + + + + + http://66.186.18.80/podcast/mp3/ls/ls050717le_Show.mp3 + + Sun, 17 Jul 2005 16:00:00 GMT + + + + Comedy + + - - - no - - 45:56 - - - - - + + + + + + + no + + 48:33 + + + 1 + 2 + bonus + + + + + le Show + Harry Shearer + + + + + http://66.186.18.80/podcast/mp3/ls/ls050710le_Show.mp3 + + Sun, 10 Jul 2005 16:00:00 GMT + + + + Comedy + + + + + + + + + + + + + + no + + 45:56 + + + + + +