From d551c6e5acb91027ed8e4151aefb773c312a7299 Mon Sep 17 00:00:00 2001 From: kebernet Date: Tue, 1 Mar 2011 19:15:21 +0000 Subject: [PATCH 02/47] Initial checkin to JIRA --- pom.xml | 24 ++ .../sun/syndication/feed/opml/Attribute.java | 107 +++++ .../com/sun/syndication/feed/opml/Opml.java | 280 +++++++++++++ .../sun/syndication/feed/opml/Outline.java | 343 ++++++++++++++++ .../sun/syndication/feed/opml/package.html | 47 +++ .../feed/synd/impl/ConverterForOPML10.java | 374 ++++++++++++++++++ .../feed/synd/impl/ConverterForOPML20.java | 64 +++ .../feed/synd/impl/TreeCategoryImpl.java | 34 ++ .../syndication/feed/synd/impl/package.html | 30 ++ .../syndication/io/impl/OPML10Generator.java | 187 +++++++++ .../sun/syndication/io/impl/OPML10Parser.java | 261 ++++++++++++ .../syndication/io/impl/OPML20Generator.java | 82 ++++ .../sun/syndication/io/impl/OPML20Parser.java | 116 ++++++ .../com/sun/syndication/io/impl/package.html | 28 ++ src/main/resources/rome.properties | 22 ++ .../sun/syndication/unittest/FeedOpsTest.java | 114 ++++++ .../sun/syndication/unittest/FeedTest.java | 78 ++++ .../syndication/unittest/SyndFeedTest.java | 267 +++++++++++++ .../syndication/unittest/TestOpsOPML10.java | 47 +++ .../unittest/TestOpsOPML10links.java | 67 ++++ .../syndication/unittest/TestOpsOPML20.java | 43 ++ .../unittest/TestXmlFixerReader.java | 134 +++++++ .../syndication/unittest/TestXmlReader.java | 257 ++++++++++++ src/test/resources/opml_1.0.xml | 29 ++ src/test/resources/opml_1.0_links.xml | 76 ++++ src/test/resources/opml_2.0.xml | 30 ++ 26 files changed, 3141 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/sun/syndication/feed/opml/Attribute.java create mode 100644 src/main/java/com/sun/syndication/feed/opml/Opml.java create mode 100644 src/main/java/com/sun/syndication/feed/opml/Outline.java create mode 100644 src/main/java/com/sun/syndication/feed/opml/package.html create mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java create mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java create mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java create mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/package.html create mode 100644 src/main/java/com/sun/syndication/io/impl/OPML10Generator.java create mode 100644 src/main/java/com/sun/syndication/io/impl/OPML10Parser.java create mode 100644 src/main/java/com/sun/syndication/io/impl/OPML20Generator.java create mode 100644 src/main/java/com/sun/syndication/io/impl/OPML20Parser.java create mode 100644 src/main/java/com/sun/syndication/io/impl/package.html create mode 100644 src/main/resources/rome.properties create mode 100644 src/test/java/com/sun/syndication/unittest/FeedOpsTest.java create mode 100644 src/test/java/com/sun/syndication/unittest/FeedTest.java create mode 100644 src/test/java/com/sun/syndication/unittest/SyndFeedTest.java create mode 100644 src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java create mode 100644 src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java create mode 100644 src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java create mode 100644 src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java create mode 100644 src/test/java/com/sun/syndication/unittest/TestXmlReader.java create mode 100644 src/test/resources/opml_1.0.xml create mode 100644 src/test/resources/opml_1.0_links.xml create mode 100644 src/test/resources/opml_2.0.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ac83b1d --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + org.rometools.opml + opml + jar + 1.0-SNAPSHOT + rome-opml + http://rometools.jira.com + + + junit + junit + 3.8.1 + test + + + rome + rome + 1.0 + + + diff --git a/src/main/java/com/sun/syndication/feed/opml/Attribute.java b/src/main/java/com/sun/syndication/feed/opml/Attribute.java new file mode 100644 index 0000000..db0db43 --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/opml/Attribute.java @@ -0,0 +1,107 @@ +/* + * Attribute.java + * + * Created on April 24, 2006, 11:11 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.syndication.feed.opml; + +import com.sun.syndication.feed.impl.EqualsBean; +import com.sun.syndication.feed.impl.ToStringBean; + +import java.io.Serializable; + + +/** + * This is a simple name-value pair attribute for outlines. + * + * @author Robert "kebernet" Cooper + */ +public class Attribute implements Cloneable, Serializable { + private String _name; + private String _value; + + /** Creates a new instance of Attribute */ + public Attribute() { + super(); + } + + /** + * Creates a new instance of Attribute. + * @param name name of the attribute. + * @param value value of the attribute. + */ + public Attribute(String name, String value) { + if ((name == null) || (value == null)) { + throw new NullPointerException("Name and value are required."); + } + + this.setName(name); + this.setValue(value); + } + + /** + * name of the attribute. + * @param name name of the attribute. + */ + public void setName(String name) { + this._name = name; + } + + /** + * name of the attribute. + * @return name of the attribute. + */ + public String getName() { + return _name; + } + + /** + * value of the attribute. + * @param value value of the attribute. + */ + public void setValue(String value) { + this._value = value; + } + + /** + * value of the attribute. + * @return value of the attribute. + */ + public String getValue() { + return _value; + } + + public Object clone() { + return new Attribute(this._name, this._value); + } + + public boolean equals(Object obj) { + EqualsBean eBean = new EqualsBean(Attribute.class, this); + + return eBean.beanEquals(obj); + } + + public int hashCode() { + EqualsBean equals = new EqualsBean(Attribute.class, this); + + return equals.beanHashCode(); + } + + public String toString() { + ToStringBean tsBean = new ToStringBean(Attribute.class, this); + + return tsBean.toString(); + } +} diff --git a/src/main/java/com/sun/syndication/feed/opml/Opml.java b/src/main/java/com/sun/syndication/feed/opml/Opml.java new file mode 100644 index 0000000..189c249 --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/opml/Opml.java @@ -0,0 +1,280 @@ +/* + * Opml.java + * + * Created on April 24, 2006, 11:00 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.syndication.feed.opml; + +import com.sun.syndication.feed.WireFeed; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +/** + * This class represents the root of an OPML 1/2 feed and contains the elements that + * may appear in the <head> tag of the feed. + * @author Robert "kebernet" Cooper + */ +public class Opml extends WireFeed { + private Date _created; + private Date _modified; + private Integer _verticalScrollState; + private Integer _windowBottom; + private Integer _windowLeft; + private Integer _windowRight; + private Integer _windowTop; + private List _outlines; + private String _docs; + private String _ownerEmail; + private String _ownerId; + private String _ownerName; + private String _title; + private int[] _expansionState; + + /** Creates a new instance of Opml */ + public Opml() { + super(); + } + + /** + * is a date-time, indicating when the document was created. + * @param created date-time, indicating when the document was created. + */ + public void setCreated(Date created) { + this._created = created; + } + + /** + * <dateCreated> is a date-time, indicating when the document was created. + * @return date-time, indicating when the document was created. + */ + public Date getCreated() { + return _created; + } + + /** + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * @param docs http address of documentation for the format used + */ + public void setDocs(String docs) { + this._docs = docs; + } + + /** + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * @return http address of documentation for the format used + */ + public String getDocs() { + return _docs; + } + + /** + * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * @param expansionState int array containing expanded elements. + */ + public void setExpansionState(int[] expansionState) { + this._expansionState = expansionState; + } + + /** + * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * @return int array containing expanded elements. + */ + public int[] getExpansionState() { + return _expansionState; + } + + /** + * <dateModified> is a date-time, indicating when the document was last modified. + * @param modified date-time, indicating when the document was last modified. + */ + public void setModified(Date modified) { + this._modified = modified; + } + + /** + * <dateModified> is a date-time, indicating when the document was last modified. + * @return date-time, indicating when the document was last modified. + */ + public Date getModified() { + return _modified; + } + + /** + * Root level Outline object that should appear in the <body> + * @param outlines Root level Outline object that should appear in the <body> + */ + public void setOutlines(List outlines) { + this._outlines = outlines; + } + + /** + * Root level Outline object that should appear in the <body> + * @return Root level Outline object that should appear in the <body> + */ + public List getOutlines() { + if (_outlines == null) { + _outlines = new ArrayList(); + } + + return _outlines; + } + + /** + * <ownerEmail> is a string, the email address of the owner of the document. + * @param ownerEmail the email address of the owner of the document. + */ + public void setOwnerEmail(String ownerEmail) { + this._ownerEmail = ownerEmail; + } + + /** + * <ownerEmail> is a string, the email address of the owner of the document. + * @return the email address of the owner of the document. + */ + public String getOwnerEmail() { + return _ownerEmail; + } + + /** + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + */ + public void setOwnerId(String ownerId) { + this._ownerId = ownerId; + } + + /** + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + * @return http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + */ + public String getOwnerId() { + return _ownerId; + } + + /** + * <ownerName> is a string, the owner of the document. + * @param ownerName the owner of the document. + */ + public void setOwnerName(String ownerName) { + this._ownerName = ownerName; + } + + /** + * <ownerName> is a string, the owner of the document. + * @return the owner of the document. + */ + public String getOwnerName() { + return _ownerName; + } + + /** + * <title> is the title of the document. + * @param title title of the document. + */ + public void setTitle(String title) { + this._title = title; + } + + /** + * <title> is the title of the document. + * @return title of the document. + */ + public String getTitle() { + return _title; + } + + /** + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + * @param verticalScrollState which line of the outline is displayed on the top line of the window. + */ + public void setVerticalScrollState(Integer verticalScrollState) { + this._verticalScrollState = verticalScrollState; + } + + /** + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + * @return which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + */ + public Integer getVerticalScrollState() { + return _verticalScrollState; + } + + /** + * <windowBottom> is a number, the pixel location of the bottom edge of the window. + * @param windowBottom the pixel location of the bottom edge of the window. + */ + public void setWindowBottom(Integer windowBottom) { + this._windowBottom = windowBottom; + } + + /** + * <windowBottom> is a number, the pixel location of the bottom edge of the window. + * @return the pixel location of the bottom edge of the window. + */ + public Integer getWindowBottom() { + return _windowBottom; + } + + /** + * <windowLeft> is a number, the pixel location of the left edge of the window. + * @param windowLeft the pixel location of the left edge of the window. + */ + public void setWindowLeft(Integer windowLeft) { + this._windowLeft = windowLeft; + } + + /** + * <windowLeft> is a number, the pixel location of the left edge of the window. + * @return the pixel location of the left edge of the window. + */ + public Integer getWindowLeft() { + return _windowLeft; + } + + /** + * <windowRight> is a number, the pixel location of the right edge of the window. + * @param windowRight the pixel location of the right edge of the window. + */ + public void setWindowRight(Integer windowRight) { + this._windowRight = windowRight; + } + + /** + * <windowRight> is a number, the pixel location of the right edge of the window. + * @return the pixel location of the right edge of the window. + */ + public Integer getWindowRight() { + return _windowRight; + } + + /** + * <windowTop> is a number, the pixel location of the top edge of the window. + * @param windowTop the pixel location of the top edge of the window. + */ + public void setWindowTop(Integer windowTop) { + this._windowTop = windowTop; + } + + /** + * <windowTop> is a number, the pixel location of the top edge of the window. + * @return the pixel location of the top edge of the window. + */ + public Integer getWindowTop() { + return _windowTop; + } +} diff --git a/src/main/java/com/sun/syndication/feed/opml/Outline.java b/src/main/java/com/sun/syndication/feed/opml/Outline.java new file mode 100644 index 0000000..df68f33 --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/opml/Outline.java @@ -0,0 +1,343 @@ +/* + * Outline.java + * + * Created on April 24, 2006, 11:04 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.syndication.feed.opml; + +import com.sun.syndication.feed.impl.EqualsBean; +import com.sun.syndication.feed.impl.ToStringBean; + +import java.io.Serializable; + +import java.net.URL; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + + +/** + * This class represents an OPML outline element. + * @author Robert "kebernet" Cooper + */ +public class Outline implements Cloneable, Serializable { + private Date _created; + private List _attributes; + private List _categories; + private List _children; + private List _modules; + private String _text; + private String _title; + private String _type; + private boolean _breakpoint; + private boolean _comment; + + /** Creates a new instance of Outline */ + public Outline() { + super(); + } + + /** + * Creates a new outline with the specified type and text values. + * @param type type attribute value/ + * @param text text attribute value + */ + public Outline(String type, String text) { + super(); + this.setType(type); + this.setText(text); + } + + /** + * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally + * used for aggregator feed lists and will get a type of "rss". + * @param title Title of the entry. + * @param xmlUrl link to XML file. + * @param htmlUrl link to html page. + */ + public Outline(String title, URL xmlUrl, URL htmlUrl) { + super(); + this.setType("rss"); + this.setTitle(title); + this.setAttributes(new ArrayList()); + + if (xmlUrl != null) { + getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); + } + + if (htmlUrl != null) { + getAttributes().add(new Attribute("htmlUrl", htmlUrl.toString())); + } + } + + /** + * List of attributes on this outline excluding the "common types" for the specification. + * @param attributes List of attributes on this outline. + */ + public void setAttributes(List attributes) { + this._attributes = attributes; + } + + /** + * List of attributes on this outline excluding the "common types" for the specification. + * @return List of attributes on this outline. + */ + public List getAttributes() { + if (this._attributes == null) { + this._attributes = new ArrayList(); + } + + return _attributes; + } + + /** + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + * @param breakpoint whether a breakpoint is set on this outline. + */ + public void setBreakpoint(boolean breakpoint) { + this._breakpoint = breakpoint; + } + + /** + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + * @return whether a breakpoint is set on this outline + */ + public boolean isBreakpoint() { + return _breakpoint; + } + + /** + * (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) { + this._categories = categories; + } + + /** + * (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() { + if (_categories == null) { + _categories = new ArrayList(); + } + + return _categories; + } + + /** + * A list of sub-outlines for this entry. + * @param children A list of sub-outlines for this entry. + */ + public void setChildren(List children) { + this._children = children; + } + + /** + * A list of sub-outlines for this entry. + * @return A list of sub-outlines for this entry. + */ + public List getChildren() { + if (_children == null) { + _children = new ArrayList(); + } + + return _children; + } + + /** + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. + * @param comment whether the outline is commented + */ + public void setComment(boolean comment) { + this._comment = comment; + } + + /** + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. + * @return whether the outline is commented + */ + public boolean isComment() { + return _comment; + } + + /** + * (OPML 2) created is the date-time that the outline node was created. + * @param created date-time that the outline node was created. + */ + public void setCreated(Date created) { + this._created = created; + } + + /** + * (OPML 2) created is the date-time that the outline node was created. + * @return date-time that the outline node was created. + */ + public Date getCreated() { + return _created; + } + + /** + * A convenience method to return the value of the url attribute. + * @return value of the htmlUrl attribute. + */ + public String getUrl() { + return getAttributeValue("url"); + } + + /** + * A convenience method to return the value of the htmlUrl attribute. + * @return value of the htmlUrl attribute. + */ + public String getHtmlUrl() { + return getAttributeValue("htmlUrl"); + } + + public void setModules(List modules) { + this._modules = modules; + } + + public List getModules() { + if (this._modules == null) { + this._modules = new ArrayList(); + } + + return _modules; + } + + /** + * The "text" attribute of the outline. + * @param text The "text" attribute of the outline. + */ + public void setText(String text) { + this._text = text; + } + + /** + * The "text" attribute of the outline. + * @return The "text" attribute of the outline. + */ + public String getText() { + return _text; + } + + /** + * The "title" attribute of the outline. + * @param title The "title" attribute of the outline. + */ + public void setTitle(String title) { + this._title = title; + } + + /** + * The "title" attribute of the outline. + * @return The "title" attribute of the outline. + */ + public String getTitle() { + return _title; + } + + /** + * The "type" attribute of the outline. + * @param type The "type" attribute of the outline. + */ + public void setType(String type) { + this._type = type; + } + + /** + * The "type" attribute of the outline. + * @return The "type" attribute of the outline. + */ + public String getType() { + return _type; + } + + /** + * A convenience method to return the value of the xmlUrl attribute. + * @return value of the xmlUrl attribute. + */ + public String getXmlUrl() { + return getAttributeValue("xmlUrl"); + } + + /** Returns the value of an attribute on the outline or null. + * @param name name of the attribute. + */ + public String getAttributeValue(String name ){ + List attributes = Collections.synchronizedList(this.getAttributes()); + + for (int i = 0; i < attributes.size(); i++) { + Attribute a = (Attribute) attributes.get(i); + + if ((a.getName() != null) && a.getName().equals(name)) { + return a.getValue(); + } + } + + return null; + } + + public Object clone() { + Outline o = new Outline(); + o.setBreakpoint(this.isBreakpoint()); + o.setCategories(new ArrayList(this.getCategories())); + o.setComment(this.isComment()); + o.setCreated((this._created != null) ? (Date) this._created.clone() : null); + o.setModules(new ArrayList(this.getModules())); + o.setText(this.getText()); + o.setTitle(this.getTitle()); + o.setType(this.getType()); + + ArrayList children = new ArrayList(); + + for (int i = 0; i < this.getChildren().size(); i++) { + children.add(((Outline) this._children.get(i)).clone()); + } + + o.setChildren(children); + + ArrayList attributes = new ArrayList(); + + for (int i = 0; i < this.getAttributes().size(); i++) { + attributes.add(((Attribute) this._attributes.get(i)).clone()); + } + + o.setAttributes(attributes); + + return o; + } + + public boolean equals(Object obj) { + EqualsBean eBean = new EqualsBean(Outline.class, this); + + return eBean.beanEquals(obj); + } + + public int hashCode() { + EqualsBean equals = new EqualsBean(Outline.class, this); + + return equals.beanHashCode(); + } + + public String toString() { + ToStringBean tsBean = new ToStringBean(Outline.class, this); + + return tsBean.toString(); + } +} diff --git a/src/main/java/com/sun/syndication/feed/opml/package.html b/src/main/java/com/sun/syndication/feed/opml/package.html new file mode 100644 index 0000000..3e0dfed --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/opml/package.html @@ -0,0 +1,47 @@ + + + + + + + + This package represents the base objects for OPML support for ROME. +

+ There are three classes here that are relevant. Opml, + which represents the root document and head information, + Outline which represents a single node on an Opml + outline tree, and provides convenience methods for commonly used + attributes such as xmlUrl. Finally, the + Attribute class, which represents a specific attribute + on an Outline object. Since OPML supports free-form attribute + assignments, this is a very multi-purpose class. +

+

Sample Usage: + To use this parser, simply include the jar file in your classpath + as you are using ROME. Be sure it exists at the same level as ROME, + such that, if ROME is in the common classpath of an application server, + don't include this jar in your webapps WEB-INF/lib. +

+  WireFeedInput input = new WireFeedInput();
+  Opml feed = (Opml) input.build( new File("myOpml.xml") );
+  List<Outline> outlines = (List<Outline>) feed.getOutlines();
+        
+

+ + +
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+    
+ + diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java new file mode 100644 index 0000000..3554ea3 --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -0,0 +1,374 @@ +/* + * ConverterForOPML10.java + * + * Created on April 25, 2006, 1:26 AM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.syndication.feed.synd.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Stack; +import java.util.logging.Logger; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; +import com.sun.syndication.feed.synd.Converter; +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndCategoryImpl; +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.feed.synd.SyndLinkImpl; +import com.sun.syndication.feed.synd.SyndPerson; +import com.sun.syndication.feed.synd.SyndPersonImpl; + + +/** + * + * @author cooper + */ +public class ConverterForOPML10 implements Converter { + private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName() + .toString()); + public static final String URI_TREE = "urn:rome.tree"; + public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; + + /** Creates a new instance of ConverterForOPML10 */ + public ConverterForOPML10() { + super(); + } + + protected void addOwner(Opml opml, SyndFeed syndFeed) { + if((opml.getOwnerEmail() != null) || (opml.getOwnerName() != null)) { + List authors = new ArrayList(); + SyndPerson person = new SyndPersonImpl(); + person.setEmail(opml.getOwnerEmail()); + person.setName(opml.getOwnerName()); + authors.add(person); + syndFeed.setAuthors(authors); + } + } + + /** + * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. + *

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

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

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

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

+ */ + public String getType() { + return "opml_1.0"; + } + + private static class OutlineHolder { + Outline outline; + String parent; + + public OutlineHolder(Outline outline, String parent) { + this.outline = outline; + this.parent = parent; + } + } + + private static class TreeContext extends Stack { + TreeContext() { + super(); + } + } +} diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java new file mode 100644 index 0000000..cd03b39 --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java @@ -0,0 +1,64 @@ +/* + * ConverterForOPML20.java + * + * Created on April 25, 2006, 5:29 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ +package com.sun.syndication.feed.synd.impl; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; + + +/** + * + * @author cooper + */ +public class ConverterForOPML20 extends ConverterForOPML10 { + /** Creates a new instance of ConverterForOPML20 */ + public ConverterForOPML20() { + super(); + } + + /** + * Returns the type (version) of the real feed this converter handles. + *

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

+ */ + public String getType() { + return "opml_2.0"; + } + + /** + * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. + *

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

+ * + * @param feed real feed to copy/convert. + * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. + */ + public void copyInto(WireFeed feed, SyndFeed syndFeed) { + super.copyInto(feed, syndFeed); + } + + /** + * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. + *

+ * + * @param syndFeed SyndFeedImpl to copy/convert value from. + * @return a real feed with copied/converted values of the SyndFeedImpl. + */ + public WireFeed createRealFeed(SyndFeed syndFeed) { + WireFeed retValue; + + retValue = super.createRealFeed(syndFeed); + + return retValue; + } +} diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java new file mode 100644 index 0000000..110147a --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java @@ -0,0 +1,34 @@ +/* + * TreeCategoryImpl.java + * + * Created on April 27, 2006, 3:44 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.sun.syndication.feed.synd.impl; + +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndCategoryImpl; + +/** + * + * @author cooper + */ +public class TreeCategoryImpl extends SyndCategoryImpl { + + /** Creates a new instance of TreeCategoryImpl */ + public TreeCategoryImpl() { + super(); + } + + public boolean equals(Object o) { + SyndCategory c = (SyndCategory) o; + if( c.getTaxonomyUri() != null && c.getTaxonomyUri().equals( this.getTaxonomyUri() ) ) + return true; + else + return false; + } + +} diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/package.html b/src/main/java/com/sun/syndication/feed/synd/impl/package.html new file mode 100644 index 0000000..40f63ad --- /dev/null +++ b/src/main/java/com/sun/syndication/feed/synd/impl/package.html @@ -0,0 +1,30 @@ + + + + + + + + + This packages contains the SyndFeed converters for the + OPML module. For information on how Opml gets turned into + other feed types through the Synd structures, see the OPML + Subproject page on the ROME wiki. + +

+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+    
+ + + diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java new file mode 100644 index 0000000..7917ab8 --- /dev/null +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java @@ -0,0 +1,187 @@ +/* + * Opml10Generator.java + * + * Created on April 24, 2006, 11:35 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.syndication.io.impl; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.WireFeedGenerator; + +import org.jdom.Document; +import org.jdom.Element; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +/** + * + * @author Robert "kebernet" Cooper + */ +public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { + /** Creates a new instance of Opml10Generator */ + public OPML10Generator() { + super("opml_1.0"); + } + + public OPML10Generator(String type) { + super(type); + } + + /** + * Creates an XML document (JDOM) for the given feed bean. + *

+ * + * @param feed the feed bean to generate the XML document from. + * @return the generated XML document (JDOM). + * @throws IllegalArgumentException thrown if the type of the given feed bean does not + * match with the type of the WireFeedGenerator. + * @throws FeedException thrown if the XML Document could not be created. + */ + public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { + if (!(feed instanceof Opml)) { + throw new IllegalArgumentException("Not an OPML file"); + } + + Opml opml = (Opml) feed; + Document doc = new Document(); + Element root = new Element("opml"); + doc.addContent(root); + + Element head = generateHead(opml); + + if (head != null) { + root.addContent(head); + } + + Element body = new Element("body"); + root.addContent(body); + super.generateFeedModules(opml.getModules(), root); + body.addContent(generateOutlines(opml.getOutlines())); + + return doc; + } + + protected boolean addNotNullAttribute(Element target, String name, Object value) { + if ((target == null) || (name == null) || (value == null)) { + return false; + } + + target.setAttribute(name, value.toString()); + + return true; + } + + protected boolean addNotNullSimpleElement(Element target, String name, Object value) { + if ((target == null) || (name == null) || (value == null)) { + return false; + } + + Element e = new Element(name); + e.addContent(value.toString()); + target.addContent(e); + + return true; + } + + protected Element generateHead(Opml opml) { + Element head = new Element("head"); + boolean hasHead = false; + + if (opml.getCreated() != null) { + hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated())); + } + + hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); + + if (opml.getModified() != null) { + hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified())); + } + + hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); + hasHead = addNotNullSimpleElement(head, "ownerName", opml.getOwnerName()); + hasHead = addNotNullSimpleElement(head, "title", opml.getTitle()); + hasHead = addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState()); + hasHead = addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom()); + hasHead = addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft()); + hasHead = addNotNullSimpleElement(head, "windowRight", opml.getWindowRight()); + hasHead = addNotNullSimpleElement(head, "windowTop", opml.getWindowTop()); + + if (hasHead) { + return head; + } else { + return null; + } + } + + protected Element generateOutline(Outline outline) { + Element e = new Element("outline"); + addNotNullAttribute(e, "text", outline.getText()); + addNotNullAttribute(e, "type", outline.getType()); + addNotNullAttribute(e, "title", outline.getTitle()); + + if (outline.isBreakpoint()) { + addNotNullAttribute(e, "isBreakpoint", "true"); + } + + if (outline.isComment()) { + addNotNullAttribute(e, "isComment", "true"); + } + + List atts = Collections.synchronizedList(outline.getAttributes()); + + for (int i = 0; i < atts.size(); i++) { + Attribute att = (Attribute) atts.get(i); + addNotNullAttribute(e, att.getName(), att.getValue()); + } + + super.generateItemModules(outline.getModules(), e); + e.addContent(generateOutlines(outline.getChildren())); + + return e; + } + + protected List generateOutlines(List outlines) { + ArrayList elements = new ArrayList(); + + for (int i = 0; (outlines != null) && (i < outlines.size()); i++) { + elements.add(generateOutline((Outline) outlines.get(i))); + } + + return elements; + } + + protected String intArrayToCsvString(int[] value) { + if ((value == null) || (value.length == 0)) { + return null; + } + + StringBuffer sb = new StringBuffer(); + sb.append(value[0]); + + for (int i = 1; i < value.length; i++) { + sb.append(","); + sb.append(value[i]); + } + + return sb.toString(); + } +} diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java new file mode 100644 index 0000000..f8bab46 --- /dev/null +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java @@ -0,0 +1,261 @@ +/* + * Opml10Parser.java + * + * Created on April 24, 2006, 11:34 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.syndication.io.impl; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.WireFeedParser; + +import org.jdom.Document; +import org.jdom.Element; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * + * @author Robert "kebernet" Cooper + */ +public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { + private static Logger LOG = Logger.getLogger(OPML10Parser.class.getName()); + + /** Creates a new instance of Opml10Parser */ + public OPML10Parser() { + super("opml_1.0", null); + } + + public OPML10Parser(String type) { + super(type, null); + } + + /** + * Inspects an XML Document (JDOM) to check if it can parse it. + *

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

+ * + * @param document XML Document (JDOM) to check if it can be parsed by this parser. + * @return true if the parser know how to parser this feed, false otherwise. + */ + public boolean isMyType(Document document) { + Element e = document.getRootElement(); + + if (e.getName().equals("opml") + && ( e.getChild("head") == null || e.getChild("head").getChild("docs") == null) + && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { + return true; + } + + return false; + } + + /** + * Parses an XML document (JDOM Document) into a feed bean. + *

+ * + * @param document XML document (JDOM) to parse. + * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). + * @return the resulting feed bean. + * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. + * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). + */ + public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { + Opml opml = new Opml(); + opml.setFeedType("opml_1.0"); + + Element root = document.getRootElement(); + Element head = root.getChild("head"); + + if (head != null) { + opml.setTitle(head.getChildText("title")); + + if (head.getChildText("dateCreated") != null) { + opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"))); + } + + if (head.getChildText("dateModified") != null) { + opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"))); + } + + opml.setOwnerName(head.getChildTextTrim("ownerName")); + opml.setOwnerEmail(head.getChildTextTrim("ownerEmail")); + opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState"))); + } + + try { + opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowBottom", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowBottom", nfe); + } + } + + try { + opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); + } + + try { + opml.setWindowRight(readInteger(head.getChildText("windowRight"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowRight", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowRight", nfe); + } + } + + try { + opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowLeft", nfe); + } + } + + try { + opml.setWindowTop(readInteger(head.getChildText("windowTop"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowTop", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowTop", nfe); + } + } + + try { + opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse expansionState", nfe); + + if (validate) { + throw new FeedException("Unable to parse expansionState", nfe); + } + } + + opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate)); + opml.setModules(this.parseFeedModules(root)); + + return opml; + } + + protected Outline parseOutline(Element e, boolean validate) throws FeedException { + if (!e.getName().equals("outline")) { + throw new RuntimeException("Not an outline element."); + } + + Outline outline = new Outline(); + outline.setText(e.getAttributeValue("text")); + outline.setType(e.getAttributeValue("type")); + outline.setTitle(e.getAttributeValue("title")); + + List jAttributes = e.getAttributes(); + ArrayList attributes = new ArrayList(); + + for (int i = 0; i < jAttributes.size(); i++) { + org.jdom.Attribute a = (org.jdom.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")) { + attributes.add(new Attribute(a.getName(), a.getValue())); + } + } + + outline.setAttributes(attributes); + + try { + outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); + } catch (Exception ex) { + LOG.log(Level.WARNING, "Unable to parse isBreakpoint value", ex); + + if (validate) { + throw new FeedException("Unable to parse isBreakpoint value", ex); + } + } + + try { + outline.setComment(readBoolean(e.getAttributeValue("isComment"))); + } catch (Exception ex) { + LOG.log(Level.WARNING, "Unable to parse isComment value", ex); + + if (validate) { + throw new FeedException("Unable to parse isComment value", ex); + } + } + + List children = e.getChildren("outline"); + outline.setModules(this.parseItemModules(e)); + outline.setChildren(parseOutlines(children, validate)); + + return outline; + } + + protected List parseOutlines(List elements, boolean validate) throws FeedException { + ArrayList results = new ArrayList(); + + for (int i = 0; i < elements.size(); i++) { + results.add(parseOutline((Element) elements.get(i), validate)); + } + + return results; + } + + protected boolean readBoolean(String value) { + if (value == null) { + return false; + } else { + return Boolean.getBoolean(value.trim()); + } + } + + protected int[] readIntArray(String value) { + if (value == null) { + return null; + } else { + StringTokenizer tok = new StringTokenizer(value, ","); + int[] result = new int[tok.countTokens()]; + int count = 0; + + while (tok.hasMoreElements()) { + result[count] = Integer.parseInt(tok.nextToken().trim()); + count++; + } + + return result; + } + } + + protected Integer readInteger(String value) { + if (value != null) { + return new Integer(value); + } else { + return null; + } + } +} diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java new file mode 100644 index 0000000..69661c0 --- /dev/null +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java @@ -0,0 +1,82 @@ +/* + * OPML20Generator.java + * + * Created on April 25, 2006, 5:31 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ +package com.sun.syndication.io.impl; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; +import com.sun.syndication.io.FeedException; + +import org.jdom.Document; +import org.jdom.Element; + + +/** + * + * @author cooper + */ +public class OPML20Generator extends OPML10Generator { + /** Creates a new instance of OPML20Generator */ + public OPML20Generator() { + } + + /** + * Returns the type of feed the generator creates. + *

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

+ */ + public String getType() { + return "opml_2.0"; + } + + /** + * Creates an XML document (JDOM) for the given feed bean. + *

+ * + * @param feed the feed bean to generate the XML document from. + * @return the generated XML document (JDOM). + * @throws IllegalArgumentException thrown if the type of the given feed bean does not + * match with the type of the WireFeedGenerator. + * @throws FeedException thrown if the XML Document could not be created. + */ + public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { + Document retValue; + + retValue = super.generate(feed); + retValue.getRootElement().setAttribute("version", "2.0"); + + return retValue; + } + + protected Element generateHead(Opml opml) { + Element retValue; + + retValue = super.generateHead(opml); + + Element docs = new Element("docs", opml.getDocs()); + retValue.addContent(docs); + + return retValue; + } + + protected Element generateOutline(Outline outline) { + Element retValue; + + retValue = super.generateOutline(outline); + + if (outline.getCreated() != null) { + retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated())); + } + + return retValue; + } +} diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java new file mode 100644 index 0000000..f8e9bdf --- /dev/null +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java @@ -0,0 +1,116 @@ +/* + * Opml20Parser.java + * + * Created on April 25, 2006, 1:04 AM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.syndication.io.impl; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; +import com.sun.syndication.io.FeedException; + +import org.jdom.Document; +import org.jdom.Element; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + + +/** + * + * @author cooper + */ +public class OPML20Parser extends OPML10Parser { + /** Creates a new instance of Opml20Parser */ + public OPML20Parser() { + super("opml_2.0"); + } + + /** + * Inspects an XML Document (JDOM) to check if it can parse it. + *

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

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

+ * + * @param document XML document (JDOM) to parse. + * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). + * @return the resulting feed bean. + * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. + * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). + */ + public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { + Opml opml; + opml = (Opml) super.parse(document, validate); + + Element head = document.getRootElement().getChild("head"); + + if (head != null) { + opml.setOwnerId(head.getChildTextTrim("ownerId")); + opml.setDocs(head.getChildTextTrim("docs")); + + if (opml.getDocs() == null) { + opml.setDocs("http://www.opml.org/spec2"); + } + } + + opml.setFeedType("opml_2.0"); + + return opml; + } + + protected Outline parseOutline(Element e, boolean validate) throws FeedException { + Outline retValue; + + retValue = super.parseOutline(e, validate); + + if (e.getAttributeValue("created") != null) { + retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"))); + } + + List atts = retValue.getAttributes(); + + for (int i = 0; i < atts.size(); i++) { + Attribute a = (Attribute) atts.get(i); + + if (a.getName().equals("created")) { + retValue.getAttributes().remove(a); + + break; + } + } + + return retValue; + } +} diff --git a/src/main/java/com/sun/syndication/io/impl/package.html b/src/main/java/com/sun/syndication/io/impl/package.html new file mode 100644 index 0000000..64d1989 --- /dev/null +++ b/src/main/java/com/sun/syndication/io/impl/package.html @@ -0,0 +1,28 @@ + + + + + + + + + This package contains the feed parsers for OPML1 and OPML2. + + +

+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+    
+ + + diff --git a/src/main/resources/rome.properties b/src/main/resources/rome.properties new file mode 100644 index 0000000..fe2c0f2 --- /dev/null +++ b/src/main/resources/rome.properties @@ -0,0 +1,22 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +WireFeedGenerator.classes=com.sun.syndication.io.impl.OPML10Generator \ + com.sun.syndication.io.impl.OPML20Generator + +WireFeedParser.classes=com.sun.syndication.io.impl.OPML10Parser \ + com.sun.syndication.io.impl.OPML20Parser + +Converter.classes=com.sun.syndication.feed.synd.impl.ConverterForOPML10 \ + com.sun.syndication.feed.synd.impl.ConverterForOPML20 diff --git a/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java b/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java new file mode 100644 index 0000000..b181f26 --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java @@ -0,0 +1,114 @@ +package com.sun.syndication.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.ObjectInputStream; + +/** + * + *

+ * @author Alejandro Abdelnur + * + */ +public abstract class FeedOpsTest extends FeedTest { + + protected FeedOpsTest(String feedType) { + super(feedType+".xml"); + System.out.println("Testing "+feedType+".xml"); + new File("target/test-reports").mkdirs(); + } + + //1.2a + public void testWireFeedEquals() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + WireFeed feed2 = getWireFeed(); + assertTrue(feed1.equals(feed2)); + } + + //1.2b + public void testWireFeedNotEqual() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + WireFeed feed2 = getWireFeed(); + feed2.setFeedType("dummy"); + assertFalse(feed1.equals(feed2)); + } + + //1.3 + public void testWireFeedCloning() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + WireFeed feed2 = (WireFeed) feed1.clone();; + assertTrue(feed1.equals(feed2)); + } + + // 1.4 + public void testWireFeedSerialization() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(feed1); + oos.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + WireFeed feed2 = (WireFeed) ois.readObject(); + ois.close(); + + assertTrue(feed1.equals(feed2)); + } + + // 1.6 + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + + assertEquals(sFeed1, sFeed2 ); + } + + //1.7a + public void testSyndFeedEquals() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + SyndFeed feed2 = getSyndFeed(); + assertTrue(feed1.equals(feed2)); + } + + //1.7b + public void testSyndFeedNotEqual() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + SyndFeed feed2 = getSyndFeed(); + feed2.setFeedType("dummy"); + assertFalse(feed1.equals(feed2)); + } + + //1.8 + public void testSyndFeedCloning() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + SyndFeed feed2 = (SyndFeed) feed1.clone();; + assertTrue(feed1.equals(feed2)); + } + + //1.9 + public void testSyndFeedSerialization() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(feed1); + oos.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + SyndFeed feed2 = (SyndFeed) ois.readObject(); + ois.close(); + + assertTrue(feed1.equals(feed2)); + } + +} diff --git a/src/test/java/com/sun/syndication/unittest/FeedTest.java b/src/test/java/com/sun/syndication/unittest/FeedTest.java new file mode 100644 index 0000000..f881c4c --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/FeedTest.java @@ -0,0 +1,78 @@ +package com.sun.syndication.unittest; + +import junit.framework.TestCase; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.WireFeedInput; + +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.InputStream; + +import org.jdom.Document; +import org.jdom.input.SAXBuilder; + +/** + * @author pat, tucu + * + */ +public abstract class FeedTest extends TestCase { + private String _feedFileName; + private Document _jDomDoc = null; + private WireFeed _wireFeed = null; + private SyndFeed _syndFeed = null; + + protected FeedTest(String feedFileName) { + _feedFileName = feedFileName; + } + + protected String getFeedFileName() { + return _feedFileName; + } + + protected Reader getFeedReader() throws Exception { + InputStream resource = Thread.currentThread(). + getContextClassLoader().getResourceAsStream(getFeedFileName()); + assertNotNull("Could not find resource " + getFeedFileName(), resource); + return new InputStreamReader(resource); + } + + protected Document getJDomDoc() throws Exception { + SAXBuilder saxBuilder = new SAXBuilder(false); + return saxBuilder.build(getFeedReader()); + } + + protected WireFeed getWireFeed() throws Exception { + WireFeedInput in = new WireFeedInput(); + return in.build(getFeedReader()); + } + + protected SyndFeed getSyndFeed() throws Exception { + SyndFeedInput in = new SyndFeedInput(); + return in.build(getFeedReader()); + } + + protected Document getCachedJDomDoc() throws Exception { + if (_jDomDoc==null) { + _jDomDoc = getJDomDoc(); + } + return _jDomDoc; + } + + protected WireFeed getCachedWireFeed() throws Exception { + if (_wireFeed==null) { + _wireFeed = getWireFeed(); + } + return _wireFeed; + } + + protected SyndFeed getCachedSyndFeed() throws Exception { + if (_syndFeed==null) { + _syndFeed = getSyndFeed(); + } + return _syndFeed; + } + +} diff --git a/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java b/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java new file mode 100644 index 0000000..2d28d91 --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java @@ -0,0 +1,267 @@ +/* + * Created on Jun 22, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package com.sun.syndication.unittest; + + + + +/** + * @author pat + * + */ +public abstract class SyndFeedTest extends FeedTest { + private String _prefix = null; + + protected SyndFeedTest(String feedType) { + this(feedType,feedType+".xml"); + } + + protected SyndFeedTest(String feedType,String feedFileName) { + super(feedFileName); + _prefix = feedType; + } + + protected String getPrefix() { + return _prefix; + } + + protected void assertProperty(String property, String value) { + assertEquals(property,getPrefix() + "." + value); + } + + public void testType() throws Exception { + assertEquals(getCachedSyndFeed().getFeedType(),getPrefix()); + } + + +/* + public void testType() throws Exception { + assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); + } + + public void testTitle() throws Exception { + assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); + } + + public void testLink() throws Exception { + assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); + } + + public void testDescription() throws Exception { + assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); + } + + public void testLanguage() throws Exception { + assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); + } + + public void testCategories() throws Exception { + List catlist = getCachedSyndFeed().getCategories(); + //don't understand why this one fails + assertEquals(2, catlist.size()); + SyndCategory cat = (SyndCategory)catlist.get(0); + assertEqualsStr("channel.category[0]", cat.getName()); + assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); + cat = (SyndCategory)catlist.get(1); + assertEqualsStr("channel.category[1]", cat.getName()); + assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); + } + + public void testPublishedDate() throws Exception { + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getCachedSyndFeed().getPublishedDate()); + } + + //how do i get height and width? + public void testImage() throws Exception { + SyndImage img = getCachedSyndFeed().getImage(); + assertEqualsStr("channel.image.description", img.getDescription()); + assertEqualsStr("channel.image.link", img.getLink()); + assertEqualsStr("channel.image.title", img.getTitle()); + assertEqualsStr("channel.image.url", img.getUrl()); + } + + public void testEntries() throws Exception { + List entrylist = getCachedSyndFeed().getEntries(); + assertEquals(2, entrylist.size()); + } + + public void testEntryTitle() throws Exception { + assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryTitle(Object o) throws Exception { + SyndEntry e = (SyndEntry) o; + return e.getTitle(); + } + + public void testEntryDescription() throws Exception { + assertEqualsStr("channel.item[0].description", getEntryDescription(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].description", getEntryDescription(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryDescription(Object o) throws Exception { + SyndEntry e = (SyndEntry) o; + return e.getDescription().getValue(); + } + + public void testEntryLink() throws Exception { + assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryLink(Object o) { + SyndEntry e = (SyndEntry) o; + return e.getLink(); + } + + public void testEntryPublishedDate() throws Exception { + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); + } + + public Date getEntryPublishedDate(Object o) { + SyndEntry e = (SyndEntry) o; + return e.getPublishedDate(); + } + + public void testEntryCategories() throws Exception { + SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); + List catlist = e.getCategories(); + //don't understand why this one fails + assertEquals(2, catlist.size()); + SyndCategory cat = (SyndCategory)catlist.get(0); + assertEqualsStr("channel.item[0].category[0]", cat.getName()); + assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); + cat = (SyndCategory)catlist.get(1); + assertEqualsStr("channel.item[0].category[1]", cat.getName()); + assertEqualsStr("channel.item[0].category[1]^domain", cat.getTaxonomyUri()); + //DO 2nd set of items + } + + public void testEntryAuthor() throws Exception { + assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryAuthor(Object o) { + SyndEntry e = (SyndEntry) o; + return e.getAuthor(); + } + +*/ +/* +//things you cannot get from SyndEntryImpl +// item[0].source +// +// + item0.category0 + item0.category1 + Thu, 08 Jul 1999 08:00:00 GMT + Thu, 08 Jul 1999 09:00:00 GMT + item0.author + http://localhost:8080/item0/comments + http://localhost:8080/item0/guid + //TODO: I still have the elements to test +*/ + /* + public void test() { + assertEqualsStr(feed, ""); + } + + public void test() { + assertEqualsStr(feed, ""); + } + + */ + //Things that you cannot get form a SyndFeedImpl today + //these need to be put in a RSS 2.0 module + //or is a roundtrip to wirefeed the right way to do this? +/* + * + Search + Search this site: + q + http://example.org/mt/mt-search.cgi + + + image height and width + * + //Copyright 2004, Mark Pilgrim + public void test() { + assertEqualsStr(getCachedSyndFeed()., ""); + } + + //Sample Toolkit + public void test() { + assertEqualsStr(feed, ""); + } + + // editor@example.org + public void test() { + assertEqualsStr(feed, ""); + } + + // webmaster@example.org + public void test() { + assertEqualsStr(feed, ""); + } + + http://blogs.law.harvard.edu/tech/rss + + 60 + + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9.5 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + + + Monday + Tuesday + Wednesday + Thursday + Friday + Saturday + Sunday + + +**/ + + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + + +} diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java b/src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java new file mode 100644 index 0000000..83aef02 --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java @@ -0,0 +1,47 @@ +/* + * TestOpsOPML10.java + * + * Created on April 25, 2006, 4:26 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.sun.syndication.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import java.io.FileOutputStream; +import java.io.PrintWriter; + +/** + * + * @author cooper + */ +public class TestOpsOPML10 extends FeedOpsTest{ + + /** Creates a new instance of TestOpsOPML10 */ + public TestOpsOPML10() { + super("opml_1.0"); + } + + // 1.6 + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); + w.println( sFeed1.toString() ); + w.close(); + w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); + w.println( sFeed2.toString() ); + w.close(); + + assertEquals(sFeed1, sFeed2); + } + + + + +} diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java b/src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java new file mode 100644 index 0000000..4364767 --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java @@ -0,0 +1,67 @@ +/* + * TestOpsOPML10.java + * + * Created on April 25, 2006, 4:26 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.sun.syndication.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.WireFeedOutput; +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; + +/** + * + * @author cooper + */ +public class TestOpsOPML10links extends FeedOpsTest{ + + /** Creates a new instance of TestOpsOPML10 */ + public TestOpsOPML10links() { + super("opml_1.0_links"); + } + + // 1.6 + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + //System.out.println( wFeed1 ); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); + w.println( sFeed1.toString() ); + w.close(); + w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); + w.println( sFeed2.toString() ); + w.close(); + + assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed()); + } + + + + public void testTemp() throws Exception { + WireFeedInput input = new WireFeedInput(); + WireFeed wf = input.build( new File( System.getProperty("basedir")+ "/src/test/resources/opml_1.0_links.xml")); + WireFeedOutput output = new WireFeedOutput(); + //System.out.println( wf ); + + //System.out.println( "================================="); + //System.out.println( new SyndFeedImpl( wf) ); + SyndFeedImpl sf = new SyndFeedImpl( wf); + sf.setFeedType("rss_2.0"); + sf.setDescription(""); + sf.setLink("http://foo.com"); + //output.output( sf.createWireFeed() , new PrintWriter( System.out ) ); + sf.setFeedType("opml_1.0"); + output.output( sf.createWireFeed() , new File( System.getProperty("basedir")+ "/target/test-reports/1.xml") ); + } + +} diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java b/src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java new file mode 100644 index 0000000..5bac1dc --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java @@ -0,0 +1,43 @@ +/* + * TestOpsOPML20.java + * + * Created on April 25, 2006, 5:38 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.sun.syndication.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import java.io.FileOutputStream; +import java.io.PrintWriter; + +/** + * + * @author cooper + */ +public class TestOpsOPML20 extends FeedOpsTest { + + /** Creates a new instance of TestOpsOPML20 */ + public TestOpsOPML20() { + super("opml_2.0"); + } + + + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/3") ); + w.println( sFeed1.toString() ); + w.close(); + w = new PrintWriter( new FileOutputStream( "target/test-reports/4") ); + w.println( sFeed2.toString() ); + w.close(); + assertEquals(sFeed1, sFeed2 ); + } + +} diff --git a/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java b/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java new file mode 100644 index 0000000..9fa434d --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java @@ -0,0 +1,134 @@ +/* + * Copyright 2004 Sun Microsystems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.sun.syndication.unittest; + +import com.sun.syndication.io.XmlReader; +import com.sun.syndication.io.impl.XmlFixerReader; +import junit.framework.TestCase; +import org.jdom.input.SAXBuilder; + +import java.io.*; + +/** + * @author pat, tucu + * + */ +public class TestXmlFixerReader extends TestCase { + private static final String XML_PROLOG = ""; + + public void testTrim() throws Exception { + _testValidTrim("",""); + _testValidTrim("",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" \n",""); + _testValidTrim(" \n",XML_PROLOG+""); + _testValidTrim("",""); + _testValidTrim("",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" \n ",""); + _testValidTrim(" \n ",XML_PROLOG+""); + + _testInvalidTrim("x",""); + _testInvalidTrim("x",XML_PROLOG+""); + _testInvalidTrim(" x",""); + _testInvalidTrim(" x",XML_PROLOG+""); + _testInvalidTrim(" x\n",""); + _testInvalidTrim(" x\n",XML_PROLOG+""); + _testInvalidTrim("x ",""); + _testInvalidTrim(" x ",XML_PROLOG+""); + _testInvalidTrim(" x ",""); + _testInvalidTrim(" x ",XML_PROLOG+""); + _testInvalidTrim(" x\n ",""); + _testInvalidTrim(" x\n ",XML_PROLOG+""); + } + + public void testHtmlEntities() throws Exception { + _testValidEntities(""); + _testValidEntities(XML_PROLOG+""); + _testValidEntities(" \n"+XML_PROLOG+""); + + _testValidEntities("'¥ú¥"); + _testValidEntities(XML_PROLOG+"'¥ú¥"); + _testValidEntities(" \n"+XML_PROLOG+"'¥ú¥"); + + _testInvalidEntities("'&yexn;ú¥"); + _testInvalidEntities(XML_PROLOG+"'&yexn;ú¥"); + _testInvalidEntities(" \n"+XML_PROLOG+"'&yexn;ú¥"); + + _testInvalidEntities("'¥x50;¥"); + _testInvalidEntities(XML_PROLOG+"'¥x50;¥"); + _testInvalidEntities(" \n"+XML_PROLOG+"'¥x50;¥"); + + } + + protected void _testXmlParse(String garbish,String xmlDoc) throws Exception { + InputStream is = getStream(garbish,xmlDoc); + Reader reader = new XmlReader(is); + reader = new XmlFixerReader(reader); + SAXBuilder saxBuilder = new SAXBuilder(); + saxBuilder.build(reader); + } + + protected void _testValidTrim(String garbish,String xmlDoc) throws Exception { + _testXmlParse(garbish,xmlDoc); + } + + protected void _testInvalidTrim(String garbish,String xmlDoc) throws Exception { + try { + _testXmlParse(garbish,xmlDoc); + assertTrue(false); + } + catch (Exception ex) { + } + } + + protected void _testValidEntities(String xmlDoc) throws Exception { + _testXmlParse("",xmlDoc); + } + + protected void _testInvalidEntities(String xmlDoc) throws Exception { + try { + _testXmlParse("",xmlDoc); + assertTrue(false); + } + catch (Exception ex) { + } + } + + // XML Stream generator + + protected InputStream getStream(String garbish,String xmlDoc) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + Writer writer = new OutputStreamWriter(baos); + writer.write(garbish); + writer.write(xmlDoc); + writer.close(); + return new ByteArrayInputStream(baos.toByteArray()); + } + + +} diff --git a/src/test/java/com/sun/syndication/unittest/TestXmlReader.java b/src/test/java/com/sun/syndication/unittest/TestXmlReader.java new file mode 100644 index 0000000..b8dedbc --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/TestXmlReader.java @@ -0,0 +1,257 @@ +/* + * Copyright 2004 Sun Microsystems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.sun.syndication.unittest; + +import com.sun.syndication.io.XmlReader; +import junit.framework.TestCase; + +import java.io.*; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +/** + * @author pat, tucu + * + */ +public class TestXmlReader extends TestCase { + + public static void main(String[] args) throws Exception { + TestXmlReader test = new TestXmlReader(); + test.testRawBom(); + test.testRawNoBom(); + test.testHttp(); + } + + protected void _testRawNoBomValid(String encoding) throws Exception { + InputStream is = getXmlStream("no-bom","xml",encoding,encoding); + XmlReader xmlReader = new XmlReader(is,false); + assertEquals(xmlReader.getEncoding(),"UTF-8"); + + is = getXmlStream("no-bom","xml-prolog",encoding,encoding); + xmlReader = new XmlReader(is); + assertEquals(xmlReader.getEncoding(),"UTF-8"); + + is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + xmlReader = new XmlReader(is); + assertEquals(xmlReader.getEncoding(),encoding); + } + + protected void _testRawNoBomInvalid(String encoding) throws Exception { + InputStream is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + try { + XmlReader xmlReader = new XmlReader(is,false); + fail("It should have failed"); + } + catch (IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); + } + } + + public void testRawNoBom() throws Exception { + _testRawNoBomValid("US-ASCII"); + _testRawNoBomValid("UTF-8"); + _testRawNoBomValid("ISO-8859-1"); + } + + protected void _testRawBomValid(String encoding) throws Exception { + InputStream is = getXmlStream(encoding+"-bom","xml-prolog-encoding",encoding,encoding); + XmlReader xmlReader = new XmlReader(is,false); + if (!encoding.equals("UTF-16")) { + assertEquals(xmlReader.getEncoding(),encoding); + } + else { + assertEquals(xmlReader.getEncoding().substring(0,encoding.length()),encoding); + } + } + + protected void _testRawBomInvalid(String bomEnc,String streamEnc,String prologEnc) throws Exception { + InputStream is = getXmlStream(bomEnc,"xml-prolog-encoding",streamEnc,prologEnc); + try { + XmlReader xmlReader = new XmlReader(is,false); + fail("It should have failed for BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + } + catch (IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); + } + } + + public void testRawBom() throws Exception { + _testRawBomValid("UTF-8"); + _testRawBomValid("UTF-16BE"); + _testRawBomValid("UTF-16LE"); + _testRawBomValid("UTF-16"); + + _testRawBomInvalid("UTF-8-bom","US-ASCII","US-ASCII"); + _testRawBomInvalid("UTF-8-bom","ISO-8859-1","ISO-8859-1"); + _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16"); + _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16BE"); + _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16LE"); + _testRawBomInvalid("UTF-16BE-bom","UTF-16BE","UTF-16LE"); + _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-16BE"); + _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-8"); + } + + public void testHttp() throws Exception { + _testHttpValid("application/xml","no-bom","US-ASCII",null); + _testHttpValid("application/xml","UTF-8-bom","US-ASCII",null); + _testHttpValid("application/xml","UTF-8-bom","UTF-8",null); + _testHttpValid("application/xml","UTF-8-bom","UTF-8","UTF-8"); + _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); + _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); + _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); + _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + + _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); + _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("application/xml","UTF-8-bom","US-ASCII","US-ASCII"); + _testHttpInvalid("application/xml;charset=UTF-16","UTF-16LE","UTF-8","UTF-8"); + _testHttpInvalid("application/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); + + _testHttpValid("text/xml","no-bom","US-ASCII",null); + _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); + _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); + _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); + _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpValid("text/xml","UTF-8-bom","US-ASCII",null); + + _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); + _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE",null); + + _testHttpLenient("text/xml","no-bom","US-ASCII",null, "US-ASCII"); + _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8", "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null, "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml","UTF-8-bom","US-ASCII",null, "US-ASCII"); + + _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE",null, "UTF-16"); + + _testHttpLenient("text/html","no-bom","US-ASCII","US-ASCII", "US-ASCII"); + _testHttpLenient("text/html","no-bom","US-ASCII",null, "US-ASCII"); + _testHttpLenient("text/html;charset=UTF-8","no-bom","US-ASCII","UTF-8", "UTF-8"); + _testHttpLenient("text/html;charset=UTF-16BE","no-bom","US-ASCII","UTF-8", "UTF-8"); + } + + public void _testHttpValid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { + InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml":"xml-prolog-encoding",streamEnc,prologEnc); + XmlReader xmlReader = new XmlReader(is,cT,false); + if (!streamEnc.equals("UTF-16")) { + // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection + } + else { + assertEquals(xmlReader.getEncoding().substring(0,streamEnc.length()),streamEnc); + } + } + + protected void _testHttpInvalid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { + InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); + try { + XmlReader xmlReader = new XmlReader(is,cT,false); + fail("It should have failed for HTTP Content-type "+cT+", BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + } + catch (IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); + } + } + + protected void _testHttpLenient(String cT, String bomEnc, String streamEnc, String prologEnc, String shouldbe) throws Exception { + InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); + XmlReader xmlReader = new XmlReader(is,cT,true); + assertEquals(xmlReader.getEncoding(),shouldbe); + } + + // XML Stream generator + + private static final int[] NO_BOM_BYTES = {}; + private static final int[] UTF_16BE_BOM_BYTES = {0xFE,0xFF}; + private static final int[] UTF_16LE_BOM_BYTES = {0xFF,0XFE}; + private static final int[] UTF_8_BOM_BYTES = {0xEF,0xBB,0xBF}; + + private static final Map BOMs = new HashMap(); + + static { + BOMs.put("no-bom",NO_BOM_BYTES); + BOMs.put("UTF-16BE-bom",UTF_16BE_BOM_BYTES); + BOMs.put("UTF-16LE-bom",UTF_16LE_BOM_BYTES); + BOMs.put("UTF-16-bom",NO_BOM_BYTES); // it's added by the writer + BOMs.put("UTF-8-bom",UTF_8_BOM_BYTES); + } + + private static final MessageFormat XML = new MessageFormat( + "{2}"); + private static final MessageFormat XML_WITH_PROLOG = new MessageFormat( + "\n{2}"); + private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat( + "\n{2}"); + + private static final MessageFormat INFO = new MessageFormat( + "\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); + + private static final Map XMLs = new HashMap(); + + static { + XMLs.put("xml",XML); + XMLs.put("xml-prolog",XML_WITH_PROLOG); + XMLs.put("xml-prolog-encoding",XML_WITH_PROLOG_AND_ENCODING); + } + + /** + * + * @param bomType no-bom, UTF-16BE-bom, UTF-16LE-bom, UTF-8-bom + * @param xmlType xml, xml-prolog, xml-prolog-charset + * @return XML stream + */ + protected InputStream getXmlStream(String bomType,String xmlType,String streamEnc,String prologEnc) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + int[] bom = (int[]) BOMs.get(bomType); + if (bom==null) { + bom = new int[0]; + } + MessageFormat xml = (MessageFormat) XMLs.get(xmlType); + for (int i=0;i\n"); + for (int i=0;i<10000;i++) { + writer.write("\n"); + } + writer.write("\n"); + + writer.close(); + return new ByteArrayInputStream(baos.toByteArray()); + } + + +} diff --git a/src/test/resources/opml_1.0.xml b/src/test/resources/opml_1.0.xml new file mode 100644 index 0000000..98b1524 --- /dev/null +++ b/src/test/resources/opml_1.0.xml @@ -0,0 +1,29 @@ + + + + Bloglines Subscriptions + Tue, 25 Apr 2006 19:19:28 GMT + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/opml_1.0_links.xml b/src/test/resources/opml_1.0_links.xml new file mode 100644 index 0000000..ae89624 --- /dev/null +++ b/src/test/resources/opml_1.0_links.xml @@ -0,0 +1,76 @@ + + + + Top Ten Sources for podcasting + Newsilike Media Group + opml@TopTenSources.com + Thu, 27 Apr 2006 05:47:27 GMT + Thu, 27 Apr 2006 05:47:27 GMT + 0 + 0 + 0 + 0 + 100 + 100 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/opml_2.0.xml b/src/test/resources/opml_2.0.xml new file mode 100644 index 0000000..22c9586 --- /dev/null +++ b/src/test/resources/opml_2.0.xml @@ -0,0 +1,30 @@ + + + + Bloglines Subscriptions + Tue, 25 Apr 2006 19:19:28 GMT + http://foo.com + Robert Cooper + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 76af530fb2862f74e48ef9ec0bf59f7eb784bb6b Mon Sep 17 00:00:00 2001 From: kebernet Date: Fri, 11 Mar 2011 18:14:23 +0000 Subject: [PATCH 03/47] 1.0 --- pom.xml | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ac83b1d..c288c86 100644 --- a/pom.xml +++ b/pom.xml @@ -2,12 +2,37 @@ 4.0.0 - org.rometools.opml - opml + org.rometools + rome-opml jar - 1.0-SNAPSHOT + 1.0 rome-opml http://rometools.jira.com + + + kebernet + kebernet@gmail.com + Robert Cooper + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + scm:svn:https://rometools.jira.com/svn/MODULES/trunk + scm:svn:https://rometools.jira.com/svn/MODULES/trunk + https://rometools.jira.com/source/browse/MODULES + + + + maven2-repository.dev.java.net + http://download.java.net/maven/2 + + junit @@ -19,6 +44,104 @@ rome rome 1.0 + compile + + + + org.apache.maven.plugins + maven-scm-plugin + 1.0 + + install + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.4 + 1.4 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.2 + + ${project.build.sourceEncoding} + + + + + + + release + + + performRelease + true + + + + + central.staging + Nexus Release Repository + http://oss.sonatype.org/service/local/staging/deploy/maven2 + + + sonatype.snapshots + My Nexus Snapshots Repository + https://oss.sonatype.org/content/repositories/snapshots/ + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + + + + + UTF-8 + From 3a338d4343f1b7cefae02fd01d5ef20a39b4e545 Mon Sep 17 00:00:00 2001 From: kebernet Date: Mon, 14 Mar 2011 23:44:16 +0000 Subject: [PATCH 04/47] Initial refactoring. --- .../sun/syndication/feed/opml/Attribute.java | 107 ----- .../com/sun/syndication/feed/opml/Opml.java | 280 ------------- .../sun/syndication/feed/opml/Outline.java | 343 ---------------- .../sun/syndication/feed/opml/package.html | 47 --- .../feed/synd/impl/ConverterForOPML10.java | 374 ------------------ .../feed/synd/impl/ConverterForOPML20.java | 64 --- .../feed/synd/impl/TreeCategoryImpl.java | 34 -- .../syndication/feed/synd/impl/package.html | 30 -- .../syndication/io/impl/OPML10Generator.java | 187 --------- .../sun/syndication/io/impl/OPML10Parser.java | 261 ------------ .../syndication/io/impl/OPML20Generator.java | 82 ---- .../sun/syndication/io/impl/OPML20Parser.java | 116 ------ .../com/sun/syndication/io/impl/package.html | 28 -- .../sun/syndication/unittest/FeedOpsTest.java | 114 ------ .../sun/syndication/unittest/FeedTest.java | 78 ---- .../syndication/unittest/SyndFeedTest.java | 267 ------------- .../syndication/unittest/TestOpsOPML10.java | 47 --- .../unittest/TestOpsOPML10links.java | 67 ---- .../syndication/unittest/TestOpsOPML20.java | 43 -- .../unittest/TestXmlFixerReader.java | 134 ------- .../syndication/unittest/TestXmlReader.java | 257 ------------ 21 files changed, 2960 deletions(-) delete mode 100644 src/main/java/com/sun/syndication/feed/opml/Attribute.java delete mode 100644 src/main/java/com/sun/syndication/feed/opml/Opml.java delete mode 100644 src/main/java/com/sun/syndication/feed/opml/Outline.java delete mode 100644 src/main/java/com/sun/syndication/feed/opml/package.html delete mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java delete mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java delete mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java delete mode 100644 src/main/java/com/sun/syndication/feed/synd/impl/package.html delete mode 100644 src/main/java/com/sun/syndication/io/impl/OPML10Generator.java delete mode 100644 src/main/java/com/sun/syndication/io/impl/OPML10Parser.java delete mode 100644 src/main/java/com/sun/syndication/io/impl/OPML20Generator.java delete mode 100644 src/main/java/com/sun/syndication/io/impl/OPML20Parser.java delete mode 100644 src/main/java/com/sun/syndication/io/impl/package.html delete mode 100644 src/test/java/com/sun/syndication/unittest/FeedOpsTest.java delete mode 100644 src/test/java/com/sun/syndication/unittest/FeedTest.java delete mode 100644 src/test/java/com/sun/syndication/unittest/SyndFeedTest.java delete mode 100644 src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java delete mode 100644 src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java delete mode 100644 src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java delete mode 100644 src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java delete mode 100644 src/test/java/com/sun/syndication/unittest/TestXmlReader.java diff --git a/src/main/java/com/sun/syndication/feed/opml/Attribute.java b/src/main/java/com/sun/syndication/feed/opml/Attribute.java deleted file mode 100644 index db0db43..0000000 --- a/src/main/java/com/sun/syndication/feed/opml/Attribute.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Attribute.java - * - * Created on April 24, 2006, 11:11 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.syndication.feed.opml; - -import com.sun.syndication.feed.impl.EqualsBean; -import com.sun.syndication.feed.impl.ToStringBean; - -import java.io.Serializable; - - -/** - * This is a simple name-value pair attribute for outlines. - * - * @author Robert "kebernet" Cooper - */ -public class Attribute implements Cloneable, Serializable { - private String _name; - private String _value; - - /** Creates a new instance of Attribute */ - public Attribute() { - super(); - } - - /** - * Creates a new instance of Attribute. - * @param name name of the attribute. - * @param value value of the attribute. - */ - public Attribute(String name, String value) { - if ((name == null) || (value == null)) { - throw new NullPointerException("Name and value are required."); - } - - this.setName(name); - this.setValue(value); - } - - /** - * name of the attribute. - * @param name name of the attribute. - */ - public void setName(String name) { - this._name = name; - } - - /** - * name of the attribute. - * @return name of the attribute. - */ - public String getName() { - return _name; - } - - /** - * value of the attribute. - * @param value value of the attribute. - */ - public void setValue(String value) { - this._value = value; - } - - /** - * value of the attribute. - * @return value of the attribute. - */ - public String getValue() { - return _value; - } - - public Object clone() { - return new Attribute(this._name, this._value); - } - - public boolean equals(Object obj) { - EqualsBean eBean = new EqualsBean(Attribute.class, this); - - return eBean.beanEquals(obj); - } - - public int hashCode() { - EqualsBean equals = new EqualsBean(Attribute.class, this); - - return equals.beanHashCode(); - } - - public String toString() { - ToStringBean tsBean = new ToStringBean(Attribute.class, this); - - return tsBean.toString(); - } -} diff --git a/src/main/java/com/sun/syndication/feed/opml/Opml.java b/src/main/java/com/sun/syndication/feed/opml/Opml.java deleted file mode 100644 index 189c249..0000000 --- a/src/main/java/com/sun/syndication/feed/opml/Opml.java +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Opml.java - * - * Created on April 24, 2006, 11:00 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.syndication.feed.opml; - -import com.sun.syndication.feed.WireFeed; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - - -/** - * This class represents the root of an OPML 1/2 feed and contains the elements that - * may appear in the <head> tag of the feed. - * @author Robert "kebernet" Cooper - */ -public class Opml extends WireFeed { - private Date _created; - private Date _modified; - private Integer _verticalScrollState; - private Integer _windowBottom; - private Integer _windowLeft; - private Integer _windowRight; - private Integer _windowTop; - private List _outlines; - private String _docs; - private String _ownerEmail; - private String _ownerId; - private String _ownerName; - private String _title; - private int[] _expansionState; - - /** Creates a new instance of Opml */ - public Opml() { - super(); - } - - /** - * is a date-time, indicating when the document was created. - * @param created date-time, indicating when the document was created. - */ - public void setCreated(Date created) { - this._created = created; - } - - /** - * <dateCreated> is a date-time, indicating when the document was created. - * @return date-time, indicating when the document was created. - */ - public Date getCreated() { - return _created; - } - - /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. - * @param docs http address of documentation for the format used - */ - public void setDocs(String docs) { - this._docs = docs; - } - - /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. - * @return http address of documentation for the format used - */ - public String getDocs() { - return _docs; - } - - /** - * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. - * @param expansionState int array containing expanded elements. - */ - public void setExpansionState(int[] expansionState) { - this._expansionState = expansionState; - } - - /** - * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. - * @return int array containing expanded elements. - */ - public int[] getExpansionState() { - return _expansionState; - } - - /** - * <dateModified> is a date-time, indicating when the document was last modified. - * @param modified date-time, indicating when the document was last modified. - */ - public void setModified(Date modified) { - this._modified = modified; - } - - /** - * <dateModified> is a date-time, indicating when the document was last modified. - * @return date-time, indicating when the document was last modified. - */ - public Date getModified() { - return _modified; - } - - /** - * Root level Outline object that should appear in the <body> - * @param outlines Root level Outline object that should appear in the <body> - */ - public void setOutlines(List outlines) { - this._outlines = outlines; - } - - /** - * Root level Outline object that should appear in the <body> - * @return Root level Outline object that should appear in the <body> - */ - public List getOutlines() { - if (_outlines == null) { - _outlines = new ArrayList(); - } - - return _outlines; - } - - /** - * <ownerEmail> is a string, the email address of the owner of the document. - * @param ownerEmail the email address of the owner of the document. - */ - public void setOwnerEmail(String ownerEmail) { - this._ownerEmail = ownerEmail; - } - - /** - * <ownerEmail> is a string, the email address of the owner of the document. - * @return the email address of the owner of the document. - */ - public String getOwnerEmail() { - return _ownerEmail; - } - - /** - * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. - * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. - */ - public void setOwnerId(String ownerId) { - this._ownerId = ownerId; - } - - /** - * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. - * @return http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. - */ - public String getOwnerId() { - return _ownerId; - } - - /** - * <ownerName> is a string, the owner of the document. - * @param ownerName the owner of the document. - */ - public void setOwnerName(String ownerName) { - this._ownerName = ownerName; - } - - /** - * <ownerName> is a string, the owner of the document. - * @return the owner of the document. - */ - public String getOwnerName() { - return _ownerName; - } - - /** - * <title> is the title of the document. - * @param title title of the document. - */ - public void setTitle(String title) { - this._title = title; - } - - /** - * <title> is the title of the document. - * @return title of the document. - */ - public String getTitle() { - return _title; - } - - /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. - * @param verticalScrollState which line of the outline is displayed on the top line of the window. - */ - public void setVerticalScrollState(Integer verticalScrollState) { - this._verticalScrollState = verticalScrollState; - } - - /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. - * @return which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. - */ - public Integer getVerticalScrollState() { - return _verticalScrollState; - } - - /** - * <windowBottom> is a number, the pixel location of the bottom edge of the window. - * @param windowBottom the pixel location of the bottom edge of the window. - */ - public void setWindowBottom(Integer windowBottom) { - this._windowBottom = windowBottom; - } - - /** - * <windowBottom> is a number, the pixel location of the bottom edge of the window. - * @return the pixel location of the bottom edge of the window. - */ - public Integer getWindowBottom() { - return _windowBottom; - } - - /** - * <windowLeft> is a number, the pixel location of the left edge of the window. - * @param windowLeft the pixel location of the left edge of the window. - */ - public void setWindowLeft(Integer windowLeft) { - this._windowLeft = windowLeft; - } - - /** - * <windowLeft> is a number, the pixel location of the left edge of the window. - * @return the pixel location of the left edge of the window. - */ - public Integer getWindowLeft() { - return _windowLeft; - } - - /** - * <windowRight> is a number, the pixel location of the right edge of the window. - * @param windowRight the pixel location of the right edge of the window. - */ - public void setWindowRight(Integer windowRight) { - this._windowRight = windowRight; - } - - /** - * <windowRight> is a number, the pixel location of the right edge of the window. - * @return the pixel location of the right edge of the window. - */ - public Integer getWindowRight() { - return _windowRight; - } - - /** - * <windowTop> is a number, the pixel location of the top edge of the window. - * @param windowTop the pixel location of the top edge of the window. - */ - public void setWindowTop(Integer windowTop) { - this._windowTop = windowTop; - } - - /** - * <windowTop> is a number, the pixel location of the top edge of the window. - * @return the pixel location of the top edge of the window. - */ - public Integer getWindowTop() { - return _windowTop; - } -} diff --git a/src/main/java/com/sun/syndication/feed/opml/Outline.java b/src/main/java/com/sun/syndication/feed/opml/Outline.java deleted file mode 100644 index df68f33..0000000 --- a/src/main/java/com/sun/syndication/feed/opml/Outline.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Outline.java - * - * Created on April 24, 2006, 11:04 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.syndication.feed.opml; - -import com.sun.syndication.feed.impl.EqualsBean; -import com.sun.syndication.feed.impl.ToStringBean; - -import java.io.Serializable; - -import java.net.URL; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - - -/** - * This class represents an OPML outline element. - * @author Robert "kebernet" Cooper - */ -public class Outline implements Cloneable, Serializable { - private Date _created; - private List _attributes; - private List _categories; - private List _children; - private List _modules; - private String _text; - private String _title; - private String _type; - private boolean _breakpoint; - private boolean _comment; - - /** Creates a new instance of Outline */ - public Outline() { - super(); - } - - /** - * Creates a new outline with the specified type and text values. - * @param type type attribute value/ - * @param text text attribute value - */ - public Outline(String type, String text) { - super(); - this.setType(type); - this.setText(text); - } - - /** - * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally - * used for aggregator feed lists and will get a type of "rss". - * @param title Title of the entry. - * @param xmlUrl link to XML file. - * @param htmlUrl link to html page. - */ - public Outline(String title, URL xmlUrl, URL htmlUrl) { - super(); - this.setType("rss"); - this.setTitle(title); - this.setAttributes(new ArrayList()); - - if (xmlUrl != null) { - getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); - } - - if (htmlUrl != null) { - getAttributes().add(new Attribute("htmlUrl", htmlUrl.toString())); - } - } - - /** - * List of attributes on this outline excluding the "common types" for the specification. - * @param attributes List of attributes on this outline. - */ - public void setAttributes(List attributes) { - this._attributes = attributes; - } - - /** - * List of attributes on this outline excluding the "common types" for the specification. - * @return List of attributes on this outline. - */ - public List getAttributes() { - if (this._attributes == null) { - this._attributes = new ArrayList(); - } - - return _attributes; - } - - /** - * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. - * @param breakpoint whether a breakpoint is set on this outline. - */ - public void setBreakpoint(boolean breakpoint) { - this._breakpoint = breakpoint; - } - - /** - * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. - * @return whether a breakpoint is set on this outline - */ - public boolean isBreakpoint() { - return _breakpoint; - } - - /** - * (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) { - this._categories = categories; - } - - /** - * (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() { - if (_categories == null) { - _categories = new ArrayList(); - } - - return _categories; - } - - /** - * A list of sub-outlines for this entry. - * @param children A list of sub-outlines for this entry. - */ - public void setChildren(List children) { - this._children = children; - } - - /** - * A list of sub-outlines for this entry. - * @return A list of sub-outlines for this entry. - */ - public List getChildren() { - if (_children == null) { - _children = new ArrayList(); - } - - return _children; - } - - /** - * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. - * @param comment whether the outline is commented - */ - public void setComment(boolean comment) { - this._comment = comment; - } - - /** - * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. - * @return whether the outline is commented - */ - public boolean isComment() { - return _comment; - } - - /** - * (OPML 2) created is the date-time that the outline node was created. - * @param created date-time that the outline node was created. - */ - public void setCreated(Date created) { - this._created = created; - } - - /** - * (OPML 2) created is the date-time that the outline node was created. - * @return date-time that the outline node was created. - */ - public Date getCreated() { - return _created; - } - - /** - * A convenience method to return the value of the url attribute. - * @return value of the htmlUrl attribute. - */ - public String getUrl() { - return getAttributeValue("url"); - } - - /** - * A convenience method to return the value of the htmlUrl attribute. - * @return value of the htmlUrl attribute. - */ - public String getHtmlUrl() { - return getAttributeValue("htmlUrl"); - } - - public void setModules(List modules) { - this._modules = modules; - } - - public List getModules() { - if (this._modules == null) { - this._modules = new ArrayList(); - } - - return _modules; - } - - /** - * The "text" attribute of the outline. - * @param text The "text" attribute of the outline. - */ - public void setText(String text) { - this._text = text; - } - - /** - * The "text" attribute of the outline. - * @return The "text" attribute of the outline. - */ - public String getText() { - return _text; - } - - /** - * The "title" attribute of the outline. - * @param title The "title" attribute of the outline. - */ - public void setTitle(String title) { - this._title = title; - } - - /** - * The "title" attribute of the outline. - * @return The "title" attribute of the outline. - */ - public String getTitle() { - return _title; - } - - /** - * The "type" attribute of the outline. - * @param type The "type" attribute of the outline. - */ - public void setType(String type) { - this._type = type; - } - - /** - * The "type" attribute of the outline. - * @return The "type" attribute of the outline. - */ - public String getType() { - return _type; - } - - /** - * A convenience method to return the value of the xmlUrl attribute. - * @return value of the xmlUrl attribute. - */ - public String getXmlUrl() { - return getAttributeValue("xmlUrl"); - } - - /** Returns the value of an attribute on the outline or null. - * @param name name of the attribute. - */ - public String getAttributeValue(String name ){ - List attributes = Collections.synchronizedList(this.getAttributes()); - - for (int i = 0; i < attributes.size(); i++) { - Attribute a = (Attribute) attributes.get(i); - - if ((a.getName() != null) && a.getName().equals(name)) { - return a.getValue(); - } - } - - return null; - } - - public Object clone() { - Outline o = new Outline(); - o.setBreakpoint(this.isBreakpoint()); - o.setCategories(new ArrayList(this.getCategories())); - o.setComment(this.isComment()); - o.setCreated((this._created != null) ? (Date) this._created.clone() : null); - o.setModules(new ArrayList(this.getModules())); - o.setText(this.getText()); - o.setTitle(this.getTitle()); - o.setType(this.getType()); - - ArrayList children = new ArrayList(); - - for (int i = 0; i < this.getChildren().size(); i++) { - children.add(((Outline) this._children.get(i)).clone()); - } - - o.setChildren(children); - - ArrayList attributes = new ArrayList(); - - for (int i = 0; i < this.getAttributes().size(); i++) { - attributes.add(((Attribute) this._attributes.get(i)).clone()); - } - - o.setAttributes(attributes); - - return o; - } - - public boolean equals(Object obj) { - EqualsBean eBean = new EqualsBean(Outline.class, this); - - return eBean.beanEquals(obj); - } - - public int hashCode() { - EqualsBean equals = new EqualsBean(Outline.class, this); - - return equals.beanHashCode(); - } - - public String toString() { - ToStringBean tsBean = new ToStringBean(Outline.class, this); - - return tsBean.toString(); - } -} diff --git a/src/main/java/com/sun/syndication/feed/opml/package.html b/src/main/java/com/sun/syndication/feed/opml/package.html deleted file mode 100644 index 3e0dfed..0000000 --- a/src/main/java/com/sun/syndication/feed/opml/package.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - This package represents the base objects for OPML support for ROME. -

- There are three classes here that are relevant. Opml, - which represents the root document and head information, - Outline which represents a single node on an Opml - outline tree, and provides convenience methods for commonly used - attributes such as xmlUrl. Finally, the - Attribute class, which represents a specific attribute - on an Outline object. Since OPML supports free-form attribute - assignments, this is a very multi-purpose class. -

-

Sample Usage: - To use this parser, simply include the jar file in your classpath - as you are using ROME. Be sure it exists at the same level as ROME, - such that, if ROME is in the common classpath of an application server, - don't include this jar in your webapps WEB-INF/lib. -

-  WireFeedInput input = new WireFeedInput();
-  Opml feed = (Opml) input.build( new File("myOpml.xml") );
-  List<Outline> outlines = (List<Outline>) feed.getOutlines();
-        
-

- - -
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-    
- - diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java deleted file mode 100644 index 3554ea3..0000000 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ /dev/null @@ -1,374 +0,0 @@ -/* - * ConverterForOPML10.java - * - * Created on April 25, 2006, 1:26 AM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.syndication.feed.synd.impl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Stack; -import java.util.logging.Logger; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.feed.synd.Converter; -import com.sun.syndication.feed.synd.SyndCategory; -import com.sun.syndication.feed.synd.SyndCategoryImpl; -import com.sun.syndication.feed.synd.SyndContent; -import com.sun.syndication.feed.synd.SyndContentImpl; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndEntryImpl; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndLink; -import com.sun.syndication.feed.synd.SyndLinkImpl; -import com.sun.syndication.feed.synd.SyndPerson; -import com.sun.syndication.feed.synd.SyndPersonImpl; - - -/** - * - * @author cooper - */ -public class ConverterForOPML10 implements Converter { - private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName() - .toString()); - public static final String URI_TREE = "urn:rome.tree"; - public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; - - /** Creates a new instance of ConverterForOPML10 */ - public ConverterForOPML10() { - super(); - } - - protected void addOwner(Opml opml, SyndFeed syndFeed) { - if((opml.getOwnerEmail() != null) || (opml.getOwnerName() != null)) { - List authors = new ArrayList(); - SyndPerson person = new SyndPersonImpl(); - person.setEmail(opml.getOwnerEmail()); - person.setName(opml.getOwnerName()); - authors.add(person); - syndFeed.setAuthors(authors); - } - } - - /** - * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. - *

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

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

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

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

- */ - public String getType() { - return "opml_1.0"; - } - - private static class OutlineHolder { - Outline outline; - String parent; - - public OutlineHolder(Outline outline, String parent) { - this.outline = outline; - this.parent = parent; - } - } - - private static class TreeContext extends Stack { - TreeContext() { - super(); - } - } -} diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java deleted file mode 100644 index cd03b39..0000000 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * ConverterForOPML20.java - * - * Created on April 25, 2006, 5:29 PM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ -package com.sun.syndication.feed.synd.impl; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; - - -/** - * - * @author cooper - */ -public class ConverterForOPML20 extends ConverterForOPML10 { - /** Creates a new instance of ConverterForOPML20 */ - public ConverterForOPML20() { - super(); - } - - /** - * Returns the type (version) of the real feed this converter handles. - *

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

- */ - public String getType() { - return "opml_2.0"; - } - - /** - * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. - *

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

- * - * @param feed real feed to copy/convert. - * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. - */ - public void copyInto(WireFeed feed, SyndFeed syndFeed) { - super.copyInto(feed, syndFeed); - } - - /** - * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. - *

- * - * @param syndFeed SyndFeedImpl to copy/convert value from. - * @return a real feed with copied/converted values of the SyndFeedImpl. - */ - public WireFeed createRealFeed(SyndFeed syndFeed) { - WireFeed retValue; - - retValue = super.createRealFeed(syndFeed); - - return retValue; - } -} diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java deleted file mode 100644 index 110147a..0000000 --- a/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * TreeCategoryImpl.java - * - * Created on April 27, 2006, 3:44 AM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ - -package com.sun.syndication.feed.synd.impl; - -import com.sun.syndication.feed.synd.SyndCategory; -import com.sun.syndication.feed.synd.SyndCategoryImpl; - -/** - * - * @author cooper - */ -public class TreeCategoryImpl extends SyndCategoryImpl { - - /** Creates a new instance of TreeCategoryImpl */ - public TreeCategoryImpl() { - super(); - } - - public boolean equals(Object o) { - SyndCategory c = (SyndCategory) o; - if( c.getTaxonomyUri() != null && c.getTaxonomyUri().equals( this.getTaxonomyUri() ) ) - return true; - else - return false; - } - -} diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/package.html b/src/main/java/com/sun/syndication/feed/synd/impl/package.html deleted file mode 100644 index 40f63ad..0000000 --- a/src/main/java/com/sun/syndication/feed/synd/impl/package.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - This packages contains the SyndFeed converters for the - OPML module. For information on how Opml gets turned into - other feed types through the Synd structures, see the OPML - Subproject page on the ROME wiki. - -

- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-    
- - - diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java deleted file mode 100644 index 7917ab8..0000000 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Opml10Generator.java - * - * Created on April 24, 2006, 11:35 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.syndication.io.impl; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.WireFeedGenerator; - -import org.jdom.Document; -import org.jdom.Element; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - - -/** - * - * @author Robert "kebernet" Cooper - */ -public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { - /** Creates a new instance of Opml10Generator */ - public OPML10Generator() { - super("opml_1.0"); - } - - public OPML10Generator(String type) { - super(type); - } - - /** - * Creates an XML document (JDOM) for the given feed bean. - *

- * - * @param feed the feed bean to generate the XML document from. - * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not - * match with the type of the WireFeedGenerator. - * @throws FeedException thrown if the XML Document could not be created. - */ - public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { - if (!(feed instanceof Opml)) { - throw new IllegalArgumentException("Not an OPML file"); - } - - Opml opml = (Opml) feed; - Document doc = new Document(); - Element root = new Element("opml"); - doc.addContent(root); - - Element head = generateHead(opml); - - if (head != null) { - root.addContent(head); - } - - Element body = new Element("body"); - root.addContent(body); - super.generateFeedModules(opml.getModules(), root); - body.addContent(generateOutlines(opml.getOutlines())); - - return doc; - } - - protected boolean addNotNullAttribute(Element target, String name, Object value) { - if ((target == null) || (name == null) || (value == null)) { - return false; - } - - target.setAttribute(name, value.toString()); - - return true; - } - - protected boolean addNotNullSimpleElement(Element target, String name, Object value) { - if ((target == null) || (name == null) || (value == null)) { - return false; - } - - Element e = new Element(name); - e.addContent(value.toString()); - target.addContent(e); - - return true; - } - - protected Element generateHead(Opml opml) { - Element head = new Element("head"); - boolean hasHead = false; - - if (opml.getCreated() != null) { - hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated())); - } - - hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); - - if (opml.getModified() != null) { - hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified())); - } - - hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); - hasHead = addNotNullSimpleElement(head, "ownerName", opml.getOwnerName()); - hasHead = addNotNullSimpleElement(head, "title", opml.getTitle()); - hasHead = addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState()); - hasHead = addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom()); - hasHead = addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft()); - hasHead = addNotNullSimpleElement(head, "windowRight", opml.getWindowRight()); - hasHead = addNotNullSimpleElement(head, "windowTop", opml.getWindowTop()); - - if (hasHead) { - return head; - } else { - return null; - } - } - - protected Element generateOutline(Outline outline) { - Element e = new Element("outline"); - addNotNullAttribute(e, "text", outline.getText()); - addNotNullAttribute(e, "type", outline.getType()); - addNotNullAttribute(e, "title", outline.getTitle()); - - if (outline.isBreakpoint()) { - addNotNullAttribute(e, "isBreakpoint", "true"); - } - - if (outline.isComment()) { - addNotNullAttribute(e, "isComment", "true"); - } - - List atts = Collections.synchronizedList(outline.getAttributes()); - - for (int i = 0; i < atts.size(); i++) { - Attribute att = (Attribute) atts.get(i); - addNotNullAttribute(e, att.getName(), att.getValue()); - } - - super.generateItemModules(outline.getModules(), e); - e.addContent(generateOutlines(outline.getChildren())); - - return e; - } - - protected List generateOutlines(List outlines) { - ArrayList elements = new ArrayList(); - - for (int i = 0; (outlines != null) && (i < outlines.size()); i++) { - elements.add(generateOutline((Outline) outlines.get(i))); - } - - return elements; - } - - protected String intArrayToCsvString(int[] value) { - if ((value == null) || (value.length == 0)) { - return null; - } - - StringBuffer sb = new StringBuffer(); - sb.append(value[0]); - - for (int i = 1; i < value.length; i++) { - sb.append(","); - sb.append(value[i]); - } - - return sb.toString(); - } -} diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java deleted file mode 100644 index f8bab46..0000000 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Opml10Parser.java - * - * Created on April 24, 2006, 11:34 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.syndication.io.impl; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.WireFeedParser; - -import org.jdom.Document; -import org.jdom.Element; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * - * @author Robert "kebernet" Cooper - */ -public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { - private static Logger LOG = Logger.getLogger(OPML10Parser.class.getName()); - - /** Creates a new instance of Opml10Parser */ - public OPML10Parser() { - super("opml_1.0", null); - } - - public OPML10Parser(String type) { - super(type, null); - } - - /** - * Inspects an XML Document (JDOM) to check if it can parse it. - *

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

- * - * @param document XML Document (JDOM) to check if it can be parsed by this parser. - * @return true if the parser know how to parser this feed, false otherwise. - */ - public boolean isMyType(Document document) { - Element e = document.getRootElement(); - - if (e.getName().equals("opml") - && ( e.getChild("head") == null || e.getChild("head").getChild("docs") == null) - && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { - return true; - } - - return false; - } - - /** - * Parses an XML document (JDOM Document) into a feed bean. - *

- * - * @param document XML document (JDOM) to parse. - * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). - * @return the resulting feed bean. - * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. - * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). - */ - public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { - Opml opml = new Opml(); - opml.setFeedType("opml_1.0"); - - Element root = document.getRootElement(); - Element head = root.getChild("head"); - - if (head != null) { - opml.setTitle(head.getChildText("title")); - - if (head.getChildText("dateCreated") != null) { - opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"))); - } - - if (head.getChildText("dateModified") != null) { - opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"))); - } - - opml.setOwnerName(head.getChildTextTrim("ownerName")); - opml.setOwnerEmail(head.getChildTextTrim("ownerEmail")); - opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState"))); - } - - try { - opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); - } catch (NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowBottom", nfe); - - if (validate) { - throw new FeedException("Unable to parse windowBottom", nfe); - } - } - - try { - opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); - } catch (NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); - } - - try { - opml.setWindowRight(readInteger(head.getChildText("windowRight"))); - } catch (NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowRight", nfe); - - if (validate) { - throw new FeedException("Unable to parse windowRight", nfe); - } - } - - try { - opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); - } catch (NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); - - if (validate) { - throw new FeedException("Unable to parse windowLeft", nfe); - } - } - - try { - opml.setWindowTop(readInteger(head.getChildText("windowTop"))); - } catch (NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowTop", nfe); - - if (validate) { - throw new FeedException("Unable to parse windowTop", nfe); - } - } - - try { - opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); - } catch (NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse expansionState", nfe); - - if (validate) { - throw new FeedException("Unable to parse expansionState", nfe); - } - } - - opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate)); - opml.setModules(this.parseFeedModules(root)); - - return opml; - } - - protected Outline parseOutline(Element e, boolean validate) throws FeedException { - if (!e.getName().equals("outline")) { - throw new RuntimeException("Not an outline element."); - } - - Outline outline = new Outline(); - outline.setText(e.getAttributeValue("text")); - outline.setType(e.getAttributeValue("type")); - outline.setTitle(e.getAttributeValue("title")); - - List jAttributes = e.getAttributes(); - ArrayList attributes = new ArrayList(); - - for (int i = 0; i < jAttributes.size(); i++) { - org.jdom.Attribute a = (org.jdom.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")) { - attributes.add(new Attribute(a.getName(), a.getValue())); - } - } - - outline.setAttributes(attributes); - - try { - outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); - } catch (Exception ex) { - LOG.log(Level.WARNING, "Unable to parse isBreakpoint value", ex); - - if (validate) { - throw new FeedException("Unable to parse isBreakpoint value", ex); - } - } - - try { - outline.setComment(readBoolean(e.getAttributeValue("isComment"))); - } catch (Exception ex) { - LOG.log(Level.WARNING, "Unable to parse isComment value", ex); - - if (validate) { - throw new FeedException("Unable to parse isComment value", ex); - } - } - - List children = e.getChildren("outline"); - outline.setModules(this.parseItemModules(e)); - outline.setChildren(parseOutlines(children, validate)); - - return outline; - } - - protected List parseOutlines(List elements, boolean validate) throws FeedException { - ArrayList results = new ArrayList(); - - for (int i = 0; i < elements.size(); i++) { - results.add(parseOutline((Element) elements.get(i), validate)); - } - - return results; - } - - protected boolean readBoolean(String value) { - if (value == null) { - return false; - } else { - return Boolean.getBoolean(value.trim()); - } - } - - protected int[] readIntArray(String value) { - if (value == null) { - return null; - } else { - StringTokenizer tok = new StringTokenizer(value, ","); - int[] result = new int[tok.countTokens()]; - int count = 0; - - while (tok.hasMoreElements()) { - result[count] = Integer.parseInt(tok.nextToken().trim()); - count++; - } - - return result; - } - } - - protected Integer readInteger(String value) { - if (value != null) { - return new Integer(value); - } else { - return null; - } - } -} diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java deleted file mode 100644 index 69661c0..0000000 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * OPML20Generator.java - * - * Created on April 25, 2006, 5:31 PM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ -package com.sun.syndication.io.impl; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; - -import org.jdom.Document; -import org.jdom.Element; - - -/** - * - * @author cooper - */ -public class OPML20Generator extends OPML10Generator { - /** Creates a new instance of OPML20Generator */ - public OPML20Generator() { - } - - /** - * Returns the type of feed the generator creates. - *

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

- */ - public String getType() { - return "opml_2.0"; - } - - /** - * Creates an XML document (JDOM) for the given feed bean. - *

- * - * @param feed the feed bean to generate the XML document from. - * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not - * match with the type of the WireFeedGenerator. - * @throws FeedException thrown if the XML Document could not be created. - */ - public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { - Document retValue; - - retValue = super.generate(feed); - retValue.getRootElement().setAttribute("version", "2.0"); - - return retValue; - } - - protected Element generateHead(Opml opml) { - Element retValue; - - retValue = super.generateHead(opml); - - Element docs = new Element("docs", opml.getDocs()); - retValue.addContent(docs); - - return retValue; - } - - protected Element generateOutline(Outline outline) { - Element retValue; - - retValue = super.generateOutline(outline); - - if (outline.getCreated() != null) { - retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated())); - } - - return retValue; - } -} diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java deleted file mode 100644 index f8e9bdf..0000000 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Opml20Parser.java - * - * Created on April 25, 2006, 1:04 AM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.syndication.io.impl; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; - -import org.jdom.Document; -import org.jdom.Element; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - - -/** - * - * @author cooper - */ -public class OPML20Parser extends OPML10Parser { - /** Creates a new instance of Opml20Parser */ - public OPML20Parser() { - super("opml_2.0"); - } - - /** - * Inspects an XML Document (JDOM) to check if it can parse it. - *

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

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

- * - * @param document XML document (JDOM) to parse. - * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). - * @return the resulting feed bean. - * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. - * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). - */ - public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { - Opml opml; - opml = (Opml) super.parse(document, validate); - - Element head = document.getRootElement().getChild("head"); - - if (head != null) { - opml.setOwnerId(head.getChildTextTrim("ownerId")); - opml.setDocs(head.getChildTextTrim("docs")); - - if (opml.getDocs() == null) { - opml.setDocs("http://www.opml.org/spec2"); - } - } - - opml.setFeedType("opml_2.0"); - - return opml; - } - - protected Outline parseOutline(Element e, boolean validate) throws FeedException { - Outline retValue; - - retValue = super.parseOutline(e, validate); - - if (e.getAttributeValue("created") != null) { - retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"))); - } - - List atts = retValue.getAttributes(); - - for (int i = 0; i < atts.size(); i++) { - Attribute a = (Attribute) atts.get(i); - - if (a.getName().equals("created")) { - retValue.getAttributes().remove(a); - - break; - } - } - - return retValue; - } -} diff --git a/src/main/java/com/sun/syndication/io/impl/package.html b/src/main/java/com/sun/syndication/io/impl/package.html deleted file mode 100644 index 64d1989..0000000 --- a/src/main/java/com/sun/syndication/io/impl/package.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - This package contains the feed parsers for OPML1 and OPML2. - - -

- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-    
- - - diff --git a/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java b/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java deleted file mode 100644 index b181f26..0000000 --- a/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.sun.syndication.unittest; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; - -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.ObjectInputStream; - -/** - * - *

- * @author Alejandro Abdelnur - * - */ -public abstract class FeedOpsTest extends FeedTest { - - protected FeedOpsTest(String feedType) { - super(feedType+".xml"); - System.out.println("Testing "+feedType+".xml"); - new File("target/test-reports").mkdirs(); - } - - //1.2a - public void testWireFeedEquals() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = getWireFeed(); - assertTrue(feed1.equals(feed2)); - } - - //1.2b - public void testWireFeedNotEqual() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = getWireFeed(); - feed2.setFeedType("dummy"); - assertFalse(feed1.equals(feed2)); - } - - //1.3 - public void testWireFeedCloning() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = (WireFeed) feed1.clone();; - assertTrue(feed1.equals(feed2)); - } - - // 1.4 - public void testWireFeedSerialization() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(feed1); - oos.close(); - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - WireFeed feed2 = (WireFeed) ois.readObject(); - ois.close(); - - assertTrue(feed1.equals(feed2)); - } - - // 1.6 - public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - - assertEquals(sFeed1, sFeed2 ); - } - - //1.7a - public void testSyndFeedEquals() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(); - assertTrue(feed1.equals(feed2)); - } - - //1.7b - public void testSyndFeedNotEqual() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(); - feed2.setFeedType("dummy"); - assertFalse(feed1.equals(feed2)); - } - - //1.8 - public void testSyndFeedCloning() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = (SyndFeed) feed1.clone();; - assertTrue(feed1.equals(feed2)); - } - - //1.9 - public void testSyndFeedSerialization() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(feed1); - oos.close(); - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - SyndFeed feed2 = (SyndFeed) ois.readObject(); - ois.close(); - - assertTrue(feed1.equals(feed2)); - } - -} diff --git a/src/test/java/com/sun/syndication/unittest/FeedTest.java b/src/test/java/com/sun/syndication/unittest/FeedTest.java deleted file mode 100644 index f881c4c..0000000 --- a/src/test/java/com/sun/syndication/unittest/FeedTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.sun.syndication.unittest; - -import junit.framework.TestCase; - -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.io.SyndFeedInput; -import com.sun.syndication.io.WireFeedInput; - -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.InputStream; - -import org.jdom.Document; -import org.jdom.input.SAXBuilder; - -/** - * @author pat, tucu - * - */ -public abstract class FeedTest extends TestCase { - private String _feedFileName; - private Document _jDomDoc = null; - private WireFeed _wireFeed = null; - private SyndFeed _syndFeed = null; - - protected FeedTest(String feedFileName) { - _feedFileName = feedFileName; - } - - protected String getFeedFileName() { - return _feedFileName; - } - - protected Reader getFeedReader() throws Exception { - InputStream resource = Thread.currentThread(). - getContextClassLoader().getResourceAsStream(getFeedFileName()); - assertNotNull("Could not find resource " + getFeedFileName(), resource); - return new InputStreamReader(resource); - } - - protected Document getJDomDoc() throws Exception { - SAXBuilder saxBuilder = new SAXBuilder(false); - return saxBuilder.build(getFeedReader()); - } - - protected WireFeed getWireFeed() throws Exception { - WireFeedInput in = new WireFeedInput(); - return in.build(getFeedReader()); - } - - protected SyndFeed getSyndFeed() throws Exception { - SyndFeedInput in = new SyndFeedInput(); - return in.build(getFeedReader()); - } - - protected Document getCachedJDomDoc() throws Exception { - if (_jDomDoc==null) { - _jDomDoc = getJDomDoc(); - } - return _jDomDoc; - } - - protected WireFeed getCachedWireFeed() throws Exception { - if (_wireFeed==null) { - _wireFeed = getWireFeed(); - } - return _wireFeed; - } - - protected SyndFeed getCachedSyndFeed() throws Exception { - if (_syndFeed==null) { - _syndFeed = getSyndFeed(); - } - return _syndFeed; - } - -} diff --git a/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java b/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java deleted file mode 100644 index 2d28d91..0000000 --- a/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Created on Jun 22, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package com.sun.syndication.unittest; - - - - -/** - * @author pat - * - */ -public abstract class SyndFeedTest extends FeedTest { - private String _prefix = null; - - protected SyndFeedTest(String feedType) { - this(feedType,feedType+".xml"); - } - - protected SyndFeedTest(String feedType,String feedFileName) { - super(feedFileName); - _prefix = feedType; - } - - protected String getPrefix() { - return _prefix; - } - - protected void assertProperty(String property, String value) { - assertEquals(property,getPrefix() + "." + value); - } - - public void testType() throws Exception { - assertEquals(getCachedSyndFeed().getFeedType(),getPrefix()); - } - - -/* - public void testType() throws Exception { - assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); - } - - public void testTitle() throws Exception { - assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); - } - - public void testLink() throws Exception { - assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); - } - - public void testDescription() throws Exception { - assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); - } - - public void testLanguage() throws Exception { - assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); - } - - public void testCategories() throws Exception { - List catlist = getCachedSyndFeed().getCategories(); - //don't understand why this one fails - assertEquals(2, catlist.size()); - SyndCategory cat = (SyndCategory)catlist.get(0); - assertEqualsStr("channel.category[0]", cat.getName()); - assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEqualsStr("channel.category[1]", cat.getName()); - assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); - } - - public void testPublishedDate() throws Exception { - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getCachedSyndFeed().getPublishedDate()); - } - - //how do i get height and width? - public void testImage() throws Exception { - SyndImage img = getCachedSyndFeed().getImage(); - assertEqualsStr("channel.image.description", img.getDescription()); - assertEqualsStr("channel.image.link", img.getLink()); - assertEqualsStr("channel.image.title", img.getTitle()); - assertEqualsStr("channel.image.url", img.getUrl()); - } - - public void testEntries() throws Exception { - List entrylist = getCachedSyndFeed().getEntries(); - assertEquals(2, entrylist.size()); - } - - public void testEntryTitle() throws Exception { - assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryTitle(Object o) throws Exception { - SyndEntry e = (SyndEntry) o; - return e.getTitle(); - } - - public void testEntryDescription() throws Exception { - assertEqualsStr("channel.item[0].description", getEntryDescription(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].description", getEntryDescription(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryDescription(Object o) throws Exception { - SyndEntry e = (SyndEntry) o; - return e.getDescription().getValue(); - } - - public void testEntryLink() throws Exception { - assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryLink(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getLink(); - } - - public void testEntryPublishedDate() throws Exception { - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); - } - - public Date getEntryPublishedDate(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getPublishedDate(); - } - - public void testEntryCategories() throws Exception { - SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); - List catlist = e.getCategories(); - //don't understand why this one fails - assertEquals(2, catlist.size()); - SyndCategory cat = (SyndCategory)catlist.get(0); - assertEqualsStr("channel.item[0].category[0]", cat.getName()); - assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEqualsStr("channel.item[0].category[1]", cat.getName()); - assertEqualsStr("channel.item[0].category[1]^domain", cat.getTaxonomyUri()); - //DO 2nd set of items - } - - public void testEntryAuthor() throws Exception { - assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryAuthor(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getAuthor(); - } - -*/ -/* -//things you cannot get from SyndEntryImpl -// item[0].source -// -// - item0.category0 - item0.category1 - Thu, 08 Jul 1999 08:00:00 GMT - Thu, 08 Jul 1999 09:00:00 GMT - item0.author - http://localhost:8080/item0/comments - http://localhost:8080/item0/guid - //TODO: I still have the elements to test -*/ - /* - public void test() { - assertEqualsStr(feed, ""); - } - - public void test() { - assertEqualsStr(feed, ""); - } - - */ - //Things that you cannot get form a SyndFeedImpl today - //these need to be put in a RSS 2.0 module - //or is a roundtrip to wirefeed the right way to do this? -/* - * - Search - Search this site: - q - http://example.org/mt/mt-search.cgi - - - image height and width - * - //Copyright 2004, Mark Pilgrim - public void test() { - assertEqualsStr(getCachedSyndFeed()., ""); - } - - //Sample Toolkit - public void test() { - assertEqualsStr(feed, ""); - } - - // editor@example.org - public void test() { - assertEqualsStr(feed, ""); - } - - // webmaster@example.org - public void test() { - assertEqualsStr(feed, ""); - } - - http://blogs.law.harvard.edu/tech/rss - - 60 - - - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9.5 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - - - Monday - Tuesday - Wednesday - Thursday - Friday - Saturday - Sunday - - -**/ - - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - - - -} diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java b/src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java deleted file mode 100644 index 83aef02..0000000 --- a/src/test/java/com/sun/syndication/unittest/TestOpsOPML10.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * TestOpsOPML10.java - * - * Created on April 25, 2006, 4:26 PM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ - -package com.sun.syndication.unittest; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import java.io.FileOutputStream; -import java.io.PrintWriter; - -/** - * - * @author cooper - */ -public class TestOpsOPML10 extends FeedOpsTest{ - - /** Creates a new instance of TestOpsOPML10 */ - public TestOpsOPML10() { - super("opml_1.0"); - } - - // 1.6 - public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); - w.println( sFeed1.toString() ); - w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); - w.println( sFeed2.toString() ); - w.close(); - - assertEquals(sFeed1, sFeed2); - } - - - - -} diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java b/src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java deleted file mode 100644 index 4364767..0000000 --- a/src/test/java/com/sun/syndication/unittest/TestOpsOPML10links.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * TestOpsOPML10.java - * - * Created on April 25, 2006, 4:26 PM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ - -package com.sun.syndication.unittest; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import com.sun.syndication.io.WireFeedInput; -import com.sun.syndication.io.WireFeedOutput; -import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintWriter; - -/** - * - * @author cooper - */ -public class TestOpsOPML10links extends FeedOpsTest{ - - /** Creates a new instance of TestOpsOPML10 */ - public TestOpsOPML10links() { - super("opml_1.0_links"); - } - - // 1.6 - public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - //System.out.println( wFeed1 ); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); - w.println( sFeed1.toString() ); - w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); - w.println( sFeed2.toString() ); - w.close(); - - assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed()); - } - - - - public void testTemp() throws Exception { - WireFeedInput input = new WireFeedInput(); - WireFeed wf = input.build( new File( System.getProperty("basedir")+ "/src/test/resources/opml_1.0_links.xml")); - WireFeedOutput output = new WireFeedOutput(); - //System.out.println( wf ); - - //System.out.println( "================================="); - //System.out.println( new SyndFeedImpl( wf) ); - SyndFeedImpl sf = new SyndFeedImpl( wf); - sf.setFeedType("rss_2.0"); - sf.setDescription(""); - sf.setLink("http://foo.com"); - //output.output( sf.createWireFeed() , new PrintWriter( System.out ) ); - sf.setFeedType("opml_1.0"); - output.output( sf.createWireFeed() , new File( System.getProperty("basedir")+ "/target/test-reports/1.xml") ); - } - -} diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java b/src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java deleted file mode 100644 index 5bac1dc..0000000 --- a/src/test/java/com/sun/syndication/unittest/TestOpsOPML20.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * TestOpsOPML20.java - * - * Created on April 25, 2006, 5:38 PM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ - -package com.sun.syndication.unittest; - -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import java.io.FileOutputStream; -import java.io.PrintWriter; - -/** - * - * @author cooper - */ -public class TestOpsOPML20 extends FeedOpsTest { - - /** Creates a new instance of TestOpsOPML20 */ - public TestOpsOPML20() { - super("opml_2.0"); - } - - - public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/3") ); - w.println( sFeed1.toString() ); - w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/4") ); - w.println( sFeed2.toString() ); - w.close(); - assertEquals(sFeed1, sFeed2 ); - } - -} diff --git a/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java b/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java deleted file mode 100644 index 9fa434d..0000000 --- a/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package com.sun.syndication.unittest; - -import com.sun.syndication.io.XmlReader; -import com.sun.syndication.io.impl.XmlFixerReader; -import junit.framework.TestCase; -import org.jdom.input.SAXBuilder; - -import java.io.*; - -/** - * @author pat, tucu - * - */ -public class TestXmlFixerReader extends TestCase { - private static final String XML_PROLOG = ""; - - public void testTrim() throws Exception { - _testValidTrim("",""); - _testValidTrim("",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" \n",""); - _testValidTrim(" \n",XML_PROLOG+""); - _testValidTrim("",""); - _testValidTrim("",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" \n ",""); - _testValidTrim(" \n ",XML_PROLOG+""); - - _testInvalidTrim("x",""); - _testInvalidTrim("x",XML_PROLOG+""); - _testInvalidTrim(" x",""); - _testInvalidTrim(" x",XML_PROLOG+""); - _testInvalidTrim(" x\n",""); - _testInvalidTrim(" x\n",XML_PROLOG+""); - _testInvalidTrim("x ",""); - _testInvalidTrim(" x ",XML_PROLOG+""); - _testInvalidTrim(" x ",""); - _testInvalidTrim(" x ",XML_PROLOG+""); - _testInvalidTrim(" x\n ",""); - _testInvalidTrim(" x\n ",XML_PROLOG+""); - } - - public void testHtmlEntities() throws Exception { - _testValidEntities(""); - _testValidEntities(XML_PROLOG+""); - _testValidEntities(" \n"+XML_PROLOG+""); - - _testValidEntities("'¥ú¥"); - _testValidEntities(XML_PROLOG+"'¥ú¥"); - _testValidEntities(" \n"+XML_PROLOG+"'¥ú¥"); - - _testInvalidEntities("'&yexn;ú¥"); - _testInvalidEntities(XML_PROLOG+"'&yexn;ú¥"); - _testInvalidEntities(" \n"+XML_PROLOG+"'&yexn;ú¥"); - - _testInvalidEntities("'¥x50;¥"); - _testInvalidEntities(XML_PROLOG+"'¥x50;¥"); - _testInvalidEntities(" \n"+XML_PROLOG+"'¥x50;¥"); - - } - - protected void _testXmlParse(String garbish,String xmlDoc) throws Exception { - InputStream is = getStream(garbish,xmlDoc); - Reader reader = new XmlReader(is); - reader = new XmlFixerReader(reader); - SAXBuilder saxBuilder = new SAXBuilder(); - saxBuilder.build(reader); - } - - protected void _testValidTrim(String garbish,String xmlDoc) throws Exception { - _testXmlParse(garbish,xmlDoc); - } - - protected void _testInvalidTrim(String garbish,String xmlDoc) throws Exception { - try { - _testXmlParse(garbish,xmlDoc); - assertTrue(false); - } - catch (Exception ex) { - } - } - - protected void _testValidEntities(String xmlDoc) throws Exception { - _testXmlParse("",xmlDoc); - } - - protected void _testInvalidEntities(String xmlDoc) throws Exception { - try { - _testXmlParse("",xmlDoc); - assertTrue(false); - } - catch (Exception ex) { - } - } - - // XML Stream generator - - protected InputStream getStream(String garbish,String xmlDoc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - Writer writer = new OutputStreamWriter(baos); - writer.write(garbish); - writer.write(xmlDoc); - writer.close(); - return new ByteArrayInputStream(baos.toByteArray()); - } - - -} diff --git a/src/test/java/com/sun/syndication/unittest/TestXmlReader.java b/src/test/java/com/sun/syndication/unittest/TestXmlReader.java deleted file mode 100644 index b8dedbc..0000000 --- a/src/test/java/com/sun/syndication/unittest/TestXmlReader.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package com.sun.syndication.unittest; - -import com.sun.syndication.io.XmlReader; -import junit.framework.TestCase; - -import java.io.*; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - -/** - * @author pat, tucu - * - */ -public class TestXmlReader extends TestCase { - - public static void main(String[] args) throws Exception { - TestXmlReader test = new TestXmlReader(); - test.testRawBom(); - test.testRawNoBom(); - test.testHttp(); - } - - protected void _testRawNoBomValid(String encoding) throws Exception { - InputStream is = getXmlStream("no-bom","xml",encoding,encoding); - XmlReader xmlReader = new XmlReader(is,false); - assertEquals(xmlReader.getEncoding(),"UTF-8"); - - is = getXmlStream("no-bom","xml-prolog",encoding,encoding); - xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),"UTF-8"); - - is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); - xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),encoding); - } - - protected void _testRawNoBomInvalid(String encoding) throws Exception { - InputStream is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); - try { - XmlReader xmlReader = new XmlReader(is,false); - fail("It should have failed"); - } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } - - public void testRawNoBom() throws Exception { - _testRawNoBomValid("US-ASCII"); - _testRawNoBomValid("UTF-8"); - _testRawNoBomValid("ISO-8859-1"); - } - - protected void _testRawBomValid(String encoding) throws Exception { - InputStream is = getXmlStream(encoding+"-bom","xml-prolog-encoding",encoding,encoding); - XmlReader xmlReader = new XmlReader(is,false); - if (!encoding.equals("UTF-16")) { - assertEquals(xmlReader.getEncoding(),encoding); - } - else { - assertEquals(xmlReader.getEncoding().substring(0,encoding.length()),encoding); - } - } - - protected void _testRawBomInvalid(String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,"xml-prolog-encoding",streamEnc,prologEnc); - try { - XmlReader xmlReader = new XmlReader(is,false); - fail("It should have failed for BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); - } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } - - public void testRawBom() throws Exception { - _testRawBomValid("UTF-8"); - _testRawBomValid("UTF-16BE"); - _testRawBomValid("UTF-16LE"); - _testRawBomValid("UTF-16"); - - _testRawBomInvalid("UTF-8-bom","US-ASCII","US-ASCII"); - _testRawBomInvalid("UTF-8-bom","ISO-8859-1","ISO-8859-1"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16BE"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16LE"); - _testRawBomInvalid("UTF-16BE-bom","UTF-16BE","UTF-16LE"); - _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-16BE"); - _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-8"); - } - - public void testHttp() throws Exception { - _testHttpValid("application/xml","no-bom","US-ASCII",null); - _testHttpValid("application/xml","UTF-8-bom","US-ASCII",null); - _testHttpValid("application/xml","UTF-8-bom","UTF-8",null); - _testHttpValid("application/xml","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); - _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("application/xml","UTF-8-bom","US-ASCII","US-ASCII"); - _testHttpInvalid("application/xml;charset=UTF-16","UTF-16LE","UTF-8","UTF-8"); - _testHttpInvalid("application/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); - - _testHttpValid("text/xml","no-bom","US-ASCII",null); - _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpValid("text/xml","UTF-8-bom","US-ASCII",null); - - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE",null); - - _testHttpLenient("text/xml","no-bom","US-ASCII",null, "US-ASCII"); - _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8", "UTF-8"); - _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null, "UTF-8"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml","UTF-8-bom","US-ASCII",null, "US-ASCII"); - - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE",null, "UTF-16"); - - _testHttpLenient("text/html","no-bom","US-ASCII","US-ASCII", "US-ASCII"); - _testHttpLenient("text/html","no-bom","US-ASCII",null, "US-ASCII"); - _testHttpLenient("text/html;charset=UTF-8","no-bom","US-ASCII","UTF-8", "UTF-8"); - _testHttpLenient("text/html;charset=UTF-16BE","no-bom","US-ASCII","UTF-8", "UTF-8"); - } - - public void _testHttpValid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml":"xml-prolog-encoding",streamEnc,prologEnc); - XmlReader xmlReader = new XmlReader(is,cT,false); - if (!streamEnc.equals("UTF-16")) { - // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection - } - else { - assertEquals(xmlReader.getEncoding().substring(0,streamEnc.length()),streamEnc); - } - } - - protected void _testHttpInvalid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); - try { - XmlReader xmlReader = new XmlReader(is,cT,false); - fail("It should have failed for HTTP Content-type "+cT+", BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); - } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } - - protected void _testHttpLenient(String cT, String bomEnc, String streamEnc, String prologEnc, String shouldbe) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); - XmlReader xmlReader = new XmlReader(is,cT,true); - assertEquals(xmlReader.getEncoding(),shouldbe); - } - - // XML Stream generator - - private static final int[] NO_BOM_BYTES = {}; - private static final int[] UTF_16BE_BOM_BYTES = {0xFE,0xFF}; - private static final int[] UTF_16LE_BOM_BYTES = {0xFF,0XFE}; - private static final int[] UTF_8_BOM_BYTES = {0xEF,0xBB,0xBF}; - - private static final Map BOMs = new HashMap(); - - static { - BOMs.put("no-bom",NO_BOM_BYTES); - BOMs.put("UTF-16BE-bom",UTF_16BE_BOM_BYTES); - BOMs.put("UTF-16LE-bom",UTF_16LE_BOM_BYTES); - BOMs.put("UTF-16-bom",NO_BOM_BYTES); // it's added by the writer - BOMs.put("UTF-8-bom",UTF_8_BOM_BYTES); - } - - private static final MessageFormat XML = new MessageFormat( - "{2}"); - private static final MessageFormat XML_WITH_PROLOG = new MessageFormat( - "\n{2}"); - private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat( - "\n{2}"); - - private static final MessageFormat INFO = new MessageFormat( - "\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); - - private static final Map XMLs = new HashMap(); - - static { - XMLs.put("xml",XML); - XMLs.put("xml-prolog",XML_WITH_PROLOG); - XMLs.put("xml-prolog-encoding",XML_WITH_PROLOG_AND_ENCODING); - } - - /** - * - * @param bomType no-bom, UTF-16BE-bom, UTF-16LE-bom, UTF-8-bom - * @param xmlType xml, xml-prolog, xml-prolog-charset - * @return XML stream - */ - protected InputStream getXmlStream(String bomType,String xmlType,String streamEnc,String prologEnc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - int[] bom = (int[]) BOMs.get(bomType); - if (bom==null) { - bom = new int[0]; - } - MessageFormat xml = (MessageFormat) XMLs.get(xmlType); - for (int i=0;i\n"); - for (int i=0;i<10000;i++) { - writer.write("\n"); - } - writer.write("\n"); - - writer.close(); - return new ByteArrayInputStream(baos.toByteArray()); - } - - -} From 1e1207404b221d088f81fa31b5cc882cb464b3a1 Mon Sep 17 00:00:00 2001 From: kebernet Date: Mon, 14 Mar 2011 23:44:51 +0000 Subject: [PATCH 05/47] Initial refactoring. --- pom.xml | 6 +- .../org/rometools/feed/opml/Attribute.java | 107 +++++ .../java/org/rometools/feed/opml/Opml.java | 280 +++++++++++++ .../java/org/rometools/feed/opml/Outline.java | 343 ++++++++++++++++ .../java/org/rometools/feed/opml/package.html | 47 +++ .../feed/synd/impl/ConverterForOPML10.java | 374 ++++++++++++++++++ .../feed/synd/impl/ConverterForOPML20.java | 64 +++ .../feed/synd/impl/TreeCategoryImpl.java | 34 ++ .../org/rometools/feed/synd/impl/package.html | 30 ++ .../rometools/io/impl/OPML10Generator.java | 189 +++++++++ .../org/rometools/io/impl/OPML10Parser.java | 263 ++++++++++++ .../rometools/io/impl/OPML20Generator.java | 83 ++++ .../org/rometools/io/impl/OPML20Parser.java | 117 ++++++ .../java/org/rometools/io/impl/package.html | 28 ++ .../org/rometools/unittest/FeedOpsTest.java | 114 ++++++ .../java/org/rometools/unittest/FeedTest.java | 78 ++++ .../org/rometools/unittest/SyndFeedTest.java | 267 +++++++++++++ .../org/rometools/unittest/TestOpsOPML10.java | 47 +++ .../unittest/TestOpsOPML10links.java | 67 ++++ .../org/rometools/unittest/TestOpsOPML20.java | 43 ++ .../unittest/TestXmlFixerReader.java | 134 +++++++ .../org/rometools/unittest/TestXmlReader.java | 257 ++++++++++++ 22 files changed, 2971 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/rometools/feed/opml/Attribute.java create mode 100644 src/main/java/org/rometools/feed/opml/Opml.java create mode 100644 src/main/java/org/rometools/feed/opml/Outline.java create mode 100644 src/main/java/org/rometools/feed/opml/package.html create mode 100644 src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java create mode 100644 src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java create mode 100644 src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java create mode 100644 src/main/java/org/rometools/feed/synd/impl/package.html create mode 100644 src/main/java/org/rometools/io/impl/OPML10Generator.java create mode 100644 src/main/java/org/rometools/io/impl/OPML10Parser.java create mode 100644 src/main/java/org/rometools/io/impl/OPML20Generator.java create mode 100644 src/main/java/org/rometools/io/impl/OPML20Parser.java create mode 100644 src/main/java/org/rometools/io/impl/package.html create mode 100644 src/test/java/org/rometools/unittest/FeedOpsTest.java create mode 100644 src/test/java/org/rometools/unittest/FeedTest.java create mode 100644 src/test/java/org/rometools/unittest/SyndFeedTest.java create mode 100644 src/test/java/org/rometools/unittest/TestOpsOPML10.java create mode 100644 src/test/java/org/rometools/unittest/TestOpsOPML10links.java create mode 100644 src/test/java/org/rometools/unittest/TestOpsOPML20.java create mode 100644 src/test/java/org/rometools/unittest/TestXmlFixerReader.java create mode 100644 src/test/java/org/rometools/unittest/TestXmlReader.java diff --git a/pom.xml b/pom.xml index c288c86..b75e5bf 100644 --- a/pom.xml +++ b/pom.xml @@ -5,9 +5,13 @@ org.rometools rome-opml jar - 1.0 + 1.5-SNAPSHOT rome-opml http://rometools.jira.com + Support for OPML 1 and OPML 2 in ROME + + https://rometools.jira.com/secure/IssueNavigator.jspa + kebernet diff --git a/src/main/java/org/rometools/feed/opml/Attribute.java b/src/main/java/org/rometools/feed/opml/Attribute.java new file mode 100644 index 0000000..a29770c --- /dev/null +++ b/src/main/java/org/rometools/feed/opml/Attribute.java @@ -0,0 +1,107 @@ +/* + * Attribute.java + * + * Created on April 24, 2006, 11:11 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rometools.feed.opml; + +import com.sun.syndication.feed.impl.EqualsBean; +import com.sun.syndication.feed.impl.ToStringBean; + +import java.io.Serializable; + + +/** + * This is a simple name-value pair attribute for outlines. + * + * @author Robert "kebernet" Cooper + */ +public class Attribute implements Cloneable, Serializable { + private String _name; + private String _value; + + /** Creates a new instance of Attribute */ + public Attribute() { + super(); + } + + /** + * Creates a new instance of Attribute. + * @param name name of the attribute. + * @param value value of the attribute. + */ + public Attribute(String name, String value) { + if ((name == null) || (value == null)) { + throw new NullPointerException("Name and value are required."); + } + + this.setName(name); + this.setValue(value); + } + + /** + * name of the attribute. + * @param name name of the attribute. + */ + public void setName(String name) { + this._name = name; + } + + /** + * name of the attribute. + * @return name of the attribute. + */ + public String getName() { + return _name; + } + + /** + * value of the attribute. + * @param value value of the attribute. + */ + public void setValue(String value) { + this._value = value; + } + + /** + * value of the attribute. + * @return value of the attribute. + */ + public String getValue() { + return _value; + } + + public Object clone() { + return new Attribute(this._name, this._value); + } + + public boolean equals(Object obj) { + EqualsBean eBean = new EqualsBean(Attribute.class, this); + + return eBean.beanEquals(obj); + } + + public int hashCode() { + EqualsBean equals = new EqualsBean(Attribute.class, this); + + return equals.beanHashCode(); + } + + public String toString() { + ToStringBean tsBean = new ToStringBean(Attribute.class, this); + + return tsBean.toString(); + } +} diff --git a/src/main/java/org/rometools/feed/opml/Opml.java b/src/main/java/org/rometools/feed/opml/Opml.java new file mode 100644 index 0000000..0f5d025 --- /dev/null +++ b/src/main/java/org/rometools/feed/opml/Opml.java @@ -0,0 +1,280 @@ +/* + * Opml.java + * + * Created on April 24, 2006, 11:00 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rometools.feed.opml; + +import com.sun.syndication.feed.WireFeed; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +/** + * This class represents the root of an OPML 1/2 feed and contains the elements that + * may appear in the <head> tag of the feed. + * @author Robert "kebernet" Cooper + */ +public class Opml extends WireFeed { + private Date _created; + private Date _modified; + private Integer _verticalScrollState; + private Integer _windowBottom; + private Integer _windowLeft; + private Integer _windowRight; + private Integer _windowTop; + private List _outlines; + private String _docs; + private String _ownerEmail; + private String _ownerId; + private String _ownerName; + private String _title; + private int[] _expansionState; + + /** Creates a new instance of Opml */ + public Opml() { + super(); + } + + /** + * is a date-time, indicating when the document was created. + * @param created date-time, indicating when the document was created. + */ + public void setCreated(Date created) { + this._created = created; + } + + /** + * <dateCreated> is a date-time, indicating when the document was created. + * @return date-time, indicating when the document was created. + */ + public Date getCreated() { + return _created; + } + + /** + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * @param docs http address of documentation for the format used + */ + public void setDocs(String docs) { + this._docs = docs; + } + + /** + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * @return http address of documentation for the format used + */ + public String getDocs() { + return _docs; + } + + /** + * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * @param expansionState int array containing expanded elements. + */ + public void setExpansionState(int[] expansionState) { + this._expansionState = expansionState; + } + + /** + * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * @return int array containing expanded elements. + */ + public int[] getExpansionState() { + return _expansionState; + } + + /** + * <dateModified> is a date-time, indicating when the document was last modified. + * @param modified date-time, indicating when the document was last modified. + */ + public void setModified(Date modified) { + this._modified = modified; + } + + /** + * <dateModified> is a date-time, indicating when the document was last modified. + * @return date-time, indicating when the document was last modified. + */ + public Date getModified() { + return _modified; + } + + /** + * Root level Outline object that should appear in the <body> + * @param outlines Root level Outline object that should appear in the <body> + */ + public void setOutlines(List outlines) { + this._outlines = outlines; + } + + /** + * Root level Outline object that should appear in the <body> + * @return Root level Outline object that should appear in the <body> + */ + public List getOutlines() { + if (_outlines == null) { + _outlines = new ArrayList(); + } + + return _outlines; + } + + /** + * <ownerEmail> is a string, the email address of the owner of the document. + * @param ownerEmail the email address of the owner of the document. + */ + public void setOwnerEmail(String ownerEmail) { + this._ownerEmail = ownerEmail; + } + + /** + * <ownerEmail> is a string, the email address of the owner of the document. + * @return the email address of the owner of the document. + */ + public String getOwnerEmail() { + return _ownerEmail; + } + + /** + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + */ + public void setOwnerId(String ownerId) { + this._ownerId = ownerId; + } + + /** + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + * @return http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the document via email or other means. + */ + public String getOwnerId() { + return _ownerId; + } + + /** + * <ownerName> is a string, the owner of the document. + * @param ownerName the owner of the document. + */ + public void setOwnerName(String ownerName) { + this._ownerName = ownerName; + } + + /** + * <ownerName> is a string, the owner of the document. + * @return the owner of the document. + */ + public String getOwnerName() { + return _ownerName; + } + + /** + * <title> is the title of the document. + * @param title title of the document. + */ + public void setTitle(String title) { + this._title = title; + } + + /** + * <title> is the title of the document. + * @return title of the document. + */ + public String getTitle() { + return _title; + } + + /** + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + * @param verticalScrollState which line of the outline is displayed on the top line of the window. + */ + public void setVerticalScrollState(Integer verticalScrollState) { + this._verticalScrollState = verticalScrollState; + } + + /** + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + * @return which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. + */ + public Integer getVerticalScrollState() { + return _verticalScrollState; + } + + /** + * <windowBottom> is a number, the pixel location of the bottom edge of the window. + * @param windowBottom the pixel location of the bottom edge of the window. + */ + public void setWindowBottom(Integer windowBottom) { + this._windowBottom = windowBottom; + } + + /** + * <windowBottom> is a number, the pixel location of the bottom edge of the window. + * @return the pixel location of the bottom edge of the window. + */ + public Integer getWindowBottom() { + return _windowBottom; + } + + /** + * <windowLeft> is a number, the pixel location of the left edge of the window. + * @param windowLeft the pixel location of the left edge of the window. + */ + public void setWindowLeft(Integer windowLeft) { + this._windowLeft = windowLeft; + } + + /** + * <windowLeft> is a number, the pixel location of the left edge of the window. + * @return the pixel location of the left edge of the window. + */ + public Integer getWindowLeft() { + return _windowLeft; + } + + /** + * <windowRight> is a number, the pixel location of the right edge of the window. + * @param windowRight the pixel location of the right edge of the window. + */ + public void setWindowRight(Integer windowRight) { + this._windowRight = windowRight; + } + + /** + * <windowRight> is a number, the pixel location of the right edge of the window. + * @return the pixel location of the right edge of the window. + */ + public Integer getWindowRight() { + return _windowRight; + } + + /** + * <windowTop> is a number, the pixel location of the top edge of the window. + * @param windowTop the pixel location of the top edge of the window. + */ + public void setWindowTop(Integer windowTop) { + this._windowTop = windowTop; + } + + /** + * <windowTop> is a number, the pixel location of the top edge of the window. + * @return the pixel location of the top edge of the window. + */ + public Integer getWindowTop() { + return _windowTop; + } +} diff --git a/src/main/java/org/rometools/feed/opml/Outline.java b/src/main/java/org/rometools/feed/opml/Outline.java new file mode 100644 index 0000000..55c0095 --- /dev/null +++ b/src/main/java/org/rometools/feed/opml/Outline.java @@ -0,0 +1,343 @@ +/* + * Outline.java + * + * Created on April 24, 2006, 11:04 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rometools.feed.opml; + +import com.sun.syndication.feed.impl.EqualsBean; +import com.sun.syndication.feed.impl.ToStringBean; + +import java.io.Serializable; + +import java.net.URL; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + + +/** + * This class represents an OPML outline element. + * @author Robert "kebernet" Cooper + */ +public class Outline implements Cloneable, Serializable { + private Date _created; + private List _attributes; + private List _categories; + private List _children; + private List _modules; + private String _text; + private String _title; + private String _type; + private boolean _breakpoint; + private boolean _comment; + + /** Creates a new instance of Outline */ + public Outline() { + super(); + } + + /** + * Creates a new outline with the specified type and text values. + * @param type type attribute value/ + * @param text text attribute value + */ + public Outline(String type, String text) { + super(); + this.setType(type); + this.setText(text); + } + + /** + * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally + * used for aggregator feed lists and will get a type of "rss". + * @param title Title of the entry. + * @param xmlUrl link to XML file. + * @param htmlUrl link to html page. + */ + public Outline(String title, URL xmlUrl, URL htmlUrl) { + super(); + this.setType("rss"); + this.setTitle(title); + this.setAttributes(new ArrayList()); + + if (xmlUrl != null) { + getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); + } + + if (htmlUrl != null) { + getAttributes().add(new Attribute("htmlUrl", htmlUrl.toString())); + } + } + + /** + * List of attributes on this outline excluding the "common types" for the specification. + * @param attributes List of attributes on this outline. + */ + public void setAttributes(List attributes) { + this._attributes = attributes; + } + + /** + * List of attributes on this outline excluding the "common types" for the specification. + * @return List of attributes on this outline. + */ + public List getAttributes() { + if (this._attributes == null) { + this._attributes = new ArrayList(); + } + + return _attributes; + } + + /** + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + * @param breakpoint whether a breakpoint is set on this outline. + */ + public void setBreakpoint(boolean breakpoint) { + this._breakpoint = breakpoint; + } + + /** + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + * @return whether a breakpoint is set on this outline + */ + public boolean isBreakpoint() { + return _breakpoint; + } + + /** + * (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) { + this._categories = categories; + } + + /** + * (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() { + if (_categories == null) { + _categories = new ArrayList(); + } + + return _categories; + } + + /** + * A list of sub-outlines for this entry. + * @param children A list of sub-outlines for this entry. + */ + public void setChildren(List children) { + this._children = children; + } + + /** + * A list of sub-outlines for this entry. + * @return A list of sub-outlines for this entry. + */ + public List getChildren() { + if (_children == null) { + _children = new ArrayList(); + } + + return _children; + } + + /** + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. + * @param comment whether the outline is commented + */ + public void setComment(boolean comment) { + this._comment = comment; + } + + /** + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not present, the value is false. + * @return whether the outline is commented + */ + public boolean isComment() { + return _comment; + } + + /** + * (OPML 2) created is the date-time that the outline node was created. + * @param created date-time that the outline node was created. + */ + public void setCreated(Date created) { + this._created = created; + } + + /** + * (OPML 2) created is the date-time that the outline node was created. + * @return date-time that the outline node was created. + */ + public Date getCreated() { + return _created; + } + + /** + * A convenience method to return the value of the url attribute. + * @return value of the htmlUrl attribute. + */ + public String getUrl() { + return getAttributeValue("url"); + } + + /** + * A convenience method to return the value of the htmlUrl attribute. + * @return value of the htmlUrl attribute. + */ + public String getHtmlUrl() { + return getAttributeValue("htmlUrl"); + } + + public void setModules(List modules) { + this._modules = modules; + } + + public List getModules() { + if (this._modules == null) { + this._modules = new ArrayList(); + } + + return _modules; + } + + /** + * The "text" attribute of the outline. + * @param text The "text" attribute of the outline. + */ + public void setText(String text) { + this._text = text; + } + + /** + * The "text" attribute of the outline. + * @return The "text" attribute of the outline. + */ + public String getText() { + return _text; + } + + /** + * The "title" attribute of the outline. + * @param title The "title" attribute of the outline. + */ + public void setTitle(String title) { + this._title = title; + } + + /** + * The "title" attribute of the outline. + * @return The "title" attribute of the outline. + */ + public String getTitle() { + return _title; + } + + /** + * The "type" attribute of the outline. + * @param type The "type" attribute of the outline. + */ + public void setType(String type) { + this._type = type; + } + + /** + * The "type" attribute of the outline. + * @return The "type" attribute of the outline. + */ + public String getType() { + return _type; + } + + /** + * A convenience method to return the value of the xmlUrl attribute. + * @return value of the xmlUrl attribute. + */ + public String getXmlUrl() { + return getAttributeValue("xmlUrl"); + } + + /** Returns the value of an attribute on the outline or null. + * @param name name of the attribute. + */ + public String getAttributeValue(String name ){ + List attributes = Collections.synchronizedList(this.getAttributes()); + + for (int i = 0; i < attributes.size(); i++) { + Attribute a = (Attribute) attributes.get(i); + + if ((a.getName() != null) && a.getName().equals(name)) { + return a.getValue(); + } + } + + return null; + } + + public Object clone() { + Outline o = new Outline(); + o.setBreakpoint(this.isBreakpoint()); + o.setCategories(new ArrayList(this.getCategories())); + o.setComment(this.isComment()); + o.setCreated((this._created != null) ? (Date) this._created.clone() : null); + o.setModules(new ArrayList(this.getModules())); + o.setText(this.getText()); + o.setTitle(this.getTitle()); + o.setType(this.getType()); + + ArrayList children = new ArrayList(); + + for (int i = 0; i < this.getChildren().size(); i++) { + children.add(((Outline) this._children.get(i)).clone()); + } + + o.setChildren(children); + + ArrayList attributes = new ArrayList(); + + for (int i = 0; i < this.getAttributes().size(); i++) { + attributes.add(((Attribute) this._attributes.get(i)).clone()); + } + + o.setAttributes(attributes); + + return o; + } + + public boolean equals(Object obj) { + EqualsBean eBean = new EqualsBean(Outline.class, this); + + return eBean.beanEquals(obj); + } + + public int hashCode() { + EqualsBean equals = new EqualsBean(Outline.class, this); + + return equals.beanHashCode(); + } + + public String toString() { + ToStringBean tsBean = new ToStringBean(Outline.class, this); + + return tsBean.toString(); + } +} diff --git a/src/main/java/org/rometools/feed/opml/package.html b/src/main/java/org/rometools/feed/opml/package.html new file mode 100644 index 0000000..3e0dfed --- /dev/null +++ b/src/main/java/org/rometools/feed/opml/package.html @@ -0,0 +1,47 @@ + + + + + + + + This package represents the base objects for OPML support for ROME. +

+ There are three classes here that are relevant. Opml, + which represents the root document and head information, + Outline which represents a single node on an Opml + outline tree, and provides convenience methods for commonly used + attributes such as xmlUrl. Finally, the + Attribute class, which represents a specific attribute + on an Outline object. Since OPML supports free-form attribute + assignments, this is a very multi-purpose class. +

+

Sample Usage: + To use this parser, simply include the jar file in your classpath + as you are using ROME. Be sure it exists at the same level as ROME, + such that, if ROME is in the common classpath of an application server, + don't include this jar in your webapps WEB-INF/lib. +

+  WireFeedInput input = new WireFeedInput();
+  Opml feed = (Opml) input.build( new File("myOpml.xml") );
+  List<Outline> outlines = (List<Outline>) feed.getOutlines();
+        
+

+ + +
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+    
+ + diff --git a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java new file mode 100644 index 0000000..efb6725 --- /dev/null +++ b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java @@ -0,0 +1,374 @@ +/* + * ConverterForOPML10.java + * + * Created on April 25, 2006, 1:26 AM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rometools.feed.synd.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Stack; +import java.util.logging.Logger; + +import com.sun.syndication.feed.WireFeed; +import org.rometools.feed.opml.Attribute; +import org.rometools.feed.opml.Opml; +import org.rometools.feed.opml.Outline; +import com.sun.syndication.feed.synd.Converter; +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndCategoryImpl; +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndLink; +import com.sun.syndication.feed.synd.SyndLinkImpl; +import com.sun.syndication.feed.synd.SyndPerson; +import com.sun.syndication.feed.synd.SyndPersonImpl; + + +/** + * + * @author cooper + */ +public class ConverterForOPML10 implements Converter { + private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName() + .toString()); + public static final String URI_TREE = "urn:rome.tree"; + public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; + + /** Creates a new instance of ConverterForOPML10 */ + public ConverterForOPML10() { + super(); + } + + protected void addOwner(Opml opml, SyndFeed syndFeed) { + if((opml.getOwnerEmail() != null) || (opml.getOwnerName() != null)) { + List authors = new ArrayList(); + SyndPerson person = new SyndPersonImpl(); + person.setEmail(opml.getOwnerEmail()); + person.setName(opml.getOwnerName()); + authors.add(person); + syndFeed.setAuthors(authors); + } + } + + /** + * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. + *

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

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

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

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

+ */ + public String getType() { + return "opml_1.0"; + } + + private static class OutlineHolder { + Outline outline; + String parent; + + public OutlineHolder(Outline outline, String parent) { + this.outline = outline; + this.parent = parent; + } + } + + private static class TreeContext extends Stack { + TreeContext() { + super(); + } + } +} diff --git a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java new file mode 100644 index 0000000..25a4e45 --- /dev/null +++ b/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java @@ -0,0 +1,64 @@ +/* + * ConverterForOPML20.java + * + * Created on April 25, 2006, 5:29 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ +package org.rometools.feed.synd.impl; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; + + +/** + * + * @author cooper + */ +public class ConverterForOPML20 extends ConverterForOPML10 { + /** Creates a new instance of ConverterForOPML20 */ + public ConverterForOPML20() { + super(); + } + + /** + * Returns the type (version) of the real feed this converter handles. + *

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

+ */ + public String getType() { + return "opml_2.0"; + } + + /** + * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. + *

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

+ * + * @param feed real feed to copy/convert. + * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. + */ + public void copyInto(WireFeed feed, SyndFeed syndFeed) { + super.copyInto(feed, syndFeed); + } + + /** + * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. + *

+ * + * @param syndFeed SyndFeedImpl to copy/convert value from. + * @return a real feed with copied/converted values of the SyndFeedImpl. + */ + public WireFeed createRealFeed(SyndFeed syndFeed) { + WireFeed retValue; + + retValue = super.createRealFeed(syndFeed); + + return retValue; + } +} diff --git a/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java new file mode 100644 index 0000000..8bb8ac0 --- /dev/null +++ b/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java @@ -0,0 +1,34 @@ +/* + * TreeCategoryImpl.java + * + * Created on April 27, 2006, 3:44 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.rometools.feed.synd.impl; + +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndCategoryImpl; + +/** + * + * @author cooper + */ +public class TreeCategoryImpl extends SyndCategoryImpl { + + /** Creates a new instance of TreeCategoryImpl */ + public TreeCategoryImpl() { + super(); + } + + public boolean equals(Object o) { + SyndCategory c = (SyndCategory) o; + if( c.getTaxonomyUri() != null && c.getTaxonomyUri().equals( this.getTaxonomyUri() ) ) + return true; + else + return false; + } + +} diff --git a/src/main/java/org/rometools/feed/synd/impl/package.html b/src/main/java/org/rometools/feed/synd/impl/package.html new file mode 100644 index 0000000..40f63ad --- /dev/null +++ b/src/main/java/org/rometools/feed/synd/impl/package.html @@ -0,0 +1,30 @@ + + + + + + + + + This packages contains the SyndFeed converters for the + OPML module. For information on how Opml gets turned into + other feed types through the Synd structures, see the OPML + Subproject page on the ROME wiki. + +

+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+    
+ + + diff --git a/src/main/java/org/rometools/io/impl/OPML10Generator.java b/src/main/java/org/rometools/io/impl/OPML10Generator.java new file mode 100644 index 0000000..09255ef --- /dev/null +++ b/src/main/java/org/rometools/io/impl/OPML10Generator.java @@ -0,0 +1,189 @@ +/* + * Opml10Generator.java + * + * Created on April 24, 2006, 11:35 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rometools.io.impl; + +import com.sun.syndication.feed.WireFeed; +import org.rometools.feed.opml.Attribute; +import org.rometools.feed.opml.Opml; +import org.rometools.feed.opml.Outline; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.WireFeedGenerator; +import com.sun.syndication.io.impl.BaseWireFeedGenerator; +import com.sun.syndication.io.impl.DateParser; + +import org.jdom.Document; +import org.jdom.Element; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +/** + * + * @author Robert "kebernet" Cooper + */ +public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { + /** Creates a new instance of Opml10Generator */ + public OPML10Generator() { + super("opml_1.0"); + } + + public OPML10Generator(String type) { + super(type); + } + + /** + * Creates an XML document (JDOM) for the given feed bean. + *

+ * + * @param feed the feed bean to generate the XML document from. + * @return the generated XML document (JDOM). + * @throws IllegalArgumentException thrown if the type of the given feed bean does not + * match with the type of the WireFeedGenerator. + * @throws FeedException thrown if the XML Document could not be created. + */ + public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { + if (!(feed instanceof Opml)) { + throw new IllegalArgumentException("Not an OPML file"); + } + + Opml opml = (Opml) feed; + Document doc = new Document(); + Element root = new Element("opml"); + doc.addContent(root); + + Element head = generateHead(opml); + + if (head != null) { + root.addContent(head); + } + + Element body = new Element("body"); + root.addContent(body); + super.generateFeedModules(opml.getModules(), root); + body.addContent(generateOutlines(opml.getOutlines())); + + return doc; + } + + protected boolean addNotNullAttribute(Element target, String name, Object value) { + if ((target == null) || (name == null) || (value == null)) { + return false; + } + + target.setAttribute(name, value.toString()); + + return true; + } + + protected boolean addNotNullSimpleElement(Element target, String name, Object value) { + if ((target == null) || (name == null) || (value == null)) { + return false; + } + + Element e = new Element(name); + e.addContent(value.toString()); + target.addContent(e); + + return true; + } + + protected Element generateHead(Opml opml) { + Element head = new Element("head"); + boolean hasHead = false; + + if (opml.getCreated() != null) { + hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated())); + } + + hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); + + if (opml.getModified() != null) { + hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified())); + } + + hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); + hasHead = addNotNullSimpleElement(head, "ownerName", opml.getOwnerName()); + hasHead = addNotNullSimpleElement(head, "title", opml.getTitle()); + hasHead = addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState()); + hasHead = addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom()); + hasHead = addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft()); + hasHead = addNotNullSimpleElement(head, "windowRight", opml.getWindowRight()); + hasHead = addNotNullSimpleElement(head, "windowTop", opml.getWindowTop()); + + if (hasHead) { + return head; + } else { + return null; + } + } + + protected Element generateOutline(Outline outline) { + Element e = new Element("outline"); + addNotNullAttribute(e, "text", outline.getText()); + addNotNullAttribute(e, "type", outline.getType()); + addNotNullAttribute(e, "title", outline.getTitle()); + + if (outline.isBreakpoint()) { + addNotNullAttribute(e, "isBreakpoint", "true"); + } + + if (outline.isComment()) { + addNotNullAttribute(e, "isComment", "true"); + } + + List atts = Collections.synchronizedList(outline.getAttributes()); + + for (int i = 0; i < atts.size(); i++) { + Attribute att = (Attribute) atts.get(i); + addNotNullAttribute(e, att.getName(), att.getValue()); + } + + super.generateItemModules(outline.getModules(), e); + e.addContent(generateOutlines(outline.getChildren())); + + return e; + } + + protected List generateOutlines(List outlines) { + ArrayList elements = new ArrayList(); + + for (int i = 0; (outlines != null) && (i < outlines.size()); i++) { + elements.add(generateOutline((Outline) outlines.get(i))); + } + + return elements; + } + + protected String intArrayToCsvString(int[] value) { + if ((value == null) || (value.length == 0)) { + return null; + } + + StringBuffer sb = new StringBuffer(); + sb.append(value[0]); + + for (int i = 1; i < value.length; i++) { + sb.append(","); + sb.append(value[i]); + } + + return sb.toString(); + } +} diff --git a/src/main/java/org/rometools/io/impl/OPML10Parser.java b/src/main/java/org/rometools/io/impl/OPML10Parser.java new file mode 100644 index 0000000..9935e40 --- /dev/null +++ b/src/main/java/org/rometools/io/impl/OPML10Parser.java @@ -0,0 +1,263 @@ +/* + * Opml10Parser.java + * + * Created on April 24, 2006, 11:34 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rometools.io.impl; + +import com.sun.syndication.feed.WireFeed; +import org.rometools.feed.opml.Attribute; +import org.rometools.feed.opml.Opml; +import org.rometools.feed.opml.Outline; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.WireFeedParser; +import com.sun.syndication.io.impl.BaseWireFeedParser; +import com.sun.syndication.io.impl.DateParser; + +import org.jdom.Document; +import org.jdom.Element; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * + * @author Robert "kebernet" Cooper + */ +public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { + private static Logger LOG = Logger.getLogger(OPML10Parser.class.getName()); + + /** Creates a new instance of Opml10Parser */ + public OPML10Parser() { + super("opml_1.0", null); + } + + public OPML10Parser(String type) { + super(type, null); + } + + /** + * Inspects an XML Document (JDOM) to check if it can parse it. + *

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

+ * + * @param document XML Document (JDOM) to check if it can be parsed by this parser. + * @return true if the parser know how to parser this feed, false otherwise. + */ + public boolean isMyType(Document document) { + Element e = document.getRootElement(); + + if (e.getName().equals("opml") + && ( e.getChild("head") == null || e.getChild("head").getChild("docs") == null) + && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { + return true; + } + + return false; + } + + /** + * Parses an XML document (JDOM Document) into a feed bean. + *

+ * + * @param document XML document (JDOM) to parse. + * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). + * @return the resulting feed bean. + * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. + * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). + */ + public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { + Opml opml = new Opml(); + opml.setFeedType("opml_1.0"); + + Element root = document.getRootElement(); + Element head = root.getChild("head"); + + if (head != null) { + opml.setTitle(head.getChildText("title")); + + if (head.getChildText("dateCreated") != null) { + opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"))); + } + + if (head.getChildText("dateModified") != null) { + opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"))); + } + + opml.setOwnerName(head.getChildTextTrim("ownerName")); + opml.setOwnerEmail(head.getChildTextTrim("ownerEmail")); + opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState"))); + } + + try { + opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowBottom", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowBottom", nfe); + } + } + + try { + opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); + } + + try { + opml.setWindowRight(readInteger(head.getChildText("windowRight"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowRight", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowRight", nfe); + } + } + + try { + opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowLeft", nfe); + } + } + + try { + opml.setWindowTop(readInteger(head.getChildText("windowTop"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse windowTop", nfe); + + if (validate) { + throw new FeedException("Unable to parse windowTop", nfe); + } + } + + try { + opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); + } catch (NumberFormatException nfe) { + LOG.log(Level.WARNING, "Unable to parse expansionState", nfe); + + if (validate) { + throw new FeedException("Unable to parse expansionState", nfe); + } + } + + opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate)); + opml.setModules(this.parseFeedModules(root)); + + return opml; + } + + protected Outline parseOutline(Element e, boolean validate) throws FeedException { + if (!e.getName().equals("outline")) { + throw new RuntimeException("Not an outline element."); + } + + Outline outline = new Outline(); + outline.setText(e.getAttributeValue("text")); + outline.setType(e.getAttributeValue("type")); + outline.setTitle(e.getAttributeValue("title")); + + List jAttributes = e.getAttributes(); + ArrayList attributes = new ArrayList(); + + for (int i = 0; i < jAttributes.size(); i++) { + org.jdom.Attribute a = (org.jdom.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")) { + attributes.add(new Attribute(a.getName(), a.getValue())); + } + } + + outline.setAttributes(attributes); + + try { + outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); + } catch (Exception ex) { + LOG.log(Level.WARNING, "Unable to parse isBreakpoint value", ex); + + if (validate) { + throw new FeedException("Unable to parse isBreakpoint value", ex); + } + } + + try { + outline.setComment(readBoolean(e.getAttributeValue("isComment"))); + } catch (Exception ex) { + LOG.log(Level.WARNING, "Unable to parse isComment value", ex); + + if (validate) { + throw new FeedException("Unable to parse isComment value", ex); + } + } + + List children = e.getChildren("outline"); + outline.setModules(this.parseItemModules(e)); + outline.setChildren(parseOutlines(children, validate)); + + return outline; + } + + protected List parseOutlines(List elements, boolean validate) throws FeedException { + ArrayList results = new ArrayList(); + + for (int i = 0; i < elements.size(); i++) { + results.add(parseOutline((Element) elements.get(i), validate)); + } + + return results; + } + + protected boolean readBoolean(String value) { + if (value == null) { + return false; + } else { + return Boolean.getBoolean(value.trim()); + } + } + + protected int[] readIntArray(String value) { + if (value == null) { + return null; + } else { + StringTokenizer tok = new StringTokenizer(value, ","); + int[] result = new int[tok.countTokens()]; + int count = 0; + + while (tok.hasMoreElements()) { + result[count] = Integer.parseInt(tok.nextToken().trim()); + count++; + } + + return result; + } + } + + protected Integer readInteger(String value) { + if (value != null) { + return new Integer(value); + } else { + return null; + } + } +} diff --git a/src/main/java/org/rometools/io/impl/OPML20Generator.java b/src/main/java/org/rometools/io/impl/OPML20Generator.java new file mode 100644 index 0000000..7793ee8 --- /dev/null +++ b/src/main/java/org/rometools/io/impl/OPML20Generator.java @@ -0,0 +1,83 @@ +/* + * OPML20Generator.java + * + * Created on April 25, 2006, 5:31 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ +package org.rometools.io.impl; + +import com.sun.syndication.feed.WireFeed; +import org.rometools.feed.opml.Opml; +import org.rometools.feed.opml.Outline; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.impl.DateParser; + +import org.jdom.Document; +import org.jdom.Element; + + +/** + * + * @author cooper + */ +public class OPML20Generator extends OPML10Generator { + /** Creates a new instance of OPML20Generator */ + public OPML20Generator() { + } + + /** + * Returns the type of feed the generator creates. + *

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

+ */ + public String getType() { + return "opml_2.0"; + } + + /** + * Creates an XML document (JDOM) for the given feed bean. + *

+ * + * @param feed the feed bean to generate the XML document from. + * @return the generated XML document (JDOM). + * @throws IllegalArgumentException thrown if the type of the given feed bean does not + * match with the type of the WireFeedGenerator. + * @throws FeedException thrown if the XML Document could not be created. + */ + public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { + Document retValue; + + retValue = super.generate(feed); + retValue.getRootElement().setAttribute("version", "2.0"); + + return retValue; + } + + protected Element generateHead(Opml opml) { + Element retValue; + + retValue = super.generateHead(opml); + + Element docs = new Element("docs", opml.getDocs()); + retValue.addContent(docs); + + return retValue; + } + + protected Element generateOutline(Outline outline) { + Element retValue; + + retValue = super.generateOutline(outline); + + if (outline.getCreated() != null) { + retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated())); + } + + return retValue; + } +} diff --git a/src/main/java/org/rometools/io/impl/OPML20Parser.java b/src/main/java/org/rometools/io/impl/OPML20Parser.java new file mode 100644 index 0000000..5aaabff --- /dev/null +++ b/src/main/java/org/rometools/io/impl/OPML20Parser.java @@ -0,0 +1,117 @@ +/* + * Opml20Parser.java + * + * Created on April 25, 2006, 1:04 AM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.rometools.io.impl; + +import com.sun.syndication.feed.WireFeed; +import org.rometools.feed.opml.Attribute; +import org.rometools.feed.opml.Opml; +import org.rometools.feed.opml.Outline; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.impl.DateParser; + +import org.jdom.Document; +import org.jdom.Element; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + + +/** + * + * @author cooper + */ +public class OPML20Parser extends OPML10Parser { + /** Creates a new instance of Opml20Parser */ + public OPML20Parser() { + super("opml_2.0"); + } + + /** + * Inspects an XML Document (JDOM) to check if it can parse it. + *

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

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

+ * + * @param document XML document (JDOM) to parse. + * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). + * @return the resulting feed bean. + * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. + * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). + */ + public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { + Opml opml; + opml = (Opml) super.parse(document, validate); + + Element head = document.getRootElement().getChild("head"); + + if (head != null) { + opml.setOwnerId(head.getChildTextTrim("ownerId")); + opml.setDocs(head.getChildTextTrim("docs")); + + if (opml.getDocs() == null) { + opml.setDocs("http://www.opml.org/spec2"); + } + } + + opml.setFeedType("opml_2.0"); + + return opml; + } + + protected Outline parseOutline(Element e, boolean validate) throws FeedException { + Outline retValue; + + retValue = super.parseOutline(e, validate); + + if (e.getAttributeValue("created") != null) { + retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"))); + } + + List atts = retValue.getAttributes(); + + for (int i = 0; i < atts.size(); i++) { + Attribute a = (Attribute) atts.get(i); + + if (a.getName().equals("created")) { + retValue.getAttributes().remove(a); + + break; + } + } + + return retValue; + } +} diff --git a/src/main/java/org/rometools/io/impl/package.html b/src/main/java/org/rometools/io/impl/package.html new file mode 100644 index 0000000..64d1989 --- /dev/null +++ b/src/main/java/org/rometools/io/impl/package.html @@ -0,0 +1,28 @@ + + + + + + + + + This package contains the feed parsers for OPML1 and OPML2. + + +

+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+    
+ + + diff --git a/src/test/java/org/rometools/unittest/FeedOpsTest.java b/src/test/java/org/rometools/unittest/FeedOpsTest.java new file mode 100644 index 0000000..36b88ac --- /dev/null +++ b/src/test/java/org/rometools/unittest/FeedOpsTest.java @@ -0,0 +1,114 @@ +package org.rometools.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.ObjectInputStream; + +/** + * + *

+ * @author Alejandro Abdelnur + * + */ +public abstract class FeedOpsTest extends FeedTest { + + protected FeedOpsTest(String feedType) { + super(feedType+".xml"); + System.out.println("Testing "+feedType+".xml"); + new File("target/test-reports").mkdirs(); + } + + //1.2a + public void testWireFeedEquals() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + WireFeed feed2 = getWireFeed(); + assertTrue(feed1.equals(feed2)); + } + + //1.2b + public void testWireFeedNotEqual() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + WireFeed feed2 = getWireFeed(); + feed2.setFeedType("dummy"); + assertFalse(feed1.equals(feed2)); + } + + //1.3 + public void testWireFeedCloning() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + WireFeed feed2 = (WireFeed) feed1.clone();; + assertTrue(feed1.equals(feed2)); + } + + // 1.4 + public void testWireFeedSerialization() throws Exception { + WireFeed feed1 = getCachedWireFeed(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(feed1); + oos.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + WireFeed feed2 = (WireFeed) ois.readObject(); + ois.close(); + + assertTrue(feed1.equals(feed2)); + } + + // 1.6 + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + + assertEquals(sFeed1, sFeed2 ); + } + + //1.7a + public void testSyndFeedEquals() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + SyndFeed feed2 = getSyndFeed(); + assertTrue(feed1.equals(feed2)); + } + + //1.7b + public void testSyndFeedNotEqual() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + SyndFeed feed2 = getSyndFeed(); + feed2.setFeedType("dummy"); + assertFalse(feed1.equals(feed2)); + } + + //1.8 + public void testSyndFeedCloning() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + SyndFeed feed2 = (SyndFeed) feed1.clone();; + assertTrue(feed1.equals(feed2)); + } + + //1.9 + public void testSyndFeedSerialization() throws Exception { + SyndFeed feed1 = getCachedSyndFeed(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(feed1); + oos.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + SyndFeed feed2 = (SyndFeed) ois.readObject(); + ois.close(); + + assertTrue(feed1.equals(feed2)); + } + +} diff --git a/src/test/java/org/rometools/unittest/FeedTest.java b/src/test/java/org/rometools/unittest/FeedTest.java new file mode 100644 index 0000000..676cd93 --- /dev/null +++ b/src/test/java/org/rometools/unittest/FeedTest.java @@ -0,0 +1,78 @@ +package org.rometools.unittest; + +import junit.framework.TestCase; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.WireFeedInput; + +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.InputStream; + +import org.jdom.Document; +import org.jdom.input.SAXBuilder; + +/** + * @author pat, tucu + * + */ +public abstract class FeedTest extends TestCase { + private String _feedFileName; + private Document _jDomDoc = null; + private WireFeed _wireFeed = null; + private SyndFeed _syndFeed = null; + + protected FeedTest(String feedFileName) { + _feedFileName = feedFileName; + } + + protected String getFeedFileName() { + return _feedFileName; + } + + protected Reader getFeedReader() throws Exception { + InputStream resource = Thread.currentThread(). + getContextClassLoader().getResourceAsStream(getFeedFileName()); + assertNotNull("Could not find resource " + getFeedFileName(), resource); + return new InputStreamReader(resource); + } + + protected Document getJDomDoc() throws Exception { + SAXBuilder saxBuilder = new SAXBuilder(false); + return saxBuilder.build(getFeedReader()); + } + + protected WireFeed getWireFeed() throws Exception { + WireFeedInput in = new WireFeedInput(); + return in.build(getFeedReader()); + } + + protected SyndFeed getSyndFeed() throws Exception { + SyndFeedInput in = new SyndFeedInput(); + return in.build(getFeedReader()); + } + + protected Document getCachedJDomDoc() throws Exception { + if (_jDomDoc==null) { + _jDomDoc = getJDomDoc(); + } + return _jDomDoc; + } + + protected WireFeed getCachedWireFeed() throws Exception { + if (_wireFeed==null) { + _wireFeed = getWireFeed(); + } + return _wireFeed; + } + + protected SyndFeed getCachedSyndFeed() throws Exception { + if (_syndFeed==null) { + _syndFeed = getSyndFeed(); + } + return _syndFeed; + } + +} diff --git a/src/test/java/org/rometools/unittest/SyndFeedTest.java b/src/test/java/org/rometools/unittest/SyndFeedTest.java new file mode 100644 index 0000000..8bdddde --- /dev/null +++ b/src/test/java/org/rometools/unittest/SyndFeedTest.java @@ -0,0 +1,267 @@ +/* + * Created on Jun 22, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +package org.rometools.unittest; + + + + +/** + * @author pat + * + */ +public abstract class SyndFeedTest extends FeedTest { + private String _prefix = null; + + protected SyndFeedTest(String feedType) { + this(feedType,feedType+".xml"); + } + + protected SyndFeedTest(String feedType,String feedFileName) { + super(feedFileName); + _prefix = feedType; + } + + protected String getPrefix() { + return _prefix; + } + + protected void assertProperty(String property, String value) { + assertEquals(property,getPrefix() + "." + value); + } + + public void testType() throws Exception { + assertEquals(getCachedSyndFeed().getFeedType(),getPrefix()); + } + + +/* + public void testType() throws Exception { + assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); + } + + public void testTitle() throws Exception { + assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); + } + + public void testLink() throws Exception { + assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); + } + + public void testDescription() throws Exception { + assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); + } + + public void testLanguage() throws Exception { + assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); + } + + public void testCategories() throws Exception { + List catlist = getCachedSyndFeed().getCategories(); + //don't understand why this one fails + assertEquals(2, catlist.size()); + SyndCategory cat = (SyndCategory)catlist.get(0); + assertEqualsStr("channel.category[0]", cat.getName()); + assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); + cat = (SyndCategory)catlist.get(1); + assertEqualsStr("channel.category[1]", cat.getName()); + assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); + } + + public void testPublishedDate() throws Exception { + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getCachedSyndFeed().getPublishedDate()); + } + + //how do i get height and width? + public void testImage() throws Exception { + SyndImage img = getCachedSyndFeed().getImage(); + assertEqualsStr("channel.image.description", img.getDescription()); + assertEqualsStr("channel.image.link", img.getLink()); + assertEqualsStr("channel.image.title", img.getTitle()); + assertEqualsStr("channel.image.url", img.getUrl()); + } + + public void testEntries() throws Exception { + List entrylist = getCachedSyndFeed().getEntries(); + assertEquals(2, entrylist.size()); + } + + public void testEntryTitle() throws Exception { + assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryTitle(Object o) throws Exception { + SyndEntry e = (SyndEntry) o; + return e.getTitle(); + } + + public void testEntryDescription() throws Exception { + assertEqualsStr("channel.item[0].description", getEntryDescription(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].description", getEntryDescription(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryDescription(Object o) throws Exception { + SyndEntry e = (SyndEntry) o; + return e.getDescription().getValue(); + } + + public void testEntryLink() throws Exception { + assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryLink(Object o) { + SyndEntry e = (SyndEntry) o; + return e.getLink(); + } + + public void testEntryPublishedDate() throws Exception { + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); + } + + public Date getEntryPublishedDate(Object o) { + SyndEntry e = (SyndEntry) o; + return e.getPublishedDate(); + } + + public void testEntryCategories() throws Exception { + SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); + List catlist = e.getCategories(); + //don't understand why this one fails + assertEquals(2, catlist.size()); + SyndCategory cat = (SyndCategory)catlist.get(0); + assertEqualsStr("channel.item[0].category[0]", cat.getName()); + assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); + cat = (SyndCategory)catlist.get(1); + assertEqualsStr("channel.item[0].category[1]", cat.getName()); + assertEqualsStr("channel.item[0].category[1]^domain", cat.getTaxonomyUri()); + //DO 2nd set of items + } + + public void testEntryAuthor() throws Exception { + assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); + } + + public String getEntryAuthor(Object o) { + SyndEntry e = (SyndEntry) o; + return e.getAuthor(); + } + +*/ +/* +//things you cannot get from SyndEntryImpl +// item[0].source +// +// + item0.category0 + item0.category1 + Thu, 08 Jul 1999 08:00:00 GMT + Thu, 08 Jul 1999 09:00:00 GMT + item0.author + http://localhost:8080/item0/comments + http://localhost:8080/item0/guid + //TODO: I still have the elements to test +*/ + /* + public void test() { + assertEqualsStr(feed, ""); + } + + public void test() { + assertEqualsStr(feed, ""); + } + + */ + //Things that you cannot get form a SyndFeedImpl today + //these need to be put in a RSS 2.0 module + //or is a roundtrip to wirefeed the right way to do this? +/* + * + Search + Search this site: + q + http://example.org/mt/mt-search.cgi + + + image height and width + * + //Copyright 2004, Mark Pilgrim + public void test() { + assertEqualsStr(getCachedSyndFeed()., ""); + } + + //Sample Toolkit + public void test() { + assertEqualsStr(feed, ""); + } + + // editor@example.org + public void test() { + assertEqualsStr(feed, ""); + } + + // webmaster@example.org + public void test() { + assertEqualsStr(feed, ""); + } + + http://blogs.law.harvard.edu/tech/rss + + 60 + + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9.5 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + + + Monday + Tuesday + Wednesday + Thursday + Friday + Saturday + Sunday + + +**/ + + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + + +} diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10.java b/src/test/java/org/rometools/unittest/TestOpsOPML10.java new file mode 100644 index 0000000..438fc73 --- /dev/null +++ b/src/test/java/org/rometools/unittest/TestOpsOPML10.java @@ -0,0 +1,47 @@ +/* + * TestOpsOPML10.java + * + * Created on April 25, 2006, 4:26 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.rometools.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import java.io.FileOutputStream; +import java.io.PrintWriter; + +/** + * + * @author cooper + */ +public class TestOpsOPML10 extends FeedOpsTest{ + + /** Creates a new instance of TestOpsOPML10 */ + public TestOpsOPML10() { + super("opml_1.0"); + } + + // 1.6 + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); + w.println( sFeed1.toString() ); + w.close(); + w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); + w.println( sFeed2.toString() ); + w.close(); + + assertEquals(sFeed1, sFeed2); + } + + + + +} diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10links.java b/src/test/java/org/rometools/unittest/TestOpsOPML10links.java new file mode 100644 index 0000000..cd14968 --- /dev/null +++ b/src/test/java/org/rometools/unittest/TestOpsOPML10links.java @@ -0,0 +1,67 @@ +/* + * TestOpsOPML10.java + * + * Created on April 25, 2006, 4:26 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.rometools.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.WireFeedOutput; +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; + +/** + * + * @author cooper + */ +public class TestOpsOPML10links extends FeedOpsTest{ + + /** Creates a new instance of TestOpsOPML10 */ + public TestOpsOPML10links() { + super("opml_1.0_links"); + } + + // 1.6 + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + //System.out.println( wFeed1 ); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); + w.println( sFeed1.toString() ); + w.close(); + w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); + w.println( sFeed2.toString() ); + w.close(); + + assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed()); + } + + + + public void testTemp() throws Exception { + WireFeedInput input = new WireFeedInput(); + WireFeed wf = input.build( new File( System.getProperty("basedir")+ "/src/test/resources/opml_1.0_links.xml")); + WireFeedOutput output = new WireFeedOutput(); + //System.out.println( wf ); + + //System.out.println( "================================="); + //System.out.println( new SyndFeedImpl( wf) ); + SyndFeedImpl sf = new SyndFeedImpl( wf); + sf.setFeedType("rss_2.0"); + sf.setDescription(""); + sf.setLink("http://foo.com"); + //output.output( sf.createWireFeed() , new PrintWriter( System.out ) ); + sf.setFeedType("opml_1.0"); + output.output( sf.createWireFeed() , new File( System.getProperty("basedir")+ "/target/test-reports/1.xml") ); + } + +} diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML20.java b/src/test/java/org/rometools/unittest/TestOpsOPML20.java new file mode 100644 index 0000000..0d49027 --- /dev/null +++ b/src/test/java/org/rometools/unittest/TestOpsOPML20.java @@ -0,0 +1,43 @@ +/* + * TestOpsOPML20.java + * + * Created on April 25, 2006, 5:38 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.rometools.unittest; + +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import java.io.FileOutputStream; +import java.io.PrintWriter; + +/** + * + * @author cooper + */ +public class TestOpsOPML20 extends FeedOpsTest { + + /** Creates a new instance of TestOpsOPML20 */ + public TestOpsOPML20() { + super("opml_2.0"); + } + + + public void testWireFeedSyndFeedConversion() throws Exception { + SyndFeed sFeed1 = getCachedSyndFeed(); + WireFeed wFeed1 = sFeed1.createWireFeed(); + SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/3") ); + w.println( sFeed1.toString() ); + w.close(); + w = new PrintWriter( new FileOutputStream( "target/test-reports/4") ); + w.println( sFeed2.toString() ); + w.close(); + assertEquals(sFeed1, sFeed2 ); + } + +} diff --git a/src/test/java/org/rometools/unittest/TestXmlFixerReader.java b/src/test/java/org/rometools/unittest/TestXmlFixerReader.java new file mode 100644 index 0000000..7c5669c --- /dev/null +++ b/src/test/java/org/rometools/unittest/TestXmlFixerReader.java @@ -0,0 +1,134 @@ +/* + * Copyright 2004 Sun Microsystems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.rometools.unittest; + +import com.sun.syndication.io.XmlReader; +import com.sun.syndication.io.impl.XmlFixerReader; +import junit.framework.TestCase; +import org.jdom.input.SAXBuilder; + +import java.io.*; + +/** + * @author pat, tucu + * + */ +public class TestXmlFixerReader extends TestCase { + private static final String XML_PROLOG = ""; + + public void testTrim() throws Exception { + _testValidTrim("",""); + _testValidTrim("",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" \n",""); + _testValidTrim(" \n",XML_PROLOG+""); + _testValidTrim("",""); + _testValidTrim("",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" ",""); + _testValidTrim(" ",XML_PROLOG+""); + _testValidTrim(" \n ",""); + _testValidTrim(" \n ",XML_PROLOG+""); + + _testInvalidTrim("x",""); + _testInvalidTrim("x",XML_PROLOG+""); + _testInvalidTrim(" x",""); + _testInvalidTrim(" x",XML_PROLOG+""); + _testInvalidTrim(" x\n",""); + _testInvalidTrim(" x\n",XML_PROLOG+""); + _testInvalidTrim("x ",""); + _testInvalidTrim(" x ",XML_PROLOG+""); + _testInvalidTrim(" x ",""); + _testInvalidTrim(" x ",XML_PROLOG+""); + _testInvalidTrim(" x\n ",""); + _testInvalidTrim(" x\n ",XML_PROLOG+""); + } + + public void testHtmlEntities() throws Exception { + _testValidEntities(""); + _testValidEntities(XML_PROLOG+""); + _testValidEntities(" \n"+XML_PROLOG+""); + + _testValidEntities("'¥ú¥"); + _testValidEntities(XML_PROLOG+"'¥ú¥"); + _testValidEntities(" \n"+XML_PROLOG+"'¥ú¥"); + + _testInvalidEntities("'&yexn;ú¥"); + _testInvalidEntities(XML_PROLOG+"'&yexn;ú¥"); + _testInvalidEntities(" \n"+XML_PROLOG+"'&yexn;ú¥"); + + _testInvalidEntities("'¥x50;¥"); + _testInvalidEntities(XML_PROLOG+"'¥x50;¥"); + _testInvalidEntities(" \n"+XML_PROLOG+"'¥x50;¥"); + + } + + protected void _testXmlParse(String garbish,String xmlDoc) throws Exception { + InputStream is = getStream(garbish,xmlDoc); + Reader reader = new XmlReader(is); + reader = new XmlFixerReader(reader); + SAXBuilder saxBuilder = new SAXBuilder(); + saxBuilder.build(reader); + } + + protected void _testValidTrim(String garbish,String xmlDoc) throws Exception { + _testXmlParse(garbish,xmlDoc); + } + + protected void _testInvalidTrim(String garbish,String xmlDoc) throws Exception { + try { + _testXmlParse(garbish,xmlDoc); + assertTrue(false); + } + catch (Exception ex) { + } + } + + protected void _testValidEntities(String xmlDoc) throws Exception { + _testXmlParse("",xmlDoc); + } + + protected void _testInvalidEntities(String xmlDoc) throws Exception { + try { + _testXmlParse("",xmlDoc); + assertTrue(false); + } + catch (Exception ex) { + } + } + + // XML Stream generator + + protected InputStream getStream(String garbish,String xmlDoc) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + Writer writer = new OutputStreamWriter(baos); + writer.write(garbish); + writer.write(xmlDoc); + writer.close(); + return new ByteArrayInputStream(baos.toByteArray()); + } + + +} diff --git a/src/test/java/org/rometools/unittest/TestXmlReader.java b/src/test/java/org/rometools/unittest/TestXmlReader.java new file mode 100644 index 0000000..78a85fb --- /dev/null +++ b/src/test/java/org/rometools/unittest/TestXmlReader.java @@ -0,0 +1,257 @@ +/* + * Copyright 2004 Sun Microsystems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.rometools.unittest; + +import com.sun.syndication.io.XmlReader; +import junit.framework.TestCase; + +import java.io.*; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +/** + * @author pat, tucu + * + */ +public class TestXmlReader extends TestCase { + + public static void main(String[] args) throws Exception { + TestXmlReader test = new TestXmlReader(); + test.testRawBom(); + test.testRawNoBom(); + test.testHttp(); + } + + protected void _testRawNoBomValid(String encoding) throws Exception { + InputStream is = getXmlStream("no-bom","xml",encoding,encoding); + XmlReader xmlReader = new XmlReader(is,false); + assertEquals(xmlReader.getEncoding(),"UTF-8"); + + is = getXmlStream("no-bom","xml-prolog",encoding,encoding); + xmlReader = new XmlReader(is); + assertEquals(xmlReader.getEncoding(),"UTF-8"); + + is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + xmlReader = new XmlReader(is); + assertEquals(xmlReader.getEncoding(),encoding); + } + + protected void _testRawNoBomInvalid(String encoding) throws Exception { + InputStream is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + try { + XmlReader xmlReader = new XmlReader(is,false); + fail("It should have failed"); + } + catch (IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); + } + } + + public void testRawNoBom() throws Exception { + _testRawNoBomValid("US-ASCII"); + _testRawNoBomValid("UTF-8"); + _testRawNoBomValid("ISO-8859-1"); + } + + protected void _testRawBomValid(String encoding) throws Exception { + InputStream is = getXmlStream(encoding+"-bom","xml-prolog-encoding",encoding,encoding); + XmlReader xmlReader = new XmlReader(is,false); + if (!encoding.equals("UTF-16")) { + assertEquals(xmlReader.getEncoding(),encoding); + } + else { + assertEquals(xmlReader.getEncoding().substring(0,encoding.length()),encoding); + } + } + + protected void _testRawBomInvalid(String bomEnc,String streamEnc,String prologEnc) throws Exception { + InputStream is = getXmlStream(bomEnc,"xml-prolog-encoding",streamEnc,prologEnc); + try { + XmlReader xmlReader = new XmlReader(is,false); + fail("It should have failed for BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + } + catch (IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); + } + } + + public void testRawBom() throws Exception { + _testRawBomValid("UTF-8"); + _testRawBomValid("UTF-16BE"); + _testRawBomValid("UTF-16LE"); + _testRawBomValid("UTF-16"); + + _testRawBomInvalid("UTF-8-bom","US-ASCII","US-ASCII"); + _testRawBomInvalid("UTF-8-bom","ISO-8859-1","ISO-8859-1"); + _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16"); + _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16BE"); + _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16LE"); + _testRawBomInvalid("UTF-16BE-bom","UTF-16BE","UTF-16LE"); + _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-16BE"); + _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-8"); + } + + public void testHttp() throws Exception { + _testHttpValid("application/xml","no-bom","US-ASCII",null); + _testHttpValid("application/xml","UTF-8-bom","US-ASCII",null); + _testHttpValid("application/xml","UTF-8-bom","UTF-8",null); + _testHttpValid("application/xml","UTF-8-bom","UTF-8","UTF-8"); + _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); + _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); + _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); + _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + + _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); + _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("application/xml","UTF-8-bom","US-ASCII","US-ASCII"); + _testHttpInvalid("application/xml;charset=UTF-16","UTF-16LE","UTF-8","UTF-8"); + _testHttpInvalid("application/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); + + _testHttpValid("text/xml","no-bom","US-ASCII",null); + _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); + _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); + _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); + _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpValid("text/xml","UTF-8-bom","US-ASCII",null); + + _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); + _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); + _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE",null); + + _testHttpLenient("text/xml","no-bom","US-ASCII",null, "US-ASCII"); + _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8", "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null, "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml","UTF-8-bom","US-ASCII",null, "US-ASCII"); + + _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE",null, "UTF-16"); + + _testHttpLenient("text/html","no-bom","US-ASCII","US-ASCII", "US-ASCII"); + _testHttpLenient("text/html","no-bom","US-ASCII",null, "US-ASCII"); + _testHttpLenient("text/html;charset=UTF-8","no-bom","US-ASCII","UTF-8", "UTF-8"); + _testHttpLenient("text/html;charset=UTF-16BE","no-bom","US-ASCII","UTF-8", "UTF-8"); + } + + public void _testHttpValid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { + InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml":"xml-prolog-encoding",streamEnc,prologEnc); + XmlReader xmlReader = new XmlReader(is,cT,false); + if (!streamEnc.equals("UTF-16")) { + // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection + } + else { + assertEquals(xmlReader.getEncoding().substring(0,streamEnc.length()),streamEnc); + } + } + + protected void _testHttpInvalid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { + InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); + try { + XmlReader xmlReader = new XmlReader(is,cT,false); + fail("It should have failed for HTTP Content-type "+cT+", BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + } + catch (IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); + } + } + + protected void _testHttpLenient(String cT, String bomEnc, String streamEnc, String prologEnc, String shouldbe) throws Exception { + InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); + XmlReader xmlReader = new XmlReader(is,cT,true); + assertEquals(xmlReader.getEncoding(),shouldbe); + } + + // XML Stream generator + + private static final int[] NO_BOM_BYTES = {}; + private static final int[] UTF_16BE_BOM_BYTES = {0xFE,0xFF}; + private static final int[] UTF_16LE_BOM_BYTES = {0xFF,0XFE}; + private static final int[] UTF_8_BOM_BYTES = {0xEF,0xBB,0xBF}; + + private static final Map BOMs = new HashMap(); + + static { + BOMs.put("no-bom",NO_BOM_BYTES); + BOMs.put("UTF-16BE-bom",UTF_16BE_BOM_BYTES); + BOMs.put("UTF-16LE-bom",UTF_16LE_BOM_BYTES); + BOMs.put("UTF-16-bom",NO_BOM_BYTES); // it's added by the writer + BOMs.put("UTF-8-bom",UTF_8_BOM_BYTES); + } + + private static final MessageFormat XML = new MessageFormat( + "{2}"); + private static final MessageFormat XML_WITH_PROLOG = new MessageFormat( + "\n{2}"); + private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat( + "\n{2}"); + + private static final MessageFormat INFO = new MessageFormat( + "\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); + + private static final Map XMLs = new HashMap(); + + static { + XMLs.put("xml",XML); + XMLs.put("xml-prolog",XML_WITH_PROLOG); + XMLs.put("xml-prolog-encoding",XML_WITH_PROLOG_AND_ENCODING); + } + + /** + * + * @param bomType no-bom, UTF-16BE-bom, UTF-16LE-bom, UTF-8-bom + * @param xmlType xml, xml-prolog, xml-prolog-charset + * @return XML stream + */ + protected InputStream getXmlStream(String bomType,String xmlType,String streamEnc,String prologEnc) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + int[] bom = (int[]) BOMs.get(bomType); + if (bom==null) { + bom = new int[0]; + } + MessageFormat xml = (MessageFormat) XMLs.get(xmlType); + for (int i=0;i\n"); + for (int i=0;i<10000;i++) { + writer.write("\n"); + } + writer.write("\n"); + + writer.close(); + return new ByteArrayInputStream(baos.toByteArray()); + } + + +} From bcfadc868e333a9456173040c5217c3cab064bc3 Mon Sep 17 00:00:00 2001 From: Martin Kurz Date: Thu, 26 Sep 2013 23:51:23 +0200 Subject: [PATCH 06/47] maven site and config --- README.md | 6 ++ pom.xml | 68 ++++++++++++-- src/site/apt/index.apt | 125 +++++++++++++++++++++++++ src/site/resources/css/site.css | 8 ++ src/site/resources/images/romelogo.png | Bin 0 -> 10835 bytes src/site/site.xml | 19 ++++ 6 files changed, 218 insertions(+), 8 deletions(-) create mode 100644 README.md create mode 100644 src/site/apt/index.apt create mode 100644 src/site/resources/css/site.css create mode 100644 src/site/resources/images/romelogo.png create mode 100644 src/site/site.xml diff --git a/README.md b/README.md new file mode 100644 index 0000000..65a6e36 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +rome +==== + +ROME is a set of RSS and Atom Utilities for Java. It makes it easy to work in Java with most syndication formats: RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0 + +More Information: http://rometools.github.io/rome-opml/ diff --git a/pom.xml b/pom.xml index b75e5bf..ae38037 100644 --- a/pom.xml +++ b/pom.xml @@ -7,11 +7,20 @@ jar 1.5-SNAPSHOT rome-opml - http://rometools.jira.com + http://rometools.github.io/rome-opml/ Support for OPML 1 and OPML 2 in ROME + + ROME Project + https://github.com/rometools/ + - https://rometools.jira.com/secure/IssueNavigator.jspa + https://github.com/rometools/rome-opml/issues + + scm:git:git@github.com:rometools/rome-opml.git + scm:git:git@github.com:rometools/rome-opml.git + https://github.com/rometools/rome-opml/ + kebernet @@ -26,11 +35,6 @@ repo - - scm:svn:https://rometools.jira.com/svn/MODULES/trunk - scm:svn:https://rometools.jira.com/svn/MODULES/trunk - https://rometools.jira.com/source/browse/MODULES - maven2-repository.dev.java.net @@ -74,11 +78,30 @@ org.apache.maven.plugins maven-resources-plugin - 2.2 + 2.6 ${project.build.sourceEncoding} + + org.apache.maven.plugins + maven-site-plugin + 3.3 + + 9000 + ${basedir}/target/site/tempdir + + + + org.apache.maven.plugins + maven-scm-publish-plugin + 1.0-beta-2 + + gh-pages + scm:git:git@github.com:rometools/rome-opml.git + ${project.build.directory}/site + + @@ -148,4 +171,33 @@ UTF-8 + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.6 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9 + + + + javadoc + test-javadoc + + + + aggregate + false + + aggregate + + + + + + diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt new file mode 100644 index 0000000..0e7e427 --- /dev/null +++ b/src/site/apt/index.apt @@ -0,0 +1,125 @@ + ----- + Home + ----- + kwebble + ----- + 2011-09-23 14:15:28.442 + ----- + +ROME OPML + + This project provides support for {{{http://www.opml.org/}OPML}} in ROME. + +*Downloads + + * {{{./apidocs/index.html}JavaDocs}} + + [] + +*Sample Usage + + To use this parser, simply include the jar file in your classpath as you are using ROME. Be sure it exists at the same level as ROME, + such that, if ROME is in the common classpath of an application server, don't include this jar in your webapps WEB\-INF/lib. + ++------+ +WireFeedInput input = new WireFeedInput(); + Opml feed = (Opml) input.build( new File("myOpml.xml") ); + List outlines = (List) feed.getOutlines(); ++------+ + +*Hierarchy vs Flat + + Since OPML is a hierarchical format, some magic is required to preserve this information when they feed is moved to a Synd\* structure. + This is accomplished by adding categories indicating the tree structure to the {{{http://wiki.java.net/bin/edit/Javawsxml/SyndEntries?topicparent\=Javawsxml.OPML;nowysiwyg\=0}SyndEntries}} ... + + For example: + ++------+ + + + Top Ten Sources for podcasting + Newsilike Media Group + opml@TopTenSources.com + + + + + + + + + + + + + + + + + + + + ++------+ + + ...\ + When converted to RSS2 becomes: + ++------+ + + Top Ten Sources for podcasting + http://foo.com + + Newsilike Media Group + + TopTenSources: podcasting + http://podcasting.TopTenSources.com/TopTenSources/ + node.-1732517202 + http://podcasting.TopTenSources.com/TopTenSources/ + http://podcasting.TopTenSources.com/TopTenSources/ + + + CBS Technology News Podcast - Larry Magid' Tech Report + node.1353657827 + + + Larry Magid's Tech Report + http://www.cbsnews.com + node.-4085850 + parent.1353657827 + http://www.cbsnews.com + http://www.cbsnews.com + + + Adam Curry: Daily Source Code + node.835791399 + + + #374 Daily Source Code for Tuesday April 25th 2006 + http://radio.weblogs.com/0001014/2006/04/26.html#a7304 + node.222050897 + parent.835791399 + http://radio.weblogs.com/0001014/2006/04/26.html#a7304 + http://radio.weblogs.com/0001014/2006/04/26.html#a7304 + + + #373 Daily Source Code for Monday April 24th 2006 + http://radio.weblogs.com/0001014/2006/04/24.html#a7303 + node.2088220478 + parent.835791399 + http://radio.weblogs.com/0001014/2006/04/24.html#a7303 + http://radio.weblogs.com/0001014/2006/04/24.html#a7303 + ++------+ + + Nodes get categories with the "urn:rome.tree" URI that is used to maintain the tree structure. + + The other thing you will notice is the "urn:rome.attribute#url". Since OPML allows you to add arbitrary attributes to each outline element, these are used to preserve these values. + + \ No newline at end of file diff --git a/src/site/resources/css/site.css b/src/site/resources/css/site.css new file mode 100644 index 0000000..43c3cd8 --- /dev/null +++ b/src/site/resources/css/site.css @@ -0,0 +1,8 @@ +h1 { + padding: 4px 4px 4px 6px; + border: 1px solid #999; + color: #900; + background-color: #ddd; + font-weight:900; + font-size: x-large; +} \ No newline at end of file diff --git a/src/site/resources/images/romelogo.png b/src/site/resources/images/romelogo.png new file mode 100644 index 0000000000000000000000000000000000000000..2c90608448e52857b31df02fa934de010996491f GIT binary patch literal 10835 zcmV-ZDy-FsP)EQkAMsI;g%@JeHXd!QkoO34|vxbt^eu#7yT)hP%6~4xtu?mRfO#vYxE!mwN zp+5h7uYrh<7DPsphQvNU#ho31-VTw*%bgveKL30_MEX1gtPMb~fyi!cM$=D4tRcYa z@4W>gC2Ng2<5c1*WRZBQL(pHq@(A=Ah`1Yb$MX=$8BMAq`w`H|5$H7#@z91y&EZZC zQ2*oo5b4K&l@aJQ5LwwzMY;&=y#yl0f^US}30ktqp)MM@zEf>)fk?iKkULQYk+GzF zSKpb-F6wEofyfMPh*bD=(ZKbcYE2Mn&J@bF3FST-xokUWOqPeEIzlMhAykJ6HHU?o zLvqIV4T(ZSk|Nh9kd`9qj+b*jX(=RvK!i3Xw|0KGjrq1h#F+J^DGxE`&ot)EFy-k& z$tt1P!<5~G3h(xD@Roau4%SBt4VO(FOe9Siv?H`%`J}Ce2u9i+qXRn9`Jr%l4JL>* zBp9>4f^||O!=GLqF2A*SsWE$mF=q@s?|jZ4Y1GKWjoGT4H56`oWgfzWdWbO}XwPV4 zzH9p|igW2A6fP7>R?@jFn8%IwQQ)0_}LN) z+11D_HpLpV0fo6v?W@Rz3hd(IDRvi1*9zsn?I`pWfWqo91vhA`6{J0+NI(j5TD0wJdrKBRZLWGoP7}VTOEa`4D>hSjTO^7gNQ=v^CA_~QaLZm_?KF#4%(%mZTjSyjs3L3gx_Ha_ZouMLj zK|~`~zPrt+!`suv5UFOIrFycS_KdP-%60>hY#kaQ8z^OCt7M&&4CK>=qGdvfXc79s zY!NEkMw-(5A!0j{x)>t0$K}Z=`i`2$x-Zf?q)0RaFX7WCZN+T zx(Eq5~xJ3sUAO4}~M`BH1HJV+v!HDmOH zWJiT9`Fe&RW7ZdZJyjvF9-2@tZ2;E$@THLoyqup%^cG2(wS0??Ky`MfrtxygFQery zr9M=64I>rKQPxo^epYxBl}=OHhsrKL$%mRpS}VE^BHezslKz?i4tR*bD+_X^bVJwy z$KFxY(Nv^&L8N!gaVLAx_aIWJ&uCOsq?3c&J09&F@P3W%VGcT+XJ|5mMybURl5tiFzqJ^>LzgwhR^iP#m8K~Fy$(vJ^1 z0zH(92nfY*s;R6m%CES6qu^pn&Z)CE{M+=c@>Kp%ZLhKb8tjcAO=3I-2dc`|5 zVcou%#r_wU1zcPn5W6BU&i!EA%7gK%{Gz`%8ryUywY9{U`MHgRgi2>@h)H)vN@YQI z!S%$#8_6`MrPP)c)sz$<*OnFu0tTbCt+l1Cxv8_wzh6`YWT3vOy0j+Ot`1z!k3JCR z9+vonIs-J8AcEIa1zM2ICG?m?5S2gAu2$Zw!f9v156&AFw#Z4$p$o@|Ib`9O;Q6D1 z=a1a${BccjzSZW$`fW%G^GS)=b1BeMP%pEthDc?7@tu<78wD{5nMcmv2snDxJ1k*6 z$iV)Xr9NlpRW+1ocA%lT77uFvv^RQj2O$EXB!9O0OaKLG$(;n-tJN{>CIxPvKODYz zLX?M#W)5FG{`v`d`-0f!`ijzPQU1x{zR3~0k*`Gh#q3@OcttFognVGm5M!&#;p$+B zG$e4t7keiHXaFw=ieD9cX-&wbwcr$?3G1=w>+V*m$GXkf7L~GnU(6El5&SK$hGEhlYlG~ch3n-UxL z{Wwj09Cn|EiRT)Y5ab1_6TW1k2naDpE}tUR0NNw8sdkb&6e7b(E5GzXJOB=EM)6Hj z<}uBY-50%BLI9BDcVSUWn}VC($d3l#ItUTGvhJLAya+v=cLbP`h525$gRIy{+&2@q zP4oluvJIyE16jJBEM7-8`Ov&$AMp<(`$92Iewl1TNe|_joTDn89AiF1h3{6 z(q`-wx{A|MfCFt3^8NVq7{v%D26=^kH%5=-h~M8Ei13R(G3%%rB7w2)#nqYW;W=@A zckrdv?DPj+S`Af&Em>BZ7Z~f-afpE36fHL9IB|r8syqdAEzj6y9|Dy8uv3xojmH)< zXz&65uH8=7Y@>O#Cs~EOm8{%CGqAYI$A3*lCK{S z*|YKJQMd6T2*71RzZ=W8Dk;Ppbft$u1hZ>WZPv0q$*;HtJD8e0z$})MeTpp^d3j4n z!a6lXY8uOJm}t3(kT;PU<_j0v_>^}5l{46h1Qn^QRy=(shOFG`7>J-}m6ATLnI{?{b*EG#ykanRKu_YreZ*~Yo z5PeP0KCn5dDFo1PDq8V;ZUGftJ5NO*mq652C$D`xOesXRT$UgLH8}68d<=C%b$Q7A zQMTZtdodc30Ki_t4#CZWSWRuV3n7Bn;}8{_(|#2b0WS!N;-6o#o);H7fEa-9%teis zX^6~9h`^}I8r?JFPQixOQy~KD8S8kvRTyt0L?SP5bqp1;8609kKm?dr=S9|d(Z85@ zh#h-Ftn-2nKm>-C29svXCCd;2Ly25Ag?;2w;MT}xlY1~kST*%>_6dj`YFR{0MIgXx zimUd@B6cE#c!iVYo@CQbA#m3fFYhv-1c(upQZ~T?3;Rb0U?DvMiD$c?cIzxd1Zar! z-@-l_wQ|NGx2Zi9A~3NxG|5VhrX3cDIT*k4O70o9+nP!*G@6=5W`mHu^DmZ%Wu>Kw zRNf-_CrM@?xweSJjwPo*CP!W-2YyBZ48-3+{{|Qm_RL-BMa2bJx6}#BDyN#-g%}uD zlCE|HB5>K?nRXsO^Lx@rFYl` zk?$E*4@UYjMp3gYu0q`{&%Pt|x3;tZHj-u67&E?Mmrib zKiu*g0f=C^Uy{))R}5a$VZ8?O4TK&kq5do;VnVG|u^J8R?yXIY(zCf&JE^w|6F^rKew?H&31`OBb&u?AAiGQifTIDR1Rx2v zr;uM#;-Qa{n|@;f5y%|3G<;3;HL#I)jMo5L8QF3}QOQl2E)bZ`AONv6NrDKBWUQM*ts) zVzMg%WDIBFDlgyv(h4|!H<4oPh!+xel)CZk;x8x+K%h=3H8fJc3`?jW`al5Egb2Ja zCpRd}fCv<_(XQG#Pp^Ckl+{fV!$=$NC9wbz*x-w+<@KUj5|U|Sa~(Ugc#2bJ4qo1t zdSZ|+L@>=e45X>jE_l$wrEyd!(Scprz5##;NQLNhMT$*QydkfUy4>uA2&Vt=Nx7aA z=jkg>GuF9talG|bq9RadV)t%j8xifZh7AX?DwOC@krYe&Xy|#hGMTpq5$tAD`C8B1 z(D2cSYy#%?{0cdQSPc>I9Rv`ueXgo62H)Wni9IyZpaG&ts@c2NWSlDlfSG&9dhJw$B{zTL z4l0vMX-^RGJ*apUlpVYLH8dW;ORnMOZCXEE$Ge&ELWn+`(M5s?#E$f6g{}9{ifJ}_ zXDl(An!{ZSk?^EVYD*|XMRXwoneo(zrK;zJg#A#7Y8oTLqyZ%W)&jv0|#GH_<_;$gbZ!1 z7!b)n^pXZdptxT6N`Vg;8Gr*#Facip9tshc3eQkQNd>-E{|6U)DzsAsCaTRO;xyZc z64cPz9ytm@Re~43ml8xDFe6S}_1so`%xw&U6pPXnQ8@6|Sd~9|Bt#JZygz1%Q7P6S z;7Bj_Juum;H2e=56AvEIq!gb6eq>4U0S-V*qF&%p0*I(pn*hVYEwX79*hB0H^bv3Y zHi22#Xp9F#@nHgIA*dpvQG^0wW7&j%RS+ozL|`Su4jQQ>0+m4(dLcx>mB39nEe7f; zv|m6+b9+QU^3Ix&$9RZ_P-EIc! zmK4|w83K}olxpkg77EMa2#jnI%yFdPIDne;2x^9|D8n;h^ zXP~D4uO1DM%xm2pBI*ttySfW>MXkbcaNqyal~UC}fhqR7 z;(ijMemub7vC-JrY<|hHb26!b3~}sjOph255c zi1i?TjX_>FSF)Y-B#4yPYXA}A{~rp7P%d*+9*&wEs;XFY%PD>ZuQ~Lr zQXKgQFOCEl+}6t**8(Esl?|@J37FT@ED5dP8hAuXYWpb{mBJN}Ai_ClG-(F+W!{x| zcK=mRf(Uw&QIY~5uT>I40~}NKP!|k~0O&GoN}kUbunZRvBybisU0crAu-~wMSE^J5 z1`=$6kyry{&#N~S6<82jIdh2GCJVJ0k=0U4xj{Ubkfjboq^+$jWWng3B(ADapH>*p zIdwIu$i5Umh3_8bjo?QVwS_-nMb}j$24?$m<|OK(^Sm~+&u}zEw);V%WYrc-D)!Z} z>DXCap%og6q~Pb|Yj}20GkA@Z;Qe8R*^WV^p}OM8Dpzj*RS%;g;)p=Ou}nxp6E}n; zZB;-7g2)Bs*@qB6ZRav#NsuM@Zlr{GHjY*K84^#+G9;WeoInb)QO0PhtSO8w3BePV zdnpA*@V1dlW<_Wxc&dU_sVFW)i?y;=<3;Fi^pT<6^tlq z_szY52*0n~cI#?x`OO;DF3z;VIK2Z!M2ZrUxFIrOodP0IP}7;)MJiHh1c|*6p#rb+ zNO(@E*<&bA3KgfVx<+H^LrFnA0Gl)|t)K^pKa!GOL?h(cM&{f`Rz=c-NOf^O&H<3N z|HD9nj5t=7vv7vBdjJuQ!@;aUME3L^yW+k3`~n;@!*Lu4t$Ic?5hCG<8x#EC8d0I>rp#fnEA2##uYe(IJfYK7rAkIhw=; zra;z__?jL>YDx<2ib~Y=^g7gZrg1>FC5T|NZf%}44Wh#jr$sckD$Y60D!Zn66o5!Y zf|E9#js8}lZg7%j{CKNTh8i>mXn>1{O$UCiP@6%kvJQy9CtuUv?G1ZIoHB@n6Giba z3~N$CbUQ2avM2#2uFH}S@!BtI(fSavFL3p~K_oI+W6ui{m?#HFh+smD$nk4F93g=? zqGvq=L{7&nlp%tt1zTYgVplDO80zvMPAxj}ibCcEQMqCc@xq2Y$)BPyjVqn|Xw{#fCBlHv1ikL5^PieAac#T z;S|9{Ts)~X(~uz~3#`~GN!ozcvz5_$EZgb1-59W>NuXT6lWg#6Ilf{P2N4{I*A3lx z8W4d`PS>}h3~!bo0)i2eu%06%Q7PLr-84Z-TN6(^$&-g!Jo>8Q*?s?NlWRr|7eIvF zM}A?jf*JuLDc_1O^49nGt9SPwIAq2Xw^;_hIt$)DE-d~s!`diBcD4Z`aQ(9#H$kM^ z1p_z+A~YZ^)-An6apOR}PA~u%H^B8Nf5bO4Dv zM@Zt*!_^yY_}FI5T!La#tA!9{D<}a(s+oHiFOK9P5<5z4q2*E#=U3g!coF*`0<0JY6ktBK84$U;NFIBm z&~b=Bt<4FQtKuL+LzZ5~uj*h@HOEm4t&17UExb9lM5e)_3cIS5B+S91d(H};n$n# z)+bnf3<(UfQc`cz)f8(WtmHB0QNnC5#*|19LF{Vb4aTp8Xq%HE;Y)PS?zMF{o;A~% zQ0yl4#p)&ryQv6!B)6uK4G80oamM~$oXslnBR;kn^O~nP(x~II2uDRAd9WLOX~4iA zF*J}fV6?CtF{HM%N@I%iw7KXIy{bTIuHBS@b@-IoFDO9-N6p-cWdf53DY|`C?_gFt z_Vm^qv9L)3moFIer*|ntWS@>EL_jbil9Um{gv8&8grs5)qvv9qF|XM0%_bOIZHY%z zE4`3K%9$e^AbGGRIM`Ya`~>f@CGHTjjtRb^3=a_7sNOndqxCE%!3<3aBJ?cHFdw$- zEe-W{>Al)MnhIY__gPbj%;+kJ?7yfu$V$&tkHE9+GC49sY>nv@8XE1)$2L=0odF^TAHa*?o3-VLM2HSxDC*=FY}4bw4QD-*qGctBz)N?|i&p~? z*o?!zZM3oKK*Z<%K}31hnI1$Sx8k%2Zg2~$GDIndk8P$J%@Rf7qXX;?77<|th*UBQ zKjKM6J)le=DukLV^c*W3J%A3vdTYf-+M>&d^>EfRSnkC=!xBW`!VOzAjvJ`>fKDG| zRdN3yf-T)_e=IosKr^o8DZ@eG???-T6PS-}hPZHfwqlr~hjhe^2Z%shW`msl|C2Z5 zo18dYFp&kJg!8lDS)BQ7`_^#IdM3h)g@~wY8fQl#sEKDuc(`Y~& zF!44*1cf1@s;M+|qW#Ic6tT^K2+W{ty6$FQRHDR*IFGT~N^2^h4kpq=3Fa85ytB!6 zK}3ukfEA8SVn~2QMF0`*L`|{q!Ee5{5F=uJH=e_&2*j2GjhlY-AOc4WPS~{(B48-6 ztHQdmfYH5? z**{^Us4HQPwb`R-;!(kp8xNCBCDsuB7^Z|kPn_3li#XE7R75G+N@J@Jk+p~uupJ^m z2@VQqZEN3^(EemZT7)8ENbTuG$qu+_xR9cfI1QZn8VU;9a45TFjhFqEy6%{0r+uNe z%Bo@|Fu}o?E2W5IbhiW`vSt^-eG&kH`gCs;Zmg|B_*plG$i-!vo?gU-;Is(4Afi5Q z1dr2g|7^&hI(Qug0{`3YcmNsz%LLJ>Bj7=G_84GFceiE~VIcyM6R?mH%wM)|3P(K< zTq>B;N2J{nxKBca2r|7RAeRYsG`%d|e`~~&iB?f^AE*e-=X)+Jq}LltIi6l`g$z~p z;%#QM2nogcnQcad@FApgO~}vz$Un4tsQU2yY#?iZZSme^amPoNqY@3 zXNy+ab14Az#xWZ+EsMJ1^&>E$N>|&!$d<}D7O&nU->oJqaLtXc3=y1F6t6sbRUC=X zMNU>-diMb$IC=M4?m3*?E#=hw=t~(jaL6z@AOqPXYp?nNMB! zyU0l-@NIIAI+(nQlmW0Mv35r|gEBQUssR_cDhe+94N)O!t8~HuSmFU>NO#R36bPRY zsD>{A5%wMvfb();GK#EG`F>7rjCFP{Lq#*cv=O}mcX++|o zc?zLgra*n6uGiVTh*-YNur2j&n!0eiK@8>{vP)9b1b93Op&9yoI?joyX^=L^mj zsHvl2ZZ_Y$WNu(>Nq*=;Md%QOR&0+@k9K2qdFZ0C@Y?7pIK31iux@dCAk@L@7%jVa z4F#F2JjAJMwbkZ*hV!9k51*x{jKEU^i+Fk#-SJRdN)OY8mF(W!tk~Lo7l%Y}az@ZM z!)uD<&~X+nNufTl%Ht4UV1;g>ST^a^=ZiciKMO{tr!&)N0o5e|*5}m0B@m3L8OBVH(_G2WLW{4x zc_t!a$%I}C5k&o{&xgS@AA6l26Y=;%s}cz)P%RUGpR!2TILpPRIC$#qs18TXNOyj- zmw$uZVB>#%B_rbM)CxPjzssk4r~bp(!dsq*Bdx29Q`nCFb+TwqIF%*EWBjF){57p3 zc+ur=tyo$y>(QeWErML4hbk_@t&<(;#N&Ba;tFphD{@*&ZCO!GNkLU%Zbh#0I9PjM z)Z-z7D?uWkC5NA<_OXM%pa=k|fXeD=An}tmMkDwkS_Tu33}A^_gcrU+C2UIHWeHMT zoUFY=-&4x>c!=l?G|t)8yHq580*U#W#EzlN=;&)C@{c6&ClnlEkMWg(>9Cg$h~%*SwnHNu`$=lnCBuCEfY#s3FW>* z<$j?$QmB`2YqSaxmBFevj8LENLu(lknr*b`S%L_Nk5Ig<&ktu`9{?*5VQ&=Z>qF(( z{u^8AWwD*i#=E2?kKTLV*<2*lCkPEm?Kx3skT)CJ0TH3F>kstZ$@Wx{!C-m5M$P0M`Y9kIiS-ydzdkMxP$UYDy5q9a9hPy z?p_jO#vp9IupyhIVh3a=lbG#*42j)Ad9uLV+tO=4+rCMHhe+1oo<1lfe~Q!v_Oqk< z#nssruW(dTE!AWDR;!*15mM+(8fS5%Kq_5YvL=bshQFkAntBRJl?$nJrGHDN(PF5l zdIn00RgtP0_{sb|idDKGn}0G@SerIps*{w_`sIJ|xn>3_pH3eyo=WOx^3B7G@Lv2a zbe3^k;7r?t2WwqP1$~x2UNN1PWZ+J}L}O4A#n@$lKBB^+spbcZrjiPCgXtr8vU*TjJ)O|xi$I#;$w7^ClI z{N?o*e>ru`Ghw?vK*{PG<34@=e*--SQam-znlkE-lScdjPu+%8LU{ zYFyuc`_VA(4@5lS@1flveeuz6FuP_%7Ek?T;A2}>yoqn(B0hiou^%g%S3LtY&zb!E zs4t$ZxaK6HgcLZ}rj2{y*$3uMe(s}pf9?LwD-;}eXRVm`@?cykphd=5^dK^Z92UAPtJ8j0K0Guek1nX+SZo z$ah}*6(&+7DyISm`E7hptPpVd=fM9ZWWn;eFYnp#9!P@Ms<-1JKNkT(3luqL$Bi5} z>}fMZYG%;MD=`xf)Euz&@6My25ogFmpIl~7`g7x*iTLK>2mim+Frb8xZ(scLFYuS* zqt12E-yf^G;Z%Qn{0q*?_pX`cPgfQR!FMp5Ed;euHY@%jK2{_2-MqSU2q z+WFv59(v$EMS8Pj_Diq+gv=MQ)i)qgHvNSEpas*OUpo6G(qdXD zB~xRDpIvtR|?|h*?4fP+gs;@KNY)x(fIJMkCMD8-fRCF=KbN#vqOQB{hR+b zYr>y5FMmTE91}$3U822^(U`dG?BDPw7&_SQj~Cyar&1 z8)wl4*UtN~OgAol;~VD}g1z1^y)p*B{`K`o8t+VK%b5&fF!GBhZ=4-ke|rLzFvMwV zn2B%ZPI->5%Z8bMeeG8O3f4VsK%sN_HK);EJ%txh%3tUD?rV=UWln6$oJ8MPKK<$6 z{xs6}qo;oRlLO#lnDX-J+gH6!A<{bM<>ww`v1@)8mV1FS-u~X}j}T!lG0y$lTmK_d zkxCbj`L9%@It}~e2~YPo@hgbO)4%&Er9F)^S1x$<+NmL^a~5FTJUhzo7+<%b& zmcLb{I$b?E1hazCY|fmBS;>HRM&$kF)3><2S#xtdCF!8>^)sJ&`e#%I1k)*-h84eY z+3R#&0wRsGUVi>TLKeRD%EOd@n+jhD`Se^cB@!Y;@)Ab@oprayUpB4mcVB;m&H-k+ z&h^80AEgo~fJNqE{*UW(2Q<*vr{XM+1c$7sfqSua5lITiR%yqdDkDwlu!?J@e^ zDi?|v5VJbhXP){wdUXBt&{1DLNr7b=2N*0!g?#X1FN6p>xd}AWB$UzFYM8ln&daH% zhUCPJT=)HJo0h*xC6YSVpzZH(T=s^?x36A3F<6xO0fp6z2IQG|xtS7N9gCp{u&8=c z=juG_nWb}Hs=GA-6A$?j#MziPnGy*+_}zekZ#@d~ZhmQjGbDzU^9KNPtG|1dqM^X~ zvkxBMyyA_TwDCbZ29mON^`v>W)6l1zvnD~59{%a?g0>F?uTcom#Zyzy40+|bUx<|h zi$3e$y>#ev1*IvQ=C|R!!lcm@tN?VS%Ttg41Z_Th@SjxH29+vsu1t0EUi*&tUa7yH z?v(SQYv0d&ap8;?a^gp#?e1q=Vw6D@Fp*SvhX5Q>*mpk#hdisWz}PhrvNV9A>>f^iVA&H~eCD^`CC#(qmCd?9y& zC9Awc2fb&l985H+mbU?@b{??)OreQ1*%Kp)9YwmXO9YJR`6LU;-CIHfyo-{jk^PV? z)E=WjE}9-hd|&RZ<1+LW$~<))fh8-A1>Yc)M%%YXJ$7GMbl2%G1}m<$4lf3*PYa7- zoCRl=MgPz#>E(>;CRdwHaG<7K4$rRgji^9q)V*oa{O)0jnZWsE*Ka zq#qWl0)_Hjx{IN7tx)W);}Un%b#&*u8sUz~`jTG^8G}gGK^;cZn`W`UFAf@kek$Ui df$Y82{2ymMg>RmA!D#>h002ovPDHLkV1j1dKi>cV literal 0 HcmV?d00001 diff --git a/src/site/site.xml b/src/site/site.xml new file mode 100644 index 0000000..23c4366 --- /dev/null +++ b/src/site/site.xml @@ -0,0 +1,19 @@ + + + + ROME + images/romelogo.png + http://github.com/ + + + + +

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

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

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

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

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

+ *

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

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

+ *

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

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

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

- * + * * @param syndFeed SyndFeedImpl to copy/convert value from. * @return a real feed with copied/converted values of the SyndFeedImpl. */ + @Override public WireFeed createRealFeed(SyndFeed syndFeed) { WireFeed retValue; diff --git a/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java index 8bb8ac0..8faea35 100644 --- a/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java +++ b/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java @@ -13,22 +13,23 @@ import com.sun.syndication.feed.synd.SyndCategory; import com.sun.syndication.feed.synd.SyndCategoryImpl; /** - * + * * @author cooper */ public class TreeCategoryImpl extends SyndCategoryImpl { - + /** Creates a new instance of TreeCategoryImpl */ public TreeCategoryImpl() { super(); } - + + @Override public boolean equals(Object o) { SyndCategory c = (SyndCategory) o; - if( c.getTaxonomyUri() != null && c.getTaxonomyUri().equals( this.getTaxonomyUri() ) ) + if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(this.getTaxonomyUri())) return true; else return false; } - + } diff --git a/src/main/java/org/rometools/io/impl/OPML10Generator.java b/src/main/java/org/rometools/io/impl/OPML10Generator.java index 09255ef..2246c1f 100644 --- a/src/main/java/org/rometools/io/impl/OPML10Generator.java +++ b/src/main/java/org/rometools/io/impl/OPML10Generator.java @@ -26,16 +26,15 @@ import com.sun.syndication.io.WireFeedGenerator; import com.sun.syndication.io.impl.BaseWireFeedGenerator; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; import java.util.ArrayList; import java.util.Collections; import java.util.List; - /** - * + * * @author Robert "kebernet" Cooper */ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { @@ -51,13 +50,13 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe /** * Creates an XML document (JDOM) for the given feed bean. *

- * + * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not - * match with the type of the WireFeedGenerator. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ + @Override public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { if (!(feed instanceof Opml)) { throw new IllegalArgumentException("Not an OPML file"); diff --git a/src/main/java/org/rometools/io/impl/OPML10Parser.java b/src/main/java/org/rometools/io/impl/OPML10Parser.java index 9935e40..16be175 100644 --- a/src/main/java/org/rometools/io/impl/OPML10Parser.java +++ b/src/main/java/org/rometools/io/impl/OPML10Parser.java @@ -26,8 +26,8 @@ import com.sun.syndication.io.WireFeedParser; import com.sun.syndication.io.impl.BaseWireFeedParser; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; import java.util.ArrayList; import java.util.List; @@ -35,9 +35,8 @@ import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; - /** - * + * * @author Robert "kebernet" Cooper */ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { @@ -57,16 +56,16 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { *

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

- * + * * @param document XML Document (JDOM) to check if it can be parsed by this parser. * @return true if the parser know how to parser this feed, false otherwise. */ + @Override public boolean isMyType(Document document) { Element e = document.getRootElement(); - if (e.getName().equals("opml") - && ( e.getChild("head") == null || e.getChild("head").getChild("docs") == null) - && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { + if (e.getName().equals("opml") && (e.getChild("head") == null || e.getChild("head").getChild("docs") == null) + && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { return true; } @@ -76,13 +75,14 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { /** * Parses an XML document (JDOM Document) into a feed bean. *

- * + * * @param document XML document (JDOM) to parse. * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). * @return the resulting feed bean. * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ + @Override public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { Opml opml = new Opml(); opml.setFeedType("opml_1.0"); @@ -182,9 +182,10 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { ArrayList attributes = new ArrayList(); for (int i = 0; i < jAttributes.size(); i++) { - org.jdom.Attribute a = (org.jdom.Attribute) jAttributes.get(i); + org.jdom2.Attribute a = (org.jdom2.Attribute) jAttributes.get(i); - if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") && !a.getName().equals("type")) { + if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") + && !a.getName().equals("type")) { attributes.add(new Attribute(a.getName(), a.getValue())); } } diff --git a/src/main/java/org/rometools/io/impl/OPML20Generator.java b/src/main/java/org/rometools/io/impl/OPML20Generator.java index 7793ee8..d1122b7 100644 --- a/src/main/java/org/rometools/io/impl/OPML20Generator.java +++ b/src/main/java/org/rometools/io/impl/OPML20Generator.java @@ -14,12 +14,11 @@ import org.rometools.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; - +import org.jdom2.Document; +import org.jdom2.Element; /** - * + * * @author cooper */ public class OPML20Generator extends OPML10Generator { @@ -30,11 +29,12 @@ public class OPML20Generator extends OPML10Generator { /** * Returns the type of feed the generator creates. *

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

+ *

*/ + @Override public String getType() { return "opml_2.0"; } @@ -42,13 +42,13 @@ public class OPML20Generator extends OPML10Generator { /** * Creates an XML document (JDOM) for the given feed bean. *

- * + * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not - * match with the type of the WireFeedGenerator. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ + @Override public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { Document retValue; @@ -58,6 +58,7 @@ public class OPML20Generator extends OPML10Generator { return retValue; } + @Override protected Element generateHead(Opml opml) { Element retValue; @@ -69,6 +70,7 @@ public class OPML20Generator extends OPML10Generator { return retValue; } + @Override protected Element generateOutline(Outline outline) { Element retValue; diff --git a/src/main/java/org/rometools/io/impl/OPML20Parser.java b/src/main/java/org/rometools/io/impl/OPML20Parser.java index 5aaabff..28ed5b2 100644 --- a/src/main/java/org/rometools/io/impl/OPML20Parser.java +++ b/src/main/java/org/rometools/io/impl/OPML20Parser.java @@ -24,16 +24,13 @@ import org.rometools.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.impl.DateParser; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; -import java.util.ArrayList; import java.util.List; -import java.util.StringTokenizer; - /** - * + * * @author cooper */ public class OPML20Parser extends OPML10Parser { @@ -47,14 +44,18 @@ public class OPML20Parser extends OPML10Parser { *

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

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

- * + * * @param document XML document (JDOM) to parse. * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). * @return the resulting feed bean. * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type. * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ + @Override public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { Opml opml; opml = (Opml) super.parse(document, validate); @@ -91,6 +93,7 @@ public class OPML20Parser extends OPML10Parser { return opml; } + @Override protected Outline parseOutline(Element e, boolean validate) throws FeedException { Outline retValue; diff --git a/src/test/java/org/rometools/unittest/FeedOpsTest.java b/src/test/java/org/rometools/unittest/FeedOpsTest.java index 36b88ac..24c322e 100644 --- a/src/test/java/org/rometools/unittest/FeedOpsTest.java +++ b/src/test/java/org/rometools/unittest/FeedOpsTest.java @@ -1,63 +1,64 @@ package org.rometools.unittest; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.ObjectInputStream; - /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public abstract class FeedOpsTest extends FeedTest { - protected FeedOpsTest(String feedType) { - super(feedType+".xml"); - System.out.println("Testing "+feedType+".xml"); + protected FeedOpsTest(final String feedType) { + super(feedType + ".xml"); new File("target/test-reports").mkdirs(); } - //1.2a + // 1.2a public void testWireFeedEquals() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = getWireFeed(); + final WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed2 = getWireFeed(); assertTrue(feed1.equals(feed2)); } - //1.2b + // 1.2b public void testWireFeedNotEqual() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = getWireFeed(); + final WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed2 = getWireFeed(); feed2.setFeedType("dummy"); assertFalse(feed1.equals(feed2)); } - //1.3 + // 1.3 public void testWireFeedCloning() throws Exception { - WireFeed feed1 = getCachedWireFeed(); - WireFeed feed2 = (WireFeed) feed1.clone();; + final WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed2 = (WireFeed) feed1.clone(); + ; assertTrue(feed1.equals(feed2)); } // 1.4 public void testWireFeedSerialization() throws Exception { - WireFeed feed1 = getCachedWireFeed(); + final WireFeed feed1 = getCachedWireFeed(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(feed1); oos.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - WireFeed feed2 = (WireFeed) ois.readObject(); + final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + final ObjectInputStream ois = new ObjectInputStream(bais); + final WireFeed feed2 = (WireFeed) ois.readObject(); ois.close(); assertTrue(feed1.equals(feed2)); @@ -65,47 +66,48 @@ public abstract class FeedOpsTest extends FeedTest { // 1.6 public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - assertEquals(sFeed1, sFeed2 ); + assertEquals(sFeed1, sFeed2); } - //1.7a + // 1.7a public void testSyndFeedEquals() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(); + final SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed2 = getSyndFeed(); assertTrue(feed1.equals(feed2)); } - //1.7b + // 1.7b public void testSyndFeedNotEqual() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(); + final SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed2 = getSyndFeed(); feed2.setFeedType("dummy"); assertFalse(feed1.equals(feed2)); } - //1.8 + // 1.8 public void testSyndFeedCloning() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = (SyndFeed) feed1.clone();; + final SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed2 = (SyndFeed) feed1.clone(); + ; assertTrue(feed1.equals(feed2)); } - //1.9 + // 1.9 public void testSyndFeedSerialization() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); + final SyndFeed feed1 = getCachedSyndFeed(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(feed1); oos.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bais); - SyndFeed feed2 = (SyndFeed) ois.readObject(); + final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + final ObjectInputStream ois = new ObjectInputStream(bais); + final SyndFeed feed2 = (SyndFeed) ois.readObject(); ois.close(); assertTrue(feed1.equals(feed2)); diff --git a/src/test/java/org/rometools/unittest/FeedTest.java b/src/test/java/org/rometools/unittest/FeedTest.java index 676cd93..70552f1 100644 --- a/src/test/java/org/rometools/unittest/FeedTest.java +++ b/src/test/java/org/rometools/unittest/FeedTest.java @@ -1,30 +1,30 @@ package org.rometools.unittest; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + import junit.framework.TestCase; -import com.sun.syndication.feed.synd.SyndFeed; +import org.jdom2.Document; +import org.jdom2.input.SAXBuilder; + import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.WireFeedInput; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.InputStream; - -import org.jdom.Document; -import org.jdom.input.SAXBuilder; - /** * @author pat, tucu - * + * */ public abstract class FeedTest extends TestCase { - private String _feedFileName; - private Document _jDomDoc = null; + private final String _feedFileName; + private Document _jDomDoc = null; private WireFeed _wireFeed = null; private SyndFeed _syndFeed = null; - protected FeedTest(String feedFileName) { + protected FeedTest(final String feedFileName) { _feedFileName = feedFileName; } @@ -33,43 +33,42 @@ public abstract class FeedTest extends TestCase { } protected Reader getFeedReader() throws Exception { - InputStream resource = Thread.currentThread(). - getContextClassLoader().getResourceAsStream(getFeedFileName()); - assertNotNull("Could not find resource " + getFeedFileName(), resource); - return new InputStreamReader(resource); + final InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream(getFeedFileName()); + assertNotNull("Could not find resource " + getFeedFileName(), resource); + return new InputStreamReader(resource); } protected Document getJDomDoc() throws Exception { - SAXBuilder saxBuilder = new SAXBuilder(false); + final SAXBuilder saxBuilder = new SAXBuilder(false); return saxBuilder.build(getFeedReader()); } protected WireFeed getWireFeed() throws Exception { - WireFeedInput in = new WireFeedInput(); + final WireFeedInput in = new WireFeedInput(); return in.build(getFeedReader()); } protected SyndFeed getSyndFeed() throws Exception { - SyndFeedInput in = new SyndFeedInput(); + final SyndFeedInput in = new SyndFeedInput(); return in.build(getFeedReader()); } protected Document getCachedJDomDoc() throws Exception { - if (_jDomDoc==null) { + if (_jDomDoc == null) { _jDomDoc = getJDomDoc(); } return _jDomDoc; } protected WireFeed getCachedWireFeed() throws Exception { - if (_wireFeed==null) { + if (_wireFeed == null) { _wireFeed = getWireFeed(); } return _wireFeed; } protected SyndFeed getCachedSyndFeed() throws Exception { - if (_syndFeed==null) { + if (_syndFeed == null) { _syndFeed = getSyndFeed(); } return _syndFeed; diff --git a/src/test/java/org/rometools/unittest/SyndFeedTest.java b/src/test/java/org/rometools/unittest/SyndFeedTest.java index 8bdddde..6686fcf 100644 --- a/src/test/java/org/rometools/unittest/SyndFeedTest.java +++ b/src/test/java/org/rometools/unittest/SyndFeedTest.java @@ -6,21 +6,18 @@ */ package org.rometools.unittest; - - - /** * @author pat - * + * */ public abstract class SyndFeedTest extends FeedTest { - private String _prefix = null; + private String _prefix = null; protected SyndFeedTest(String feedType) { - this(feedType,feedType+".xml"); + this(feedType, feedType + ".xml"); } - protected SyndFeedTest(String feedType,String feedFileName) { + protected SyndFeedTest(String feedType, String feedFileName) { super(feedFileName); _prefix = feedType; } @@ -29,239 +26,117 @@ public abstract class SyndFeedTest extends FeedTest { return _prefix; } - protected void assertProperty(String property, String value) { - assertEquals(property,getPrefix() + "." + value); - } - - public void testType() throws Exception { - assertEquals(getCachedSyndFeed().getFeedType(),getPrefix()); + protected void assertProperty(String property, String value) { + assertEquals(property, getPrefix() + "." + value); } - -/* - public void testType() throws Exception { - assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); - } - - public void testTitle() throws Exception { - assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); - } - - public void testLink() throws Exception { - assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); - } - - public void testDescription() throws Exception { - assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); - } - - public void testLanguage() throws Exception { - assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); - } - - public void testCategories() throws Exception { - List catlist = getCachedSyndFeed().getCategories(); - //don't understand why this one fails - assertEquals(2, catlist.size()); - SyndCategory cat = (SyndCategory)catlist.get(0); - assertEqualsStr("channel.category[0]", cat.getName()); - assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEqualsStr("channel.category[1]", cat.getName()); - assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); - } - - public void testPublishedDate() throws Exception { - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getCachedSyndFeed().getPublishedDate()); - } - - //how do i get height and width? - public void testImage() throws Exception { - SyndImage img = getCachedSyndFeed().getImage(); - assertEqualsStr("channel.image.description", img.getDescription()); - assertEqualsStr("channel.image.link", img.getLink()); - assertEqualsStr("channel.image.title", img.getTitle()); - assertEqualsStr("channel.image.url", img.getUrl()); - } - - public void testEntries() throws Exception { - List entrylist = getCachedSyndFeed().getEntries(); - assertEquals(2, entrylist.size()); - } - - public void testEntryTitle() throws Exception { - assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryTitle(Object o) throws Exception { - SyndEntry e = (SyndEntry) o; - return e.getTitle(); - } - - public void testEntryDescription() throws Exception { - assertEqualsStr("channel.item[0].description", getEntryDescription(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].description", getEntryDescription(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryDescription(Object o) throws Exception { - SyndEntry e = (SyndEntry) o; - return e.getDescription().getValue(); - } - - public void testEntryLink() throws Exception { - assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryLink(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getLink(); - } - - public void testEntryPublishedDate() throws Exception { - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); - } - - public Date getEntryPublishedDate(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getPublishedDate(); - } - - public void testEntryCategories() throws Exception { - SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); - List catlist = e.getCategories(); - //don't understand why this one fails - assertEquals(2, catlist.size()); - SyndCategory cat = (SyndCategory)catlist.get(0); - assertEqualsStr("channel.item[0].category[0]", cat.getName()); - assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEqualsStr("channel.item[0].category[1]", cat.getName()); - assertEqualsStr("channel.item[0].category[1]^domain", cat.getTaxonomyUri()); - //DO 2nd set of items - } - - public void testEntryAuthor() throws Exception { - assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); - } - - public String getEntryAuthor(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getAuthor(); - } - -*/ -/* -//things you cannot get from SyndEntryImpl -// item[0].source -// -// - item0.category0 - item0.category1 - Thu, 08 Jul 1999 08:00:00 GMT - Thu, 08 Jul 1999 09:00:00 GMT - item0.author - http://localhost:8080/item0/comments - http://localhost:8080/item0/guid - //TODO: I still have the elements to test -*/ - /* - public void test() { - assertEqualsStr(feed, ""); - } - - public void test() { - assertEqualsStr(feed, ""); - } - - */ - //Things that you cannot get form a SyndFeedImpl today - //these need to be put in a RSS 2.0 module - //or is a roundtrip to wirefeed the right way to do this? -/* - * - Search - Search this site: - q - http://example.org/mt/mt-search.cgi - - - image height and width - * - //Copyright 2004, Mark Pilgrim - public void test() { - assertEqualsStr(getCachedSyndFeed()., ""); - } - - //Sample Toolkit - public void test() { - assertEqualsStr(feed, ""); - } - - // editor@example.org - public void test() { - assertEqualsStr(feed, ""); - } - - // webmaster@example.org - public void test() { - assertEqualsStr(feed, ""); - } - - http://blogs.law.harvard.edu/tech/rss - - 60 - - - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9.5 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - - - Monday - Tuesday - Wednesday - Thursday - Friday - Saturday - Sunday - - -**/ - - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } + public void testType() throws Exception { + assertEquals(getCachedSyndFeed().getFeedType(), getPrefix()); + } + /* + * public void testType() throws Exception { assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); } + * + * public void testTitle() throws Exception { assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); } + * + * public void testLink() throws Exception { assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); } + * + * public void testDescription() throws Exception { assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); } + * + * public void testLanguage() throws Exception { assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); } + * + * public void testCategories() throws Exception { List catlist = getCachedSyndFeed().getCategories(); //don't understand why this one fails assertEquals(2, + * catlist.size()); SyndCategory cat = (SyndCategory)catlist.get(0); assertEqualsStr("channel.category[0]", cat.getName()); + * assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); cat = (SyndCategory)catlist.get(1); assertEqualsStr("channel.category[1]", + * cat.getName()); assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); } + * + * public void testPublishedDate() throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getCachedSyndFeed().getPublishedDate()); } + * + * //how do i get height and width? public void testImage() throws Exception { SyndImage img = getCachedSyndFeed().getImage(); + * assertEqualsStr("channel.image.description", img.getDescription()); assertEqualsStr("channel.image.link", img.getLink()); + * assertEqualsStr("channel.image.title", img.getTitle()); assertEqualsStr("channel.image.url", img.getUrl()); } + * + * public void testEntries() throws Exception { List entrylist = getCachedSyndFeed().getEntries(); assertEquals(2, entrylist.size()); } + * + * public void testEntryTitle() throws Exception { assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryTitle(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getTitle(); } + * + * public void testEntryDescription() throws Exception { assertEqualsStr("channel.item[0].description", + * getEntryDescription(getCachedSyndFeed().getEntries().get(0))); assertEqualsStr("channel.item[1].description", + * getEntryDescription(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryDescription(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getDescription().getValue(); } + * + * public void testEntryLink() throws Exception { assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryLink(Object o) { SyndEntry e = (SyndEntry) o; return e.getLink(); } + * + * public void testEntryPublishedDate() throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); } + * + * public Date getEntryPublishedDate(Object o) { SyndEntry e = (SyndEntry) o; return e.getPublishedDate(); } + * + * public void testEntryCategories() throws Exception { SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); List catlist = e.getCategories(); + * //don't understand why this one fails assertEquals(2, catlist.size()); SyndCategory cat = (SyndCategory)catlist.get(0); + * assertEqualsStr("channel.item[0].category[0]", cat.getName()); assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); cat = + * (SyndCategory)catlist.get(1); assertEqualsStr("channel.item[0].category[1]", cat.getName()); assertEqualsStr("channel.item[0].category[1]^domain", + * cat.getTaxonomyUri()); //DO 2nd set of items } + * + * public void testEntryAuthor() throws Exception { assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); } + * + * public String getEntryAuthor(Object o) { SyndEntry e = (SyndEntry) o; return e.getAuthor(); } + */ + /* + * //things you cannot get from SyndEntryImpl // item[0].source // // item0.category0 item0.category1 + * Thu, 08 Jul 1999 08:00:00 GMT Thu, 08 Jul 1999 09:00:00 GMT item0.author + * http://localhost:8080/item0/comments http://localhost:8080/item0/guid //TODO: I still have the + * elements to test + */ + /* + * public void test() { assertEqualsStr(feed, ""); } + * + * public void test() { assertEqualsStr(feed, ""); } + */ + // Things that you cannot get form a SyndFeedImpl today + // these need to be put in a RSS 2.0 module + // or is a roundtrip to wirefeed the right way to do this? + /* + * Search Search this site: q http://example.org/mt/mt-search.cgi + * + * + * image height and width + * + * //Copyright 2004, Mark Pilgrim public void test() { assertEqualsStr(getCachedSyndFeed()., ""); } + * + * //Sample Toolkit public void test() { assertEqualsStr(feed, ""); } + * + * // editor@example.org public void test() { assertEqualsStr(feed, ""); } + * + * // webmaster@example.org public void test() { assertEqualsStr(feed, ""); } + * + * http://blogs.law.harvard.edu/tech/rss + * 60 + * + * 0 1 2 3 4 5 6 7 8 + * 9.5 10 11 12 13 14 15 16 17 + * 18 19 20 21 22 23 Monday + * Tuesday Wednesday Thursday Friday Saturday Sunday + */ + /* + * @see TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } } diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10.java b/src/test/java/org/rometools/unittest/TestOpsOPML10.java index 438fc73..a796dd6 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML10.java +++ b/src/test/java/org/rometools/unittest/TestOpsOPML10.java @@ -9,39 +9,38 @@ package org.rometools.unittest; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; import java.io.FileOutputStream; import java.io.PrintWriter; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + /** - * + * * @author cooper */ -public class TestOpsOPML10 extends FeedOpsTest{ - +public class TestOpsOPML10 extends FeedOpsTest { + /** Creates a new instance of TestOpsOPML10 */ public TestOpsOPML10() { super("opml_1.0"); } - + // 1.6 + @Override public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); - w.println( sFeed1.toString() ); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1")); + w.println(sFeed1.toString()); w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); - w.println( sFeed2.toString() ); + w = new PrintWriter(new FileOutputStream("target/test-reports/2")); + w.println(sFeed2.toString()); w.close(); - + assertEquals(sFeed1, sFeed2); } - - - - + } diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10links.java b/src/test/java/org/rometools/unittest/TestOpsOPML10links.java index cd14968..1b9b143 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML10links.java +++ b/src/test/java/org/rometools/unittest/TestOpsOPML10links.java @@ -9,59 +9,54 @@ package org.rometools.unittest; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import com.sun.syndication.io.WireFeedInput; -import com.sun.syndication.io.WireFeedOutput; import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.WireFeedOutput; + /** - * + * * @author cooper */ -public class TestOpsOPML10links extends FeedOpsTest{ - +public class TestOpsOPML10links extends FeedOpsTest { + /** Creates a new instance of TestOpsOPML10 */ public TestOpsOPML10links() { super("opml_1.0_links"); } - + // 1.6 + @Override public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - //System.out.println( wFeed1 ); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/1") ); - w.println( sFeed1.toString() ); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1")); + w.println(sFeed1.toString()); w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/2") ); - w.println( sFeed2.toString() ); + w = new PrintWriter(new FileOutputStream("target/test-reports/2")); + w.println(sFeed2.toString()); w.close(); - + assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed()); } - - - - public void testTemp() throws Exception { - WireFeedInput input = new WireFeedInput(); - WireFeed wf = input.build( new File( System.getProperty("basedir")+ "/src/test/resources/opml_1.0_links.xml")); - WireFeedOutput output = new WireFeedOutput(); - //System.out.println( wf ); - - //System.out.println( "================================="); - //System.out.println( new SyndFeedImpl( wf) ); - SyndFeedImpl sf = new SyndFeedImpl( wf); + + public void testTemp() throws Exception { + final WireFeedInput input = new WireFeedInput(); + final WireFeed wf = input.build(new File(System.getProperty("basedir") + "/src/test/resources/opml_1.0_links.xml")); + final WireFeedOutput output = new WireFeedOutput(); + + final SyndFeedImpl sf = new SyndFeedImpl(wf); sf.setFeedType("rss_2.0"); sf.setDescription(""); sf.setLink("http://foo.com"); - //output.output( sf.createWireFeed() , new PrintWriter( System.out ) ); sf.setFeedType("opml_1.0"); - output.output( sf.createWireFeed() , new File( System.getProperty("basedir")+ "/target/test-reports/1.xml") ); + output.output(sf.createWireFeed(), new File(System.getProperty("basedir") + "/target/test-reports/1.xml")); } - + } diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML20.java b/src/test/java/org/rometools/unittest/TestOpsOPML20.java index 0d49027..74d58e1 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML20.java +++ b/src/test/java/org/rometools/unittest/TestOpsOPML20.java @@ -9,35 +9,36 @@ package org.rometools.unittest; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; import java.io.FileOutputStream; import java.io.PrintWriter; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + /** - * + * * @author cooper */ public class TestOpsOPML20 extends FeedOpsTest { - + /** Creates a new instance of TestOpsOPML20 */ public TestOpsOPML20() { super("opml_2.0"); } - - + + @Override public void testWireFeedSyndFeedConversion() throws Exception { - SyndFeed sFeed1 = getCachedSyndFeed(); - WireFeed wFeed1 = sFeed1.createWireFeed(); - SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); - PrintWriter w = new PrintWriter( new FileOutputStream( "target/test-reports/3") ); - w.println( sFeed1.toString() ); + final SyndFeed sFeed1 = getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); + PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/3")); + w.println(sFeed1.toString()); w.close(); - w = new PrintWriter( new FileOutputStream( "target/test-reports/4") ); - w.println( sFeed2.toString() ); + w = new PrintWriter(new FileOutputStream("target/test-reports/4")); + w.println(sFeed2.toString()); w.close(); - assertEquals(sFeed1, sFeed2 ); + assertEquals(sFeed1, sFeed2); } } diff --git a/src/test/java/org/rometools/unittest/TestXmlFixerReader.java b/src/test/java/org/rometools/unittest/TestXmlFixerReader.java index 7c5669c..f232f34 100644 --- a/src/test/java/org/rometools/unittest/TestXmlFixerReader.java +++ b/src/test/java/org/rometools/unittest/TestXmlFixerReader.java @@ -16,119 +16,124 @@ */ package org.rometools.unittest; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; + +import junit.framework.TestCase; + +import org.jdom2.input.SAXBuilder; + import com.sun.syndication.io.XmlReader; import com.sun.syndication.io.impl.XmlFixerReader; -import junit.framework.TestCase; -import org.jdom.input.SAXBuilder; - -import java.io.*; /** * @author pat, tucu - * + * */ public class TestXmlFixerReader extends TestCase { private static final String XML_PROLOG = ""; public void testTrim() throws Exception { - _testValidTrim("",""); - _testValidTrim("",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" \n",""); - _testValidTrim(" \n",XML_PROLOG+""); - _testValidTrim("",""); - _testValidTrim("",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" ",""); - _testValidTrim(" ",XML_PROLOG+""); - _testValidTrim(" \n ",""); - _testValidTrim(" \n ",XML_PROLOG+""); + _testValidTrim("", ""); + _testValidTrim("", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" \n", ""); + _testValidTrim(" \n", XML_PROLOG + ""); + _testValidTrim("", ""); + _testValidTrim("", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" ", ""); + _testValidTrim(" ", XML_PROLOG + ""); + _testValidTrim(" \n ", ""); + _testValidTrim(" \n ", XML_PROLOG + ""); - _testInvalidTrim("x",""); - _testInvalidTrim("x",XML_PROLOG+""); - _testInvalidTrim(" x",""); - _testInvalidTrim(" x",XML_PROLOG+""); - _testInvalidTrim(" x\n",""); - _testInvalidTrim(" x\n",XML_PROLOG+""); - _testInvalidTrim("x ",""); - _testInvalidTrim(" x ",XML_PROLOG+""); - _testInvalidTrim(" x ",""); - _testInvalidTrim(" x ",XML_PROLOG+""); - _testInvalidTrim(" x\n ",""); - _testInvalidTrim(" x\n ",XML_PROLOG+""); + _testInvalidTrim("x", ""); + _testInvalidTrim("x", XML_PROLOG + ""); + _testInvalidTrim(" x", ""); + _testInvalidTrim(" x", XML_PROLOG + ""); + _testInvalidTrim(" x\n", ""); + _testInvalidTrim(" x\n", XML_PROLOG + ""); + _testInvalidTrim("x ", ""); + _testInvalidTrim(" x ", XML_PROLOG + ""); + _testInvalidTrim(" x ", ""); + _testInvalidTrim(" x ", XML_PROLOG + ""); + _testInvalidTrim(" x\n ", ""); + _testInvalidTrim(" x\n ", XML_PROLOG + ""); } public void testHtmlEntities() throws Exception { _testValidEntities(""); - _testValidEntities(XML_PROLOG+""); - _testValidEntities(" \n"+XML_PROLOG+""); + _testValidEntities(XML_PROLOG + ""); + _testValidEntities(" \n" + XML_PROLOG + ""); _testValidEntities("'¥ú¥"); - _testValidEntities(XML_PROLOG+"'¥ú¥"); - _testValidEntities(" \n"+XML_PROLOG+"'¥ú¥"); + _testValidEntities(XML_PROLOG + "'¥ú¥"); + _testValidEntities(" \n" + XML_PROLOG + "'¥ú¥"); _testInvalidEntities("'&yexn;ú¥"); - _testInvalidEntities(XML_PROLOG+"'&yexn;ú¥"); - _testInvalidEntities(" \n"+XML_PROLOG+"'&yexn;ú¥"); + _testInvalidEntities(XML_PROLOG + "'&yexn;ú¥"); + _testInvalidEntities(" \n" + XML_PROLOG + "'&yexn;ú¥"); _testInvalidEntities("'¥x50;¥"); - _testInvalidEntities(XML_PROLOG+"'¥x50;¥"); - _testInvalidEntities(" \n"+XML_PROLOG+"'¥x50;¥"); + _testInvalidEntities(XML_PROLOG + "'¥x50;¥"); + _testInvalidEntities(" \n" + XML_PROLOG + "'¥x50;¥"); } - protected void _testXmlParse(String garbish,String xmlDoc) throws Exception { - InputStream is = getStream(garbish,xmlDoc); + protected void _testXmlParse(final String garbish, final String xmlDoc) throws Exception { + final InputStream is = getStream(garbish, xmlDoc); Reader reader = new XmlReader(is); reader = new XmlFixerReader(reader); - SAXBuilder saxBuilder = new SAXBuilder(); + final SAXBuilder saxBuilder = new SAXBuilder(); saxBuilder.build(reader); } - protected void _testValidTrim(String garbish,String xmlDoc) throws Exception { - _testXmlParse(garbish,xmlDoc); + protected void _testValidTrim(final String garbish, final String xmlDoc) throws Exception { + _testXmlParse(garbish, xmlDoc); } - protected void _testInvalidTrim(String garbish,String xmlDoc) throws Exception { + protected void _testInvalidTrim(final String garbish, final String xmlDoc) throws Exception { try { - _testXmlParse(garbish,xmlDoc); + _testXmlParse(garbish, xmlDoc); assertTrue(false); - } - catch (Exception ex) { + } catch (final Exception ex) { } } - protected void _testValidEntities(String xmlDoc) throws Exception { - _testXmlParse("",xmlDoc); + protected void _testValidEntities(final String xmlDoc) throws Exception { + _testXmlParse("", xmlDoc); } - protected void _testInvalidEntities(String xmlDoc) throws Exception { + protected void _testInvalidEntities(final String xmlDoc) throws Exception { try { - _testXmlParse("",xmlDoc); + _testXmlParse("", xmlDoc); assertTrue(false); - } - catch (Exception ex) { + } catch (final Exception ex) { } } // XML Stream generator - protected InputStream getStream(String garbish,String xmlDoc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - Writer writer = new OutputStreamWriter(baos); + protected InputStream getStream(final String garbish, final String xmlDoc) throws IOException { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + final Writer writer = new OutputStreamWriter(baos); writer.write(garbish); writer.write(xmlDoc); writer.close(); return new ByteArrayInputStream(baos.toByteArray()); } - } diff --git a/src/test/java/org/rometools/unittest/TestXmlReader.java b/src/test/java/org/rometools/unittest/TestXmlReader.java index 78a85fb..9b335fd 100644 --- a/src/test/java/org/rometools/unittest/TestXmlReader.java +++ b/src/test/java/org/rometools/unittest/TestXmlReader.java @@ -16,51 +16,56 @@ */ package org.rometools.unittest; -import com.sun.syndication.io.XmlReader; -import junit.framework.TestCase; - -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; +import junit.framework.TestCase; + +import com.sun.syndication.io.XmlReader; + /** * @author pat, tucu - * + * */ public class TestXmlReader extends TestCase { - public static void main(String[] args) throws Exception { - TestXmlReader test = new TestXmlReader(); + public static void main(final String[] args) throws Exception { + final TestXmlReader test = new TestXmlReader(); test.testRawBom(); test.testRawNoBom(); test.testHttp(); } - protected void _testRawNoBomValid(String encoding) throws Exception { - InputStream is = getXmlStream("no-bom","xml",encoding,encoding); - XmlReader xmlReader = new XmlReader(is,false); - assertEquals(xmlReader.getEncoding(),"UTF-8"); + protected void _testRawNoBomValid(final String encoding) throws Exception { + InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); + XmlReader xmlReader = new XmlReader(is, false); + assertEquals(xmlReader.getEncoding(), "UTF-8"); - is = getXmlStream("no-bom","xml-prolog",encoding,encoding); + is = getXmlStream("no-bom", "xml-prolog", encoding, encoding); xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),"UTF-8"); + assertEquals(xmlReader.getEncoding(), "UTF-8"); - is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),encoding); + assertEquals(xmlReader.getEncoding(), encoding); } - protected void _testRawNoBomInvalid(String encoding) throws Exception { - InputStream is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding); + protected void _testRawNoBomInvalid(final String encoding) throws Exception { + final InputStream is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); try { - XmlReader xmlReader = new XmlReader(is,false); + final XmlReader xmlReader = new XmlReader(is, false); fail("It should have failed"); + } catch (final IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } + } public void testRawNoBom() throws Exception { _testRawNoBomValid("US-ASCII"); @@ -68,27 +73,25 @@ public class TestXmlReader extends TestCase { _testRawNoBomValid("ISO-8859-1"); } - protected void _testRawBomValid(String encoding) throws Exception { - InputStream is = getXmlStream(encoding+"-bom","xml-prolog-encoding",encoding,encoding); - XmlReader xmlReader = new XmlReader(is,false); + protected void _testRawBomValid(final String encoding) throws Exception { + final InputStream is = getXmlStream(encoding + "-bom", "xml-prolog-encoding", encoding, encoding); + final XmlReader xmlReader = new XmlReader(is, false); if (!encoding.equals("UTF-16")) { - assertEquals(xmlReader.getEncoding(),encoding); - } - else { - assertEquals(xmlReader.getEncoding().substring(0,encoding.length()),encoding); + assertEquals(xmlReader.getEncoding(), encoding); + } else { + assertEquals(xmlReader.getEncoding().substring(0, encoding.length()), encoding); } } - protected void _testRawBomInvalid(String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,"xml-prolog-encoding",streamEnc,prologEnc); + protected void _testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { + final InputStream is = getXmlStream(bomEnc, "xml-prolog-encoding", streamEnc, prologEnc); try { - XmlReader xmlReader = new XmlReader(is,false); - fail("It should have failed for BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + final XmlReader xmlReader = new XmlReader(is, false); + fail("It should have failed for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); + } catch (final IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } + } public void testRawBom() throws Exception { _testRawBomValid("UTF-8"); @@ -96,155 +99,150 @@ public class TestXmlReader extends TestCase { _testRawBomValid("UTF-16LE"); _testRawBomValid("UTF-16"); - _testRawBomInvalid("UTF-8-bom","US-ASCII","US-ASCII"); - _testRawBomInvalid("UTF-8-bom","ISO-8859-1","ISO-8859-1"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16BE"); - _testRawBomInvalid("UTF-8-bom","UTF-8","UTF-16LE"); - _testRawBomInvalid("UTF-16BE-bom","UTF-16BE","UTF-16LE"); - _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-16BE"); - _testRawBomInvalid("UTF-16LE-bom","UTF-16LE","UTF-8"); + _testRawBomInvalid("UTF-8-bom", "US-ASCII", "US-ASCII"); + _testRawBomInvalid("UTF-8-bom", "ISO-8859-1", "ISO-8859-1"); + _testRawBomInvalid("UTF-8-bom", "UTF-8", "UTF-16"); + _testRawBomInvalid("UTF-8-bom", "UTF-8", "UTF-16BE"); + _testRawBomInvalid("UTF-8-bom", "UTF-8", "UTF-16LE"); + _testRawBomInvalid("UTF-16BE-bom", "UTF-16BE", "UTF-16LE"); + _testRawBomInvalid("UTF-16LE-bom", "UTF-16LE", "UTF-16BE"); + _testRawBomInvalid("UTF-16LE-bom", "UTF-16LE", "UTF-8"); } public void testHttp() throws Exception { - _testHttpValid("application/xml","no-bom","US-ASCII",null); - _testHttpValid("application/xml","UTF-8-bom","US-ASCII",null); - _testHttpValid("application/xml","UTF-8-bom","UTF-8",null); - _testHttpValid("application/xml","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); - _testHttpValid("application/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpValid("application/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); + _testHttpValid("application/xml", "no-bom", "US-ASCII", null); + _testHttpValid("application/xml", "UTF-8-bom", "US-ASCII", null); + _testHttpValid("application/xml", "UTF-8-bom", "UTF-8", null); + _testHttpValid("application/xml", "UTF-8-bom", "UTF-8", "UTF-8"); + _testHttpValid("application/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", null); + _testHttpValid("application/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", "UTF-8"); + _testHttpValid("application/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpValid("application/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpValid("application/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpInvalid("application/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("application/xml","UTF-8-bom","US-ASCII","US-ASCII"); - _testHttpInvalid("application/xml;charset=UTF-16","UTF-16LE","UTF-8","UTF-8"); - _testHttpInvalid("application/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); + _testHttpInvalid("application/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpInvalid("application/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpInvalid("application/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); + _testHttpInvalid("application/xml", "UTF-8-bom", "US-ASCII", "US-ASCII"); + _testHttpInvalid("application/xml;charset=UTF-16", "UTF-16LE", "UTF-8", "UTF-8"); + _testHttpInvalid("application/xml;charset=UTF-16", "no-bom", "UTF-16BE", "UTF-16BE"); - _testHttpValid("text/xml","no-bom","US-ASCII",null); - _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8"); - _testHttpValid("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpValid("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpValid("text/xml","UTF-8-bom","US-ASCII",null); + _testHttpValid("text/xml", "no-bom", "US-ASCII", null); + _testHttpValid("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", "UTF-8"); + _testHttpValid("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", null); + _testHttpValid("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpValid("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpValid("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); + _testHttpValid("text/xml", "UTF-8-bom", "US-ASCII", null); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16"); - _testHttpInvalid("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE"); - _testHttpInvalid("text/xml;charset=UTF-16","no-bom","UTF-16BE",null); + _testHttpInvalid("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", null); + _testHttpInvalid("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16"); + _testHttpInvalid("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", "UTF-16BE"); + _testHttpInvalid("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", null); - _testHttpLenient("text/xml","no-bom","US-ASCII",null, "US-ASCII"); - _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8","UTF-8", "UTF-8"); - _testHttpLenient("text/xml;charset=UTF-8","UTF-8-bom","UTF-8",null, "UTF-8"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); - _testHttpLenient("text/xml;charset=UTF-16","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml","UTF-8-bom","US-ASCII",null, "US-ASCII"); + _testHttpLenient("text/xml", "no-bom", "US-ASCII", null, "US-ASCII"); + _testHttpLenient("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", "UTF-8", "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-8", "UTF-8-bom", "UTF-8", null, "UTF-8"); + _testHttpLenient("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml", "UTF-8-bom", "US-ASCII", null, "US-ASCII"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE",null, "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16", "UTF-16"); - _testHttpLenient("text/xml;charset=UTF-16BE","UTF-16BE-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE","UTF-16BE", "UTF-16BE"); - _testHttpLenient("text/xml;charset=UTF-16","no-bom","UTF-16BE",null, "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", null, "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16", "UTF-16"); + _testHttpLenient("text/xml;charset=UTF-16BE", "UTF-16BE-bom", "UTF-16BE", "UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", "UTF-16BE", "UTF-16BE"); + _testHttpLenient("text/xml;charset=UTF-16", "no-bom", "UTF-16BE", null, "UTF-16"); - _testHttpLenient("text/html","no-bom","US-ASCII","US-ASCII", "US-ASCII"); - _testHttpLenient("text/html","no-bom","US-ASCII",null, "US-ASCII"); - _testHttpLenient("text/html;charset=UTF-8","no-bom","US-ASCII","UTF-8", "UTF-8"); - _testHttpLenient("text/html;charset=UTF-16BE","no-bom","US-ASCII","UTF-8", "UTF-8"); + _testHttpLenient("text/html", "no-bom", "US-ASCII", "US-ASCII", "US-ASCII"); + _testHttpLenient("text/html", "no-bom", "US-ASCII", null, "US-ASCII"); + _testHttpLenient("text/html;charset=UTF-8", "no-bom", "US-ASCII", "UTF-8", "UTF-8"); + _testHttpLenient("text/html;charset=UTF-16BE", "no-bom", "US-ASCII", "UTF-8", "UTF-8"); } - public void _testHttpValid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml":"xml-prolog-encoding",streamEnc,prologEnc); - XmlReader xmlReader = new XmlReader(is,cT,false); + public void _testHttpValid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { + final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml" : "xml-prolog-encoding", streamEnc, prologEnc); + final XmlReader xmlReader = new XmlReader(is, cT, false); if (!streamEnc.equals("UTF-16")) { // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection - } - else { - assertEquals(xmlReader.getEncoding().substring(0,streamEnc.length()),streamEnc); + } else { + assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); } } - protected void _testHttpInvalid(String cT,String bomEnc,String streamEnc,String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); + protected void _testHttpInvalid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { + final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml-prolog" : "xml-prolog-encoding", streamEnc, prologEnc); try { - XmlReader xmlReader = new XmlReader(is,cT,false); - fail("It should have failed for HTTP Content-type "+cT+", BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + final XmlReader xmlReader = new XmlReader(is, cT, false); + fail("It should have failed for HTTP Content-type " + cT + ", BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); + } catch (final IOException ex) { + assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } - catch (IOException ex) { - assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1); - } - } + } - protected void _testHttpLenient(String cT, String bomEnc, String streamEnc, String prologEnc, String shouldbe) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?"xml-prolog":"xml-prolog-encoding",streamEnc,prologEnc); - XmlReader xmlReader = new XmlReader(is,cT,true); - assertEquals(xmlReader.getEncoding(),shouldbe); + protected void _testHttpLenient(final String cT, final String bomEnc, final String streamEnc, final String prologEnc, final String shouldbe) + throws Exception { + final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml-prolog" : "xml-prolog-encoding", streamEnc, prologEnc); + final XmlReader xmlReader = new XmlReader(is, cT, true); + assertEquals(xmlReader.getEncoding(), shouldbe); } // XML Stream generator private static final int[] NO_BOM_BYTES = {}; - private static final int[] UTF_16BE_BOM_BYTES = {0xFE,0xFF}; - private static final int[] UTF_16LE_BOM_BYTES = {0xFF,0XFE}; - private static final int[] UTF_8_BOM_BYTES = {0xEF,0xBB,0xBF}; + private static final int[] UTF_16BE_BOM_BYTES = { 0xFE, 0xFF }; + private static final int[] UTF_16LE_BOM_BYTES = { 0xFF, 0XFE }; + private static final int[] UTF_8_BOM_BYTES = { 0xEF, 0xBB, 0xBF }; private static final Map BOMs = new HashMap(); static { - BOMs.put("no-bom",NO_BOM_BYTES); - BOMs.put("UTF-16BE-bom",UTF_16BE_BOM_BYTES); - BOMs.put("UTF-16LE-bom",UTF_16LE_BOM_BYTES); - BOMs.put("UTF-16-bom",NO_BOM_BYTES); // it's added by the writer - BOMs.put("UTF-8-bom",UTF_8_BOM_BYTES); + BOMs.put("no-bom", NO_BOM_BYTES); + BOMs.put("UTF-16BE-bom", UTF_16BE_BOM_BYTES); + BOMs.put("UTF-16LE-bom", UTF_16LE_BOM_BYTES); + BOMs.put("UTF-16-bom", NO_BOM_BYTES); // it's added by the writer + BOMs.put("UTF-8-bom", UTF_8_BOM_BYTES); } - private static final MessageFormat XML = new MessageFormat( - "{2}"); - private static final MessageFormat XML_WITH_PROLOG = new MessageFormat( - "\n{2}"); - private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat( - "\n{2}"); + private static final MessageFormat XML = new MessageFormat("{2}"); + private static final MessageFormat XML_WITH_PROLOG = new MessageFormat("\n{2}"); + private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING = new MessageFormat("\n{2}"); - private static final MessageFormat INFO = new MessageFormat( - "\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); + private static final MessageFormat INFO = new MessageFormat("\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); private static final Map XMLs = new HashMap(); static { - XMLs.put("xml",XML); - XMLs.put("xml-prolog",XML_WITH_PROLOG); - XMLs.put("xml-prolog-encoding",XML_WITH_PROLOG_AND_ENCODING); + XMLs.put("xml", XML); + XMLs.put("xml-prolog", XML_WITH_PROLOG); + XMLs.put("xml-prolog-encoding", XML_WITH_PROLOG_AND_ENCODING); } /** - * + * * @param bomType no-bom, UTF-16BE-bom, UTF-16LE-bom, UTF-8-bom * @param xmlType xml, xml-prolog, xml-prolog-charset * @return XML stream */ - protected InputStream getXmlStream(String bomType,String xmlType,String streamEnc,String prologEnc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); + protected InputStream getXmlStream(final String bomType, final String xmlType, final String streamEnc, final String prologEnc) throws IOException { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); int[] bom = (int[]) BOMs.get(bomType); - if (bom==null) { + if (bom == null) { bom = new int[0]; } - MessageFormat xml = (MessageFormat) XMLs.get(xmlType); - for (int i=0;i\n"); - for (int i=0;i<10000;i++) { + for (int i = 0; i < 10000; i++) { writer.write("\n"); } writer.write("\n"); @@ -253,5 +251,4 @@ public class TestXmlReader extends TestCase { return new ByteArrayInputStream(baos.toByteArray()); } - } From c702966daaaca0ebdf2847d3370b81e47c3f1293 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 7 Oct 2013 22:11:49 +0200 Subject: [PATCH 10/47] Fixed tests --- pom.xml | 12 +++++------ .../sun/syndication}/feed/opml/Attribute.java | 2 +- .../sun/syndication}/feed/opml/Opml.java | 2 +- .../sun/syndication}/feed/opml/Outline.java | 2 +- .../sun/syndication}/feed/opml/package.html | 0 .../feed/synd/impl/ConverterForOPML10.java | 8 ++++---- .../feed/synd/impl/ConverterForOPML20.java | 2 +- .../feed/synd/impl/TreeCategoryImpl.java | 2 +- .../syndication}/feed/synd/impl/package.html | 0 .../syndication}/io/impl/OPML10Generator.java | 8 ++++---- .../syndication}/io/impl/OPML10Parser.java | 8 ++++---- .../syndication}/io/impl/OPML20Generator.java | 6 +++--- .../syndication}/io/impl/OPML20Parser.java | 8 ++++---- .../sun/syndication}/io/impl/package.html | 0 .../sun/syndication}/FeedOpsTest.java | 2 +- .../sun/syndication}/FeedTest.java | 2 +- .../sun/syndication}/SyndFeedTest.java | 2 +- .../sun/syndication}/TestOpsOPML10.java | 2 +- .../sun/syndication}/TestOpsOPML10links.java | 10 ++++++---- .../sun/syndication}/TestOpsOPML20.java | 2 +- .../sun/syndication}/TestXmlFixerReader.java | 2 +- .../sun/syndication}/TestXmlReader.java | 2 +- src/test/java/test/NullWriter.java | 20 +++++++++++++++++++ src/test/java/test/TestUtil.java | 15 ++++++++++++++ 24 files changed, 78 insertions(+), 41 deletions(-) rename src/main/java/{org/rometools => com/sun/syndication}/feed/opml/Attribute.java (98%) rename src/main/java/{org/rometools => com/sun/syndication}/feed/opml/Opml.java (99%) rename src/main/java/{org/rometools => com/sun/syndication}/feed/opml/Outline.java (99%) rename src/main/java/{org/rometools => com/sun/syndication}/feed/opml/package.html (100%) rename src/main/java/{org/rometools => com/sun/syndication}/feed/synd/impl/ConverterForOPML10.java (98%) rename src/main/java/{org/rometools => com/sun/syndication}/feed/synd/impl/ConverterForOPML20.java (97%) rename src/main/java/{org/rometools => com/sun/syndication}/feed/synd/impl/TreeCategoryImpl.java (94%) rename src/main/java/{org/rometools => com/sun/syndication}/feed/synd/impl/package.html (100%) rename src/main/java/{org/rometools => com/sun/syndication}/io/impl/OPML10Generator.java (97%) rename src/main/java/{org/rometools => com/sun/syndication}/io/impl/OPML10Parser.java (98%) rename src/main/java/{org/rometools => com/sun/syndication}/io/impl/OPML20Generator.java (94%) rename src/main/java/{org/rometools => com/sun/syndication}/io/impl/OPML20Parser.java (95%) rename src/main/java/{org/rometools => com/sun/syndication}/io/impl/package.html (100%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/FeedOpsTest.java (99%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/FeedTest.java (98%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/SyndFeedTest.java (99%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/TestOpsOPML10.java (97%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/TestOpsOPML10links.java (84%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/TestOpsOPML20.java (97%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/TestXmlFixerReader.java (99%) rename src/test/java/{org/rometools/unittest => com/sun/syndication}/TestXmlReader.java (99%) create mode 100644 src/test/java/test/NullWriter.java create mode 100644 src/test/java/test/TestUtil.java diff --git a/pom.xml b/pom.xml index 6aca63a..d7bce29 100644 --- a/pom.xml +++ b/pom.xml @@ -163,18 +163,18 @@ - - junit - junit - 4.11 - test - org.rometools rome 2.0.0-SNAPSHOT compile + + junit + junit + 4.11 + test + diff --git a/src/main/java/org/rometools/feed/opml/Attribute.java b/src/main/java/com/sun/syndication/feed/opml/Attribute.java similarity index 98% rename from src/main/java/org/rometools/feed/opml/Attribute.java rename to src/main/java/com/sun/syndication/feed/opml/Attribute.java index 934b106..a90662c 100644 --- a/src/main/java/org/rometools/feed/opml/Attribute.java +++ b/src/main/java/com/sun/syndication/feed/opml/Attribute.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.rometools.feed.opml; +package com.sun.syndication.feed.opml; import com.sun.syndication.feed.impl.EqualsBean; import com.sun.syndication.feed.impl.ToStringBean; diff --git a/src/main/java/org/rometools/feed/opml/Opml.java b/src/main/java/com/sun/syndication/feed/opml/Opml.java similarity index 99% rename from src/main/java/org/rometools/feed/opml/Opml.java rename to src/main/java/com/sun/syndication/feed/opml/Opml.java index 2773b0e..5e0e965 100644 --- a/src/main/java/org/rometools/feed/opml/Opml.java +++ b/src/main/java/com/sun/syndication/feed/opml/Opml.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.rometools.feed.opml; +package com.sun.syndication.feed.opml; import com.sun.syndication.feed.WireFeed; diff --git a/src/main/java/org/rometools/feed/opml/Outline.java b/src/main/java/com/sun/syndication/feed/opml/Outline.java similarity index 99% rename from src/main/java/org/rometools/feed/opml/Outline.java rename to src/main/java/com/sun/syndication/feed/opml/Outline.java index 691f764..950cd77 100644 --- a/src/main/java/org/rometools/feed/opml/Outline.java +++ b/src/main/java/com/sun/syndication/feed/opml/Outline.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.rometools.feed.opml; +package com.sun.syndication.feed.opml; import com.sun.syndication.feed.impl.EqualsBean; import com.sun.syndication.feed.impl.ToStringBean; diff --git a/src/main/java/org/rometools/feed/opml/package.html b/src/main/java/com/sun/syndication/feed/opml/package.html similarity index 100% rename from src/main/java/org/rometools/feed/opml/package.html rename to src/main/java/com/sun/syndication/feed/opml/package.html diff --git a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java similarity index 98% rename from src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java rename to src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java index 110418f..74ba153 100644 --- a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.rometools.feed.synd.impl; +package com.sun.syndication.feed.synd.impl; import java.util.ArrayList; import java.util.Collections; @@ -25,9 +25,9 @@ import java.util.Stack; import java.util.logging.Logger; import com.sun.syndication.feed.WireFeed; -import org.rometools.feed.opml.Attribute; -import org.rometools.feed.opml.Opml; -import org.rometools.feed.opml.Outline; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.feed.synd.Converter; import com.sun.syndication.feed.synd.SyndCategory; import com.sun.syndication.feed.synd.SyndCategoryImpl; diff --git a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java similarity index 97% rename from src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java rename to src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java index d053bc7..53e5d9b 100644 --- a/src/main/java/org/rometools/feed/synd/impl/ConverterForOPML20.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java @@ -6,7 +6,7 @@ * To change this template, choose Tools | Template Manager * and open the template in the editor. */ -package org.rometools.feed.synd.impl; +package com.sun.syndication.feed.synd.impl; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; diff --git a/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java similarity index 94% rename from src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java rename to src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java index 8faea35..02ced72 100644 --- a/src/main/java/org/rometools/feed/synd/impl/TreeCategoryImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java @@ -7,7 +7,7 @@ * and open the template in the editor. */ -package org.rometools.feed.synd.impl; +package com.sun.syndication.feed.synd.impl; import com.sun.syndication.feed.synd.SyndCategory; import com.sun.syndication.feed.synd.SyndCategoryImpl; diff --git a/src/main/java/org/rometools/feed/synd/impl/package.html b/src/main/java/com/sun/syndication/feed/synd/impl/package.html similarity index 100% rename from src/main/java/org/rometools/feed/synd/impl/package.html rename to src/main/java/com/sun/syndication/feed/synd/impl/package.html diff --git a/src/main/java/org/rometools/io/impl/OPML10Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java similarity index 97% rename from src/main/java/org/rometools/io/impl/OPML10Generator.java rename to src/main/java/com/sun/syndication/io/impl/OPML10Generator.java index 2246c1f..ca3b0d3 100644 --- a/src/main/java/org/rometools/io/impl/OPML10Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.rometools.io.impl; +package com.sun.syndication.io.impl; import com.sun.syndication.feed.WireFeed; -import org.rometools.feed.opml.Attribute; -import org.rometools.feed.opml.Opml; -import org.rometools.feed.opml.Outline; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedGenerator; import com.sun.syndication.io.impl.BaseWireFeedGenerator; diff --git a/src/main/java/org/rometools/io/impl/OPML10Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java similarity index 98% rename from src/main/java/org/rometools/io/impl/OPML10Parser.java rename to src/main/java/com/sun/syndication/io/impl/OPML10Parser.java index 16be175..d40082a 100644 --- a/src/main/java/org/rometools/io/impl/OPML10Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.rometools.io.impl; +package com.sun.syndication.io.impl; import com.sun.syndication.feed.WireFeed; -import org.rometools.feed.opml.Attribute; -import org.rometools.feed.opml.Opml; -import org.rometools.feed.opml.Outline; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedParser; import com.sun.syndication.io.impl.BaseWireFeedParser; diff --git a/src/main/java/org/rometools/io/impl/OPML20Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java similarity index 94% rename from src/main/java/org/rometools/io/impl/OPML20Generator.java rename to src/main/java/com/sun/syndication/io/impl/OPML20Generator.java index d1122b7..3034d01 100644 --- a/src/main/java/org/rometools/io/impl/OPML20Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java @@ -6,11 +6,11 @@ * To change this template, choose Tools | Template Manager * and open the template in the editor. */ -package org.rometools.io.impl; +package com.sun.syndication.io.impl; import com.sun.syndication.feed.WireFeed; -import org.rometools.feed.opml.Opml; -import org.rometools.feed.opml.Outline; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.impl.DateParser; diff --git a/src/main/java/org/rometools/io/impl/OPML20Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java similarity index 95% rename from src/main/java/org/rometools/io/impl/OPML20Parser.java rename to src/main/java/com/sun/syndication/io/impl/OPML20Parser.java index 28ed5b2..e53cc6a 100644 --- a/src/main/java/org/rometools/io/impl/OPML20Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.rometools.io.impl; +package com.sun.syndication.io.impl; import com.sun.syndication.feed.WireFeed; -import org.rometools.feed.opml.Attribute; -import org.rometools.feed.opml.Opml; -import org.rometools.feed.opml.Outline; +import com.sun.syndication.feed.opml.Attribute; +import com.sun.syndication.feed.opml.Opml; +import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.impl.DateParser; diff --git a/src/main/java/org/rometools/io/impl/package.html b/src/main/java/com/sun/syndication/io/impl/package.html similarity index 100% rename from src/main/java/org/rometools/io/impl/package.html rename to src/main/java/com/sun/syndication/io/impl/package.html diff --git a/src/test/java/org/rometools/unittest/FeedOpsTest.java b/src/test/java/com/sun/syndication/FeedOpsTest.java similarity index 99% rename from src/test/java/org/rometools/unittest/FeedOpsTest.java rename to src/test/java/com/sun/syndication/FeedOpsTest.java index 24c322e..2e1ddb0 100644 --- a/src/test/java/org/rometools/unittest/FeedOpsTest.java +++ b/src/test/java/com/sun/syndication/FeedOpsTest.java @@ -1,4 +1,4 @@ -package org.rometools.unittest; +package com.sun.syndication; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/src/test/java/org/rometools/unittest/FeedTest.java b/src/test/java/com/sun/syndication/FeedTest.java similarity index 98% rename from src/test/java/org/rometools/unittest/FeedTest.java rename to src/test/java/com/sun/syndication/FeedTest.java index 70552f1..2f6032b 100644 --- a/src/test/java/org/rometools/unittest/FeedTest.java +++ b/src/test/java/com/sun/syndication/FeedTest.java @@ -1,4 +1,4 @@ -package org.rometools.unittest; +package com.sun.syndication; import java.io.InputStream; import java.io.InputStreamReader; diff --git a/src/test/java/org/rometools/unittest/SyndFeedTest.java b/src/test/java/com/sun/syndication/SyndFeedTest.java similarity index 99% rename from src/test/java/org/rometools/unittest/SyndFeedTest.java rename to src/test/java/com/sun/syndication/SyndFeedTest.java index 6686fcf..4fc0033 100644 --- a/src/test/java/org/rometools/unittest/SyndFeedTest.java +++ b/src/test/java/com/sun/syndication/SyndFeedTest.java @@ -4,7 +4,7 @@ * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ -package org.rometools.unittest; +package com.sun.syndication; /** * @author pat diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10.java b/src/test/java/com/sun/syndication/TestOpsOPML10.java similarity index 97% rename from src/test/java/org/rometools/unittest/TestOpsOPML10.java rename to src/test/java/com/sun/syndication/TestOpsOPML10.java index a796dd6..7c4691d 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML10.java +++ b/src/test/java/com/sun/syndication/TestOpsOPML10.java @@ -7,7 +7,7 @@ * and open the template in the editor. */ -package org.rometools.unittest; +package com.sun.syndication; import java.io.FileOutputStream; import java.io.PrintWriter; diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML10links.java b/src/test/java/com/sun/syndication/TestOpsOPML10links.java similarity index 84% rename from src/test/java/org/rometools/unittest/TestOpsOPML10links.java rename to src/test/java/com/sun/syndication/TestOpsOPML10links.java index 1b9b143..202a342 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML10links.java +++ b/src/test/java/com/sun/syndication/TestOpsOPML10links.java @@ -7,12 +7,14 @@ * and open the template in the editor. */ -package org.rometools.unittest; +package com.sun.syndication; -import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; +import test.NullWriter; +import test.TestUtil; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; @@ -48,7 +50,7 @@ public class TestOpsOPML10links extends FeedOpsTest { public void testTemp() throws Exception { final WireFeedInput input = new WireFeedInput(); - final WireFeed wf = input.build(new File(System.getProperty("basedir") + "/src/test/resources/opml_1.0_links.xml")); + final WireFeed wf = input.build(TestUtil.loadFile("/opml_1.0_links.xml")); final WireFeedOutput output = new WireFeedOutput(); final SyndFeedImpl sf = new SyndFeedImpl(wf); @@ -56,7 +58,7 @@ public class TestOpsOPML10links extends FeedOpsTest { sf.setDescription(""); sf.setLink("http://foo.com"); sf.setFeedType("opml_1.0"); - output.output(sf.createWireFeed(), new File(System.getProperty("basedir") + "/target/test-reports/1.xml")); + output.output(sf.createWireFeed(), new NullWriter()); } } diff --git a/src/test/java/org/rometools/unittest/TestOpsOPML20.java b/src/test/java/com/sun/syndication/TestOpsOPML20.java similarity index 97% rename from src/test/java/org/rometools/unittest/TestOpsOPML20.java rename to src/test/java/com/sun/syndication/TestOpsOPML20.java index 74d58e1..cd219cb 100644 --- a/src/test/java/org/rometools/unittest/TestOpsOPML20.java +++ b/src/test/java/com/sun/syndication/TestOpsOPML20.java @@ -7,7 +7,7 @@ * and open the template in the editor. */ -package org.rometools.unittest; +package com.sun.syndication; import java.io.FileOutputStream; import java.io.PrintWriter; diff --git a/src/test/java/org/rometools/unittest/TestXmlFixerReader.java b/src/test/java/com/sun/syndication/TestXmlFixerReader.java similarity index 99% rename from src/test/java/org/rometools/unittest/TestXmlFixerReader.java rename to src/test/java/com/sun/syndication/TestXmlFixerReader.java index f232f34..c44a910 100644 --- a/src/test/java/org/rometools/unittest/TestXmlFixerReader.java +++ b/src/test/java/com/sun/syndication/TestXmlFixerReader.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.rometools.unittest; +package com.sun.syndication; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/src/test/java/org/rometools/unittest/TestXmlReader.java b/src/test/java/com/sun/syndication/TestXmlReader.java similarity index 99% rename from src/test/java/org/rometools/unittest/TestXmlReader.java rename to src/test/java/com/sun/syndication/TestXmlReader.java index 9b335fd..3b2d3af 100644 --- a/src/test/java/org/rometools/unittest/TestXmlReader.java +++ b/src/test/java/com/sun/syndication/TestXmlReader.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.rometools.unittest; +package com.sun.syndication; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/src/test/java/test/NullWriter.java b/src/test/java/test/NullWriter.java new file mode 100644 index 0000000..4039735 --- /dev/null +++ b/src/test/java/test/NullWriter.java @@ -0,0 +1,20 @@ +package test; + +import java.io.IOException; +import java.io.Writer; + +public class NullWriter extends Writer { + + @Override + public void write(final char[] cbuf, final int off, final int len) throws IOException { + } + + @Override + public void flush() throws IOException { + } + + @Override + public void close() throws IOException { + } + +} diff --git a/src/test/java/test/TestUtil.java b/src/test/java/test/TestUtil.java new file mode 100644 index 0000000..d2b3842 --- /dev/null +++ b/src/test/java/test/TestUtil.java @@ -0,0 +1,15 @@ +package test; + +import java.io.InputStreamReader; +import java.io.Reader; + +public final class TestUtil { + + private TestUtil() { + } + + public static Reader loadFile(final String path) { + return new InputStreamReader(TestUtil.class.getResourceAsStream(path)); + } + +} From ba81950da44d5728022d647c420a69e4fce1a516 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 11 Oct 2013 17:56:06 +0200 Subject: [PATCH 11/47] Changed groupId --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d7bce29..247cb94 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 - org.rometools + com.rometools rome-opml 2.0.0-SNAPSHOT From d3509f97ca7d25ddbbf67ab4ec90f4a1557df360 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 11 Oct 2013 23:51:07 +0200 Subject: [PATCH 12/47] Enhanced POM Updated dependencies --- pom.xml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 247cb94..91a8983 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,7 @@ UTF-8 + UTF-8 @@ -56,20 +57,19 @@ sonatype.snapshots - https://oss.sonatype.org/content/repositories/snapshots/ + https://oss.sonatype.org/content/repositories/snapshots + + + sonatype.snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + - - - - - - - - org.apache.maven.plugins maven-compiler-plugin @@ -79,11 +79,6 @@ 1.6 - - org.apache.maven.plugins - maven-resources-plugin - 2.6 - org.apache.maven.plugins maven-site-plugin @@ -93,6 +88,14 @@ ${basedir}/target/site/tempdir + + org.apache.maven.plugins + maven-scm-plugin + 1.8.1 + + install + + org.apache.maven.plugins maven-scm-publish-plugin @@ -109,7 +112,6 @@ 2.2.1 - attach-sources jar @@ -122,7 +124,6 @@ 2.9.1 - attach-javadocs jar @@ -164,10 +165,9 @@ - org.rometools + com.rometools rome 2.0.0-SNAPSHOT - compile junit From c71113f1976b88e5b246d0b81a3bb33f130692ba Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Oct 2013 00:12:08 +0200 Subject: [PATCH 13/47] Formatted code Added Eclipse formatter and cleanup configuration --- .../sun/syndication/feed/opml/Attribute.java | 34 +++-- .../com/sun/syndication/feed/opml/Opml.java | 60 ++++----- .../sun/syndication/feed/opml/Outline.java | 116 ++++++++--------- .../feed/synd/impl/ConverterForOPML10.java | 122 +++++++++--------- .../feed/synd/impl/ConverterForOPML20.java | 4 +- .../feed/synd/impl/TreeCategoryImpl.java | 9 +- .../syndication/io/impl/OPML10Generator.java | 64 +++++---- .../sun/syndication/io/impl/OPML10Parser.java | 80 ++++++------ .../syndication/io/impl/OPML20Generator.java | 15 +-- .../sun/syndication/io/impl/OPML20Parser.java | 30 ++--- .../com/sun/syndication/SyndFeedTest.java | 6 +- 11 files changed, 264 insertions(+), 276 deletions(-) diff --git a/src/main/java/com/sun/syndication/feed/opml/Attribute.java b/src/main/java/com/sun/syndication/feed/opml/Attribute.java index a90662c..c3925c2 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Attribute.java +++ b/src/main/java/com/sun/syndication/feed/opml/Attribute.java @@ -17,11 +17,11 @@ */ package com.sun.syndication.feed.opml; +import java.io.Serializable; + import com.sun.syndication.feed.impl.EqualsBean; import com.sun.syndication.feed.impl.ToStringBean; -import java.io.Serializable; - /** * This is a simple name-value pair attribute for outlines. * @@ -42,13 +42,12 @@ public class Attribute implements Cloneable, Serializable { * @param name name of the attribute. * @param value value of the attribute. */ - public Attribute(String name, String value) { - if ((name == null) || (value == null)) { + public Attribute(final String name, final String value) { + if (name == null || value == null) { throw new NullPointerException("Name and value are required."); } - - this.setName(name); - this.setValue(value); + setName(name); + setValue(value); } /** @@ -56,8 +55,8 @@ public class Attribute implements Cloneable, Serializable { * * @param name name of the attribute. */ - public void setName(String name) { - this._name = name; + public void setName(final String name) { + _name = name; } /** @@ -74,8 +73,8 @@ public class Attribute implements Cloneable, Serializable { * * @param value value of the attribute. */ - public void setValue(String value) { - this._value = value; + public void setValue(final String value) { + _value = value; } /** @@ -89,27 +88,24 @@ public class Attribute implements Cloneable, Serializable { @Override public Object clone() { - return new Attribute(this._name, this._value); + return new Attribute(_name, _value); } @Override - public boolean equals(Object obj) { - EqualsBean eBean = new EqualsBean(Attribute.class, this); - + public boolean equals(final Object obj) { + final EqualsBean eBean = new EqualsBean(Attribute.class, this); return eBean.beanEquals(obj); } @Override public int hashCode() { - EqualsBean equals = new EqualsBean(Attribute.class, this); - + final EqualsBean equals = new EqualsBean(Attribute.class, this); return equals.beanHashCode(); } @Override public String toString() { - ToStringBean tsBean = new ToStringBean(Attribute.class, this); - + final ToStringBean tsBean = new ToStringBean(Attribute.class, this); return tsBean.toString(); } } diff --git a/src/main/java/com/sun/syndication/feed/opml/Opml.java b/src/main/java/com/sun/syndication/feed/opml/Opml.java index 5e0e965..cb8ed8a 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Opml.java +++ b/src/main/java/com/sun/syndication/feed/opml/Opml.java @@ -17,12 +17,12 @@ */ package com.sun.syndication.feed.opml; -import com.sun.syndication.feed.WireFeed; - import java.util.ArrayList; import java.util.Date; import java.util.List; +import com.sun.syndication.feed.WireFeed; + /** * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in the <head> tag of the feed. * @@ -54,8 +54,8 @@ public class Opml extends WireFeed { * * @param created date-time, indicating when the document was created. */ - public void setCreated(Date created) { - this._created = created; + public void setCreated(final Date created) { + _created = created; } /** @@ -73,8 +73,8 @@ public class Opml extends WireFeed { * * @param docs http address of documentation for the format used */ - public void setDocs(String docs) { - this._docs = docs; + public void setDocs(final String docs) { + _docs = docs; } /** @@ -94,8 +94,8 @@ public class Opml extends WireFeed { * * @param expansionState int array containing expanded elements. */ - public void setExpansionState(int[] expansionState) { - this._expansionState = expansionState; + public void setExpansionState(final int[] expansionState) { + _expansionState = expansionState; } /** @@ -114,8 +114,8 @@ public class Opml extends WireFeed { * * @param modified date-time, indicating when the document was last modified. */ - public void setModified(Date modified) { - this._modified = modified; + public void setModified(final Date modified) { + _modified = modified; } /** @@ -132,8 +132,8 @@ public class Opml extends WireFeed { * * @param outlines Root level Outline object that should appear in the <body> */ - public void setOutlines(List outlines) { - this._outlines = outlines; + public void setOutlines(final List outlines) { + _outlines = outlines; } /** @@ -154,8 +154,8 @@ public class Opml extends WireFeed { * * @param ownerEmail the email address of the owner of the document. */ - public void setOwnerEmail(String ownerEmail) { - this._ownerEmail = ownerEmail; + public void setOwnerEmail(final String ownerEmail) { + _ownerEmail = ownerEmail; } /** @@ -174,8 +174,8 @@ public class Opml extends WireFeed { * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the * document via email or other means. */ - public void setOwnerId(String ownerId) { - this._ownerId = ownerId; + public void setOwnerId(final String ownerId) { + _ownerId = ownerId; } /** @@ -194,8 +194,8 @@ public class Opml extends WireFeed { * * @param ownerName the owner of the document. */ - public void setOwnerName(String ownerName) { - this._ownerName = ownerName; + public void setOwnerName(final String ownerName) { + _ownerName = ownerName; } /** @@ -212,8 +212,8 @@ public class Opml extends WireFeed { * * @param title title of the document. */ - public void setTitle(String title) { - this._title = title; + public void setTitle(final String title) { + _title = title; } /** @@ -231,8 +231,8 @@ public class Opml extends WireFeed { * * @param verticalScrollState which line of the outline is displayed on the top line of the window. */ - public void setVerticalScrollState(Integer verticalScrollState) { - this._verticalScrollState = verticalScrollState; + public void setVerticalScrollState(final Integer verticalScrollState) { + _verticalScrollState = verticalScrollState; } /** @@ -250,8 +250,8 @@ public class Opml extends WireFeed { * * @param windowBottom the pixel location of the bottom edge of the window. */ - public void setWindowBottom(Integer windowBottom) { - this._windowBottom = windowBottom; + public void setWindowBottom(final Integer windowBottom) { + _windowBottom = windowBottom; } /** @@ -268,8 +268,8 @@ public class Opml extends WireFeed { * * @param windowLeft the pixel location of the left edge of the window. */ - public void setWindowLeft(Integer windowLeft) { - this._windowLeft = windowLeft; + public void setWindowLeft(final Integer windowLeft) { + _windowLeft = windowLeft; } /** @@ -286,8 +286,8 @@ public class Opml extends WireFeed { * * @param windowRight the pixel location of the right edge of the window. */ - public void setWindowRight(Integer windowRight) { - this._windowRight = windowRight; + public void setWindowRight(final Integer windowRight) { + _windowRight = windowRight; } /** @@ -304,8 +304,8 @@ public class Opml extends WireFeed { * * @param windowTop the pixel location of the top edge of the window. */ - public void setWindowTop(Integer windowTop) { - this._windowTop = windowTop; + public void setWindowTop(final Integer windowTop) { + _windowTop = windowTop; } /** diff --git a/src/main/java/com/sun/syndication/feed/opml/Outline.java b/src/main/java/com/sun/syndication/feed/opml/Outline.java index 950cd77..3fbb0b7 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Outline.java +++ b/src/main/java/com/sun/syndication/feed/opml/Outline.java @@ -17,18 +17,16 @@ */ package com.sun.syndication.feed.opml; -import com.sun.syndication.feed.impl.EqualsBean; -import com.sun.syndication.feed.impl.ToStringBean; - import java.io.Serializable; - import java.net.URL; - import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; +import com.sun.syndication.feed.impl.EqualsBean; +import com.sun.syndication.feed.impl.ToStringBean; + /** * This class represents an OPML outline element. * @@ -57,10 +55,10 @@ public class Outline implements Cloneable, Serializable { * @param type type attribute value/ * @param text text attribute value */ - public Outline(String type, String text) { + public Outline(final String type, final String text) { super(); - this.setType(type); - this.setText(text); + setType(type); + setText(text); } /** @@ -70,11 +68,11 @@ public class Outline implements Cloneable, Serializable { * @param xmlUrl link to XML file. * @param htmlUrl link to html page. */ - public Outline(String title, URL xmlUrl, URL htmlUrl) { + public Outline(final String title, final URL xmlUrl, final URL htmlUrl) { super(); - this.setType("rss"); - this.setTitle(title); - this.setAttributes(new ArrayList()); + setType("rss"); + setTitle(title); + setAttributes(new ArrayList()); if (xmlUrl != null) { getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); @@ -90,8 +88,8 @@ public class Outline implements Cloneable, Serializable { * * @param attributes List of attributes on this outline. */ - public void setAttributes(List attributes) { - this._attributes = attributes; + public void setAttributes(final List attributes) { + _attributes = attributes; } /** @@ -100,8 +98,8 @@ public class Outline implements Cloneable, Serializable { * @return List of attributes on this outline. */ public List getAttributes() { - if (this._attributes == null) { - this._attributes = new ArrayList(); + if (_attributes == null) { + _attributes = new ArrayList(); } return _attributes; @@ -113,8 +111,8 @@ public class Outline implements Cloneable, Serializable { * * @param breakpoint whether a breakpoint is set on this outline. */ - public void setBreakpoint(boolean breakpoint) { - this._breakpoint = breakpoint; + public void setBreakpoint(final boolean breakpoint) { + _breakpoint = breakpoint; } /** @@ -132,8 +130,8 @@ public class Outline implements Cloneable, Serializable { * * @param categories (OPML 2) A List of Strings indicating values in the category attribute. */ - public void setCategories(List categories) { - this._categories = categories; + public void setCategories(final List categories) { + _categories = categories; } /** @@ -154,8 +152,8 @@ public class Outline implements Cloneable, Serializable { * * @param children A list of sub-outlines for this entry. */ - public void setChildren(List children) { - this._children = children; + public void setChildren(final List children) { + _children = children; } /** @@ -177,8 +175,8 @@ public class Outline implements Cloneable, Serializable { * * @param comment whether the outline is commented */ - public void setComment(boolean comment) { - this._comment = comment; + public void setComment(final boolean comment) { + _comment = comment; } /** @@ -196,8 +194,8 @@ public class Outline implements Cloneable, Serializable { * * @param created date-time that the outline node was created. */ - public void setCreated(Date created) { - this._created = created; + public void setCreated(final Date created) { + _created = created; } /** @@ -227,13 +225,13 @@ public class Outline implements Cloneable, Serializable { return getAttributeValue("htmlUrl"); } - public void setModules(List modules) { - this._modules = modules; + public void setModules(final List modules) { + _modules = modules; } public List getModules() { - if (this._modules == null) { - this._modules = new ArrayList(); + if (_modules == null) { + _modules = new ArrayList(); } return _modules; @@ -244,8 +242,8 @@ public class Outline implements Cloneable, Serializable { * * @param text The "text" attribute of the outline. */ - public void setText(String text) { - this._text = text; + public void setText(final String text) { + _text = text; } /** @@ -262,8 +260,8 @@ public class Outline implements Cloneable, Serializable { * * @param title The "title" attribute of the outline. */ - public void setTitle(String title) { - this._title = title; + public void setTitle(final String title) { + _title = title; } /** @@ -280,8 +278,8 @@ public class Outline implements Cloneable, Serializable { * * @param type The "type" attribute of the outline. */ - public void setType(String type) { - this._type = type; + public void setType(final String type) { + _type = type; } /** @@ -307,13 +305,13 @@ public class Outline implements Cloneable, Serializable { * * @param name name of the attribute. */ - public String getAttributeValue(String name) { - List attributes = Collections.synchronizedList(this.getAttributes()); + public String getAttributeValue(final String name) { + final List attributes = Collections.synchronizedList(getAttributes()); for (int i = 0; i < attributes.size(); i++) { - Attribute a = (Attribute) attributes.get(i); + final Attribute a = (Attribute) attributes.get(i); - if ((a.getName() != null) && a.getName().equals(name)) { + if (a.getName() != null && a.getName().equals(name)) { return a.getValue(); } } @@ -323,28 +321,28 @@ public class Outline implements Cloneable, Serializable { @Override public Object clone() { - Outline o = new Outline(); - o.setBreakpoint(this.isBreakpoint()); - o.setCategories(new ArrayList(this.getCategories())); - o.setComment(this.isComment()); - o.setCreated((this._created != null) ? (Date) this._created.clone() : null); - o.setModules(new ArrayList(this.getModules())); - o.setText(this.getText()); - o.setTitle(this.getTitle()); - o.setType(this.getType()); + final Outline o = new Outline(); + o.setBreakpoint(isBreakpoint()); + o.setCategories(new ArrayList(getCategories())); + o.setComment(isComment()); + o.setCreated(_created != null ? (Date) _created.clone() : null); + o.setModules(new ArrayList(getModules())); + o.setText(getText()); + o.setTitle(getTitle()); + o.setType(getType()); - ArrayList children = new ArrayList(); + final ArrayList children = new ArrayList(); - for (int i = 0; i < this.getChildren().size(); i++) { - children.add(((Outline) this._children.get(i)).clone()); + for (int i = 0; i < getChildren().size(); i++) { + children.add(((Outline) _children.get(i)).clone()); } o.setChildren(children); - ArrayList attributes = new ArrayList(); + final ArrayList attributes = new ArrayList(); - for (int i = 0; i < this.getAttributes().size(); i++) { - attributes.add(((Attribute) this._attributes.get(i)).clone()); + for (int i = 0; i < getAttributes().size(); i++) { + attributes.add(((Attribute) _attributes.get(i)).clone()); } o.setAttributes(attributes); @@ -353,22 +351,22 @@ public class Outline implements Cloneable, Serializable { } @Override - public boolean equals(Object obj) { - EqualsBean eBean = new EqualsBean(Outline.class, this); + public boolean equals(final Object obj) { + final EqualsBean eBean = new EqualsBean(Outline.class, this); return eBean.beanEquals(obj); } @Override public int hashCode() { - EqualsBean equals = new EqualsBean(Outline.class, this); + final EqualsBean equals = new EqualsBean(Outline.class, this); return equals.beanHashCode(); } @Override public String toString() { - ToStringBean tsBean = new ToStringBean(Outline.class, this); + final ToStringBean tsBean = new ToStringBean(Outline.class, this); return tsBean.toString(); } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java index 74ba153..41b40d8 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -55,10 +55,10 @@ public class ConverterForOPML10 implements Converter { super(); } - protected void addOwner(Opml opml, SyndFeed syndFeed) { - if ((opml.getOwnerEmail() != null) || (opml.getOwnerName() != null)) { - List authors = new ArrayList(); - SyndPerson person = new SyndPersonImpl(); + protected void addOwner(final Opml opml, final SyndFeed syndFeed) { + if (opml.getOwnerEmail() != null || opml.getOwnerName() != null) { + final List authors = new ArrayList(); + final SyndPerson person = new SyndPersonImpl(); person.setEmail(opml.getOwnerEmail()); person.setName(opml.getOwnerName()); authors.add(person); @@ -76,38 +76,38 @@ public class ConverterForOPML10 implements Converter { * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. */ @Override - public void copyInto(WireFeed feed, SyndFeed syndFeed) { - Opml opml = (Opml) feed; + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + final Opml opml = (Opml) feed; syndFeed.setTitle(opml.getTitle()); addOwner(opml, syndFeed); - syndFeed.setPublishedDate((opml.getModified() != null) ? opml.getModified() : opml.getCreated()); + syndFeed.setPublishedDate(opml.getModified() != null ? opml.getModified() : opml.getCreated()); syndFeed.setFeedType(opml.getFeedType()); syndFeed.setModules(opml.getModules()); - syndFeed.setFeedType(this.getType()); + syndFeed.setFeedType(getType()); - ArrayList entries = new ArrayList(); + final ArrayList entries = new ArrayList(); createEntries(new TreeContext(), syndFeed.getEntries(), opml.getOutlines()); } - protected void createEntries(TreeContext context, List allEntries, List outlines) { - List so = Collections.synchronizedList(outlines); + protected void createEntries(final TreeContext context, final List allEntries, final List outlines) { + final List so = Collections.synchronizedList(outlines); for (int i = 0; i < so.size(); i++) { createEntry(context, allEntries, (Outline) so.get(i)); } } - protected SyndEntry createEntry(TreeContext context, List allEntries, Outline outline) { - SyndEntry entry = new SyndEntryImpl(); + protected SyndEntry createEntry(final TreeContext context, final List allEntries, final Outline outline) { + final SyndEntry entry = new SyndEntryImpl(); - if ((outline.getType() != null) && outline.getType().equals("rss")) { - entry.setLink((outline.getHtmlUrl() != null) ? outline.getHtmlUrl() : outline.getXmlUrl()); - } else if ((outline.getType() != null) && outline.getType().equals("link")) { + if (outline.getType() != null && outline.getType().equals("rss")) { + entry.setLink(outline.getHtmlUrl() != null ? outline.getHtmlUrl() : outline.getXmlUrl()); + } else if (outline.getType() != null && outline.getType().equals("link")) { entry.setLink(outline.getUrl()); } if (outline.getHtmlUrl() != null) { - SyndLink link = new SyndLinkImpl(); + final SyndLink link = new SyndLinkImpl(); link.setRel("alternate"); link.setType("text/html"); link.setHref(outline.getHtmlUrl()); @@ -115,8 +115,8 @@ public class ConverterForOPML10 implements Converter { entry.setLink(outline.getHtmlUrl()); } - if ((outline.getXmlUrl() != null) && (outline.getType() != null) && outline.getType().equalsIgnoreCase("rss")) { - SyndLink link = new SyndLinkImpl(); + if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("rss")) { + final SyndLink link = new SyndLinkImpl(); link.setRel("alternate"); link.setType("application/rss+xml"); link.setHref(outline.getXmlUrl()); @@ -127,8 +127,8 @@ public class ConverterForOPML10 implements Converter { } } - if ((outline.getXmlUrl() != null) && (outline.getType() != null) && outline.getType().equalsIgnoreCase("atom")) { - SyndLink link = new SyndLinkImpl(); + if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("atom")) { + final SyndLink link = new SyndLinkImpl(); link.setRel("alternate"); link.setType("application/atom+xml"); link.setHref(outline.getXmlUrl()); @@ -139,40 +139,40 @@ public class ConverterForOPML10 implements Converter { } } - if ((outline.getType() != null) && outline.getType().equals("rss")) { + if (outline.getType() != null && outline.getType().equals("rss")) { entry.setTitle(outline.getTitle()); } else { entry.setTitle(outline.getText()); } - if ((outline.getText() == null) && (entry.getTitle() != null)) { - SyndContent c = new SyndContentImpl(); + if (outline.getText() == null && entry.getTitle() != null) { + final SyndContent c = new SyndContentImpl(); c.setValue(outline.getText()); entry.setDescription(c); } entry.setPublishedDate(outline.getCreated()); - String nodeName = "node." + outline.hashCode(); + final String nodeName = "node." + outline.hashCode(); - SyndCategory cat = new TreeCategoryImpl(); + final SyndCategory cat = new TreeCategoryImpl(); cat.setTaxonomyUri(URI_TREE); cat.setName(nodeName); entry.getCategories().add(cat); if (context.size() > 0) { - Integer parent = (Integer) context.peek(); - SyndCategory pcat = new TreeCategoryImpl(); + final Integer parent = (Integer) context.peek(); + final SyndCategory pcat = new TreeCategoryImpl(); pcat.setTaxonomyUri(URI_TREE); pcat.setName("parent." + parent); entry.getCategories().add(pcat); } - List attributes = Collections.synchronizedList(outline.getAttributes()); + final List attributes = Collections.synchronizedList(outline.getAttributes()); for (int i = 0; i < attributes.size(); i++) { - Attribute a = (Attribute) attributes.get(i); - SyndCategory acat = new SyndCategoryImpl(); + final Attribute a = (Attribute) attributes.get(i); + final SyndCategory acat = new SyndCategoryImpl(); acat.setName(a.getValue()); acat.setTaxonomyUri(URI_ATTRIBUTE + a.getName()); entry.getCategories().add(acat); @@ -196,33 +196,33 @@ public class ConverterForOPML10 implements Converter { * */ @Override - public WireFeed createRealFeed(SyndFeed syndFeed) { - List entries = Collections.synchronizedList(syndFeed.getEntries()); + public WireFeed createRealFeed(final SyndFeed syndFeed) { + final List entries = Collections.synchronizedList(syndFeed.getEntries()); - HashMap entriesByNode = new HashMap(); - ArrayList doAfterPass = new ArrayList(); // this will hold entries that we can't parent the first time. - ArrayList root = new ArrayList(); // this holds root level outlines; + final HashMap entriesByNode = new HashMap(); + final ArrayList doAfterPass = new ArrayList(); // this will hold entries that we can't parent the first time. + final ArrayList root = new ArrayList(); // this holds root level outlines; for (int i = 0; i < entries.size(); i++) { - SyndEntry entry = (SyndEntry) entries.get(i); - Outline o = new Outline(); + final SyndEntry entry = (SyndEntry) entries.get(i); + final Outline o = new Outline(); - List cats = Collections.synchronizedList(entry.getCategories()); + final List cats = Collections.synchronizedList(entry.getCategories()); boolean parentFound = false; - StringBuffer category = new StringBuffer(); + final StringBuffer category = new StringBuffer(); for (int j = 0; j < cats.size(); j++) { - SyndCategory cat = (SyndCategory) cats.get(j); + final SyndCategory cat = (SyndCategory) cats.get(j); - if ((cat.getTaxonomyUri() != null) && cat.getTaxonomyUri().equals(URI_TREE)) { - String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length()); + if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().equals(URI_TREE)) { + final String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length()); if (cat.getName().startsWith("node.")) { entriesByNode.put(nodeVal, o); } else if (cat.getName().startsWith("parent.")) { parentFound = true; - Outline parent = (Outline) entriesByNode.get(nodeVal); + final Outline parent = (Outline) entriesByNode.get(nodeVal); if (parent != null) { parent.getChildren().add(o); @@ -230,8 +230,8 @@ public class ConverterForOPML10 implements Converter { doAfterPass.add(new OutlineHolder(o, nodeVal)); } } - } else if ((cat.getTaxonomyUri() != null) && cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) { - String name = cat.getTaxonomyUri().substring(cat.getTaxonomyUri().indexOf("#") + 1, cat.getTaxonomyUri().length()); + } else if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) { + final String name = cat.getTaxonomyUri().substring(cat.getTaxonomyUri().indexOf("#") + 1, cat.getTaxonomyUri().length()); o.getAttributes().add(new Attribute(name, cat.getName())); } else { if (category.length() > 0) { @@ -250,21 +250,21 @@ public class ConverterForOPML10 implements Converter { o.getAttributes().add(new Attribute("category", category.toString())); } - List links = Collections.synchronizedList(entry.getLinks()); - String entryLink = entry.getLink(); + final List links = Collections.synchronizedList(entry.getLinks()); + final String entryLink = entry.getLink(); for (int j = 0; j < links.size(); j++) { - SyndLink link = (SyndLink) links.get(j); + final SyndLink link = (SyndLink) links.get(j); // if(link.getHref().equals(entryLink)) { - if (((link.getType() != null) && (link.getRel() != null) && link.getRel().equals("alternate")) + if (link.getType() != null && link.getRel() != null && link.getRel().equals("alternate") && (link.getType().equals("application/rss+xml") || link.getType().equals("application/atom+xml"))) { o.setType("rss"); if (o.getXmlUrl() == null) { o.getAttributes().add(new Attribute("xmlUrl", link.getHref())); } - } else if ((link.getType() != null) && (link.getType().equals("text/html"))) { + } else if (link.getType() != null && link.getType().equals("text/html")) { if (o.getHtmlUrl() == null) { o.getAttributes().add(new Attribute("htmlUrl", link.getHref())); } @@ -275,22 +275,22 @@ 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()); } else { o.setTitle(entry.getTitle()); } - if ((o.getText() == null) && (entry.getDescription() != null)) { + if (o.getText() == null && entry.getDescription() != null) { o.setText(entry.getDescription().getValue()); } } // Do back and parenting for things we missed. for (int i = 0; i < doAfterPass.size(); i++) { - OutlineHolder o = (OutlineHolder) doAfterPass.get(i); - Outline parent = (Outline) entriesByNode.get(o.parent); + final OutlineHolder o = (OutlineHolder) doAfterPass.get(i); + final Outline parent = (Outline) entriesByNode.get(o.parent); if (parent == null) { root.add(o.outline); @@ -300,17 +300,17 @@ public class ConverterForOPML10 implements Converter { } } - Opml opml = new Opml(); - opml.setFeedType(this.getType()); + final Opml opml = new Opml(); + opml.setFeedType(getType()); opml.setCreated(syndFeed.getPublishedDate()); opml.setTitle(syndFeed.getTitle()); - List authors = Collections.synchronizedList(syndFeed.getAuthors()); + final List authors = Collections.synchronizedList(syndFeed.getAuthors()); for (int i = 0; i < authors.size(); i++) { - SyndPerson p = (SyndPerson) authors.get(i); + final SyndPerson p = (SyndPerson) authors.get(i); - if ((syndFeed.getAuthor() == null) || syndFeed.getAuthor().equals(p.getName())) { + if (syndFeed.getAuthor() == null || syndFeed.getAuthor().equals(p.getName())) { opml.setOwnerName(p.getName()); opml.setOwnerEmail(p.getEmail()); opml.setOwnerId(p.getUri()); @@ -339,7 +339,7 @@ public class ConverterForOPML10 implements Converter { Outline outline; String parent; - public OutlineHolder(Outline outline, String parent) { + public OutlineHolder(final Outline outline, final String parent) { this.outline = outline; this.parent = parent; } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java index 53e5d9b..414c87a 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java @@ -44,7 +44,7 @@ public class ConverterForOPML20 extends ConverterForOPML10 { * @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(final WireFeed feed, final SyndFeed syndFeed) { super.copyInto(feed, syndFeed); } @@ -56,7 +56,7 @@ public class ConverterForOPML20 extends ConverterForOPML10 { * @return a real feed with copied/converted values of the SyndFeedImpl. */ @Override - public WireFeed createRealFeed(SyndFeed syndFeed) { + public WireFeed createRealFeed(final SyndFeed syndFeed) { WireFeed retValue; retValue = super.createRealFeed(syndFeed); diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java index 02ced72..c7a5a3c 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java @@ -24,12 +24,13 @@ public class TreeCategoryImpl extends SyndCategoryImpl { } @Override - public boolean equals(Object o) { - SyndCategory c = (SyndCategory) o; - if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(this.getTaxonomyUri())) + public boolean equals(final Object o) { + final SyndCategory c = (SyndCategory) o; + if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(getTaxonomyUri())) { return true; - else + } else { return false; + } } } diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java index ca3b0d3..c8a497f 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java @@ -17,21 +17,19 @@ */ package com.sun.syndication.io.impl; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.jdom2.Document; +import org.jdom2.Element; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.opml.Attribute; import com.sun.syndication.feed.opml.Opml; import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedGenerator; -import com.sun.syndication.io.impl.BaseWireFeedGenerator; -import com.sun.syndication.io.impl.DateParser; - -import org.jdom2.Document; -import org.jdom2.Element; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; /** * @@ -43,7 +41,7 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe super("opml_1.0"); } - public OPML10Generator(String type) { + public OPML10Generator(final String type) { super(type); } @@ -57,23 +55,23 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe * @throws FeedException thrown if the XML Document could not be created. */ @Override - public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { + public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { if (!(feed instanceof Opml)) { throw new IllegalArgumentException("Not an OPML file"); } - Opml opml = (Opml) feed; - Document doc = new Document(); - Element root = new Element("opml"); + final Opml opml = (Opml) feed; + final Document doc = new Document(); + final Element root = new Element("opml"); doc.addContent(root); - Element head = generateHead(opml); + final Element head = generateHead(opml); if (head != null) { root.addContent(head); } - Element body = new Element("body"); + final Element body = new Element("body"); root.addContent(body); super.generateFeedModules(opml.getModules(), root); body.addContent(generateOutlines(opml.getOutlines())); @@ -81,8 +79,8 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe return doc; } - protected boolean addNotNullAttribute(Element target, String name, Object value) { - if ((target == null) || (name == null) || (value == null)) { + protected boolean addNotNullAttribute(final Element target, final String name, final Object value) { + if (target == null || name == null || value == null) { return false; } @@ -91,20 +89,20 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe return true; } - protected boolean addNotNullSimpleElement(Element target, String name, Object value) { - if ((target == null) || (name == null) || (value == null)) { + protected boolean addNotNullSimpleElement(final Element target, final String name, final Object value) { + if (target == null || name == null || value == null) { return false; } - Element e = new Element(name); + final Element e = new Element(name); e.addContent(value.toString()); target.addContent(e); return true; } - protected Element generateHead(Opml opml) { - Element head = new Element("head"); + protected Element generateHead(final Opml opml) { + final Element head = new Element("head"); boolean hasHead = false; if (opml.getCreated() != null) { @@ -133,8 +131,8 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe } } - protected Element generateOutline(Outline outline) { - Element e = new Element("outline"); + protected Element generateOutline(final Outline outline) { + final Element e = new Element("outline"); addNotNullAttribute(e, "text", outline.getText()); addNotNullAttribute(e, "type", outline.getType()); addNotNullAttribute(e, "title", outline.getTitle()); @@ -147,10 +145,10 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe addNotNullAttribute(e, "isComment", "true"); } - List atts = Collections.synchronizedList(outline.getAttributes()); + final List atts = Collections.synchronizedList(outline.getAttributes()); for (int i = 0; i < atts.size(); i++) { - Attribute att = (Attribute) atts.get(i); + final Attribute att = (Attribute) atts.get(i); addNotNullAttribute(e, att.getName(), att.getValue()); } @@ -160,22 +158,22 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe return e; } - protected List generateOutlines(List outlines) { - ArrayList elements = new ArrayList(); + protected List generateOutlines(final List outlines) { + final ArrayList elements = new ArrayList(); - for (int i = 0; (outlines != null) && (i < outlines.size()); i++) { + for (int i = 0; outlines != null && i < outlines.size(); i++) { elements.add(generateOutline((Outline) outlines.get(i))); } return elements; } - protected String intArrayToCsvString(int[] value) { - if ((value == null) || (value.length == 0)) { + protected String intArrayToCsvString(final int[] value) { + if (value == null || value.length == 0) { return null; } - StringBuffer sb = new StringBuffer(); + final StringBuffer sb = new StringBuffer(); sb.append(value[0]); for (int i = 1; i < value.length; i++) { diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java index d40082a..70c9a23 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java @@ -17,23 +17,21 @@ */ package com.sun.syndication.io.impl; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jdom2.Document; +import org.jdom2.Element; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.opml.Attribute; import com.sun.syndication.feed.opml.Opml; import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedParser; -import com.sun.syndication.io.impl.BaseWireFeedParser; -import com.sun.syndication.io.impl.DateParser; - -import org.jdom2.Document; -import org.jdom2.Element; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @@ -47,7 +45,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { super("opml_1.0", null); } - public OPML10Parser(String type) { + public OPML10Parser(final String type) { super(type, null); } @@ -61,8 +59,8 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { * @return true if the parser know how to parser this feed, false otherwise. */ @Override - public boolean isMyType(Document document) { - Element e = document.getRootElement(); + public boolean isMyType(final Document document) { + final Element e = document.getRootElement(); if (e.getName().equals("opml") && (e.getChild("head") == null || e.getChild("head").getChild("docs") == null) && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) { @@ -83,12 +81,12 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ @Override - public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { - Opml opml = new Opml(); + public WireFeed parse(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { + final Opml opml = new Opml(); opml.setFeedType("opml_1.0"); - Element root = document.getRootElement(); - Element head = root.getChild("head"); + final Element root = document.getRootElement(); + final Element head = root.getChild("head"); if (head != null) { opml.setTitle(head.getChildText("title")); @@ -108,7 +106,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); - } catch (NumberFormatException nfe) { + } catch (final NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to parse windowBottom", nfe); if (validate) { @@ -118,13 +116,13 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); - } catch (NumberFormatException nfe) { + } catch (final NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); } try { opml.setWindowRight(readInteger(head.getChildText("windowRight"))); - } catch (NumberFormatException nfe) { + } catch (final NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to parse windowRight", nfe); if (validate) { @@ -134,7 +132,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); - } catch (NumberFormatException nfe) { + } catch (final NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); if (validate) { @@ -144,7 +142,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowTop(readInteger(head.getChildText("windowTop"))); - } catch (NumberFormatException nfe) { + } catch (final NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to parse windowTop", nfe); if (validate) { @@ -154,7 +152,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); - } catch (NumberFormatException nfe) { + } catch (final NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to parse expansionState", nfe); if (validate) { @@ -163,26 +161,26 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { } opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate)); - opml.setModules(this.parseFeedModules(root)); + opml.setModules(parseFeedModules(root)); return opml; } - protected Outline parseOutline(Element e, boolean validate) throws FeedException { + protected Outline parseOutline(final Element e, final boolean validate) throws FeedException { if (!e.getName().equals("outline")) { throw new RuntimeException("Not an outline element."); } - Outline outline = new Outline(); + final Outline outline = new Outline(); outline.setText(e.getAttributeValue("text")); outline.setType(e.getAttributeValue("type")); outline.setTitle(e.getAttributeValue("title")); - List jAttributes = e.getAttributes(); - ArrayList attributes = new ArrayList(); + final List jAttributes = e.getAttributes(); + final ArrayList attributes = new ArrayList(); for (int i = 0; i < jAttributes.size(); i++) { - org.jdom2.Attribute a = (org.jdom2.Attribute) jAttributes.get(i); + final 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")) { @@ -194,7 +192,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); - } catch (Exception ex) { + } catch (final Exception ex) { LOG.log(Level.WARNING, "Unable to parse isBreakpoint value", ex); if (validate) { @@ -204,7 +202,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { outline.setComment(readBoolean(e.getAttributeValue("isComment"))); - } catch (Exception ex) { + } catch (final Exception ex) { LOG.log(Level.WARNING, "Unable to parse isComment value", ex); if (validate) { @@ -212,15 +210,15 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { } } - List children = e.getChildren("outline"); - outline.setModules(this.parseItemModules(e)); + final List children = e.getChildren("outline"); + outline.setModules(parseItemModules(e)); outline.setChildren(parseOutlines(children, validate)); return outline; } - protected List parseOutlines(List elements, boolean validate) throws FeedException { - ArrayList results = new ArrayList(); + protected List parseOutlines(final List elements, final boolean validate) throws FeedException { + final ArrayList results = new ArrayList(); for (int i = 0; i < elements.size(); i++) { results.add(parseOutline((Element) elements.get(i), validate)); @@ -229,7 +227,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { return results; } - protected boolean readBoolean(String value) { + protected boolean readBoolean(final String value) { if (value == null) { return false; } else { @@ -237,12 +235,12 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { } } - protected int[] readIntArray(String value) { + protected int[] readIntArray(final String value) { if (value == null) { return null; } else { - StringTokenizer tok = new StringTokenizer(value, ","); - int[] result = new int[tok.countTokens()]; + final StringTokenizer tok = new StringTokenizer(value, ","); + final int[] result = new int[tok.countTokens()]; int count = 0; while (tok.hasMoreElements()) { @@ -254,7 +252,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { } } - protected Integer readInteger(String value) { + protected Integer readInteger(final String value) { if (value != null) { return new Integer(value); } else { diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java index 3034d01..9f6df0d 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java @@ -8,14 +8,13 @@ */ package com.sun.syndication.io.impl; +import org.jdom2.Document; +import org.jdom2.Element; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.opml.Opml; import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.impl.DateParser; - -import org.jdom2.Document; -import org.jdom2.Element; /** * @@ -49,7 +48,7 @@ public class OPML20Generator extends OPML10Generator { * @throws FeedException thrown if the XML Document could not be created. */ @Override - public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException { + public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { Document retValue; retValue = super.generate(feed); @@ -59,19 +58,19 @@ public class OPML20Generator extends OPML10Generator { } @Override - protected Element generateHead(Opml opml) { + protected Element generateHead(final Opml opml) { Element retValue; retValue = super.generateHead(opml); - Element docs = new Element("docs", opml.getDocs()); + final Element docs = new Element("docs", opml.getDocs()); retValue.addContent(docs); return retValue; } @Override - protected Element generateOutline(Outline outline) { + protected Element generateOutline(final Outline outline) { Element retValue; retValue = super.generateOutline(outline); diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java index e53cc6a..6461b53 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java @@ -17,17 +17,16 @@ */ package com.sun.syndication.io.impl; +import java.util.List; + +import org.jdom2.Document; +import org.jdom2.Element; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.opml.Attribute; import com.sun.syndication.feed.opml.Opml; import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.impl.DateParser; - -import org.jdom2.Document; -import org.jdom2.Element; - -import java.util.List; /** * @@ -49,13 +48,12 @@ public class OPML20Parser extends OPML10Parser { * @return true if the parser know how to parser this feed, false otherwise. */ @Override - public boolean isMyType(Document document) { - Element e = document.getRootElement(); + public boolean isMyType(final Document document) { + final 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)))) { + && (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; } @@ -73,11 +71,11 @@ public class OPML20Parser extends OPML10Parser { * @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(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { Opml opml; opml = (Opml) super.parse(document, validate); - Element head = document.getRootElement().getChild("head"); + final Element head = document.getRootElement().getChild("head"); if (head != null) { opml.setOwnerId(head.getChildTextTrim("ownerId")); @@ -94,7 +92,7 @@ public class OPML20Parser extends OPML10Parser { } @Override - protected Outline parseOutline(Element e, boolean validate) throws FeedException { + protected Outline parseOutline(final Element e, final boolean validate) throws FeedException { Outline retValue; retValue = super.parseOutline(e, validate); @@ -103,10 +101,10 @@ public class OPML20Parser extends OPML10Parser { retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"))); } - List atts = retValue.getAttributes(); + final List atts = retValue.getAttributes(); for (int i = 0; i < atts.size(); i++) { - Attribute a = (Attribute) atts.get(i); + final Attribute a = (Attribute) atts.get(i); if (a.getName().equals("created")) { retValue.getAttributes().remove(a); diff --git a/src/test/java/com/sun/syndication/SyndFeedTest.java b/src/test/java/com/sun/syndication/SyndFeedTest.java index 4fc0033..3a20b33 100644 --- a/src/test/java/com/sun/syndication/SyndFeedTest.java +++ b/src/test/java/com/sun/syndication/SyndFeedTest.java @@ -13,11 +13,11 @@ package com.sun.syndication; public abstract class SyndFeedTest extends FeedTest { private String _prefix = null; - protected SyndFeedTest(String feedType) { + protected SyndFeedTest(final String feedType) { this(feedType, feedType + ".xml"); } - protected SyndFeedTest(String feedType, String feedFileName) { + protected SyndFeedTest(final String feedType, final String feedFileName) { super(feedFileName); _prefix = feedType; } @@ -26,7 +26,7 @@ public abstract class SyndFeedTest extends FeedTest { return _prefix; } - protected void assertProperty(String property, String value) { + protected void assertProperty(final String property, final String value) { assertEquals(property, getPrefix() + "." + value); } From 093be5d0c4d84ab051a4dc41612f29e9462b2bc0 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Oct 2013 00:12:23 +0200 Subject: [PATCH 14/47] Added Eclipse formatter and cleanup configuration --- cleanup.xml | 56 ++++++++++ formatter.xml | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 347 insertions(+) create mode 100644 cleanup.xml create mode 100644 formatter.xml diff --git a/cleanup.xml b/cleanup.xml new file mode 100644 index 0000000..40f9b7a --- /dev/null +++ b/cleanup.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/formatter.xml b/formatter.xml new file mode 100644 index 0000000..e7ba7aa --- /dev/null +++ b/formatter.xml @@ -0,0 +1,291 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0baa10d58d707308dc6d836db20fdb98256a7bce Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Oct 2013 22:35:20 +0200 Subject: [PATCH 15/47] Enhanced POM --- pom.xml | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index 91a8983..e89d23e 100644 --- a/pom.xml +++ b/pom.xml @@ -79,33 +79,6 @@ 1.6 - - org.apache.maven.plugins - maven-site-plugin - 3.3 - - 9000 - ${basedir}/target/site/tempdir - - - - org.apache.maven.plugins - maven-scm-plugin - 1.8.1 - - install - - - - org.apache.maven.plugins - maven-scm-publish-plugin - 1.0-beta-2 - - gh-pages - scm:git:git@github.com:rometools/rome-opml.git - ${project.build.directory}/site - - org.apache.maven.plugins maven-source-plugin @@ -130,6 +103,29 @@ + + org.apache.maven.plugins + maven-site-plugin + 3.3 + + + org.apache.maven.plugins + maven-scm-plugin + 1.8.1 + + install + + + + org.apache.maven.plugins + maven-scm-publish-plugin + 1.0-beta-2 + + gh-pages + scm:git:git@github.com:rometools/rome-opml.git + ${project.build.directory}/site + + From 63ac66e5b8c87c072235b14d90b79f61f3f8434a Mon Sep 17 00:00:00 2001 From: Martin Kurz Date: Sun, 13 Oct 2013 16:28:35 +0200 Subject: [PATCH 16/47] adapted locale changes from rometools/rome-moudles#22 --- .../syndication/io/impl/OPML10Generator.java | 5 +++-- .../sun/syndication/io/impl/OPML10Parser.java | 21 ++++++++++--------- .../syndication/io/impl/OPML20Generator.java | 4 +++- .../sun/syndication/io/impl/OPML20Parser.java | 11 +++++----- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java index c8a497f..008bef1 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java @@ -20,6 +20,7 @@ package com.sun.syndication.io.impl; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import org.jdom2.Document; import org.jdom2.Element; @@ -106,13 +107,13 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe boolean hasHead = false; if (opml.getCreated() != null) { - hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated())); + hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US)); } hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); if (opml.getModified() != null) { - hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified())); + hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US)); } hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java index 70c9a23..ab540d6 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java @@ -19,6 +19,7 @@ package com.sun.syndication.io.impl; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; @@ -81,7 +82,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ @Override - public WireFeed parse(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { + public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException { final Opml opml = new Opml(); opml.setFeedType("opml_1.0"); @@ -92,11 +93,11 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { opml.setTitle(head.getChildText("title")); if (head.getChildText("dateCreated") != null) { - opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"))); + opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US)); } if (head.getChildText("dateModified") != null) { - opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"))); + opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US)); } opml.setOwnerName(head.getChildTextTrim("ownerName")); @@ -160,13 +161,13 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { } } - opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate)); - opml.setModules(parseFeedModules(root)); + opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale)); + opml.setModules(parseFeedModules(root, locale)); return opml; } - protected Outline parseOutline(final Element e, final boolean validate) throws FeedException { + protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException { if (!e.getName().equals("outline")) { throw new RuntimeException("Not an outline element."); } @@ -211,17 +212,17 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { } final List children = e.getChildren("outline"); - outline.setModules(parseItemModules(e)); - outline.setChildren(parseOutlines(children, validate)); + outline.setModules(parseItemModules(e, locale)); + outline.setChildren(parseOutlines(children, validate, locale)); return outline; } - protected List parseOutlines(final List elements, final boolean validate) throws FeedException { + protected List parseOutlines(final List elements, final boolean validate, final Locale locale) throws FeedException { final ArrayList results = new ArrayList(); for (int i = 0; i < elements.size(); i++) { - results.add(parseOutline((Element) elements.get(i), validate)); + results.add(parseOutline((Element) elements.get(i), validate, locale)); } return results; diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java index 9f6df0d..c88826e 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java @@ -8,6 +8,8 @@ */ package com.sun.syndication.io.impl; +import java.util.Locale; + import org.jdom2.Document; import org.jdom2.Element; @@ -76,7 +78,7 @@ public class OPML20Generator extends OPML10Generator { retValue = super.generateOutline(outline); if (outline.getCreated() != null) { - retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated())); + retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated(), Locale.US)); } return retValue; diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java index 6461b53..5ddba37 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java @@ -18,6 +18,7 @@ package com.sun.syndication.io.impl; import java.util.List; +import java.util.Locale; import org.jdom2.Document; import org.jdom2.Element; @@ -71,9 +72,9 @@ public class OPML20Parser extends OPML10Parser { * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). */ @Override - public WireFeed parse(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { + public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException { Opml opml; - opml = (Opml) super.parse(document, validate); + opml = (Opml) super.parse(document, validate, locale); final Element head = document.getRootElement().getChild("head"); @@ -92,13 +93,13 @@ public class OPML20Parser extends OPML10Parser { } @Override - protected Outline parseOutline(final Element e, final boolean validate) throws FeedException { + protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException { Outline retValue; - retValue = super.parseOutline(e, validate); + retValue = super.parseOutline(e, validate, locale); if (e.getAttributeValue("created") != null) { - retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"))); + retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"), locale)); } final List atts = retValue.getAttributes(); From 9e1291dd6a30e74ba4274b09269ea8d158482ac1 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 11:09:25 +0200 Subject: [PATCH 17/47] Preparing release 1.5.0 Cleaned up POM --- pom.xml | 241 +++++++++++++++++++------------------------------------- 1 file changed, 82 insertions(+), 159 deletions(-) diff --git a/pom.xml b/pom.xml index e89d23e..cd72385 100644 --- a/pom.xml +++ b/pom.xml @@ -1,176 +1,99 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - 4.0.0 + 4.0.0 - com.rometools - rome-opml - 2.0.0-SNAPSHOT + + org.sonatype.oss + oss-parent + 9 + - rome-opml + com.rometools + rome-opml + 1.5.0-SNAPSHOT + jar - http://rometools.github.io/rome-opml/ + rome-opml - Support for OPML 1 and OPML 2 in ROME + Support for OPML 1 and OPML 2 in ROME - - ROME Project - https://github.com/rometools/ - + http://rometools.github.io/rome-opml/ - - https://github.com/rometools/rome-opml/issues - + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + - - scm:git:git@github.com:rometools/rome-opml.git - scm:git:git@github.com:rometools/rome-opml.git - https://github.com/rometools/rome-opml/ - + + scm:git:git@github.com:rometools/rome-opml.git + scm:git:git@github.com:rometools/rome-opml.git + https://github.com/rometools/rome-opml/ + - - - kebernet - kebernet@gmail.com - Robert Cooper - - + + + kebernet + kebernet@gmail.com + Robert Cooper + + - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - + + UTF-8 + UTF-8 + - - UTF-8 - UTF-8 - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-scm-publish-plugin + 1.0 + + gh-pages + ${project.scm.developerConnection} + ${project.build.directory}/site + + + + - - - central.staging - http://oss.sonatype.org/service/local/staging/deploy/maven2 - - - sonatype.snapshots - https://oss.sonatype.org/content/repositories/snapshots - - + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + - - - sonatype.snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - - jar - - - - - - org.apache.maven.plugins - maven-site-plugin - 3.3 - - - org.apache.maven.plugins - maven-scm-plugin - 1.8.1 - - install - - - - org.apache.maven.plugins - maven-scm-publish-plugin - 1.0-beta-2 - - gh-pages - scm:git:git@github.com:rometools/rome-opml.git - ${project.build.directory}/site - - - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.7 - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - - javadoc - test-javadoc - - - - aggregate - false - - aggregate - - - - - - - - - - com.rometools - rome - 2.0.0-SNAPSHOT - - - junit - junit - 4.11 - test - - + + + com.rometools + rome + 1.5.0-SNAPSHOT + + + junit + junit + 4.11 + test + + From cfed9745456ed90c44f7f0a89d2b419a5ced541c Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 13:37:22 +0200 Subject: [PATCH 18/47] Migration to rome-parent --- cleanup.xml | 56 ---------- formatter.xml | 291 -------------------------------------------------- pom.xml | 43 +------- 3 files changed, 3 insertions(+), 387 deletions(-) delete mode 100644 cleanup.xml delete mode 100644 formatter.xml diff --git a/cleanup.xml b/cleanup.xml deleted file mode 100644 index 40f9b7a..0000000 --- a/cleanup.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/formatter.xml b/formatter.xml deleted file mode 100644 index e7ba7aa..0000000 --- a/formatter.xml +++ /dev/null @@ -1,291 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index cd72385..60d6320 100644 --- a/pom.xml +++ b/pom.xml @@ -5,14 +5,12 @@ 4.0.0 - org.sonatype.oss - oss-parent - 9 + com.rometools + rome-parent + 1.5.0-SNAPSHOT - com.rometools rome-opml - 1.5.0-SNAPSHOT jar rome-opml @@ -21,14 +19,6 @@ http://rometools.github.io/rome-opml/ - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - scm:git:git@github.com:rometools/rome-opml.git scm:git:git@github.com:rometools/rome-opml.git @@ -43,26 +33,11 @@ - - UTF-8 - UTF-8 - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - org.apache.maven.plugins maven-scm-publish-plugin - 1.0 gh-pages ${project.scm.developerConnection} @@ -72,26 +47,14 @@ - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.7 - - - - com.rometools rome - 1.5.0-SNAPSHOT junit junit - 4.11 test From a8a0290187cd1dd5d94369fae67f8847dd976aa1 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 16:34:44 +0200 Subject: [PATCH 19/47] Added missing serialVersionUIDs --- .../sun/syndication/feed/opml/Attribute.java | 15 +++-- .../com/sun/syndication/feed/opml/Opml.java | 61 ++++++++++--------- .../sun/syndication/feed/opml/Outline.java | 53 ++++++++-------- .../feed/synd/impl/ConverterForOPML10.java | 13 ++-- .../feed/synd/impl/TreeCategoryImpl.java | 4 +- 5 files changed, 80 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/sun/syndication/feed/opml/Attribute.java b/src/main/java/com/sun/syndication/feed/opml/Attribute.java index c3925c2..133a254 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Attribute.java +++ b/src/main/java/com/sun/syndication/feed/opml/Attribute.java @@ -24,10 +24,13 @@ import com.sun.syndication.feed.impl.ToStringBean; /** * This is a simple name-value pair attribute for outlines. - * + * * @author Robert "kebernet" Cooper */ public class Attribute implements Cloneable, Serializable { + + private static final long serialVersionUID = 1L; + private String _name; private String _value; @@ -38,7 +41,7 @@ public class Attribute implements Cloneable, Serializable { /** * Creates a new instance of Attribute. - * + * * @param name name of the attribute. * @param value value of the attribute. */ @@ -52,7 +55,7 @@ public class Attribute implements Cloneable, Serializable { /** * name of the attribute. - * + * * @param name name of the attribute. */ public void setName(final String name) { @@ -61,7 +64,7 @@ public class Attribute implements Cloneable, Serializable { /** * name of the attribute. - * + * * @return name of the attribute. */ public String getName() { @@ -70,7 +73,7 @@ public class Attribute implements Cloneable, Serializable { /** * value of the attribute. - * + * * @param value value of the attribute. */ public void setValue(final String value) { @@ -79,7 +82,7 @@ public class Attribute implements Cloneable, Serializable { /** * value of the attribute. - * + * * @return value of the attribute. */ public String getValue() { diff --git a/src/main/java/com/sun/syndication/feed/opml/Opml.java b/src/main/java/com/sun/syndication/feed/opml/Opml.java index cb8ed8a..b42a26e 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Opml.java +++ b/src/main/java/com/sun/syndication/feed/opml/Opml.java @@ -25,10 +25,13 @@ import com.sun.syndication.feed.WireFeed; /** * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in the <head> tag of the feed. - * + * * @author Robert "kebernet" Cooper */ public class Opml extends WireFeed { + + private static final long serialVersionUID = 1L; + private Date _created; private Date _modified; private Integer _verticalScrollState; @@ -51,7 +54,7 @@ public class Opml extends WireFeed { /** * is a date-time, indicating when the document was created. - * + * * @param created date-time, indicating when the document was created. */ public void setCreated(final Date created) { @@ -60,7 +63,7 @@ public class Opml extends WireFeed { /** * <dateCreated> is a date-time, indicating when the document was created. - * + * * @return date-time, indicating when the document was created. */ public Date getCreated() { @@ -70,7 +73,7 @@ public class Opml extends WireFeed { /** * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. - * + * * @param docs http address of documentation for the format used */ public void setDocs(final String docs) { @@ -80,7 +83,7 @@ public class Opml extends WireFeed { /** * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. - * + * * @return http address of documentation for the format used */ public String getDocs() { @@ -91,7 +94,7 @@ public class Opml extends WireFeed { * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The * order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the * list. - * + * * @param expansionState int array containing expanded elements. */ public void setExpansionState(final int[] expansionState) { @@ -102,7 +105,7 @@ public class Opml extends WireFeed { * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The * order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the * list. - * + * * @return int array containing expanded elements. */ public int[] getExpansionState() { @@ -111,7 +114,7 @@ public class Opml extends WireFeed { /** * <dateModified> is a date-time, indicating when the document was last modified. - * + * * @param modified date-time, indicating when the document was last modified. */ public void setModified(final Date modified) { @@ -120,7 +123,7 @@ public class Opml extends WireFeed { /** * <dateModified> is a date-time, indicating when the document was last modified. - * + * * @return date-time, indicating when the document was last modified. */ public Date getModified() { @@ -129,7 +132,7 @@ public class Opml extends WireFeed { /** * Root level Outline object that should appear in the <body> - * + * * @param outlines Root level Outline object that should appear in the <body> */ public void setOutlines(final List outlines) { @@ -138,7 +141,7 @@ public class Opml extends WireFeed { /** * Root level Outline object that should appear in the <body> - * + * * @return Root level Outline object that should appear in the <body> */ public List getOutlines() { @@ -151,7 +154,7 @@ public class Opml extends WireFeed { /** * <ownerEmail> is a string, the email address of the owner of the document. - * + * * @param ownerEmail the email address of the owner of the document. */ public void setOwnerEmail(final String ownerEmail) { @@ -160,7 +163,7 @@ public class Opml extends WireFeed { /** * <ownerEmail> is a string, the email address of the owner of the document. - * + * * @return the email address of the owner of the document. */ public String getOwnerEmail() { @@ -170,7 +173,7 @@ public class Opml extends WireFeed { /** * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with * the author of the document via email or other means. - * + * * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the * document via email or other means. */ @@ -181,7 +184,7 @@ public class Opml extends WireFeed { /** * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with * the author of the document via email or other means. - * + * * @return http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the * document via email or other means. */ @@ -191,7 +194,7 @@ public class Opml extends WireFeed { /** * <ownerName> is a string, the owner of the document. - * + * * @param ownerName the owner of the document. */ public void setOwnerName(final String ownerName) { @@ -200,7 +203,7 @@ public class Opml extends WireFeed { /** * <ownerName> is a string, the owner of the document. - * + * * @return the owner of the document. */ public String getOwnerName() { @@ -209,7 +212,7 @@ public class Opml extends WireFeed { /** * <title> is the title of the document. - * + * * @param title title of the document. */ public void setTitle(final String title) { @@ -218,7 +221,7 @@ public class Opml extends WireFeed { /** * <title> is the title of the document. - * + * * @return title of the document. */ public String getTitle() { @@ -228,7 +231,7 @@ public class Opml extends WireFeed { /** * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the * expansion state already applied. - * + * * @param verticalScrollState which line of the outline is displayed on the top line of the window. */ public void setVerticalScrollState(final Integer verticalScrollState) { @@ -238,7 +241,7 @@ public class Opml extends WireFeed { /** * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the * expansion state already applied. - * + * * @return which line of the outline is displayed on the top line of the window. This number is calculated with the expansion state already applied. */ public Integer getVerticalScrollState() { @@ -247,7 +250,7 @@ public class Opml extends WireFeed { /** * <windowBottom> is a number, the pixel location of the bottom edge of the window. - * + * * @param windowBottom the pixel location of the bottom edge of the window. */ public void setWindowBottom(final Integer windowBottom) { @@ -256,7 +259,7 @@ public class Opml extends WireFeed { /** * <windowBottom> is a number, the pixel location of the bottom edge of the window. - * + * * @return the pixel location of the bottom edge of the window. */ public Integer getWindowBottom() { @@ -265,7 +268,7 @@ public class Opml extends WireFeed { /** * <windowLeft> is a number, the pixel location of the left edge of the window. - * + * * @param windowLeft the pixel location of the left edge of the window. */ public void setWindowLeft(final Integer windowLeft) { @@ -274,7 +277,7 @@ public class Opml extends WireFeed { /** * <windowLeft> is a number, the pixel location of the left edge of the window. - * + * * @return the pixel location of the left edge of the window. */ public Integer getWindowLeft() { @@ -283,7 +286,7 @@ public class Opml extends WireFeed { /** * <windowRight> is a number, the pixel location of the right edge of the window. - * + * * @param windowRight the pixel location of the right edge of the window. */ public void setWindowRight(final Integer windowRight) { @@ -292,7 +295,7 @@ public class Opml extends WireFeed { /** * <windowRight> is a number, the pixel location of the right edge of the window. - * + * * @return the pixel location of the right edge of the window. */ public Integer getWindowRight() { @@ -301,7 +304,7 @@ public class Opml extends WireFeed { /** * <windowTop> is a number, the pixel location of the top edge of the window. - * + * * @param windowTop the pixel location of the top edge of the window. */ public void setWindowTop(final Integer windowTop) { @@ -310,7 +313,7 @@ public class Opml extends WireFeed { /** * <windowTop> is a number, the pixel location of the top edge of the window. - * + * * @return the pixel location of the top edge of the window. */ public Integer getWindowTop() { diff --git a/src/main/java/com/sun/syndication/feed/opml/Outline.java b/src/main/java/com/sun/syndication/feed/opml/Outline.java index 3fbb0b7..f66aeda 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Outline.java +++ b/src/main/java/com/sun/syndication/feed/opml/Outline.java @@ -29,10 +29,13 @@ import com.sun.syndication.feed.impl.ToStringBean; /** * This class represents an OPML outline element. - * + * * @author Robert "kebernet" Cooper */ public class Outline implements Cloneable, Serializable { + + private static final long serialVersionUID = 1L; + private Date _created; private List _attributes; private List _categories; @@ -51,7 +54,7 @@ public class Outline implements Cloneable, Serializable { /** * Creates a new outline with the specified type and text values. - * + * * @param type type attribute value/ * @param text text attribute value */ @@ -63,7 +66,7 @@ public class Outline implements Cloneable, Serializable { /** * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for aggregator feed lists and will get a type of "rss". - * + * * @param title Title of the entry. * @param xmlUrl link to XML file. * @param htmlUrl link to html page. @@ -85,7 +88,7 @@ public class Outline implements Cloneable, Serializable { /** * List of attributes on this outline excluding the "common types" for the specification. - * + * * @param attributes List of attributes on this outline. */ public void setAttributes(final List attributes) { @@ -94,7 +97,7 @@ public class Outline implements Cloneable, Serializable { /** * List of attributes on this outline excluding the "common types" for the specification. - * + * * @return List of attributes on this outline. */ public List getAttributes() { @@ -108,7 +111,7 @@ 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. - * + * * @param breakpoint whether a breakpoint is set on this outline. */ public void setBreakpoint(final boolean breakpoint) { @@ -118,7 +121,7 @@ public class Outline implements Cloneable, Serializable { /** * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This attribute is mainly necessary for * outlines used to edit scripts. If it's not present, the value is false. - * + * * @return whether a breakpoint is set on this outline */ public boolean isBreakpoint() { @@ -127,7 +130,7 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) A List of Strings indicating values in the category attribute. - * + * * @param categories (OPML 2) A List of Strings indicating values in the category attribute. */ public void setCategories(final List categories) { @@ -136,7 +139,7 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) A List of Strings indicating values in the category attribute. - * + * * @return (OPML 2) A List of Strings indicating values in the category attribute. */ public List getCategories() { @@ -149,7 +152,7 @@ public class Outline implements Cloneable, Serializable { /** * A list of sub-outlines for this entry. - * + * * @param children A list of sub-outlines for this entry. */ public void setChildren(final List children) { @@ -158,7 +161,7 @@ public class Outline implements Cloneable, Serializable { /** * A list of sub-outlines for this entry. - * + * * @return A list of sub-outlines for this entry. */ public List getChildren() { @@ -172,7 +175,7 @@ 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. - * + * * @param comment whether the outline is commented */ public void setComment(final boolean comment) { @@ -182,7 +185,7 @@ public class Outline implements Cloneable, Serializable { /** * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By convention if an outline is commented, all * subordinate outlines are considered to also be commented. If it's not present, the value is false. - * + * * @return whether the outline is commented */ public boolean isComment() { @@ -191,7 +194,7 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) created is the date-time that the outline node was created. - * + * * @param created date-time that the outline node was created. */ public void setCreated(final Date created) { @@ -200,7 +203,7 @@ public class Outline implements Cloneable, Serializable { /** * (OPML 2) created is the date-time that the outline node was created. - * + * * @return date-time that the outline node was created. */ public Date getCreated() { @@ -209,7 +212,7 @@ public class Outline implements Cloneable, Serializable { /** * A convenience method to return the value of the url attribute. - * + * * @return value of the htmlUrl attribute. */ public String getUrl() { @@ -218,7 +221,7 @@ public class Outline implements Cloneable, Serializable { /** * A convenience method to return the value of the htmlUrl attribute. - * + * * @return value of the htmlUrl attribute. */ public String getHtmlUrl() { @@ -239,7 +242,7 @@ public class Outline implements Cloneable, Serializable { /** * The "text" attribute of the outline. - * + * * @param text The "text" attribute of the outline. */ public void setText(final String text) { @@ -248,7 +251,7 @@ public class Outline implements Cloneable, Serializable { /** * The "text" attribute of the outline. - * + * * @return The "text" attribute of the outline. */ public String getText() { @@ -257,7 +260,7 @@ public class Outline implements Cloneable, Serializable { /** * The "title" attribute of the outline. - * + * * @param title The "title" attribute of the outline. */ public void setTitle(final String title) { @@ -266,7 +269,7 @@ public class Outline implements Cloneable, Serializable { /** * The "title" attribute of the outline. - * + * * @return The "title" attribute of the outline. */ public String getTitle() { @@ -275,7 +278,7 @@ public class Outline implements Cloneable, Serializable { /** * The "type" attribute of the outline. - * + * * @param type The "type" attribute of the outline. */ public void setType(final String type) { @@ -284,7 +287,7 @@ public class Outline implements Cloneable, Serializable { /** * The "type" attribute of the outline. - * + * * @return The "type" attribute of the outline. */ public String getType() { @@ -293,7 +296,7 @@ public class Outline implements Cloneable, Serializable { /** * A convenience method to return the value of the xmlUrl attribute. - * + * * @return value of the xmlUrl attribute. */ public String getXmlUrl() { @@ -302,7 +305,7 @@ public class Outline implements Cloneable, Serializable { /** * Returns the value of an attribute on the outline or null. - * + * * @param name name of the attribute. */ public String getAttributeValue(final String name) { diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java index 41b40d8..099ce10 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -42,7 +42,7 @@ import com.sun.syndication.feed.synd.SyndPerson; import com.sun.syndication.feed.synd.SyndPersonImpl; /** - * + * * @author cooper */ public class ConverterForOPML10 implements Converter { @@ -71,7 +71,7 @@ public class ConverterForOPML10 implements Converter { *

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

- * + * * @param feed real feed to copy/convert. * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. */ @@ -190,10 +190,10 @@ public class ConverterForOPML10 implements Converter { /** * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. *

- * + * * @param syndFeed SyndFeedImpl to copy/convert value from. * @return a real feed with copied/converted values of the SyndFeedImpl. - * + * */ @Override public WireFeed createRealFeed(final SyndFeed syndFeed) { @@ -325,7 +325,7 @@ public class ConverterForOPML10 implements Converter { /** * Returns the type (version) of the real feed this converter handles. *

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

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

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

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

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

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

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

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

- * + * * @param document XML document (JDOM) to parse. * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED). * @return the resulting feed bean. @@ -102,10 +102,10 @@ public class OPML20Parser extends OPML10Parser { retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"), locale)); } - final List atts = retValue.getAttributes(); + final List atts = retValue.getAttributes(); for (int i = 0; i < atts.size(); i++) { - final Attribute a = (Attribute) atts.get(i); + final Attribute a = atts.get(i); if (a.getName().equals("created")) { retValue.getAttributes().remove(a); diff --git a/src/test/java/com/sun/syndication/TestXmlReader.java b/src/test/java/com/sun/syndication/TestXmlReader.java index 3b2d3af..23ec2e6 100644 --- a/src/test/java/com/sun/syndication/TestXmlReader.java +++ b/src/test/java/com/sun/syndication/TestXmlReader.java @@ -32,7 +32,7 @@ import com.sun.syndication.io.XmlReader; /** * @author pat, tucu - * + * */ public class TestXmlReader extends TestCase { @@ -44,17 +44,22 @@ public class TestXmlReader extends TestCase { } protected void _testRawNoBomValid(final String encoding) throws Exception { + InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); - XmlReader xmlReader = new XmlReader(is, false); + final XmlReader xmlReader = new XmlReader(is, false); assertEquals(xmlReader.getEncoding(), "UTF-8"); + xmlReader.close(); is = getXmlStream("no-bom", "xml-prolog", encoding, encoding); - xmlReader = new XmlReader(is); + final XmlReader xmlReader2 = new XmlReader(is); assertEquals(xmlReader.getEncoding(), "UTF-8"); + xmlReader2.close(); is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); - xmlReader = new XmlReader(is); + final XmlReader xmlReader3 = new XmlReader(is); assertEquals(xmlReader.getEncoding(), encoding); + xmlReader3.close(); + } protected void _testRawNoBomInvalid(final String encoding) throws Exception { @@ -62,6 +67,7 @@ public class TestXmlReader extends TestCase { try { final XmlReader xmlReader = new XmlReader(is, false); fail("It should have failed"); + xmlReader.close(); } catch (final IOException ex) { assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } @@ -81,6 +87,7 @@ public class TestXmlReader extends TestCase { } else { assertEquals(xmlReader.getEncoding().substring(0, encoding.length()), encoding); } + xmlReader.close(); } protected void _testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { @@ -88,6 +95,7 @@ public class TestXmlReader extends TestCase { try { final XmlReader xmlReader = new XmlReader(is, false); fail("It should have failed for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); + xmlReader.close(); } catch (final IOException ex) { assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } @@ -169,6 +177,7 @@ public class TestXmlReader extends TestCase { } else { assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); } + xmlReader.close(); } protected void _testHttpInvalid(final String cT, final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { @@ -176,6 +185,7 @@ public class TestXmlReader extends TestCase { try { final XmlReader xmlReader = new XmlReader(is, cT, false); fail("It should have failed for HTTP Content-type " + cT + ", BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc); + xmlReader.close(); } catch (final IOException ex) { assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1); } @@ -186,6 +196,7 @@ public class TestXmlReader extends TestCase { final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml-prolog" : "xml-prolog-encoding", streamEnc, prologEnc); final XmlReader xmlReader = new XmlReader(is, cT, true); assertEquals(xmlReader.getEncoding(), shouldbe); + xmlReader.close(); } // XML Stream generator @@ -195,7 +206,7 @@ public class TestXmlReader extends TestCase { private static final int[] UTF_16LE_BOM_BYTES = { 0xFF, 0XFE }; private static final int[] UTF_8_BOM_BYTES = { 0xEF, 0xBB, 0xBF }; - private static final Map BOMs = new HashMap(); + private static final Map BOMs = new HashMap(); static { BOMs.put("no-bom", NO_BOM_BYTES); @@ -211,7 +222,7 @@ public class TestXmlReader extends TestCase { private static final MessageFormat INFO = new MessageFormat("\nBOM : {0}\nDoc : {1}\nStream Enc : {2}\nProlog Enc : {3}\n"); - private static final Map XMLs = new HashMap(); + private static final Map XMLs = new HashMap(); static { XMLs.put("xml", XML); @@ -220,18 +231,18 @@ public class TestXmlReader extends TestCase { } /** - * + * * @param bomType no-bom, UTF-16BE-bom, UTF-16LE-bom, UTF-8-bom * @param xmlType xml, xml-prolog, xml-prolog-charset * @return XML stream */ protected InputStream getXmlStream(final String bomType, final String xmlType, final String streamEnc, final String prologEnc) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - int[] bom = (int[]) BOMs.get(bomType); + int[] bom = BOMs.get(bomType); if (bom == null) { bom = new int[0]; } - final MessageFormat xml = (MessageFormat) XMLs.get(xmlType); + final MessageFormat xml = XMLs.get(xmlType); for (final int element : bom) { baos.write(element); } From f8cc30630221a2ebb8297e3dc582635ba97729e8 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 16:59:47 +0200 Subject: [PATCH 21/47] Reverted changes (fixes build) --- src/test/java/com/sun/syndication/TestXmlReader.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/sun/syndication/TestXmlReader.java b/src/test/java/com/sun/syndication/TestXmlReader.java index 23ec2e6..2195e84 100644 --- a/src/test/java/com/sun/syndication/TestXmlReader.java +++ b/src/test/java/com/sun/syndication/TestXmlReader.java @@ -46,19 +46,16 @@ public class TestXmlReader extends TestCase { protected void _testRawNoBomValid(final String encoding) throws Exception { InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); - final XmlReader xmlReader = new XmlReader(is, false); + XmlReader xmlReader = new XmlReader(is, false); assertEquals(xmlReader.getEncoding(), "UTF-8"); - xmlReader.close(); is = getXmlStream("no-bom", "xml-prolog", encoding, encoding); - final XmlReader xmlReader2 = new XmlReader(is); + xmlReader = new XmlReader(is); assertEquals(xmlReader.getEncoding(), "UTF-8"); - xmlReader2.close(); is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); - final XmlReader xmlReader3 = new XmlReader(is); + xmlReader = new XmlReader(is); assertEquals(xmlReader.getEncoding(), encoding); - xmlReader3.close(); } From c217eca998f89f96831fb29a80dce8c545c65da4 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 12 Apr 2014 23:26:02 +0200 Subject: [PATCH 22/47] Refactored code Replaced deprecated SAXBuilder constructor call --- .../java/com/sun/syndication/FeedTest.java | 36 ++++++++++--------- .../com/sun/syndication/TestXmlReader.java | 5 ++- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/sun/syndication/FeedTest.java b/src/test/java/com/sun/syndication/FeedTest.java index 2f6032b..733afa6 100644 --- a/src/test/java/com/sun/syndication/FeedTest.java +++ b/src/test/java/com/sun/syndication/FeedTest.java @@ -8,6 +8,7 @@ import junit.framework.TestCase; import org.jdom2.Document; import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.XMLReaders; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; @@ -16,20 +17,21 @@ import com.sun.syndication.io.WireFeedInput; /** * @author pat, tucu - * + * */ public abstract class FeedTest extends TestCase { - private final String _feedFileName; - private Document _jDomDoc = null; - private WireFeed _wireFeed = null; - private SyndFeed _syndFeed = null; + + private final String fileName; + private Document jDomDoc = null; + private WireFeed wireFeed = null; + private SyndFeed syndFeed = null; protected FeedTest(final String feedFileName) { - _feedFileName = feedFileName; + fileName = feedFileName; } protected String getFeedFileName() { - return _feedFileName; + return fileName; } protected Reader getFeedReader() throws Exception { @@ -39,7 +41,7 @@ public abstract class FeedTest extends TestCase { } protected Document getJDomDoc() throws Exception { - final SAXBuilder saxBuilder = new SAXBuilder(false); + final SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING); return saxBuilder.build(getFeedReader()); } @@ -54,24 +56,24 @@ public abstract class FeedTest extends TestCase { } protected Document getCachedJDomDoc() throws Exception { - if (_jDomDoc == null) { - _jDomDoc = getJDomDoc(); + if (jDomDoc == null) { + jDomDoc = getJDomDoc(); } - return _jDomDoc; + return jDomDoc; } protected WireFeed getCachedWireFeed() throws Exception { - if (_wireFeed == null) { - _wireFeed = getWireFeed(); + if (wireFeed == null) { + wireFeed = getWireFeed(); } - return _wireFeed; + return wireFeed; } protected SyndFeed getCachedSyndFeed() throws Exception { - if (_syndFeed == null) { - _syndFeed = getSyndFeed(); + if (syndFeed == null) { + syndFeed = getSyndFeed(); } - return _syndFeed; + return syndFeed; } } diff --git a/src/test/java/com/sun/syndication/TestXmlReader.java b/src/test/java/com/sun/syndication/TestXmlReader.java index 2195e84..5621d1a 100644 --- a/src/test/java/com/sun/syndication/TestXmlReader.java +++ b/src/test/java/com/sun/syndication/TestXmlReader.java @@ -45,6 +45,8 @@ public class TestXmlReader extends TestCase { protected void _testRawNoBomValid(final String encoding) throws Exception { + // TODO review this test + InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); XmlReader xmlReader = new XmlReader(is, false); assertEquals(xmlReader.getEncoding(), "UTF-8"); @@ -170,7 +172,8 @@ public class TestXmlReader extends TestCase { final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml" : "xml-prolog-encoding", streamEnc, prologEnc); final XmlReader xmlReader = new XmlReader(is, cT, false); if (!streamEnc.equals("UTF-16")) { - // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection + // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for + // the chars used for detection } else { assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); } From 9918198dfcffa69a82d3f7cda3d1313b36708f52 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sun, 13 Apr 2014 20:29:45 +0200 Subject: [PATCH 23/47] Replaced Collection.size() > 0 through !Collection.isEmpty() --- .../com/sun/syndication/feed/synd/impl/ConverterForOPML10.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java index 15b2ccb..6bbcdc5 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -159,7 +159,7 @@ public class ConverterForOPML10 implements Converter { cat.setName(nodeName); entry.getCategories().add(cat); - if (context.size() > 0) { + if (!context.isEmpty()) { final Integer parent = context.peek(); final SyndCategory pcat = new TreeCategoryImpl(); pcat.setTaxonomyUri(URI_TREE); From 1c009f66bb98c818baaeeae7c6fd02f5e59ace70 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sun, 13 Apr 2014 20:39:28 +0200 Subject: [PATCH 24/47] Removed useless TODOs --- src/test/java/com/sun/syndication/SyndFeedTest.java | 8 +------- src/test/java/com/sun/syndication/TestXmlReader.java | 3 ++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/sun/syndication/SyndFeedTest.java b/src/test/java/com/sun/syndication/SyndFeedTest.java index 3a20b33..6020a8e 100644 --- a/src/test/java/com/sun/syndication/SyndFeedTest.java +++ b/src/test/java/com/sun/syndication/SyndFeedTest.java @@ -1,9 +1,3 @@ -/* - * Created on Jun 22, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ package com.sun.syndication; /** @@ -139,4 +133,4 @@ public abstract class SyndFeedTest extends FeedTest { super.tearDown(); } -} +} \ No newline at end of file diff --git a/src/test/java/com/sun/syndication/TestXmlReader.java b/src/test/java/com/sun/syndication/TestXmlReader.java index 5621d1a..14a334b 100644 --- a/src/test/java/com/sun/syndication/TestXmlReader.java +++ b/src/test/java/com/sun/syndication/TestXmlReader.java @@ -45,7 +45,8 @@ public class TestXmlReader extends TestCase { protected void _testRawNoBomValid(final String encoding) throws Exception { - // TODO review this test + // TODO review this test (XmlReader is never closed, test fails when using a new XmlReader + // for each Assert) InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); XmlReader xmlReader = new XmlReader(is, false); From ccc764b2b55d6c44026ba4a823d0ca6b61e96321 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 14 Apr 2014 19:15:34 +0200 Subject: [PATCH 25/47] Migrated logging to SLF4J --- pom.xml | 5 ++++ .../feed/synd/impl/ConverterForOPML10.java | 21 ++++++++++++----- .../sun/syndication/io/impl/OPML10Parser.java | 23 ++++++++++--------- src/test/resources/logback-test.xml | 13 +++++++++++ 4 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 src/test/resources/logback-test.xml diff --git a/pom.xml b/pom.xml index 60d6320..f634fd4 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ com.rometools rome + + ch.qos.logback + logback-classic + test + junit junit diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java index 6bbcdc5..073bbcf 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -22,7 +22,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Stack; -import java.util.logging.Logger; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.opml.Attribute; @@ -46,7 +48,9 @@ import com.sun.syndication.feed.synd.SyndPersonImpl; * @author cooper */ public class ConverterForOPML10 implements Converter { - private static final Logger LOG = Logger.getLogger(ConverterForOPML10.class.getName().toString()); + + private static final Logger LOG = LoggerFactory.getLogger(ConverterForOPML10.class); + public static final String URI_TREE = "urn:rome.tree"; public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; @@ -73,7 +77,8 @@ public class ConverterForOPML10 implements Converter { *

* * @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(final WireFeed feed, final SyndFeed syndFeed) { @@ -200,8 +205,12 @@ public class ConverterForOPML10 implements Converter { final List entries = Collections.synchronizedList(syndFeed.getEntries()); final HashMap entriesByNode = new HashMap(); - final ArrayList doAfterPass = new ArrayList(); // this will hold entries that we can't parent the first time. - final ArrayList root = new ArrayList(); // this holds root level outlines; + + // this will hold entries that we can't parent the first time. + final ArrayList doAfterPass = new ArrayList(); + + // this holds root level outlines; + final ArrayList root = new ArrayList(); for (int i = 0; i < entries.size(); i++) { final SyndEntry entry = entries.get(i); @@ -294,7 +303,7 @@ public class ConverterForOPML10 implements Converter { if (parent == null) { root.add(o.outline); - LOG.warning("Unable to find parent node :" + o.parent); + LOG.warn("Unable to find parent node: {}", o.parent); } else { parent.getChildren().add(o.outline); } diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java index 34b4a7f..a3ff729 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java @@ -21,11 +21,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; import org.jdom2.Document; import org.jdom2.Element; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.opml.Attribute; @@ -39,7 +39,8 @@ import com.sun.syndication.io.WireFeedParser; * @author Robert "kebernet" Cooper */ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { - private static Logger LOG = Logger.getLogger(OPML10Parser.class.getName()); + + private static Logger LOG = LoggerFactory.getLogger(OPML10Parser.class); /** Creates a new instance of Opml10Parser */ public OPML10Parser() { @@ -108,7 +109,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); } catch (final NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowBottom", nfe); + LOG.warn("Unable to parse windowBottom", nfe); if (validate) { throw new FeedException("Unable to parse windowBottom", nfe); @@ -118,13 +119,13 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); } catch (final NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); + LOG.warn("Unable to parse windowLeft", nfe); } try { opml.setWindowRight(readInteger(head.getChildText("windowRight"))); } catch (final NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowRight", nfe); + LOG.warn("Unable to parse windowRight", nfe); if (validate) { throw new FeedException("Unable to parse windowRight", nfe); @@ -134,7 +135,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); } catch (final NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowLeft", nfe); + LOG.warn("Unable to parse windowLeft", nfe); if (validate) { throw new FeedException("Unable to parse windowLeft", nfe); @@ -144,7 +145,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setWindowTop(readInteger(head.getChildText("windowTop"))); } catch (final NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse windowTop", nfe); + LOG.warn("Unable to parse windowTop", nfe); if (validate) { throw new FeedException("Unable to parse windowTop", nfe); @@ -154,7 +155,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); } catch (final NumberFormatException nfe) { - LOG.log(Level.WARNING, "Unable to parse expansionState", nfe); + LOG.warn("Unable to parse expansionState", nfe); if (validate) { throw new FeedException("Unable to parse expansionState", nfe); @@ -194,7 +195,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); } catch (final Exception ex) { - LOG.log(Level.WARNING, "Unable to parse isBreakpoint value", ex); + LOG.warn("Unable to parse isBreakpoint value", ex); if (validate) { throw new FeedException("Unable to parse isBreakpoint value", ex); @@ -204,7 +205,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { try { outline.setComment(readBoolean(e.getAttributeValue("isComment"))); } catch (final Exception ex) { - LOG.log(Level.WARNING, "Unable to parse isComment value", ex); + LOG.warn("Unable to parse isComment value", ex); if (validate) { throw new FeedException("Unable to parse isComment value", ex); diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000..44dea42 --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n + + + + + + + + \ No newline at end of file From cace53d3c231ab58762b7dc415af1521b41dc731 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Mon, 28 Apr 2014 17:48:36 +0200 Subject: [PATCH 26/47] Added snapshot repository --- pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pom.xml b/pom.xml index f634fd4..88e6cc2 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,19 @@ + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + From 6fc3c3ffe194c56a30fc89e6a7660256f1a768a7 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 29 Apr 2014 19:21:08 +0200 Subject: [PATCH 27/47] Moved classes into another package --- src/test/java/com/sun/syndication/TestOpsOPML10links.java | 5 ++--- src/test/java/{ => com/sun/syndication}/test/NullWriter.java | 2 +- src/test/java/{ => com/sun/syndication}/test/TestUtil.java | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) rename src/test/java/{ => com/sun/syndication}/test/NullWriter.java (86%) rename src/test/java/{ => com/sun/syndication}/test/TestUtil.java (84%) diff --git a/src/test/java/com/sun/syndication/TestOpsOPML10links.java b/src/test/java/com/sun/syndication/TestOpsOPML10links.java index 202a342..d74bc5a 100644 --- a/src/test/java/com/sun/syndication/TestOpsOPML10links.java +++ b/src/test/java/com/sun/syndication/TestOpsOPML10links.java @@ -12,14 +12,13 @@ package com.sun.syndication; import java.io.FileOutputStream; import java.io.PrintWriter; -import test.NullWriter; -import test.TestUtil; - import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; import com.sun.syndication.io.WireFeedInput; import com.sun.syndication.io.WireFeedOutput; +import com.sun.syndication.test.NullWriter; +import com.sun.syndication.test.TestUtil; /** * diff --git a/src/test/java/test/NullWriter.java b/src/test/java/com/sun/syndication/test/NullWriter.java similarity index 86% rename from src/test/java/test/NullWriter.java rename to src/test/java/com/sun/syndication/test/NullWriter.java index 4039735..c82eb05 100644 --- a/src/test/java/test/NullWriter.java +++ b/src/test/java/com/sun/syndication/test/NullWriter.java @@ -1,4 +1,4 @@ -package test; +package com.sun.syndication.test; import java.io.IOException; import java.io.Writer; diff --git a/src/test/java/test/TestUtil.java b/src/test/java/com/sun/syndication/test/TestUtil.java similarity index 84% rename from src/test/java/test/TestUtil.java rename to src/test/java/com/sun/syndication/test/TestUtil.java index d2b3842..bc63fe3 100644 --- a/src/test/java/test/TestUtil.java +++ b/src/test/java/com/sun/syndication/test/TestUtil.java @@ -1,4 +1,4 @@ -package test; +package com.sun.syndication.test; import java.io.InputStreamReader; import java.io.Reader; From c83d2b9ec1508af0d2be1cd01b0b12055e6cc53d Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Tue, 13 May 2014 19:28:37 +0200 Subject: [PATCH 28/47] Formatted and cleaned up sources --- .../sun/syndication/feed/opml/Attribute.java | 4 +- .../com/sun/syndication/feed/opml/Opml.java | 61 ++++--- .../sun/syndication/feed/opml/Outline.java | 23 ++- .../feed/synd/impl/ConverterForOPML10.java | 6 +- .../feed/synd/impl/ConverterForOPML20.java | 11 +- .../syndication/io/impl/OPML10Generator.java | 3 +- .../syndication/io/impl/OPML20Generator.java | 9 +- .../sun/syndication/io/impl/OPML20Parser.java | 2 +- .../java/com/sun/syndication/FeedOpsTest.java | 6 +- .../com/sun/syndication/SyndFeedTest.java | 172 +++++++++--------- .../com/sun/syndication/TestOpsOPML10.java | 2 +- .../sun/syndication/TestOpsOPML10links.java | 2 +- .../com/sun/syndication/TestOpsOPML20.java | 2 +- .../sun/syndication/TestXmlFixerReader.java | 2 +- 14 files changed, 162 insertions(+), 143 deletions(-) diff --git a/src/main/java/com/sun/syndication/feed/opml/Attribute.java b/src/main/java/com/sun/syndication/feed/opml/Attribute.java index 133a254..803ede7 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Attribute.java +++ b/src/main/java/com/sun/syndication/feed/opml/Attribute.java @@ -29,8 +29,8 @@ import com.sun.syndication.feed.impl.ToStringBean; */ public class Attribute implements Cloneable, Serializable { - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 1L; + private String _name; private String _value; diff --git a/src/main/java/com/sun/syndication/feed/opml/Opml.java b/src/main/java/com/sun/syndication/feed/opml/Opml.java index e574d5c..61aead0 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Opml.java +++ b/src/main/java/com/sun/syndication/feed/opml/Opml.java @@ -24,7 +24,8 @@ import java.util.List; import com.sun.syndication.feed.WireFeed; /** - * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in the <head> tag of the feed. + * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in + * the <head> tag of the feed. * * @author Robert "kebernet" Cooper */ @@ -71,8 +72,9 @@ public class Opml extends WireFeed { } /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML + * file. It's probably a pointer to this page for people + * who might stumble across the file on a web server 25 years from now and wonder what it is. * * @param docs http address of documentation for the format used */ @@ -81,8 +83,9 @@ public class Opml extends WireFeed { } /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a pointer to this page for people who might stumble across the file on a web server 25 years from now and wonder what it is. + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML + * file. It's probably a pointer to this page for people + * who might stumble across the file on a web server 25 years from now and wonder what it is. * * @return http address of documentation for the format used */ @@ -91,9 +94,10 @@ public class Opml extends WireFeed { } /** - * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The - * order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the - * list. + * <expansionState>is a comma-separated list of line numbers that are expanded. The line + * numbers in the list tell you which headlines to expand. The order is important. For each + * element in the list, X, starting at the first summit, navigate flatdown X times and expand. + * Repeat for each element in the list. * * @param expansionState int array containing expanded elements. */ @@ -102,9 +106,10 @@ public class Opml extends WireFeed { } /** - * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list tell you which headlines to expand. The - * order is important. For each element in the list, X, starting at the first summit, navigate flatdown X times and expand. Repeat for each element in the - * list. + * <expansionState> is a comma-separated list of line numbers that are expanded. The line + * numbers in the list tell you which headlines to expand. The order is important. For each + * element in the list, X, starting at the first summit, navigate flatdown X times and expand. + * Repeat for each element in the list. * * @return int array containing expanded elements. */ @@ -171,22 +176,26 @@ public class Opml extends WireFeed { } /** - * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with - * the author of the document via email or other means. + * (OPML 2) <ownerId> is the http address of a web page that contains an + * HTML a form that allows a human reader to communicate with the author of the + * document via email or other means. * - * @param ownerId http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the - * document via email or other means. + * @param ownerId http address of a web page that contains an HTML a form that + * allows a human reader to communicate with the author of the document via email or + * other means. */ public void setOwnerId(final String ownerId) { _ownerId = ownerId; } /** - * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that allows a human reader to communicate with - * the author of the document via email or other means. + * (OPML 2) <ownerId> is the http address of a web page that contains an + * HTML a form that allows a human reader to communicate with the author of the + * document via email or other means. * - * @return http address of a web page that contains an HTML a form that allows a human reader to communicate with the author of the - * document via email or other means. + * @return http address of a web page that contains an HTML a form that allows + * a human reader to communicate with the author of the document via email or other + * means. */ public String getOwnerId() { return _ownerId; @@ -229,20 +238,22 @@ public class Opml extends WireFeed { } /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the - * expansion state already applied. + * <vertScrollState> is a number, saying which line of the outline is displayed on the top + * line of the window. This number is calculated with the expansion state already applied. * - * @param verticalScrollState which line of the outline is displayed on the top line of the window. + * @param verticalScrollState which line of the outline is displayed on the top line of the + * window. */ public void setVerticalScrollState(final Integer verticalScrollState) { _verticalScrollState = verticalScrollState; } /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. This number is calculated with the - * expansion state already applied. + * <vertScrollState> is a number, saying which line of the outline is displayed on the top + * line of the window. This number is calculated with the expansion state already applied. * - * @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() { return _verticalScrollState; diff --git a/src/main/java/com/sun/syndication/feed/opml/Outline.java b/src/main/java/com/sun/syndication/feed/opml/Outline.java index 6d0f009..4985973 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Outline.java +++ b/src/main/java/com/sun/syndication/feed/opml/Outline.java @@ -66,7 +66,8 @@ public class Outline implements Cloneable, Serializable { } /** - * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for aggregator feed lists and will get a type of "rss". + * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for + * aggregator feed lists and will get a type of "rss". * * @param title Title of the entry. * @param xmlUrl link to XML file. @@ -110,8 +111,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. */ @@ -120,8 +122,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 */ @@ -174,8 +177,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 */ @@ -184,8 +188,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 */ diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java index 073bbcf..8e0c53c 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java @@ -205,12 +205,12 @@ public class ConverterForOPML10 implements Converter { final List entries = Collections.synchronizedList(syndFeed.getEntries()); final HashMap entriesByNode = new HashMap(); - + // this will hold entries that we can't parent the first time. - final ArrayList doAfterPass = new ArrayList(); + final ArrayList doAfterPass = new ArrayList(); // this holds root level outlines; - final ArrayList root = new ArrayList(); + final ArrayList root = new ArrayList(); for (int i = 0; i < entries.size(); i++) { final SyndEntry entry = entries.get(i); diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java index 414c87a..85ea090 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java @@ -12,7 +12,7 @@ import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.synd.SyndFeed; /** - * + * * @author cooper */ public class ConverterForOPML20 extends ConverterForOPML10 { @@ -24,7 +24,7 @@ public class ConverterForOPML20 extends ConverterForOPML10 { /** * Returns the type (version) of the real feed this converter handles. *

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

@@ -39,9 +39,10 @@ public class ConverterForOPML20 extends ConverterForOPML10 { *

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

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

- * + * * @param syndFeed SyndFeedImpl to copy/convert value from. * @return a real feed with copied/converted values of the SyndFeedImpl. */ diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java index 4ed5b07..d4f7f73 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java @@ -52,7 +52,8 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match + * with the type of the WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ @Override diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java index c88826e..b75eac9 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java @@ -19,7 +19,7 @@ import com.sun.syndication.feed.opml.Outline; import com.sun.syndication.io.FeedException; /** - * + * * @author cooper */ public class OPML20Generator extends OPML10Generator { @@ -30,7 +30,7 @@ public class OPML20Generator extends OPML10Generator { /** * Returns the type of feed the generator creates. *

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

@@ -43,10 +43,11 @@ public class OPML20Generator extends OPML10Generator { /** * Creates an XML document (JDOM) for the given feed bean. *

- * + * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the WireFeedGenerator. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match + * with the type of the WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ @Override diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java index 089f686..7de2bc5 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java @@ -54,7 +54,7 @@ public class OPML20Parser extends OPML10Parser { if (e.getName().equals("opml") && (e.getChild("head") != null && e.getChild("head").getChild("docs") != null || e.getAttributeValue("version") != null - && e.getAttributeValue("version").equals("2.0") || e.getChild("head") != null && e.getChild("head").getChild("ownerId") != null)) { + && e.getAttributeValue("version").equals("2.0") || e.getChild("head") != null && e.getChild("head").getChild("ownerId") != null)) { return true; } diff --git a/src/test/java/com/sun/syndication/FeedOpsTest.java b/src/test/java/com/sun/syndication/FeedOpsTest.java index 2e1ddb0..65cb058 100644 --- a/src/test/java/com/sun/syndication/FeedOpsTest.java +++ b/src/test/java/com/sun/syndication/FeedOpsTest.java @@ -11,11 +11,11 @@ import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; /** - * + * *

- * + * * @author Alejandro Abdelnur - * + * */ public abstract class FeedOpsTest extends FeedTest { diff --git a/src/test/java/com/sun/syndication/SyndFeedTest.java b/src/test/java/com/sun/syndication/SyndFeedTest.java index 6020a8e..19341f2 100644 --- a/src/test/java/com/sun/syndication/SyndFeedTest.java +++ b/src/test/java/com/sun/syndication/SyndFeedTest.java @@ -2,7 +2,7 @@ package com.sun.syndication; /** * @author pat - * + * */ public abstract class SyndFeedTest extends FeedTest { private String _prefix = null; @@ -29,100 +29,100 @@ public abstract class SyndFeedTest extends FeedTest { } /* - * public void testType() throws Exception { assertEquals(getPrefix(), getCachedSyndFeed().getFeedType()); } - * - * public void testTitle() throws Exception { assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); } - * - * public void testLink() throws Exception { assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); } - * - * public void testDescription() throws Exception { assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); } - * - * public void testLanguage() throws Exception { assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); } - * - * public void testCategories() throws Exception { List catlist = getCachedSyndFeed().getCategories(); //don't understand why this one fails assertEquals(2, - * catlist.size()); SyndCategory cat = (SyndCategory)catlist.get(0); assertEqualsStr("channel.category[0]", cat.getName()); - * assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); cat = (SyndCategory)catlist.get(1); assertEqualsStr("channel.category[1]", - * cat.getName()); assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); } - * - * public void testPublishedDate() throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), - * getCachedSyndFeed().getPublishedDate()); } - * - * //how do i get height and width? public void testImage() throws Exception { SyndImage img = getCachedSyndFeed().getImage(); - * assertEqualsStr("channel.image.description", img.getDescription()); assertEqualsStr("channel.image.link", img.getLink()); - * assertEqualsStr("channel.image.title", img.getTitle()); assertEqualsStr("channel.image.url", img.getUrl()); } - * - * public void testEntries() throws Exception { List entrylist = getCachedSyndFeed().getEntries(); assertEquals(2, entrylist.size()); } - * - * public void testEntryTitle() throws Exception { assertEqualsStr("channel.item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); - * assertEqualsStr("channel.item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); } - * - * public String getEntryTitle(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getTitle(); } - * - * public void testEntryDescription() throws Exception { assertEqualsStr("channel.item[0].description", - * getEntryDescription(getCachedSyndFeed().getEntries().get(0))); assertEqualsStr("channel.item[1].description", - * getEntryDescription(getCachedSyndFeed().getEntries().get(1))); } - * - * public String getEntryDescription(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getDescription().getValue(); } - * - * public void testEntryLink() throws Exception { assertEqualsStr("channel.item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); - * assertEqualsStr("channel.item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); } - * - * public String getEntryLink(Object o) { SyndEntry e = (SyndEntry) o; return e.getLink(); } - * - * public void testEntryPublishedDate() throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), - * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), - * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); } - * - * public Date getEntryPublishedDate(Object o) { SyndEntry e = (SyndEntry) o; return e.getPublishedDate(); } - * - * public void testEntryCategories() throws Exception { SyndEntry e = (SyndEntry)getCachedSyndFeed().getEntries().get(0); List catlist = e.getCategories(); - * //don't understand why this one fails assertEquals(2, catlist.size()); SyndCategory cat = (SyndCategory)catlist.get(0); - * assertEqualsStr("channel.item[0].category[0]", cat.getName()); assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); cat = - * (SyndCategory)catlist.get(1); assertEqualsStr("channel.item[0].category[1]", cat.getName()); assertEqualsStr("channel.item[0].category[1]^domain", - * cat.getTaxonomyUri()); //DO 2nd set of items } - * - * public void testEntryAuthor() throws Exception { assertEqualsStr("channel.item[0].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); - * assertEqualsStr("channel.item[1].author", getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); } - * - * public String getEntryAuthor(Object o) { SyndEntry e = (SyndEntry) o; return e.getAuthor(); } + * public void testType() throws Exception { assertEquals(getPrefix(), + * getCachedSyndFeed().getFeedType()); } public void testTitle() throws Exception { + * assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); } public void testLink() + * throws Exception { assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); } public + * void testDescription() throws Exception { assertEqualsStr("channel.description", + * getCachedSyndFeed().getDescription()); } public void testLanguage() throws Exception { + * assertEqualsStr("channel.language", getCachedSyndFeed().getLanguage()); } public void + * testCategories() throws Exception { List catlist = getCachedSyndFeed().getCategories(); + * //don't understand why this one fails assertEquals(2, catlist.size()); SyndCategory cat = + * (SyndCategory)catlist.get(0); assertEqualsStr("channel.category[0]", cat.getName()); + * assertEqualsStr("channel.category[0]^domain", cat.getTaxonomyUri()); cat = + * (SyndCategory)catlist.get(1); assertEqualsStr("channel.category[1]", cat.getName()); + * assertEqualsStr("channel.category[1]^domain", cat.getTaxonomyUri()); } public void + * testPublishedDate() throws Exception { + * assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getCachedSyndFeed().getPublishedDate()); } //how do i get height and width? public void + * testImage() throws Exception { SyndImage img = getCachedSyndFeed().getImage(); + * assertEqualsStr("channel.image.description", img.getDescription()); + * assertEqualsStr("channel.image.link", img.getLink()); assertEqualsStr("channel.image.title", + * img.getTitle()); assertEqualsStr("channel.image.url", img.getUrl()); } public void + * testEntries() throws Exception { List entrylist = getCachedSyndFeed().getEntries(); + * assertEquals(2, entrylist.size()); } public void testEntryTitle() throws Exception { + * assertEqualsStr("channel.item[0].title", + * getEntryTitle(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].title", + * getEntryTitle(getCachedSyndFeed().getEntries().get(1))); } public String getEntryTitle(Object + * o) throws Exception { SyndEntry e = (SyndEntry) o; return e.getTitle(); } public void + * testEntryDescription() throws Exception { assertEqualsStr("channel.item[0].description", + * getEntryDescription(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].description", + * getEntryDescription(getCachedSyndFeed().getEntries().get(1))); } public String + * getEntryDescription(Object o) throws Exception { SyndEntry e = (SyndEntry) o; return + * e.getDescription().getValue(); } public void testEntryLink() throws Exception { + * assertEqualsStr("channel.item[0].link", + * getEntryLink(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].link", + * getEntryLink(getCachedSyndFeed().getEntries().get(1))); } public String getEntryLink(Object + * o) { SyndEntry e = (SyndEntry) o; return e.getLink(); } public void testEntryPublishedDate() + * throws Exception { assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); + * assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + * getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); } public Date + * getEntryPublishedDate(Object o) { SyndEntry e = (SyndEntry) o; return e.getPublishedDate(); } + * public void testEntryCategories() throws Exception { SyndEntry e = + * (SyndEntry)getCachedSyndFeed().getEntries().get(0); List catlist = e.getCategories(); //don't + * understand why this one fails assertEquals(2, catlist.size()); SyndCategory cat = + * (SyndCategory)catlist.get(0); assertEqualsStr("channel.item[0].category[0]", cat.getName()); + * assertEqualsStr("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); cat = + * (SyndCategory)catlist.get(1); assertEqualsStr("channel.item[0].category[1]", cat.getName()); + * assertEqualsStr("channel.item[0].category[1]^domain", cat.getTaxonomyUri()); //DO 2nd set of + * items } public void testEntryAuthor() throws Exception { + * assertEqualsStr("channel.item[0].author", + * getEntryAuthor(getCachedSyndFeed().getEntries().get(0))); + * assertEqualsStr("channel.item[1].author", + * getEntryAuthor(getCachedSyndFeed().getEntries().get(1))); } public String + * getEntryAuthor(Object o) { SyndEntry e = (SyndEntry) o; return e.getAuthor(); } */ /* - * //things you cannot get from SyndEntryImpl // item[0].source // // item0.category0 item0.category1 - * Thu, 08 Jul 1999 08:00:00 GMT Thu, 08 Jul 1999 09:00:00 GMT item0.author - * http://localhost:8080/item0/comments http://localhost:8080/item0/guid //TODO: I still have the - * elements to test + * //things you cannot get from SyndEntryImpl // item[0].source // // + * + * item0.category0 item0.category1 Thu, 08 Jul 1999 08:00:00 + * GMT Thu, 08 Jul 1999 09:00:00 GMT + * item0.author http://localhost:8080/item0/comments http://localhost:8080/item0/guid //TODO: I still have the elements + * to test */ /* - * public void test() { assertEqualsStr(feed, ""); } - * - * public void test() { assertEqualsStr(feed, ""); } + * public void test() { assertEqualsStr(feed, ""); } public void test() { assertEqualsStr(feed, + * ""); } */ // Things that you cannot get form a SyndFeedImpl today // these need to be put in a RSS 2.0 module // or is a roundtrip to wirefeed the right way to do this? /* - * Search Search this site: q http://example.org/mt/mt-search.cgi - * - * - * image height and width - * - * //Copyright 2004, Mark Pilgrim public void test() { assertEqualsStr(getCachedSyndFeed()., ""); } - * - * //Sample Toolkit public void test() { assertEqualsStr(feed, ""); } - * - * // editor@example.org public void test() { assertEqualsStr(feed, ""); } - * - * // webmaster@example.org public void test() { assertEqualsStr(feed, ""); } - * - * http://blogs.law.harvard.edu/tech/rss - * 60 - * - * 0 1 2 3 4 5 6 7 8 - * 9.5 10 11 12 13 14 15 16 17 - * 18 19 20 21 22 23 Monday - * Tuesday Wednesday Thursday Friday Saturday Sunday + * Search Search this site: q + * http://example.org/mt/mt-search.cgi image height and width + * //Copyright 2004, Mark Pilgrim public void test() { + * assertEqualsStr(getCachedSyndFeed()., ""); } //Sample Toolkit public + * void test() { assertEqualsStr(feed, ""); } // + * editor@example.org public void test() { + * assertEqualsStr(feed, ""); } // webmaster@example.org public void + * test() { assertEqualsStr(feed, ""); } http://blogs.law.harvard.edu/tech/rss + * 60 0 1 + * 2 3 4 5 6 7 + * 8 9.5 10 11 12 + * 13 14 15 16 17 + * 18 19 20 21 22 + * 23 Monday Tuesday + * Wednesday Thursday Friday Saturday + * Sunday */ /* diff --git a/src/test/java/com/sun/syndication/TestOpsOPML10.java b/src/test/java/com/sun/syndication/TestOpsOPML10.java index 7c4691d..6f20c42 100644 --- a/src/test/java/com/sun/syndication/TestOpsOPML10.java +++ b/src/test/java/com/sun/syndication/TestOpsOPML10.java @@ -17,7 +17,7 @@ import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; /** - * + * * @author cooper */ public class TestOpsOPML10 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/TestOpsOPML10links.java b/src/test/java/com/sun/syndication/TestOpsOPML10links.java index d74bc5a..2b319ce 100644 --- a/src/test/java/com/sun/syndication/TestOpsOPML10links.java +++ b/src/test/java/com/sun/syndication/TestOpsOPML10links.java @@ -21,7 +21,7 @@ import com.sun.syndication.test.NullWriter; import com.sun.syndication.test.TestUtil; /** - * + * * @author cooper */ public class TestOpsOPML10links extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/TestOpsOPML20.java b/src/test/java/com/sun/syndication/TestOpsOPML20.java index cd219cb..1ce1f98 100644 --- a/src/test/java/com/sun/syndication/TestOpsOPML20.java +++ b/src/test/java/com/sun/syndication/TestOpsOPML20.java @@ -17,7 +17,7 @@ import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; /** - * + * * @author cooper */ public class TestOpsOPML20 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/TestXmlFixerReader.java b/src/test/java/com/sun/syndication/TestXmlFixerReader.java index c44a910..745962f 100644 --- a/src/test/java/com/sun/syndication/TestXmlFixerReader.java +++ b/src/test/java/com/sun/syndication/TestXmlFixerReader.java @@ -33,7 +33,7 @@ import com.sun.syndication.io.impl.XmlFixerReader; /** * @author pat, tucu - * + * */ public class TestXmlFixerReader extends TestCase { private static final String XML_PROLOG = ""; From c70578ff7c7f41db7e840132047cf7e778e25143 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 30 May 2014 16:31:37 +0200 Subject: [PATCH 29/47] Renamed and harmonized packages --- .../opml}/feed/opml/Attribute.java | 6 ++-- .../opml}/feed/opml/Opml.java | 4 +-- .../opml}/feed/opml/Outline.java | 8 ++--- .../opml}/feed/opml/package.html | 0 .../feed/synd/impl/ConverterForOPML10.java | 34 +++++++++---------- .../feed/synd/impl/ConverterForOPML20.java | 6 ++-- .../feed/synd/impl/TreeCategoryImpl.java | 6 ++-- .../opml}/feed/synd/impl/package.html | 0 .../opml}/io/impl/OPML10Generator.java | 16 +++++---- .../opml}/io/impl/OPML10Parser.java | 16 +++++---- .../opml}/io/impl/OPML20Generator.java | 11 +++--- .../opml}/io/impl/OPML20Parser.java | 13 +++---- .../opml}/io/impl/package.html | 0 src/main/resources/rome.properties | 12 +++---- .../opml}/FeedOpsTest.java | 8 ++--- .../opml}/FeedTest.java | 10 +++--- .../opml}/SyndFeedTest.java | 2 +- .../opml}/TestOpsOPML10.java | 8 ++--- .../opml}/TestOpsOPML10links.java | 16 ++++----- .../opml}/TestOpsOPML20.java | 8 ++--- .../opml}/TestXmlFixerReader.java | 6 ++-- .../opml}/TestXmlReader.java | 4 +-- .../opml}/test/NullWriter.java | 2 +- .../opml}/test/TestUtil.java | 2 +- 24 files changed, 102 insertions(+), 96 deletions(-) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/opml/Attribute.java (95%) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/opml/Opml.java (99%) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/opml/Outline.java (98%) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/opml/package.html (100%) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/synd/impl/ConverterForOPML10.java (93%) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/synd/impl/ConverterForOPML20.java (92%) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/synd/impl/TreeCategoryImpl.java (82%) rename src/main/java/com/{sun/syndication => rometools/opml}/feed/synd/impl/package.html (100%) rename src/main/java/com/{sun/syndication => rometools/opml}/io/impl/OPML10Generator.java (93%) rename src/main/java/com/{sun/syndication => rometools/opml}/io/impl/OPML10Parser.java (95%) rename src/main/java/com/{sun/syndication => rometools/opml}/io/impl/OPML20Generator.java (89%) rename src/main/java/com/{sun/syndication => rometools/opml}/io/impl/OPML20Parser.java (92%) rename src/main/java/com/{sun/syndication => rometools/opml}/io/impl/package.html (100%) rename src/test/java/com/{sun/syndication => rometools/opml}/FeedOpsTest.java (95%) rename src/test/java/com/{sun/syndication => rometools/opml}/FeedTest.java (90%) rename src/test/java/com/{sun/syndication => rometools/opml}/SyndFeedTest.java (99%) rename src/test/java/com/{sun/syndication => rometools/opml}/TestOpsOPML10.java (85%) rename src/test/java/com/{sun/syndication => rometools/opml}/TestOpsOPML10links.java (82%) rename src/test/java/com/{sun/syndication => rometools/opml}/TestOpsOPML20.java (85%) rename src/test/java/com/{sun/syndication => rometools/opml}/TestXmlFixerReader.java (97%) rename src/test/java/com/{sun/syndication => rometools/opml}/TestXmlReader.java (99%) rename src/test/java/com/{sun/syndication => rometools/opml}/test/NullWriter.java (86%) rename src/test/java/com/{sun/syndication => rometools/opml}/test/TestUtil.java (84%) diff --git a/src/main/java/com/sun/syndication/feed/opml/Attribute.java b/src/main/java/com/rometools/opml/feed/opml/Attribute.java similarity index 95% rename from src/main/java/com/sun/syndication/feed/opml/Attribute.java rename to src/main/java/com/rometools/opml/feed/opml/Attribute.java index 803ede7..5934d75 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Attribute.java +++ b/src/main/java/com/rometools/opml/feed/opml/Attribute.java @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.sun.syndication.feed.opml; +package com.rometools.opml.feed.opml; import java.io.Serializable; -import com.sun.syndication.feed.impl.EqualsBean; -import com.sun.syndication.feed.impl.ToStringBean; +import com.rometools.rome.feed.impl.EqualsBean; +import com.rometools.rome.feed.impl.ToStringBean; /** * This is a simple name-value pair attribute for outlines. diff --git a/src/main/java/com/sun/syndication/feed/opml/Opml.java b/src/main/java/com/rometools/opml/feed/opml/Opml.java similarity index 99% rename from src/main/java/com/sun/syndication/feed/opml/Opml.java rename to src/main/java/com/rometools/opml/feed/opml/Opml.java index 61aead0..da17604 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Opml.java +++ b/src/main/java/com/rometools/opml/feed/opml/Opml.java @@ -15,13 +15,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.sun.syndication.feed.opml; +package com.rometools.opml.feed.opml; import java.util.ArrayList; import java.util.Date; import java.util.List; -import com.sun.syndication.feed.WireFeed; +import com.rometools.rome.feed.WireFeed; /** * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in diff --git a/src/main/java/com/sun/syndication/feed/opml/Outline.java b/src/main/java/com/rometools/opml/feed/opml/Outline.java similarity index 98% rename from src/main/java/com/sun/syndication/feed/opml/Outline.java rename to src/main/java/com/rometools/opml/feed/opml/Outline.java index 4985973..14e988d 100644 --- a/src/main/java/com/sun/syndication/feed/opml/Outline.java +++ b/src/main/java/com/rometools/opml/feed/opml/Outline.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.sun.syndication.feed.opml; +package com.rometools.opml.feed.opml; import java.io.Serializable; import java.net.URL; @@ -24,9 +24,9 @@ import java.util.Collections; import java.util.Date; import java.util.List; -import com.sun.syndication.feed.impl.EqualsBean; -import com.sun.syndication.feed.impl.ToStringBean; -import com.sun.syndication.feed.module.Module; +import com.rometools.rome.feed.impl.EqualsBean; +import com.rometools.rome.feed.impl.ToStringBean; +import com.rometools.rome.feed.module.Module; /** * This class represents an OPML outline element. diff --git a/src/main/java/com/sun/syndication/feed/opml/package.html b/src/main/java/com/rometools/opml/feed/opml/package.html similarity index 100% rename from src/main/java/com/sun/syndication/feed/opml/package.html rename to src/main/java/com/rometools/opml/feed/opml/package.html diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML10.java similarity index 93% rename from src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java rename to src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML10.java index 8e0c53c..28c8020 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML10.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.sun.syndication.feed.synd.impl; +package com.rometools.opml.feed.synd.impl; import java.util.ArrayList; import java.util.Collections; @@ -26,22 +26,22 @@ import java.util.Stack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.feed.synd.Converter; -import com.sun.syndication.feed.synd.SyndCategory; -import com.sun.syndication.feed.synd.SyndCategoryImpl; -import com.sun.syndication.feed.synd.SyndContent; -import com.sun.syndication.feed.synd.SyndContentImpl; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndEntryImpl; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndLink; -import com.sun.syndication.feed.synd.SyndLinkImpl; -import com.sun.syndication.feed.synd.SyndPerson; -import com.sun.syndication.feed.synd.SyndPersonImpl; +import com.rometools.opml.feed.opml.Attribute; +import com.rometools.opml.feed.opml.Opml; +import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.Converter; +import com.rometools.rome.feed.synd.SyndCategory; +import com.rometools.rome.feed.synd.SyndCategoryImpl; +import com.rometools.rome.feed.synd.SyndContent; +import com.rometools.rome.feed.synd.SyndContentImpl; +import com.rometools.rome.feed.synd.SyndEntry; +import com.rometools.rome.feed.synd.SyndEntryImpl; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndLink; +import com.rometools.rome.feed.synd.SyndLinkImpl; +import com.rometools.rome.feed.synd.SyndPerson; +import com.rometools.rome.feed.synd.SyndPersonImpl; /** * diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML20.java similarity index 92% rename from src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java rename to src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML20.java index 85ea090..b467b46 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForOPML20.java +++ b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML20.java @@ -6,10 +6,10 @@ * To change this template, choose Tools | Template Manager * and open the template in the editor. */ -package com.sun.syndication.feed.synd.impl; +package com.rometools.opml.feed.synd.impl; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.SyndFeed; /** * diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/com/rometools/opml/feed/synd/impl/TreeCategoryImpl.java similarity index 82% rename from src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java rename to src/main/java/com/rometools/opml/feed/synd/impl/TreeCategoryImpl.java index 60d8203..c3c8e18 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/TreeCategoryImpl.java +++ b/src/main/java/com/rometools/opml/feed/synd/impl/TreeCategoryImpl.java @@ -7,10 +7,10 @@ * and open the template in the editor. */ -package com.sun.syndication.feed.synd.impl; +package com.rometools.opml.feed.synd.impl; -import com.sun.syndication.feed.synd.SyndCategory; -import com.sun.syndication.feed.synd.SyndCategoryImpl; +import com.rometools.rome.feed.synd.SyndCategory; +import com.rometools.rome.feed.synd.SyndCategoryImpl; /** * diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/package.html b/src/main/java/com/rometools/opml/feed/synd/impl/package.html similarity index 100% rename from src/main/java/com/sun/syndication/feed/synd/impl/package.html rename to src/main/java/com/rometools/opml/feed/synd/impl/package.html diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java similarity index 93% rename from src/main/java/com/sun/syndication/io/impl/OPML10Generator.java rename to src/main/java/com/rometools/opml/io/impl/OPML10Generator.java index d4f7f73..707b4c5 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.sun.syndication.io.impl; +package com.rometools.opml.io.impl; import java.util.ArrayList; import java.util.Collections; @@ -25,12 +25,14 @@ import java.util.Locale; import org.jdom2.Document; import org.jdom2.Element; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.WireFeedGenerator; +import com.rometools.opml.feed.opml.Attribute; +import com.rometools.opml.feed.opml.Opml; +import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.WireFeedGenerator; +import com.rometools.rome.io.impl.BaseWireFeedGenerator; +import com.rometools.rome.io.impl.DateParser; /** * diff --git a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java similarity index 95% rename from src/main/java/com/sun/syndication/io/impl/OPML10Parser.java rename to src/main/java/com/rometools/opml/io/impl/OPML10Parser.java index a3ff729..7d4f7d6 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML10Parser.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.sun.syndication.io.impl; +package com.rometools.opml.io.impl; import java.util.ArrayList; import java.util.List; @@ -27,12 +27,14 @@ import org.jdom2.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.WireFeedParser; +import com.rometools.opml.feed.opml.Attribute; +import com.rometools.opml.feed.opml.Opml; +import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.WireFeedParser; +import com.rometools.rome.io.impl.BaseWireFeedParser; +import com.rometools.rome.io.impl.DateParser; /** * diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java similarity index 89% rename from src/main/java/com/sun/syndication/io/impl/OPML20Generator.java rename to src/main/java/com/rometools/opml/io/impl/OPML20Generator.java index b75eac9..68dacb9 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java @@ -6,17 +6,18 @@ * To change this template, choose Tools | Template Manager * and open the template in the editor. */ -package com.sun.syndication.io.impl; +package com.rometools.opml.io.impl; import java.util.Locale; import org.jdom2.Document; import org.jdom2.Element; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; +import com.rometools.opml.feed.opml.Opml; +import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.impl.DateParser; /** * diff --git a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java b/src/main/java/com/rometools/opml/io/impl/OPML20Parser.java similarity index 92% rename from src/main/java/com/sun/syndication/io/impl/OPML20Parser.java rename to src/main/java/com/rometools/opml/io/impl/OPML20Parser.java index 7de2bc5..fa56857 100644 --- a/src/main/java/com/sun/syndication/io/impl/OPML20Parser.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Parser.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.sun.syndication.io.impl; +package com.rometools.opml.io.impl; import java.util.List; import java.util.Locale; @@ -23,11 +23,12 @@ import java.util.Locale; import org.jdom2.Document; import org.jdom2.Element; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.opml.Attribute; -import com.sun.syndication.feed.opml.Opml; -import com.sun.syndication.feed.opml.Outline; -import com.sun.syndication.io.FeedException; +import com.rometools.opml.feed.opml.Attribute; +import com.rometools.opml.feed.opml.Opml; +import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.impl.DateParser; /** * diff --git a/src/main/java/com/sun/syndication/io/impl/package.html b/src/main/java/com/rometools/opml/io/impl/package.html similarity index 100% rename from src/main/java/com/sun/syndication/io/impl/package.html rename to src/main/java/com/rometools/opml/io/impl/package.html diff --git a/src/main/resources/rome.properties b/src/main/resources/rome.properties index fe2c0f2..151f949 100644 --- a/src/main/resources/rome.properties +++ b/src/main/resources/rome.properties @@ -12,11 +12,11 @@ # -WireFeedGenerator.classes=com.sun.syndication.io.impl.OPML10Generator \ - com.sun.syndication.io.impl.OPML20Generator +WireFeedGenerator.classes=com.rometools.rome.io.impl.OPML10Generator \ + com.rometools.rome.io.impl.OPML20Generator -WireFeedParser.classes=com.sun.syndication.io.impl.OPML10Parser \ - com.sun.syndication.io.impl.OPML20Parser +WireFeedParser.classes=com.rometools.rome.io.impl.OPML10Parser \ + com.rometools.rome.io.impl.OPML20Parser -Converter.classes=com.sun.syndication.feed.synd.impl.ConverterForOPML10 \ - com.sun.syndication.feed.synd.impl.ConverterForOPML20 +Converter.classes=com.rometools.rome.feed.synd.impl.ConverterForOPML10 \ + com.rometools.rome.feed.synd.impl.ConverterForOPML20 diff --git a/src/test/java/com/sun/syndication/FeedOpsTest.java b/src/test/java/com/rometools/opml/FeedOpsTest.java similarity index 95% rename from src/test/java/com/sun/syndication/FeedOpsTest.java rename to src/test/java/com/rometools/opml/FeedOpsTest.java index 65cb058..122bc1d 100644 --- a/src/test/java/com/sun/syndication/FeedOpsTest.java +++ b/src/test/java/com/rometools/opml/FeedOpsTest.java @@ -1,4 +1,4 @@ -package com.sun.syndication; +package com.rometools.opml; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -6,9 +6,9 @@ import java.io.File; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndFeedImpl; /** * diff --git a/src/test/java/com/sun/syndication/FeedTest.java b/src/test/java/com/rometools/opml/FeedTest.java similarity index 90% rename from src/test/java/com/sun/syndication/FeedTest.java rename to src/test/java/com/rometools/opml/FeedTest.java index 733afa6..a2919e9 100644 --- a/src/test/java/com/sun/syndication/FeedTest.java +++ b/src/test/java/com/rometools/opml/FeedTest.java @@ -1,4 +1,4 @@ -package com.sun.syndication; +package com.rometools.opml; import java.io.InputStream; import java.io.InputStreamReader; @@ -10,10 +10,10 @@ import org.jdom2.Document; import org.jdom2.input.SAXBuilder; import org.jdom2.input.sax.XMLReaders; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.io.SyndFeedInput; -import com.sun.syndication.io.WireFeedInput; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.io.SyndFeedInput; +import com.rometools.rome.io.WireFeedInput; /** * @author pat, tucu diff --git a/src/test/java/com/sun/syndication/SyndFeedTest.java b/src/test/java/com/rometools/opml/SyndFeedTest.java similarity index 99% rename from src/test/java/com/sun/syndication/SyndFeedTest.java rename to src/test/java/com/rometools/opml/SyndFeedTest.java index 19341f2..09bc640 100644 --- a/src/test/java/com/sun/syndication/SyndFeedTest.java +++ b/src/test/java/com/rometools/opml/SyndFeedTest.java @@ -1,4 +1,4 @@ -package com.sun.syndication; +package com.rometools.opml; /** * @author pat diff --git a/src/test/java/com/sun/syndication/TestOpsOPML10.java b/src/test/java/com/rometools/opml/TestOpsOPML10.java similarity index 85% rename from src/test/java/com/sun/syndication/TestOpsOPML10.java rename to src/test/java/com/rometools/opml/TestOpsOPML10.java index 6f20c42..7f78a80 100644 --- a/src/test/java/com/sun/syndication/TestOpsOPML10.java +++ b/src/test/java/com/rometools/opml/TestOpsOPML10.java @@ -7,14 +7,14 @@ * and open the template in the editor. */ -package com.sun.syndication; +package com.rometools.opml; import java.io.FileOutputStream; import java.io.PrintWriter; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndFeedImpl; /** * diff --git a/src/test/java/com/sun/syndication/TestOpsOPML10links.java b/src/test/java/com/rometools/opml/TestOpsOPML10links.java similarity index 82% rename from src/test/java/com/sun/syndication/TestOpsOPML10links.java rename to src/test/java/com/rometools/opml/TestOpsOPML10links.java index 2b319ce..33c6216 100644 --- a/src/test/java/com/sun/syndication/TestOpsOPML10links.java +++ b/src/test/java/com/rometools/opml/TestOpsOPML10links.java @@ -7,18 +7,18 @@ * and open the template in the editor. */ -package com.sun.syndication; +package com.rometools.opml; import java.io.FileOutputStream; import java.io.PrintWriter; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import com.sun.syndication.io.WireFeedInput; -import com.sun.syndication.io.WireFeedOutput; -import com.sun.syndication.test.NullWriter; -import com.sun.syndication.test.TestUtil; +import com.rometools.opml.test.NullWriter; +import com.rometools.opml.test.TestUtil; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndFeedImpl; +import com.rometools.rome.io.WireFeedInput; +import com.rometools.rome.io.WireFeedOutput; /** * diff --git a/src/test/java/com/sun/syndication/TestOpsOPML20.java b/src/test/java/com/rometools/opml/TestOpsOPML20.java similarity index 85% rename from src/test/java/com/sun/syndication/TestOpsOPML20.java rename to src/test/java/com/rometools/opml/TestOpsOPML20.java index 1ce1f98..32f8348 100644 --- a/src/test/java/com/sun/syndication/TestOpsOPML20.java +++ b/src/test/java/com/rometools/opml/TestOpsOPML20.java @@ -7,14 +7,14 @@ * and open the template in the editor. */ -package com.sun.syndication; +package com.rometools.opml; import java.io.FileOutputStream; import java.io.PrintWriter; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndFeedImpl; /** * diff --git a/src/test/java/com/sun/syndication/TestXmlFixerReader.java b/src/test/java/com/rometools/opml/TestXmlFixerReader.java similarity index 97% rename from src/test/java/com/sun/syndication/TestXmlFixerReader.java rename to src/test/java/com/rometools/opml/TestXmlFixerReader.java index 745962f..eea78af 100644 --- a/src/test/java/com/sun/syndication/TestXmlFixerReader.java +++ b/src/test/java/com/rometools/opml/TestXmlFixerReader.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.sun.syndication; +package com.rometools.opml; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -28,8 +28,8 @@ import junit.framework.TestCase; import org.jdom2.input.SAXBuilder; -import com.sun.syndication.io.XmlReader; -import com.sun.syndication.io.impl.XmlFixerReader; +import com.rometools.rome.io.XmlReader; +import com.rometools.rome.io.impl.XmlFixerReader; /** * @author pat, tucu diff --git a/src/test/java/com/sun/syndication/TestXmlReader.java b/src/test/java/com/rometools/opml/TestXmlReader.java similarity index 99% rename from src/test/java/com/sun/syndication/TestXmlReader.java rename to src/test/java/com/rometools/opml/TestXmlReader.java index 14a334b..d2e8ff9 100644 --- a/src/test/java/com/sun/syndication/TestXmlReader.java +++ b/src/test/java/com/rometools/opml/TestXmlReader.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.sun.syndication; +package com.rometools.opml; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -28,7 +28,7 @@ import java.util.Map; import junit.framework.TestCase; -import com.sun.syndication.io.XmlReader; +import com.rometools.rome.io.XmlReader; /** * @author pat, tucu diff --git a/src/test/java/com/sun/syndication/test/NullWriter.java b/src/test/java/com/rometools/opml/test/NullWriter.java similarity index 86% rename from src/test/java/com/sun/syndication/test/NullWriter.java rename to src/test/java/com/rometools/opml/test/NullWriter.java index c82eb05..f4783e2 100644 --- a/src/test/java/com/sun/syndication/test/NullWriter.java +++ b/src/test/java/com/rometools/opml/test/NullWriter.java @@ -1,4 +1,4 @@ -package com.sun.syndication.test; +package com.rometools.opml.test; import java.io.IOException; import java.io.Writer; diff --git a/src/test/java/com/sun/syndication/test/TestUtil.java b/src/test/java/com/rometools/opml/test/TestUtil.java similarity index 84% rename from src/test/java/com/sun/syndication/test/TestUtil.java rename to src/test/java/com/rometools/opml/test/TestUtil.java index bc63fe3..1af2465 100644 --- a/src/test/java/com/sun/syndication/test/TestUtil.java +++ b/src/test/java/com/rometools/opml/test/TestUtil.java @@ -1,4 +1,4 @@ -package com.sun.syndication.test; +package com.rometools.opml.test; import java.io.InputStreamReader; import java.io.Reader; From c19dd95fa489bf34b95abd238c63e38dd4c91adb Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 30 May 2014 16:44:54 +0200 Subject: [PATCH 30/47] Removed "cyclic dependency" to parent POM Fixed module paths in rome.properties --- pom.xml | 1 + src/main/resources/rome.properties | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 88e6cc2..54491a8 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ com.rometools rome + 1.5.0-SNAPSHOT ch.qos.logback diff --git a/src/main/resources/rome.properties b/src/main/resources/rome.properties index 151f949..f57e9e3 100644 --- a/src/main/resources/rome.properties +++ b/src/main/resources/rome.properties @@ -12,11 +12,11 @@ # -WireFeedGenerator.classes=com.rometools.rome.io.impl.OPML10Generator \ - com.rometools.rome.io.impl.OPML20Generator +WireFeedGenerator.classes=com.rometools.opml.io.impl.OPML10Generator \ + com.rometools.opml.io.impl.OPML20Generator -WireFeedParser.classes=com.rometools.rome.io.impl.OPML10Parser \ - com.rometools.rome.io.impl.OPML20Parser +WireFeedParser.classes=com.rometools.opml.io.impl.OPML10Parser \ + com.rometools.opml.io.impl.OPML20Parser -Converter.classes=com.rometools.rome.feed.synd.impl.ConverterForOPML10 \ - com.rometools.rome.feed.synd.impl.ConverterForOPML20 +Converter.classes=com.rometools.opml.feed.synd.impl.ConverterForOPML10 \ + com.rometools.opml.feed.synd.impl.ConverterForOPML20 From d0f54caadd6da4e105a200407f9e329b36c97608 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:11:17 +0200 Subject: [PATCH 31/47] Prepared release --- pom.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 54491a8..be0d522 100644 --- a/pom.xml +++ b/pom.xml @@ -7,10 +7,11 @@ com.rometools rome-parent - 1.5.0-SNAPSHOT + 1.5.0 rome-opml + 1.5.0-SNAPSHOT jar rome-opml @@ -20,9 +21,9 @@ http://rometools.github.io/rome-opml/ - scm:git:git@github.com:rometools/rome-opml.git - scm:git:git@github.com:rometools/rome-opml.git - https://github.com/rometools/rome-opml/ + scm:git:ssh://github.com/rometools/rome-opml.git + scm:git:ssh://git@github.com/rometools/rome-opml.git + https://github.com/rometools/rome-opml From cde7de26df6ce5d5695d70af643d340f59d62720 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:16:52 +0200 Subject: [PATCH 32/47] Prepared release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index be0d522..f4c3585 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ com.rometools rome - 1.5.0-SNAPSHOT + 1.5.0 ch.qos.logback From 1f099a34c32b3756ce12c287c42c56fe0cb8d902 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:59:15 +0200 Subject: [PATCH 33/47] [maven-release-plugin] prepare release rome-opml-1.5.0 --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index f4c3585..7a30eef 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,5 @@ - + 4.0.0 @@ -11,7 +10,7 @@ rome-opml - 1.5.0-SNAPSHOT + 1.5.0 jar rome-opml From ebce5846b768d6b1759cda6c8bbcb2e150c92768 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 00:59:20 +0200 Subject: [PATCH 34/47] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7a30eef..c8e07c8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ rome-opml - 1.5.0 + 1.6.0-SNAPSHOT jar rome-opml From 1d15605d2c0838defac92b57d2cca9d838dea2d3 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Wed, 4 Jun 2014 22:21:08 +0200 Subject: [PATCH 35/47] Prepared next development version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c8e07c8..00d86de 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.rometools rome-parent - 1.5.0 + 1.6.0-SNAPSHOT rome-opml @@ -64,7 +64,7 @@ com.rometools rome - 1.5.0 + 1.6.0-SNAPSHOT ch.qos.logback From 8588d21adb9b7335db9b16f5d0c84ee64ab144da Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 7 Feb 2015 09:49:43 +0100 Subject: [PATCH 36/47] Formatted POM file --- pom.xml | 110 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/pom.xml b/pom.xml index 00d86de..4c225b2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,37 +1,37 @@ + - + 4.0.0 - 4.0.0 + + com.rometools + rome-parent + 1.6.0-SNAPSHOT + - - com.rometools - rome-parent - 1.6.0-SNAPSHOT - + rome-opml + 1.6.0-SNAPSHOT + jar - rome-opml - 1.6.0-SNAPSHOT - jar + rome-opml - rome-opml + Support for OPML 1 and OPML 2 in ROME - Support for OPML 1 and OPML 2 in ROME + http://rometools.github.io/rome-opml/ - http://rometools.github.io/rome-opml/ + + scm:git:ssh://github.com/rometools/rome-opml.git + scm:git:ssh://git@github.com/rometools/rome-opml.git + https://github.com/rometools/rome-opml + - - scm:git:ssh://github.com/rometools/rome-opml.git - scm:git:ssh://git@github.com/rometools/rome-opml.git - https://github.com/rometools/rome-opml - - - - - kebernet - kebernet@gmail.com - Robert Cooper - - + + + kebernet + kebernet@gmail.com + Robert Cooper + + @@ -46,36 +46,36 @@ - - - - org.apache.maven.plugins - maven-scm-publish-plugin - - gh-pages - ${project.scm.developerConnection} - ${project.build.directory}/site - - - - + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + gh-pages + ${project.scm.developerConnection} + ${project.build.directory}/site + + + + - - - com.rometools - rome + + + com.rometools + rome 1.6.0-SNAPSHOT - - - ch.qos.logback - logback-classic - test - - - junit - junit - test - - + + + ch.qos.logback + logback-classic + test + + + junit + junit + test + + From 74b85d9a2c95cb135c6e40a9fc7a562462ebf4e5 Mon Sep 17 00:00:00 2001 From: Jeremie Panzer Date: Tue, 10 Mar 2015 08:27:59 +0100 Subject: [PATCH 37/47] add header if at least one element is set --- .../opml/io/impl/OPML10Generator.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java index 707b4c5..e9af30b 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java @@ -110,23 +110,23 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe boolean hasHead = false; if (opml.getCreated() != null) { - hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US)); + hasHead |= addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US)); } - hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); + hasHead |= addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); if (opml.getModified() != null) { - hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US)); + hasHead |= addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US)); } - hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); - hasHead = addNotNullSimpleElement(head, "ownerName", opml.getOwnerName()); - hasHead = addNotNullSimpleElement(head, "title", opml.getTitle()); - hasHead = addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState()); - hasHead = addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom()); - hasHead = addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft()); - hasHead = addNotNullSimpleElement(head, "windowRight", opml.getWindowRight()); - hasHead = addNotNullSimpleElement(head, "windowTop", opml.getWindowTop()); + hasHead |= addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); + hasHead |= addNotNullSimpleElement(head, "ownerName", opml.getOwnerName()); + hasHead |= addNotNullSimpleElement(head, "title", opml.getTitle()); + hasHead |= addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState()); + hasHead |= addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom()); + hasHead |= addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft()); + hasHead |= addNotNullSimpleElement(head, "windowRight", opml.getWindowRight()); + hasHead |= addNotNullSimpleElement(head, "windowTop", opml.getWindowTop()); if (hasHead) { return head; From c47ec5fa9e6212518ad6a3432ce46216f837de02 Mon Sep 17 00:00:00 2001 From: Jeremie Panzer Date: Tue, 10 Mar 2015 08:28:26 +0100 Subject: [PATCH 38/47] set the docs url as the content of the element instead of its namespace --- src/main/java/com/rometools/opml/io/impl/OPML20Generator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java index 68dacb9..c87dbfe 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java @@ -67,7 +67,8 @@ public class OPML20Generator extends OPML10Generator { retValue = super.generateHead(opml); - final Element docs = new Element("docs", opml.getDocs()); + final Element docs = new Element("docs"); + docs.setText(opml.getDocs()); retValue.addContent(docs); return retValue; From b015f3ae0cb4a259ce2db37880ef07ff0150c699 Mon Sep 17 00:00:00 2001 From: Jeremie Panzer Date: Tue, 10 Mar 2015 08:44:33 +0100 Subject: [PATCH 39/47] test serialization to and from jdom documents --- pom.xml | 6 ++++ .../java/com/rometools/opml/FeedOpsTest.java | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/pom.xml b/pom.xml index 4c225b2..e58c56b 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,12 @@ junit test + + xmlunit + xmlunit + 1.6 + test + diff --git a/src/test/java/com/rometools/opml/FeedOpsTest.java b/src/test/java/com/rometools/opml/FeedOpsTest.java index 122bc1d..5eb5f61 100644 --- a/src/test/java/com/rometools/opml/FeedOpsTest.java +++ b/src/test/java/com/rometools/opml/FeedOpsTest.java @@ -6,9 +6,18 @@ import java.io.File; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier; +import org.custommonkey.xmlunit.XMLAssert; +import org.custommonkey.xmlunit.XMLUnit; +import org.jdom2.Document; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; + import com.rometools.rome.feed.WireFeed; import com.rometools.rome.feed.synd.SyndFeed; import com.rometools.rome.feed.synd.SyndFeedImpl; +import com.rometools.rome.io.WireFeedOutput; /** * @@ -64,6 +73,27 @@ public abstract class FeedOpsTest extends FeedTest { assertTrue(feed1.equals(feed2)); } + // 1.5 + public void testWireFeedJDOMSerialization() throws Exception { + Document inputDoc = getCachedJDomDoc(); + + final WireFeed feed = getCachedWireFeed(); + WireFeedOutput output = new WireFeedOutput(); + Document outputDoc = output.outputJDom(feed); + + XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); + String inputString = outputter.outputString(inputDoc); + String outputString = outputter.outputString(outputDoc); + + XMLUnit.setIgnoreWhitespace(true); + XMLUnit.setIgnoreAttributeOrder(true); + Diff diff = XMLUnit.compareXML(inputString, outputString); + // ignore elements order + diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); + + XMLAssert.assertXMLEqual(diff, true); + } + // 1.6 public void testWireFeedSyndFeedConversion() throws Exception { final SyndFeed sFeed1 = getCachedSyndFeed(); From 3fe096365cd528a5c9a35e91f2a30370c83cb1f7 Mon Sep 17 00:00:00 2001 From: Jeremie Panzer Date: Tue, 10 Mar 2015 08:58:06 +0100 Subject: [PATCH 40/47] remove warning about reader not closed --- src/test/java/com/rometools/opml/TestXmlReader.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/rometools/opml/TestXmlReader.java b/src/test/java/com/rometools/opml/TestXmlReader.java index d2e8ff9..a7137a0 100644 --- a/src/test/java/com/rometools/opml/TestXmlReader.java +++ b/src/test/java/com/rometools/opml/TestXmlReader.java @@ -51,14 +51,17 @@ public class TestXmlReader extends TestCase { InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); XmlReader xmlReader = new XmlReader(is, false); assertEquals(xmlReader.getEncoding(), "UTF-8"); + xmlReader.close(); is = getXmlStream("no-bom", "xml-prolog", encoding, encoding); xmlReader = new XmlReader(is); assertEquals(xmlReader.getEncoding(), "UTF-8"); + xmlReader.close(); is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding); xmlReader = new XmlReader(is); assertEquals(xmlReader.getEncoding(), encoding); + xmlReader.close(); } From 86dc04fcd902253771d813086d9e956ceb4ae92d Mon Sep 17 00:00:00 2001 From: Jeremie Panzer Date: Tue, 10 Mar 2015 09:02:45 +0100 Subject: [PATCH 41/47] set opml version for OPML 1.0 generator --- src/main/java/com/rometools/opml/io/impl/OPML10Generator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java index e9af30b..dfb0368 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java @@ -67,6 +67,7 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe final Opml opml = (Opml) feed; final Document doc = new Document(); final Element root = new Element("opml"); + root.setAttribute("version", "1.0"); doc.addContent(root); final Element head = generateHead(opml); From 1a09f86736d101e351343b8ab1c8218dd75689d9 Mon Sep 17 00:00:00 2001 From: Jeremie Panzer Date: Wed, 3 Jun 2015 15:48:13 +0200 Subject: [PATCH 42/47] fix exception when head is null --- .../rometools/opml/io/impl/OPML10Parser.java | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java index 7d4f7d6..576182e 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java @@ -106,61 +106,61 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { opml.setOwnerName(head.getChildTextTrim("ownerName")); opml.setOwnerEmail(head.getChildTextTrim("ownerEmail")); opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState"))); - } - try { - opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); - } catch (final NumberFormatException nfe) { - LOG.warn("Unable to parse windowBottom", nfe); + try { + opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); + } catch (final NumberFormatException nfe) { + LOG.warn("Unable to parse windowBottom", nfe); - if (validate) { - throw new FeedException("Unable to parse windowBottom", nfe); + if (validate) { + throw new FeedException("Unable to parse windowBottom", nfe); + } } - } - try { - opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); - } catch (final NumberFormatException nfe) { - LOG.warn("Unable to parse windowLeft", nfe); - } - - try { - opml.setWindowRight(readInteger(head.getChildText("windowRight"))); - } catch (final NumberFormatException nfe) { - LOG.warn("Unable to parse windowRight", nfe); - - if (validate) { - throw new FeedException("Unable to parse windowRight", nfe); + try { + opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); + } catch (final NumberFormatException nfe) { + LOG.warn("Unable to parse windowLeft", nfe); } - } - try { - opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); - } catch (final NumberFormatException nfe) { - LOG.warn("Unable to parse windowLeft", nfe); + try { + opml.setWindowRight(readInteger(head.getChildText("windowRight"))); + } catch (final NumberFormatException nfe) { + LOG.warn("Unable to parse windowRight", nfe); - if (validate) { - throw new FeedException("Unable to parse windowLeft", nfe); + if (validate) { + throw new FeedException("Unable to parse windowRight", nfe); + } } - } - try { - opml.setWindowTop(readInteger(head.getChildText("windowTop"))); - } catch (final NumberFormatException nfe) { - LOG.warn("Unable to parse windowTop", nfe); + try { + opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); + } catch (final NumberFormatException nfe) { + LOG.warn("Unable to parse windowLeft", nfe); - if (validate) { - throw new FeedException("Unable to parse windowTop", nfe); + if (validate) { + throw new FeedException("Unable to parse windowLeft", nfe); + } } - } - try { - opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); - } catch (final NumberFormatException nfe) { - LOG.warn("Unable to parse expansionState", nfe); + try { + opml.setWindowTop(readInteger(head.getChildText("windowTop"))); + } catch (final NumberFormatException nfe) { + LOG.warn("Unable to parse windowTop", nfe); - if (validate) { - throw new FeedException("Unable to parse expansionState", nfe); + if (validate) { + throw new FeedException("Unable to parse windowTop", nfe); + } + } + + try { + opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); + } catch (final NumberFormatException nfe) { + LOG.warn("Unable to parse expansionState", nfe); + + if (validate) { + throw new FeedException("Unable to parse expansionState", nfe); + } } } From f9576b8d00e9fd7b94c770591dfd988782ba7bc3 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 8 Jan 2016 18:29:50 +0100 Subject: [PATCH 43/47] Refactored some code --- .../rometools/opml/feed/opml/Attribute.java | 201 ++--- .../com/rometools/opml/feed/opml/Opml.java | 655 ++++++++------- .../com/rometools/opml/feed/opml/Outline.java | 744 +++++++++--------- .../feed/synd/impl/ConverterForOPML10.java | 714 ++++++++--------- .../feed/synd/impl/ConverterForOPML20.java | 117 ++- .../opml/feed/synd/impl/TreeCategoryImpl.java | 61 +- .../opml/io/impl/OPML10Generator.java | 11 +- .../rometools/opml/io/impl/OPML10Parser.java | 10 +- .../opml/io/impl/OPML20Generator.java | 35 +- 9 files changed, 1215 insertions(+), 1333 deletions(-) diff --git a/src/main/java/com/rometools/opml/feed/opml/Attribute.java b/src/main/java/com/rometools/opml/feed/opml/Attribute.java index 5934d75..7e29065 100644 --- a/src/main/java/com/rometools/opml/feed/opml/Attribute.java +++ b/src/main/java/com/rometools/opml/feed/opml/Attribute.java @@ -1,114 +1,87 @@ -/* - * Attribute.java - * - * Created on April 24, 2006, 11:11 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.rometools.opml.feed.opml; - -import java.io.Serializable; - -import com.rometools.rome.feed.impl.EqualsBean; -import com.rometools.rome.feed.impl.ToStringBean; - -/** - * This is a simple name-value pair attribute for outlines. - * - * @author Robert "kebernet" Cooper - */ -public class Attribute implements Cloneable, Serializable { - - private static final long serialVersionUID = 1L; - - private String _name; - private String _value; - - /** Creates a new instance of Attribute */ - public Attribute() { - super(); - } - - /** - * Creates a new instance of Attribute. - * - * @param name name of the attribute. - * @param value value of the attribute. - */ - public Attribute(final String name, final String value) { - if (name == null || value == null) { - throw new NullPointerException("Name and value are required."); - } - setName(name); - setValue(value); - } - - /** - * name of the attribute. - * - * @param name name of the attribute. - */ - public void setName(final String name) { - _name = name; - } - - /** - * name of the attribute. - * - * @return name of the attribute. - */ - public String getName() { - return _name; - } - - /** - * value of the attribute. - * - * @param value value of the attribute. - */ - public void setValue(final String value) { - _value = value; - } - - /** - * value of the attribute. - * - * @return value of the attribute. - */ - public String getValue() { - return _value; - } - - @Override - public Object clone() { - return new Attribute(_name, _value); - } - - @Override - public boolean equals(final Object obj) { - final EqualsBean eBean = new EqualsBean(Attribute.class, this); - return eBean.beanEquals(obj); - } - - @Override - public int hashCode() { - final EqualsBean equals = new EqualsBean(Attribute.class, this); - return equals.beanHashCode(); - } - - @Override - public String toString() { - final ToStringBean tsBean = new ToStringBean(Attribute.class, this); - return tsBean.toString(); - } -} +/* + * Attribute.java + * + * Created on April 24, 2006, 11:11 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.rometools.opml.feed.opml; + +import java.io.Serializable; + +import com.rometools.rome.feed.impl.EqualsBean; +import com.rometools.rome.feed.impl.ToStringBean; + +/** + * This is a simple name-value pair attribute for outlines. + * + * @author Robert "kebernet" Cooper + */ +public class Attribute implements Cloneable, Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + private String value; + + /** + * Creates a new instance of Attribute. + * + * @param name name of the attribute. + * @param value value of the attribute. + */ + public Attribute(final String name, final String value) { + if (name == null || value == null) { + throw new NullPointerException("Name and value are required."); + } + setName(name); + setValue(value); + } + + public void setName(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setValue(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public Object clone() { + return new Attribute(name, value); + } + + @Override + public boolean equals(final Object obj) { + return new EqualsBean(Attribute.class, this).beanEquals(obj); + } + + @Override + public int hashCode() { + return new EqualsBean(Attribute.class, this).beanHashCode(); + } + + @Override + public String toString() { + return new ToStringBean(Attribute.class, this).toString(); + } + +} diff --git a/src/main/java/com/rometools/opml/feed/opml/Opml.java b/src/main/java/com/rometools/opml/feed/opml/Opml.java index da17604..3b1fbd8 100644 --- a/src/main/java/com/rometools/opml/feed/opml/Opml.java +++ b/src/main/java/com/rometools/opml/feed/opml/Opml.java @@ -1,333 +1,322 @@ -/* - * Opml.java - * - * Created on April 24, 2006, 11:00 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.rometools.opml.feed.opml; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import com.rometools.rome.feed.WireFeed; - -/** - * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in - * the <head> tag of the feed. - * - * @author Robert "kebernet" Cooper - */ -public class Opml extends WireFeed { - - private static final long serialVersionUID = 1L; - - private Date _created; - private Date _modified; - private Integer _verticalScrollState; - private Integer _windowBottom; - private Integer _windowLeft; - private Integer _windowRight; - private Integer _windowTop; - private List _outlines; - private String _docs; - private String _ownerEmail; - private String _ownerId; - private String _ownerName; - private String _title; - private int[] _expansionState; - - /** Creates a new instance of Opml */ - public Opml() { - super(); - } - - /** - * is a date-time, indicating when the document was created. - * - * @param created date-time, indicating when the document was created. - */ - public void setCreated(final Date created) { - _created = created; - } - - /** - * <dateCreated> is a date-time, indicating when the document was created. - * - * @return date-time, indicating when the document was created. - */ - public Date getCreated() { - return _created; - } - - /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML - * file. It's probably a pointer to this page for people - * who might stumble across the file on a web server 25 years from now and wonder what it is. - * - * @param docs http address of documentation for the format used - */ - public void setDocs(final String docs) { - _docs = docs; - } - - /** - * (OPML 2) <docs> is the http address of documentation for the format used in the OPML - * file. It's probably a pointer to this page for people - * who might stumble across the file on a web server 25 years from now and wonder what it is. - * - * @return http address of documentation for the format used - */ - public String getDocs() { - return _docs; - } - - /** - * <expansionState>is a comma-separated list of line numbers that are expanded. The line - * numbers in the list tell you which headlines to expand. The order is important. For each - * element in the list, X, starting at the first summit, navigate flatdown X times and expand. - * Repeat for each element in the list. - * - * @param expansionState int array containing expanded elements. - */ - public void setExpansionState(final int[] expansionState) { - _expansionState = expansionState; - } - - /** - * <expansionState> is a comma-separated list of line numbers that are expanded. The line - * numbers in the list tell you which headlines to expand. The order is important. For each - * element in the list, X, starting at the first summit, navigate flatdown X times and expand. - * Repeat for each element in the list. - * - * @return int array containing expanded elements. - */ - public int[] getExpansionState() { - return _expansionState; - } - - /** - * <dateModified> is a date-time, indicating when the document was last modified. - * - * @param modified date-time, indicating when the document was last modified. - */ - public void setModified(final Date modified) { - _modified = modified; - } - - /** - * <dateModified> is a date-time, indicating when the document was last modified. - * - * @return date-time, indicating when the document was last modified. - */ - public Date getModified() { - return _modified; - } - - /** - * Root level Outline object that should appear in the <body> - * - * @param outlines Root level Outline object that should appear in the <body> - */ - public void setOutlines(final List outlines) { - _outlines = outlines; - } - - /** - * Root level Outline object that should appear in the <body> - * - * @return Root level Outline object that should appear in the <body> - */ - public List getOutlines() { - if (_outlines == null) { - _outlines = new ArrayList(); - } - - return _outlines; - } - - /** - * <ownerEmail> is a string, the email address of the owner of the document. - * - * @param ownerEmail the email address of the owner of the document. - */ - public void setOwnerEmail(final String ownerEmail) { - _ownerEmail = ownerEmail; - } - - /** - * <ownerEmail> is a string, the email address of the owner of the document. - * - * @return the email address of the owner of the document. - */ - public String getOwnerEmail() { - return _ownerEmail; - } - - /** - * (OPML 2) <ownerId> is the http address of a web page that contains an - * HTML a form that allows a human reader to communicate with the author of the - * document via email or other means. - * - * @param ownerId http address of a web page that contains an HTML a form that - * allows a human reader to communicate with the author of the document via email or - * other means. - */ - public void setOwnerId(final String ownerId) { - _ownerId = ownerId; - } - - /** - * (OPML 2) <ownerId> is the http address of a web page that contains an - * HTML a form that allows a human reader to communicate with the author of the - * document via email or other means. - * - * @return http address of a web page that contains an HTML a form that allows - * a human reader to communicate with the author of the document via email or other - * means. - */ - public String getOwnerId() { - return _ownerId; - } - - /** - * <ownerName> is a string, the owner of the document. - * - * @param ownerName the owner of the document. - */ - public void setOwnerName(final String ownerName) { - _ownerName = ownerName; - } - - /** - * <ownerName> is a string, the owner of the document. - * - * @return the owner of the document. - */ - public String getOwnerName() { - return _ownerName; - } - - /** - * <title> is the title of the document. - * - * @param title title of the document. - */ - public void setTitle(final String title) { - _title = title; - } - - /** - * <title> is the title of the document. - * - * @return title of the document. - */ - public String getTitle() { - return _title; - } - - /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top - * line of the window. This number is calculated with the expansion state already applied. - * - * @param verticalScrollState which line of the outline is displayed on the top line of the - * window. - */ - public void setVerticalScrollState(final Integer verticalScrollState) { - _verticalScrollState = verticalScrollState; - } - - /** - * <vertScrollState> is a number, saying which line of the outline is displayed on the top - * line of the window. This number is calculated with the expansion state already applied. - * - * @return which line of the outline is displayed on the top line of the window. This number is - * calculated with the expansion state already applied. - */ - public Integer getVerticalScrollState() { - return _verticalScrollState; - } - - /** - * <windowBottom> is a number, the pixel location of the bottom edge of the window. - * - * @param windowBottom the pixel location of the bottom edge of the window. - */ - public void setWindowBottom(final Integer windowBottom) { - _windowBottom = windowBottom; - } - - /** - * <windowBottom> is a number, the pixel location of the bottom edge of the window. - * - * @return the pixel location of the bottom edge of the window. - */ - public Integer getWindowBottom() { - return _windowBottom; - } - - /** - * <windowLeft> is a number, the pixel location of the left edge of the window. - * - * @param windowLeft the pixel location of the left edge of the window. - */ - public void setWindowLeft(final Integer windowLeft) { - _windowLeft = windowLeft; - } - - /** - * <windowLeft> is a number, the pixel location of the left edge of the window. - * - * @return the pixel location of the left edge of the window. - */ - public Integer getWindowLeft() { - return _windowLeft; - } - - /** - * <windowRight> is a number, the pixel location of the right edge of the window. - * - * @param windowRight the pixel location of the right edge of the window. - */ - public void setWindowRight(final Integer windowRight) { - _windowRight = windowRight; - } - - /** - * <windowRight> is a number, the pixel location of the right edge of the window. - * - * @return the pixel location of the right edge of the window. - */ - public Integer getWindowRight() { - return _windowRight; - } - - /** - * <windowTop> is a number, the pixel location of the top edge of the window. - * - * @param windowTop the pixel location of the top edge of the window. - */ - public void setWindowTop(final Integer windowTop) { - _windowTop = windowTop; - } - - /** - * <windowTop> is a number, the pixel location of the top edge of the window. - * - * @return the pixel location of the top edge of the window. - */ - public Integer getWindowTop() { - return _windowTop; - } -} +/* + * Opml.java + * + * Created on April 24, 2006, 11:00 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.rometools.opml.feed.opml; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import com.rometools.rome.feed.WireFeed; + +/** + * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in the <head> tag + * of the feed. + * + * @author Robert "kebernet" Cooper + */ +public class Opml extends WireFeed { + + private static final long serialVersionUID = 1L; + + private Date created; + private Date modified; + private Integer verticalScrollState; + private Integer windowBottom; + private Integer windowLeft; + private Integer windowRight; + private Integer windowTop; + private List outlines; + private String docs; + private String ownerEmail; + private String ownerId; + private String ownerName; + private String title; + private int[] expansionState; + + /** + * is a date-time, indicating when the document was created. + * + * @param created date-time, indicating when the document was created. + */ + public void setCreated(final Date created) { + this.created = created; + } + + /** + * <dateCreated> is a date-time, indicating when the document was created. + * + * @return date-time, indicating when the document was created. + */ + public Date getCreated() { + return created; + } + + /** + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a + * pointer to this page for people who might stumble across the file on a + * web server 25 years from now and wonder what it is. + * + * @param docs http address of documentation for the format used + */ + public void setDocs(final String docs) { + this.docs = docs; + } + + /** + * (OPML 2) <docs> is the http address of documentation for the format used in the OPML file. It's probably a + * pointer to this page for people who might stumble across the file on a + * web server 25 years from now and wonder what it is. + * + * @return http address of documentation for the format used + */ + public String getDocs() { + return docs; + } + + /** + * <expansionState>is a comma-separated list of line numbers that are expanded. The line numbers in the list + * tell you which headlines to expand. The order is important. For each element in the list, X, starting at the + * first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * + * @param expansionState int array containing expanded elements. + */ + public void setExpansionState(final int[] expansionState) { + this.expansionState = expansionState; + } + + /** + * <expansionState> is a comma-separated list of line numbers that are expanded. The line numbers in the list + * tell you which headlines to expand. The order is important. For each element in the list, X, starting at the + * first summit, navigate flatdown X times and expand. Repeat for each element in the list. + * + * @return int array containing expanded elements. + */ + public int[] getExpansionState() { + return expansionState; + } + + /** + * <dateModified> is a date-time, indicating when the document was last modified. + * + * @param modified date-time, indicating when the document was last modified. + */ + public void setModified(final Date modified) { + this.modified = modified; + } + + /** + * <dateModified> is a date-time, indicating when the document was last modified. + * + * @return date-time, indicating when the document was last modified. + */ + public Date getModified() { + return modified; + } + + /** + * Root level Outline object that should appear in the <body> + * + * @param outlines Root level Outline object that should appear in the <body> + */ + public void setOutlines(final List outlines) { + this.outlines = outlines; + } + + /** + * Root level Outline object that should appear in the <body> + * + * @return Root level Outline object that should appear in the <body> + */ + public List getOutlines() { + if (outlines == null) { + outlines = new ArrayList(); + } + + return outlines; + } + + /** + * <ownerEmail> is a string, the email address of the owner of the document. + * + * @param ownerEmail the email address of the owner of the document. + */ + public void setOwnerEmail(final String ownerEmail) { + this.ownerEmail = ownerEmail; + } + + /** + * <ownerEmail> is a string, the email address of the owner of the document. + * + * @return the email address of the owner of the document. + */ + public String getOwnerEmail() { + return ownerEmail; + } + + /** + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that + * allows a human reader to communicate with the author of the document via email or other means. + * + * @param ownerId http address of a web page that contains an HTML a form that allows a human + * reader to communicate with the author of the document via email or other means. + */ + public void setOwnerId(final String ownerId) { + this.ownerId = ownerId; + } + + /** + * (OPML 2) <ownerId> is the http address of a web page that contains an HTML a form that + * allows a human reader to communicate with the author of the document via email or other means. + * + * @return http address of a web page that contains an HTML a form that allows a human reader to + * communicate with the author of the document via email or other means. + */ + public String getOwnerId() { + return ownerId; + } + + /** + * <ownerName> is a string, the owner of the document. + * + * @param ownerName the owner of the document. + */ + public void setOwnerName(final String ownerName) { + this.ownerName = ownerName; + } + + /** + * <ownerName> is a string, the owner of the document. + * + * @return the owner of the document. + */ + public String getOwnerName() { + return ownerName; + } + + /** + * <title> is the title of the document. + * + * @param title title of the document. + */ + public void setTitle(final String title) { + this.title = title; + } + + /** + * <title> is the title of the document. + * + * @return title of the document. + */ + public String getTitle() { + return title; + } + + /** + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. + * This number is calculated with the expansion state already applied. + * + * @param verticalScrollState which line of the outline is displayed on the top line of the window. + */ + public void setVerticalScrollState(final Integer verticalScrollState) { + this.verticalScrollState = verticalScrollState; + } + + /** + * <vertScrollState> is a number, saying which line of the outline is displayed on the top line of the window. + * This number is calculated with the expansion state already applied. + * + * @return which line of the outline is displayed on the top line of the window. This number is calculated with the + * expansion state already applied. + */ + public Integer getVerticalScrollState() { + return verticalScrollState; + } + + /** + * <windowBottom> is a number, the pixel location of the bottom edge of the window. + * + * @param windowBottom the pixel location of the bottom edge of the window. + */ + public void setWindowBottom(final Integer windowBottom) { + this.windowBottom = windowBottom; + } + + /** + * <windowBottom> is a number, the pixel location of the bottom edge of the window. + * + * @return the pixel location of the bottom edge of the window. + */ + public Integer getWindowBottom() { + return windowBottom; + } + + /** + * <windowLeft> is a number, the pixel location of the left edge of the window. + * + * @param windowLeft the pixel location of the left edge of the window. + */ + public void setWindowLeft(final Integer windowLeft) { + this.windowLeft = windowLeft; + } + + /** + * <windowLeft> is a number, the pixel location of the left edge of the window. + * + * @return the pixel location of the left edge of the window. + */ + public Integer getWindowLeft() { + return windowLeft; + } + + /** + * <windowRight> is a number, the pixel location of the right edge of the window. + * + * @param windowRight the pixel location of the right edge of the window. + */ + public void setWindowRight(final Integer windowRight) { + this.windowRight = windowRight; + } + + /** + * <windowRight> is a number, the pixel location of the right edge of the window. + * + * @return the pixel location of the right edge of the window. + */ + public Integer getWindowRight() { + return windowRight; + } + + /** + * <windowTop> is a number, the pixel location of the top edge of the window. + * + * @param windowTop the pixel location of the top edge of the window. + */ + public void setWindowTop(final Integer windowTop) { + this.windowTop = windowTop; + } + + /** + * <windowTop> is a number, the pixel location of the top edge of the window. + * + * @return the pixel location of the top edge of the window. + */ + public Integer getWindowTop() { + return windowTop; + } + +} diff --git a/src/main/java/com/rometools/opml/feed/opml/Outline.java b/src/main/java/com/rometools/opml/feed/opml/Outline.java index 14e988d..2d97405 100644 --- a/src/main/java/com/rometools/opml/feed/opml/Outline.java +++ b/src/main/java/com/rometools/opml/feed/opml/Outline.java @@ -1,377 +1,367 @@ -/* - * Outline.java - * - * Created on April 24, 2006, 11:04 PM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.rometools.opml.feed.opml; - -import java.io.Serializable; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import com.rometools.rome.feed.impl.EqualsBean; -import com.rometools.rome.feed.impl.ToStringBean; -import com.rometools.rome.feed.module.Module; - -/** - * This class represents an OPML outline element. - * - * @author Robert "kebernet" Cooper - */ -public class Outline implements Cloneable, Serializable { - - private static final long serialVersionUID = 1L; - - private Date _created; - private List _attributes; - private List _categories; - private List _children; - private List _modules; - private String _text; - private String _title; - private String _type; - private boolean _breakpoint; - private boolean _comment; - - /** Creates a new instance of Outline */ - public Outline() { - super(); - } - - /** - * Creates a new outline with the specified type and text values. - * - * @param type type attribute value/ - * @param text text attribute value - */ - public Outline(final String type, final String text) { - super(); - setType(type); - setText(text); - } - - /** - * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for - * aggregator feed lists and will get a type of "rss". - * - * @param title Title of the entry. - * @param xmlUrl link to XML file. - * @param htmlUrl link to html page. - */ - public Outline(final String title, final URL xmlUrl, final URL htmlUrl) { - super(); - setType("rss"); - setTitle(title); - setAttributes(new ArrayList()); - - if (xmlUrl != null) { - getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); - } - - if (htmlUrl != null) { - getAttributes().add(new Attribute("htmlUrl", htmlUrl.toString())); - } - } - - /** - * List of attributes on this outline excluding the "common types" for the specification. - * - * @param attributes List of attributes on this outline. - */ - public void setAttributes(final List attributes) { - _attributes = attributes; - } - - /** - * List of attributes on this outline excluding the "common types" for the specification. - * - * @return List of attributes on this outline. - */ - public List getAttributes() { - if (_attributes == null) { - _attributes = new ArrayList(); - } - - return _attributes; - } - - /** - * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on - * this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's - * not present, the value is false. - * - * @param breakpoint whether a breakpoint is set on this outline. - */ - public void setBreakpoint(final boolean breakpoint) { - _breakpoint = breakpoint; - } - - /** - * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on - * this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's - * not present, the value is false. - * - * @return whether a breakpoint is set on this outline - */ - public boolean isBreakpoint() { - return _breakpoint; - } - - /** - * (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(final List categories) { - _categories = categories; - } - - /** - * (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() { - if (_categories == null) { - _categories = new ArrayList(); - } - - return _categories; - } - - /** - * A list of sub-outlines for this entry. - * - * @param children A list of sub-outlines for this entry. - */ - public void setChildren(final List children) { - _children = children; - } - - /** - * A list of sub-outlines for this entry. - * - * @return A list of sub-outlines for this entry. - */ - public List getChildren() { - if (_children == null) { - _children = new ArrayList(); - } - - return _children; - } - - /** - * isComment is a string, either "true" or "false", indicating whether the outline is commented - * or not. By convention if an outline is commented, all subordinate outlines are considered to - * also be commented. If it's not present, the value is false. - * - * @param comment whether the outline is commented - */ - public void setComment(final boolean comment) { - _comment = comment; - } - - /** - * isComment is a string, either "true" or "false", indicating whether the outline is commented - * or not. By convention if an outline is commented, all subordinate outlines are considered to - * also be commented. If it's not present, the value is false. - * - * @return whether the outline is commented - */ - public boolean isComment() { - return _comment; - } - - /** - * (OPML 2) created is the date-time that the outline node was created. - * - * @param created date-time that the outline node was created. - */ - public void setCreated(final Date created) { - _created = created; - } - - /** - * (OPML 2) created is the date-time that the outline node was created. - * - * @return date-time that the outline node was created. - */ - public Date getCreated() { - return _created; - } - - /** - * A convenience method to return the value of the url attribute. - * - * @return value of the htmlUrl attribute. - */ - public String getUrl() { - return getAttributeValue("url"); - } - - /** - * A convenience method to return the value of the htmlUrl attribute. - * - * @return value of the htmlUrl attribute. - */ - public String getHtmlUrl() { - return getAttributeValue("htmlUrl"); - } - - public void setModules(final List modules) { - _modules = modules; - } - - public List getModules() { - if (_modules == null) { - _modules = new ArrayList(); - } - - return _modules; - } - - /** - * The "text" attribute of the outline. - * - * @param text The "text" attribute of the outline. - */ - public void setText(final String text) { - _text = text; - } - - /** - * The "text" attribute of the outline. - * - * @return The "text" attribute of the outline. - */ - public String getText() { - return _text; - } - - /** - * The "title" attribute of the outline. - * - * @param title The "title" attribute of the outline. - */ - public void setTitle(final String title) { - _title = title; - } - - /** - * The "title" attribute of the outline. - * - * @return The "title" attribute of the outline. - */ - public String getTitle() { - return _title; - } - - /** - * The "type" attribute of the outline. - * - * @param type The "type" attribute of the outline. - */ - public void setType(final String type) { - _type = type; - } - - /** - * The "type" attribute of the outline. - * - * @return The "type" attribute of the outline. - */ - public String getType() { - return _type; - } - - /** - * A convenience method to return the value of the xmlUrl attribute. - * - * @return value of the xmlUrl attribute. - */ - public String getXmlUrl() { - return getAttributeValue("xmlUrl"); - } - - /** - * Returns the value of an attribute on the outline or null. - * - * @param name name of the attribute. - */ - public String getAttributeValue(final String name) { - final List attributes = Collections.synchronizedList(getAttributes()); - for (int i = 0; i < attributes.size(); i++) { - final Attribute a = attributes.get(i); - - if (a.getName() != null && a.getName().equals(name)) { - return a.getValue(); - } - } - return null; - } - - @Override - public Object clone() { - - final Outline o = new Outline(); - o.setBreakpoint(isBreakpoint()); - o.setCategories(new ArrayList(getCategories())); - o.setComment(isComment()); - o.setCreated(_created != null ? (Date) _created.clone() : null); - o.setModules(new ArrayList(getModules())); - o.setText(getText()); - o.setTitle(getTitle()); - o.setType(getType()); - - final ArrayList children = new ArrayList(); - for (int i = 0; i < getChildren().size(); i++) { - children.add((Outline) _children.get(i).clone()); - } - o.setChildren(children); - - final ArrayList attributes = new ArrayList(); - for (int i = 0; i < getAttributes().size(); i++) { - attributes.add((Attribute) _attributes.get(i).clone()); - } - o.setAttributes(attributes); - - return o; - } - - @Override - public boolean equals(final Object obj) { - final EqualsBean eBean = new EqualsBean(Outline.class, this); - - return eBean.beanEquals(obj); - } - - @Override - public int hashCode() { - final EqualsBean equals = new EqualsBean(Outline.class, this); - - return equals.beanHashCode(); - } - - @Override - public String toString() { - final ToStringBean tsBean = new ToStringBean(Outline.class, this); - - return tsBean.toString(); - } -} +/* + * Outline.java + * + * Created on April 24, 2006, 11:04 PM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.rometools.opml.feed.opml; + +import java.io.Serializable; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import com.rometools.rome.feed.impl.EqualsBean; +import com.rometools.rome.feed.impl.ToStringBean; +import com.rometools.rome.feed.module.Module; + +/** + * This class represents an OPML outline element. + * + * @author Robert "kebernet" Cooper + */ +public class Outline implements Cloneable, Serializable { + + private static final long serialVersionUID = 1L; + + private Date created; + private List attributes; + private List categories; + private List children; + private List modules; + private String text; + private String title; + private String type; + private boolean breakpoint; + private boolean comment; + + public Outline() { + } + + /** + * Creates a new outline with the specified type and text values. + * + * @param type type attribute value/ + * @param text text attribute value + */ + public Outline(final String type, final String text) { + setType(type); + setText(text); + } + + /** + * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for aggregator feed lists + * and will get a type of "rss". + * + * @param title Title of the entry. + * @param xmlUrl link to XML file. + * @param htmlUrl link to html page. + */ + public Outline(final String title, final URL xmlUrl, final URL htmlUrl) { + super(); + setType("rss"); + setTitle(title); + setAttributes(new ArrayList()); + + if (xmlUrl != null) { + getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); + } + + if (htmlUrl != null) { + getAttributes().add(new Attribute("htmlUrl", htmlUrl.toString())); + } + } + + /** + * List of attributes on this outline excluding the "common types" for the specification. + * + * @param attributes List of attributes on this outline. + */ + public void setAttributes(final List attributes) { + this.attributes = attributes; + } + + /** + * List of attributes on this outline excluding the "common types" for the specification. + * + * @return List of attributes on this outline. + */ + public List getAttributes() { + if (attributes == null) { + attributes = new ArrayList(); + } + + return attributes; + } + + /** + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This + * attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + * + * @param breakpoint whether a breakpoint is set on this outline. + */ + public void setBreakpoint(final boolean breakpoint) { + this.breakpoint = breakpoint; + } + + /** + * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This + * attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false. + * + * @return whether a breakpoint is set on this outline + */ + public boolean isBreakpoint() { + return breakpoint; + } + + /** + * (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(final List categories) { + this.categories = categories; + } + + /** + * (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() { + if (categories == null) { + categories = new ArrayList(); + } + + return categories; + } + + /** + * A list of sub-outlines for this entry. + * + * @param children A list of sub-outlines for this entry. + */ + public void setChildren(final List children) { + this.children = children; + } + + /** + * A list of sub-outlines for this entry. + * + * @return A list of sub-outlines for this entry. + */ + public List getChildren() { + if (children == null) { + children = new ArrayList(); + } + + return children; + } + + /** + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By + * convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not + * present, the value is false. + * + * @param comment whether the outline is commented + */ + public void setComment(final boolean comment) { + this.comment = comment; + } + + /** + * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By + * convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not + * present, the value is false. + * + * @return whether the outline is commented + */ + public boolean isComment() { + return comment; + } + + /** + * (OPML 2) created is the date-time that the outline node was created. + * + * @param created date-time that the outline node was created. + */ + public void setCreated(final Date created) { + this.created = created; + } + + /** + * (OPML 2) created is the date-time that the outline node was created. + * + * @return date-time that the outline node was created. + */ + public Date getCreated() { + return created; + } + + /** + * A convenience method to return the value of the url attribute. + * + * @return value of the htmlUrl attribute. + */ + public String getUrl() { + return getAttributeValue("url"); + } + + /** + * A convenience method to return the value of the htmlUrl attribute. + * + * @return value of the htmlUrl attribute. + */ + public String getHtmlUrl() { + return getAttributeValue("htmlUrl"); + } + + public void setModules(final List modules) { + this.modules = modules; + } + + public List getModules() { + if (modules == null) { + modules = new ArrayList(); + } + + return modules; + } + + /** + * The "text" attribute of the outline. + * + * @param text The "text" attribute of the outline. + */ + public void setText(final String text) { + this.text = text; + } + + /** + * The "text" attribute of the outline. + * + * @return The "text" attribute of the outline. + */ + public String getText() { + return text; + } + + /** + * The "title" attribute of the outline. + * + * @param title The "title" attribute of the outline. + */ + public void setTitle(final String title) { + this.title = title; + } + + /** + * The "title" attribute of the outline. + * + * @return The "title" attribute of the outline. + */ + public String getTitle() { + return title; + } + + /** + * The "type" attribute of the outline. + * + * @param type The "type" attribute of the outline. + */ + public void setType(final String type) { + this.type = type; + } + + /** + * The "type" attribute of the outline. + * + * @return The "type" attribute of the outline. + */ + public String getType() { + return type; + } + + /** + * A convenience method to return the value of the xmlUrl attribute. + * + * @return value of the xmlUrl attribute. + */ + public String getXmlUrl() { + return getAttributeValue("xmlUrl"); + } + + /** + * Returns the value of an attribute on the outline or null. + * + * @param name name of the attribute. + */ + public String getAttributeValue(final String name) { + final List attributes = Collections.synchronizedList(getAttributes()); + for (int i = 0; i < attributes.size(); i++) { + final Attribute a = attributes.get(i); + + if (a.getName() != null && a.getName().equals(name)) { + return a.getValue(); + } + } + return null; + } + + @Override + public Object clone() { + + final Outline o = new Outline(); + o.setBreakpoint(isBreakpoint()); + o.setCategories(new ArrayList(getCategories())); + o.setComment(isComment()); + o.setCreated(created != null ? (Date) created.clone() : null); + o.setModules(new ArrayList(getModules())); + o.setText(getText()); + o.setTitle(getTitle()); + o.setType(getType()); + + final ArrayList children = new ArrayList(); + for (int i = 0; i < getChildren().size(); i++) { + children.add((Outline) this.children.get(i).clone()); + } + o.setChildren(children); + + final ArrayList attributes = new ArrayList(); + for (int i = 0; i < getAttributes().size(); i++) { + attributes.add((Attribute) this.attributes.get(i).clone()); + } + o.setAttributes(attributes); + + return o; + } + + @Override + public boolean equals(final Object obj) { + return new EqualsBean(Outline.class, this).beanEquals(obj); + } + + @Override + public int hashCode() { + return new EqualsBean(Outline.class, this).beanHashCode(); + } + + @Override + public String toString() { + return new ToStringBean(Outline.class, this).toString(); + } + +} diff --git a/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML10.java b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML10.java index 28c8020..4cf6363 100644 --- a/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML10.java +++ b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML10.java @@ -1,365 +1,349 @@ -/* - * ConverterForOPML10.java - * - * Created on April 25, 2006, 1:26 AM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.rometools.opml.feed.synd.impl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Stack; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.rometools.opml.feed.opml.Attribute; -import com.rometools.opml.feed.opml.Opml; -import com.rometools.opml.feed.opml.Outline; -import com.rometools.rome.feed.WireFeed; -import com.rometools.rome.feed.synd.Converter; -import com.rometools.rome.feed.synd.SyndCategory; -import com.rometools.rome.feed.synd.SyndCategoryImpl; -import com.rometools.rome.feed.synd.SyndContent; -import com.rometools.rome.feed.synd.SyndContentImpl; -import com.rometools.rome.feed.synd.SyndEntry; -import com.rometools.rome.feed.synd.SyndEntryImpl; -import com.rometools.rome.feed.synd.SyndFeed; -import com.rometools.rome.feed.synd.SyndLink; -import com.rometools.rome.feed.synd.SyndLinkImpl; -import com.rometools.rome.feed.synd.SyndPerson; -import com.rometools.rome.feed.synd.SyndPersonImpl; - -/** - * - * @author cooper - */ -public class ConverterForOPML10 implements Converter { - - private static final Logger LOG = LoggerFactory.getLogger(ConverterForOPML10.class); - - public static final String URI_TREE = "urn:rome.tree"; - public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; - - /** Creates a new instance of ConverterForOPML10 */ - public ConverterForOPML10() { - super(); - } - - protected void addOwner(final Opml opml, final SyndFeed syndFeed) { - if (opml.getOwnerEmail() != null || opml.getOwnerName() != null) { - final List authors = new ArrayList(); - final SyndPerson person = new SyndPersonImpl(); - person.setEmail(opml.getOwnerEmail()); - person.setName(opml.getOwnerName()); - authors.add(person); - syndFeed.setAuthors(authors); - } - } - - /** - * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. - *

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

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

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

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

- */ - @Override - public String getType() { - return "opml_1.0"; - } - - private static class OutlineHolder { - Outline outline; - String parent; - - public OutlineHolder(final Outline outline, final String parent) { - this.outline = outline; - this.parent = parent; - } - } - - private static class TreeContext extends Stack { - - private static final long serialVersionUID = 1L; - - TreeContext() { - super(); - } - } -} +/* + * ConverterForOPML10.java + * + * Created on April 25, 2006, 1:26 AM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.rometools.opml.feed.synd.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Stack; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.rometools.opml.feed.opml.Attribute; +import com.rometools.opml.feed.opml.Opml; +import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.Converter; +import com.rometools.rome.feed.synd.SyndCategory; +import com.rometools.rome.feed.synd.SyndCategoryImpl; +import com.rometools.rome.feed.synd.SyndContent; +import com.rometools.rome.feed.synd.SyndContentImpl; +import com.rometools.rome.feed.synd.SyndEntry; +import com.rometools.rome.feed.synd.SyndEntryImpl; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndLink; +import com.rometools.rome.feed.synd.SyndLinkImpl; +import com.rometools.rome.feed.synd.SyndPerson; +import com.rometools.rome.feed.synd.SyndPersonImpl; + +/** + * @author cooper + */ +public class ConverterForOPML10 implements Converter { + + private static final Logger LOG = LoggerFactory.getLogger(ConverterForOPML10.class); + + public static final String URI_TREE = "urn:rome.tree"; + public static final String URI_ATTRIBUTE = "urn:rome.attribute#"; + + protected void addOwner(final Opml opml, final SyndFeed syndFeed) { + if (opml.getOwnerEmail() != null || opml.getOwnerName() != null) { + final List authors = new ArrayList(); + final SyndPerson person = new SyndPersonImpl(); + person.setEmail(opml.getOwnerEmail()); + person.setName(opml.getOwnerName()); + authors.add(person); + syndFeed.setAuthors(authors); + } + } + + /** + * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. + *

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

+ * + * @param feed real feed to copy/convert. + * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. + */ + @Override + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + final Opml opml = (Opml) feed; + syndFeed.setTitle(opml.getTitle()); + addOwner(opml, syndFeed); + syndFeed.setPublishedDate(opml.getModified() != null ? opml.getModified() : opml.getCreated()); + syndFeed.setFeedType(opml.getFeedType()); + syndFeed.setModules(opml.getModules()); + syndFeed.setFeedType(getType()); + + createEntries(new Stack(), syndFeed.getEntries(), opml.getOutlines()); + } + + protected void createEntries(final Stack context, final List allEntries, final List outlines) { + final List so = Collections.synchronizedList(outlines); + + for (int i = 0; i < so.size(); i++) { + createEntry(context, allEntries, so.get(i)); + } + } + + protected SyndEntry createEntry(final Stack context, final List allEntries, final Outline outline) { + final SyndEntry entry = new SyndEntryImpl(); + + if (outline.getType() != null && outline.getType().equals("rss")) { + entry.setLink(outline.getHtmlUrl() != null ? outline.getHtmlUrl() : outline.getXmlUrl()); + } else if (outline.getType() != null && outline.getType().equals("link")) { + entry.setLink(outline.getUrl()); + } + + if (outline.getHtmlUrl() != null) { + final SyndLink link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setType("text/html"); + link.setHref(outline.getHtmlUrl()); + entry.getLinks().add(link); + entry.setLink(outline.getHtmlUrl()); + } + + if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("rss")) { + final SyndLink link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setType("application/rss+xml"); + link.setHref(outline.getXmlUrl()); + entry.getLinks().add(link); + + if (entry.getLink() == null) { + entry.setLink(outline.getXmlUrl()); + } + } + + if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("atom")) { + final SyndLink link = new SyndLinkImpl(); + link.setRel("alternate"); + link.setType("application/atom+xml"); + link.setHref(outline.getXmlUrl()); + entry.getLinks().add(link); + + if (entry.getLink() == null) { + entry.setLink(outline.getXmlUrl()); + } + } + + if (outline.getType() != null && outline.getType().equals("rss")) { + entry.setTitle(outline.getTitle()); + } else { + entry.setTitle(outline.getText()); + } + + if (outline.getText() == null && entry.getTitle() != null) { + final SyndContent c = new SyndContentImpl(); + c.setValue(outline.getText()); + entry.setDescription(c); + } + + entry.setPublishedDate(outline.getCreated()); + + final String nodeName = "node." + outline.hashCode(); + + final SyndCategory cat = new TreeCategoryImpl(); + cat.setTaxonomyUri(URI_TREE); + cat.setName(nodeName); + entry.getCategories().add(cat); + + if (!context.isEmpty()) { + final Integer parent = context.peek(); + final SyndCategory pcat = new TreeCategoryImpl(); + pcat.setTaxonomyUri(URI_TREE); + pcat.setName("parent." + parent); + entry.getCategories().add(pcat); + } + + final List attributes = Collections.synchronizedList(outline.getAttributes()); + + for (int i = 0; i < attributes.size(); i++) { + final Attribute a = attributes.get(i); + final SyndCategory acat = new SyndCategoryImpl(); + acat.setName(a.getValue()); + acat.setTaxonomyUri(URI_ATTRIBUTE + a.getName()); + entry.getCategories().add(acat); + } + + entry.setModules(outline.getModules()); + allEntries.add(entry); + context.push(new Integer(outline.hashCode())); + createEntries(context, allEntries, outline.getChildren()); + context.pop(); + + return entry; + } + + /** + * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. + *

+ * + * @param syndFeed SyndFeedImpl to copy/convert value from. + * @return a real feed with copied/converted values of the SyndFeedImpl. + */ + @Override + public WireFeed createRealFeed(final SyndFeed syndFeed) { + + final List entries = Collections.synchronizedList(syndFeed.getEntries()); + + final HashMap entriesByNode = new HashMap(); + + // this will hold entries that we can't parent the first time. + final ArrayList doAfterPass = new ArrayList(); + + // this holds root level outlines; + final ArrayList root = new ArrayList(); + + for (int i = 0; i < entries.size(); i++) { + final SyndEntry entry = entries.get(i); + final Outline o = new Outline(); + + final List cats = Collections.synchronizedList(entry.getCategories()); + boolean parentFound = false; + final StringBuffer category = new StringBuffer(); + + for (int j = 0; j < cats.size(); j++) { + final SyndCategory cat = cats.get(j); + + if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().equals(URI_TREE)) { + final String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length()); + + if (cat.getName().startsWith("node.")) { + entriesByNode.put(nodeVal, o); + } else if (cat.getName().startsWith("parent.")) { + parentFound = true; + + final Outline parent = entriesByNode.get(nodeVal); + + if (parent != null) { + parent.getChildren().add(o); + } else { + doAfterPass.add(new OutlineHolder(o, nodeVal)); + } + } + } else if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) { + final String name = cat.getTaxonomyUri().substring(cat.getTaxonomyUri().indexOf("#") + 1, cat.getTaxonomyUri().length()); + o.getAttributes().add(new Attribute(name, cat.getName())); + } else { + if (category.length() > 0) { + category.append(", "); + } + + category.append(cat.getName()); + } + } + + if (!parentFound) { + root.add(o); + } + + if (category.length() > 0) { + o.getAttributes().add(new Attribute("category", category.toString())); + } + + final List links = Collections.synchronizedList(entry.getLinks()); + // final String entryLink = entry.getLink(); + + for (int j = 0; j < links.size(); j++) { + final SyndLink link = links.get(j); + + // if(link.getHref().equals(entryLink)) { + if (link.getType() != null && link.getRel() != null && link.getRel().equals("alternate") + && (link.getType().equals("application/rss+xml") || link.getType().equals("application/atom+xml"))) { + o.setType("rss"); + + if (o.getXmlUrl() == null) { + o.getAttributes().add(new Attribute("xmlUrl", link.getHref())); + } + } else if (link.getType() != null && link.getType().equals("text/html")) { + if (o.getHtmlUrl() == null) { + o.getAttributes().add(new Attribute("htmlUrl", link.getHref())); + } + } else { + o.setType(link.getType()); + } + + // } + } + + if (o.getType() == null || o.getType().equals("link")) { + o.setText(entry.getTitle()); + + } else { + o.setTitle(entry.getTitle()); + } + + if (o.getText() == null && entry.getDescription() != null) { + o.setText(entry.getDescription().getValue()); + } + } + + // Do back and parenting for things we missed. + for (int i = 0; i < doAfterPass.size(); i++) { + final OutlineHolder o = doAfterPass.get(i); + final Outline parent = entriesByNode.get(o.parent); + + if (parent == null) { + root.add(o.outline); + LOG.warn("Unable to find parent node: {}", o.parent); + } else { + parent.getChildren().add(o.outline); + } + } + + final Opml opml = new Opml(); + opml.setFeedType(getType()); + opml.setCreated(syndFeed.getPublishedDate()); + opml.setTitle(syndFeed.getTitle()); + + final List authors = Collections.synchronizedList(syndFeed.getAuthors()); + + for (int i = 0; i < authors.size(); i++) { + final SyndPerson p = authors.get(i); + + if (syndFeed.getAuthor() == null || syndFeed.getAuthor().equals(p.getName())) { + opml.setOwnerName(p.getName()); + opml.setOwnerEmail(p.getEmail()); + opml.setOwnerId(p.getUri()); + } + } + + opml.setOutlines(root); + + return opml; + } + + /** + * Returns the type (version) of the real feed this converter handles. + * + * @return the real feed type. + * @see WireFeed for details on the format of this string. + */ + @Override + public String getType() { + return "opml_1.0"; + } + + private static class OutlineHolder { + + private final Outline outline; + private final String parent; + + public OutlineHolder(final Outline outline, final String parent) { + this.outline = outline; + this.parent = parent; + } + + } + +} diff --git a/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML20.java b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML20.java index b467b46..672da88 100644 --- a/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML20.java +++ b/src/main/java/com/rometools/opml/feed/synd/impl/ConverterForOPML20.java @@ -1,67 +1,50 @@ -/* - * ConverterForOPML20.java - * - * Created on April 25, 2006, 5:29 PM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ -package com.rometools.opml.feed.synd.impl; - -import com.rometools.rome.feed.WireFeed; -import com.rometools.rome.feed.synd.SyndFeed; - -/** - * - * @author cooper - */ -public class ConverterForOPML20 extends ConverterForOPML10 { - /** Creates a new instance of ConverterForOPML20 */ - public ConverterForOPML20() { - super(); - } - - /** - * Returns the type (version) of the real feed this converter handles. - *

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

- */ - @Override - public String getType() { - return "opml_2.0"; - } - - /** - * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. - *

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

- * - * @param feed real feed to copy/convert. - * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real - * feed. - */ - @Override - public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { - super.copyInto(feed, syndFeed); - } - - /** - * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. - *

- * - * @param syndFeed SyndFeedImpl to copy/convert value from. - * @return a real feed with copied/converted values of the SyndFeedImpl. - */ - @Override - public WireFeed createRealFeed(final SyndFeed syndFeed) { - WireFeed retValue; - - retValue = super.createRealFeed(syndFeed); - - return retValue; - } -} +package com.rometools.opml.feed.synd.impl; + +import com.rometools.rome.feed.WireFeed; +import com.rometools.rome.feed.synd.SyndFeed; + +/** + * @author cooper + */ +public class ConverterForOPML20 extends ConverterForOPML10 { + + /** + * Returns the type (version) of the real feed this converter handles. + *

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

+ */ + @Override + public String getType() { + return "opml_2.0"; + } + + /** + * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. + *

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

+ * + * @param feed real feed to copy/convert. + * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. + */ + @Override + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + super.copyInto(feed, syndFeed); + } + + /** + * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. + *

+ * + * @param syndFeed SyndFeedImpl to copy/convert value from. + * @return a real feed with copied/converted values of the SyndFeedImpl. + */ + @Override + public WireFeed createRealFeed(final SyndFeed syndFeed) { + return super.createRealFeed(syndFeed); + } + +} diff --git a/src/main/java/com/rometools/opml/feed/synd/impl/TreeCategoryImpl.java b/src/main/java/com/rometools/opml/feed/synd/impl/TreeCategoryImpl.java index c3c8e18..b338798 100644 --- a/src/main/java/com/rometools/opml/feed/synd/impl/TreeCategoryImpl.java +++ b/src/main/java/com/rometools/opml/feed/synd/impl/TreeCategoryImpl.java @@ -1,38 +1,23 @@ -/* - * TreeCategoryImpl.java - * - * Created on April 27, 2006, 3:44 AM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ - -package com.rometools.opml.feed.synd.impl; - -import com.rometools.rome.feed.synd.SyndCategory; -import com.rometools.rome.feed.synd.SyndCategoryImpl; - -/** - * - * @author cooper - */ -public class TreeCategoryImpl extends SyndCategoryImpl { - - private static final long serialVersionUID = 1L; - - /** Creates a new instance of TreeCategoryImpl */ - public TreeCategoryImpl() { - super(); - } - - @Override - public boolean equals(final Object o) { - final SyndCategory c = (SyndCategory) o; - if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(getTaxonomyUri())) { - return true; - } else { - return false; - } - } - -} +package com.rometools.opml.feed.synd.impl; + +import com.rometools.rome.feed.synd.SyndCategory; +import com.rometools.rome.feed.synd.SyndCategoryImpl; + +/** + * @author cooper + */ +public class TreeCategoryImpl extends SyndCategoryImpl { + + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(final Object o) { + final SyndCategory c = (SyndCategory) o; + if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(getTaxonomyUri())) { + return true; + } else { + return false; + } + } + +} diff --git a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java index dfb0368..8851312 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java @@ -35,11 +35,10 @@ import com.rometools.rome.io.impl.BaseWireFeedGenerator; import com.rometools.rome.io.impl.DateParser; /** - * * @author Robert "kebernet" Cooper */ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { - /** Creates a new instance of Opml10Generator */ + public OPML10Generator() { super("opml_1.0"); } @@ -50,16 +49,16 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe /** * Creates an XML document (JDOM) for the given feed bean. - *

* * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not match - * with the type of the WireFeedGenerator. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the + * WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ @Override public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { + if (!(feed instanceof Opml)) { throw new IllegalArgumentException("Not an OPML file"); } @@ -88,9 +87,7 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe if (target == null || name == null || value == null) { return false; } - target.setAttribute(name, value.toString()); - return true; } diff --git a/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java index 576182e..02b1bf5 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java @@ -37,14 +37,12 @@ import com.rometools.rome.io.impl.BaseWireFeedParser; import com.rometools.rome.io.impl.DateParser; /** - * * @author Robert "kebernet" Cooper */ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { private static Logger LOG = LoggerFactory.getLogger(OPML10Parser.class); - /** Creates a new instance of Opml10Parser */ public OPML10Parser() { super("opml_1.0", null); } @@ -111,7 +109,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); } catch (final NumberFormatException nfe) { LOG.warn("Unable to parse windowBottom", nfe); - if (validate) { throw new FeedException("Unable to parse windowBottom", nfe); } @@ -121,13 +118,15 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); } catch (final NumberFormatException nfe) { LOG.warn("Unable to parse windowLeft", nfe); + if (validate) { + throw new FeedException("Unable to parse windowLeft", nfe); + } } try { opml.setWindowRight(readInteger(head.getChildText("windowRight"))); } catch (final NumberFormatException nfe) { LOG.warn("Unable to parse windowRight", nfe); - if (validate) { throw new FeedException("Unable to parse windowRight", nfe); } @@ -137,7 +136,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); } catch (final NumberFormatException nfe) { LOG.warn("Unable to parse windowLeft", nfe); - if (validate) { throw new FeedException("Unable to parse windowLeft", nfe); } @@ -147,7 +145,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { opml.setWindowTop(readInteger(head.getChildText("windowTop"))); } catch (final NumberFormatException nfe) { LOG.warn("Unable to parse windowTop", nfe); - if (validate) { throw new FeedException("Unable to parse windowTop", nfe); } @@ -157,7 +154,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); } catch (final NumberFormatException nfe) { LOG.warn("Unable to parse expansionState", nfe); - if (validate) { throw new FeedException("Unable to parse expansionState", nfe); } diff --git a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java index c87dbfe..dfc4137 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java @@ -1,11 +1,3 @@ -/* - * OPML20Generator.java - * - * Created on April 25, 2006, 5:31 PM - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ package com.rometools.opml.io.impl; import java.util.Locale; @@ -20,21 +12,18 @@ import com.rometools.rome.io.FeedException; import com.rometools.rome.io.impl.DateParser; /** - * * @author cooper */ public class OPML20Generator extends OPML10Generator { - /** Creates a new instance of OPML20Generator */ + public OPML20Generator() { } /** * Returns the type of feed the generator creates. - *

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

*/ @Override public String getType() { @@ -43,47 +32,43 @@ public class OPML20Generator extends OPML10Generator { /** * Creates an XML document (JDOM) for the given feed bean. - *

* * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). - * @throws IllegalArgumentException thrown if the type of the given feed bean does not match - * with the type of the WireFeedGenerator. + * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the + * WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ @Override public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { - Document retValue; - - retValue = super.generate(feed); + final Document retValue = super.generate(feed); retValue.getRootElement().setAttribute("version", "2.0"); - return retValue; } @Override protected Element generateHead(final Opml opml) { - Element retValue; - - retValue = super.generateHead(opml); final Element docs = new Element("docs"); docs.setText(opml.getDocs()); - retValue.addContent(docs); + final Element retValue = super.generateHead(opml); + retValue.addContent(docs); return retValue; + } @Override protected Element generateOutline(final Outline outline) { - Element retValue; - retValue = super.generateOutline(outline); + final Element retValue = super.generateOutline(outline); if (outline.getCreated() != null) { retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated(), Locale.US)); } return retValue; + } + } From 6e8590ba8ecf6801b2787193a94bb34a37941072 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 8 Jan 2016 19:55:35 +0100 Subject: [PATCH 44/47] The category attribute of outlines will now be exported --- pom.xml | 4 ++ .../opml/io/impl/OPML20Generator.java | 48 ++++++++++++----- .../opml/io/impl/OPML20GeneratorTest.java | 52 +++++++++++++++++++ 3 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java diff --git a/pom.xml b/pom.xml index e58c56b..b8d6cc4 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,10 @@ junit test + + org.hamcrest + hamcrest-library + xmlunit xmlunit diff --git a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java index dfc4137..a774291 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java @@ -1,5 +1,7 @@ package com.rometools.opml.io.impl; +import java.util.Collection; +import java.util.List; import java.util.Locale; import org.jdom2.Document; @@ -12,7 +14,9 @@ import com.rometools.rome.io.FeedException; import com.rometools.rome.io.impl.DateParser; /** - * @author cooper + * Generator for OPML 2.0 documents. + * + * @see http://dev.opml.org/spec2.html */ public class OPML20Generator extends OPML10Generator { @@ -41,34 +45,54 @@ public class OPML20Generator extends OPML10Generator { */ @Override public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { - final Document retValue = super.generate(feed); - retValue.getRootElement().setAttribute("version", "2.0"); - return retValue; + final Document document = super.generate(feed); + document.getRootElement().setAttribute("version", "2.0"); + return document; } @Override protected Element generateHead(final Opml opml) { - final Element docs = new Element("docs"); - docs.setText(opml.getDocs()); + final Element docsElement = new Element("docs"); + docsElement.setText(opml.getDocs()); - final Element retValue = super.generateHead(opml); - retValue.addContent(docs); - return retValue; + final Element headElement = super.generateHead(opml); + headElement.addContent(docsElement); + return headElement; } @Override protected Element generateOutline(final Outline outline) { - final Element retValue = super.generateOutline(outline); + final Element outlineElement = super.generateOutline(outline); if (outline.getCreated() != null) { - retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated(), Locale.US)); + outlineElement.setAttribute("created", DateParser.formatRFC822(outline.getCreated(), Locale.US)); } - return retValue; + final List categories = outline.getCategories(); + final String categoriesValue = generateCategoriesValue(categories); + addNotNullAttribute(outlineElement, "category", categoriesValue); + + return outlineElement; } + private String generateCategoriesValue(final Collection categories) { + final StringBuilder builder = new StringBuilder(); + for (final String category : categories) { + if (category != null && !category.trim().isEmpty()) { + builder.append("/"); + builder.append(category.trim()); + } + } + final String categoryString = builder.toString(); + if (categoryString == null || categoryString.trim().isEmpty()) { + return null; + } else { + return categoryString; + } + } + } diff --git a/src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java b/src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java new file mode 100644 index 0000000..d4359b8 --- /dev/null +++ b/src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java @@ -0,0 +1,52 @@ +package com.rometools.opml.io.impl; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.custommonkey.xmlunit.XMLUnit; +import org.custommonkey.xmlunit.exceptions.XpathException; +import org.junit.Test; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import com.rometools.opml.feed.opml.Opml; +import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.WireFeedOutput; + +public class OPML20GeneratorTest { + + @Test + public void testCategoryOutput() throws IllegalArgumentException, FeedException, SAXException, IOException, XpathException { + checkCategoryOutput(null, ""); + checkCategoryOutput(Arrays.asList("category1"), "/category1"); + checkCategoryOutput(Arrays.asList("category1", "category2"), "/category1/category2"); + } + + private void checkCategoryOutput(final List categories, final String asserted) + throws IllegalArgumentException, FeedException, SAXException, IOException, XpathException { + + final Outline outline = new Outline("outline1", null); + outline.setCategories(categories); + final List outlines = Arrays.asList(outline); + + final Opml opml = new Opml(); + opml.setFeedType("opml_2.0"); + opml.setTitle("title"); + opml.setOutlines(outlines); + + final WireFeedOutput output = new WireFeedOutput(); + final String xml = output.outputString(opml); + + final Document document = XMLUnit.buildControlDocument(xml); + final String categoryValue = XMLUnit.newXpathEngine().evaluate("/opml/body/outline/@category", document); + assertThat(categoryValue, is(equalTo(asserted))); + + } + +} From db6138b4406aa029ad9b101cebb12a7c2376b947 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 8 Jan 2016 19:58:28 +0100 Subject: [PATCH 45/47] Removed useless trim --- src/main/java/com/rometools/opml/io/impl/OPML20Generator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java index a774291..b83379b 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java @@ -88,7 +88,7 @@ public class OPML20Generator extends OPML10Generator { } } final String categoryString = builder.toString(); - if (categoryString == null || categoryString.trim().isEmpty()) { + if (categoryString == null || categoryString.isEmpty()) { return null; } else { return categoryString; From 5133609c6e7b0bf3c581d63eececd4f9bc40e861 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Fri, 8 Jan 2016 20:03:46 +0100 Subject: [PATCH 46/47] Refactored category value creation --- .../rometools/opml/io/impl/OPML20Generator.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java index b83379b..8845c82 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java @@ -72,27 +72,30 @@ public class OPML20Generator extends OPML10Generator { } final List categories = outline.getCategories(); - final String categoriesValue = generateCategoriesValue(categories); - addNotNullAttribute(outlineElement, "category", categoriesValue); + final String categoryValue = generateCategoryValue(categories); + addNotNullAttribute(outlineElement, "category", categoryValue); return outlineElement; } - private String generateCategoriesValue(final Collection categories) { + private String generateCategoryValue(final Collection categories) { + final StringBuilder builder = new StringBuilder(); + for (final String category : categories) { if (category != null && !category.trim().isEmpty()) { builder.append("/"); builder.append(category.trim()); } } - final String categoryString = builder.toString(); - if (categoryString == null || categoryString.isEmpty()) { - return null; + + if (builder.length() > 0) { + return builder.toString(); } else { - return categoryString; + return null; } + } } From 4eefb566e86dd48ee16912986daa1cb59461e80f Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 9 Jan 2016 01:52:09 +0100 Subject: [PATCH 47/47] Fixed wrong category concatenation --- .../opml/io/impl/OPML20Generator.java | 7 +- .../opml/io/impl/OPML20GeneratorTest.java | 67 ++++++++++++------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java index 8845c82..96ff4ae 100644 --- a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java +++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java @@ -83,9 +83,14 @@ public class OPML20Generator extends OPML10Generator { final StringBuilder builder = new StringBuilder(); + boolean first = true; for (final String category : categories) { if (category != null && !category.trim().isEmpty()) { - builder.append("/"); + if (first) { + first = false; + } else { + builder.append(","); + } builder.append(category.trim()); } } diff --git a/src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java b/src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java index d4359b8..28dd3d1 100644 --- a/src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java +++ b/src/test/java/com/rometools/opml/io/impl/OPML20GeneratorTest.java @@ -4,49 +4,70 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import java.io.IOException; import java.util.Arrays; -import java.util.List; import org.custommonkey.xmlunit.XMLUnit; -import org.custommonkey.xmlunit.exceptions.XpathException; import org.junit.Test; import org.w3c.dom.Document; -import org.xml.sax.SAXException; +import org.w3c.dom.NodeList; import com.rometools.opml.feed.opml.Opml; import com.rometools.opml.feed.opml.Outline; -import com.rometools.rome.io.FeedException; import com.rometools.rome.io.WireFeedOutput; public class OPML20GeneratorTest { @Test - public void testCategoryOutput() throws IllegalArgumentException, FeedException, SAXException, IOException, XpathException { - checkCategoryOutput(null, ""); - checkCategoryOutput(Arrays.asList("category1"), "/category1"); - checkCategoryOutput(Arrays.asList("category1", "category2"), "/category1/category2"); + public void testOutputOfNullCategory() { + assertThat(categoryOf((String) null).getLength(), is(equalTo(0))); } - private void checkCategoryOutput(final List categories, final String asserted) - throws IllegalArgumentException, FeedException, SAXException, IOException, XpathException { + @Test + public void testOutputOfEmptyCategory() { + assertThat(categoryOf("").getLength(), is(equalTo(0))); + } - final Outline outline = new Outline("outline1", null); - outline.setCategories(categories); - final List outlines = Arrays.asList(outline); + @Test + public void testOutputOfBlankCategory() { + assertThat(categoryOf(" ").getLength(), is(equalTo(0))); + } - final Opml opml = new Opml(); - opml.setFeedType("opml_2.0"); - opml.setTitle("title"); - opml.setOutlines(outlines); + @Test + public void testOutputOfOneCategory() { + assertThat(categoryValueOf("category1"), is(equalTo("category1"))); + } - final WireFeedOutput output = new WireFeedOutput(); - final String xml = output.outputString(opml); + @Test + public void testOutputOfMultipleCategories() { + assertThat(categoryValueOf("category1", "category2"), is(equalTo("category1,category2"))); + } - final Document document = XMLUnit.buildControlDocument(xml); - final String categoryValue = XMLUnit.newXpathEngine().evaluate("/opml/body/outline/@category", document); - assertThat(categoryValue, is(equalTo(asserted))); + private NodeList categoryOf(final String... categories) { + try { + + final Outline outline = new Outline("outline1", null); + outline.setCategories(Arrays.asList(categories)); + + final Opml opml = new Opml(); + opml.setFeedType("opml_2.0"); + opml.setTitle("title"); + opml.setOutlines(Arrays.asList(outline)); + + final WireFeedOutput output = new WireFeedOutput(); + final String xml = output.outputString(opml); + + final Document document = XMLUnit.buildControlDocument(xml); + return XMLUnit.newXpathEngine().getMatchingNodes("/opml/body/outline/@category", document); + + } catch (final Exception e) { + throw new RuntimeException(e); + } + + } + + private String categoryValueOf(final String... categories) { + return categoryOf(categories).item(0).getNodeValue(); } }