diff --git a/src/main/java/com/sun/syndication/feed/opml/Opml.java b/src/main/java/com/sun/syndication/feed/opml/Opml.java index b42a26e..e574d5c 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Opml.java +++ b/src/main/java/com/sun/syndication/feed/opml/Opml.java @@ -29,9 +29,9 @@ import com.sun.syndication.feed.WireFeed; * @author Robert "kebernet" Cooper */ public class Opml extends WireFeed { - + private static final long serialVersionUID = 1L; - + private Date _created; private Date _modified; private Integer _verticalScrollState; @@ -39,7 +39,7 @@ public class Opml extends WireFeed { private Integer _windowLeft; private Integer _windowRight; private Integer _windowTop; - private List _outlines; + private List _outlines; private String _docs; private String _ownerEmail; private String _ownerId; @@ -135,7 +135,7 @@ public class Opml extends WireFeed { * * @param outlines Root level Outline object that should appear in the <body> */ - public void setOutlines(final List outlines) { + public void setOutlines(final List outlines) { _outlines = outlines; } @@ -144,9 +144,9 @@ public class Opml extends WireFeed { * * @return Root level Outline object that should appear in the <body> */ - public List getOutlines() { + public List getOutlines() { if (_outlines == null) { - _outlines = new ArrayList(); + _outlines = new ArrayList(); } return _outlines; diff --git a/src/main/java/com/sun/syndication/feed/opml/Outline.java b/src/main/java/com/sun/syndication/feed/opml/Outline.java index f66aeda..6d0f009 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Outline.java +++ b/src/main/java/com/sun/syndication/feed/opml/Outline.java @@ -26,6 +26,7 @@ import java.util.List; import com.sun.syndication.feed.impl.EqualsBean; import com.sun.syndication.feed.impl.ToStringBean; +import com.sun.syndication.feed.module.Module; /** * This class represents an OPML outline element. @@ -33,14 +34,14 @@ import com.sun.syndication.feed.impl.ToStringBean; * @author Robert "kebernet" Cooper */ public class Outline implements Cloneable, Serializable { - + private static final long serialVersionUID = 1L; - + private Date _created; - private List _attributes; - private List _categories; - private List _children; - private List _modules; + private List _attributes; + private List _categories; + private List _children; + private List _modules; private String _text; private String _title; private String _type; @@ -75,7 +76,7 @@ public class Outline implements Cloneable, Serializable { super(); setType("rss"); setTitle(title); - setAttributes(new ArrayList()); + setAttributes(new ArrayList()); if (xmlUrl != null) { getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); @@ -91,7 +92,7 @@ public class Outline implements Cloneable, Serializable { * * @param attributes List of attributes on this outline. */ - public void setAttributes(final List attributes) { + public void setAttributes(final List attributes) { _attributes = attributes; } @@ -100,9 +101,9 @@ public class Outline implements Cloneable, Serializable { * * @return List of attributes on this outline. */ - public List getAttributes() { + public List getAttributes() { if (_attributes == null) { - _attributes = new ArrayList(); + _attributes = new ArrayList(); } return _attributes; @@ -133,7 +134,7 @@ public class Outline implements Cloneable, Serializable { * * @param categories (OPML 2) A List of Strings indicating values in the category attribute. */ - public void setCategories(final List categories) { + public void setCategories(final List categories) { _categories = categories; } @@ -142,9 +143,9 @@ public class Outline implements Cloneable, Serializable { * * @return (OPML 2) A List of Strings indicating values in the category attribute. */ - public List getCategories() { + public List getCategories() { if (_categories == null) { - _categories = new ArrayList(); + _categories = new ArrayList(); } return _categories; @@ -155,7 +156,7 @@ public class Outline implements Cloneable, Serializable { * * @param children A list of sub-outlines for this entry. */ - public void setChildren(final List children) { + public void setChildren(final List children) { _children = children; } @@ -164,9 +165,9 @@ public class Outline implements Cloneable, Serializable { * * @return A list of sub-outlines for this entry. */ - public List getChildren() { + public List getChildren() { if (_children == null) { - _children = new ArrayList(); + _children = new ArrayList(); } return _children; @@ -228,13 +229,13 @@ public class Outline implements Cloneable, Serializable { return getAttributeValue("htmlUrl"); } - public void setModules(final List modules) { + public void setModules(final List modules) { _modules = modules; } - public List getModules() { + public List getModules() { if (_modules == null) { - _modules = new ArrayList(); + _modules = new ArrayList(); } return _modules; @@ -309,45 +310,40 @@ public class Outline implements Cloneable, Serializable { * @param name name of the attribute. */ public String getAttributeValue(final String name) { - final List attributes = Collections.synchronizedList(getAttributes()); - + final List attributes = Collections.synchronizedList(getAttributes()); for (int i = 0; i < attributes.size(); i++) { - final Attribute a = (Attribute) attributes.get(i); + final Attribute a = attributes.get(i); if (a.getName() != null && a.getName().equals(name)) { return a.getValue(); } } - return null; } @Override public Object clone() { + final Outline o = new Outline(); o.setBreakpoint(isBreakpoint()); - o.setCategories(new ArrayList(getCategories())); + o.setCategories(new ArrayList(getCategories())); o.setComment(isComment()); o.setCreated(_created != null ? (Date) _created.clone() : null); - o.setModules(new ArrayList(getModules())); + o.setModules(new ArrayList(getModules())); o.setText(getText()); o.setTitle(getTitle()); o.setType(getType()); - final ArrayList children = new ArrayList(); - + final ArrayList children = new ArrayList(); for (int i = 0; i < getChildren().size(); i++) { - children.add(((Outline) _children.get(i)).clone()); + children.add((Outline) _children.get(i).clone()); } - o.setChildren(children); - final ArrayList attributes = new ArrayList(); - + final ArrayList attributes = new ArrayList(); for (int i = 0; i < getAttributes().size(); i++) { - attributes.add(((Attribute) _attributes.get(i)).clone()); + attributes.add((Attribute) _attributes.get(i).clone()); } - o.setAttributes(attributes); return o; diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java index 099ce10..15b2ccb 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -57,7 +57,7 @@ public class ConverterForOPML10 implements Converter { protected void addOwner(final Opml opml, final SyndFeed syndFeed) { if (opml.getOwnerEmail() != null || opml.getOwnerName() != null) { - final List authors = new ArrayList(); + final List authors = new ArrayList(); final SyndPerson person = new SyndPersonImpl(); person.setEmail(opml.getOwnerEmail()); person.setName(opml.getOwnerName()); @@ -85,19 +85,18 @@ public class ConverterForOPML10 implements Converter { syndFeed.setModules(opml.getModules()); syndFeed.setFeedType(getType()); - final ArrayList entries = new ArrayList(); createEntries(new TreeContext(), syndFeed.getEntries(), opml.getOutlines()); } - protected void createEntries(final TreeContext context, final List allEntries, final List outlines) { - final List so = Collections.synchronizedList(outlines); + protected void createEntries(final TreeContext context, final List allEntries, final List outlines) { + final List so = Collections.synchronizedList(outlines); for (int i = 0; i < so.size(); i++) { - createEntry(context, allEntries, (Outline) so.get(i)); + createEntry(context, allEntries, so.get(i)); } } - protected SyndEntry createEntry(final TreeContext context, final List allEntries, final Outline outline) { + protected SyndEntry createEntry(final TreeContext context, final List allEntries, final Outline outline) { final SyndEntry entry = new SyndEntryImpl(); if (outline.getType() != null && outline.getType().equals("rss")) { @@ -161,17 +160,17 @@ public class ConverterForOPML10 implements Converter { entry.getCategories().add(cat); if (context.size() > 0) { - final Integer parent = (Integer) context.peek(); + final Integer parent = context.peek(); final SyndCategory pcat = new TreeCategoryImpl(); pcat.setTaxonomyUri(URI_TREE); pcat.setName("parent." + parent); entry.getCategories().add(pcat); } - final List attributes = Collections.synchronizedList(outline.getAttributes()); + final List attributes = Collections.synchronizedList(outline.getAttributes()); for (int i = 0; i < attributes.size(); i++) { - final Attribute a = (Attribute) attributes.get(i); + final Attribute a = attributes.get(i); final SyndCategory acat = new SyndCategoryImpl(); acat.setName(a.getValue()); acat.setTaxonomyUri(URI_ATTRIBUTE + a.getName()); @@ -197,22 +196,23 @@ public class ConverterForOPML10 implements Converter { */ @Override public WireFeed createRealFeed(final SyndFeed syndFeed) { - final List entries = Collections.synchronizedList(syndFeed.getEntries()); - final HashMap entriesByNode = new HashMap(); - final ArrayList doAfterPass = new ArrayList(); // this will hold entries that we can't parent the first time. - final ArrayList root = new ArrayList(); // this holds root level outlines; + final List entries = Collections.synchronizedList(syndFeed.getEntries()); + + final HashMap entriesByNode = new HashMap(); + final ArrayList doAfterPass = new ArrayList(); // this will hold entries that we can't parent the first time. + final ArrayList root = new ArrayList(); // this holds root level outlines; for (int i = 0; i < entries.size(); i++) { - final SyndEntry entry = (SyndEntry) entries.get(i); + final SyndEntry entry = entries.get(i); final Outline o = new Outline(); - final List cats = Collections.synchronizedList(entry.getCategories()); + final List cats = Collections.synchronizedList(entry.getCategories()); boolean parentFound = false; final StringBuffer category = new StringBuffer(); for (int j = 0; j < cats.size(); j++) { - final SyndCategory cat = (SyndCategory) cats.get(j); + final SyndCategory cat = cats.get(j); if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().equals(URI_TREE)) { final String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length()); @@ -222,7 +222,7 @@ public class ConverterForOPML10 implements Converter { } else if (cat.getName().startsWith("parent.")) { parentFound = true; - final Outline parent = (Outline) entriesByNode.get(nodeVal); + final Outline parent = entriesByNode.get(nodeVal); if (parent != null) { parent.getChildren().add(o); @@ -250,11 +250,11 @@ public class ConverterForOPML10 implements Converter { o.getAttributes().add(new Attribute("category", category.toString())); } - final List links = Collections.synchronizedList(entry.getLinks()); - final String entryLink = entry.getLink(); + final List links = Collections.synchronizedList(entry.getLinks()); + // final String entryLink = entry.getLink(); for (int j = 0; j < links.size(); j++) { - final SyndLink link = (SyndLink) links.get(j); + final SyndLink link = links.get(j); // if(link.getHref().equals(entryLink)) { if (link.getType() != null && link.getRel() != null && link.getRel().equals("alternate") @@ -289,8 +289,8 @@ public class ConverterForOPML10 implements Converter { // Do back and parenting for things we missed. for (int i = 0; i < doAfterPass.size(); i++) { - final OutlineHolder o = (OutlineHolder) doAfterPass.get(i); - final Outline parent = (Outline) entriesByNode.get(o.parent); + final OutlineHolder o = doAfterPass.get(i); + final Outline parent = entriesByNode.get(o.parent); if (parent == null) { root.add(o.outline); @@ -305,10 +305,10 @@ public class ConverterForOPML10 implements Converter { opml.setCreated(syndFeed.getPublishedDate()); opml.setTitle(syndFeed.getTitle()); - final List authors = Collections.synchronizedList(syndFeed.getAuthors()); + final List authors = Collections.synchronizedList(syndFeed.getAuthors()); for (int i = 0; i < authors.size(); i++) { - final SyndPerson p = (SyndPerson) authors.get(i); + final SyndPerson p = authors.get(i); if (syndFeed.getAuthor() == null || syndFeed.getAuthor().equals(p.getName())) { opml.setOwnerName(p.getName()); @@ -345,8 +345,8 @@ public class ConverterForOPML10 implements Converter { } } - private static class TreeContext extends Stack { - + private static class TreeContext extends Stack { + private static final long serialVersionUID = 1L; TreeContext() { diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java index 008bef1..4ed5b07 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java @@ -33,7 +33,7 @@ import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedGenerator; /** - * + * * @author Robert "kebernet" Cooper */ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { @@ -49,7 +49,7 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe /** * Creates an XML document (JDOM) for the given feed bean. *

- * + * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator. @@ -146,10 +146,10 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe addNotNullAttribute(e, "isComment", "true"); } - final List atts = Collections.synchronizedList(outline.getAttributes()); + final List atts = Collections.synchronizedList(outline.getAttributes()); for (int i = 0; i < atts.size(); i++) { - final Attribute att = (Attribute) atts.get(i); + final Attribute att = atts.get(i); addNotNullAttribute(e, att.getName(), att.getValue()); } @@ -159,13 +159,11 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe return e; } - protected List generateOutlines(final List outlines) { - final ArrayList elements = new ArrayList(); - + protected List generateOutlines(final List outlines) { + final ArrayList elements = new ArrayList(); for (int i = 0; outlines != null && i < outlines.size(); i++) { - elements.add(generateOutline((Outline) outlines.get(i))); + elements.add(generateOutline(outlines.get(i))); } - return elements; } diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java index ab540d6..34b4a7f 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java @@ -35,7 +35,7 @@ import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedParser; /** - * + * * @author Robert "kebernet" Cooper */ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { @@ -55,7 +55,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { *

* It checks if the given document if the type of feeds the parser understands. *

- * + * * @param document XML Document (JDOM) to check if it can be parsed by this parser. * @return true if the parser know how to parser this feed, false otherwise. */ @@ -74,7 +74,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { /** * Parses an XML document (JDOM Document) into a feed bean. *

- * + * * @param document XML document (JDOM) to parse. * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). * @return the resulting feed bean. @@ -177,11 +177,11 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { outline.setType(e.getAttributeValue("type")); outline.setTitle(e.getAttributeValue("title")); - final List jAttributes = e.getAttributes(); - final ArrayList attributes = new ArrayList(); + final List jAttributes = e.getAttributes(); + final ArrayList attributes = new ArrayList(); for (int i = 0; i < jAttributes.size(); i++) { - final org.jdom2.Attribute a = (org.jdom2.Attribute) jAttributes.get(i); + final org.jdom2.Attribute a = jAttributes.get(i); if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") && !a.getName().equals("type")) { @@ -211,20 +211,18 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { } } - final List children = e.getChildren("outline"); + final List children = e.getChildren("outline"); outline.setModules(parseItemModules(e, locale)); outline.setChildren(parseOutlines(children, validate, locale)); return outline; } - protected List parseOutlines(final List elements, final boolean validate, final Locale locale) throws FeedException { - final ArrayList results = new ArrayList(); - + protected List parseOutlines(final List elements, final boolean validate, final Locale locale) throws FeedException { + final ArrayList results = new ArrayList(); for (int i = 0; i < elements.size(); i++) { - results.add(parseOutline((Element) elements.get(i), validate, locale)); + results.add(parseOutline(elements.get(i), validate, locale)); } - return results; } diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java index 5ddba37..089f686 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java @@ -30,7 +30,7 @@ import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; /** - * + * * @author cooper */ public class OPML20Parser extends OPML10Parser { @@ -44,7 +44,7 @@ public class OPML20Parser extends OPML10Parser { *

* It checks if the given document if the type of feeds the parser understands. *

- * + * * @param document XML Document (JDOM) to check if it can be parsed by this parser. * @return true if the parser know how to parser this feed, false otherwise. */ @@ -54,7 +54,7 @@ public class OPML20Parser extends OPML10Parser { if (e.getName().equals("opml") && (e.getChild("head") != null && e.getChild("head").getChild("docs") != null || e.getAttributeValue("version") != null - && e.getAttributeValue("version").equals("2.0") || e.getChild("head") != null && e.getChild("head").getChild("ownerId") != null)) { + && e.getAttributeValue("version").equals("2.0") || e.getChild("head") != null && e.getChild("head").getChild("ownerId") != null)) { return true; } @@ -64,7 +64,7 @@ public class OPML20Parser extends OPML10Parser { /** * Parses an XML document (JDOM Document) into a feed bean. *

- * + * * @param document XML document (JDOM) to parse. * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). * @return the resulting feed bean. @@ -102,10 +102,10 @@ public class OPML20Parser extends OPML10Parser { retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"), locale)); } - final List atts = retValue.getAttributes(); + final List atts = retValue.getAttributes(); for (int i = 0; i < atts.size(); i++) { - final Attribute a = (Attribute) atts.get(i); + final Attribute a = atts.get(i); if (a.getName().equals("created")) { retValue.getAttributes().remove(a); diff --git a/src/test/java/com/sun/syndication/TestXmlReader.java b/src/test/java/com/sun/syndication/TestXmlReader.java index 3b2d3af..23ec2e6 100644 --- a/src/test/java/com/sun/syndication/TestXmlReader.java +++ b/src/test/java/com/sun/syndication/TestXmlReader.java @@ -32,7 +32,7 @@ import com.sun.syndication.io.XmlReader; /** * @author pat, tucu - * + * */ public class TestXmlReader extends TestCase { @@ -44,17 +44,22 @@ public class TestXmlReader extends TestCase { } protected void _testRawNoBomValid(final String encoding) throws Exception { + InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); - XmlReader xmlReader = new XmlReader(is, false); + final XmlReader xmlReader = new XmlReader(is, false); assertEquals(xmlReader.getEncoding(), "UTF-8"); + xmlReader.close(); is = getXmlStream("no-bom", "xml-prolog", encoding, encoding); - xmlReader = new XmlReader(is); + final XmlReader xmlReader2 = new XmlReader(is); assertEquals(xmlReader.getEncoding(), "UTF-8"); + xmlReader2.close(); is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); - xmlReader = new XmlReader(is); + final XmlReader xmlReader3 = new XmlReader(is); assertEquals(xmlReader.getEncoding(), encoding); + xmlReader3.close(); + } protected void _testRawNoBomInvalid(final String encoding) throws Exception { @@ -62,6 +67,7 @@ public class TestXmlReader extends TestCase { try { final XmlReader xmlReader = new XmlReader(is, false); fail("It should have failed"); + xmlReader.close(); } catch (final IOException ex) { assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } @@ -81,6 +87,7 @@ public class TestXmlReader extends TestCase { } else { assertEquals(xmlReader.getEncoding().substring(0, encoding.length()), encoding); } + xmlReader.close(); } protected void _testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { @@ -88,6 +95,7 @@ public class TestXmlReader extends TestCase { try { final XmlReader xmlReader = new XmlReader(is, false); fail("It should have failed for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); + xmlReader.close(); } catch (final IOException ex) { assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } @@ -169,6 +177,7 @@ public class TestXmlReader extends TestCase { } else { assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); } + xmlReader.close(); } protected void _testHttpInvalid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { @@ -176,6 +185,7 @@ public class TestXmlReader extends TestCase { try { final XmlReader xmlReader = new XmlReader(is, cT, false); fail("It should have failed for HTTP Content-type " + cT + ", BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); + xmlReader.close(); } catch (final IOException ex) { assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } @@ -186,6 +196,7 @@ public class TestXmlReader extends TestCase { final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml-prolog" : "xml-prolog-encoding", streamEnc, prologEnc); final XmlReader xmlReader = new XmlReader(is, cT, true); assertEquals(xmlReader.getEncoding(), shouldbe); + xmlReader.close(); } // XML Stream generator @@ -195,7 +206,7 @@ public class TestXmlReader extends TestCase { private static final int[] UTF_16LE_BOM_BYTES = { 0xFF, 0XFE }; private static final int[] UTF_8_BOM_BYTES = { 0xEF, 0xBB, 0xBF }; - private static final Map BOMs = new HashMap(); + private static final Map BOMs = new HashMap(); static { BOMs.put("no-bom", NO_BOM_BYTES); @@ -211,7 +222,7 @@ public class TestXmlReader extends TestCase { private static final MessageFormat INFO = new MessageFormat("\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); - private static final Map XMLs = new HashMap(); + private static final Map XMLs = new HashMap(); static { XMLs.put("xml", XML); @@ -220,18 +231,18 @@ public class TestXmlReader extends TestCase { } /** - * + * * @param bomType no-bom, UTF-16BE-bom, UTF-16LE-bom, UTF-8-bom * @param xmlType xml, xml-prolog, xml-prolog-charset * @return XML stream */ protected InputStream getXmlStream(final String bomType, final String xmlType, final String streamEnc, final String prologEnc) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - int[] bom = (int[]) BOMs.get(bomType); + int[] bom = BOMs.get(bomType); if (bom == null) { bom = new int[0]; } - final MessageFormat xml = (MessageFormat) XMLs.get(xmlType); + final MessageFormat xml = XMLs.get(xmlType); for (final int element : bom) { baos.write(element); }