From 14696ebed038577e825f6309be971f64fdf1229c Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 7 Oct 2013 22:02:04 +0200 Subject: [PATCH] Formatted code Updated POM --- pom.xml | 275 +++++++------- .../org/rometools/feed/opml/Attribute.java | 12 +- .../java/org/rometools/feed/opml/Opml.java | 81 ++-- .../java/org/rometools/feed/opml/Outline.java | 66 +++- .../feed/synd/impl/ConverterForOPML10.java | 135 +++---- .../feed/synd/impl/ConverterForOPML20.java | 14 +- .../feed/synd/impl/TreeCategoryImpl.java | 11 +- .../rometools/io/impl/OPML10Generator.java | 13 +- .../org/rometools/io/impl/OPML10Parser.java | 23 +- .../rometools/io/impl/OPML20Generator.java | 20 +- .../org/rometools/io/impl/OPML20Parser.java | 21 +- .../org/rometools/unittest/FeedOpsTest.java | 94 ++--- .../java/org/rometools/unittest/FeedTest.java | 43 ++- .../org/rometools/unittest/SyndFeedTest.java | 349 ++++++------------ .../org/rometools/unittest/TestOpsOPML10.java | 37 +- .../unittest/TestOpsOPML10links.java | 61 ++- .../org/rometools/unittest/TestOpsOPML20.java | 31 +- .../unittest/TestXmlFixerReader.java | 133 +++---- .../org/rometools/unittest/TestXmlReader.java | 271 +++++++------- 19 files changed, 803 insertions(+), 887 deletions(-) diff --git a/pom.xml b/pom.xml index ae38037..6aca63a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,26 +1,34 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + org.rometools rome-opml - jar - 1.5-SNAPSHOT + 2.0.0-SNAPSHOT + rome-opml + http://rometools.github.io/rome-opml/ + Support for OPML 1 and OPML 2 in ROME + ROME Project https://github.com/rometools/ + https://github.com/rometools/rome-opml/issues + scm:git:git@github.com:rometools/rome-opml.git scm:git:git@github.com:rometools/rome-opml.git https://github.com/rometools/rome-opml/ + kebernet @@ -28,6 +36,7 @@ Robert Cooper + The Apache Software License, Version 2.0 @@ -35,169 +44,137 @@ repo - + + + UTF-8 + + + - maven2-repository.dev.java.net - http://download.java.net/maven/2 + central.staging + http://oss.sonatype.org/service/local/staging/deploy/maven2 - - - - junit - junit - 3.8.1 - test - - - rome - rome - 1.0 - compile - - + + sonatype.snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + - - org.apache.maven.plugins - maven-scm-plugin - 1.0 - - install - - + + + + + + + + org.apache.maven.plugins maven-compiler-plugin - 2.0.2 + 3.1 - 1.4 - 1.4 - ${project.build.sourceEncoding} + 1.6 + 1.6 org.apache.maven.plugins maven-resources-plugin 2.6 + + + org.apache.maven.plugins + maven-site-plugin + 3.3 - ${project.build.sourceEncoding} + 9000 + ${basedir}/target/site/tempdir - - org.apache.maven.plugins - maven-site-plugin - 3.3 - - 9000 - ${basedir}/target/site/tempdir - - - - org.apache.maven.plugins - maven-scm-publish-plugin - 1.0-beta-2 - - gh-pages - scm:git:git@github.com:rometools/rome-opml.git - ${project.build.directory}/site - - + + org.apache.maven.plugins + maven-scm-publish-plugin + 1.0-beta-2 + + gh-pages + scm:git:git@github.com:rometools/rome-opml.git + ${project.build.directory}/site + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + - - - release - - - performRelease - true - - - - - central.staging - Nexus Release Repository - http://oss.sonatype.org/service/local/staging/deploy/maven2 - - - sonatype.snapshots - My Nexus Snapshots Repository - https://oss.sonatype.org/content/repositories/snapshots/ - - - - - - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - verify - - sign - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - - - - - UTF-8 - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.6 - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9 - - - - javadoc - test-javadoc - - - - aggregate - false - - aggregate - - - - - - + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + + javadoc + test-javadoc + + + + aggregate + false + + aggregate + + + + + + + + + + junit + junit + 4.11 + test + + + org.rometools + rome + 2.0.0-SNAPSHOT + compile + + + diff --git a/src/main/java/org/rometools/feed/opml/Attribute.java b/src/main/java/org/rometools/feed/opml/Attribute.java index a29770c..934b106 100644 --- a/src/main/java/org/rometools/feed/opml/Attribute.java +++ b/src/main/java/org/rometools/feed/opml/Attribute.java @@ -22,10 +22,9 @@ import com.sun.syndication.feed.impl.ToStringBean; import java.io.Serializable; - /** * This is a simple name-value pair attribute for outlines. - * + * * @author Robert "kebernet" Cooper */ public class Attribute implements Cloneable, Serializable { @@ -39,6 +38,7 @@ public class Attribute implements Cloneable, Serializable { /** * Creates a new instance of Attribute. + * * @param name name of the attribute. * @param value value of the attribute. */ @@ -53,6 +53,7 @@ public class Attribute implements Cloneable, Serializable { /** * name of the attribute. + * * @param name name of the attribute. */ public void setName(String name) { @@ -61,6 +62,7 @@ public class Attribute implements Cloneable, Serializable { /** * name of the attribute. + * * @return name of the attribute. */ public String getName() { @@ -69,6 +71,7 @@ public class Attribute implements Cloneable, Serializable { /** * value of the attribute. + * * @param value value of the attribute. */ public void setValue(String value) { @@ -77,28 +80,33 @@ public class Attribute implements Cloneable, Serializable { /** * value of the attribute. + * * @return value of the attribute. */ public String getValue() { return _value; } + @Override public Object clone() { return new Attribute(this._name, this._value); } + @Override public boolean equals(Object obj) { EqualsBean eBean = new EqualsBean(Attribute.class, this); return eBean.beanEquals(obj); } + @Override public int hashCode() { EqualsBean equals = new EqualsBean(Attribute.class, this); return equals.beanHashCode(); } + @Override public String toString() { ToStringBean tsBean = new ToStringBean(Attribute.class, this); diff --git a/src/main/java/org/rometools/feed/opml/Opml.java b/src/main/java/org/rometools/feed/opml/Opml.java index 0f5d025..2773b0e 100644 --- a/src/main/java/org/rometools/feed/opml/Opml.java +++ b/src/main/java/org/rometools/feed/opml/Opml.java @@ -23,10 +23,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; - /** - * This class represents the root of an OPML 1/2 feed and contains the elements that - * may appear in the <head> tag of the feed. + * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in the <head> tag of the feed. + * * @author Robert "kebernet" Cooper */ public class Opml extends WireFeed { @@ -52,6 +51,7 @@ public class Opml extends WireFeed { /** * is a date-time, indicating when the document was created. + * * @param created date-time, indicating when the document was created. */ public void setCreated(Date created) { @@ -60,6 +60,7 @@ public class Opml extends WireFeed { /** * <dateCreated> is a date-time, indicating when the document was created. + * * @return date-time, indicating when the document was created. */ public Date getCreated() { @@ -67,7 +68,9 @@ public class Opml extends WireFeed { } /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * * @param docs http address of documentation for the format used */ public void setDocs(String docs) { @@ -75,7 +78,9 @@ public class Opml extends WireFeed { } /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * * @return http address of documentation for the format used */ public String getDocs() { @@ -83,7 +88,10 @@ public class Opml extends WireFeed { } /** - * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The + * order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the + * list. + * * @param expansionState int array containing expanded elements. */ public void setExpansionState(int[] expansionState) { @@ -91,7 +99,10 @@ public class Opml extends WireFeed { } /** - * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The + * order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the + * list. + * * @return int array containing expanded elements. */ public int[] getExpansionState() { @@ -100,6 +111,7 @@ public class Opml extends WireFeed { /** * <dateModified> is a date-time, indicating when the document was last modified. + * * @param modified date-time, indicating when the document was last modified. */ public void setModified(Date modified) { @@ -108,6 +120,7 @@ public class Opml extends WireFeed { /** * <dateModified> is a date-time, indicating when the document was last modified. + * * @return date-time, indicating when the document was last modified. */ public Date getModified() { @@ -116,6 +129,7 @@ public class Opml extends WireFeed { /** * Root level Outline object that should appear in the <body> + * * @param outlines Root level Outline object that should appear in the <body> */ public void setOutlines(List outlines) { @@ -124,6 +138,7 @@ public class Opml extends WireFeed { /** * Root level Outline object that should appear in the <body> + * * @return Root level Outline object that should appear in the <body> */ public List getOutlines() { @@ -135,7 +150,8 @@ public class Opml extends WireFeed { } /** - * <ownerEmail> is a string, the email address of the owner of the document. + * <ownerEmail> is a string, the email address of the owner of the document. + * * @param ownerEmail the email address of the owner of the document. */ public void setOwnerEmail(String ownerEmail) { @@ -143,7 +159,8 @@ public class Opml extends WireFeed { } /** - * <ownerEmail> is a string, the email address of the owner of the document. + * <ownerEmail> is a string, the email address of the owner of the document. + * * @return the email address of the owner of the document. */ public String getOwnerEmail() { @@ -151,23 +168,30 @@ public class Opml extends WireFeed { } /** - * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. - * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with + * the author of the document via email or other means. + * + * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the + * document via email or other means. */ public void setOwnerId(String ownerId) { this._ownerId = ownerId; } /** - * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. - * @return http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with + * the author of the document via email or other means. + * + * @return http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the + * document via email or other means. */ public String getOwnerId() { return _ownerId; } /** - * <ownerName> is a string, the owner of the document. + * <ownerName> is a string, the owner of the document. + * * @param ownerName the owner of the document. */ public void setOwnerName(String ownerName) { @@ -175,7 +199,8 @@ public class Opml extends WireFeed { } /** - * <ownerName> is a string, the owner of the document. + * <ownerName> is a string, the owner of the document. + * * @return the owner of the document. */ public String getOwnerName() { @@ -183,7 +208,8 @@ public class Opml extends WireFeed { } /** - * <title> is the title of the document. + * <title> is the title of the document. + * * @param title title of the document. */ public void setTitle(String title) { @@ -191,7 +217,8 @@ public class Opml extends WireFeed { } /** - * <title> is the title of the document. + * <title> is the title of the document. + * * @return title of the document. */ public String getTitle() { @@ -199,7 +226,9 @@ public class Opml extends WireFeed { } /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the + * expansion state already applied. + * * @param verticalScrollState which line of the outline is displayed on the top line of the window. */ public void setVerticalScrollState(Integer verticalScrollState) { @@ -207,8 +236,10 @@ public class Opml extends WireFeed { } /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. - * @return which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the + * expansion state already applied. + * + * @return which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. */ public Integer getVerticalScrollState() { return _verticalScrollState; @@ -216,6 +247,7 @@ public class Opml extends WireFeed { /** * <windowBottom> is a number, the pixel location of the bottom edge of the window. + * * @param windowBottom the pixel location of the bottom edge of the window. */ public void setWindowBottom(Integer windowBottom) { @@ -224,7 +256,8 @@ public class Opml extends WireFeed { /** * <windowBottom> is a number, the pixel location of the bottom edge of the window. - * @return the pixel location of the bottom edge of the window. + * + * @return the pixel location of the bottom edge of the window. */ public Integer getWindowBottom() { return _windowBottom; @@ -232,6 +265,7 @@ public class Opml extends WireFeed { /** * <windowLeft> is a number, the pixel location of the left edge of the window. + * * @param windowLeft the pixel location of the left edge of the window. */ public void setWindowLeft(Integer windowLeft) { @@ -240,6 +274,7 @@ public class Opml extends WireFeed { /** * <windowLeft> is a number, the pixel location of the left edge of the window. + * * @return the pixel location of the left edge of the window. */ public Integer getWindowLeft() { @@ -248,6 +283,7 @@ public class Opml extends WireFeed { /** * <windowRight> is a number, the pixel location of the right edge of the window. + * * @param windowRight the pixel location of the right edge of the window. */ public void setWindowRight(Integer windowRight) { @@ -256,6 +292,7 @@ public class Opml extends WireFeed { /** * <windowRight> is a number, the pixel location of the right edge of the window. + * * @return the pixel location of the right edge of the window. */ public Integer getWindowRight() { @@ -264,6 +301,7 @@ public class Opml extends WireFeed { /** * <windowTop> is a number, the pixel location of the top edge of the window. + * * @param windowTop the pixel location of the top edge of the window. */ public void setWindowTop(Integer windowTop) { @@ -272,6 +310,7 @@ public class Opml extends WireFeed { /** * <windowTop> is a number, the pixel location of the top edge of the window. + * * @return the pixel location of the top edge of the window. */ public Integer getWindowTop() { diff --git a/src/main/java/org/rometools/feed/opml/Outline.java b/src/main/java/org/rometools/feed/opml/Outline.java index 55c0095..691f764 100644 --- a/src/main/java/org/rometools/feed/opml/Outline.java +++ b/src/main/java/org/rometools/feed/opml/Outline.java @@ -29,9 +29,9 @@ import java.util.Collections; import java.util.Date; import java.util.List; - /** * This class represents an OPML outline element. + * * @author Robert "kebernet" Cooper */ public class Outline implements Cloneable, Serializable { @@ -53,6 +53,7 @@ public class Outline implements Cloneable, Serializable { /** * Creates a new outline with the specified type and text values. + * * @param type type attribute value/ * @param text text attribute value */ @@ -63,8 +64,8 @@ public class Outline implements Cloneable, Serializable { } /** - * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally - * used for aggregator feed lists and will get a type of "rss". + * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for aggregator feed lists and will get a type of "rss". + * * @param title Title of the entry. * @param xmlUrl link to XML file. * @param htmlUrl link to html page. @@ -86,6 +87,7 @@ public class Outline implements Cloneable, Serializable { /** * List of attributes on this outline excluding the "common types" for the specification. + * * @param attributes List of attributes on this outline. */ public void setAttributes(List attributes) { @@ -94,6 +96,7 @@ public class Outline implements Cloneable, Serializable { /** * List of attributes on this outline excluding the "common types" for the specification. + * * @return List of attributes on this outline. */ public List getAttributes() { @@ -105,7 +108,9 @@ public class Outline implements Cloneable, Serializable { } /** - * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for + * outlines used to edit scripts. If it's not present, the value is false. + * * @param breakpoint whether a breakpoint is set on this outline. */ public void setBreakpoint(boolean breakpoint) { @@ -113,8 +118,10 @@ public class Outline implements Cloneable, Serializable { } /** - * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. - * @return whether a breakpoint is set on this outline + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for + * outlines used to edit scripts. If it's not present, the value is false. + * + * @return whether a breakpoint is set on this outline */ public boolean isBreakpoint() { return _breakpoint; @@ -122,6 +129,7 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) A List of Strings indicating values in the category attribute. + * * @param categories (OPML 2) A List of Strings indicating values in the category attribute. */ public void setCategories(List categories) { @@ -130,6 +138,7 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) A List of Strings indicating values in the category attribute. + * * @return (OPML 2) A List of Strings indicating values in the category attribute. */ public List getCategories() { @@ -142,6 +151,7 @@ public class Outline implements Cloneable, Serializable { /** * A list of sub-outlines for this entry. + * * @param children A list of sub-outlines for this entry. */ public void setChildren(List children) { @@ -150,6 +160,7 @@ public class Outline implements Cloneable, Serializable { /** * A list of sub-outlines for this entry. + * * @return A list of sub-outlines for this entry. */ public List getChildren() { @@ -161,7 +172,9 @@ public class Outline implements Cloneable, Serializable { } /** - * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all + * subordinate outlines are considered to also be commented. If it's not present, the value is false. + * * @param comment whether the outline is commented */ public void setComment(boolean comment) { @@ -169,8 +182,10 @@ public class Outline implements Cloneable, Serializable { } /** - * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. - * @return whether the outline is commented + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all + * subordinate outlines are considered to also be commented. If it's not present, the value is false. + * + * @return whether the outline is commented */ public boolean isComment() { return _comment; @@ -178,6 +193,7 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) created is the date-time that the outline node was created. + * * @param created date-time that the outline node was created. */ public void setCreated(Date created) { @@ -186,22 +202,25 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) created is the date-time that the outline node was created. + * * @return date-time that the outline node was created. */ public Date getCreated() { return _created; } - + /** * A convenience method to return the value of the url attribute. + * * @return value of the htmlUrl attribute. */ public String getUrl() { - return getAttributeValue("url"); + return getAttributeValue("url"); } - + /** * A convenience method to return the value of the htmlUrl attribute. + * * @return value of the htmlUrl attribute. */ public String getHtmlUrl() { @@ -222,6 +241,7 @@ public class Outline implements Cloneable, Serializable { /** * The "text" attribute of the outline. + * * @param text The "text" attribute of the outline. */ public void setText(String text) { @@ -230,6 +250,7 @@ public class Outline implements Cloneable, Serializable { /** * The "text" attribute of the outline. + * * @return The "text" attribute of the outline. */ public String getText() { @@ -238,6 +259,7 @@ public class Outline implements Cloneable, Serializable { /** * The "title" attribute of the outline. + * * @param title The "title" attribute of the outline. */ public void setTitle(String title) { @@ -246,6 +268,7 @@ public class Outline implements Cloneable, Serializable { /** * The "title" attribute of the outline. + * * @return The "title" attribute of the outline. */ public String getTitle() { @@ -254,6 +277,7 @@ public class Outline implements Cloneable, Serializable { /** * The "type" attribute of the outline. + * * @param type The "type" attribute of the outline. */ public void setType(String type) { @@ -262,6 +286,7 @@ public class Outline implements Cloneable, Serializable { /** * The "type" attribute of the outline. + * * @return The "type" attribute of the outline. */ public String getType() { @@ -270,16 +295,19 @@ public class Outline implements Cloneable, Serializable { /** * A convenience method to return the value of the xmlUrl attribute. - * @return value of the xmlUrl attribute. + * + * @return value of the xmlUrl attribute. */ public String getXmlUrl() { - return getAttributeValue("xmlUrl"); + return getAttributeValue("xmlUrl"); } - - /** Returns the value of an attribute on the outline or null. + + /** + * Returns the value of an attribute on the outline or null. + * * @param name name of the attribute. */ - public String getAttributeValue(String name ){ + public String getAttributeValue(String name) { List attributes = Collections.synchronizedList(this.getAttributes()); for (int i = 0; i < attributes.size(); i++) { @@ -293,6 +321,7 @@ public class Outline implements Cloneable, Serializable { return null; } + @Override public Object clone() { Outline o = new Outline(); o.setBreakpoint(this.isBreakpoint()); @@ -323,18 +352,21 @@ public class Outline implements Cloneable, Serializable { return o; } + @Override public boolean equals(Object obj) { EqualsBean eBean = new EqualsBean(Outline.class, this); return eBean.beanEquals(obj); } + @Override public int hashCode() { EqualsBean equals = new EqualsBean(Outline.class, this); return equals.beanHashCode(); } + @Override public String toString() { ToStringBean tsBean = new ToStringBean(Outline.class, this); diff --git a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java index efb6725..110418f 100644 --- a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java @@ -41,14 +41,12 @@ import com.sun.syndication.feed.synd.SyndLinkImpl; import com.sun.syndication.feed.synd.SyndPerson; import com.sun.syndication.feed.synd.SyndPersonImpl; - /** - * + * * @author cooper */ public class ConverterForOPML10 implements Converter { - private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName() - .toString()); + private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName().toString()); public static final String URI_TREE = "urn:rome.tree"; public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; @@ -58,7 +56,7 @@ public class ConverterForOPML10 implements Converter { } protected void addOwner(Opml opml, SyndFeed syndFeed) { - if((opml.getOwnerEmail() != null) || (opml.getOwnerName() != null)) { + if ((opml.getOwnerEmail() != null) || (opml.getOwnerName() != null)) { List authors = new ArrayList(); SyndPerson person = new SyndPersonImpl(); person.setEmail(opml.getOwnerEmail()); @@ -73,47 +71,42 @@ public class ConverterForOPML10 implements Converter { *

* It assumes the given SyndFeedImpl has no properties set. *

- * + * * @param feed real feed to copy/convert. * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. */ + @Override public void copyInto(WireFeed feed, SyndFeed syndFeed) { Opml opml = (Opml) feed; syndFeed.setTitle(opml.getTitle()); addOwner(opml, syndFeed); - syndFeed.setPublishedDate((opml.getModified() != null) - ? opml.getModified() : opml.getCreated()); + syndFeed.setPublishedDate((opml.getModified() != null) ? opml.getModified() : opml.getCreated()); syndFeed.setFeedType(opml.getFeedType()); syndFeed.setModules(opml.getModules()); syndFeed.setFeedType(this.getType()); ArrayList entries = new ArrayList(); - createEntries(new TreeContext(), syndFeed.getEntries(), - opml.getOutlines()); + createEntries(new TreeContext(), syndFeed.getEntries(), opml.getOutlines()); } - protected void createEntries(TreeContext context, List allEntries, - List outlines) { + protected void createEntries(TreeContext context, List allEntries, List outlines) { List so = Collections.synchronizedList(outlines); - for(int i = 0; i < so.size(); i++) { + for (int i = 0; i < so.size(); i++) { createEntry(context, allEntries, (Outline) so.get(i)); } } - protected SyndEntry createEntry(TreeContext context, List allEntries, - Outline outline) { + protected SyndEntry createEntry(TreeContext context, List allEntries, Outline outline) { SyndEntry entry = new SyndEntryImpl(); - if((outline.getType() != null) && outline.getType().equals("rss")) { - entry.setLink((outline.getHtmlUrl() != null) ? outline.getHtmlUrl() - : outline.getXmlUrl()); - } else if((outline.getType() != null) && - outline.getType().equals("link")) { + if ((outline.getType() != null) && outline.getType().equals("rss")) { + entry.setLink((outline.getHtmlUrl() != null) ? outline.getHtmlUrl() : outline.getXmlUrl()); + } else if ((outline.getType() != null) && outline.getType().equals("link")) { entry.setLink(outline.getUrl()); } - if(outline.getHtmlUrl() != null) { + if (outline.getHtmlUrl() != null) { SyndLink link = new SyndLinkImpl(); link.setRel("alternate"); link.setType("text/html"); @@ -122,39 +115,37 @@ public class ConverterForOPML10 implements Converter { entry.setLink(outline.getHtmlUrl()); } - if((outline.getXmlUrl() != null) && (outline.getType() != null) && - outline.getType().equalsIgnoreCase("rss")) { + if ((outline.getXmlUrl() != null) && (outline.getType() != null) && outline.getType().equalsIgnoreCase("rss")) { SyndLink link = new SyndLinkImpl(); link.setRel("alternate"); link.setType("application/rss+xml"); link.setHref(outline.getXmlUrl()); entry.getLinks().add(link); - if(entry.getLink() == null) { + if (entry.getLink() == null) { entry.setLink(outline.getXmlUrl()); } } - if((outline.getXmlUrl() != null) && (outline.getType() != null) && - outline.getType().equalsIgnoreCase("atom")) { + if ((outline.getXmlUrl() != null) && (outline.getType() != null) && outline.getType().equalsIgnoreCase("atom")) { SyndLink link = new SyndLinkImpl(); link.setRel("alternate"); link.setType("application/atom+xml"); link.setHref(outline.getXmlUrl()); entry.getLinks().add(link); - if(entry.getLink() == null) { + if (entry.getLink() == null) { entry.setLink(outline.getXmlUrl()); } } - if((outline.getType() != null) && outline.getType().equals("rss")) { + if ((outline.getType() != null) && outline.getType().equals("rss")) { entry.setTitle(outline.getTitle()); } else { entry.setTitle(outline.getText()); } - if((outline.getText() == null) && (entry.getTitle() != null)) { + if ((outline.getText() == null) && (entry.getTitle() != null)) { SyndContent c = new SyndContentImpl(); c.setValue(outline.getText()); entry.setDescription(c); @@ -169,7 +160,7 @@ public class ConverterForOPML10 implements Converter { cat.setName(nodeName); entry.getCategories().add(cat); - if(context.size() > 0) { + if (context.size() > 0) { Integer parent = (Integer) context.peek(); SyndCategory pcat = new TreeCategoryImpl(); pcat.setTaxonomyUri(URI_TREE); @@ -179,7 +170,7 @@ public class ConverterForOPML10 implements Converter { List attributes = Collections.synchronizedList(outline.getAttributes()); - for(int i = 0; i < attributes.size(); i++) { + for (int i = 0; i < attributes.size(); i++) { Attribute a = (Attribute) attributes.get(i); SyndCategory acat = new SyndCategoryImpl(); acat.setName(a.getValue()); @@ -199,11 +190,12 @@ public class ConverterForOPML10 implements Converter { /** * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. *

- * + * * @param syndFeed SyndFeedImpl to copy/convert value from. * @return a real feed with copied/converted values of the SyndFeedImpl. - * + * */ + @Override public WireFeed createRealFeed(SyndFeed syndFeed) { List entries = Collections.synchronizedList(syndFeed.getEntries()); @@ -211,7 +203,7 @@ public class ConverterForOPML10 implements Converter { ArrayList doAfterPass = new ArrayList(); // this will hold entries that we can't parent the first time. ArrayList root = new ArrayList(); // this holds root level outlines; - for(int i = 0; i < entries.size(); i++) { + for (int i = 0; i < entries.size(); i++) { SyndEntry entry = (SyndEntry) entries.get(i); Outline o = new Outline(); @@ -219,36 +211,30 @@ public class ConverterForOPML10 implements Converter { boolean parentFound = false; StringBuffer category = new StringBuffer(); - for(int j = 0; j < cats.size(); j++) { + for (int j = 0; j < cats.size(); j++) { SyndCategory cat = (SyndCategory) cats.get(j); - if((cat.getTaxonomyUri() != null) && - cat.getTaxonomyUri().equals(URI_TREE)) { - String nodeVal = cat.getName() - .substring(cat.getName().lastIndexOf("."), - cat.getName().length()); + if ((cat.getTaxonomyUri() != null) && cat.getTaxonomyUri().equals(URI_TREE)) { + String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length()); - if(cat.getName().startsWith("node.")) { + if (cat.getName().startsWith("node.")) { entriesByNode.put(nodeVal, o); - } else if(cat.getName().startsWith("parent.")) { + } else if (cat.getName().startsWith("parent.")) { parentFound = true; Outline parent = (Outline) entriesByNode.get(nodeVal); - if(parent != null) { + if (parent != null) { parent.getChildren().add(o); } else { doAfterPass.add(new OutlineHolder(o, nodeVal)); } } - } else if((cat.getTaxonomyUri() != null) && - cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) { - String name = cat.getTaxonomyUri() - .substring(cat.getTaxonomyUri().indexOf("#") + - 1, cat.getTaxonomyUri().length()); + } else if ((cat.getTaxonomyUri() != null) && cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) { + String name = cat.getTaxonomyUri().substring(cat.getTaxonomyUri().indexOf("#") + 1, cat.getTaxonomyUri().length()); o.getAttributes().add(new Attribute(name, cat.getName())); } else { - if(category.length() > 0) { + if (category.length() > 0) { category.append(", "); } @@ -256,64 +242,57 @@ public class ConverterForOPML10 implements Converter { } } - if(!parentFound) { + if (!parentFound) { root.add(o); } - if(category.length() > 0) { - o.getAttributes() - .add(new Attribute("category", category.toString())); + if (category.length() > 0) { + o.getAttributes().add(new Attribute("category", category.toString())); } List links = Collections.synchronizedList(entry.getLinks()); String entryLink = entry.getLink(); - for(int j = 0; j < links.size(); j++) { + for (int j = 0; j < links.size(); j++) { SyndLink link = (SyndLink) links.get(j); - //if(link.getHref().equals(entryLink)) { - if(((link.getType() != null) && (link.getRel() != null) && - link.getRel().equals("alternate")) && - (link.getType().equals("application/rss+xml") || - link.getType().equals("application/atom+xml"))) { + // if(link.getHref().equals(entryLink)) { + if (((link.getType() != null) && (link.getRel() != null) && link.getRel().equals("alternate")) + && (link.getType().equals("application/rss+xml") || link.getType().equals("application/atom+xml"))) { o.setType("rss"); - if(o.getXmlUrl() == null) { - o.getAttributes() - .add(new Attribute("xmlUrl", link.getHref())); + if (o.getXmlUrl() == null) { + o.getAttributes().add(new Attribute("xmlUrl", link.getHref())); } - } else if((link.getType() != null) && - (link.getType().equals("text/html"))) { - if(o.getHtmlUrl() == null) { - o.getAttributes() - .add(new Attribute("htmlUrl", link.getHref())); + } else if ((link.getType() != null) && (link.getType().equals("text/html"))) { + if (o.getHtmlUrl() == null) { + o.getAttributes().add(new Attribute("htmlUrl", link.getHref())); } } else { o.setType(link.getType()); } - //} + // } } - if((o.getType() == null) || o.getType().equals("link")) { + if ((o.getType() == null) || o.getType().equals("link")) { o.setText(entry.getTitle()); - } else { o.setTitle(entry.getTitle()); } - if((o.getText() == null) && (entry.getDescription() != null)) { + if ((o.getText() == null) && (entry.getDescription() != null)) { o.setText(entry.getDescription().getValue()); } } // Do back and parenting for things we missed. - for(int i = 0; i < doAfterPass.size(); i++) { + for (int i = 0; i < doAfterPass.size(); i++) { OutlineHolder o = (OutlineHolder) doAfterPass.get(i); Outline parent = (Outline) entriesByNode.get(o.parent); - if(parent == null) { + if (parent == null) { root.add(o.outline); LOG.warning("Unable to find parent node :" + o.parent); } else { @@ -328,11 +307,10 @@ public class ConverterForOPML10 implements Converter { List authors = Collections.synchronizedList(syndFeed.getAuthors()); - for(int i = 0; i < authors.size(); i++) { + for (int i = 0; i < authors.size(); i++) { SyndPerson p = (SyndPerson) authors.get(i); - if((syndFeed.getAuthor() == null) || - syndFeed.getAuthor().equals(p.getName())) { + if ((syndFeed.getAuthor() == null) || syndFeed.getAuthor().equals(p.getName())) { opml.setOwnerName(p.getName()); opml.setOwnerEmail(p.getEmail()); opml.setOwnerId(p.getUri()); @@ -347,11 +325,12 @@ public class ConverterForOPML10 implements Converter { /** * Returns the type (version) of the real feed this converter handles. *

- * + * * @return the real feed type. * @see WireFeed for details on the format of this string. - *

+ *

*/ + @Override public String getType() { return "opml_1.0"; } diff --git a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java index 25a4e45..d053bc7 100644 --- a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java +++ b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java @@ -11,9 +11,8 @@ package org.rometools.feed.synd.impl; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; - /** - * + * * @author cooper */ public class ConverterForOPML20 extends ConverterForOPML10 { @@ -25,11 +24,12 @@ public class ConverterForOPML20 extends ConverterForOPML10 { /** * Returns the type (version) of the real feed this converter handles. *

- * + * * @return the real feed type. * @see WireFeed for details on the format of this string. - *

+ *

*/ + @Override public String getType() { return "opml_2.0"; } @@ -39,10 +39,11 @@ public class ConverterForOPML20 extends ConverterForOPML10 { *

* It assumes the given SyndFeedImpl has no properties set. *

- * + * * @param feed real feed to copy/convert. * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. */ + @Override public void copyInto(WireFeed feed, SyndFeed syndFeed) { super.copyInto(feed, syndFeed); } @@ -50,10 +51,11 @@ public class ConverterForOPML20 extends ConverterForOPML10 { /** * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. *

- * + * * @param syndFeed SyndFeedImpl to copy/convert value from. * @return a real feed with copied/converted values of the SyndFeedImpl. */ + @Override public WireFeed createRealFeed(SyndFeed syndFeed) { WireFeed retValue; diff --git a/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java index 8bb8ac0..8faea35 100644 --- a/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java +++ b/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java @@ -13,22 +13,23 @@ import com.sun.syndication.feed.synd.SyndCategory; import com.sun.syndication.feed.synd.SyndCategoryImpl; /** - * + * * @author cooper */ public class TreeCategoryImpl extends SyndCategoryImpl { - + /** Creates a new instance of TreeCategoryImpl */ public TreeCategoryImpl() { super(); } - + + @Override public boolean equals(Object o) { SyndCategory c = (SyndCategory) o; - if( c.getTaxonomyUri() != null && c.getTaxonomyUri().equals( this.getTaxonomyUri() ) ) + if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(this.getTaxonomyUri())) return true; else return false; } - + } diff --git a/src/main/java/org/rometools/io/impl/OPML10Generator.java b/src/main/java/org/rometools/io/impl/OPML10Generator.java index 09255ef..2246c1f 100644 --- a/src/main/java/org/rometools/io/impl/OPML10Generator.java +++ b/src/main/java/org/rometools/io/impl/OPML10Generator.java @@ -26,16 +26,15 @@ import com.sun.syndication.io.WireFeedGenerator; import com.sun.syndication.io.impl.BaseWireFeedGenerator; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; import java.util.ArrayList; import java.util.Collections; import java.util.List; - /** - * + * * @author Robert "kebernet" Cooper */ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { @@ -51,13 +50,13 @@ 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. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ + @Override public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { if (!(feed instanceof Opml)) { throw new IllegalArgumentException("Not an OPML file"); diff --git a/src/main/java/org/rometools/io/impl/OPML10Parser.java b/src/main/java/org/rometools/io/impl/OPML10Parser.java index 9935e40..16be175 100644 --- a/src/main/java/org/rometools/io/impl/OPML10Parser.java +++ b/src/main/java/org/rometools/io/impl/OPML10Parser.java @@ -26,8 +26,8 @@ import com.sun.syndication.io.WireFeedParser; import com.sun.syndication.io.impl.BaseWireFeedParser; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; import java.util.ArrayList; import java.util.List; @@ -35,9 +35,8 @@ import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; - /** - * + * * @author Robert "kebernet" Cooper */ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { @@ -57,16 +56,16 @@ 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. */ + @Override public boolean isMyType(Document document) { Element e = document.getRootElement(); - if (e.getName().equals("opml") - && ( e.getChild("head") == null || e.getChild("head").getChild("docs") == null) - && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { + if (e.getName().equals("opml") && (e.getChild("head") == null || e.getChild("head").getChild("docs") == null) + && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { return true; } @@ -76,13 +75,14 @@ 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. * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ + @Override public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { Opml opml = new Opml(); opml.setFeedType("opml_1.0"); @@ -182,9 +182,10 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { ArrayList attributes = new ArrayList(); for (int i = 0; i < jAttributes.size(); i++) { - org.jdom.Attribute a = (org.jdom.Attribute) jAttributes.get(i); + org.jdom2.Attribute a = (org.jdom2.Attribute) jAttributes.get(i); - if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") && !a.getName().equals("type")) { + if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") + && !a.getName().equals("type")) { attributes.add(new Attribute(a.getName(), a.getValue())); } } diff --git a/src/main/java/org/rometools/io/impl/OPML20Generator.java b/src/main/java/org/rometools/io/impl/OPML20Generator.java index 7793ee8..d1122b7 100644 --- a/src/main/java/org/rometools/io/impl/OPML20Generator.java +++ b/src/main/java/org/rometools/io/impl/OPML20Generator.java @@ -14,12 +14,11 @@ import org.rometools.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; - +import org.jdom2.Document; +import org.jdom2.Element; /** - * + * * @author cooper */ public class OPML20Generator extends OPML10Generator { @@ -30,11 +29,12 @@ public class OPML20Generator extends OPML10Generator { /** * Returns the type of feed the generator creates. *

- * + * * @return the type of feed the generator creates. * @see WireFeed for details on the format of this string. - *

+ *

*/ + @Override public String getType() { return "opml_2.0"; } @@ -42,13 +42,13 @@ public class OPML20Generator extends OPML10Generator { /** * 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. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ + @Override public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { Document retValue; @@ -58,6 +58,7 @@ public class OPML20Generator extends OPML10Generator { return retValue; } + @Override protected Element generateHead(Opml opml) { Element retValue; @@ -69,6 +70,7 @@ public class OPML20Generator extends OPML10Generator { return retValue; } + @Override protected Element generateOutline(Outline outline) { Element retValue; diff --git a/src/main/java/org/rometools/io/impl/OPML20Parser.java b/src/main/java/org/rometools/io/impl/OPML20Parser.java index 5aaabff..28ed5b2 100644 --- a/src/main/java/org/rometools/io/impl/OPML20Parser.java +++ b/src/main/java/org/rometools/io/impl/OPML20Parser.java @@ -24,16 +24,13 @@ import org.rometools.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; -import java.util.ArrayList; import java.util.List; -import java.util.StringTokenizer; - /** - * + * * @author cooper */ public class OPML20Parser extends OPML10Parser { @@ -47,14 +44,18 @@ 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. */ + @Override public boolean isMyType(Document document) { Element e = document.getRootElement(); - 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)))) { + 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)))) { return true; } @@ -64,13 +65,14 @@ 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. * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ + @Override public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { Opml opml; opml = (Opml) super.parse(document, validate); @@ -91,6 +93,7 @@ public class OPML20Parser extends OPML10Parser { return opml; } + @Override protected Outline parseOutline(Element e, boolean validate) throws FeedException { Outline retValue; diff --git a/src/test/java/org/rometools/unittest/FeedOpsTest.java b/src/test/java/org/rometools/unittest/FeedOpsTest.java index 36b88ac..24c322e 100644 --- a/src/test/java/org/rometools/unittest/FeedOpsTest.java +++ b/src/test/java/org/rometools/unittest/FeedOpsTest.java @@ -1,63 +1,64 @@ package org.rometools.unittest; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.ObjectInputStream; - /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public abstract class FeedOpsTest extends FeedTest { - protected FeedOpsTest(String feedType) { - super(feedType+".xml"); - System.out.println("Testing "+feedType+".xml"); + protected FeedOpsTest(final String feedType) { + super(feedType + ".xml"); new File("target/test-reports").mkdirs(); } - //1.2a + // 1.2a public void testWireFeedEquals() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = getWireFeed(); + final WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed2 = getWireFeed(); assertTrue(feed1.equals(feed2)); } - //1.2b + // 1.2b public void testWireFeedNotEqual() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = getWireFeed(); + final WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed2 = getWireFeed(); feed2.setFeedType("dummy"); assertFalse(feed1.equals(feed2)); } - //1.3 + // 1.3 public void testWireFeedCloning() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = (WireFeed) feed1.clone();; + final WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed2 = (WireFeed) feed1.clone(); + ; assertTrue(feed1.equals(feed2)); } // 1.4 public void testWireFeedSerialization() throws Exception { - WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed1 = getCachedWireFeed(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(feed1); oos.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - WireFeed feed2 = (WireFeed) ois.readObject(); + final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + final ObjectInputStream ois = new ObjectInputStream(bais); + final WireFeed feed2 = (WireFeed) ois.readObject(); ois.close(); assertTrue(feed1.equals(feed2)); @@ -65,47 +66,48 @@ public abstract class FeedOpsTest extends FeedTest { // 1.6 public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - assertEquals(sFeed1, sFeed2 ); + assertEquals(sFeed1, sFeed2); } - //1.7a + // 1.7a public void testSyndFeedEquals() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(); + final SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed2 = getSyndFeed(); assertTrue(feed1.equals(feed2)); } - //1.7b + // 1.7b public void testSyndFeedNotEqual() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(); + final SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed2 = getSyndFeed(); feed2.setFeedType("dummy"); assertFalse(feed1.equals(feed2)); } - //1.8 + // 1.8 public void testSyndFeedCloning() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = (SyndFeed) feed1.clone();; + final SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed2 = (SyndFeed) feed1.clone(); + ; assertTrue(feed1.equals(feed2)); } - //1.9 + // 1.9 public void testSyndFeedSerialization() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed1 = getCachedSyndFeed(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(feed1); oos.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - SyndFeed feed2 = (SyndFeed) ois.readObject(); + final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + final ObjectInputStream ois = new ObjectInputStream(bais); + final SyndFeed feed2 = (SyndFeed) ois.readObject(); ois.close(); assertTrue(feed1.equals(feed2)); diff --git a/src/test/java/org/rometools/unittest/FeedTest.java b/src/test/java/org/rometools/unittest/FeedTest.java index 676cd93..70552f1 100644 --- a/src/test/java/org/rometools/unittest/FeedTest.java +++ b/src/test/java/org/rometools/unittest/FeedTest.java @@ -1,30 +1,30 @@ package org.rometools.unittest; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + import junit.framework.TestCase; -import com.sun.syndication.feed.synd.SyndFeed; +import org.jdom2.Document; +import org.jdom2.input.SAXBuilder; + import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.WireFeedInput; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.InputStream; - -import org.jdom.Document; -import org.jdom.input.SAXBuilder; - /** * @author pat, tucu - * + * */ public abstract class FeedTest extends TestCase { - private String _feedFileName; - private Document _jDomDoc = null; + private final String _feedFileName; + private Document _jDomDoc = null; private WireFeed _wireFeed = null; private SyndFeed _syndFeed = null; - protected FeedTest(String feedFileName) { + protected FeedTest(final String feedFileName) { _feedFileName = feedFileName; } @@ -33,43 +33,42 @@ public abstract class FeedTest extends TestCase { } protected Reader getFeedReader() throws Exception { - InputStream resource = Thread.currentThread(). - getContextClassLoader().getResourceAsStream(getFeedFileName()); - assertNotNull("Could not find resource " + getFeedFileName(), resource); - return new InputStreamReader(resource); + final InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream(getFeedFileName()); + assertNotNull("Could not find resource " + getFeedFileName(), resource); + return new InputStreamReader(resource); } protected Document getJDomDoc() throws Exception { - SAXBuilder saxBuilder = new SAXBuilder(false); + final SAXBuilder saxBuilder = new SAXBuilder(false); return saxBuilder.build(getFeedReader()); } protected WireFeed getWireFeed() throws Exception { - WireFeedInput in = new WireFeedInput(); + final WireFeedInput in = new WireFeedInput(); return in.build(getFeedReader()); } protected SyndFeed getSyndFeed() throws Exception { - SyndFeedInput in = new SyndFeedInput(); + final SyndFeedInput in = new SyndFeedInput(); return in.build(getFeedReader()); } protected Document getCachedJDomDoc() throws Exception { - if (_jDomDoc==null) { + if (_jDomDoc == null) { _jDomDoc = getJDomDoc(); } return _jDomDoc; } protected WireFeed getCachedWireFeed() throws Exception { - if (_wireFeed==null) { + if (_wireFeed == null) { _wireFeed = getWireFeed(); } return _wireFeed; } protected SyndFeed getCachedSyndFeed() throws Exception { - if (_syndFeed==null) { + if (_syndFeed == null) { _syndFeed = getSyndFeed(); } return _syndFeed; diff --git a/src/test/java/org/rometools/unittest/SyndFeedTest.java b/src/test/java/org/rometools/unittest/SyndFeedTest.java index 8bdddde..6686fcf 100644 --- a/src/test/java/org/rometools/unittest/SyndFeedTest.java +++ b/src/test/java/org/rometools/unittest/SyndFeedTest.java @@ -6,21 +6,18 @@ */ package org.rometools.unittest; - - - /** * @author pat - * + * */ public abstract class SyndFeedTest extends FeedTest { - private String _prefix = null; + private String _prefix = null; protected SyndFeedTest(String feedType) { - this(feedType,feedType+".xml"); + this(feedType, feedType + ".xml"); } - protected SyndFeedTest(String feedType,String feedFileName) { + protected SyndFeedTest(String feedType, String feedFileName) { super(feedFileName); _prefix = feedType; } @@ -29,239 +26,117 @@ public abstract class SyndFeedTest extends FeedTest { return _prefix; } - protected void assertProperty(String property, String value) { - assertEquals(property,getPrefix() + "." + value); - } - - public void testType() throws Exception { - assertEquals(getCachedSyndFeed().getFeedType(),getPrefix()); + protected void assertProperty(String property, String value) { + assertEquals(property, getPrefix() + "." + value); } - -/* - public void testType() throws Exception { - assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); - } - - public void testTitle() throws Exception { - assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); - } - - public void testLink() throws Exception { - assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); - } - - public void testDescription() throws Exception { - assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); - } - - public void testLanguage() throws Exception { - assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); - } - - public void testCategories() throws Exception { - List catlist = getCachedSyndFeed().getCategories(); - //don't understand why this one fails - assertEquals(2, catlist.size()); - SyndCategory cat = (SyndCategory)catlist.get(0); - assertEqualsStr("channel.category[0]", cat.getName()); - assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEqualsStr("channel.category[1]", cat.getName()); - assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); - } - - public void testPublishedDate() throws Exception { - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getCachedSyndFeed().getPublishedDate()); - } - - //how do i get height and width? - public void testImage() throws Exception { - SyndImage img = getCachedSyndFeed().getImage(); - assertEqualsStr("channel.image.description", img.getDescription()); - assertEqualsStr("channel.image.link", img.getLink()); - assertEqualsStr("channel.image.title", img.getTitle()); - assertEqualsStr("channel.image.url", img.getUrl()); - } - - public void testEntries() throws Exception { - List entrylist = getCachedSyndFeed().getEntries(); - assertEquals(2, entrylist.size()); - } - - public void testEntryTitle() throws Exception { - assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryTitle(Object o) throws Exception { - SyndEntry e = (SyndEntry) o; - return e.getTitle(); - } - - public void testEntryDescription() throws Exception { - assertEqualsStr("channel.item[0].description", getEntryDescription(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].description", getEntryDescription(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryDescription(Object o) throws Exception { - SyndEntry e = (SyndEntry) o; - return e.getDescription().getValue(); - } - - public void testEntryLink() throws Exception { - assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryLink(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getLink(); - } - - public void testEntryPublishedDate() throws Exception { - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); - } - - public Date getEntryPublishedDate(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getPublishedDate(); - } - - public void testEntryCategories() throws Exception { - SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); - List catlist = e.getCategories(); - //don't understand why this one fails - assertEquals(2, catlist.size()); - SyndCategory cat = (SyndCategory)catlist.get(0); - assertEqualsStr("channel.item[0].category[0]", cat.getName()); - assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEqualsStr("channel.item[0].category[1]", cat.getName()); - assertEqualsStr("channel.item[0].category[1]^domain", cat.getTaxonomyUri()); - //DO 2nd set of items - } - - public void testEntryAuthor() throws Exception { - assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryAuthor(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getAuthor(); - } - -*/ -/* -//things you cannot get from SyndEntryImpl -// item[0].source -// -// - item0.category0 - item0.category1 - Thu, 08 Jul 1999 08:00:00 GMT - Thu, 08 Jul 1999 09:00:00 GMT - item0.author - http://localhost:8080/item0/comments - http://localhost:8080/item0/guid - //TODO: I still have the elements to test -*/ - /* - public void test() { - assertEqualsStr(feed, ""); - } - - public void test() { - assertEqualsStr(feed, ""); - } - - */ - //Things that you cannot get form a SyndFeedImpl today - //these need to be put in a RSS 2.0 module - //or is a roundtrip to wirefeed the right way to do this? -/* - * - Search - Search this site: - q - http://example.org/mt/mt-search.cgi - - - image height and width - * - //Copyright 2004, Mark Pilgrim - public void test() { - assertEqualsStr(getCachedSyndFeed()., ""); - } - - //Sample Toolkit - public void test() { - assertEqualsStr(feed, ""); - } - - // editor@example.org - public void test() { - assertEqualsStr(feed, ""); - } - - // webmaster@example.org - public void test() { - assertEqualsStr(feed, ""); - } - - http://blogs.law.harvard.edu/tech/rss - - 60 - - - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9.5 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - - - Monday - Tuesday - Wednesday - Thursday - Friday - Saturday - Sunday - - -**/ - - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } + public void testType() throws Exception { + assertEquals(getCachedSyndFeed().getFeedType(), getPrefix()); + } + /* + * public void testType() throws Exception { assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); } + * + * public void testTitle() throws Exception { assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); } + * + * public void testLink() throws Exception { assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); } + * + * public void testDescription() throws Exception { assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); } + * + * public void testLanguage() throws Exception { assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); } + * + * public void testCategories() throws Exception { List catlist = getCachedSyndFeed().getCategories(); //don't understand why this one fails assertEquals(2, + * catlist.size()); SyndCategory cat = (SyndCategory)catlist.get(0); assertEqualsStr("channel.category[0]", cat.getName()); + * assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); cat = (SyndCategory)catlist.get(1); assertEqualsStr("channel.category[1]", + * cat.getName()); assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); } + * + * public void testPublishedDate() throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getCachedSyndFeed().getPublishedDate()); } + * + * //how do i get height and width? public void testImage() throws Exception { SyndImage img = getCachedSyndFeed().getImage(); + * assertEqualsStr("channel.image.description", img.getDescription()); assertEqualsStr("channel.image.link", img.getLink()); + * assertEqualsStr("channel.image.title", img.getTitle()); assertEqualsStr("channel.image.url", img.getUrl()); } + * + * public void testEntries() throws Exception { List entrylist = getCachedSyndFeed().getEntries(); assertEquals(2, entrylist.size()); } + * + * public void testEntryTitle() throws Exception { assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryTitle(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getTitle(); } + * + * public void testEntryDescription() throws Exception { assertEqualsStr("channel.item[0].description", + * getEntryDescription(getCachedSyndFeed().getEntries().get(0))); assertEqualsStr("channel.item[1].description", + * getEntryDescription(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryDescription(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getDescription().getValue(); } + * + * public void testEntryLink() throws Exception { assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryLink(Object o) { SyndEntry e = (SyndEntry) o; return e.getLink(); } + * + * public void testEntryPublishedDate() throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); } + * + * public Date getEntryPublishedDate(Object o) { SyndEntry e = (SyndEntry) o; return e.getPublishedDate(); } + * + * public void testEntryCategories() throws Exception { SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); List catlist = e.getCategories(); + * //don't understand why this one fails assertEquals(2, catlist.size()); SyndCategory cat = (SyndCategory)catlist.get(0); + * assertEqualsStr("channel.item[0].category[0]", cat.getName()); assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); cat = + * (SyndCategory)catlist.get(1); assertEqualsStr("channel.item[0].category[1]", cat.getName()); assertEqualsStr("channel.item[0].category[1]^domain", + * cat.getTaxonomyUri()); //DO 2nd set of items } + * + * public void testEntryAuthor() throws Exception { assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryAuthor(Object o) { SyndEntry e = (SyndEntry) o; return e.getAuthor(); } + */ + /* + * //things you cannot get from SyndEntryImpl // item[0].source // // item0.category0 item0.category1 + * Thu, 08 Jul 1999 08:00:00 GMT Thu, 08 Jul 1999 09:00:00 GMT item0.author + * http://localhost:8080/item0/comments http://localhost:8080/item0/guid //TODO: I still have the + * elements to test + */ + /* + * public void test() { assertEqualsStr(feed, ""); } + * + * public void test() { assertEqualsStr(feed, ""); } + */ + // Things that you cannot get form a SyndFeedImpl today + // these need to be put in a RSS 2.0 module + // or is a roundtrip to wirefeed the right way to do this? + /* + * Search Search this site: q http://example.org/mt/mt-search.cgi + * + * + * image height and width + * + * //Copyright 2004, Mark Pilgrim public void test() { assertEqualsStr(getCachedSyndFeed()., ""); } + * + * //Sample Toolkit public void test() { assertEqualsStr(feed, ""); } + * + * // editor@example.org public void test() { assertEqualsStr(feed, ""); } + * + * // webmaster@example.org public void test() { assertEqualsStr(feed, ""); } + * + * http://blogs.law.harvard.edu/tech/rss + * 60 + * + * 0 1 2 3 4 5 6 7 8 + * 9.5 10 11 12 13 14 15 16 17 + * 18 19 20 21 22 23 Monday + * Tuesday Wednesday Thursday Friday Saturday Sunday + */ + /* + * @see TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } } diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10.java b/src/test/java/org/rometools/unittest/TestOpsOPML10.java index 438fc73..a796dd6 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML10.java +++ b/src/test/java/org/rometools/unittest/TestOpsOPML10.java @@ -9,39 +9,38 @@ package org.rometools.unittest; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; import java.io.FileOutputStream; import java.io.PrintWriter; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + /** - * + * * @author cooper */ -public class TestOpsOPML10 extends FeedOpsTest{ - +public class TestOpsOPML10 extends FeedOpsTest { + /** Creates a new instance of TestOpsOPML10 */ public TestOpsOPML10() { super("opml_1.0"); } - + // 1.6 + @Override public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); - w.println( sFeed1.toString() ); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1")); + w.println(sFeed1.toString()); w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); - w.println( sFeed2.toString() ); + w = new PrintWriter(new FileOutputStream("target/test-reports/2")); + w.println(sFeed2.toString()); w.close(); - + assertEquals(sFeed1, sFeed2); } - - - - + } diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10links.java b/src/test/java/org/rometools/unittest/TestOpsOPML10links.java index cd14968..1b9b143 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML10links.java +++ b/src/test/java/org/rometools/unittest/TestOpsOPML10links.java @@ -9,59 +9,54 @@ package org.rometools.unittest; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import com.sun.syndication.io.WireFeedInput; -import com.sun.syndication.io.WireFeedOutput; import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.WireFeedOutput; + /** - * + * * @author cooper */ -public class TestOpsOPML10links extends FeedOpsTest{ - +public class TestOpsOPML10links extends FeedOpsTest { + /** Creates a new instance of TestOpsOPML10 */ public TestOpsOPML10links() { super("opml_1.0_links"); } - + // 1.6 + @Override public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - //System.out.println( wFeed1 ); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); - w.println( sFeed1.toString() ); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1")); + w.println(sFeed1.toString()); w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); - w.println( sFeed2.toString() ); + w = new PrintWriter(new FileOutputStream("target/test-reports/2")); + w.println(sFeed2.toString()); w.close(); - + assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed()); } - - - - public void testTemp() throws Exception { - WireFeedInput input = new WireFeedInput(); - WireFeed wf = input.build( new File( System.getProperty("basedir")+ "/src/test/resources/opml_1.0_links.xml")); - WireFeedOutput output = new WireFeedOutput(); - //System.out.println( wf ); - - //System.out.println( "================================="); - //System.out.println( new SyndFeedImpl( wf) ); - SyndFeedImpl sf = new SyndFeedImpl( wf); + + public void testTemp() throws Exception { + final WireFeedInput input = new WireFeedInput(); + final WireFeed wf = input.build(new File(System.getProperty("basedir") + "/src/test/resources/opml_1.0_links.xml")); + final WireFeedOutput output = new WireFeedOutput(); + + final SyndFeedImpl sf = new SyndFeedImpl(wf); sf.setFeedType("rss_2.0"); sf.setDescription(""); sf.setLink("http://foo.com"); - //output.output( sf.createWireFeed() , new PrintWriter( System.out ) ); sf.setFeedType("opml_1.0"); - output.output( sf.createWireFeed() , new File( System.getProperty("basedir")+ "/target/test-reports/1.xml") ); + output.output(sf.createWireFeed(), new File(System.getProperty("basedir") + "/target/test-reports/1.xml")); } - + } diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML20.java b/src/test/java/org/rometools/unittest/TestOpsOPML20.java index 0d49027..74d58e1 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML20.java +++ b/src/test/java/org/rometools/unittest/TestOpsOPML20.java @@ -9,35 +9,36 @@ package org.rometools.unittest; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; import java.io.FileOutputStream; import java.io.PrintWriter; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + /** - * + * * @author cooper */ public class TestOpsOPML20 extends FeedOpsTest { - + /** Creates a new instance of TestOpsOPML20 */ public TestOpsOPML20() { super("opml_2.0"); } - - + + @Override public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/3") ); - w.println( sFeed1.toString() ); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/3")); + w.println(sFeed1.toString()); w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/4") ); - w.println( sFeed2.toString() ); + w = new PrintWriter(new FileOutputStream("target/test-reports/4")); + w.println(sFeed2.toString()); w.close(); - assertEquals(sFeed1, sFeed2 ); + assertEquals(sFeed1, sFeed2); } } diff --git a/src/test/java/org/rometools/unittest/TestXmlFixerReader.java b/src/test/java/org/rometools/unittest/TestXmlFixerReader.java index 7c5669c..f232f34 100644 --- a/src/test/java/org/rometools/unittest/TestXmlFixerReader.java +++ b/src/test/java/org/rometools/unittest/TestXmlFixerReader.java @@ -16,119 +16,124 @@ */ package org.rometools.unittest; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; + +import junit.framework.TestCase; + +import org.jdom2.input.SAXBuilder; + import com.sun.syndication.io.XmlReader; import com.sun.syndication.io.impl.XmlFixerReader; -import junit.framework.TestCase; -import org.jdom.input.SAXBuilder; - -import java.io.*; /** * @author pat, tucu - * + * */ public class TestXmlFixerReader extends TestCase { private static final String XML_PROLOG = ""; public void testTrim() throws Exception { - _testValidTrim("",""); - _testValidTrim("",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" \n",""); - _testValidTrim(" \n",XML_PROLOG+""); - _testValidTrim("",""); - _testValidTrim("",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" \n ",""); - _testValidTrim(" \n ",XML_PROLOG+""); + _testValidTrim("", ""); + _testValidTrim("", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" \n", ""); + _testValidTrim(" \n", XML_PROLOG + ""); + _testValidTrim("", ""); + _testValidTrim("", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" \n ", ""); + _testValidTrim(" \n ", XML_PROLOG + ""); - _testInvalidTrim("x",""); - _testInvalidTrim("x",XML_PROLOG+""); - _testInvalidTrim(" x",""); - _testInvalidTrim(" x",XML_PROLOG+""); - _testInvalidTrim(" x\n",""); - _testInvalidTrim(" x\n",XML_PROLOG+""); - _testInvalidTrim("x ",""); - _testInvalidTrim(" x ",XML_PROLOG+""); - _testInvalidTrim(" x ",""); - _testInvalidTrim(" x ",XML_PROLOG+""); - _testInvalidTrim(" x\n ",""); - _testInvalidTrim(" x\n ",XML_PROLOG+""); + _testInvalidTrim("x", ""); + _testInvalidTrim("x", XML_PROLOG + ""); + _testInvalidTrim(" x", ""); + _testInvalidTrim(" x", XML_PROLOG + ""); + _testInvalidTrim(" x\n", ""); + _testInvalidTrim(" x\n", XML_PROLOG + ""); + _testInvalidTrim("x ", ""); + _testInvalidTrim(" x ", XML_PROLOG + ""); + _testInvalidTrim(" x ", ""); + _testInvalidTrim(" x ", XML_PROLOG + ""); + _testInvalidTrim(" x\n ", ""); + _testInvalidTrim(" x\n ", XML_PROLOG + ""); } public void testHtmlEntities() throws Exception { _testValidEntities(""); - _testValidEntities(XML_PROLOG+""); - _testValidEntities(" \n"+XML_PROLOG+""); + _testValidEntities(XML_PROLOG + ""); + _testValidEntities(" \n" + XML_PROLOG + ""); _testValidEntities("'¥ú¥"); - _testValidEntities(XML_PROLOG+"'¥ú¥"); - _testValidEntities(" \n"+XML_PROLOG+"'¥ú¥"); + _testValidEntities(XML_PROLOG + "'¥ú¥"); + _testValidEntities(" \n" + XML_PROLOG + "'¥ú¥"); _testInvalidEntities("'&yexn;ú¥"); - _testInvalidEntities(XML_PROLOG+"'&yexn;ú¥"); - _testInvalidEntities(" \n"+XML_PROLOG+"'&yexn;ú¥"); + _testInvalidEntities(XML_PROLOG + "'&yexn;ú¥"); + _testInvalidEntities(" \n" + XML_PROLOG + "'&yexn;ú¥"); _testInvalidEntities("'¥x50;¥"); - _testInvalidEntities(XML_PROLOG+"'¥x50;¥"); - _testInvalidEntities(" \n"+XML_PROLOG+"'¥x50;¥"); + _testInvalidEntities(XML_PROLOG + "'¥x50;¥"); + _testInvalidEntities(" \n" + XML_PROLOG + "'¥x50;¥"); } - protected void _testXmlParse(String garbish,String xmlDoc) throws Exception { - InputStream is = getStream(garbish,xmlDoc); + protected void _testXmlParse(final String garbish, final String xmlDoc) throws Exception { + final InputStream is = getStream(garbish, xmlDoc); Reader reader = new XmlReader(is); reader = new XmlFixerReader(reader); - SAXBuilder saxBuilder = new SAXBuilder(); + final SAXBuilder saxBuilder = new SAXBuilder(); saxBuilder.build(reader); } - protected void _testValidTrim(String garbish,String xmlDoc) throws Exception { - _testXmlParse(garbish,xmlDoc); + protected void _testValidTrim(final String garbish, final String xmlDoc) throws Exception { + _testXmlParse(garbish, xmlDoc); } - protected void _testInvalidTrim(String garbish,String xmlDoc) throws Exception { + protected void _testInvalidTrim(final String garbish, final String xmlDoc) throws Exception { try { - _testXmlParse(garbish,xmlDoc); + _testXmlParse(garbish, xmlDoc); assertTrue(false); - } - catch (Exception ex) { + } catch (final Exception ex) { } } - protected void _testValidEntities(String xmlDoc) throws Exception { - _testXmlParse("",xmlDoc); + protected void _testValidEntities(final String xmlDoc) throws Exception { + _testXmlParse("", xmlDoc); } - protected void _testInvalidEntities(String xmlDoc) throws Exception { + protected void _testInvalidEntities(final String xmlDoc) throws Exception { try { - _testXmlParse("",xmlDoc); + _testXmlParse("", xmlDoc); assertTrue(false); - } - catch (Exception ex) { + } catch (final Exception ex) { } } // XML Stream generator - protected InputStream getStream(String garbish,String xmlDoc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - Writer writer = new OutputStreamWriter(baos); + protected InputStream getStream(final String garbish, final String xmlDoc) throws IOException { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + final Writer writer = new OutputStreamWriter(baos); writer.write(garbish); writer.write(xmlDoc); writer.close(); return new ByteArrayInputStream(baos.toByteArray()); } - } diff --git a/src/test/java/org/rometools/unittest/TestXmlReader.java b/src/test/java/org/rometools/unittest/TestXmlReader.java index 78a85fb..9b335fd 100644 --- a/src/test/java/org/rometools/unittest/TestXmlReader.java +++ b/src/test/java/org/rometools/unittest/TestXmlReader.java @@ -16,51 +16,56 @@ */ package org.rometools.unittest; -import com.sun.syndication.io.XmlReader; -import junit.framework.TestCase; - -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; +import junit.framework.TestCase; + +import com.sun.syndication.io.XmlReader; + /** * @author pat, tucu - * + * */ public class TestXmlReader extends TestCase { - public static void main(String[] args) throws Exception { - TestXmlReader test = new TestXmlReader(); + public static void main(final String[] args) throws Exception { + final TestXmlReader test = new TestXmlReader(); test.testRawBom(); test.testRawNoBom(); test.testHttp(); } - protected void _testRawNoBomValid(String encoding) throws Exception { - InputStream is = getXmlStream("no-bom","xml",encoding,encoding); - XmlReader xmlReader = new XmlReader(is,false); - assertEquals(xmlReader.getEncoding(),"UTF-8"); + protected void _testRawNoBomValid(final String encoding) throws Exception { + InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); + XmlReader xmlReader = new XmlReader(is, false); + assertEquals(xmlReader.getEncoding(), "UTF-8"); - is = getXmlStream("no-bom","xml-prolog",encoding,encoding); + is = getXmlStream("no-bom", "xml-prolog", encoding, encoding); xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),"UTF-8"); + assertEquals(xmlReader.getEncoding(), "UTF-8"); - is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),encoding); + assertEquals(xmlReader.getEncoding(), encoding); } - protected void _testRawNoBomInvalid(String encoding) throws Exception { - InputStream is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + protected void _testRawNoBomInvalid(final String encoding) throws Exception { + final InputStream is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); try { - XmlReader xmlReader = new XmlReader(is,false); + final XmlReader xmlReader = new XmlReader(is, false); fail("It should have failed"); + } catch (final IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } + } public void testRawNoBom() throws Exception { _testRawNoBomValid("US-ASCII"); @@ -68,27 +73,25 @@ public class TestXmlReader extends TestCase { _testRawNoBomValid("ISO-8859-1"); } - protected void _testRawBomValid(String encoding) throws Exception { - InputStream is = getXmlStream(encoding+"-bom","xml-prolog-encoding",encoding,encoding); - XmlReader xmlReader = new XmlReader(is,false); + protected void _testRawBomValid(final String encoding) throws Exception { + final InputStream is = getXmlStream(encoding + "-bom", "xml-prolog-encoding", encoding, encoding); + final XmlReader xmlReader = new XmlReader(is, false); if (!encoding.equals("UTF-16")) { - assertEquals(xmlReader.getEncoding(),encoding); - } - else { - assertEquals(xmlReader.getEncoding().substring(0,encoding.length()),encoding); + assertEquals(xmlReader.getEncoding(), encoding); + } else { + assertEquals(xmlReader.getEncoding().substring(0, encoding.length()), encoding); } } - protected void _testRawBomInvalid(String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,"xml-prolog-encoding",streamEnc,prologEnc); + protected void _testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { + final InputStream is = getXmlStream(bomEnc, "xml-prolog-encoding", streamEnc, prologEnc); try { - XmlReader xmlReader = new XmlReader(is,false); - fail("It should have failed for BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + final XmlReader xmlReader = new XmlReader(is, false); + fail("It should have failed for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); + } catch (final IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } + } public void testRawBom() throws Exception { _testRawBomValid("UTF-8"); @@ -96,155 +99,150 @@ public class TestXmlReader extends TestCase { _testRawBomValid("UTF-16LE"); _testRawBomValid("UTF-16"); - _testRawBomInvalid("UTF-8-bom","US-ASCII","US-ASCII"); - _testRawBomInvalid("UTF-8-bom","ISO-8859-1","ISO-8859-1"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16BE"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16LE"); - _testRawBomInvalid("UTF-16BE-bom","UTF-16BE","UTF-16LE"); - _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-16BE"); - _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-8"); + _testRawBomInvalid("UTF-8-bom", "US-ASCII", "US-ASCII"); + _testRawBomInvalid("UTF-8-bom", "ISO-8859-1", "ISO-8859-1"); + _testRawBomInvalid("UTF-8-bom", "UTF-8", "UTF-16"); + _testRawBomInvalid("UTF-8-bom", "UTF-8", "UTF-16BE"); + _testRawBomInvalid("UTF-8-bom", "UTF-8", "UTF-16LE"); + _testRawBomInvalid("UTF-16BE-bom", "UTF-16BE", "UTF-16LE"); + _testRawBomInvalid("UTF-16LE-bom", "UTF-16LE", "UTF-16BE"); + _testRawBomInvalid("UTF-16LE-bom", "UTF-16LE", "UTF-8"); } public void testHttp() throws Exception { - _testHttpValid("application/xml","no-bom","US-ASCII",null); - _testHttpValid("application/xml","UTF-8-bom","US-ASCII",null); - _testHttpValid("application/xml","UTF-8-bom","UTF-8",null); - _testHttpValid("application/xml","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); - _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpValid("application/xml", "no-bom", "US-ASCII", null); + _testHttpValid("application/xml", "UTF-8-bom", "US-ASCII", null); + _testHttpValid("application/xml", "UTF-8-bom", "UTF-8", null); + _testHttpValid("application/xml", "UTF-8-bom", "UTF-8", "UTF-8"); + _testHttpValid("application/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", null); + _testHttpValid("application/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", "UTF-8"); + _testHttpValid("application/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpValid("application/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpValid("application/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("application/xml","UTF-8-bom","US-ASCII","US-ASCII"); - _testHttpInvalid("application/xml;charset=UTF-16","UTF-16LE","UTF-8","UTF-8"); - _testHttpInvalid("application/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("application/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpInvalid("application/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpInvalid("application/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); + _testHttpInvalid("application/xml", "UTF-8-bom", "US-ASCII", "US-ASCII"); + _testHttpInvalid("application/xml;charset=UTF-16", "UTF-16LE", "UTF-8", "UTF-8"); + _testHttpInvalid("application/xml;charset=UTF-16", "no-bom", "UTF-16BE", "UTF-16BE"); - _testHttpValid("text/xml","no-bom","US-ASCII",null); - _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpValid("text/xml","UTF-8-bom","US-ASCII",null); + _testHttpValid("text/xml", "no-bom", "US-ASCII", null); + _testHttpValid("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", "UTF-8"); + _testHttpValid("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", null); + _testHttpValid("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpValid("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpValid("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); + _testHttpValid("text/xml", "UTF-8-bom", "US-ASCII", null); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE",null); + _testHttpInvalid("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpInvalid("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpInvalid("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", "UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", null); - _testHttpLenient("text/xml","no-bom","US-ASCII",null, "US-ASCII"); - _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8", "UTF-8"); - _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null, "UTF-8"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml","UTF-8-bom","US-ASCII",null, "US-ASCII"); + _testHttpLenient("text/xml", "no-bom", "US-ASCII", null, "US-ASCII"); + _testHttpLenient("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", "UTF-8", "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", null, "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml", "UTF-8-bom", "US-ASCII", null, "US-ASCII"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE",null, "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", "UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", null, "UTF-16"); - _testHttpLenient("text/html","no-bom","US-ASCII","US-ASCII", "US-ASCII"); - _testHttpLenient("text/html","no-bom","US-ASCII",null, "US-ASCII"); - _testHttpLenient("text/html;charset=UTF-8","no-bom","US-ASCII","UTF-8", "UTF-8"); - _testHttpLenient("text/html;charset=UTF-16BE","no-bom","US-ASCII","UTF-8", "UTF-8"); + _testHttpLenient("text/html", "no-bom", "US-ASCII", "US-ASCII", "US-ASCII"); + _testHttpLenient("text/html", "no-bom", "US-ASCII", null, "US-ASCII"); + _testHttpLenient("text/html;charset=UTF-8", "no-bom", "US-ASCII", "UTF-8", "UTF-8"); + _testHttpLenient("text/html;charset=UTF-16BE", "no-bom", "US-ASCII", "UTF-8", "UTF-8"); } - public void _testHttpValid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml":"xml-prolog-encoding",streamEnc,prologEnc); - XmlReader xmlReader = new XmlReader(is,cT,false); + public void _testHttpValid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { + final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml" : "xml-prolog-encoding", streamEnc, prologEnc); + final XmlReader xmlReader = new XmlReader(is, cT, false); if (!streamEnc.equals("UTF-16")) { // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection - } - else { - assertEquals(xmlReader.getEncoding().substring(0,streamEnc.length()),streamEnc); + } else { + assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); } } - protected void _testHttpInvalid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); + protected void _testHttpInvalid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { + final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml-prolog" : "xml-prolog-encoding", streamEnc, prologEnc); try { - XmlReader xmlReader = new XmlReader(is,cT,false); - fail("It should have failed for HTTP Content-type "+cT+", BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + 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); + } catch (final IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } + } - protected void _testHttpLenient(String cT, String bomEnc, String streamEnc, String prologEnc, String shouldbe) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); - XmlReader xmlReader = new XmlReader(is,cT,true); - assertEquals(xmlReader.getEncoding(),shouldbe); + protected void _testHttpLenient(final String cT, final String bomEnc, final String streamEnc, final String prologEnc, final String shouldbe) + throws Exception { + 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); } // XML Stream generator private static final int[] NO_BOM_BYTES = {}; - private static final int[] UTF_16BE_BOM_BYTES = {0xFE,0xFF}; - private static final int[] UTF_16LE_BOM_BYTES = {0xFF,0XFE}; - private static final int[] UTF_8_BOM_BYTES = {0xEF,0xBB,0xBF}; + private static final int[] UTF_16BE_BOM_BYTES = { 0xFE, 0xFF }; + 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(); static { - BOMs.put("no-bom",NO_BOM_BYTES); - BOMs.put("UTF-16BE-bom",UTF_16BE_BOM_BYTES); - BOMs.put("UTF-16LE-bom",UTF_16LE_BOM_BYTES); - BOMs.put("UTF-16-bom",NO_BOM_BYTES); // it's added by the writer - BOMs.put("UTF-8-bom",UTF_8_BOM_BYTES); + BOMs.put("no-bom", NO_BOM_BYTES); + BOMs.put("UTF-16BE-bom", UTF_16BE_BOM_BYTES); + BOMs.put("UTF-16LE-bom", UTF_16LE_BOM_BYTES); + BOMs.put("UTF-16-bom", NO_BOM_BYTES); // it's added by the writer + BOMs.put("UTF-8-bom", UTF_8_BOM_BYTES); } - private static final MessageFormat XML = new MessageFormat( - "{2}"); - private static final MessageFormat XML_WITH_PROLOG = new MessageFormat( - "\n{2}"); - private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat( - "\n{2}"); + private static final MessageFormat XML = new MessageFormat("{2}"); + private static final MessageFormat XML_WITH_PROLOG = new MessageFormat("\n{2}"); + private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat("\n{2}"); - private static final MessageFormat INFO = new MessageFormat( - "\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); + 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(); static { - XMLs.put("xml",XML); - XMLs.put("xml-prolog",XML_WITH_PROLOG); - XMLs.put("xml-prolog-encoding",XML_WITH_PROLOG_AND_ENCODING); + XMLs.put("xml", XML); + XMLs.put("xml-prolog", XML_WITH_PROLOG); + XMLs.put("xml-prolog-encoding", XML_WITH_PROLOG_AND_ENCODING); } /** - * + * * @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(String bomType,String xmlType,String streamEnc,String prologEnc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + 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); - if (bom==null) { + if (bom == null) { bom = new int[0]; } - MessageFormat xml = (MessageFormat) XMLs.get(xmlType); - for (int i=0;i\n"); - for (int i=0;i<10000;i++) { + for (int i = 0; i < 10000; i++) { writer.write("\n"); } writer.write("\n"); @@ -253,5 +251,4 @@ public class TestXmlReader extends TestCase { return new ByteArrayInputStream(baos.toByteArray()); } - }