Formatted code

Updated POM
This commit is contained in:
Patrick Gotthard 2013-10-07 22:02:04 +02:00
parent 9e24592ef3
commit 14696ebed0
19 changed files with 803 additions and 887 deletions

137
pom.xml
View file

@ -1,26 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.rometools</groupId> <groupId>org.rometools</groupId>
<artifactId>rome-opml</artifactId> <artifactId>rome-opml</artifactId>
<packaging>jar</packaging> <version>2.0.0-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>
<name>rome-opml</name> <name>rome-opml</name>
<url>http://rometools.github.io/rome-opml/</url> <url>http://rometools.github.io/rome-opml/</url>
<description>Support for OPML 1 and OPML 2 in ROME</description> <description>Support for OPML 1 and OPML 2 in ROME</description>
<organization> <organization>
<name>ROME Project</name> <name>ROME Project</name>
<url>https://github.com/rometools/</url> <url>https://github.com/rometools/</url>
</organization> </organization>
<issueManagement> <issueManagement>
<url>https://github.com/rometools/rome-opml/issues</url> <url>https://github.com/rometools/rome-opml/issues</url>
</issueManagement> </issueManagement>
<scm> <scm>
<connection>scm:git:git@github.com:rometools/rome-opml.git</connection> <connection>scm:git:git@github.com:rometools/rome-opml.git</connection>
<developerConnection>scm:git:git@github.com:rometools/rome-opml.git</developerConnection> <developerConnection>scm:git:git@github.com:rometools/rome-opml.git</developerConnection>
<url>https://github.com/rometools/rome-opml/</url> <url>https://github.com/rometools/rome-opml/</url>
</scm> </scm>
<developers> <developers>
<developer> <developer>
<id>kebernet</id> <id>kebernet</id>
@ -28,6 +36,7 @@
<name>Robert Cooper</name> <name>Robert Cooper</name>
</developer> </developer>
</developers> </developers>
<licenses> <licenses>
<license> <license>
<name>The Apache Software License, Version 2.0</name> <name>The Apache Software License, Version 2.0</name>
@ -35,53 +44,45 @@
<distribution>repo</distribution> <distribution>repo</distribution>
</license> </license>
</licenses> </licenses>
<repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<repository> <repository>
<id>maven2-repository.dev.java.net</id> <id>central.staging</id>
<url>http://download.java.net/maven/2</url> <url>http://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository> </repository>
</repositories> <snapshotRepository>
<dependencies> <id>sonatype.snapshots</id>
<dependency> <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<groupId>junit</groupId> </snapshotRepository>
<artifactId>junit</artifactId> </distributionManagement>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <!-- <plugin> -->
<groupId>org.apache.maven.plugins</groupId> <!-- <groupId>org.apache.maven.plugins</groupId> -->
<artifactId>maven-scm-plugin</artifactId> <!-- <artifactId>maven-scm-plugin</artifactId> -->
<version>1.0</version> <!-- <version>1.8.1</version> -->
<configuration> <!-- <configuration> -->
<goals>install</goals> <!-- <goals>install</goals> -->
</configuration> <!-- </configuration> -->
</plugin> <!-- </plugin> -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version> <version>3.1</version>
<configuration> <configuration>
<source>1.4</source> <source>1.6</source>
<target>1.4</target> <target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>2.6</version> <version>2.6</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -102,47 +103,10 @@
<content>${project.build.directory}/site</content> <content>${project.build.directory}/site</content>
</configuration> </configuration>
</plugin> </plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<distributionManagement>
<repository>
<id>central.staging</id>
<name>Nexus Release Repository</name>
<url>http://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
<snapshotRepository>
<id>sonatype.snapshots</id>
<name>My Nexus Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-sources</id> <id>attach-sources</id>
@ -155,6 +119,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-javadocs</id> <id>attach-javadocs</id>
@ -166,22 +131,18 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<reporting> <reporting>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.6</version> <version>2.7</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version> <version>2.9.1</version>
<reportSets> <reportSets>
<reportSet> <reportSet>
<reports> <reports>
@ -200,4 +161,20 @@
</plugin> </plugin>
</plugins> </plugins>
</reporting> </reporting>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.rometools</groupId>
<artifactId>rome</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project> </project>

View file

@ -22,7 +22,6 @@ import com.sun.syndication.feed.impl.ToStringBean;
import java.io.Serializable; import java.io.Serializable;
/** /**
* This is a simple name-value pair attribute for outlines. * This is a simple name-value pair attribute for outlines.
* *
@ -39,6 +38,7 @@ public class Attribute implements Cloneable, Serializable {
/** /**
* Creates a new instance of Attribute. * Creates a new instance of Attribute.
*
* @param name name of the attribute. * @param name name of the attribute.
* @param value value of the attribute. * @param value value of the attribute.
*/ */
@ -53,6 +53,7 @@ public class Attribute implements Cloneable, Serializable {
/** /**
* name of the attribute. * name of the attribute.
*
* @param name name of the attribute. * @param name name of the attribute.
*/ */
public void setName(String name) { public void setName(String name) {
@ -61,6 +62,7 @@ public class Attribute implements Cloneable, Serializable {
/** /**
* name of the attribute. * name of the attribute.
*
* @return name of the attribute. * @return name of the attribute.
*/ */
public String getName() { public String getName() {
@ -69,6 +71,7 @@ public class Attribute implements Cloneable, Serializable {
/** /**
* value of the attribute. * value of the attribute.
*
* @param value value of the attribute. * @param value value of the attribute.
*/ */
public void setValue(String value) { public void setValue(String value) {
@ -77,28 +80,33 @@ public class Attribute implements Cloneable, Serializable {
/** /**
* value of the attribute. * value of the attribute.
*
* @return value of the attribute. * @return value of the attribute.
*/ */
public String getValue() { public String getValue() {
return _value; return _value;
} }
@Override
public Object clone() { public Object clone() {
return new Attribute(this._name, this._value); return new Attribute(this._name, this._value);
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
EqualsBean eBean = new EqualsBean(Attribute.class, this); EqualsBean eBean = new EqualsBean(Attribute.class, this);
return eBean.beanEquals(obj); return eBean.beanEquals(obj);
} }
@Override
public int hashCode() { public int hashCode() {
EqualsBean equals = new EqualsBean(Attribute.class, this); EqualsBean equals = new EqualsBean(Attribute.class, this);
return equals.beanHashCode(); return equals.beanHashCode();
} }
@Override
public String toString() { public String toString() {
ToStringBean tsBean = new ToStringBean(Attribute.class, this); ToStringBean tsBean = new ToStringBean(Attribute.class, this);

View file

@ -23,10 +23,9 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* This class represents the root of an OPML 1/2 feed and contains the elements that * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in the &lt;head&gt; tag of the feed.
* may appear in the &lt;head&gt; tag of the feed. *
* @author <a href="mailto:cooper@screaming-penguin.com"> Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com"> Robert "kebernet" Cooper</a>
*/ */
public class Opml extends WireFeed { public class Opml extends WireFeed {
@ -52,6 +51,7 @@ public class Opml extends WireFeed {
/** /**
* <dateCreated> is a date-time, indicating when the document was created. * <dateCreated> is a date-time, indicating when the document was created.
*
* @param created date-time, indicating when the document was created. * @param created date-time, indicating when the document was created.
*/ */
public void setCreated(Date created) { public void setCreated(Date created) {
@ -60,6 +60,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;dateCreated&gt; is a date-time, indicating when the document was created. * &lt;dateCreated&gt; is a date-time, indicating when the document was created.
*
* @return date-time, indicating when the document was created. * @return date-time, indicating when the document was created.
*/ */
public Date getCreated() { public Date getCreated() {
@ -67,7 +68,9 @@ public class Opml extends WireFeed {
} }
/** /**
* (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML file. It's probably a pointer to <a href="http://www.opml.org/spec2">this page</a> for people who might stumble across the file on a web server 25 years from now and wonder what it is. * (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML file. It's probably a pointer to <a
* href="http://www.opml.org/spec2">this page</a> 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 * @param docs http address of documentation for the format used
*/ */
public void setDocs(String docs) { public void setDocs(String docs) {
@ -75,7 +78,9 @@ public class Opml extends WireFeed {
} }
/** /**
* (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML file. It's probably a pointer to <a href="http://www.opml.org/spec2">this page</a> for people who might stumble across the file on a web server 25 years from now and wonder what it is. * (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML file. It's probably a pointer to <a
* href="http://www.opml.org/spec2">this page</a> 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 * @return http address of documentation for the format used
*/ */
public String getDocs() { public String getDocs() {
@ -83,7 +88,10 @@ public class Opml extends WireFeed {
} }
/** /**
* &lt;expansionState&gt;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. * &lt;expansionState&gt;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. * @param expansionState int array containing expanded elements.
*/ */
public void setExpansionState(int[] expansionState) { public void setExpansionState(int[] expansionState) {
@ -91,7 +99,10 @@ public class Opml extends WireFeed {
} }
/** /**
* &lt;expansionState&gt; 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. * &lt;expansionState&gt; 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. * @return int array containing expanded elements.
*/ */
public int[] getExpansionState() { public int[] getExpansionState() {
@ -100,6 +111,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;dateModified&gt; is a date-time, indicating when the document was last modified. * &lt;dateModified&gt; is a date-time, indicating when the document was last modified.
*
* @param modified 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) { public void setModified(Date modified) {
@ -108,6 +120,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;dateModified&gt; is a date-time, indicating when the document was last modified. * &lt;dateModified&gt; is a date-time, indicating when the document was last modified.
*
* @return date-time, indicating when the document was last modified. * @return date-time, indicating when the document was last modified.
*/ */
public Date getModified() { public Date getModified() {
@ -116,6 +129,7 @@ public class Opml extends WireFeed {
/** /**
* Root level Outline object that should appear in the &lt;body&gt; * Root level Outline object that should appear in the &lt;body&gt;
*
* @param outlines Root level Outline object that should appear in the &lt;body&gt; * @param outlines Root level Outline object that should appear in the &lt;body&gt;
*/ */
public void setOutlines(List outlines) { public void setOutlines(List outlines) {
@ -124,6 +138,7 @@ public class Opml extends WireFeed {
/** /**
* Root level Outline object that should appear in the &lt;body&gt; * Root level Outline object that should appear in the &lt;body&gt;
*
* @return Root level Outline object that should appear in the &lt;body&gt; * @return Root level Outline object that should appear in the &lt;body&gt;
*/ */
public List getOutlines() { public List getOutlines() {
@ -136,6 +151,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;ownerEmail&gt; is a string, the email address of the owner of the document. * &lt;ownerEmail&gt; is a string, the email address of the owner of the document.
*
* @param ownerEmail 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) { public void setOwnerEmail(String ownerEmail) {
@ -144,6 +160,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;ownerEmail&gt; is a string, the email address of the owner of the document. * &lt;ownerEmail&gt; is a string, the email address of the owner of the document.
*
* @return the email address of the owner of the document. * @return the email address of the owner of the document.
*/ */
public String getOwnerEmail() { public String getOwnerEmail() {
@ -151,16 +168,22 @@ public class Opml extends WireFeed {
} }
/** /**
* (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to communicate with the author of the document via email or other means. * (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to communicate with
* @param ownerId http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to communicate with the author of the document via email or other means. * the author of the document via email or other means.
*
* @param ownerId http address of a web page that contains <strike>an HTML</strike> 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) { public void setOwnerId(String ownerId) {
this._ownerId = ownerId; this._ownerId = ownerId;
} }
/** /**
* (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to communicate with the author of the document via email or other means. * (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to communicate with
* @return http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to communicate with the author of the document via email or other means. * the author of the document via email or other means.
*
* @return http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to communicate with the author of the
* document via email or other means.
*/ */
public String getOwnerId() { public String getOwnerId() {
return _ownerId; return _ownerId;
@ -168,6 +191,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;ownerName&gt; is a string, the owner of the document. * &lt;ownerName&gt; is a string, the owner of the document.
*
* @param ownerName the owner of the document. * @param ownerName the owner of the document.
*/ */
public void setOwnerName(String ownerName) { public void setOwnerName(String ownerName) {
@ -176,6 +200,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;ownerName&gt; is a string, the owner of the document. * &lt;ownerName&gt; is a string, the owner of the document.
*
* @return the owner of the document. * @return the owner of the document.
*/ */
public String getOwnerName() { public String getOwnerName() {
@ -184,6 +209,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;title&gt; is the title of the document. * &lt;title&gt; is the title of the document.
*
* @param title title of the document. * @param title title of the document.
*/ */
public void setTitle(String title) { public void setTitle(String title) {
@ -192,6 +218,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;title&gt; is the title of the document. * &lt;title&gt; is the title of the document.
*
* @return title of the document. * @return title of the document.
*/ */
public String getTitle() { public String getTitle() {
@ -199,7 +226,9 @@ public class Opml extends WireFeed {
} }
/** /**
* &lt;vertScrollState&gt; 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. * &lt;vertScrollState&gt; 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. * @param verticalScrollState which line of the outline is displayed on the top line of the window.
*/ */
public void setVerticalScrollState(Integer verticalScrollState) { public void setVerticalScrollState(Integer verticalScrollState) {
@ -207,7 +236,9 @@ public class Opml extends WireFeed {
} }
/** /**
* &lt;vertScrollState&gt; 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. * &lt;vertScrollState&gt; 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. * @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() { public Integer getVerticalScrollState() {
@ -216,6 +247,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowBottom&gt; is a number, the pixel location of the bottom edge of the window. * &lt;windowBottom&gt; 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. * @param windowBottom the pixel location of the bottom edge of the window.
*/ */
public void setWindowBottom(Integer windowBottom) { public void setWindowBottom(Integer windowBottom) {
@ -224,6 +256,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowBottom&gt; is a number, the pixel location of the bottom edge of the window. * &lt;windowBottom&gt; 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() { public Integer getWindowBottom() {
@ -232,6 +265,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowLeft&gt; is a number, the pixel location of the left edge of the window. * &lt;windowLeft&gt; 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. * @param windowLeft the pixel location of the left edge of the window.
*/ */
public void setWindowLeft(Integer windowLeft) { public void setWindowLeft(Integer windowLeft) {
@ -240,6 +274,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowLeft&gt; is a number, the pixel location of the left edge of the window. * &lt;windowLeft&gt; is a number, the pixel location of the left edge of the window.
*
* @return the pixel location of the left edge of the window. * @return the pixel location of the left edge of the window.
*/ */
public Integer getWindowLeft() { public Integer getWindowLeft() {
@ -248,6 +283,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowRight&gt; is a number, the pixel location of the right edge of the window. * &lt;windowRight&gt; 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. * @param windowRight the pixel location of the right edge of the window.
*/ */
public void setWindowRight(Integer windowRight) { public void setWindowRight(Integer windowRight) {
@ -256,6 +292,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowRight&gt; is a number, the pixel location of the right edge of the window. * &lt;windowRight&gt; is a number, the pixel location of the right edge of the window.
*
* @return the pixel location of the right edge of the window. * @return the pixel location of the right edge of the window.
*/ */
public Integer getWindowRight() { public Integer getWindowRight() {
@ -264,6 +301,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowTop&gt; is a number, the pixel location of the top edge of the window. * &lt;windowTop&gt; 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. * @param windowTop the pixel location of the top edge of the window.
*/ */
public void setWindowTop(Integer windowTop) { public void setWindowTop(Integer windowTop) {
@ -272,6 +310,7 @@ public class Opml extends WireFeed {
/** /**
* &lt;windowTop&gt; is a number, the pixel location of the top edge of the window. * &lt;windowTop&gt; is a number, the pixel location of the top edge of the window.
*
* @return the pixel location of the top edge of the window. * @return the pixel location of the top edge of the window.
*/ */
public Integer getWindowTop() { public Integer getWindowTop() {

View file

@ -29,9 +29,9 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* This class represents an OPML outline element. * This class represents an OPML outline element.
*
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class Outline implements Cloneable, Serializable { 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. * Creates a new outline with the specified type and text values.
*
* @param type type attribute value/ * @param type type attribute value/
* @param text text 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 * 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".
* used for aggregator feed lists and will get a type of "rss". *
* @param title Title of the entry. * @param title Title of the entry.
* @param xmlUrl link to XML file. * @param xmlUrl link to XML file.
* @param htmlUrl link to html page. * @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. * List of attributes on this outline excluding the "common types" for the specification.
*
* @param attributes List of attributes on this outline. * @param attributes List of attributes on this outline.
*/ */
public void setAttributes(List attributes) { 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. * List of attributes on this outline excluding the "common types" for the specification.
*
* @return List of attributes on this outline. * @return List of attributes on this outline.
*/ */
public List getAttributes() { 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. * @param breakpoint whether a breakpoint is set on this outline.
*/ */
public void setBreakpoint(boolean breakpoint) { public void setBreakpoint(boolean breakpoint) {
@ -113,7 +118,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.
*
* @return whether a breakpoint is set on this outline * @return whether a breakpoint is set on this outline
*/ */
public boolean isBreakpoint() { public boolean isBreakpoint() {
@ -122,6 +129,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* (OPML 2) A List of Strings indicating values in the category attribute. * (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. * @param categories (OPML 2) A List of Strings indicating values in the category attribute.
*/ */
public void setCategories(List categories) { 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. * (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. * @return (OPML 2) A List of Strings indicating values in the category attribute.
*/ */
public List getCategories() { public List getCategories() {
@ -142,6 +151,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* A list of sub-outlines for this entry. * A list of sub-outlines for this entry.
*
* @param children A list of sub-outlines for this entry. * @param children A list of sub-outlines for this entry.
*/ */
public void setChildren(List children) { public void setChildren(List children) {
@ -150,6 +160,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* A list of sub-outlines for this entry. * A list of sub-outlines for this entry.
*
* @return A list of sub-outlines for this entry. * @return A list of sub-outlines for this entry.
*/ */
public List getChildren() { 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 * @param comment whether the outline is commented
*/ */
public void setComment(boolean comment) { public void setComment(boolean comment) {
@ -169,7 +182,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.
*
* @return whether the outline is commented * @return whether the outline is commented
*/ */
public boolean isComment() { public boolean isComment() {
@ -178,6 +193,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* (OPML 2) created is the date-time that the outline node was created. * (OPML 2) created is the date-time that the outline node was created.
*
* @param created date-time that the outline node was created. * @param created date-time that the outline node was created.
*/ */
public void setCreated(Date created) { public void setCreated(Date created) {
@ -186,6 +202,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* (OPML 2) created is the date-time that the outline node was created. * (OPML 2) created is the date-time that the outline node was created.
*
* @return date-time that the outline node was created. * @return date-time that the outline node was created.
*/ */
public Date getCreated() { public Date getCreated() {
@ -194,6 +211,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* A convenience method to return the value of the url attribute. * A convenience method to return the value of the url attribute.
*
* @return value of the htmlUrl attribute. * @return value of the htmlUrl attribute.
*/ */
public String getUrl() { public String getUrl() {
@ -202,6 +220,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* A convenience method to return the value of the htmlUrl attribute. * A convenience method to return the value of the htmlUrl attribute.
*
* @return value of the htmlUrl attribute. * @return value of the htmlUrl attribute.
*/ */
public String getHtmlUrl() { public String getHtmlUrl() {
@ -222,6 +241,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* The "text" attribute of the outline. * The "text" attribute of the outline.
*
* @param text The "text" attribute of the outline. * @param text The "text" attribute of the outline.
*/ */
public void setText(String text) { public void setText(String text) {
@ -230,6 +250,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* The "text" attribute of the outline. * The "text" attribute of the outline.
*
* @return The "text" attribute of the outline. * @return The "text" attribute of the outline.
*/ */
public String getText() { public String getText() {
@ -238,6 +259,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* The "title" attribute of the outline. * The "title" attribute of the outline.
*
* @param title The "title" attribute of the outline. * @param title The "title" attribute of the outline.
*/ */
public void setTitle(String title) { public void setTitle(String title) {
@ -246,6 +268,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* The "title" attribute of the outline. * The "title" attribute of the outline.
*
* @return The "title" attribute of the outline. * @return The "title" attribute of the outline.
*/ */
public String getTitle() { public String getTitle() {
@ -254,6 +277,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* The "type" attribute of the outline. * The "type" attribute of the outline.
*
* @param type The "type" attribute of the outline. * @param type The "type" attribute of the outline.
*/ */
public void setType(String type) { public void setType(String type) {
@ -262,6 +286,7 @@ public class Outline implements Cloneable, Serializable {
/** /**
* The "type" attribute of the outline. * The "type" attribute of the outline.
*
* @return The "type" attribute of the outline. * @return The "type" attribute of the outline.
*/ */
public String getType() { public String getType() {
@ -270,13 +295,16 @@ public class Outline implements Cloneable, Serializable {
/** /**
* A convenience method to return the value of the xmlUrl attribute. * 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() { 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. * @param name name of the attribute.
*/ */
public String getAttributeValue(String name) { public String getAttributeValue(String name) {
@ -293,6 +321,7 @@ public class Outline implements Cloneable, Serializable {
return null; return null;
} }
@Override
public Object clone() { public Object clone() {
Outline o = new Outline(); Outline o = new Outline();
o.setBreakpoint(this.isBreakpoint()); o.setBreakpoint(this.isBreakpoint());
@ -323,18 +352,21 @@ public class Outline implements Cloneable, Serializable {
return o; return o;
} }
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
EqualsBean eBean = new EqualsBean(Outline.class, this); EqualsBean eBean = new EqualsBean(Outline.class, this);
return eBean.beanEquals(obj); return eBean.beanEquals(obj);
} }
@Override
public int hashCode() { public int hashCode() {
EqualsBean equals = new EqualsBean(Outline.class, this); EqualsBean equals = new EqualsBean(Outline.class, this);
return equals.beanHashCode(); return equals.beanHashCode();
} }
@Override
public String toString() { public String toString() {
ToStringBean tsBean = new ToStringBean(Outline.class, this); ToStringBean tsBean = new ToStringBean(Outline.class, this);

View file

@ -41,14 +41,12 @@ import com.sun.syndication.feed.synd.SyndLinkImpl;
import com.sun.syndication.feed.synd.SyndPerson; import com.sun.syndication.feed.synd.SyndPerson;
import com.sun.syndication.feed.synd.SyndPersonImpl; import com.sun.syndication.feed.synd.SyndPersonImpl;
/** /**
* *
* @author cooper * @author cooper
*/ */
public class ConverterForOPML10 implements Converter { public class ConverterForOPML10 implements Converter {
private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName() private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName().toString());
.toString());
public static final String URI_TREE = "urn:rome.tree"; public static final String URI_TREE = "urn:rome.tree";
public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; public static final String URI_ATTRIBUTE = "urn:rome.attribute#";
@ -77,23 +75,21 @@ public class ConverterForOPML10 implements Converter {
* @param feed real feed to copy/convert. * @param feed real feed to copy/convert.
* @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed.
*/ */
@Override
public void copyInto(WireFeed feed, SyndFeed syndFeed) { public void copyInto(WireFeed feed, SyndFeed syndFeed) {
Opml opml = (Opml) feed; Opml opml = (Opml) feed;
syndFeed.setTitle(opml.getTitle()); syndFeed.setTitle(opml.getTitle());
addOwner(opml, syndFeed); addOwner(opml, syndFeed);
syndFeed.setPublishedDate((opml.getModified() != null) syndFeed.setPublishedDate((opml.getModified() != null) ? opml.getModified() : opml.getCreated());
? opml.getModified() : opml.getCreated());
syndFeed.setFeedType(opml.getFeedType()); syndFeed.setFeedType(opml.getFeedType());
syndFeed.setModules(opml.getModules()); syndFeed.setModules(opml.getModules());
syndFeed.setFeedType(this.getType()); syndFeed.setFeedType(this.getType());
ArrayList entries = new ArrayList(); ArrayList entries = new ArrayList();
createEntries(new TreeContext(), syndFeed.getEntries(), createEntries(new TreeContext(), syndFeed.getEntries(), opml.getOutlines());
opml.getOutlines());
} }
protected void createEntries(TreeContext context, List allEntries, protected void createEntries(TreeContext context, List allEntries, List outlines) {
List outlines) {
List so = Collections.synchronizedList(outlines); List so = Collections.synchronizedList(outlines);
for (int i = 0; i < so.size(); i++) { for (int i = 0; i < so.size(); i++) {
@ -101,15 +97,12 @@ public class ConverterForOPML10 implements Converter {
} }
} }
protected SyndEntry createEntry(TreeContext context, List allEntries, protected SyndEntry createEntry(TreeContext context, List allEntries, Outline outline) {
Outline outline) {
SyndEntry entry = new SyndEntryImpl(); SyndEntry entry = new SyndEntryImpl();
if ((outline.getType() != null) && outline.getType().equals("rss")) { if ((outline.getType() != null) && outline.getType().equals("rss")) {
entry.setLink((outline.getHtmlUrl() != null) ? outline.getHtmlUrl() entry.setLink((outline.getHtmlUrl() != null) ? outline.getHtmlUrl() : outline.getXmlUrl());
: outline.getXmlUrl()); } else if ((outline.getType() != null) && outline.getType().equals("link")) {
} else if((outline.getType() != null) &&
outline.getType().equals("link")) {
entry.setLink(outline.getUrl()); entry.setLink(outline.getUrl());
} }
@ -122,8 +115,7 @@ public class ConverterForOPML10 implements Converter {
entry.setLink(outline.getHtmlUrl()); entry.setLink(outline.getHtmlUrl());
} }
if((outline.getXmlUrl() != null) && (outline.getType() != null) && if ((outline.getXmlUrl() != null) && (outline.getType() != null) && outline.getType().equalsIgnoreCase("rss")) {
outline.getType().equalsIgnoreCase("rss")) {
SyndLink link = new SyndLinkImpl(); SyndLink link = new SyndLinkImpl();
link.setRel("alternate"); link.setRel("alternate");
link.setType("application/rss+xml"); link.setType("application/rss+xml");
@ -135,8 +127,7 @@ public class ConverterForOPML10 implements Converter {
} }
} }
if((outline.getXmlUrl() != null) && (outline.getType() != null) && if ((outline.getXmlUrl() != null) && (outline.getType() != null) && outline.getType().equalsIgnoreCase("atom")) {
outline.getType().equalsIgnoreCase("atom")) {
SyndLink link = new SyndLinkImpl(); SyndLink link = new SyndLinkImpl();
link.setRel("alternate"); link.setRel("alternate");
link.setType("application/atom+xml"); link.setType("application/atom+xml");
@ -204,6 +195,7 @@ public class ConverterForOPML10 implements Converter {
* @return a real feed with copied/converted values of the SyndFeedImpl. * @return a real feed with copied/converted values of the SyndFeedImpl.
* *
*/ */
@Override
public WireFeed createRealFeed(SyndFeed syndFeed) { public WireFeed createRealFeed(SyndFeed syndFeed) {
List entries = Collections.synchronizedList(syndFeed.getEntries()); List entries = Collections.synchronizedList(syndFeed.getEntries());
@ -222,11 +214,8 @@ public class ConverterForOPML10 implements Converter {
for (int j = 0; j < cats.size(); j++) { for (int j = 0; j < cats.size(); j++) {
SyndCategory cat = (SyndCategory) cats.get(j); SyndCategory cat = (SyndCategory) cats.get(j);
if((cat.getTaxonomyUri() != null) && if ((cat.getTaxonomyUri() != null) && cat.getTaxonomyUri().equals(URI_TREE)) {
cat.getTaxonomyUri().equals(URI_TREE)) { String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length());
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); entriesByNode.put(nodeVal, o);
@ -241,11 +230,8 @@ public class ConverterForOPML10 implements Converter {
doAfterPass.add(new OutlineHolder(o, nodeVal)); doAfterPass.add(new OutlineHolder(o, nodeVal));
} }
} }
} else if((cat.getTaxonomyUri() != null) && } else if ((cat.getTaxonomyUri() != null) && cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) {
cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) { String name = cat.getTaxonomyUri().substring(cat.getTaxonomyUri().indexOf("#") + 1, cat.getTaxonomyUri().length());
String name = cat.getTaxonomyUri()
.substring(cat.getTaxonomyUri().indexOf("#") +
1, cat.getTaxonomyUri().length());
o.getAttributes().add(new Attribute(name, cat.getName())); o.getAttributes().add(new Attribute(name, cat.getName()));
} else { } else {
if (category.length() > 0) { if (category.length() > 0) {
@ -261,8 +247,7 @@ public class ConverterForOPML10 implements Converter {
} }
if (category.length() > 0) { if (category.length() > 0) {
o.getAttributes() o.getAttributes().add(new Attribute("category", category.toString()));
.add(new Attribute("category", category.toString()));
} }
List links = Collections.synchronizedList(entry.getLinks()); List links = Collections.synchronizedList(entry.getLinks());
@ -272,21 +257,16 @@ public class ConverterForOPML10 implements Converter {
SyndLink link = (SyndLink) links.get(j); SyndLink link = (SyndLink) links.get(j);
// if(link.getHref().equals(entryLink)) { // if(link.getHref().equals(entryLink)) {
if(((link.getType() != null) && (link.getRel() != null) && if (((link.getType() != null) && (link.getRel() != null) && link.getRel().equals("alternate"))
link.getRel().equals("alternate")) && && (link.getType().equals("application/rss+xml") || link.getType().equals("application/atom+xml"))) {
(link.getType().equals("application/rss+xml") ||
link.getType().equals("application/atom+xml"))) {
o.setType("rss"); o.setType("rss");
if (o.getXmlUrl() == null) { if (o.getXmlUrl() == null) {
o.getAttributes() o.getAttributes().add(new Attribute("xmlUrl", link.getHref()));
.add(new Attribute("xmlUrl", link.getHref()));
} }
} else if((link.getType() != null) && } else if ((link.getType() != null) && (link.getType().equals("text/html"))) {
(link.getType().equals("text/html"))) {
if (o.getHtmlUrl() == null) { if (o.getHtmlUrl() == null) {
o.getAttributes() o.getAttributes().add(new Attribute("htmlUrl", link.getHref()));
.add(new Attribute("htmlUrl", link.getHref()));
} }
} else { } else {
o.setType(link.getType()); o.setType(link.getType());
@ -298,7 +278,6 @@ public class ConverterForOPML10 implements Converter {
if ((o.getType() == null) || o.getType().equals("link")) { if ((o.getType() == null) || o.getType().equals("link")) {
o.setText(entry.getTitle()); o.setText(entry.getTitle());
} else { } else {
o.setTitle(entry.getTitle()); o.setTitle(entry.getTitle());
} }
@ -331,8 +310,7 @@ public class ConverterForOPML10 implements Converter {
for (int i = 0; i < authors.size(); i++) { for (int i = 0; i < authors.size(); i++) {
SyndPerson p = (SyndPerson) authors.get(i); SyndPerson p = (SyndPerson) authors.get(i);
if((syndFeed.getAuthor() == null) || if ((syndFeed.getAuthor() == null) || syndFeed.getAuthor().equals(p.getName())) {
syndFeed.getAuthor().equals(p.getName())) {
opml.setOwnerName(p.getName()); opml.setOwnerName(p.getName());
opml.setOwnerEmail(p.getEmail()); opml.setOwnerEmail(p.getEmail());
opml.setOwnerId(p.getUri()); opml.setOwnerId(p.getUri());
@ -352,6 +330,7 @@ public class ConverterForOPML10 implements Converter {
* @see WireFeed for details on the format of this string. * @see WireFeed for details on the format of this string.
* <p> * <p>
*/ */
@Override
public String getType() { public String getType() {
return "opml_1.0"; return "opml_1.0";
} }

View file

@ -11,7 +11,6 @@ package org.rometools.feed.synd.impl;
import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
/** /**
* *
* @author cooper * @author cooper
@ -30,6 +29,7 @@ public class ConverterForOPML20 extends ConverterForOPML10 {
* @see WireFeed for details on the format of this string. * @see WireFeed for details on the format of this string.
* <p> * <p>
*/ */
@Override
public String getType() { public String getType() {
return "opml_2.0"; return "opml_2.0";
} }
@ -43,6 +43,7 @@ public class ConverterForOPML20 extends ConverterForOPML10 {
* @param feed real feed to copy/convert. * @param feed real feed to copy/convert.
* @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed.
*/ */
@Override
public void copyInto(WireFeed feed, SyndFeed syndFeed) { public void copyInto(WireFeed feed, SyndFeed syndFeed) {
super.copyInto(feed, syndFeed); super.copyInto(feed, syndFeed);
} }
@ -54,6 +55,7 @@ public class ConverterForOPML20 extends ConverterForOPML10 {
* @param syndFeed SyndFeedImpl to copy/convert value from. * @param syndFeed SyndFeedImpl to copy/convert value from.
* @return a real feed with copied/converted values of the SyndFeedImpl. * @return a real feed with copied/converted values of the SyndFeedImpl.
*/ */
@Override
public WireFeed createRealFeed(SyndFeed syndFeed) { public WireFeed createRealFeed(SyndFeed syndFeed) {
WireFeed retValue; WireFeed retValue;

View file

@ -23,6 +23,7 @@ public class TreeCategoryImpl extends SyndCategoryImpl {
super(); super();
} }
@Override
public boolean equals(Object o) { public boolean equals(Object o) {
SyndCategory c = (SyndCategory) o; SyndCategory c = (SyndCategory) o;
if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(this.getTaxonomyUri())) if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(this.getTaxonomyUri()))

View file

@ -26,14 +26,13 @@ import com.sun.syndication.io.WireFeedGenerator;
import com.sun.syndication.io.impl.BaseWireFeedGenerator; import com.sun.syndication.io.impl.BaseWireFeedGenerator;
import com.sun.syndication.io.impl.DateParser; import com.sun.syndication.io.impl.DateParser;
import org.jdom.Document; import org.jdom2.Document;
import org.jdom.Element; import org.jdom2.Element;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* *
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
@ -54,10 +53,10 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
* *
* @param feed the feed bean to generate the XML document from. * @param feed the feed bean to generate the XML document from.
* @return the generated XML document (JDOM). * @return the generated XML document (JDOM).
* @throws IllegalArgumentException thrown if the type of the given feed bean does not * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator.
* match with the type of the WireFeedGenerator.
* @throws FeedException thrown if the XML Document could not be created. * @throws FeedException thrown if the XML Document could not be created.
*/ */
@Override
public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException {
if (!(feed instanceof Opml)) { if (!(feed instanceof Opml)) {
throw new IllegalArgumentException("Not an OPML file"); throw new IllegalArgumentException("Not an OPML file");

View file

@ -26,8 +26,8 @@ import com.sun.syndication.io.WireFeedParser;
import com.sun.syndication.io.impl.BaseWireFeedParser; import com.sun.syndication.io.impl.BaseWireFeedParser;
import com.sun.syndication.io.impl.DateParser; import com.sun.syndication.io.impl.DateParser;
import org.jdom.Document; import org.jdom2.Document;
import org.jdom.Element; import org.jdom2.Element;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -35,7 +35,6 @@ import java.util.StringTokenizer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* *
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
@ -61,11 +60,11 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
* @param document XML Document (JDOM) to check if it can be parsed by this parser. * @param document XML Document (JDOM) to check if it can be parsed by this parser.
* @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise. * @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise.
*/ */
@Override
public boolean isMyType(Document document) { public boolean isMyType(Document document) {
Element e = document.getRootElement(); Element e = document.getRootElement();
if (e.getName().equals("opml") if (e.getName().equals("opml") && (e.getChild("head") == null || e.getChild("head").getChild("docs") == null)
&& ( e.getChild("head") == null || e.getChild("head").getChild("docs") == null)
&& (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) {
return true; return true;
} }
@ -83,6 +82,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
* @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. * @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). * @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 { public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException {
Opml opml = new Opml(); Opml opml = new Opml();
opml.setFeedType("opml_1.0"); opml.setFeedType("opml_1.0");
@ -182,9 +182,10 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
ArrayList attributes = new ArrayList(); ArrayList attributes = new ArrayList();
for (int i = 0; i < jAttributes.size(); i++) { 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())); attributes.add(new Attribute(a.getName(), a.getValue()));
} }
} }

View file

@ -14,9 +14,8 @@ import org.rometools.feed.opml.Outline;
import com.sun.syndication.io.FeedException; import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.impl.DateParser; import com.sun.syndication.io.impl.DateParser;
import org.jdom.Document; import org.jdom2.Document;
import org.jdom.Element; import org.jdom2.Element;
/** /**
* *
@ -35,6 +34,7 @@ public class OPML20Generator extends OPML10Generator {
* @see WireFeed for details on the format of this string. * @see WireFeed for details on the format of this string.
* <p> * <p>
*/ */
@Override
public String getType() { public String getType() {
return "opml_2.0"; return "opml_2.0";
} }
@ -45,10 +45,10 @@ public class OPML20Generator extends OPML10Generator {
* *
* @param feed the feed bean to generate the XML document from. * @param feed the feed bean to generate the XML document from.
* @return the generated XML document (JDOM). * @return the generated XML document (JDOM).
* @throws IllegalArgumentException thrown if the type of the given feed bean does not * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator.
* match with the type of the WireFeedGenerator.
* @throws FeedException thrown if the XML Document could not be created. * @throws FeedException thrown if the XML Document could not be created.
*/ */
@Override
public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException {
Document retValue; Document retValue;
@ -58,6 +58,7 @@ public class OPML20Generator extends OPML10Generator {
return retValue; return retValue;
} }
@Override
protected Element generateHead(Opml opml) { protected Element generateHead(Opml opml) {
Element retValue; Element retValue;
@ -69,6 +70,7 @@ public class OPML20Generator extends OPML10Generator {
return retValue; return retValue;
} }
@Override
protected Element generateOutline(Outline outline) { protected Element generateOutline(Outline outline) {
Element retValue; Element retValue;

View file

@ -24,13 +24,10 @@ import org.rometools.feed.opml.Outline;
import com.sun.syndication.io.FeedException; import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.impl.DateParser; import com.sun.syndication.io.impl.DateParser;
import org.jdom.Document; import org.jdom2.Document;
import org.jdom.Element; import org.jdom2.Element;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.StringTokenizer;
/** /**
* *
@ -51,10 +48,14 @@ public class OPML20Parser extends OPML10Parser {
* @param document XML Document (JDOM) to check if it can be parsed by this parser. * @param document XML Document (JDOM) to check if it can be parsed by this parser.
* @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise. * @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise.
*/ */
@Override
public boolean isMyType(Document document) { public boolean isMyType(Document document) {
Element e = document.getRootElement(); 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; return true;
} }
@ -71,6 +72,7 @@ public class OPML20Parser extends OPML10Parser {
* @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. * @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). * @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 { public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException {
Opml opml; Opml opml;
opml = (Opml) super.parse(document, validate); opml = (Opml) super.parse(document, validate);
@ -91,6 +93,7 @@ public class OPML20Parser extends OPML10Parser {
return opml; return opml;
} }
@Override
protected Outline parseOutline(Element e, boolean validate) throws FeedException { protected Outline parseOutline(Element e, boolean validate) throws FeedException {
Outline retValue; Outline retValue;

View file

@ -1,63 +1,64 @@
package org.rometools.unittest; 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.WireFeed;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl; 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;
/** /**
* *
* <p> * <p>
*
* @author Alejandro Abdelnur * @author Alejandro Abdelnur
* *
*/ */
public abstract class FeedOpsTest extends FeedTest { public abstract class FeedOpsTest extends FeedTest {
protected FeedOpsTest(String feedType) { protected FeedOpsTest(final String feedType) {
super(feedType + ".xml"); super(feedType + ".xml");
System.out.println("Testing "+feedType+".xml");
new File("target/test-reports").mkdirs(); new File("target/test-reports").mkdirs();
} }
// 1.2a // 1.2a
public void testWireFeedEquals() throws Exception { public void testWireFeedEquals() throws Exception {
WireFeed feed1 = getCachedWireFeed(); final WireFeed feed1 = getCachedWireFeed();
WireFeed feed2 = getWireFeed(); final WireFeed feed2 = getWireFeed();
assertTrue(feed1.equals(feed2)); assertTrue(feed1.equals(feed2));
} }
// 1.2b // 1.2b
public void testWireFeedNotEqual() throws Exception { public void testWireFeedNotEqual() throws Exception {
WireFeed feed1 = getCachedWireFeed(); final WireFeed feed1 = getCachedWireFeed();
WireFeed feed2 = getWireFeed(); final WireFeed feed2 = getWireFeed();
feed2.setFeedType("dummy"); feed2.setFeedType("dummy");
assertFalse(feed1.equals(feed2)); assertFalse(feed1.equals(feed2));
} }
// 1.3 // 1.3
public void testWireFeedCloning() throws Exception { public void testWireFeedCloning() throws Exception {
WireFeed feed1 = getCachedWireFeed(); final WireFeed feed1 = getCachedWireFeed();
WireFeed feed2 = (WireFeed) feed1.clone();; final WireFeed feed2 = (WireFeed) feed1.clone();
;
assertTrue(feed1.equals(feed2)); assertTrue(feed1.equals(feed2));
} }
// 1.4 // 1.4
public void testWireFeedSerialization() throws Exception { public void testWireFeedSerialization() throws Exception {
WireFeed feed1 = getCachedWireFeed(); final WireFeed feed1 = getCachedWireFeed();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(feed1); oos.writeObject(feed1);
oos.close(); oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais); final ObjectInputStream ois = new ObjectInputStream(bais);
WireFeed feed2 = (WireFeed) ois.readObject(); final WireFeed feed2 = (WireFeed) ois.readObject();
ois.close(); ois.close();
assertTrue(feed1.equals(feed2)); assertTrue(feed1.equals(feed2));
@ -65,47 +66,48 @@ public abstract class FeedOpsTest extends FeedTest {
// 1.6 // 1.6
public void testWireFeedSyndFeedConversion() throws Exception { public void testWireFeedSyndFeedConversion() throws Exception {
SyndFeed sFeed1 = getCachedSyndFeed(); final SyndFeed sFeed1 = getCachedSyndFeed();
WireFeed wFeed1 = sFeed1.createWireFeed(); final WireFeed wFeed1 = sFeed1.createWireFeed();
SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
assertEquals(sFeed1, sFeed2); assertEquals(sFeed1, sFeed2);
} }
// 1.7a // 1.7a
public void testSyndFeedEquals() throws Exception { public void testSyndFeedEquals() throws Exception {
SyndFeed feed1 = getCachedSyndFeed(); final SyndFeed feed1 = getCachedSyndFeed();
SyndFeed feed2 = getSyndFeed(); final SyndFeed feed2 = getSyndFeed();
assertTrue(feed1.equals(feed2)); assertTrue(feed1.equals(feed2));
} }
// 1.7b // 1.7b
public void testSyndFeedNotEqual() throws Exception { public void testSyndFeedNotEqual() throws Exception {
SyndFeed feed1 = getCachedSyndFeed(); final SyndFeed feed1 = getCachedSyndFeed();
SyndFeed feed2 = getSyndFeed(); final SyndFeed feed2 = getSyndFeed();
feed2.setFeedType("dummy"); feed2.setFeedType("dummy");
assertFalse(feed1.equals(feed2)); assertFalse(feed1.equals(feed2));
} }
// 1.8 // 1.8
public void testSyndFeedCloning() throws Exception { public void testSyndFeedCloning() throws Exception {
SyndFeed feed1 = getCachedSyndFeed(); final SyndFeed feed1 = getCachedSyndFeed();
SyndFeed feed2 = (SyndFeed) feed1.clone();; final SyndFeed feed2 = (SyndFeed) feed1.clone();
;
assertTrue(feed1.equals(feed2)); assertTrue(feed1.equals(feed2));
} }
// 1.9 // 1.9
public void testSyndFeedSerialization() throws Exception { public void testSyndFeedSerialization() throws Exception {
SyndFeed feed1 = getCachedSyndFeed(); final SyndFeed feed1 = getCachedSyndFeed();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(feed1); oos.writeObject(feed1);
oos.close(); oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais); final ObjectInputStream ois = new ObjectInputStream(bais);
SyndFeed feed2 = (SyndFeed) ois.readObject(); final SyndFeed feed2 = (SyndFeed) ois.readObject();
ois.close(); ois.close();
assertTrue(feed1.equals(feed2)); assertTrue(feed1.equals(feed2));

View file

@ -1,30 +1,30 @@
package org.rometools.unittest; package org.rometools.unittest;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import junit.framework.TestCase; 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.WireFeed;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.WireFeedInput; 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 * @author pat, tucu
* *
*/ */
public abstract class FeedTest extends TestCase { public abstract class FeedTest extends TestCase {
private String _feedFileName; private final String _feedFileName;
private Document _jDomDoc = null; private Document _jDomDoc = null;
private WireFeed _wireFeed = null; private WireFeed _wireFeed = null;
private SyndFeed _syndFeed = null; private SyndFeed _syndFeed = null;
protected FeedTest(String feedFileName) { protected FeedTest(final String feedFileName) {
_feedFileName = feedFileName; _feedFileName = feedFileName;
} }
@ -33,24 +33,23 @@ public abstract class FeedTest extends TestCase {
} }
protected Reader getFeedReader() throws Exception { protected Reader getFeedReader() throws Exception {
InputStream resource = Thread.currentThread(). final InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream(getFeedFileName());
getContextClassLoader().getResourceAsStream(getFeedFileName());
assertNotNull("Could not find resource " + getFeedFileName(), resource); assertNotNull("Could not find resource " + getFeedFileName(), resource);
return new InputStreamReader(resource); return new InputStreamReader(resource);
} }
protected Document getJDomDoc() throws Exception { protected Document getJDomDoc() throws Exception {
SAXBuilder saxBuilder = new SAXBuilder(false); final SAXBuilder saxBuilder = new SAXBuilder(false);
return saxBuilder.build(getFeedReader()); return saxBuilder.build(getFeedReader());
} }
protected WireFeed getWireFeed() throws Exception { protected WireFeed getWireFeed() throws Exception {
WireFeedInput in = new WireFeedInput(); final WireFeedInput in = new WireFeedInput();
return in.build(getFeedReader()); return in.build(getFeedReader());
} }
protected SyndFeed getSyndFeed() throws Exception { protected SyndFeed getSyndFeed() throws Exception {
SyndFeedInput in = new SyndFeedInput(); final SyndFeedInput in = new SyndFeedInput();
return in.build(getFeedReader()); return in.build(getFeedReader());
} }

View file

@ -6,9 +6,6 @@
*/ */
package org.rometools.unittest; package org.rometools.unittest;
/** /**
* @author pat * @author pat
* *
@ -37,231 +34,109 @@ public abstract class SyndFeedTest extends FeedTest {
assertEquals(getCachedSyndFeed().getFeedType(), getPrefix()); assertEquals(getCachedSyndFeed().getFeedType(), getPrefix());
} }
/* /*
public void testType() throws Exception { * public void testType() throws Exception { assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); }
assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); *
} * public void testTitle() throws Exception { assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); }
*
public void testTitle() throws Exception { * public void testLink() throws Exception { assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); }
assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); *
} * public void testDescription() throws Exception { assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); }
*
public void testLink() throws Exception { * public void testLanguage() throws Exception { assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); }
assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); *
} * 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());
public void testDescription() throws Exception { * assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); cat = (SyndCategory)catlist.get(1); assertEqualsStr("channel.category[1]",
assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); * 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"),
public void testLanguage() throws Exception { * getCachedSyndFeed().getPublishedDate()); }
assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); *
} * //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());
public void testCategories() throws Exception { * assertEqualsStr("channel.image.title", img.getTitle()); assertEqualsStr("channel.image.url", img.getUrl()); }
List catlist = getCachedSyndFeed().getCategories(); *
//don't understand why this one fails * public void testEntries() throws Exception { List entrylist = getCachedSyndFeed().getEntries(); assertEquals(2, entrylist.size()); }
assertEquals(2, catlist.size()); *
SyndCategory cat = (SyndCategory)catlist.get(0); * public void testEntryTitle() throws Exception { assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0)));
assertEqualsStr("channel.category[0]", cat.getName()); * assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); }
assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); *
cat = (SyndCategory)catlist.get(1); * public String getEntryTitle(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getTitle(); }
assertEqualsStr("channel.category[1]", cat.getName()); *
assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); * 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 void testPublishedDate() throws Exception { *
assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getCachedSyndFeed().getPublishedDate()); * 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)));
//how do i get height and width? * assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); }
public void testImage() throws Exception { *
SyndImage img = getCachedSyndFeed().getImage(); * public String getEntryLink(Object o) { SyndEntry e = (SyndEntry) o; return e.getLink(); }
assertEqualsStr("channel.image.description", img.getDescription()); *
assertEqualsStr("channel.image.link", img.getLink()); * public void testEntryPublishedDate() throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"),
assertEqualsStr("channel.image.title", img.getTitle()); * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"),
assertEqualsStr("channel.image.url", img.getUrl()); * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); }
} *
* public Date getEntryPublishedDate(Object o) { SyndEntry e = (SyndEntry) o; return e.getPublishedDate(); }
public void testEntries() throws Exception { *
List entrylist = getCachedSyndFeed().getEntries(); * public void testEntryCategories() throws Exception { SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); List catlist = e.getCategories();
assertEquals(2, entrylist.size()); * //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",
public void testEntryTitle() throws Exception { * cat.getTaxonomyUri()); //DO 2nd set of items }
assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); *
assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); * 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 getEntryTitle(Object o) throws Exception { * public String getEntryAuthor(Object o) { SyndEntry e = (SyndEntry) o; return e.getAuthor(); }
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 * //things you cannot get from SyndEntryImpl // <source url="http://localhost:8080/item0/source.url">item[0].source</source> // <enclosure
// <source url="http://localhost:8080/item0/source.url">item[0].source</source> * url="http://localhost:8080/item0/enclosure0.url" length="100" type="audio/mpeg"/> // <enclosure url="http://localhost:8080/item0/enclosure1.url"
// <enclosure url="http://localhost:8080/item0/enclosure0.url" length="100" type="audio/mpeg"/> * length="1000" type="audio/mpeg"/> <category domain="item0.domain0">item0.category0</category> <category domain="item0.domain1">item0.category1</category>
// <enclosure url="http://localhost:8080/item0/enclosure1.url" length="1000" type="audio/mpeg"/> * <pubDate>Thu, 08 Jul 1999 08:00:00 GMT</pubDate> <expirationDate>Thu, 08 Jul 1999 09:00:00 GMT</.expirationDate> <author>item0.author</author>
<category domain="item0.domain0">item0.category0</category> * <comments>http://localhost:8080/item0/comments</comments> <guid isPermaLink="true">http://localhost:8080/item0/guid</guid> //TODO: I still have the
<category domain="item0.domain1">item0.category1</category> * elements to test
<pubDate>Thu, 08 Jul 1999 08:00:00 GMT</pubDate>
<expirationDate>Thu, 08 Jul 1999 09:00:00 GMT</.expirationDate>
<author>item0.author</author>
<comments>http://localhost:8080/item0/comments</comments>
<guid isPermaLink="true">http://localhost:8080/item0/guid</guid>
//TODO: I still have the elements to test
*/ */
/* /*
public void test() { * public void test() { assertEqualsStr(feed, ""); }
assertEqualsStr(feed, ""); *
} * public void test() { assertEqualsStr(feed, ""); }
public void test() {
assertEqualsStr(feed, "");
}
*/ */
// Things that you cannot get form a SyndFeedImpl today // Things that you cannot get form a SyndFeedImpl today
// these need to be put in a RSS 2.0 module // these need to be put in a RSS 2.0 module
// or is a roundtrip to wirefeed the right way to do this? // or is a roundtrip to wirefeed the right way to do this?
/* /*
* <textInput> * <textInput> <title>Search</title> <description>Search this site:</description> <name>q</name> <link>http://example.org/mt/mt-search.cgi</link>
<title>Search</title> * </textInput>
<description>Search this site:</description>
<name>q</name>
<link>http://example.org/mt/mt-search.cgi</link>
</textInput>
image height and width
* *
//<copyright>Copyright 2004, Mark Pilgrim</copyright> * image height and width
public void test() { *
assertEqualsStr(getCachedSyndFeed()., ""); * //<copyright>Copyright 2004, Mark Pilgrim</copyright> public void test() { assertEqualsStr(getCachedSyndFeed()., ""); }
} *
* //<generator>Sample Toolkit</generator> public void test() { assertEqualsStr(feed, ""); }
//<generator>Sample Toolkit</generator> *
public void test() { * // <managingEditor>editor@example.org</managingEditor> public void test() { assertEqualsStr(feed, ""); }
assertEqualsStr(feed, ""); *
} * // <webMaster>webmaster@example.org</webMaster> public void test() { assertEqualsStr(feed, ""); }
*
// <managingEditor>editor@example.org</managingEditor> * <docs>http://blogs.law.harvard.edu/tech/rss</docs> <cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap"/>
public void test() { * <ttl>60</ttl> <rating></rating>
assertEqualsStr(feed, ""); *
} * <skiphours> <hour>0</hour> <hour>1</hour> <hour>2</hour> <hour>3</hour> <hour>4</hour> <hour>5</hour> <hour>6</hour> <hour>7</hour> <hour>8</hour>
* <hour>9.5</hour> <hour>10</hour> <hour>11</hour> <hour>12</hour> <hour>13</hour> <hour>14</hour> <hour>15</hour> <hour>16</hour> <hour>17</hour>
// <webMaster>webmaster@example.org</webMaster> * <hour>18</hour> <hour>19</hour> <hour>20</hour> <hour>21</hour> <hour>22</hour> <hour>23</hour> </skiphours> <skipdays> <day>Monday</day>
public void test() { * <day>Tuesday</day> <day>Wednesday</day> <day>Thursday</day> <day>Friday</day> <day>Saturday</day> <day>Sunday</day> </skipdays>
assertEqualsStr(feed, ""); */
}
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap"/>
<ttl>60</ttl>
<rating></rating>
<skiphours>
<hour>0</hour>
<hour>1</hour>
<hour>2</hour>
<hour>3</hour>
<hour>4</hour>
<hour>5</hour>
<hour>6</hour>
<hour>7</hour>
<hour>8</hour>
<hour>9.5</hour>
<hour>10</hour>
<hour>11</hour>
<hour>12</hour>
<hour>13</hour>
<hour>14</hour>
<hour>15</hour>
<hour>16</hour>
<hour>17</hour>
<hour>18</hour>
<hour>19</hour>
<hour>20</hour>
<hour>21</hour>
<hour>22</hour>
<hour>23</hour>
</skiphours>
<skipdays>
<day>Monday</day>
<day>Tuesday</day>
<day>Wednesday</day>
<day>Thursday</day>
<day>Friday</day>
<day>Saturday</day>
<day>Sunday</day>
</skipdays>
**/
/* /*
* @see TestCase#tearDown() * @see TestCase#tearDown()
*/ */
@Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
} }
} }

View file

@ -9,11 +9,12 @@
package org.rometools.unittest; package org.rometools.unittest;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl; import com.sun.syndication.feed.synd.SyndFeedImpl;
import java.io.FileOutputStream;
import java.io.PrintWriter;
/** /**
* *
@ -27,10 +28,11 @@ public class TestOpsOPML10 extends FeedOpsTest{
} }
// 1.6 // 1.6
@Override
public void testWireFeedSyndFeedConversion() throws Exception { public void testWireFeedSyndFeedConversion() throws Exception {
SyndFeed sFeed1 = getCachedSyndFeed(); final SyndFeed sFeed1 = getCachedSyndFeed();
WireFeed wFeed1 = sFeed1.createWireFeed(); final WireFeed wFeed1 = sFeed1.createWireFeed();
SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1")); PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1"));
w.println(sFeed1.toString()); w.println(sFeed1.toString());
w.close(); w.close();
@ -41,7 +43,4 @@ public class TestOpsOPML10 extends FeedOpsTest{
assertEquals(sFeed1, sFeed2); assertEquals(sFeed1, sFeed2);
} }
} }

View file

@ -9,14 +9,15 @@
package org.rometools.unittest; package org.rometools.unittest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl; import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.io.WireFeedInput; import com.sun.syndication.io.WireFeedInput;
import com.sun.syndication.io.WireFeedOutput; import com.sun.syndication.io.WireFeedOutput;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
/** /**
* *
@ -30,11 +31,11 @@ public class TestOpsOPML10links extends FeedOpsTest{
} }
// 1.6 // 1.6
@Override
public void testWireFeedSyndFeedConversion() throws Exception { public void testWireFeedSyndFeedConversion() throws Exception {
SyndFeed sFeed1 = getCachedSyndFeed(); final SyndFeed sFeed1 = getCachedSyndFeed();
WireFeed wFeed1 = sFeed1.createWireFeed(); final WireFeed wFeed1 = sFeed1.createWireFeed();
//System.out.println( wFeed1 ); final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1")); PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1"));
w.println(sFeed1.toString()); w.println(sFeed1.toString());
w.close(); w.close();
@ -45,21 +46,15 @@ public class TestOpsOPML10links extends FeedOpsTest{
assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed()); assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed());
} }
public void testTemp() throws Exception { public void testTemp() throws Exception {
WireFeedInput input = new WireFeedInput(); final WireFeedInput input = new WireFeedInput();
WireFeed wf = input.build( new File( System.getProperty("basedir")+ "/src/test/resources/opml_1.0_links.xml")); final WireFeed wf = input.build(new File(System.getProperty("basedir") + "/src/test/resources/opml_1.0_links.xml"));
WireFeedOutput output = new WireFeedOutput(); final WireFeedOutput output = new WireFeedOutput();
//System.out.println( wf );
//System.out.println( "================================="); final SyndFeedImpl sf = new SyndFeedImpl(wf);
//System.out.println( new SyndFeedImpl( wf) );
SyndFeedImpl sf = new SyndFeedImpl( wf);
sf.setFeedType("rss_2.0"); sf.setFeedType("rss_2.0");
sf.setDescription(""); sf.setDescription("");
sf.setLink("http://foo.com"); sf.setLink("http://foo.com");
//output.output( sf.createWireFeed() , new PrintWriter( System.out ) );
sf.setFeedType("opml_1.0"); 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"));
} }

View file

@ -9,11 +9,12 @@
package org.rometools.unittest; package org.rometools.unittest;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl; import com.sun.syndication.feed.synd.SyndFeedImpl;
import java.io.FileOutputStream;
import java.io.PrintWriter;
/** /**
* *
@ -26,11 +27,11 @@ public class TestOpsOPML20 extends FeedOpsTest {
super("opml_2.0"); super("opml_2.0");
} }
@Override
public void testWireFeedSyndFeedConversion() throws Exception { public void testWireFeedSyndFeedConversion() throws Exception {
SyndFeed sFeed1 = getCachedSyndFeed(); final SyndFeed sFeed1 = getCachedSyndFeed();
WireFeed wFeed1 = sFeed1.createWireFeed(); final WireFeed wFeed1 = sFeed1.createWireFeed();
SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/3")); PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/3"));
w.println(sFeed1.toString()); w.println(sFeed1.toString());
w.close(); w.close();

View file

@ -16,12 +16,20 @@
*/ */
package org.rometools.unittest; 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.XmlReader;
import com.sun.syndication.io.impl.XmlFixerReader; import com.sun.syndication.io.impl.XmlFixerReader;
import junit.framework.TestCase;
import org.jdom.input.SAXBuilder;
import java.io.*;
/** /**
* @author pat, tucu * @author pat, tucu
@ -85,50 +93,47 @@ public class TestXmlFixerReader extends TestCase {
} }
protected void _testXmlParse(String garbish,String xmlDoc) throws Exception { protected void _testXmlParse(final String garbish, final String xmlDoc) throws Exception {
InputStream is = getStream(garbish,xmlDoc); final InputStream is = getStream(garbish, xmlDoc);
Reader reader = new XmlReader(is); Reader reader = new XmlReader(is);
reader = new XmlFixerReader(reader); reader = new XmlFixerReader(reader);
SAXBuilder saxBuilder = new SAXBuilder(); final SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.build(reader); saxBuilder.build(reader);
} }
protected void _testValidTrim(String garbish,String xmlDoc) throws Exception { protected void _testValidTrim(final String garbish, final String xmlDoc) throws Exception {
_testXmlParse(garbish, xmlDoc); _testXmlParse(garbish, xmlDoc);
} }
protected void _testInvalidTrim(String garbish,String xmlDoc) throws Exception { protected void _testInvalidTrim(final String garbish, final String xmlDoc) throws Exception {
try { try {
_testXmlParse(garbish, xmlDoc); _testXmlParse(garbish, xmlDoc);
assertTrue(false); assertTrue(false);
} } catch (final Exception ex) {
catch (Exception ex) {
} }
} }
protected void _testValidEntities(String xmlDoc) throws Exception { protected void _testValidEntities(final String xmlDoc) throws Exception {
_testXmlParse("", xmlDoc); _testXmlParse("", xmlDoc);
} }
protected void _testInvalidEntities(String xmlDoc) throws Exception { protected void _testInvalidEntities(final String xmlDoc) throws Exception {
try { try {
_testXmlParse("", xmlDoc); _testXmlParse("", xmlDoc);
assertTrue(false); assertTrue(false);
} } catch (final Exception ex) {
catch (Exception ex) {
} }
} }
// XML Stream generator // XML Stream generator
protected InputStream getStream(String garbish,String xmlDoc) throws IOException { protected InputStream getStream(final String garbish, final String xmlDoc) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
Writer writer = new OutputStreamWriter(baos); final Writer writer = new OutputStreamWriter(baos);
writer.write(garbish); writer.write(garbish);
writer.write(xmlDoc); writer.write(xmlDoc);
writer.close(); writer.close();
return new ByteArrayInputStream(baos.toByteArray()); return new ByteArrayInputStream(baos.toByteArray());
} }
} }

View file

@ -16,28 +16,34 @@
*/ */
package org.rometools.unittest; package org.rometools.unittest;
import com.sun.syndication.io.XmlReader; import java.io.ByteArrayInputStream;
import junit.framework.TestCase; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.*; import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase;
import com.sun.syndication.io.XmlReader;
/** /**
* @author pat, tucu * @author pat, tucu
* *
*/ */
public class TestXmlReader extends TestCase { public class TestXmlReader extends TestCase {
public static void main(String[] args) throws Exception { public static void main(final String[] args) throws Exception {
TestXmlReader test = new TestXmlReader(); final TestXmlReader test = new TestXmlReader();
test.testRawBom(); test.testRawBom();
test.testRawNoBom(); test.testRawNoBom();
test.testHttp(); test.testHttp();
} }
protected void _testRawNoBomValid(String encoding) throws Exception { protected void _testRawNoBomValid(final String encoding) throws Exception {
InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); InputStream is = getXmlStream("no-bom", "xml", encoding, encoding);
XmlReader xmlReader = new XmlReader(is, false); XmlReader xmlReader = new XmlReader(is, false);
assertEquals(xmlReader.getEncoding(), "UTF-8"); assertEquals(xmlReader.getEncoding(), "UTF-8");
@ -51,13 +57,12 @@ public class TestXmlReader extends TestCase {
assertEquals(xmlReader.getEncoding(), encoding); assertEquals(xmlReader.getEncoding(), encoding);
} }
protected void _testRawNoBomInvalid(String encoding) throws Exception { protected void _testRawNoBomInvalid(final String encoding) throws Exception {
InputStream is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); final InputStream is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding);
try { try {
XmlReader xmlReader = new XmlReader(is,false); final XmlReader xmlReader = new XmlReader(is, false);
fail("It should have failed"); fail("It should have failed");
} } catch (final IOException ex) {
catch (IOException ex) {
assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1);
} }
} }
@ -68,24 +73,22 @@ public class TestXmlReader extends TestCase {
_testRawNoBomValid("ISO-8859-1"); _testRawNoBomValid("ISO-8859-1");
} }
protected void _testRawBomValid(String encoding) throws Exception { protected void _testRawBomValid(final String encoding) throws Exception {
InputStream is = getXmlStream(encoding+"-bom","xml-prolog-encoding",encoding,encoding); final InputStream is = getXmlStream(encoding + "-bom", "xml-prolog-encoding", encoding, encoding);
XmlReader xmlReader = new XmlReader(is,false); final XmlReader xmlReader = new XmlReader(is, false);
if (!encoding.equals("UTF-16")) { if (!encoding.equals("UTF-16")) {
assertEquals(xmlReader.getEncoding(), encoding); assertEquals(xmlReader.getEncoding(), encoding);
} } else {
else {
assertEquals(xmlReader.getEncoding().substring(0, encoding.length()), encoding); assertEquals(xmlReader.getEncoding().substring(0, encoding.length()), encoding);
} }
} }
protected void _testRawBomInvalid(String bomEnc,String streamEnc,String prologEnc) throws Exception { protected void _testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception {
InputStream is = getXmlStream(bomEnc,"xml-prolog-encoding",streamEnc,prologEnc); final InputStream is = getXmlStream(bomEnc, "xml-prolog-encoding", streamEnc, prologEnc);
try { try {
XmlReader xmlReader = new XmlReader(is,false); final XmlReader xmlReader = new XmlReader(is, false);
fail("It should have failed for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); fail("It should have failed for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc);
} } catch (final IOException ex) {
catch (IOException ex) {
assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1);
} }
} }
@ -158,31 +161,30 @@ public class TestXmlReader extends TestCase {
_testHttpLenient("text/html;charset=UTF-16BE", "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 { public void _testHttpValid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception {
InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml":"xml-prolog-encoding",streamEnc,prologEnc); final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml" : "xml-prolog-encoding", streamEnc, prologEnc);
XmlReader xmlReader = new XmlReader(is,cT,false); final XmlReader xmlReader = new XmlReader(is, cT, false);
if (!streamEnc.equals("UTF-16")) { 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 // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection
} } else {
else {
assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc);
} }
} }
protected void _testHttpInvalid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { protected void _testHttpInvalid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception {
InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml-prolog" : "xml-prolog-encoding", streamEnc, prologEnc);
try { try {
XmlReader xmlReader = new XmlReader(is,cT,false); 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); fail("It should have failed for HTTP Content-type " + cT + ", BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc);
} } catch (final IOException ex) {
catch (IOException ex) {
assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1);
} }
} }
protected void _testHttpLenient(String cT, String bomEnc, String streamEnc, String prologEnc, String shouldbe) throws Exception { protected void _testHttpLenient(final String cT, final String bomEnc, final String streamEnc, final String prologEnc, final String shouldbe)
InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); throws Exception {
XmlReader xmlReader = new XmlReader(is,cT,true); 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); assertEquals(xmlReader.getEncoding(), shouldbe);
} }
@ -203,15 +205,11 @@ public class TestXmlReader extends TestCase {
BOMs.put("UTF-8-bom", UTF_8_BOM_BYTES); BOMs.put("UTF-8-bom", UTF_8_BOM_BYTES);
} }
private static final MessageFormat XML = new MessageFormat( private static final MessageFormat XML = new MessageFormat("<root>{2}</root>");
"<root>{2}</root>"); private static final MessageFormat XML_WITH_PROLOG = new MessageFormat("<?xml version=\"1.0\"?>\n<root>{2}</root>");
private static final MessageFormat XML_WITH_PROLOG = new MessageFormat( private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat("<?xml version=\"1.0\" encoding=\"{1}\"?>\n<root>{2}</root>");
"<?xml version=\"1.0\"?>\n<root>{2}</root>");
private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat(
"<?xml version=\"1.0\" encoding=\"{1}\"?>\n<root>{2}</root>");
private static final MessageFormat INFO = new MessageFormat( private static final MessageFormat INFO = new MessageFormat("\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n");
"\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n");
private static final Map XMLs = new HashMap(); private static final Map XMLs = new HashMap();
@ -227,19 +225,19 @@ public class TestXmlReader extends TestCase {
* @param xmlType xml, xml-prolog, xml-prolog-charset * @param xmlType xml, xml-prolog, xml-prolog-charset
* @return XML stream * @return XML stream
*/ */
protected InputStream getXmlStream(String bomType,String xmlType,String streamEnc,String prologEnc) throws IOException { protected InputStream getXmlStream(final String bomType, final String xmlType, final String streamEnc, final String prologEnc) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
int[] bom = (int[]) BOMs.get(bomType); int[] bom = (int[]) BOMs.get(bomType);
if (bom == null) { if (bom == null) {
bom = new int[0]; bom = new int[0];
} }
MessageFormat xml = (MessageFormat) XMLs.get(xmlType); final MessageFormat xml = (MessageFormat) XMLs.get(xmlType);
for (int i=0;i<bom.length;i++) { for (final int element : bom) {
baos.write(bom[i]); baos.write(element);
} }
Writer writer = new OutputStreamWriter(baos,streamEnc); final Writer writer = new OutputStreamWriter(baos, streamEnc);
String info = INFO.format(new Object[]{bomType,xmlType,prologEnc}); final String info = INFO.format(new Object[] { bomType, xmlType, prologEnc });
String xmlDoc = xml.format(new Object[]{streamEnc,prologEnc,info}); final String xmlDoc = xml.format(new Object[] { streamEnc, prologEnc, info });
writer.write(xmlDoc); writer.write(xmlDoc);
// PADDDING TO TEST THINGS WORK BEYOND PUSHBACK_SIZE // PADDDING TO TEST THINGS WORK BEYOND PUSHBACK_SIZE
@ -253,5 +251,4 @@ public class TestXmlReader extends TestCase {
return new ByteArrayInputStream(baos.toByteArray()); return new ByteArrayInputStream(baos.toByteArray());
} }
} }