diff --git a/src/main/java/com/sun/syndication/feed/CopyFrom.java b/src/main/java/com/sun/syndication/feed/CopyFrom.java index fbcad95..09d07c8 100644 --- a/src/main/java/com/sun/syndication/feed/CopyFrom.java +++ b/src/main/java/com/sun/syndication/feed/CopyFrom.java @@ -25,9 +25,10 @@ public interface CopyFrom { /** * Returns the interface the copyFrom works on. *

- * This is useful when dealing with properties that may have multiple implementations. - * For example, Module. + * This is useful when dealing with properties that may have multiple + * implementations. For example, Module. *

+ * * @return the interface the copyFrom works on. */ public Class getInterface(); @@ -37,11 +38,13 @@ public interface CopyFrom { *

* Any existing properties in this bean are lost. *

- * This method is useful for moving from one implementation of a bean interface to another. - * For example from the default SyndFeed bean implementation to a Hibernate ready implementation. + * This method is useful for moving from one implementation of a bean + * interface to another. For example from the default SyndFeed bean + * implementation to a Hibernate ready implementation. *

+ * * @param obj the instance to copy properties from. - * + * */ public void copyFrom(CopyFrom obj); diff --git a/src/main/java/com/sun/syndication/feed/WireFeed.java b/src/main/java/com/sun/syndication/feed/WireFeed.java index 670427e..2415b48 100644 --- a/src/main/java/com/sun/syndication/feed/WireFeed.java +++ b/src/main/java/com/sun/syndication/feed/WireFeed.java @@ -17,32 +17,33 @@ */ package com.sun.syndication.feed; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.module.Module; -import com.sun.syndication.feed.module.impl.ModuleUtils; -import com.sun.syndication.feed.module.Extendable; - -import java.util.List; -import java.util.ArrayList; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import org.jdom2.Element; +import com.sun.syndication.feed.impl.ObjectBean; +import com.sun.syndication.feed.module.Extendable; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.feed.module.impl.ModuleUtils; + /** * Parent class of the RSS (Channel) and Atom (Feed) feed beans. *

- * NOTE: We don't like this class at this package level but the alternative would have - * been a proliferation of packages (one more level to hold atom and rss package with - * this class just in that package). + * NOTE: We don't like this class at this package level but the alternative + * would have been a proliferation of packages (one more level to hold atom and + * rss package with this class just in that package). *

- * The format of the 'type' property must be [FEEDNAME]_[FEEDVERSION] with the FEEDNAME in lower case, - * for example: rss_0.9, rss_0.93, atom_0.3 + * The format of the 'type' property must be [FEEDNAME]_[FEEDVERSION] with the + * FEEDNAME in lower case, for example: rss_0.9, rss_0.93, atom_0.3 *

+ * * @author Alejandro Abdelnur - * + * */ public abstract class WireFeed implements Cloneable, Serializable, Extendable { - private ObjectBean _objBean; + private final ObjectBean _objBean; private String _feedType; private String _encoding; private List _modules; @@ -51,54 +52,59 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable { /** * Default constructor, for bean cloning purposes only. *

- * + * */ protected WireFeed() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a feed for a given type. *

+ * * @param type of the feed to create. - * + * */ - protected WireFeed(String type) { + protected WireFeed(final String type) { this(); - _feedType = type; + this._feedType = type; } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { + public boolean equals(final Object other) { if (other == null) { return false; } - if (!(other instanceof WireFeed)){ + if (!(other instanceof WireFeed)) { return false; } // can't use foreign markup in equals, due to JDOM equals impl - List fm = getForeignMarkup(); - setForeignMarkup(((WireFeed)other).getForeignMarkup()); - boolean ret = _objBean.equals(other); + final List fm = getForeignMarkup(); + setForeignMarkup(((WireFeed) other).getForeignMarkup()); + final boolean ret = this._objBean.equals(other); // restore foreign markup setForeignMarkup(fm); return ret; @@ -109,124 +115,133 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } - - - - /** - * Sets the feedType of a the feed. Do not use, for bean cloning purposes only. + * Sets the feedType of a the feed. Do not use, for bean cloning + * purposes only. *

+ * * @param feedType the feedType of the feed. - * + * */ - public void setFeedType(String feedType) { - _feedType = feedType; + public void setFeedType(final String feedType) { + this._feedType = feedType; } /** * Returns the type of the feed. - * + * * @return the type of the feed. */ public String getFeedType() { - return _feedType; + return this._feedType; } /** * Returns the charset encoding of a the feed. *

- * This property is not set by feed parsers. But it is used by feed generators - * to set the encoding in the XML prolog. + * This property is not set by feed parsers. But it is used by feed + * generators to set the encoding in the XML prolog. *

+ * * @return the charset encoding of the feed. - * + * */ public String getEncoding() { - return _encoding; + return this._encoding; } /** * Sets the charset encoding of a the feed. *

- * This property is not set by feed parsers. But it is used by feed generators - * to set the encoding in the XML prolog. + * This property is not set by feed parsers. But it is used by feed + * generators to set the encoding in the XML prolog. *

+ * * @param encoding the charset encoding of the feed. - * + * */ - public void setEncoding(String encoding) { - _encoding = encoding; + public void setEncoding(final String encoding) { + this._encoding = encoding; } - /** * Returns the channel modules. *

- * @return a list of ModuleImpl elements with the channel modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the channel modules, an empty + * list if none. + * */ + @Override public List getModules() { - return (_modules==null) ? (_modules=new ArrayList()) : _modules; + return this._modules == null ? (this._modules = new ArrayList()) : this._modules; } /** * Sets the channel modules. *

- * @param modules the list of ModuleImpl elements with the channel modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the channel modules + * to set, an empty list or null if none. + * */ - public void setModules(List modules) { - _modules = modules; + @Override + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ - public Module getModule(String uri) { - return ModuleUtils.getModule(_modules,uri); + @Override + public Module getModule(final String uri) { + return ModuleUtils.getModule(this._modules, uri); } /** * Returns foreign markup found at channel level. *

+ * * @return Opaque object to discourage use - * + * */ public List getForeignMarkup() { - return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup; + return this._foreignMarkup == null ? (this._foreignMarkup = new ArrayList()) : this._foreignMarkup; } /** * Sets foreign markup found at channel level. *

+ * * @param foreignMarkup Opaque object to discourage use - * + * */ - public void setForeignMarkup(List foreignMarkup) { - _foreignMarkup = (List)foreignMarkup; + public void setForeignMarkup(final List foreignMarkup) { + this._foreignMarkup = foreignMarkup; } } diff --git a/src/main/java/com/sun/syndication/feed/atom/Category.java b/src/main/java/com/sun/syndication/feed/atom/Category.java index f521957..8df3f8f 100644 --- a/src/main/java/com/sun/syndication/feed/atom/Category.java +++ b/src/main/java/com/sun/syndication/feed/atom/Category.java @@ -16,58 +16,63 @@ */ package com.sun.syndication.feed.atom; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for category elements of Atom feeds. *

+ * * @author Dave Johnson (added for Atom 1.0) */ -public class Category implements Cloneable, Serializable { - - private ObjectBean _objBean; - +public class Category implements Cloneable, Serializable { + + private final ObjectBean _objBean; + private String _term; - private String _scheme; - private String _schemeResolved; + private String _scheme; + private String _schemeResolved; private String _label; /** * Default constructor. All properties are set to null. *

- * + * */ public Category() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Category)){ + public boolean equals(final Object other) { + if (!(other instanceof Category)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -75,84 +80,92 @@ public class Category implements Cloneable, Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } - - /** + + /** * Get label for category. *

+ * * @return Label for category. */ public String getLabel() { - return _label; + return this._label; } - + /** * Set label for category. *

+ * * @param label Label for category. */ - public void setLabel(String label) { + public void setLabel(final String label) { this._label = label; } - + /** * Get Scheme URI for category. *

+ * * @return Scheme URI for category. */ public String getScheme() { - return _scheme; + return this._scheme; } - + /** * Set scheme URI for category. *

+ * * @param scheme Scheme URI for category. */ - public void setScheme(String scheme) { + public void setScheme(final String scheme) { this._scheme = scheme; } - - public void setSchemeResolved(String schemeResolved) { - _schemeResolved = schemeResolved; + + public void setSchemeResolved(final String schemeResolved) { + this._schemeResolved = schemeResolved; } public String getSchemeResolved() { - return _schemeResolved != null ? _schemeResolved : _scheme; + return this._schemeResolved != null ? this._schemeResolved : this._scheme; } /** * Return term for category. *

+ * * @return Term for category. */ public String getTerm() { - return _term; + return this._term; } - + /** * Set term for category. *

+ * * @param term Term for category. */ - public void setTerm(String term) { + public void setTerm(final String term) { this._term = term; } } diff --git a/src/main/java/com/sun/syndication/feed/atom/Content.java b/src/main/java/com/sun/syndication/feed/atom/Content.java index 8e90181..43c752a 100644 --- a/src/main/java/com/sun/syndication/feed/atom/Content.java +++ b/src/main/java/com/sun/syndication/feed/atom/Content.java @@ -16,45 +16,46 @@ */ package com.sun.syndication.feed.atom; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; import java.util.HashSet; import java.util.Set; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for content elements of Atom feeds. *

+ * * @author Alejandro Abdelnur * @author Dave Johnson (updated for Atom 1.0) */ -public class Content implements Cloneable,Serializable { - - private ObjectBean _objBean; - +public class Content implements Cloneable, Serializable { + + private final ObjectBean _objBean; + private String _type; private String _value; - private String _src; - + private String _src; + /** @since Atom 1.0 */ public static final String TEXT = "text"; - + /** @since Atom 1.0 */ public static final String HTML = "html"; - + /** @since Atom 1.0 */ public static final String XHTML = "xhtml"; /** Atom 0.3 only */ - public static final String XML = "xml"; - - /** Atom 0.3 only */ - public static final String BASE64 = "base64"; - - /** Atom 0.3 only */ - public static final String ESCAPED = "escaped"; + public static final String XML = "xml"; - private String _mode; + /** Atom 0.3 only */ + public static final String BASE64 = "base64"; + + /** Atom 0.3 only */ + public static final String ESCAPED = "escaped"; + + private String _mode; private static final Set MODES = new HashSet(); static { MODES.add(XML); @@ -62,41 +63,44 @@ public class Content implements Cloneable,Serializable { MODES.add(ESCAPED); } - /** * Default constructor. All properties are set to null. *

- * + * */ public Content() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Content)){ + public boolean equals(final Object other) { + if (!(other instanceof Content)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -104,23 +108,25 @@ public class Content implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** @@ -128,10 +134,11 @@ public class Content implements Cloneable,Serializable { *

* The type indicates how the value was/will-be encoded in the XML feed. *

+ * * @since Atom 1.0 */ public String getType() { - return _type; + return this._type; } /** @@ -139,10 +146,11 @@ public class Content implements Cloneable,Serializable { *

* The type indicates how the value was/will-be encoded in the XML feed. *

+ * * @since Atom 1.0 */ - public void setType(String type) { - _type = type; + public void setType(final String type) { + this._type = type; } /** @@ -150,10 +158,11 @@ public class Content implements Cloneable,Serializable { *

* The mode indicates how the value was/will-be encoded in the XML feed. *

+ * * @return the content mode, null if none. */ public String getMode() { - return _mode; + return this._mode; } /** @@ -161,14 +170,15 @@ public class Content implements Cloneable,Serializable { *

* The mode indicates how the value was/will-be encoded in the XML feed. *

+ * * @param mode the content mode, null if none. */ public void setMode(String mode) { - mode = (mode!=null) ? mode.toLowerCase() : null; - if (mode==null || !MODES.contains(mode)) { - throw new IllegalArgumentException("Invalid mode ["+mode+"]"); + mode = mode != null ? mode.toLowerCase() : null; + if (mode == null || !MODES.contains(mode)) { + throw new IllegalArgumentException("Invalid mode [" + mode + "]"); } - _mode = mode; + this._mode = mode; } /** @@ -176,11 +186,12 @@ public class Content implements Cloneable,Serializable { *

* The return value should be decoded. *

+ * * @return the content value, null if none. - * + * */ public String getValue() { - return _value; + return this._value; } /** @@ -188,32 +199,33 @@ public class Content implements Cloneable,Serializable { *

* The value being set should be decoded. *

+ * * @param value the content value, null if none. - * + * */ - public void setValue(String value) { - _value = value; + public void setValue(final String value) { + this._value = value; } /** * Returns the src *

+ * * @return Returns the src. * @since Atom 1.0 */ public String getSrc() { - return _src; + return this._src; } - + /** * Set the src *

+ * * @param src The src to set. * @since Atom 1.0 */ - public void setSrc(String src) { - _src = src; + public void setSrc(final String src) { + this._src = src; } } - - diff --git a/src/main/java/com/sun/syndication/feed/atom/Entry.java b/src/main/java/com/sun/syndication/feed/atom/Entry.java index e26363d..aec7cff 100644 --- a/src/main/java/com/sun/syndication/feed/atom/Entry.java +++ b/src/main/java/com/sun/syndication/feed/atom/Entry.java @@ -19,7 +19,6 @@ package com.sun.syndication.feed.atom; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; import java.util.List; import org.jdom2.Element; @@ -29,10 +28,10 @@ import com.sun.syndication.feed.module.Extendable; import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.module.impl.ModuleUtils; - /** * Bean for entry elements of Atom feeds. *

+ * * @author Alejandro Abdelnur * @author Dave Johnson (updated for Atom 1.0) */ @@ -40,7 +39,7 @@ public class Entry implements Cloneable, Serializable, Extendable { private Content _summary; private Content _title; private Date _created; // Atom 0.3 only - private Date _published; // AKA issued + private Date _published; // AKA issued private Date _updated; // AKA modified private Feed _source; private List _alternateLinks; @@ -51,7 +50,7 @@ public class Entry implements Cloneable, Serializable, Extendable { private List _foreignMarkup; private List _modules; private List _otherLinks; - private ObjectBean _objBean; + private final ObjectBean _objBean; private String _id; private String _rights; private String _xmlBase; @@ -59,201 +58,220 @@ public class Entry implements Cloneable, Serializable, Extendable { /** * Default constructor. All properties are set to null. *

- * + * */ public Entry() { - _objBean = new ObjectBean(this.getClass(), this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Sets the entry alternate links. *

- * @param alternateLinks the list of Link elements with the entry alternate links to set, - * an empty list or null if none. + * + * @param alternateLinks the list of Link elements with the entry alternate + * links to set, an empty list or null if none. */ - public void setAlternateLinks(List alternateLinks) { - _alternateLinks = alternateLinks; + public void setAlternateLinks(final List alternateLinks) { + this._alternateLinks = alternateLinks; } /** * Returns the entry alternate links. *

- * @return a list of Link elements with the entry alternate links, an empty list if none. + * + * @return a list of Link elements with the entry alternate links, an empty + * list if none. */ public List getAlternateLinks() { - return (_alternateLinks == null) ? (_alternateLinks = new ArrayList()) : _alternateLinks; + return this._alternateLinks == null ? (this._alternateLinks = new ArrayList()) : this._alternateLinks; } /** * Sets the author of the entry. *

+ * * @param authors the author of the entry, null if none. - * + * */ - public void setAuthors(List authors) { - _authors = authors; + public void setAuthors(final List authors) { + this._authors = authors; } /** * Returns the entry author. *

+ * * @return the entry author, null if none. - * + * */ public List getAuthors() { - return (_authors == null) ? (_authors = new ArrayList()) : _authors; + return this._authors == null ? (this._authors = new ArrayList()) : this._authors; } /** * Set the categories *

+ * * @param categories The categories to set. * @since Atom 1.0 */ - public void setCategories(List categories) { - _categories = categories; + public void setCategories(final List categories) { + this._categories = categories; } /** * Returns the categories *

+ * * @return Returns the categories. * @since Atom 1.0 */ public List getCategories() { - return (_categories == null) ? (_categories = new ArrayList()) : _categories; + return this._categories == null ? (this._categories = new ArrayList()) : this._categories; } /** * Sets the entry contents. *

- * @param contents the list of Content elements with the entry contents to set, - * an empty list or null if none. + * + * @param contents the list of Content elements with the entry contents to + * set, an empty list or null if none. */ - public void setContents(List contents) { - _contents = contents; + public void setContents(final List contents) { + this._contents = contents; } /** * Returns the entry contents. *

- * @return a list of Content elements with the entry contents, - * an empty list if none. + * + * @return a list of Content elements with the entry contents, an empty list + * if none. */ public List getContents() { - return (_contents == null) ? (_contents = new ArrayList()) : _contents; + return this._contents == null ? (this._contents = new ArrayList()) : this._contents; } /** * Sets the entry contributors. *

- * @param contributors the list of Person elements with the entry contributors to set, - * an empty list or null if none. - * + * + * @param contributors the list of Person elements with the entry + * contributors to set, an empty list or null if none. + * */ - public void setContributors(List contributors) { - _contributors = contributors; + public void setContributors(final List contributors) { + this._contributors = contributors; } /** * Returns the entry contributors. *

- * @return a list of Person elements with the entry contributors, - * an empty list if none. - * + * + * @return a list of Person elements with the entry contributors, an empty + * list if none. + * */ public List getContributors() { - return (_contributors == null) ? (_contributors = new ArrayList()) : _contributors; + return this._contributors == null ? (this._contributors = new ArrayList()) : this._contributors; } /** * Sets the entry created date (Atom 0.3 only) *

+ * * @param created the entry created date, null if none. */ - public void setCreated(Date created) { - _created = new Date(created.getTime()); + public void setCreated(final Date created) { + this._created = new Date(created.getTime()); } /** * Returns the entry created date (Atom 0.3 only) *

+ * * @return the entry created date, null if none. */ public Date getCreated() { - return _created == null ? null : new Date(_created.getTime()); + return this._created == null ? null : new Date(this._created.getTime()); } /** * Sets foreign markup found at entry level. *

+ * * @param foreignMarkup Opaque object to discourage use - * + * */ - public void setForeignMarkup(List foreignMarkup) { - _foreignMarkup = (List) foreignMarkup; + public void setForeignMarkup(final List foreignMarkup) { + this._foreignMarkup = foreignMarkup; } /** * Returns foreign markup found at entry level. *

+ * * @return list of Opaque object to discourage use - * + * */ public List getForeignMarkup() { - return (_foreignMarkup == null) ? (_foreignMarkup = new ArrayList()) : _foreignMarkup; + return this._foreignMarkup == null ? (this._foreignMarkup = new ArrayList()) : this._foreignMarkup; } /** * Sets the entry ID. *

+ * * @param id the entry ID, null if none. - * + * */ - public void setId(String id) { - _id = id; + public void setId(final String id) { + this._id = id; } /** * Returns the entry ID. *

+ * * @return the entry ID, null if none. - * + * */ public String getId() { - return _id; + return this._id; } /** - * Sets the entry issued date (Atom 0.3, maps to {@link #setPublished(java.util.Date)}). + * Sets the entry issued date (Atom 0.3, maps to + * {@link #setPublished(java.util.Date)}). *

+ * * @param issued the entry issued date, null if none. */ - public void setIssued(Date issued) { - _published = issued == null ? null : new Date(issued.getTime()); + public void setIssued(final Date issued) { + this._published = issued == null ? null : new Date(issued.getTime()); } /** - * Returns the entry issued date (Atom 0.3, maps to {@link #getPublished()}). + * Returns the entry issued date (Atom 0.3, maps to {@link #getPublished()} + * ). *

+ * * @return the entry issued date, null if none. */ public Date getIssued() { - return _published == null ? null : new Date(_published.getTime()); + return this._published == null ? null : new Date(this._published.getTime()); } /** * Returns true if entry is a media entry, i.e. has rel="edit-media". - * + * * @return true if entry is a media entry */ public boolean isMediaEntry() { boolean mediaEntry = false; - List links = getOtherLinks(); - - for (Iterator it = links.iterator(); it.hasNext();) { - Link link = it.next(); + final List links = getOtherLinks(); + for (final Link link : links) { if ("edit-media".equals(link.getRel())) { mediaEntry = true; @@ -265,176 +283,198 @@ public class Entry implements Cloneable, Serializable, Extendable { } /** - * Sets the entry modified date (Atom 0.3, maps to {@link #setUpdated(java.util.Date)}). + * Sets the entry modified date (Atom 0.3, maps to + * {@link #setUpdated(java.util.Date)}). *

+ * * @param modified the entry modified date, null if none. */ - public void setModified(Date modified) { - _updated = modified == null ? null : new Date(modified.getTime()); + public void setModified(final Date modified) { + this._updated = modified == null ? null : new Date(modified.getTime()); } /** - * Returns the entry modified date (Atom 0.3, maps to {@link #getUpdated()}). + * Returns the entry modified date (Atom 0.3, maps to {@link #getUpdated()} + * ). *

+ * * @return the entry modified date, null if none. */ public Date getModified() { - return _updated == null ? null : new Date(_updated.getTime()); + return this._updated == null ? null : new Date(this._updated.getTime()); } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ - public Module getModule(String uri) { - return ModuleUtils.getModule(_modules, uri); + @Override + public Module getModule(final String uri) { + return ModuleUtils.getModule(this._modules, uri); } /** * Sets the entry modules. *

- * @param modules the list of ModuleImpl elements with the entry modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the entry modules to + * set, an empty list or null if none. + * */ - public void setModules(List modules) { - _modules = modules; + @Override + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the entry modules. *

- * @return a list of ModuleImpl elements with the entry modules, - * an emtpy list if none. - * + * + * @return a list of ModuleImpl elements with the entry modules, an emtpy + * list if none. + * */ + @Override public List getModules() { - return (_modules == null) ? (_modules = new ArrayList()) : _modules; + return this._modules == null ? (this._modules = new ArrayList()) : this._modules; } /** * Sets the entry non-alternate links. *

- * @param otherLinks the list Link elements with the entry non-alternate links to set, - * an empty list or null if none. + * + * @param otherLinks the list Link elements with the entry non-alternate + * links to set, an empty list or null if none. */ - public void setOtherLinks(List otherLinks) { - _otherLinks = otherLinks; + public void setOtherLinks(final List otherLinks) { + this._otherLinks = otherLinks; } /** * Returns the entry non-alternate links. *

- * @return the list of Link elements with the entry non-alternate links to set, - * an empty list if none. + * + * @return the list of Link elements with the entry non-alternate links to + * set, an empty list if none. */ public List getOtherLinks() { - return (_otherLinks == null) ? (_otherLinks = new ArrayList()) : _otherLinks; + return this._otherLinks == null ? (this._otherLinks = new ArrayList()) : this._otherLinks; } /** * Set the published *

+ * * @param published The published to set. * @since Atom 1.0 */ - public void setPublished(Date published) { - _published = published == null ? null : new Date(published.getTime()); + public void setPublished(final Date published) { + this._published = published == null ? null : new Date(published.getTime()); } /** * Returns the published *

+ * * @return Returns the published. * @since Atom 1.0 */ public Date getPublished() { - return _published == null ? null : new Date(_published.getTime()); + return this._published == null ? null : new Date(this._published.getTime()); } /** * Set the rights *

+ * * @param rights The rights to set. * @since Atom 1.0 */ - public void setRights(String rights) { - _rights = rights; + public void setRights(final String rights) { + this._rights = rights; } /** * Returns the rights *

+ * * @return Returns the rights. * @since Atom 1.0 */ public String getRights() { - return _rights; + return this._rights; } /** * Set the source *

+ * * @param source The source to set. */ - public void setSource(Feed source) { - _source = source; + public void setSource(final Feed source) { + this._source = source; } /** * Returns the source *

+ * * @return Returns the source. */ public Feed getSource() { - return _source; + return this._source; } /** * Sets the entry summary. *

+ * * @param summary the entry summary, null if none. - * + * */ - public void setSummary(Content summary) { - _summary = summary; + public void setSummary(final Content summary) { + this._summary = summary; } /** * Returns the entry summary. *

- * @return the entry summary, null if none. - * + * + * @return the entry summary, null if none. + * */ public Content getSummary() { - return _summary; + return this._summary; } /** * Sets the entry title. *

+ * * @param title the entry title, null if none. - * + * */ - public void setTitle(String title) { - if (_title == null) { - _title = new Content(); + public void setTitle(final String title) { + if (this._title == null) { + this._title = new Content(); } - _title.setValue(title); + this._title.setValue(title); } /** * Returns the entry title. *

+ * * @return the entry title, null if none. - * + * */ public String getTitle() { - if (_title != null) { - return _title.getValue(); + if (this._title != null) { + return this._title.getValue(); } return null; @@ -443,95 +483,105 @@ public class Entry implements Cloneable, Serializable, Extendable { /** * Sets the entry title as a text construct. *

+ * * @param title the entry title, null if none. - * + * */ - public void setTitleEx(Content title) { - _title = title; + public void setTitleEx(final Content title) { + this._title = title; } /** * Returns the entry title as a text construct. *

+ * * @return the entry title, null if none. - * + * */ public Content getTitleEx() { - return _title; + return this._title; } /** * Set the updated *

+ * * @param updated The updated to set. * @since Atom 1.0 */ - public void setUpdated(Date updated) { - _updated = updated == null? null : new Date(updated.getTime()); + public void setUpdated(final Date updated) { + this._updated = updated == null ? null : new Date(updated.getTime()); } /** * Returns the updated *

+ * * @return Returns the updated. * @since Atom 1.0 */ public Date getUpdated() { - return _updated == null ? null : new Date(_updated.getTime()); + return this._updated == null ? null : new Date(this._updated.getTime()); } /** * Set the xmlBase *

+ * * @param xmlBase The xmlBase to set. * @since Atom 1.0 */ - public void setXmlBase(String xmlBase) { - _xmlBase = xmlBase; + public void setXmlBase(final String xmlBase) { + this._xmlBase = xmlBase; } /** * Returns the xmlBase *

+ * * @return Returns the xmlBase. * @since Atom 1.0 */ public String getXmlBase() { - return _xmlBase; + return this._xmlBase; } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { + public boolean equals(final Object other) { if (other == null) { return false; } - if(!(other instanceof Entry)){ + if (!(other instanceof Entry)) { return false; } // can't use foreign markup in equals, due to JDOM equals impl - List fm = getForeignMarkup(); + final List fm = getForeignMarkup(); setForeignMarkup(((Entry) other).getForeignMarkup()); - boolean ret = _objBean.equals(other); + final boolean ret = this._objBean.equals(other); // restore foreign markup setForeignMarkup(fm); @@ -543,29 +593,30 @@ public class Entry implements Cloneable, Serializable, Extendable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } - - public Link findRelatedLink(String relation){ - for(Link l : this._otherLinks){ - if(relation.equals(l.getRel())){ + public Link findRelatedLink(final String relation) { + for (final Link l : this._otherLinks) { + if (relation.equals(l.getRel())) { return l; } } diff --git a/src/main/java/com/sun/syndication/feed/atom/Feed.java b/src/main/java/com/sun/syndication/feed/atom/Feed.java index 7a5677f..1edf82f 100644 --- a/src/main/java/com/sun/syndication/feed/atom/Feed.java +++ b/src/main/java/com/sun/syndication/feed/atom/Feed.java @@ -16,512 +16,568 @@ */ package com.sun.syndication.feed.atom; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.module.Module; -import com.sun.syndication.feed.module.impl.ModuleUtils; - import java.util.ArrayList; import java.util.Date; import java.util.List; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.feed.module.impl.ModuleUtils; + /** * Bean for Atom feeds. *

* It handles Atom feeds version 0.3 without loosing any feed information. *

+ * * @author Alejandro Abdelnur * @author Dave Johnson (updated for Atom 1.0) */ public class Feed extends WireFeed { - - private String _xmlBase; + + private String _xmlBase; private List _categories; - private List _authors; - private List _contributors; + private List _authors; + private List _contributors; private Generator _generator; - private String _icon; - private String _id; - private String _logo; - private String _rights; // AKA copyright - private Content _subtitle; // AKA tagline - private Content _title; - private Date _updated; // AKA modified - private List _alternateLinks; - private List _otherLinks; - private List _entries; - - private List _modules; - - private Content _info; // Atom 0.3 only - private String _language; // Atom 0.3 only + private String _icon; + private String _id; + private String _logo; + private String _rights; // AKA copyright + private Content _subtitle; // AKA tagline + private Content _title; + private Date _updated; // AKA modified + private List _alternateLinks; + private List _otherLinks; + private List _entries; + + private List _modules; + + private Content _info; // Atom 0.3 only + private String _language; // Atom 0.3 only /** * Default constructor, for bean cloning purposes only. - * + * */ public Feed() { } /** - * Feed Constructor. All properties, except the type, are set to null. + * Feed Constructor. All properties, except the type, are set to + * null. *

+ * * @param type the type of the Atom feed. - * + * */ - public Feed(String type) { + public Feed(final String type) { super(type); } /** * Returns the feed language (Atom 0.3 only) *

+ * * @return the feed language, null if none. - * + * */ public String getLanguage() { - return _language; + return this._language; } /** * Sets the feed language (Atom 0.3 only) *

+ * * @param language the feed language to set, null if none. - * + * */ - public void setLanguage(String language) { - _language = language; + public void setLanguage(final String language) { + this._language = language; } /** * Returns the feed title. *

+ * * @return the feed title, null if none. - * + * */ public String getTitle() { - if (_title != null) return _title.getValue(); + if (this._title != null) { + return this._title.getValue(); + } return null; } /** * Sets the feed title. *

+ * * @param title the feed title to set, null if none. - * + * */ - public void setTitle(String title) { - if (_title == null) _title = new Content(); - _title.setValue(title); + public void setTitle(final String title) { + if (this._title == null) { + this._title = new Content(); + } + this._title.setValue(title); } - + /** * Returns the feed title. *

+ * * @return the feed title, null if none. - * + * */ public Content getTitleEx() { - return _title; + return this._title; } /** * Sets the feed title. *

+ * * @param title the feed title to set, null if none. - * + * */ - public void setTitleEx(Content title) { - _title = title; + public void setTitleEx(final Content title) { + this._title = title; } /** * Returns the feed alternate links. *

- * @return a list of Link elements with the feed alternate links, - * an empty list if none. + * + * @return a list of Link elements with the feed alternate links, an empty + * list if none. */ public List getAlternateLinks() { - return (_alternateLinks==null) ? (_alternateLinks=new ArrayList()) : _alternateLinks; + return this._alternateLinks == null ? (this._alternateLinks = new ArrayList()) : this._alternateLinks; } /** * Sets the feed alternate links. *

- * @param alternateLinks the list of Link elements with the feed alternate links to set, - * an empty list or null if none. + * + * @param alternateLinks the list of Link elements with the feed alternate + * links to set, an empty list or null if none. */ - public void setAlternateLinks(List alternateLinks) { - _alternateLinks = alternateLinks; + public void setAlternateLinks(final List alternateLinks) { + this._alternateLinks = alternateLinks; } /** * Returns the feed other links (non-alternate ones). *

- * @return a list of Link elements with the feed other links (non-alternate ones), - * an empty list if none. + * + * @return a list of Link elements with the feed other links (non-alternate + * ones), an empty list if none. */ public List getOtherLinks() { - return (_otherLinks==null) ? (_otherLinks=new ArrayList()) : _otherLinks; + return this._otherLinks == null ? (this._otherLinks = new ArrayList()) : this._otherLinks; } /** * Sets the feed other links (non-alternate ones). *

- * @param otherLinks the list of Link elements with the feed other links (non-alternate ones) to set, - * an empty list or null if none. + * + * @param otherLinks the list of Link elements with the feed other links + * (non-alternate ones) to set, an empty list or null if + * none. */ - public void setOtherLinks(List otherLinks) { - _otherLinks = otherLinks; + public void setOtherLinks(final List otherLinks) { + this._otherLinks = otherLinks; } /** * Returns the feed author. *

+ * * @return the feed author, null if none. * */ public List getAuthors() { - return (_authors==null) ? (_authors=new ArrayList()) : _authors; + return this._authors == null ? (this._authors = new ArrayList()) : this._authors; } /** * Sets the feed author. *

+ * * @param authors the feed author to set, null if none. * */ - public void setAuthors(List authors) { - _authors = authors; + public void setAuthors(final List authors) { + this._authors = authors; } /** * Returns the feed contributors. *

- * @return a list of Person elements with the feed contributors, - * an empty list if none. - * + * + * @return a list of Person elements with the feed contributors, an empty + * list if none. + * */ public List getContributors() { - return (_contributors==null) ? (_contributors=new ArrayList()) : _contributors; + return this._contributors == null ? (this._contributors = new ArrayList()) : this._contributors; } /** * Sets the feed contributors. *

- * @param contributors the list of Person elements with the feed contributors to set, - * an empty list or null if none. - * + * + * @param contributors the list of Person elements with the feed + * contributors to set, an empty list or null if none. + * */ - public void setContributors(List contributors) { - _contributors = contributors; + public void setContributors(final List contributors) { + this._contributors = contributors; } /** * Returns the feed tag line (Atom 0.3, maps to {@link #getSubtitle()}). *

+ * * @return the feed tag line, null if none. */ public Content getTagline() { - return _subtitle; + return this._subtitle; } /** - * Sets the feed tagline (Atom 0.3, maps to {@link #setSubtitle(com.sun.syndication.feed.atom.Content)}). + * Sets the feed tagline (Atom 0.3, maps to + * {@link #setSubtitle(com.sun.syndication.feed.atom.Content)}). *

+ * * @param tagline the feed tagline to set, null if none. */ - public void setTagline(Content tagline) { - _subtitle = tagline; + public void setTagline(final Content tagline) { + this._subtitle = tagline; } /** * Returns the feed ID. *

+ * * @return the feed ID, null if none. - * + * */ public String getId() { - return _id; + return this._id; } /** * Sets the feed ID. *

+ * * @param id the feed ID to set, null if none. - * + * */ - public void setId(String id) { - _id = id; + public void setId(final String id) { + this._id = id; } /** * Returns the feed generator. *

+ * * @return the feed generator, null if none. - * + * */ public Generator getGenerator() { - return _generator; + return this._generator; } /** * Sets the feed generator. *

+ * * @param generator the feed generator to set, null if none. - * + * */ - public void setGenerator(Generator generator) { - _generator = generator; + public void setGenerator(final Generator generator) { + this._generator = generator; } /** * Returns the feed copyright (Atom 0.3, maps to {@link #getRights()}). *

+ * * @return the feed copyright, null if none. */ public String getCopyright() { - return _rights; + return this._rights; } /** - * Sets the feed copyright (Atom 0.3, maps to {@link #setRights(java.lang.String)}). + * Sets the feed copyright (Atom 0.3, maps to + * {@link #setRights(java.lang.String)}). *

+ * * @param copyright the feed copyright to set, null if none. */ - public void setCopyright(String copyright) { - _rights = copyright; + public void setCopyright(final String copyright) { + this._rights = copyright; } /** * Returns the feed info (Atom 0.3 only) *

+ * * @return the feed info, null if none. */ public Content getInfo() { - return _info; + return this._info; } /** * Sets the feed info (Atom 0.3 only) *

+ * * @param info the feed info to set, null if none. */ - public void setInfo(Content info) { - _info = info; + public void setInfo(final Content info) { + this._info = info; } /** * Returns the feed modified date (Atom 0.3, maps to {@link #getUpdated()}). *

+ * * @return the feed modified date, null if none. */ public Date getModified() { - return _updated; + return this._updated; } /** - * Sets the feed modified date (Atom 0.3, maps to {@link #setUpdated(java.util.Date)}). + * Sets the feed modified date (Atom 0.3, maps to + * {@link #setUpdated(java.util.Date)}). *

+ * * @param modified the feed modified date to set, null if none. */ - public void setModified(Date modified) { - _updated = modified; + public void setModified(final Date modified) { + this._updated = modified; } /** * Returns the feed entries. *

- * @return a list of Entry elements with the feed entries, - * an empty list if none. - * + * + * @return a list of Entry elements with the feed entries, an empty list if + * none. + * */ public List getEntries() { - return (_entries==null) ? (_entries=new ArrayList()) : _entries; + return this._entries == null ? (this._entries = new ArrayList()) : this._entries; } /** * Sets the feed entries. *

+ * * @param entries the list of Entry elements with the feed entries to set, - * an empty list or null if none. - * + * an empty list or null if none. + * */ - public void setEntries(List entries) { - _entries = entries; + public void setEntries(final List entries) { + this._entries = entries; } /** * Returns the feed modules. *

- * @return a list of ModuleImpl elements with the feed modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the feed modules, an empty + * list if none. + * */ + @Override public List getModules() { - return (_modules==null) ? (_modules=new ArrayList()) : _modules; + return this._modules == null ? (this._modules = new ArrayList()) : this._modules; } /** * Sets the feed moduless. *

- * @param modules the list of ModuleImpl elements with the feed moduless to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the feed moduless to + * set, an empty list or null if none. + * */ @Override - public void setModules(List modules) { - _modules = modules; + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ @Override - public Module getModule(String uri) { - return ModuleUtils.getModule(_modules,uri); + public Module getModule(final String uri) { + return ModuleUtils.getModule(this._modules, uri); } /** * Returns the categories *

+ * * @return Returns the categories. * @since Atom 1.0 */ public List getCategories() { - return (_categories==null) ? (_categories=new ArrayList()) : _categories; + return this._categories == null ? (this._categories = new ArrayList()) : this._categories; } - + /** * Set the categories *

+ * * @param categories The categories to set. * @since Atom 1.0 */ - public void setCategories(List categories) { - _categories = categories; + public void setCategories(final List categories) { + this._categories = categories; } - + /** * Returns the icon *

+ * * @return Returns the icon. * @since Atom 1.0 */ public String getIcon() { - return _icon; + return this._icon; } - + /** * Set the icon *

+ * * @param icon The icon to set. * @since Atom 1.0 */ - public void setIcon(String icon) { - _icon = icon; + public void setIcon(final String icon) { + this._icon = icon; } - + /** * Returns the logo *

+ * * @return Returns the logo. * @since Atom 1.0 */ public String getLogo() { - return _logo; + return this._logo; } - + /** * Set the logo *

+ * * @param logo The logo to set. * @since Atom 1.0 */ - public void setLogo(String logo) { - _logo = logo; + public void setLogo(final String logo) { + this._logo = logo; } - + /** * Returns the rights *

+ * * @return Returns the rights. * @since Atom 1.0 */ public String getRights() { - return _rights; + return this._rights; } - + /** * Set the rights *

+ * * @param rights The rights to set. * @since Atom 1.0 */ - public void setRights(String rights) { - _rights = rights; + public void setRights(final String rights) { + this._rights = rights; } - + /** * Returns the subtitle *

+ * * @return Returns the subtitle. * @since Atom 1.0 - */ + */ public Content getSubtitle() { - return _subtitle; + return this._subtitle; } - + /** * Set the subtitle *

+ * * @param subtitle The subtitle to set. * @since Atom 1.0 */ - public void setSubtitle(Content subtitle) { - _subtitle = subtitle; + public void setSubtitle(final Content subtitle) { + this._subtitle = subtitle; } - + /** * Returns the updated *

+ * * @return Returns the updated. * @since Atom 1.0 */ public Date getUpdated() { - return _updated; + return this._updated; } - + /** * Set the updated *

+ * * @param updated The updated to set. * @since Atom 1.0 */ - public void setUpdated(Date updated) { - _updated = updated; + public void setUpdated(final Date updated) { + this._updated = updated; } /** * Returns the xmlBase *

+ * * @return Returns the xmlBase. * @since Atom 1.0 */ public String getXmlBase() { - return _xmlBase; + return this._xmlBase; } - + /** * Set the xmlBase *

+ * * @param xmlBase The xmlBase to set. * @since Atom 1.0 */ - public void setXmlBase(String xmlBase) { - _xmlBase = xmlBase; + public void setXmlBase(final String xmlBase) { + this._xmlBase = xmlBase; } } - diff --git a/src/main/java/com/sun/syndication/feed/atom/Generator.java b/src/main/java/com/sun/syndication/feed/atom/Generator.java index 2763fb5..b7938ff 100644 --- a/src/main/java/com/sun/syndication/feed/atom/Generator.java +++ b/src/main/java/com/sun/syndication/feed/atom/Generator.java @@ -16,18 +16,19 @@ */ package com.sun.syndication.feed.atom; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for the generator element of Atom feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class Generator implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Generator implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _url; private String _version; private String _value; @@ -35,37 +36,41 @@ public class Generator implements Cloneable,Serializable { /** * Default constructor. All properties are set to null. *

- * + * */ public Generator() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Generator)){ + public boolean equals(final Object other) { + if (!(other instanceof Generator)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -73,83 +78,91 @@ public class Generator implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** - * Returns the generator URL. - *

- * @return the generator URL, null if none. - * - */ + * Returns the generator URL. + *

+ * + * @return the generator URL, null if none. + * + */ public String getUrl() { - return _url; + return this._url; } /** - * Sets the generator URL. - *

- * @param url the generator URL, null if none. - * - */ - public void setUrl(String url) { - _url = url; + * Sets the generator URL. + *

+ * + * @param url the generator URL, null if none. + * + */ + public void setUrl(final String url) { + this._url = url; } /** * Returns the generator version. *

+ * * @return the generator version, null if none. - * + * */ public String getVersion() { - return _version; + return this._version; } /** * Sets the generator version. *

+ * * @param version the generator version, null if none. - * + * */ - public void setVersion(String version) { - _version = version; + public void setVersion(final String version) { + this._version = version; } /** * Returns the generator value. *

+ * * @return the generator value, null if none. - * + * */ public String getValue() { - return _value; + return this._value; } /** * Sets the generator value. *

+ * * @param value the generator value, null if none. - * + * */ - public void setValue(String value) { - _value = value; + public void setValue(final String value) { + this._value = value; } } diff --git a/src/main/java/com/sun/syndication/feed/atom/Link.java b/src/main/java/com/sun/syndication/feed/atom/Link.java index 5a88cfa..a98f500 100644 --- a/src/main/java/com/sun/syndication/feed/atom/Link.java +++ b/src/main/java/com/sun/syndication/feed/atom/Link.java @@ -16,59 +16,64 @@ */ package com.sun.syndication.feed.atom; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for link elements of Atom feeds. *

+ * * @author Alejandro Abdelnur * @author Dave Johnson (updated for Atom 1.0) */ -public class Link implements Cloneable,Serializable { - - private ObjectBean _objBean; - +public class Link implements Cloneable, Serializable { + + private final ObjectBean _objBean; + private String _href; private String _hrefResolved; private String _rel = "alternate"; private String _type; private String _hreflang; private String _title; - private long _length; + private long _length; /** * Default constructor. All properties are set to null. *

- * + * */ public Link() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - return _objBean.equals(other); + public boolean equals(final Object other) { + return this._objBean.equals(other); } /** @@ -76,149 +81,163 @@ public class Link implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the link rel. *

+ * * @return the link rel, null if none. - * + * */ public String getRel() { - return _rel; + return this._rel; } /** * Sets the link rel. *

+ * * @param rel the link rel,, null if none. - * + * */ - public void setRel(String rel) { - //TODO add check, ask P@ about the check - _rel = rel; + public void setRel(final String rel) { + // TODO add check, ask P@ about the check + this._rel = rel; } /** * Returns the link type. *

+ * * @return the link type, null if none. - * + * */ public String getType() { - return _type; + return this._type; } /** * Sets the link type. *

+ * * @param type the link type, null if none. - * + * */ - public void setType(String type) { - _type = type; + public void setType(final String type) { + this._type = type; } /** * Returns the link href. *

+ * * @return the link href, null if none. - * + * */ public String getHref() { - return _href; + return this._href; } /** * Sets the link href. *

+ * * @param href the link href, null if none. - * + * */ - public void setHref(String href) { - _href = href; + public void setHref(final String href) { + this._href = href; } - public void setHrefResolved(String hrefResolved) { - _hrefResolved = hrefResolved; + public void setHrefResolved(final String hrefResolved) { + this._hrefResolved = hrefResolved; } public String getHrefResolved() { - return _hrefResolved != null ? _hrefResolved : _href; + return this._hrefResolved != null ? this._hrefResolved : this._href; } /** * Returns the link title. *

+ * * @return the link title, null if none. - * + * */ public String getTitle() { - return _title; + return this._title; } /** * Sets the link title. *

+ * * @param title the link title, null if none. - * + * */ - public void setTitle(String title) { - _title = title; + public void setTitle(final String title) { + this._title = title; } /** * Returns the hreflang *

+ * * @return Returns the hreflang. * @since Atom 1.0 */ public String getHreflang() { - return _hreflang; + return this._hreflang; } - + /** * Set the hreflang *

+ * * @param hreflang The hreflang to set. * @since Atom 1.0 */ - public void setHreflang(String hreflang) { - _hreflang = hreflang; + public void setHreflang(final String hreflang) { + this._hreflang = hreflang; } - + /** * Returns the length *

+ * * @return Returns the length. */ public long getLength() { - return _length; + return this._length; } - + /** * Set the length *

+ * * @param length The length to set. */ - public void setLength(long length) { - _length = length; + public void setLength(final long length) { + this._length = length; } } diff --git a/src/main/java/com/sun/syndication/feed/atom/Person.java b/src/main/java/com/sun/syndication/feed/atom/Person.java index 28495d9..3a0fdbb 100644 --- a/src/main/java/com/sun/syndication/feed/atom/Person.java +++ b/src/main/java/com/sun/syndication/feed/atom/Person.java @@ -16,63 +16,67 @@ */ package com.sun.syndication.feed.atom; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + import com.sun.syndication.feed.impl.ObjectBean; import com.sun.syndication.feed.module.Extendable; import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.module.impl.ModuleUtils; -import java.io.Serializable; -import java.util.List; -import java.util.ArrayList; - /** * Bean for person elements of Atom feeds. *

+ * * @author Alejandro Abdelnur * @author Dave Johnson (updated for Atom 1.0) */ -public class Person implements Cloneable,Serializable, Extendable -{ - - private ObjectBean _objBean; - +public class Person implements Cloneable, Serializable, Extendable { + + private final ObjectBean _objBean; + private String _name; - private String _uri; // since Atom 1.0 (was called url) - private String _uriResolved; + private String _uri; // since Atom 1.0 (was called url) + private String _uriResolved; private String _email; private List _modules; /** * Default constructor. All properties are set to null. *

- * + * */ public Person() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - return _objBean.equals(other); + public boolean equals(final Object other) { + return this._objBean.equals(other); } /** @@ -80,141 +84,157 @@ public class Person implements Cloneable,Serializable, Extendable *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** - * Returns the person name. - *

- * @return the person name, null if none. - * - */ + * Returns the person name. + *

+ * + * @return the person name, null if none. + * + */ public String getName() { - return _name; + return this._name; } /** - * Sets the personname. - *

- * @param name the person name, null if none. - * - */ - public void setName(String name) { - _name = name; + * Sets the personname. + *

+ * + * @param name the person name, null if none. + * + */ + public void setName(final String name) { + this._name = name; } /** - * Returns the person URL (same as {@link #getUri()}) - *

- * @return the person URL, null if none. - */ + * Returns the person URL (same as {@link #getUri()}) + *

+ * + * @return the person URL, null if none. + */ public String getUrl() { - return _uri; + return this._uri; } /** - * Sets the person URL (same as {@link #setUri(java.lang.String)}) - *

- * @param url the person URL, null if none. - */ - public void setUrl(String url) { - _uri = url; + * Sets the person URL (same as {@link #setUri(java.lang.String)}) + *

+ * + * @param url the person URL, null if none. + */ + public void setUrl(final String url) { + this._uri = url; } - public void setUriResolved(String uriResolved) { - _uriResolved = uriResolved; + public void setUriResolved(final String uriResolved) { + this._uriResolved = uriResolved; } - public String getUriResolved(String resolveURI) { - return _uriResolved != null ? _uriResolved : _uri; + public String getUriResolved(final String resolveURI) { + return this._uriResolved != null ? this._uriResolved : this._uri; } /** - * Returns the person email. - *

- * @return the person email, null if none. - * - */ + * Returns the person email. + *

+ * + * @return the person email, null if none. + * + */ public String getEmail() { - return _email; + return this._email; } /** - * Sets the person email. - *

- * @param email the person email, null if none. - * - */ - public void setEmail(String email) { - _email = email; + * Sets the person email. + *

+ * + * @param email the person email, null if none. + * + */ + public void setEmail(final String email) { + this._email = email; } /** * Returns the uri *

+ * * @return Returns the uri. * @since Atom 1.0 */ public String getUri() { - return _uri; + return this._uri; } - + /** * Set the uri *

+ * * @param uri The uri to set. * @since Atom 1.0 */ - public void setUri(String uri) { - _uri = uri; + public void setUri(final String uri) { + this._uri = uri; } /** * Returns the entry modules. *

- * @return a list of ModuleImpl elements with the entry modules, - * an emtpy list if none. - * + * + * @return a list of ModuleImpl elements with the entry modules, an emtpy + * list if none. + * */ + @Override public List getModules() { - return (_modules==null) ? (_modules=new ArrayList()) : _modules; + return this._modules == null ? (this._modules = new ArrayList()) : this._modules; } /** * Sets the entry modules. *

- * @param modules the list of ModuleImpl elements with the entry modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the entry modules to + * set, an empty list or null if none. + * */ - public void setModules(List modules) { - _modules = modules; + @Override + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ - public Module getModule(String uri) { - return ModuleUtils.getModule(_modules,uri); + @Override + public Module getModule(final String uri) { + return ModuleUtils.getModule(this._modules, uri); } } diff --git a/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java b/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java index dded484..2800f84 100644 --- a/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java +++ b/src/main/java/com/sun/syndication/feed/impl/BeanIntrospector.java @@ -21,35 +21,43 @@ import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Obtains all property descriptors from a bean (interface or implementation). *

- * The java.beans.Introspector does not process the interfaces hierarchy chain, this one does. + * The java.beans.Introspector does not process the interfaces hierarchy chain, + * this one does. *

+ * * @author Alejandro Abdelnur - * + * */ public class BeanIntrospector { private static final Map _introspected = new HashMap(); - public static synchronized PropertyDescriptor[] getPropertyDescriptors(Class klass) throws IntrospectionException { + public static synchronized PropertyDescriptor[] getPropertyDescriptors(final Class klass) throws IntrospectionException { PropertyDescriptor[] descriptors = (PropertyDescriptor[]) _introspected.get(klass); - if (descriptors==null) { + if (descriptors == null) { descriptors = getPDs(klass); - _introspected.put(klass,descriptors); + _introspected.put(klass, descriptors); } return descriptors; } - private static PropertyDescriptor[] getPDs(Class klass) throws IntrospectionException { - Method[] methods = klass.getMethods(); - Map getters = getPDs(methods,false); - Map setters = getPDs(methods,true); - List pds = merge(getters,setters); - PropertyDescriptor[] array = new PropertyDescriptor[pds.size()]; + private static PropertyDescriptor[] getPDs(final Class klass) throws IntrospectionException { + final Method[] methods = klass.getMethods(); + final Map getters = getPDs(methods, false); + final Map setters = getPDs(methods, true); + final List pds = merge(getters, setters); + final PropertyDescriptor[] array = new PropertyDescriptor[pds.size()]; pds.toArray(array); return array; } @@ -58,63 +66,56 @@ public class BeanIntrospector { private static final String GETTER = "get"; private static final String BOOLEAN_GETTER = "is"; - private static Map getPDs(Method[] methods,boolean setters) throws IntrospectionException { - Map pds = new HashMap(); - for (int i=0;iBean clonning support. *

- * It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, - * Cloneable objects and multi-dimensional arrays of any of them. + * It works on all read/write properties, recursively. It support all primitive + * types, Strings, Collections, Cloneable objects and multi-dimensional arrays + * of any of them. *

+ * * @author Alejandro Abdelnur - * + * */ public class CloneableBean implements Serializable, Cloneable { private static final Class[] NO_PARAMS_DEF = new Class[0]; private static final Object[] NO_PARAMS = new Object[0]; - private Object _obj; + private final Object _obj; private Set _ignoreProperties; /** @@ -45,10 +53,10 @@ public class CloneableBean implements Serializable, Cloneable { *

* To be used by classes extending CloneableBean only. *

- * + * */ protected CloneableBean() { - _obj = this; + this._obj = this; } /** @@ -59,55 +67,62 @@ public class CloneableBean implements Serializable, Cloneable { * * public class Foo implements Cloneable { * private CloneableBean _cloneableBean; - * + * * public Foo() { * _cloneableBean = new CloneableBean(this); * } - * + * * public Object clone() throws CloneNotSupportedException { * return _cloneableBean.beanClone(); * } - * + * * } * *

+ * * @param obj object bean to clone. - * + * */ - public CloneableBean(Object obj) { - this(obj,null); + public CloneableBean(final Object obj) { + this(obj, null); } /** * Creates a CloneableBean to be used in a delegation pattern. *

* The property names in the ignoreProperties Set will not be copied into - * the cloned instance. This is useful for cases where the Bean has convenience - * properties (properties that are actually references to other properties or - * properties of properties). For example SyndFeed and SyndEntry beans have - * convenience properties, publishedDate, author, copyright and categories all - * of them mapped to properties in the DC Module. + * the cloned instance. This is useful for cases where the Bean has + * convenience properties (properties that are actually references to other + * properties or properties of properties). For example SyndFeed and + * SyndEntry beans have convenience properties, publishedDate, author, + * copyright and categories all of them mapped to properties in the DC + * Module. *

+ * * @param obj object bean to clone. * @param ignoreProperties properties to ignore when cloning. - * + * */ - public CloneableBean(Object obj,Set ignoreProperties) { - _obj = obj; - _ignoreProperties = (ignoreProperties!=null) ? ignoreProperties : Collections.EMPTY_SET; + public CloneableBean(final Object obj, final Set ignoreProperties) { + this._obj = obj; + this._ignoreProperties = ignoreProperties != null ? ignoreProperties : Collections.EMPTY_SET; } /** * Makes a deep bean clone of the object. *

- * To be used by classes extending CloneableBean. Although it works also for classes using - * CloneableBean in a delegation pattern, for correctness those classes should use the + * To be used by classes extending CloneableBean. Although it works also for + * classes using CloneableBean in a delegation pattern, for correctness + * those classes should use the + * * @see #beanClone() beanClone method. - *

- * @return a clone of the object bean. - * @throws CloneNotSupportedException thrown if the object bean could not be cloned. - * + *

+ * @return a clone of the object bean. + * @throws CloneNotSupportedException thrown if the object bean could not be + * cloned. + * */ + @Override public Object clone() throws CloneNotSupportedException { return beanClone(); } @@ -116,111 +131,122 @@ public class CloneableBean implements Serializable, Cloneable { * Makes a deep bean clone of the object passed in the constructor. *

* To be used by classes using CloneableBean in a delegation pattern, + * * @see #CloneableBean(Object) constructor. - * + * * @return a clone of the object bean. - * @throws CloneNotSupportedException thrown if the object bean could not be cloned. - * + * @throws CloneNotSupportedException thrown if the object bean could not be + * cloned. + * */ public Object beanClone() throws CloneNotSupportedException { Object clonedBean; try { - clonedBean = _obj.getClass().newInstance(); - PropertyDescriptor[] pds = BeanIntrospector.getPropertyDescriptors(_obj.getClass()); - if (pds!=null) { - for (int i=0;iBean equals() and hashCode() functionality for Java Beans. + * Provides deep Bean equals() and hashCode() functionality for Java + * Beans. *

- * It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, - * bean-like objects and multi-dimensional arrays of any of them. + * It works on all read/write properties, recursively. It support all primitive + * types, Strings, Collections, bean-like objects and multi-dimensional arrays + * of any of them. *

- * The hashcode is calculated by getting the hashcode of the Bean String representation. + * The hashcode is calculated by getting the hashcode of the Bean String + * representation. *

+ * * @author Alejandro Abdelnur - * + * */ public class EqualsBean implements Serializable { private static final Object[] NO_PARAMS = new Object[0]; - private Class _beanClass; - private Object _obj; + private final Class _beanClass; + private final Object _obj; /** * Default constructor. *

* To be used by classes extending EqualsBean only. *

+ * * @param beanClass the class/interface to be used for property scanning. - * + * */ - protected EqualsBean(Class beanClass) { - _beanClass = beanClass; - _obj = this; + protected EqualsBean(final Class beanClass) { + this._beanClass = beanClass; + this._obj = this; } /** @@ -60,97 +65,108 @@ public class EqualsBean implements Serializable { * * public class Foo implements FooI { * private EqualsBean _equalsBean; - * + * * public Foo() { * _equalsBean = new EqualsBean(FooI.class); * } - * + * * public boolean equals(Object obj) { * return _equalsBean.beanEquals(obj); * } - * + * * public int hashCode() { * return _equalsBean.beanHashCode(); * } - * + * * } * *

+ * * @param beanClass the class/interface to be used for property scanning. * @param obj object bean to test equality. - * + * */ - public EqualsBean(Class beanClass,Object obj) { + public EqualsBean(final Class beanClass, final Object obj) { if (!beanClass.isInstance(obj)) { - throw new IllegalArgumentException(obj.getClass()+" is not instance of "+beanClass); + throw new IllegalArgumentException(obj.getClass() + " is not instance of " + beanClass); } - _beanClass = beanClass; - _obj = obj; + this._beanClass = beanClass; + this._obj = obj; } /** - * Indicates whether some other object is "equal to" this object as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this object as defined + * by the Object equals() method. *

- * To be used by classes extending EqualsBean. Although it works also for classes using - * EqualsBean in a delegation pattern, for correctness those classes should use the + * To be used by classes extending EqualsBean. Although it works also for + * classes using EqualsBean in a delegation pattern, for correctness those + * classes should use the + * * @see #beanEquals(Object) beanEquals method. - *

+ *

* @param obj he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public boolean equals(Object obj) { + @Override + public boolean equals(final Object obj) { return beanEquals(obj); } /** - * Indicates whether some other object is "equal to" the object passed in the constructor, - * as defined by the Object equals() method. + * Indicates whether some other object is "equal to" the object passed in + * the constructor, as defined by the Object equals() method. *

* To be used by classes using EqualsBean in a delegation pattern, + * * @see #EqualsBean(Class,Object) constructor. - *

+ *

* @param obj he reference object with which to compare. - * @return true if the object passed in the constructor is equal to the 'obj' object. - * + * @return true if the object passed in the constructor is equal to + * the 'obj' object. + * */ - public boolean beanEquals(Object obj) { - Object bean1 = _obj; - Object bean2 = obj; + public boolean beanEquals(final Object obj) { + final Object bean1 = this._obj; + final Object bean2 = obj; boolean eq; - if (bean1==null && bean2==null) { + if (bean1 == null && bean2 == null) { eq = true; - } - else - if (bean1==null || bean2==null) { + } else if (bean1 == null || bean2 == null) { + eq = false; + } else { + if (!this._beanClass.isInstance(bean2)) { eq = false; - } - else { - if (!_beanClass.isInstance(bean2)) { - eq = false; - } - else { - eq = true; - try { - PropertyDescriptor[] pds = BeanIntrospector.getPropertyDescriptors(_beanClass); - if (pds!=null) { - for (int i = 0; eq && i * It follows the contract defined by the Object hashCode() method. *

- * The hashcode is calculated by getting the hashcode of the Bean String representation. + * The hashcode is calculated by getting the hashcode of the Bean String + * representation. *

- * To be used by classes extending EqualsBean. Although it works also for classes using - * EqualsBean in a delegation pattern, for correctness those classes should use the + * To be used by classes extending EqualsBean. Although it works also for + * classes using EqualsBean in a delegation pattern, for correctness those + * classes should use the + * * @see #beanHashCode() beanHashCode method. - *

+ *

* @return the hashcode of the bean object. - * + * */ + @Override public int hashCode() { return beanHashCode(); } @@ -177,51 +197,49 @@ public class EqualsBean implements Serializable { *

* It follows the contract defined by the Object hashCode() method. *

- * The hashcode is calculated by getting the hashcode of the Bean String representation. + * The hashcode is calculated by getting the hashcode of the Bean String + * representation. *

* To be used by classes using EqualsBean in a delegation pattern, + * * @see #EqualsBean(Class,Object) constructor. - *

+ *

* @return the hashcode of the bean object. - * + * */ public int beanHashCode() { - return _obj.toString().hashCode(); + return this._obj.toString().hashCode(); } - - private boolean doEquals(Object obj1, Object obj2) { - boolean eq = obj1==obj2; - if (!eq && obj1!=null && obj2!=null) { - Class classObj1 = obj1.getClass(); - Class classObj2 = obj2.getClass(); + private boolean doEquals(final Object obj1, final Object obj2) { + boolean eq = obj1 == obj2; + if (!eq && obj1 != null && obj2 != null) { + final Class classObj1 = obj1.getClass(); + final Class classObj2 = obj2.getClass(); if (classObj1.isArray() && classObj2.isArray()) { eq = equalsArray(obj1, obj2); - } - else { + } else { eq = obj1.equals(obj2); } } return eq; } - private boolean equalsArray(Object array1, Object array2) { + private boolean equalsArray(final Object array1, final Object array2) { boolean eq; - int length1 = Array.getLength(array1); - int length2 = Array.getLength(array2); - if (length1==length2) { + final int length1 = Array.getLength(array1); + final int length2 = Array.getLength(array2); + if (length1 == length2) { eq = true; - for (int i = 0; eq && i * It works on all read/write properties, recursively. *

- * It uses the CloneableBean, EqualsBean and ToStringBean classes in a delegation pattern. + * It uses the CloneableBean, EqualsBean and ToStringBean classes in a + * delegation pattern. *

*

ObjectBean programming conventions

*

- * All ObjectBean subclasses having properties that return collections they should never - * return null if the property has been set to null or if a collection has not been set. - * They should create and return an empty collection, this empty collection instance should - * also be set to the corresponding property. + * All ObjectBean subclasses having properties that return collections they + * should never return null if the property has been set to null or if a + * collection has not been set. They should create and return an empty + * collection, this empty collection instance should also be set to the + * corresponding property. *

* All ObjectBean subclasses properties should be live references. *

+ * * @author Alejandro Abdelnur - * + * */ public class ObjectBean implements Serializable, Cloneable { - private EqualsBean _equalsBean; - private ToStringBean _toStringBean; - private CloneableBean _cloneableBean; + private final EqualsBean _equalsBean; + private final ToStringBean _toStringBean; + private final CloneableBean _cloneableBean; /** * Constructor. *

+ * * @param beanClass the class/interface to be used for property scanning. - * + * */ - public ObjectBean(Class beanClass,Object obj) { - this(beanClass,obj,null); + public ObjectBean(final Class beanClass, final Object obj) { + this(beanClass, obj, null); } /** * Constructor. *

* The property names in the ignoreProperties Set will not be copied into - * the cloned instance. This is useful for cases where the Bean has convenience - * properties (properties that are actually references to other properties or - * properties of properties). For example SyndFeed and SyndEntry beans have - * convenience properties, publishedDate, author, copyright and categories all - * of them mapped to properties in the DC Module. + * the cloned instance. This is useful for cases where the Bean has + * convenience properties (properties that are actually references to other + * properties or properties of properties). For example SyndFeed and + * SyndEntry beans have convenience properties, publishedDate, author, + * copyright and categories all of them mapped to properties in the DC + * Module. *

+ * * @param beanClass the class/interface to be used for property scanning. * @param ignoreProperties properties to ignore when cloning. - * + * */ - public ObjectBean(Class beanClass,Object obj,Set ignoreProperties) { - _equalsBean = new EqualsBean(beanClass,obj); - _toStringBean = new ToStringBean(beanClass,obj); - _cloneableBean = new CloneableBean(obj,ignoreProperties); + public ObjectBean(final Class beanClass, final Object obj, final Set ignoreProperties) { + this._equalsBean = new EqualsBean(beanClass, obj); + this._toStringBean = new ToStringBean(beanClass, obj); + this._cloneableBean = new CloneableBean(obj, ignoreProperties); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ + @Override public Object clone() throws CloneNotSupportedException { - return _cloneableBean.beanClone(); + return this._cloneableBean.beanClone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public boolean equals(Object other) { - return _equalsBean.beanEquals(other); + @Override + public boolean equals(final Object other) { + return this._equalsBean.beanEquals(other); } /** @@ -103,22 +113,25 @@ public class ObjectBean implements Serializable, Cloneable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ + @Override public int hashCode() { - return _equalsBean.beanHashCode(); + return this._equalsBean.beanHashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ + @Override public String toString() { - return _toStringBean.toString(); + return this._toStringBean.toString(); } } - diff --git a/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java b/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java index 50fdc6d..7fa45c3 100644 --- a/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java +++ b/src/main/java/com/sun/syndication/feed/impl/ToStringBean.java @@ -17,28 +17,31 @@ package com.sun.syndication.feed.impl; import java.beans.PropertyDescriptor; +import java.io.Serializable; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Stack; -import java.io.Serializable; /** * Provides deep Bean toString support. *

- * It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, - * ToString objects and multi-dimensional arrays of any of them. + * It works on all read/write properties, recursively. It support all primitive + * types, Strings, Collections, ToString objects and multi-dimensional arrays of + * any of them. *

+ * * @author Alejandro Abdelnur - * + * */ public class ToStringBean implements Serializable { private static final ThreadLocal PREFIX_TL = new ThreadLocal() { + @Override public Object get() { Object o = super.get(); - if (o==null) { + if (o == null) { o = new Stack(); set(o); } @@ -48,20 +51,22 @@ public class ToStringBean implements Serializable { private static final Object[] NO_PARAMS = new Object[0]; - private Class _beanClass; - private Object _obj; + private final Class _beanClass; + private final Object _obj; /** * Default constructor. *

* To be used by classes extending ToStringBean only. *

- * @param beanClass indicates the class to scan for properties, normally an interface class. - * + * + * @param beanClass indicates the class to scan for properties, normally an + * interface class. + * */ - protected ToStringBean(Class beanClass) { - _beanClass = beanClass; - _obj = this; + protected ToStringBean(final Class beanClass) { + this._beanClass = beanClass; + this._obj = this; } /** @@ -71,26 +76,28 @@ public class ToStringBean implements Serializable { *

* * public class Foo implements ToString { - * + * * public String toString(String prefix) { * ToStringBean tsb = new ToStringBean(this); * return tsb.toString(prefix); * } - * + * * public String toString() { * return toString("Foo"); * } - * + * * } * *

- * @param beanClass indicates the class to scan for properties, normally an interface class. + * + * @param beanClass indicates the class to scan for properties, normally an + * interface class. * @param obj object bean to create String representation. - * + * */ - public ToStringBean(Class beanClass,Object obj) { - _beanClass = beanClass; - _obj = obj; + public ToStringBean(final Class beanClass, final Object obj) { + this._beanClass = beanClass; + this._obj = obj; } /** @@ -98,143 +105,139 @@ public class ToStringBean implements Serializable { *

* It uses the Class name as the prefix. *

+ * * @return bean object String representation. - * + * */ + @Override public String toString() { - Stack stack = (Stack) PREFIX_TL.get(); - String[] tsInfo = (String[]) ((stack.isEmpty()) ? null : stack.peek()); + final Stack stack = (Stack) PREFIX_TL.get(); + final String[] tsInfo = (String[]) (stack.isEmpty() ? null : stack.peek()); String prefix; - if (tsInfo==null) { - String className = _obj.getClass().getName(); - prefix = className.substring(className.lastIndexOf(".")+1); - } - else { + if (tsInfo == null) { + final String className = this._obj.getClass().getName(); + prefix = className.substring(className.lastIndexOf(".") + 1); + } else { prefix = tsInfo[0]; tsInfo[1] = prefix; } - return toString(prefix); + return this.toString(prefix); } /** * Returns the String representation of the bean given in the constructor. *

+ * * @param prefix to use for bean properties. * @return bean object String representation. - * + * */ - private String toString(String prefix) { - StringBuffer sb = new StringBuffer(128); + private String toString(final String prefix) { + final StringBuffer sb = new StringBuffer(128); try { - PropertyDescriptor[] pds = BeanIntrospector.getPropertyDescriptors(_beanClass); - if (pds!=null) { - for (int i=0;i - * @see Dublin Core module. + * + * @see Dublin Core + * module. * @author Alejandro Abdelnur - * + * */ public interface DCModule extends Module, CopyFrom { /** * URI of the Dublin Core Module (http://purl.org/dc/elements/1.1/). - * + * */ String URI = "http://purl.org/dc/elements/1.1/"; /** * Returns the DublinCore module titles. *

- * @return a list of Strings representing the DublinCore module title, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module title, an + * empty list if none. + * */ List getTitles(); /** * Sets the DublinCore module titles. *

- * @param titles the list of String representing the DublinCore module titles - * to set, an empty list or null if none. - * + * + * @param titles the list of String representing the DublinCore module + * titles to set, an empty list or null if none. + * */ void setTitles(List titles); /** - * Gets the DublinCore module title. Convenience method that can be used - * to obtain the first item, null if none. + * Gets the DublinCore module title. Convenience method that can be used to + * obtain the first item, null if none. *

+ * * @return the first DublinCore module title, null if none. */ String getTitle(); @@ -66,26 +71,29 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module title. Convenience method that can be used * when there is only one title to set. *

+ * * @param title the DublinCore module title to set, null if none. - * + * */ void setTitle(String title); /** * Returns the DublinCore module creator. *

- * @return a list of Strings representing the DublinCore module creator, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module creator, an + * empty list if none. + * */ List getCreators(); /** * Sets the DublinCore module creators. *

+ * * @param creators the list of String representing the DublinCore module - * creators to set, an empty list or null if none. - * + * creators to set, an empty list or null if none. + * */ void setCreators(List creators); @@ -93,34 +101,38 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module creator. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module creator, null if none. */ String getCreator(); - + /** * Sets the DublinCore module creator. Convenience method that can be used * when there is only one creator to set. *

+ * * @param creator the DublinCore module creator to set, null if none. - * + * */ void setCreator(String creator); /** * Returns the DublinCore module subjects. *

+ * * @return a list of DCSubject elements with the DublinCore module subjects, * an empty list if none. - * + * */ List getSubjects(); /** * Sets the DublinCore module subjects. *

- * @param subjects the list of DCSubject elements with the DublinCore - * module subjects to set, an empty list or null if none. - * + * + * @param subjects the list of DCSubject elements with the DublinCore module + * subjects to set, an empty list or null if none. + * */ void setSubjects(List subjects); @@ -128,6 +140,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module subject. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module subject, null if none. */ DCSubject getSubject(); @@ -136,26 +149,29 @@ public interface DCModule extends Module, CopyFrom { * Sets the DCSubject element. Convenience method that can be used when * there is only one subject to set. *

+ * * @param subject the DublinCore module subject to set, null if none. - * + * */ void setSubject(DCSubject subject); /** * Returns the DublinCore module description. *

+ * * @return a list of Strings representing the DublinCore module description, * an empty list if none. - * + * */ List getDescriptions(); /** * Sets the DublinCore module descriptions. *

- * @param descriptions the list of String representing the DublinCore - * module descriptions to set, an empty list or null if none. - * + * + * @param descriptions the list of String representing the DublinCore module + * descriptions to set, an empty list or null if none. + * */ void setDescriptions(List descriptions); @@ -163,6 +179,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module description. Convenience method that can be * used to obtain the first item, null if none. *

+ * * @return the first DublinCore module description, null if none. */ String getDescription(); @@ -171,61 +188,70 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module description. Convenience method that can be * used when there is only one description to set. *

- * @param description the DublinCore module description to set, null if none. - * + * + * @param description the DublinCore module description to set, null + * if none. + * */ void setDescription(String description); /** * Returns the DublinCore module publisher. *

+ * * @return a list of Strings representing the DublinCore module publisher, * an empty list if none. - * + * */ List getPublishers(); /** * Sets the DublinCore module publishers. *

+ * * @param publishers the list of String representing the DublinCore module - * publishers to set, an empty list or null if none. - * + * publishers to set, an empty list or null if none. + * */ void setPublishers(List publishers); /** - * Gets the DublinCore module publisher. Convenience method that can be - * used to obtain the first item, null if none. + * Gets the DublinCore module publisher. Convenience method that can be used + * to obtain the first item, null if none. *

+ * * @return the first DublinCore module publisher, null if none. */ String getPublisher(); /** - * Sets the DublinCore module publisher. Convenience method that can be used when - * there is only one publisher to set. + * Sets the DublinCore module publisher. Convenience method that can be used + * when there is only one publisher to set. *

- * @param publisher the DublinCore module publisher to set, null if none. - * + * + * @param publisher the DublinCore module publisher to set, null if + * none. + * */ void setPublisher(String publisher); /** * Returns the DublinCore module contributor. *

+ * * @return a list of Strings representing the DublinCore module contributor, * an empty list if none. - * + * */ List getContributors(); /** * Sets the DublinCore module contributors. *

+ * * @param contributors the list of String representing the DublinCore module - * contributors to set, an empty list or null if none. - * + * contributors to set, an empty list or null if none. + * */ void setContributors(List contributors); @@ -233,6 +259,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module contributor. Convenience method that can be * used to obtain the first item, null if none. *

+ * * @return the first DublinCore module contributor, null if none. */ String getContributor(); @@ -241,26 +268,30 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module contributor. Convenience method that can be * used when there is only one contributor to set. *

- * @param contributor the DublinCore module contributor to set, null if none. - * + * + * @param contributor the DublinCore module contributor to set, null + * if none. + * */ void setContributor(String contributor); /** * Returns the DublinCore module date. *

- * @return a list of Strings representing the DublinCore module date, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module date, an + * empty list if none. + * */ List getDates(); /** * Sets the DublinCore module dates. *

- * @param dates the list of Date representing the DublinCore module dates to set, - * an empty list or null if none. - * + * + * @param dates the list of Date representing the DublinCore module dates to + * set, an empty list or null if none. + * */ void setDates(List dates); @@ -268,76 +299,85 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module date. Convenience method that can be used to * obtain the first item, null if none. *

+ * * @return the first DublinCore module date, null if none. */ Date getDate(); /** - * Sets the DublinCore module date. Convenience method that can be used - * when there is only one date to set. + * Sets the DublinCore module date. Convenience method that can be used when + * there is only one date to set. *

+ * * @param date the DublinCore module date to set, null if none. - * + * */ void setDate(Date date); /** * Returns the DublinCore module type. *

- * @return a list of Strings representing the DublinCore module type, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module type, an + * empty list if none. + * */ List getTypes(); /** * Sets the DublinCore module types. *

- * @param types the list of String representing the DublinCore module types to set, - * an empty list or null if none. - * + * + * @param types the list of String representing the DublinCore module types + * to set, an empty list or null if none. + * */ void setTypes(List types); /** - * Gets the DublinCore module type. Convenience method that can be used - * to obtain the first item, null if none. + * Gets the DublinCore module type. Convenience method that can be used to + * obtain the first item, null if none. *

+ * * @return the first DublinCore module type, null if none. */ String getType(); /** - * Sets the DublinCore module type. Convenience method that can be used - * when there is only one type to set. + * Sets the DublinCore module type. Convenience method that can be used when + * there is only one type to set. *

+ * * @param type the DublinCore module type to set, null if none. - * + * */ void setType(String type); /** * Returns the DublinCore module format. *

- * @return a list of Strings representing the DublinCore module format, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module format, an + * empty list if none. + * */ List getFormats(); /** * Sets the DublinCore module formats. *

+ * * @param formats the list of String representing the DublinCore module - * formats to set, an empty list or null if none. - * + * formats to set, an empty list or null if none. + * */ void setFormats(List formats); /** - * Gets the DublinCore module format. Convenience method that can be used - * to obtain the first item, null if none. + * Gets the DublinCore module format. Convenience method that can be used to + * obtain the first item, null if none. *

+ * * @return the first DublinCore module format, null if none. */ String getFormat(); @@ -346,26 +386,29 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module format. Convenience method that can be used * when there is only one format to set. *

+ * * @param format the DublinCore module format to set, null if none. - * + * */ void setFormat(String format); /** * Returns the DublinCore module identifier. *

+ * * @return a list of Strings representing the DublinCore module identifier, * an empty list if none. - * + * */ List getIdentifiers(); /** * Sets the DublinCore module identifiers. *

+ * * @param identifiers the list of String representing the DublinCore module - * identifiers to set, an empty list or null if none. - * + * identifiers to set, an empty list or null if none. + * */ void setIdentifiers(List identifiers); @@ -373,6 +416,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module identifier. Convenience method that can be * used to obtain the first item, null if none. *

+ * * @return the first DublinCore module identifier, null if none. */ String getIdentifier(); @@ -381,26 +425,30 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module identifier. Convenience method that can be * used when there is only one identifier to set. *

- * @param identifier the DublinCore module identifier to set, null if none. - * + * + * @param identifier the DublinCore module identifier to set, null if + * none. + * */ void setIdentifier(String identifier); /** * Returns the DublinCore module source. *

- * @return a list of Strings representing the DublinCore module source, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module source, an + * empty list if none. + * */ List getSources(); /** * Sets the DublinCore module sources. *

+ * * @param sources the list of String representing the DublinCore module - * sources to set, an empty list or null if none. - * + * sources to set, an empty list or null if none. + * */ void setSources(List sources); @@ -408,6 +456,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module subject. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module creator, null if none. */ String getSource(); @@ -416,26 +465,29 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module source. Convenience method that can be used * when there is only one source to set. *

+ * * @param source the DublinCore module source to set, null if none. - * + * */ void setSource(String source); /** * Returns the DublinCore module language. *

- * @return a list of Strings representing the DublinCore module language, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module language, an + * empty list if none. + * */ List getLanguages(); /** * Sets the DublinCore module languages. *

+ * * @param languages the list of String representing the DublinCore module - * languages to set, an empty list or null if none. - * + * languages to set, an empty list or null if none. + * */ void setLanguages(List languages); @@ -443,6 +495,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module language. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module language, null if none. */ String getLanguage(); @@ -451,26 +504,30 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module language. Convenience method that can be used * when there is only one language to set. *

- * @param language the DublinCore module language to set, null if none. - * + * + * @param language the DublinCore module language to set, null if + * none. + * */ void setLanguage(String language); /** * Returns the DublinCore module relation. *

- * @return a list of Strings representing the DublinCore module relation, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module relation, an + * empty list if none. + * */ List getRelations(); /** * Sets the DublinCore module relations. *

+ * * @param relations the list of String representing the DublinCore module - * relations to set, an empty list or null if none. - * + * relations to set, an empty list or null if none. + * */ void setRelations(List relations); @@ -478,6 +535,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module relation. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module relation, null if none. */ String getRelation(); @@ -486,26 +544,30 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module relation. Convenience method that can be used * when there is only one relation to set. *

- * @param relation the DublinCore module relation to set, null if none. - * + * + * @param relation the DublinCore module relation to set, null if + * none. + * */ void setRelation(String relation); /** * Returns the DublinCore module coverage. *

- * @return a list of Strings representing the DublinCore module coverage, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module coverage, an + * empty list if none. + * */ List getCoverages(); /** * Sets the DublinCore module coverages. *

+ * * @param coverages the list of String representing the DublinCore module - * coverages to set, an empty list or null if none. - * + * coverages to set, an empty list or null if none. + * */ void setCoverages(List coverages); @@ -513,6 +575,7 @@ public interface DCModule extends Module, CopyFrom { * Gets the DublinCore module coverage. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module coverage, null if none. */ String getCoverage(); @@ -521,33 +584,38 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module coverage. Convenience method that can be used * when there is only one coverage to set. *

- * @param coverage the DublinCore module coverage to set, null if none. - * + * + * @param coverage the DublinCore module coverage to set, null if + * none. + * */ void setCoverage(String coverage); /** * Returns the DublinCore module rights. *

- * @return a list of Strings representing the DublinCore module rights, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module rights, an + * empty list if none. + * */ List getRightsList(); /** * Sets the DublinCore module rightss. *

+ * * @param rights the list of String representing the DublinCore module - * rights to set, an empty list or null if none. - * + * rights to set, an empty list or null if none. + * */ void setRightsList(List rights); /** - * Gets the DublinCore module right. Convenience method that can be used - * to obtain the first item, null if none. + * Gets the DublinCore module right. Convenience method that can be used to + * obtain the first item, null if none. *

+ * * @return the first DublinCore module right, null if none. */ String getRights(); @@ -556,8 +624,9 @@ public interface DCModule extends Module, CopyFrom { * Sets the DublinCore module rights. Convenience method that can be used * when there is only one rights to set. *

+ * * @param rights the DublinCore module rights to set, null if none. - * + * */ void setRights(String rights); } diff --git a/src/main/java/com/sun/syndication/feed/module/DCModuleImpl.java b/src/main/java/com/sun/syndication/feed/module/DCModuleImpl.java index 047666c..fd07683 100644 --- a/src/main/java/com/sun/syndication/feed/module/DCModuleImpl.java +++ b/src/main/java/com/sun/syndication/feed/module/DCModuleImpl.java @@ -16,22 +16,30 @@ */ package com.sun.syndication.feed.module; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.impl.CopyFromHelper; import com.sun.syndication.feed.impl.ObjectBean; -import java.util.*; - - /** * Dublin Core ModuleImpl, default implementation. *

- * @see Dublin Core module. + * + * @see Dublin Core + * module. * @author Alejandro Abdelnur - * + * */ public class DCModuleImpl extends ModuleImpl implements DCModule { - private ObjectBean _objBean; + private final ObjectBean _objBean; private List _title; private List _creator; private List _subject; @@ -83,704 +91,826 @@ public class DCModuleImpl extends ModuleImpl implements DCModule { /** * Default constructor. All properties are set to null. *

- * + * */ public DCModuleImpl() { super(DCModule.class, URI); - _objBean = new ObjectBean(DCModule.class, this, CONVENIENCE_PROPERTIES); + this._objBean = new ObjectBean(DCModule.class, this, CONVENIENCE_PROPERTIES); } /** * Returns the DublinCore module titles. *

- * @return a list of Strings representing the DublinCore module title, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module title, an + * empty list if none. + * */ + @Override public List getTitles() { - return (_title == null) ? (_title = new ArrayList()) : _title; + return this._title == null ? (this._title = new ArrayList()) : this._title; } /** * Sets the DublinCore module titles. *

+ * * @param titles the list of String representing the DublinCore module - * titles to set, an empty list or null if none. - * + * titles to set, an empty list or null if none. + * */ - public void setTitles(List titles) { - _title = titles; + @Override + public void setTitles(final List titles) { + this._title = titles; } /** * Gets the DublinCore module title. Convenience method that can be used to * obtain the first item, null if none. *

+ * * @return the first DublinCore module title, null if none. */ + @Override public String getTitle() { - return ((_title != null) && (_title.size() > 0)) ? (String) _title.get(0) : null; + return this._title != null && this._title.size() > 0 ? (String) this._title.get(0) : null; } /** * Sets the DublinCore module title. Convenience method that can be used * when there is only one title to set. *

+ * * @param title the DublinCore module title to set, null if none. - * + * */ - public void setTitle(String title) { - _title = new ArrayList(); - _title.add(title); + @Override + public void setTitle(final String title) { + this._title = new ArrayList(); + this._title.add(title); } /** * Returns the DublinCore module creator. *

- * @return a list of Strings representing the DublinCore module creator, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module creator, an + * empty list if none. + * */ + @Override public List getCreators() { - return (_creator == null) ? (_creator = new ArrayList()) : _creator; + return this._creator == null ? (this._creator = new ArrayList()) : this._creator; } /** * Sets the DublinCore module creators. *

+ * * @param creators the list of String representing the DublinCore module - * creators to set, an empty list or null if none. - * + * creators to set, an empty list or null if none. + * */ - public void setCreators(List creators) { - _creator = creators; - } - - /** - * Gets the DublinCore module title. Convenience method that can be used - * to obtain the first item, null if none. - *

- * @return the first DublinCore module title, null if none. - */ - public String getCreator() { - return ((_creator != null) && (_creator.size() > 0)) ? (String) _creator.get(0) : null; - } - - /** - * Sets the DublinCore module creator. Convenience method that can be used - * when there is only one creator to set. - *

- * @param creator the DublinCore module creator to set, null if none. - * - */ - public void setCreator(String creator) { - _creator = new ArrayList(); - _creator.add(creator); - } - - /** - * Returns the DublinCore module subjects. - *

- * @return a list of DCSubject elements with the DublinCore module subjects, - * an empty list if none. - * - */ - public List getSubjects() { - return (_subject == null) ? (_subject = new ArrayList()) : _subject; - } - - /** - * Sets the DublinCore module subjects. - *

- * @param subjects the list of DCSubject elements with the DublinCore - * module subjects to set, an empty list or null if none. - * - */ - public void setSubjects(List subjects) { - _subject = subjects; - } - - /** - * Gets the DublinCore module subject. Convenience method that can be used - * to obtain the first item, null if none. - *

- * @return the first DublinCore module subject, null if none. - */ - public DCSubject getSubject() { - return ((_subject != null) && (_subject.size() > 0)) ? - (DCSubject) _subject.get(0) : null; - } - - /** - * Sets the DCSubject element. Convenience method that can be used when - * there is only one subject to set. - *

- * @param subject the DublinCore module subject to set, null if none. - * - */ - public void setSubject(DCSubject subject) { - _subject = new ArrayList(); - _subject.add(subject); - } - - /** - * Returns the DublinCore module description. - *

- * @return a list of Strings representing the DublinCore module - * description, an empty list if none. - * - */ - public List getDescriptions() { - return (_description == null) ? (_description = new ArrayList()) : _description; - } - - /** - * Sets the DublinCore module descriptions. - *

- * @param descriptions the list of String representing the DublinCore - * module descriptions to set, an empty list or null if none. - * - */ - public void setDescriptions(List descriptions) { - _description = descriptions; - } - - /** - * Gets the DublinCore module description. Convenience method that can be - * used to obtain the first item, null if none. - *

- * @return the first DublinCore module description, null if none. - */ - public String getDescription() { - return ((_description != null) && (_description.size() > 0)) ? - (String) _description.get(0) : null; - } - - /** - * Sets the DublinCore module description. Convenience method that can be - * used when there is only one description to set. - *

- * @param description the DublinCore module description to set, null if none. - * - */ - public void setDescription(String description) { - _description = new ArrayList(); - _description.add(description); - } - - /** - * Returns the DublinCore module publisher. - *

- * @return a list of Strings representing the DublinCore module publisher, - * an empty list if none. - * - */ - public List getPublishers() { - return (_publisher == null) ? (_publisher = new ArrayList()) : _publisher; - } - - /** - * Sets the DublinCore module publishers. - *

- * @param publishers the list of String representing the DublinCore module - * publishers to set, an empty list or null if none. - * - */ - public void setPublishers(List publishers) { - _publisher = publishers; + @Override + public void setCreators(final List creators) { + this._creator = creators; } /** * Gets the DublinCore module title. Convenience method that can be used to * obtain the first item, null if none. *

+ * * @return the first DublinCore module title, null if none. */ - public String getPublisher() { - return ((_publisher != null) && (_publisher.size() > 0)) ? - (String) _publisher.get(0) : null; + @Override + public String getCreator() { + return this._creator != null && this._creator.size() > 0 ? (String) this._creator.get(0) : null; } /** - * Sets the DublinCore module publisher. Convenience method that can be - * used when there is only one publisher to set. + * Sets the DublinCore module creator. Convenience method that can be used + * when there is only one creator to set. *

- * @param publisher the DublinCore module publisher to set, null if none. - * + * + * @param creator the DublinCore module creator to set, null if none. + * */ - public void setPublisher(String publisher) { - _publisher = new ArrayList(); - _publisher.add(publisher); + @Override + public void setCreator(final String creator) { + this._creator = new ArrayList(); + this._creator.add(creator); + } + + /** + * Returns the DublinCore module subjects. + *

+ * + * @return a list of DCSubject elements with the DublinCore module subjects, + * an empty list if none. + * + */ + @Override + public List getSubjects() { + return this._subject == null ? (this._subject = new ArrayList()) : this._subject; + } + + /** + * Sets the DublinCore module subjects. + *

+ * + * @param subjects the list of DCSubject elements with the DublinCore module + * subjects to set, an empty list or null if none. + * + */ + @Override + public void setSubjects(final List subjects) { + this._subject = subjects; + } + + /** + * Gets the DublinCore module subject. Convenience method that can be used + * to obtain the first item, null if none. + *

+ * + * @return the first DublinCore module subject, null if none. + */ + @Override + public DCSubject getSubject() { + return this._subject != null && this._subject.size() > 0 ? (DCSubject) this._subject.get(0) : null; + } + + /** + * Sets the DCSubject element. Convenience method that can be used when + * there is only one subject to set. + *

+ * + * @param subject the DublinCore module subject to set, null if none. + * + */ + @Override + public void setSubject(final DCSubject subject) { + this._subject = new ArrayList(); + this._subject.add(subject); + } + + /** + * Returns the DublinCore module description. + *

+ * + * @return a list of Strings representing the DublinCore module description, + * an empty list if none. + * + */ + @Override + public List getDescriptions() { + return this._description == null ? (this._description = new ArrayList()) : this._description; + } + + /** + * Sets the DublinCore module descriptions. + *

+ * + * @param descriptions the list of String representing the DublinCore module + * descriptions to set, an empty list or null if none. + * + */ + @Override + public void setDescriptions(final List descriptions) { + this._description = descriptions; + } + + /** + * Gets the DublinCore module description. Convenience method that can be + * used to obtain the first item, null if none. + *

+ * + * @return the first DublinCore module description, null if none. + */ + @Override + public String getDescription() { + return this._description != null && this._description.size() > 0 ? (String) this._description.get(0) : null; + } + + /** + * Sets the DublinCore module description. Convenience method that can be + * used when there is only one description to set. + *

+ * + * @param description the DublinCore module description to set, null + * if none. + * + */ + @Override + public void setDescription(final String description) { + this._description = new ArrayList(); + this._description.add(description); + } + + /** + * Returns the DublinCore module publisher. + *

+ * + * @return a list of Strings representing the DublinCore module publisher, + * an empty list if none. + * + */ + @Override + public List getPublishers() { + return this._publisher == null ? (this._publisher = new ArrayList()) : this._publisher; + } + + /** + * Sets the DublinCore module publishers. + *

+ * + * @param publishers the list of String representing the DublinCore module + * publishers to set, an empty list or null if none. + * + */ + @Override + public void setPublishers(final List publishers) { + this._publisher = publishers; + } + + /** + * Gets the DublinCore module title. Convenience method that can be used to + * obtain the first item, null if none. + *

+ * + * @return the first DublinCore module title, null if none. + */ + @Override + public String getPublisher() { + return this._publisher != null && this._publisher.size() > 0 ? (String) this._publisher.get(0) : null; + } + + /** + * Sets the DublinCore module publisher. Convenience method that can be used + * when there is only one publisher to set. + *

+ * + * @param publisher the DublinCore module publisher to set, null if + * none. + * + */ + @Override + public void setPublisher(final String publisher) { + this._publisher = new ArrayList(); + this._publisher.add(publisher); } /** * Returns the DublinCore module contributor. *

+ * * @return a list of Strings representing the DublinCore module contributor, * an empty list if none. - * + * */ + @Override public List getContributors() { - return (_contributors == null) ? (_contributors = new ArrayList()) : _contributors; + return this._contributors == null ? (this._contributors = new ArrayList()) : this._contributors; } /** * Sets the DublinCore module contributors. *

- * @param contributors the list of String representing the DublinCore - * module contributors to set, an empty list or null if none. - * + * + * @param contributors the list of String representing the DublinCore module + * contributors to set, an empty list or null if none. + * */ - public void setContributors(List contributors) { - _contributors = contributors; + @Override + public void setContributors(final List contributors) { + this._contributors = contributors; } /** * Gets the DublinCore module contributor. Convenience method that can be * used to obtain the first item, null if none. *

+ * * @return the first DublinCore module contributor, null if none. */ + @Override public String getContributor() { - return ((_contributors != null) && (_contributors.size() > 0)) ? - (String) _contributors.get(0) : null; + return this._contributors != null && this._contributors.size() > 0 ? (String) this._contributors.get(0) : null; } - + /** * Sets the DublinCore module contributor. Convenience method that can be * used when there is only one contributor to set. *

- * @param contributor the DublinCore module contributor to set, null if none. - * + * + * @param contributor the DublinCore module contributor to set, null + * if none. + * */ - public void setContributor(String contributor) { - _contributors = new ArrayList(); - _contributors.add(contributor); + @Override + public void setContributor(final String contributor) { + this._contributors = new ArrayList(); + this._contributors.add(contributor); } /** * Returns the DublinCore module date. *

- * @return a list of Strings representing the DublinCore module date, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module date, an + * empty list if none. + * */ + @Override public List getDates() { - return (_date == null) ? (_date = new ArrayList()) : _date; + return this._date == null ? (this._date = new ArrayList()) : this._date; } /** * Sets the DublinCore module dates. *

- * @param dates the list of Date representing the DublinCore module dates - * to set, an empty list or null if none. - * + * + * @param dates the list of Date representing the DublinCore module dates to + * set, an empty list or null if none. + * */ - public void setDates(List dates) { - _date = dates; + @Override + public void setDates(final List dates) { + this._date = dates; } - + /** * Gets the DublinCore module date. Convenience method that can be used to * obtain the first item, null if none. *

+ * * @return the first DublinCore module date, null if none. */ + @Override public Date getDate() { - return ((_date != null) && (_date.size() > 0)) ? - (Date) _date.get(0) : null; + return this._date != null && this._date.size() > 0 ? (Date) this._date.get(0) : null; } + /** - * Sets the DublinCore module date. Convenience method that can be used - * when there is only one date to set. + * Sets the DublinCore module date. Convenience method that can be used when + * there is only one date to set. *

+ * * @param date the DublinCore module date to set, null if none. - * + * */ - public void setDate(Date date) { - _date = new ArrayList(); - _date.add(date); + @Override + public void setDate(final Date date) { + this._date = new ArrayList(); + this._date.add(date); } /** * Returns the DublinCore module type. *

- * @return a list of Strings representing the DublinCore module type, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module type, an + * empty list if none. + * */ + @Override public List getTypes() { - return (_type == null) ? (_type = new ArrayList()) : _type; + return this._type == null ? (this._type = new ArrayList()) : this._type; } /** * Sets the DublinCore module types. *

+ * * @param types the list of String representing the DublinCore module types - * to set, an empty list or null if none. - * + * to set, an empty list or null if none. + * */ - public void setTypes(List types) { - _type = types; + @Override + public void setTypes(final List types) { + this._type = types; } - + /** * Gets the DublinCore module type. Convenience method that can be used to * obtain the first item, null if none. *

+ * * @return the first DublinCore module type, null if none. */ + @Override public String getType() { - return ((_type != null) && (_type.size() > 0)) ? - (String) _type.get(0) : null; + return this._type != null && this._type.size() > 0 ? (String) this._type.get(0) : null; } - + /** - * Sets the DublinCore module type. Convenience method that can be used - * when there is only one type to set. + * Sets the DublinCore module type. Convenience method that can be used when + * there is only one type to set. *

+ * * @param type the DublinCore module type to set, null if none. - * + * */ - public void setType(String type) { - _type = new ArrayList(); - _type.add(type); + @Override + public void setType(final String type) { + this._type = new ArrayList(); + this._type.add(type); } /** * Returns the DublinCore module format. *

- * @return a list of Strings representing the DublinCore module format, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module format, an + * empty list if none. + * */ + @Override public List getFormats() { - return (_format == null) ? (_format = new ArrayList()) : _format; + return this._format == null ? (this._format = new ArrayList()) : this._format; } /** * Sets the DublinCore module formats. *

+ * * @param formats the list of String representing the DublinCore module - * formats to set, an empty list or null if none. - * + * formats to set, an empty list or null if none. + * */ - public void setFormats(List formats) { - _format = formats; + @Override + public void setFormats(final List formats) { + this._format = formats; } /** - * Gets the DublinCore module format. Convenience method that can be used - * to obtain the first item, null if none. + * Gets the DublinCore module format. Convenience method that can be used to + * obtain the first item, null if none. *

+ * * @return the first DublinCore module format, null if none. */ + @Override public String getFormat() { - return ((_format != null) && (_format.size() > 0)) ? - (String) _format.get(0) : null; + return this._format != null && this._format.size() > 0 ? (String) this._format.get(0) : null; } /** * Sets the DublinCore module format. Convenience method that can be used * when there is only one format to set. *

+ * * @param format the DublinCore module format to set, null if none. - * + * */ - public void setFormat(String format) { - _format = new ArrayList(); - _format.add(format); + @Override + public void setFormat(final String format) { + this._format = new ArrayList(); + this._format.add(format); } /** * Returns the DublinCore module identifier. *

+ * * @return a list of Strings representing the DublinCore module identifier, * an empty list if none. - * + * */ + @Override public List getIdentifiers() { - return (_identifier == null) ? (_identifier = new ArrayList()) : _identifier; + return this._identifier == null ? (this._identifier = new ArrayList()) : this._identifier; } /** * Sets the DublinCore module identifiers. *

+ * * @param identifiers the list of String representing the DublinCore module - * identifiers to set, an empty list or null if none. - * + * identifiers to set, an empty list or null if none. + * */ - public void setIdentifiers(List identifiers) { - _identifier = identifiers; + @Override + public void setIdentifiers(final List identifiers) { + this._identifier = identifiers; } - + /** * Gets the DublinCore module identifier. Convenience method that can be * used to obtain the first item, null if none. *

+ * * @return the first DublinCore module identifier, null if none. */ + @Override public String getIdentifier() { - return ((_identifier != null) && (_identifier.size() > 0)) ? - (String) _identifier.get(0) : null; + return this._identifier != null && this._identifier.size() > 0 ? (String) this._identifier.get(0) : null; } /** * Sets the DublinCore module identifier. Convenience method that can be * used when there is only one identifier to set. *

- * @param identifier the DublinCore module identifier to set, null if none. - * + * + * @param identifier the DublinCore module identifier to set, null if + * none. + * */ - public void setIdentifier(String identifier) { - _identifier = new ArrayList(); - _identifier.add(identifier); + @Override + public void setIdentifier(final String identifier) { + this._identifier = new ArrayList(); + this._identifier.add(identifier); } /** * Returns the DublinCore module source. *

- * @return a list of Strings representing the DublinCore module source, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module source, an + * empty list if none. + * */ + @Override public List getSources() { - return (_source == null) ? (_source = new ArrayList()) : _source; + return this._source == null ? (this._source = new ArrayList()) : this._source; } /** * Sets the DublinCore module sources. *

+ * * @param sources the list of String representing the DublinCore module - * sources to set, an empty list or null if none. - * + * sources to set, an empty list or null if none. + * */ - public void setSources(List sources) { - _source = sources; + @Override + public void setSources(final List sources) { + this._source = sources; } - + /** - * Gets the DublinCore module source. Convenience method that can be used - * to obtain the first item, null if none. + * Gets the DublinCore module source. Convenience method that can be used to + * obtain the first item, null if none. *

+ * * @return the first DublinCore module source, null if none. */ + @Override public String getSource() { - return ((_source != null) && (_source.size() > 0)) ? - (String) _source.get(0) : null; + return this._source != null && this._source.size() > 0 ? (String) this._source.get(0) : null; } /** * Sets the DublinCore module source. Convenience method that can be used * when there is only one source to set. *

+ * * @param source the DublinCore module source to set, null if none. - * + * */ - public void setSource(String source) { - _source = new ArrayList(); - _source.add(source); + @Override + public void setSource(final String source) { + this._source = new ArrayList(); + this._source.add(source); } /** * Returns the DublinCore module language. *

- * @return a list of Strings representing the DublinCore module language, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module language, an + * empty list if none. + * */ + @Override public List getLanguages() { - return (_language == null) ? (_language = new ArrayList()) : _language; + return this._language == null ? (this._language = new ArrayList()) : this._language; } /** * Sets the DublinCore module languages. *

+ * * @param languages the list of String representing the DublinCore module - * languages to set, an empty list or null if none. - * + * languages to set, an empty list or null if none. + * */ - public void setLanguages(List languages) { - _language = languages; + @Override + public void setLanguages(final List languages) { + this._language = languages; } /** - * Gets the DublinCore module language. Convenience method that can be - * used to obtain the first item, null if none. + * Gets the DublinCore module language. Convenience method that can be used + * to obtain the first item, null if none. *

+ * * @return the first DublinCore module langauge, null if none. */ + @Override public String getLanguage() { - return ((_language != null) && (_language.size() > 0)) ? - (String) _language.get(0) : null; + return this._language != null && this._language.size() > 0 ? (String) this._language.get(0) : null; } + /** * Sets the DublinCore module language. Convenience method that can be used * when there is only one language to set. *

- * @param language the DublinCore module language to set, null if none. - * + * + * @param language the DublinCore module language to set, null if + * none. + * */ - public void setLanguage(String language) { - _language = new ArrayList(); - _language.add(language); + @Override + public void setLanguage(final String language) { + this._language = new ArrayList(); + this._language.add(language); } /** * Returns the DublinCore module relation. *

- * @return a list of Strings representing the DublinCore module relation, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module relation, an + * empty list if none. + * */ + @Override public List getRelations() { - return (_relation == null) ? (_relation = new ArrayList()) : _relation; + return this._relation == null ? (this._relation = new ArrayList()) : this._relation; } /** * Sets the DublinCore module relations. *

+ * * @param relations the list of String representing the DublinCore module - * relations to set, an empty list or null if none. - * + * relations to set, an empty list or null if none. + * */ - public void setRelations(List relations) { - _relation = relations; + @Override + public void setRelations(final List relations) { + this._relation = relations; } /** * Gets the DublinCore module relation. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module relation, null if none. */ + @Override public String getRelation() { - return ((_relation != null) && (_relation.size() > 0)) ? - (String) _relation.get(0) : null; + return this._relation != null && this._relation.size() > 0 ? (String) this._relation.get(0) : null; } /** * Sets the DublinCore module relation. Convenience method that can be used * when there is only one relation to set. *

- * @param relation the DublinCore module relation to set, null if none. - * + * + * @param relation the DublinCore module relation to set, null if + * none. + * */ - public void setRelation(String relation) { - _relation = new ArrayList(); - _relation.add(relation); + @Override + public void setRelation(final String relation) { + this._relation = new ArrayList(); + this._relation.add(relation); } /** * Returns the DublinCore module coverage. *

- * @return a list of Strings representing the DublinCore module coverage, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module coverage, an + * empty list if none. + * */ + @Override public List getCoverages() { - return (_coverage == null) ? (_coverage = new ArrayList()) : _coverage; + return this._coverage == null ? (this._coverage = new ArrayList()) : this._coverage; } /** * Sets the DublinCore module coverages. *

+ * * @param coverages the list of String representing the DublinCore module - * coverages to set, an empty list or null if none. - * + * coverages to set, an empty list or null if none. + * */ - public void setCoverages(List coverages) { - _coverage = coverages; + @Override + public void setCoverages(final List coverages) { + this._coverage = coverages; } /** * Gets the DublinCore module coverage. Convenience method that can be used * to obtain the first item, null if none. *

+ * * @return the first DublinCore module coverage, null if none. */ + @Override public String getCoverage() { - return ((_coverage != null) && (_coverage.size() > 0)) ? - (String) _coverage.get(0) : null; + return this._coverage != null && this._coverage.size() > 0 ? (String) this._coverage.get(0) : null; } /** * Sets the DublinCore module coverage. Convenience method that can be used * when there is only one coverage to set. *

- * @param coverage the DublinCore module coverage to set, null if none. - * + * + * @param coverage the DublinCore module coverage to set, null if + * none. + * */ - public void setCoverage(String coverage) { - _coverage = new ArrayList(); - _coverage.add(coverage); + @Override + public void setCoverage(final String coverage) { + this._coverage = new ArrayList(); + this._coverage.add(coverage); } /** * Returns the DublinCore module rights. *

- * @return a list of Strings representing the DublinCore module rights, - * an empty list if none. - * + * + * @return a list of Strings representing the DublinCore module rights, an + * empty list if none. + * */ + @Override public List getRightsList() { - return (_rights == null) ? (_rights = new ArrayList()) : _rights; + return this._rights == null ? (this._rights = new ArrayList()) : this._rights; } /** * Sets the DublinCore module rights. *

+ * * @param rights the list of String representing the DublinCore module - * rights to set, an empty list or null if none. - * + * rights to set, an empty list or null if none. + * */ - public void setRightsList(List rights) { - _rights = rights; + @Override + public void setRightsList(final List rights) { + this._rights = rights; } - + /** - * Gets the DublinCore module rights. Convenience method that can be used - * to obtain the first item, null if none. + * Gets the DublinCore module rights. Convenience method that can be used to + * obtain the first item, null if none. *

+ * * @return the first DublinCore module rights, null if none. */ + @Override public String getRights() { - return ((_rights != null) && (_rights.size() > 0)) ? - (String) _rights.get(0) : null; + return this._rights != null && this._rights.size() > 0 ? (String) this._rights.get(0) : null; } - + /** * Sets the DublinCore module rights. Convenience method that can be used * when there is only one rights to set. *

+ * * @param rights the DublinCore module rights to set, null if none. - * + * */ - public void setRights(String rights) { - _rights = new ArrayList(); - _rights.add(rights); + @Override + public void setRights(final String rights) { + this._rights = new ArrayList(); + this._rights.add(rights); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ + @Override public final Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public final boolean equals(Object other) { - return _objBean.equals(other); + @Override + public final boolean equals(final Object other) { + return this._objBean.equals(other); } /** @@ -788,36 +918,41 @@ public class DCModuleImpl extends ModuleImpl implements DCModule { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ + @Override public final int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public final String toString() { - return _objBean.toString(); + return this._objBean.toString(); } - + + @Override public final Class getInterface() { return DCModule.class; } - public final void copyFrom(CopyFrom obj) { - COPY_FROM_HELPER.copy(this,obj); + @Override + public final void copyFrom(final CopyFrom obj) { + COPY_FROM_HELPER.copy(this, obj); } private static final CopyFromHelper COPY_FROM_HELPER; - + static { - Map basePropInterfaceMap = new HashMap(); + final Map basePropInterfaceMap = new HashMap(); basePropInterfaceMap.put("titles", String.class); basePropInterfaceMap.put("creators", String.class); basePropInterfaceMap.put("subjects", DCSubject.class); @@ -834,9 +969,9 @@ public class DCModuleImpl extends ModuleImpl implements DCModule { basePropInterfaceMap.put("coverages", String.class); basePropInterfaceMap.put("rightsList", String.class); - Map basePropClassImplMap = new HashMap(); - basePropClassImplMap.put(DCSubject.class,DCSubjectImpl.class); + final Map basePropClassImplMap = new HashMap(); + basePropClassImplMap.put(DCSubject.class, DCSubjectImpl.class); - COPY_FROM_HELPER = new CopyFromHelper(DCModule.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(DCModule.class, basePropInterfaceMap, basePropClassImplMap); } } diff --git a/src/main/java/com/sun/syndication/feed/module/DCSubject.java b/src/main/java/com/sun/syndication/feed/module/DCSubject.java index d4fb96e..3c79b4d 100644 --- a/src/main/java/com/sun/syndication/feed/module/DCSubject.java +++ b/src/main/java/com/sun/syndication/feed/module/DCSubject.java @@ -21,49 +21,58 @@ import com.sun.syndication.feed.CopyFrom; /** * Subject of the Dublin Core ModuleImpl. *

- * @see Dublin Core module. + * + * @see Dublin Core + * module. * @author Alejandro Abdelnur - * + * */ -public interface DCSubject extends Cloneable,CopyFrom { +public interface DCSubject extends Cloneable, CopyFrom { /** * Returns the DublinCore subject taxonomy URI. *

+ * * @return the DublinCore subject taxonomy URI, null if none. - * + * */ String getTaxonomyUri(); /** * Sets the DublinCore subject taxonomy URI. *

- * @param taxonomyUri the DublinCore subject taxonomy URI to set, null if none. - * + * + * @param taxonomyUri the DublinCore subject taxonomy URI to set, + * null if none. + * */ void setTaxonomyUri(String taxonomyUri); /** * Returns the DublinCore subject value. *

+ * * @return the DublinCore subject value, null if none. - * + * */ String getValue(); /** * Sets the DublinCore subject value. *

+ * * @param value the DublinCore subject value to set, null if none. - * + * */ void setValue(String value); /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; diff --git a/src/main/java/com/sun/syndication/feed/module/DCSubjectImpl.java b/src/main/java/com/sun/syndication/feed/module/DCSubjectImpl.java index 038d5e3..e9b89c2 100644 --- a/src/main/java/com/sun/syndication/feed/module/DCSubjectImpl.java +++ b/src/main/java/com/sun/syndication/feed/module/DCSubjectImpl.java @@ -16,61 +16,67 @@ */ package com.sun.syndication.feed.module; -import com.sun.syndication.feed.CopyFrom; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.impl.CopyFromHelper; - +import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.io.Serializable; + +import com.sun.syndication.feed.CopyFrom; +import com.sun.syndication.feed.impl.CopyFromHelper; +import com.sun.syndication.feed.impl.ObjectBean; /** * Subject of the Dublin Core ModuleImpl, default implementation. *

- * @see Dublin Core module. + * + * @see Dublin Core + * module. * @author Alejandro Abdelnur - * + * */ -public class DCSubjectImpl implements Cloneable,Serializable, DCSubject { - private ObjectBean _objBean; +public class DCSubjectImpl implements Cloneable, Serializable, DCSubject { + private final ObjectBean _objBean; private String _taxonomyUri; private String _value; /** * Default constructor. All properties are set to null. *

- * + * */ public DCSubjectImpl() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof DCSubjectImpl)){ + public boolean equals(final Object other) { + if (!(other instanceof DCSubjectImpl)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -78,83 +84,96 @@ public class DCSubjectImpl implements Cloneable,Serializable, DCSubject { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the DublinCore subject taxonomy URI. *

+ * * @return the DublinCore subject taxonomy URI, null if none. - * + * */ + @Override public String getTaxonomyUri() { - return _taxonomyUri; + return this._taxonomyUri; } /** * Sets the DublinCore subject taxonomy URI. *

- * @param taxonomyUri the DublinCore subject taxonomy URI to set, null if none. - * + * + * @param taxonomyUri the DublinCore subject taxonomy URI to set, + * null if none. + * */ - public void setTaxonomyUri(String taxonomyUri) { - _taxonomyUri = taxonomyUri; + @Override + public void setTaxonomyUri(final String taxonomyUri) { + this._taxonomyUri = taxonomyUri; } /** * Returns the DublinCore subject value. *

+ * * @return the DublinCore subject value, null if none. - * + * */ + @Override public String getValue() { - return _value; + return this._value; } /** * Sets the DublinCore subject value. *

+ * * @param value the DublinCore subject value to set, null if none. - * + * */ - public void setValue(String value) { - _value = value; + @Override + public void setValue(final String value) { + this._value = value; } + @Override public Class getInterface() { return DCSubject.class; } - public void copyFrom(CopyFrom obj) { - COPY_FROM_HELPER.copy(this,obj); + @Override + public void copyFrom(final CopyFrom obj) { + COPY_FROM_HELPER.copy(this, obj); } private static final CopyFromHelper COPY_FROM_HELPER; static { - Map basePropInterfaceMap = new HashMap(); - basePropInterfaceMap.put("taxonomyUri",String.class); - basePropInterfaceMap.put("value",String.class); + final Map basePropInterfaceMap = new HashMap(); + basePropInterfaceMap.put("taxonomyUri", String.class); + basePropInterfaceMap.put("value", String.class); - Map basePropClassImplMap = Collections.EMPTY_MAP; + final Map basePropClassImplMap = Collections.EMPTY_MAP; - COPY_FROM_HELPER = new CopyFromHelper(DCSubject.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(DCSubject.class, basePropInterfaceMap, basePropClassImplMap); } } diff --git a/src/main/java/com/sun/syndication/feed/module/Extendable.java b/src/main/java/com/sun/syndication/feed/module/Extendable.java index f58f774..f63668c 100644 --- a/src/main/java/com/sun/syndication/feed/module/Extendable.java +++ b/src/main/java/com/sun/syndication/feed/module/Extendable.java @@ -21,13 +21,15 @@ import java.util.List; /** * Objects that can have modules are Extendable. + * * @author Dave Johnson */ public interface Extendable { - + /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ @@ -36,18 +38,20 @@ public interface Extendable { /** * Returns the entry modules. *

- * @return a list of ModuleImpl elements with the entry modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the entry modules, an empty + * list if none. + * */ List getModules(); /** * Sets the entry modules. *

- * @param modules the list of ModuleImpl elements with the entry modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the entry modules to + * set, an empty list or null if none. + * */ void setModules(List modules); } diff --git a/src/main/java/com/sun/syndication/feed/module/Module.java b/src/main/java/com/sun/syndication/feed/module/Module.java index 8ba7f94..4e2950d 100644 --- a/src/main/java/com/sun/syndication/feed/module/Module.java +++ b/src/main/java/com/sun/syndication/feed/module/Module.java @@ -16,32 +16,37 @@ */ package com.sun.syndication.feed.module; -import com.sun.syndication.feed.CopyFrom; import java.io.Serializable; +import com.sun.syndication.feed.CopyFrom; + /** - * Base class for modules describing Metadata of feeds. Examples of such modules are - * the Dublin Core and Syndication modules. + * Base class for modules describing Metadata of feeds. Examples of such modules + * are the Dublin Core and Syndication modules. *

+ * * @author Alejandro Abdelnur - * + * */ -public interface Module extends Cloneable,CopyFrom,Serializable{ +public interface Module extends Cloneable, CopyFrom, Serializable { /** * Returns the URI of the module. *

+ * * @return URI of the module. - * + * */ String getUri(); /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; diff --git a/src/main/java/com/sun/syndication/feed/module/ModuleImpl.java b/src/main/java/com/sun/syndication/feed/module/ModuleImpl.java index 7e80031..7f608d0 100644 --- a/src/main/java/com/sun/syndication/feed/module/ModuleImpl.java +++ b/src/main/java/com/sun/syndication/feed/module/ModuleImpl.java @@ -16,57 +16,63 @@ */ package com.sun.syndication.feed.module; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Base class for modules describing Metadata of feeds, default implementations. * Examples of such modules are the Dublin Core and Syndication modules. *

+ * * @author Alejandro Abdelnur - * + * */ -public abstract class ModuleImpl implements Cloneable,Serializable,Module { - private ObjectBean _objBean; - private String _uri; +public abstract class ModuleImpl implements Cloneable, Serializable, Module { + private final ObjectBean _objBean; + private final String _uri; /** * Constructor. *

+ * * @param uri URI of the module. - * + * */ - protected ModuleImpl(Class beanClass,String uri) { - _objBean = new ObjectBean(beanClass,this); - _uri = uri; + protected ModuleImpl(final Class beanClass, final String uri) { + this._objBean = new ObjectBean(beanClass, this); + this._uri = uri; } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof ModuleImpl)){ + public boolean equals(final Object other) { + if (!(other instanceof ModuleImpl)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -74,33 +80,37 @@ public abstract class ModuleImpl implements Cloneable,Serializable,Module { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the URI of the module. *

+ * * @return URI of the module. - * + * */ + @Override public String getUri() { - return _uri; + return this._uri; } } diff --git a/src/main/java/com/sun/syndication/feed/module/SyModule.java b/src/main/java/com/sun/syndication/feed/module/SyModule.java index f241e91..c2ee14b 100644 --- a/src/main/java/com/sun/syndication/feed/module/SyModule.java +++ b/src/main/java/com/sun/syndication/feed/module/SyModule.java @@ -21,69 +21,82 @@ import java.util.Date; /** * Syndication ModuleImpl. *

- * @see Syndication module. + * + * @see Syndication + * module. * @author Alejandro Abdelnur - * + * */ public interface SyModule extends Module { /** - * URI of the Syndication ModuleImpl (http://purl.org/rss/1.0/modules/syndication/). - * + * URI of the Syndication ModuleImpl + * (http://purl.org/rss/1.0/modules/syndication/). + * */ static final String URI = "http://purl.org/rss/1.0/modules/syndication/"; - static final String HOURLY = "hourly"; - static final String DAILY = "daily"; - static final String WEEKLY = "weekly"; + static final String HOURLY = "hourly"; + static final String DAILY = "daily"; + static final String WEEKLY = "weekly"; static final String MONTHLY = "monthly"; - static final String YEARLY = "yearly"; + static final String YEARLY = "yearly"; /** * Returns the Syndication module update period. *

+ * * @return the Syndication module update period, null if none. - * + * */ String getUpdatePeriod(); /** * Sets the Syndication module update period. *

- * @param updatePeriod the Syndication module update period to set, null if none. - * + * + * @param updatePeriod the Syndication module update period to set, + * null if none. + * */ void setUpdatePeriod(String updatePeriod); /** * Returns the Syndication module update frequency. *

+ * * @return the Syndication module update frequency, null if none. - * + * */ int getUpdateFrequency(); /** * Sets the Syndication module update frequency. *

- * @param updateFrequency the Syndication module update frequency to set, null if none. - * + * + * @param updateFrequency the Syndication module update frequency to set, + * null if none. + * */ void setUpdateFrequency(int updateFrequency); /** * Returns the Syndication module update base date. *

+ * * @return the Syndication module update base date, null if none. - * + * */ Date getUpdateBase(); /** * Sets the Syndication module update base date. *

- * @param updateBase the Syndication module update base date to set, null if none. - * + * + * @param updateBase the Syndication module update base date to set, + * null if none. + * */ void setUpdateBase(Date updateBase); diff --git a/src/main/java/com/sun/syndication/feed/module/SyModuleImpl.java b/src/main/java/com/sun/syndication/feed/module/SyModuleImpl.java index a87e8a9..1c0c7d9 100644 --- a/src/main/java/com/sun/syndication/feed/module/SyModuleImpl.java +++ b/src/main/java/com/sun/syndication/feed/module/SyModuleImpl.java @@ -16,30 +16,37 @@ */ package com.sun.syndication.feed.module; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.impl.CopyFromHelper; -import java.util.*; - /** * Syndication ModuleImpl, default implementation. *

- * @see Syndication module. + * + * @see Syndication + * module. * @author Alejandro Abdelnur - * + * */ public class SyModuleImpl extends ModuleImpl implements SyModule { private static final Set PERIODS = new HashSet(); static { - PERIODS.add(HOURLY ); - PERIODS.add(DAILY ); - PERIODS.add(WEEKLY ); + PERIODS.add(HOURLY); + PERIODS.add(DAILY); + PERIODS.add(WEEKLY); PERIODS.add(MONTHLY); - PERIODS.add(YEARLY ); + PERIODS.add(YEARLY); } - private String _updatePeriod; private int _updateFrequency; private Date _updateBase; @@ -47,94 +54,111 @@ public class SyModuleImpl extends ModuleImpl implements SyModule { /** * Default constructor. All properties are set to null. *

- * + * */ public SyModuleImpl() { - super(SyModule.class,URI); + super(SyModule.class, URI); } /** * Returns the Syndication module update period. *

+ * * @return the Syndication module update period, null if none. - * + * */ + @Override public String getUpdatePeriod() { - return _updatePeriod; + return this._updatePeriod; } /** * Sets the Syndication module update period. *

- * @param updatePeriod the Syndication module update period to set, null if none. - * + * + * @param updatePeriod the Syndication module update period to set, + * null if none. + * */ - public void setUpdatePeriod(String updatePeriod) { + @Override + public void setUpdatePeriod(final String updatePeriod) { if (!PERIODS.contains(updatePeriod)) { - throw new IllegalArgumentException("Invalid period ["+updatePeriod+"]"); + throw new IllegalArgumentException("Invalid period [" + updatePeriod + "]"); } - _updatePeriod = updatePeriod; + this._updatePeriod = updatePeriod; } /** * Returns the Syndication module update frequency. *

+ * * @return the Syndication module update frequency, null if none. - * + * */ + @Override public int getUpdateFrequency() { - return _updateFrequency; + return this._updateFrequency; } /** * Sets the Syndication module update frequency. *

- * @param updateFrequency the Syndication module update frequency to set, null if none. - * + * + * @param updateFrequency the Syndication module update frequency to set, + * null if none. + * */ - public void setUpdateFrequency(int updateFrequency) { - _updateFrequency = updateFrequency; + @Override + public void setUpdateFrequency(final int updateFrequency) { + this._updateFrequency = updateFrequency; } /** * Returns the Syndication module update base date. *

+ * * @return the Syndication module update base date, null if none. - * + * */ + @Override public Date getUpdateBase() { - return new Date(_updateBase.getTime()); + return new Date(this._updateBase.getTime()); } /** * Sets the Syndication module update base date. *

- * @param updateBase the Syndication module update base date to set, null if none. - * + * + * @param updateBase the Syndication module update base date to set, + * null if none. + * */ - public void setUpdateBase(Date updateBase) { - _updateBase = new Date(updateBase.getTime()); + @Override + public void setUpdateBase(final Date updateBase) { + this._updateBase = new Date(updateBase.getTime()); } + @Override public Class getInterface() { return SyModule.class; } - public void copyFrom(CopyFrom obj) { - COPY_FROM_HELPER.copy(this,obj); + @Override + public void copyFrom(final CopyFrom obj) { + COPY_FROM_HELPER.copy(this, obj); } private static final CopyFromHelper COPY_FROM_HELPER; static { - Map basePropInterfaceMap = new HashMap(); - basePropInterfaceMap.put("updatePeriod",String.class); - basePropInterfaceMap.put("updateFrequency",Integer.TYPE); - basePropInterfaceMap.put("updateBase",Date.class); + final Map basePropInterfaceMap = new HashMap(); + basePropInterfaceMap.put("updatePeriod", String.class); + basePropInterfaceMap.put("updateFrequency", Integer.TYPE); + basePropInterfaceMap.put("updateBase", Date.class); - Map basePropClassImplMap = Collections.EMPTY_MAP; + final Map basePropClassImplMap = Collections.EMPTY_MAP; - COPY_FROM_HELPER = new CopyFromHelper(SyModule.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(SyModule.class, basePropInterfaceMap, basePropClassImplMap); } } diff --git a/src/main/java/com/sun/syndication/feed/module/impl/ModuleUtils.java b/src/main/java/com/sun/syndication/feed/module/impl/ModuleUtils.java index ca1738c..f1324c8 100644 --- a/src/main/java/com/sun/syndication/feed/module/impl/ModuleUtils.java +++ b/src/main/java/com/sun/syndication/feed/module/impl/ModuleUtils.java @@ -16,26 +16,25 @@ */ package com.sun.syndication.feed.module.impl; -import com.sun.syndication.feed.module.Module; - import java.util.ArrayList; import java.util.List; +import com.sun.syndication.feed.module.Module; + /** */ public class ModuleUtils { - public static List cloneModules(List modules) { + public static List cloneModules(final List modules) { List cModules = null; - if (modules!=null) { + if (modules != null) { cModules = new ArrayList(); - for (Module module : modules) { + for (final Module module : modules) { try { - Module c = (Module) module.clone(); + final Module c = (Module) module.clone(); cModules.add(c); - } - catch (Exception ex) { - throw new RuntimeException("Cloning modules "+module.getUri(),ex); + } catch (final Exception ex) { + throw new RuntimeException("Cloning modules " + module.getUri(), ex); } } } @@ -44,16 +43,16 @@ public class ModuleUtils { /** * - * + * * @since 1.5 Changed to return the first, not the last. * * @param modules * @param uri * @return */ - public static Module getModule(List modules,String uri) { + public static Module getModule(final List modules, final String uri) { Module module = null; - for (int i=0; modules!=null && i + * * @author Alejandro Abdelnur - * + * */ -public class Category implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Category implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _domain; private String _value; /** * Default constructor. All properties are set to null. *

- * + * */ public Category() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Category)){ + public boolean equals(final Object other) { + if (!(other instanceof Category)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -73,62 +78,69 @@ public class Category implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ + @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the category domain. *

+ * * @return the category domain, null if none. - * + * */ public String getDomain() { - return _domain; + return this._domain; } /** * Sets the category domain. *

+ * * @param domain the category domain to set, null if none. - * + * */ - public void setDomain(String domain) { - _domain = domain; + public void setDomain(final String domain) { + this._domain = domain; } /** * Returns the category value. *

+ * * @return the category value, null if none. - * + * */ public String getValue() { - return _value; + return this._value; } /** * Sets the category value. *

+ * * @param value the category value to set, null if none. - * + * */ - public void setValue(String value) { - _value = value; + public void setValue(final String value) { + this._value = value; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Channel.java b/src/main/java/com/sun/syndication/feed/rss/Channel.java index 53273ba..3abb08a 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Channel.java +++ b/src/main/java/com/sun/syndication/feed/rss/Channel.java @@ -17,41 +17,47 @@ */ package com.sun.syndication.feed.rss; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.module.impl.ModuleUtils; -import java.util.*; - /** * Bean for RSS feeds. *

* It handles all RSS versions (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) * without losing information. *

+ * * @author Alejandro Abdelnur - * + * */ public class Channel extends WireFeed { - public static final String SUNDAY = "sunday"; - public static final String MONDAY = "monday"; - public static final String TUESDAY = "tuesday"; + public static final String SUNDAY = "sunday"; + public static final String MONDAY = "monday"; + public static final String TUESDAY = "tuesday"; public static final String WEDNESDAY = "wednesday"; - public static final String THURSDAY = "thursday"; - public static final String FRIDAY = "friday"; - public static final String SATURDAY = "saturday"; + public static final String THURSDAY = "thursday"; + public static final String FRIDAY = "friday"; + public static final String SATURDAY = "saturday"; private static final Set DAYS; static { - HashSet days = new HashSet(); - days.add(SUNDAY ); - days.add(MONDAY ); - days.add(TUESDAY ); + final HashSet days = new HashSet(); + days.add(SUNDAY); + days.add(MONDAY); + days.add(TUESDAY); days.add(WEDNESDAY); - days.add(THURSDAY ); - days.add(FRIDAY ); - days.add(SATURDAY ); + days.add(THURSDAY); + days.add(FRIDAY); + days.add(SATURDAY); DAYS = Collections.unmodifiableSet(days); } @@ -80,510 +86,556 @@ public class Channel extends WireFeed { /** * Default constructor, for bean cloning purposes only. - * + * */ public Channel() { } /** - * Channel Constructor. All properties, except the type, are set to null. + * Channel Constructor. All properties, except the type, are set to + * null. *

+ * * @param type the type of the RSS feed. - * + * */ - public Channel(String type) { + public Channel(final String type) { super(type); } /** * Returns the channel title. *

+ * * @return the channel title, null if none. - * + * */ public String getTitle() { - return _title; + return this._title; } /** * Sets the channel title. *

+ * * @param title the channel title to set, null if none. - * + * */ - public void setTitle(String title) { - _title = title; + public void setTitle(final String title) { + this._title = title; } /** * Returns the channel description. *

+ * * @return the channel description, null if none. - * + * */ public String getDescription() { - return _description; + return this._description; } /** * Sets the channel description. *

+ * * @param description the channel description to set, null if none. - * + * */ - public void setDescription(String description) { - _description = description; + public void setDescription(final String description) { + this._description = description; } /** * Returns the channel link. *

+ * * @return the channel link, null if none. - * + * */ public String getLink() { - return _link; + return this._link; } /** * Sets the channel link. *

+ * * @param link the channel link to set, null if none. - * + * */ - public void setLink(String link) { - _link = link; + public void setLink(final String link) { + this._link = link; } /** * Returns the channel uri. *

+ * * @return the channel uri, null if none. */ public String getUri() { - return _uri; + return this._uri; } /** * Sets the channel uri. *

+ * * @param uri the channel uri, null if none. */ - public void setUri(String uri) { - _uri = uri; + public void setUri(final String uri) { + this._uri = uri; } /** * Returns the channel image. *

+ * * @return the channel image, null if none. - * + * */ public Image getImage() { - return _image; + return this._image; } /** * Sets the channel image. *

+ * * @param image the channel image to set, null if none. - * + * */ - public void setImage(Image image) { - _image = image; + public void setImage(final Image image) { + this._image = image; } /** * Returns the channel items. *

- * @return a list of Item elements with the channel items, - * an empty list if none. - * + * + * @return a list of Item elements with the channel items, an empty list if + * none. + * */ public List getItems() { - return (_items==null) ? (_items=new ArrayList()) : _items; + return this._items == null ? (this._items = new ArrayList()) : this._items; } /** * Sets the channel items. *

- * @param items the list of Item elements with the channel items to set, - * an empty list or null if none. - * + * + * @param items the list of Item elements with the channel items to set, an + * empty list or null if none. + * */ - public void setItems(List items) { - _items = items; + public void setItems(final List items) { + this._items = items; } /** * Returns the channel text input. *

+ * * @return the channel text input, null if none. - * + * */ public TextInput getTextInput() { - return _textInput; + return this._textInput; } /** * Sets the channel text input. *

+ * * @param textInput the channel text input to set, null if none. - * + * */ - public void setTextInput(TextInput textInput) { - _textInput = textInput; + public void setTextInput(final TextInput textInput) { + this._textInput = textInput; } /** * Returns the channel language. *

+ * * @return the channel language, null if none. - * + * */ public String getLanguage() { - return _language; + return this._language; } /** * Sets the channel language. *

+ * * @param language the channel language to set, null if none. - * + * */ - public void setLanguage(String language) { - _language = language; + public void setLanguage(final String language) { + this._language = language; } /** * Returns the channel rating. *

+ * * @return the channel rating, null if none. - * + * */ public String getRating() { - return _rating; + return this._rating; } /** * Sets the channel rating. *

+ * * @param rating the channel rating to set, null if none. - * + * */ - public void setRating(String rating) { - _rating = rating; + public void setRating(final String rating) { + this._rating = rating; } /** * Returns the channel copyright. *

+ * * @return the channel copyright, null if none. - * + * */ public String getCopyright() { - return _copyright; + return this._copyright; } /** * Sets the channel copyright. *

+ * * @param copyright the channel copyright to set, null if none. - * + * */ - public void setCopyright(String copyright) { - _copyright = copyright; + public void setCopyright(final String copyright) { + this._copyright = copyright; } /** * Returns the channel publishing date. *

+ * * @return the channel publishing date, null if none. - * + * */ public Date getPubDate() { - return _pubDate == null ? null : new Date(_pubDate.getTime()); + return this._pubDate == null ? null : new Date(this._pubDate.getTime()); } /** * Sets the channel publishing date. *

+ * * @param pubDate the channel publishing date to set, null if none. - * + * */ - public void setPubDate(Date pubDate) { - _pubDate = pubDate == null ? null : new Date( pubDate.getTime()); + public void setPubDate(final Date pubDate) { + this._pubDate = pubDate == null ? null : new Date(pubDate.getTime()); } /** * Returns the channel last build date. *

+ * * @return the channel last build date, null if none. - * + * */ public Date getLastBuildDate() { - return _lastBuildDate == null ? null : new Date(_lastBuildDate.getTime()); + return this._lastBuildDate == null ? null : new Date(this._lastBuildDate.getTime()); } /** * Sets the channel last build date. *

- * @param lastBuildDate the channel last build date to set, null if none. - * + * + * @param lastBuildDate the channel last build date to set, null if + * none. + * */ - public void setLastBuildDate(Date lastBuildDate) { - _lastBuildDate = lastBuildDate == null ? null : new Date( lastBuildDate.getTime()); + public void setLastBuildDate(final Date lastBuildDate) { + this._lastBuildDate = lastBuildDate == null ? null : new Date(lastBuildDate.getTime()); } /** * Returns the channel docs. *

+ * * @return the channel docs, null if none. - * + * */ public String getDocs() { - return _docs; + return this._docs; } /** * Sets the channel docs. *

+ * * @param docs the channel docs to set, null if none. - * + * */ - public void setDocs(String docs) { - _docs = docs; + public void setDocs(final String docs) { + this._docs = docs; } /** * Returns the channel managing editor. *

+ * * @return the channel managing editor, null if none. - * + * */ public String getManagingEditor() { - return _managingEditor; + return this._managingEditor; } /** * Sets the channel managing editor. *

- * @param managingEditor the channel managing editor to set, null if none. - * + * + * @param managingEditor the channel managing editor to set, null if + * none. + * */ - public void setManagingEditor(String managingEditor) { - _managingEditor = managingEditor; + public void setManagingEditor(final String managingEditor) { + this._managingEditor = managingEditor; } /** * Returns the channel web master. *

+ * * @return the channel web master, null if none. - * + * */ public String getWebMaster() { - return _webMaster; + return this._webMaster; } /** * Sets the channel web master. *

+ * * @param webMaster the channel web master to set, null if none. - * + * */ - public void setWebMaster(String webMaster) { - _webMaster = webMaster; + public void setWebMaster(final String webMaster) { + this._webMaster = webMaster; } /** * Returns the channel skip hours. *

- * @return a list of Integer elements with the channel skip hours, - * an empty list if none. - * + * + * @return a list of Integer elements with the channel skip hours, an empty + * list if none. + * */ public List getSkipHours() { - return (_skipHours!=null) ? _skipHours : new ArrayList(); + return this._skipHours != null ? this._skipHours : new ArrayList(); } /** * Sets the channel skip hours. *

- * @param skipHours the list of Integer elements with the channel skip hours to set, - * an empty list or null if none. - * + * + * @param skipHours the list of Integer elements with the channel skip hours + * to set, an empty list or null if none. + * */ - public void setSkipHours(List skipHours) { - if (skipHours!=null) { - for (int i=0;i24) { - throw new IllegalArgumentException("Invalid hour ["+hour+"]"); + public void setSkipHours(final List skipHours) { + if (skipHours != null) { + for (int i = 0; i < skipHours.size(); i++) { + final Integer iHour = skipHours.get(i); + if (iHour != null) { + final int hour = iHour.intValue(); + if (hour < 0 || hour > 24) { + throw new IllegalArgumentException("Invalid hour [" + hour + "]"); } - } - else { + } else { throw new IllegalArgumentException("Invalid hour [null]"); } } } - _skipHours = skipHours; + this._skipHours = skipHours; } /** * Returns the channel skip days. *

- * @return a list of Day elements with the channel skip days, - * an empty list if none. - * + * + * @return a list of Day elements with the channel skip days, an empty list + * if none. + * */ public List getSkipDays() { - return (_skipDays!=null) ? _skipDays : new ArrayList(); + return this._skipDays != null ? this._skipDays : new ArrayList(); } /** * Sets the channel skip days. *

- * @param skipDays the list of Day elements with the channel skip days to set, - * an empty list or null if none. - * + * + * @param skipDays the list of Day elements with the channel skip days to + * set, an empty list or null if none. + * */ - public void setSkipDays(List skipDays) { - if (skipDays!=null) { - for (int i=0;i skipDays) { + if (skipDays != null) { + for (int i = 0; i < skipDays.size(); i++) { + String day = skipDays.get(i); + if (day != null) { day = day.toLowerCase(); if (!DAYS.contains(day)) { - throw new IllegalArgumentException("Invalid day ["+day+"]"); + throw new IllegalArgumentException("Invalid day [" + day + "]"); } - skipDays.set(i,day); - } - else { + skipDays.set(i, day); + } else { throw new IllegalArgumentException("Invalid day [null]"); } } } - _skipDays = skipDays; + this._skipDays = skipDays; } /** * Returns the channel cloud. *

+ * * @return the channel cloud, null if none. - * + * */ public Cloud getCloud() { - return _cloud; + return this._cloud; } /** * Sets the channel cloud. *

+ * * @param cloud the channel cloud to set, null if none. - * + * */ - public void setCloud(Cloud cloud) { - _cloud = cloud; + public void setCloud(final Cloud cloud) { + this._cloud = cloud; } /** * Returns the channel categories. *

- * @return a list of Category elements with the channel categories, - * an empty list if none. - * + * + * @return a list of Category elements with the channel categories, an empty + * list if none. + * */ public List getCategories() { - return (_categories==null) ? (_categories=new ArrayList()) : _categories; + return this._categories == null ? (this._categories = new ArrayList()) : this._categories; } /** * Sets the channel categories. *

- * @param categories the list of Category elements with the channel categories to set, - * an empty list or null if none. - * + * + * @param categories the list of Category elements with the channel + * categories to set, an empty list or null if none. + * */ - public void setCategories(List categories) { - _categories = categories; + public void setCategories(final List categories) { + this._categories = categories; } /** * Returns the channel generator. *

+ * * @return the channel generator, null if none. - * + * */ public String getGenerator() { - return _generator; + return this._generator; } /** * Sets the channel generator. *

+ * * @param generator the channel generator to set, null if none. - * + * */ - public void setGenerator(String generator) { - _generator = generator; + public void setGenerator(final String generator) { + this._generator = generator; } /** * Returns the channel time to live. *

+ * * @return the channel time to live, null if none. - * + * */ public int getTtl() { - return _ttl; + return this._ttl; } /** * Sets the channel time to live. *

+ * * @param ttl the channel time to live to set, null if none. - * + * */ - public void setTtl(int ttl) { - _ttl = ttl; + public void setTtl(final int ttl) { + this._ttl = ttl; } /** * Returns the channel modules. *

- * @return a list of ModuleImpl elements with the channel modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the channel modules, an empty + * list if none. + * */ @Override public List getModules() { - return (_modules==null) ? (_modules=new ArrayList()) : _modules; + return this._modules == null ? (this._modules = new ArrayList()) : this._modules; } /** * Sets the channel modules. *

- * @param modules the list of ModuleImpl elements with the channel modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the channel modules + * to set, an empty list or null if none. + * */ @Override - public void setModules(List modules) { - _modules = modules; + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ @Override - public Module getModule(String uri) { - return ModuleUtils.getModule(_modules,uri); + public Module getModule(final String uri) { + return ModuleUtils.getModule(this._modules, uri); } - } diff --git a/src/main/java/com/sun/syndication/feed/rss/Cloud.java b/src/main/java/com/sun/syndication/feed/rss/Cloud.java index 69c27ae..d912bbd 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Cloud.java +++ b/src/main/java/com/sun/syndication/feed/rss/Cloud.java @@ -17,18 +17,19 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for clouds of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class Cloud implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Cloud implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _domain; private int _port; private String _path; @@ -38,33 +39,38 @@ public class Cloud implements Cloneable,Serializable { /** * Default constructor. All properties are set to null. *

- * + * */ public Cloud() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public boolean equals(Object other) { - return _objBean.equals(other); + @Override + public boolean equals(final Object other) { + return this._objBean.equals(other); } /** @@ -72,123 +78,136 @@ public class Cloud implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the cloud domain. *

+ * * @return the cloud domain, null if none. - * + * */ public String getDomain() { - return _domain; + return this._domain; } /** * Sets the cloud domain. *

+ * * @param domain the cloud domain to set, null if none. - * + * */ - public void setDomain(String domain) { - _domain = domain; + public void setDomain(final String domain) { + this._domain = domain; } /** * Returns the cloud port. *

+ * * @return the cloud port, null if none. - * + * */ public int getPort() { - return _port; + return this._port; } /** * Sets the cloud port. *

+ * * @param port the cloud port to set, null if none. - * + * */ - public void setPort(int port) { - _port = port; + public void setPort(final int port) { + this._port = port; } /** * Returns the cloud path. *

+ * * @return the cloud path, null if none. - * + * */ public String getPath() { - return _path; + return this._path; } /** * Sets the cloud path. *

+ * * @param path the cloud path to set, null if none. - * + * */ - public void setPath(String path) { - _path = path; + public void setPath(final String path) { + this._path = path; } /** * Returns the cloud register procedure. *

+ * * @return the cloud register procedure, null if none. - * + * */ public String getRegisterProcedure() { - return _registerProcedure; + return this._registerProcedure; } /** * Sets the cloud register procedure. *

- * @param registerProcedure the cloud register procedure to set, null if none. - * + * + * @param registerProcedure the cloud register procedure to set, null + * if none. + * */ - public void setRegisterProcedure(String registerProcedure) { - _registerProcedure = registerProcedure; + public void setRegisterProcedure(final String registerProcedure) { + this._registerProcedure = registerProcedure; } /** * Returns the cloud protocol. *

+ * * @return the cloud protocol, null if none. - * + * */ public String getProtocol() { - return _protocol; + return this._protocol; } /** * Sets the cloud protocol. *

+ * * @param protocol the cloud protocol to set, null if none. - * + * */ - public void setProtocol(String protocol) { - _protocol = protocol; + public void setProtocol(final String protocol) { + this._protocol = protocol; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Content.java b/src/main/java/com/sun/syndication/feed/rss/Content.java index 07a47df..6e1ba6b 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Content.java +++ b/src/main/java/com/sun/syndication/feed/rss/Content.java @@ -17,99 +17,107 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; /** * Bean for item descriptions of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ public class Content implements Cloneable, Serializable { public static final String HTML = "html"; public static final String TEXT = "text"; - private ObjectBean _objBean; + private final ObjectBean _objBean; private String _type; private String _value; /** * Default constructor. All properties are set to null. *

- * + * */ public Content() { - _objBean = new ObjectBean(this.getClass(), this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Sets the description type. *

+ * * @param type the description type to set, null if none. - * + * */ - public void setType(String type) { - _type = type; + public void setType(final String type) { + this._type = type; } /** * Returns the description type. *

+ * * @return the description type, null if none. - * + * */ public String getType() { - return _type; + return this._type; } /** * Sets the description value. *

+ * * @param value the description value to set, null if none. - * + * */ - public void setValue(String value) { - _value = value; + public void setValue(final String value) { + this._value = value; } /** * Returns the description value. *

+ * * @return the description value, null if none. - * + * */ public String getValue() { - return _value; + return this._value; } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { + public boolean equals(final Object other) { if (!(other instanceof Content)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -117,22 +125,24 @@ public class Content implements Cloneable, Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Description.java b/src/main/java/com/sun/syndication/feed/rss/Description.java index c032abe..07679b9 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Description.java +++ b/src/main/java/com/sun/syndication/feed/rss/Description.java @@ -17,54 +17,60 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for item descriptions of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class Description implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Description implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _type; private String _value; /** * Default constructor. All properties are set to null. *

- * + * */ public Description() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ + @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Description)){ + public boolean equals(final Object other) { + if (!(other instanceof Description)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -72,63 +78,69 @@ public class Description implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the description type. *

+ * * @return the description type, null if none. - * + * */ public String getType() { - return _type; + return this._type; } /** * Sets the description type. *

+ * * @param type the description type to set, null if none. - * + * */ - public void setType(String type) { - _type = type; + public void setType(final String type) { + this._type = type; } /** * Returns the description value. *

+ * * @return the description value, null if none. - * + * */ public String getValue() { - return _value; + return this._value; } /** * Sets the description value. *

+ * * @param value the description value to set, null if none. - * + * */ - public void setValue(String value) { - _value = value; + public void setValue(final String value) { + this._value = value; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Enclosure.java b/src/main/java/com/sun/syndication/feed/rss/Enclosure.java index 4d22131..3bfe746 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Enclosure.java +++ b/src/main/java/com/sun/syndication/feed/rss/Enclosure.java @@ -17,18 +17,19 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for item enclosures of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class Enclosure implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Enclosure implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _url; private long _length; private String _type; @@ -36,37 +37,41 @@ public class Enclosure implements Cloneable,Serializable { /** * Default constructor. All properties are set to null. *

- * + * */ public Enclosure() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Enclosure)){ + public boolean equals(final Object other) { + if (!(other instanceof Enclosure)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -74,83 +79,91 @@ public class Enclosure implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the enclosure URL. *

+ * * @return the enclosure URL, null if none. - * + * */ public String getUrl() { - return _url; + return this._url; } /** * Sets the enclosure URL. *

+ * * @param url the enclosure URL to set, null if none. - * + * */ - public void setUrl(String url) { - _url = url; + public void setUrl(final String url) { + this._url = url; } /** * Returns the enclosure length. *

+ * * @return the enclosure length, 0 if none. - * + * */ public long getLength() { - return _length; + return this._length; } /** * Sets the enclosure length. *

+ * * @param length the enclosure length to set, 0 if none. - * + * */ - public void setLength(long length) { - _length = length; + public void setLength(final long length) { + this._length = length; } /** * Returns the enclosure type. *

+ * * @return the enclosure type, null if none. - * + * */ public String getType() { - return _type; + return this._type; } /** * Sets the enclosure type. *

+ * * @param type the enclosure type to set, null if none. - * + * */ - public void setType(String type) { - _type = type; + public void setType(final String type) { + this._type = type; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Guid.java b/src/main/java/com/sun/syndication/feed/rss/Guid.java index e75ace4..1a081c8 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Guid.java +++ b/src/main/java/com/sun/syndication/feed/rss/Guid.java @@ -17,55 +17,60 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for item GUIDs of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class Guid implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Guid implements Cloneable, Serializable { + private final ObjectBean _objBean; private boolean _permaLink; private String _value; /** * Default constructor. All properties are set to null. *

- * + * */ public Guid() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Guid)){ + public boolean equals(final Object other) { + if (!(other instanceof Guid)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -73,63 +78,69 @@ public class Guid implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the guid perma link. *

+ * * @return the guid perma link, null if none. - * + * */ public boolean isPermaLink() { - return _permaLink; + return this._permaLink; } /** * Sets the guid perma link. *

+ * * @param permaLink the guid perma link to set, null if none. - * + * */ - public void setPermaLink(boolean permaLink) { - _permaLink = permaLink; + public void setPermaLink(final boolean permaLink) { + this._permaLink = permaLink; } /** * Returns the guid value. *

+ * * @return the guid value, null if none. - * + * */ public String getValue() { - return _value; + return this._value; } /** * Sets the guid value. *

+ * * @param value the guid value to set, null if none. - * + * */ - public void setValue(String value) { - _value = value; + public void setValue(final String value) { + this._value = value; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Image.java b/src/main/java/com/sun/syndication/feed/rss/Image.java index 4971683..e990cfd 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Image.java +++ b/src/main/java/com/sun/syndication/feed/rss/Image.java @@ -16,18 +16,19 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for images of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class Image implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Image implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _title; private String _url; private String _link; @@ -38,37 +39,41 @@ public class Image implements Cloneable,Serializable { /** * Default constructor. All properties are set to null. *

- * + * */ public Image() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Image)){ + public boolean equals(final Object other) { + if (!(other instanceof Image)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -76,143 +81,157 @@ public class Image implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the image title. *

+ * * @return the image title, null if none. - * + * */ public String getTitle() { - return _title; + return this._title; } /** * Sets the image title. *

+ * * @param title the image title to set, null if none. - * + * */ - public void setTitle(String title) { - _title = title; + public void setTitle(final String title) { + this._title = title; } /** * Returns the image URL. *

+ * * @return the image URL, null if none. - * + * */ public String getUrl() { - return _url; + return this._url; } /** * Sets the image URL. *

+ * * @param url the image URL to set, null if none. - * + * */ - public void setUrl(String url) { - _url = url; + public void setUrl(final String url) { + this._url = url; } /** * Returns the image link. *

+ * * @return the image link, null if none. - * + * */ public String getLink() { - return _link; + return this._link; } /** * Sets the image link. *

+ * * @param link the image link to set, null if none. - * + * */ - public void setLink(String link) { - _link = link; + public void setLink(final String link) { + this._link = link; } /** * Returns the image width. *

+ * * @return the image width, null if none. - * + * */ public Integer getWidth() { - return _width; + return this._width; } /** * Sets the image width. *

+ * * @param width the image width to set, null if none. - * + * */ - public void setWidth(Integer width) { - _width = width; + public void setWidth(final Integer width) { + this._width = width; } /** * Returns the image height. *

+ * * @return the image height, null if none. - * + * */ public Integer getHeight() { - return _height; + return this._height; } /** * Sets the image height. *

+ * * @param height the image height to set, null if none. - * + * */ - public void setHeight(Integer height) { - _height = height; + public void setHeight(final Integer height) { + this._height = height; } /** * Returns the image description. *

+ * * @return the image description, null if none. - * + * */ public String getDescription() { - return _description; + return this._description; } /** * Sets the image description. *

+ * * @param description the image description to set, null if none. - * + * */ - public void setDescription(String description) { - _description = description; + public void setDescription(final String description) { + this._description = description; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Item.java b/src/main/java/com/sun/syndication/feed/rss/Item.java index 9063bd1..2f95166 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Item.java +++ b/src/main/java/com/sun/syndication/feed/rss/Item.java @@ -17,31 +17,32 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.module.Module; -import com.sun.syndication.feed.module.impl.ModuleUtils; -import com.sun.syndication.feed.module.Extendable; - +import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.io.Serializable; import org.jdom2.Element; +import com.sun.syndication.feed.impl.ObjectBean; +import com.sun.syndication.feed.module.Extendable; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.feed.module.impl.ModuleUtils; + /** * Bean for items of RSS feeds. *

* It handles all RSS versions without loosing information. *

- * For RSS1.0 it supports Dublin Core and Syndication modules. Note that - * those modules currently support simple syntax format only. + * For RSS1.0 it supports Dublin Core and Syndication modules. Note that those + * modules currently support simple syntax format only. *

+ * * @author Alejandro Abdelnur - * + * */ public class Item implements Cloneable, Serializable, Extendable { - private ObjectBean _objBean; + private final ObjectBean _objBean; private String _title; private String _link; private String _uri; @@ -61,40 +62,44 @@ public class Item implements Cloneable, Serializable, Extendable { /** * Default constructor. All properties are set to null. *

- * + * */ public Item() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { + public boolean equals(final Object other) { if (other == null || !(other instanceof Item)) { return false; } // can't use foreign markup in equals, due to JDOM equals impl - List fm = getForeignMarkup(); - setForeignMarkup(((Item)other).getForeignMarkup()); - boolean ret = _objBean.equals(other); + final List fm = getForeignMarkup(); + setForeignMarkup(((Item) other).getForeignMarkup()); + final boolean ret = this._objBean.equals(other); // restore foreign markup setForeignMarkup(fm); return ret; @@ -105,338 +110,374 @@ public class Item implements Cloneable, Serializable, Extendable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the item title. *

+ * * @return the item title, null if none. - * + * */ public String getTitle() { - return _title; + return this._title; } /** * Sets the item title. *

+ * * @param title the item title to set, null if none. - * + * */ - public void setTitle(String title) { - _title = title; + public void setTitle(final String title) { + this._title = title; } /** * Returns the item link. *

+ * * @return the item link, null if none. - * + * */ public String getLink() { - return _link; + return this._link; } /** * Sets the item link. *

+ * * @param link the item link to set, null if none. - * + * */ - public void setLink(String link) { - _link = link; + public void setLink(final String link) { + this._link = link; } /** * Returns the item uri. *

+ * * @return the item uri, null if none. */ public String getUri() { - return _uri; + return this._uri; } /** * Sets the item uri. *

+ * * @param uri the item uri to set, null if none. */ - public void setUri(String uri) { - _uri = uri; + public void setUri(final String uri) { + this._uri = uri; } /** * Returns the item description. *

+ * * @return the item description, null if none. - * + * */ public Description getDescription() { - return _description; + return this._description; } /** * Sets the item description. *

+ * * @param description the item description to set, null if none. - * + * */ - public void setDescription(Description description) { - _description = description; + public void setDescription(final Description description) { + this._description = description; } /** * Returns the item content. *

+ * * @return the item content, null if none. - * + * */ public Content getContent() { - return _content; + return this._content; } /** * Sets the item content. *

+ * * @param content the item content to set, null if none. - * + * */ - public void setContent(Content content) { - _content = content; + public void setContent(final Content content) { + this._content = content; } /** * Returns the item source. *

+ * * @return the item source, null if none. - * + * */ public Source getSource() { - return _source; + return this._source; } /** * Sets the item source. *

+ * * @param source the item source to set, null if none. - * + * */ - public void setSource(Source source) { - _source = source; + public void setSource(final Source source) { + this._source = source; } /** * Returns the item enclosures. *

- * @return a list of Enclosure elements with the item enclosures, - * an empty list if none. - * + * + * @return a list of Enclosure elements with the item enclosures, an empty + * list if none. + * */ public List getEnclosures() { - return (_enclosures==null) ? (_enclosures=new ArrayList()) : _enclosures; + return this._enclosures == null ? (this._enclosures = new ArrayList()) : this._enclosures; } /** * Sets the item enclosures. *

- * @param enclosures the list of Enclosure elements with the item enclosures to set, - * an empty list or null if none. - * + * + * @param enclosures the list of Enclosure elements with the item enclosures + * to set, an empty list or null if none. + * */ - public void setEnclosures(List enclosures) { - _enclosures = enclosures; + public void setEnclosures(final List enclosures) { + this._enclosures = enclosures; } /** * Returns the item categories. *

- * @return a list of Category elements with the item categories, - * an empty list if none. - * + * + * @return a list of Category elements with the item categories, an empty + * list if none. + * */ public List getCategories() { - return (_categories==null) ? (_categories=new ArrayList()) : _categories; + return this._categories == null ? (this._categories = new ArrayList()) : this._categories; } /** * Sets the item categories. *

- * @param categories the list of Categories elements with the item categories to set, - * an empty list or null if none. - * + * + * @param categories the list of Categories elements with the item + * categories to set, an empty list or null if none. + * */ - public void setCategories(List categories) { - _categories = categories; + public void setCategories(final List categories) { + this._categories = categories; } /** * Returns the item GUID. *

+ * * @return the item GUID, null if none. - * + * */ public Guid getGuid() { - return _guid; + return this._guid; } /** * Sets the item GUID. *

+ * * @param guid the item GUID to set, null if none. - * + * */ - public void setGuid(Guid guid) { - _guid = guid; + public void setGuid(final Guid guid) { + this._guid = guid; } /** * Returns the item comments. *

+ * * @return the item comments, null if none. - * + * */ public String getComments() { - return _comments; + return this._comments; } /** * Sets the item comments. *

+ * * @param comments the item comments to set, null if none. - * + * */ - public void setComments(String comments) { - _comments = comments; + public void setComments(final String comments) { + this._comments = comments; } /** * Returns the item author. *

+ * * @return the item author, null if none. - * + * */ public String getAuthor() { - return _author; + return this._author; } /** * Sets the item author. *

+ * * @param author the item author to set, null if none. - * + * */ - public void setAuthor(String author) { - _author = author; + public void setAuthor(final String author) { + this._author = author; } /** * Returns the item modules. *

- * @return a list of ModuleImpl elements with the item modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the item modules, an empty + * list if none. + * */ + @Override public List getModules() { - return (_modules==null) ? (_modules=new ArrayList()) : _modules; + return this._modules == null ? (this._modules = new ArrayList()) : this._modules; } /** * Sets the item modules. *

- * @param modules the list of ModuleImpl elements with the item modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the item modules to + * set, an empty list or null if none. + * */ - public void setModules(List modules) { - _modules = modules; + @Override + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ - public Module getModule(String uri) { - return ModuleUtils.getModule(_modules,uri); + @Override + public Module getModule(final String uri) { + return ModuleUtils.getModule(this._modules, uri); } - /** * Returns the item publishing date. *

+ * * @return the item publishing date, null if none. - * + * */ public Date getPubDate() { - return _pubDate == null ? null : new Date( _pubDate.getTime()); + return this._pubDate == null ? null : new Date(this._pubDate.getTime()); } /** * Sets the item publishing date. *

+ * * @param pubDate the item publishing date to set, null if none. - * + * */ - public void setPubDate(Date pubDate) { - _pubDate = pubDate == null ? null : new Date( pubDate.getTime()); + public void setPubDate(final Date pubDate) { + this._pubDate = pubDate == null ? null : new Date(pubDate.getTime()); } /** * Returns the item expiration date. *

+ * * @return the item expiration date, null if none. - * + * */ public Date getExpirationDate() { - return _expirationDate == null ? null : new Date(_expirationDate.getTime()); + return this._expirationDate == null ? null : new Date(this._expirationDate.getTime()); } /** * Sets the item expiration date. *

- * @param expirationDate the item expiration date to set, null if none. - * + * + * @param expirationDate the item expiration date to set, null if + * none. + * */ - public void setExpirationDate(Date expirationDate) { - _expirationDate = expirationDate == null ? null : new Date(expirationDate.getTime()); + public void setExpirationDate(final Date expirationDate) { + this._expirationDate = expirationDate == null ? null : new Date(expirationDate.getTime()); } /** * Returns foreign markup found at item level. *

+ * * @return Opaque object to discourage use - * + * */ public List getForeignMarkup() { - return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup; + return this._foreignMarkup == null ? (this._foreignMarkup = new ArrayList()) : this._foreignMarkup; } /** * Sets foreign markup found at item level. *

+ * * @param foreignMarkup Opaque object to discourage use - * + * */ - public void setForeignMarkup(List foreignMarkup) { - _foreignMarkup = (List)foreignMarkup; + public void setForeignMarkup(final List foreignMarkup) { + this._foreignMarkup = foreignMarkup; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/Source.java b/src/main/java/com/sun/syndication/feed/rss/Source.java index 8122e39..723e832 100644 --- a/src/main/java/com/sun/syndication/feed/rss/Source.java +++ b/src/main/java/com/sun/syndication/feed/rss/Source.java @@ -17,55 +17,60 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for item sources of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class Source implements Cloneable,Serializable { - private ObjectBean _objBean; +public class Source implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _url; private String _value; /** * Default constructor. All properties are set to null. *

- * + * */ public Source() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof Source)){ + public boolean equals(final Object other) { + if (!(other instanceof Source)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -73,62 +78,68 @@ public class Source implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the source URL. *

+ * * @return the source URL, null if none. - * + * */ public String getUrl() { - return _url; + return this._url; } /** * Sets the source URL. *

+ * * @param url the source URL to set, null if none. - * + * */ - public void setUrl(String url) { - _url = url; + public void setUrl(final String url) { + this._url = url; } /** * Returns the source value. *

+ * * @return the source value, null if none. - * + * */ public String getValue() { - return _value; + return this._value; } /** * Sets the source value. *

+ * * @param value the source value to set, null if none. - * + * */ - public void setValue(String value) { - _value = value; + public void setValue(final String value) { + this._value = value; } } diff --git a/src/main/java/com/sun/syndication/feed/rss/TextInput.java b/src/main/java/com/sun/syndication/feed/rss/TextInput.java index b797941..eed49b5 100644 --- a/src/main/java/com/sun/syndication/feed/rss/TextInput.java +++ b/src/main/java/com/sun/syndication/feed/rss/TextInput.java @@ -17,18 +17,19 @@ */ package com.sun.syndication.feed.rss; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Bean for text input of RSS feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class TextInput implements Cloneable,Serializable { - private ObjectBean _objBean; +public class TextInput implements Cloneable, Serializable { + private final ObjectBean _objBean; private String _title; private String _description; private String _name; @@ -37,37 +38,41 @@ public class TextInput implements Cloneable,Serializable { /** * Default constructor. All properties are set to null. *

- * + * */ public TextInput() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof TextInput)){ + public boolean equals(final Object other) { + if (!(other instanceof TextInput)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -75,103 +80,114 @@ public class TextInput implements Cloneable,Serializable { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the text input title. *

+ * * @return the text input title, null if none. - * + * */ public String getTitle() { - return _title; + return this._title; } /** * Sets the text input title. *

+ * * @param title the text input title to set, null if none. - * + * */ - public void setTitle(String title) { - _title = title; + public void setTitle(final String title) { + this._title = title; } /** * Returns the text input description. *

+ * * @return the text input description, null if none. - * + * */ public String getDescription() { - return _description; + return this._description; } /** * Sets the text input description. *

- * @param description the text input description to set, null if none. - * + * + * @param description the text input description to set, null if + * none. + * */ - public void setDescription(String description) { - _description = description; + public void setDescription(final String description) { + this._description = description; } /** * Returns the text input name. *

+ * * @return the text input name, null if none. - * + * */ public String getName() { - return _name; + return this._name; } /** * Sets the text input name. *

+ * * @param name the text input name to set, null if none. - * + * */ - public void setName(String name) { - _name = name; + public void setName(final String name) { + this._name = name; } /** * Returns the text input link. *

+ * * @return the text input link, null if none. - * + * */ public String getLink() { - return _link; + return this._link; } /** * Sets the text input link. *

+ * * @param link the text input link to set, null if none. - * + * */ - public void setLink(String link) { - _link = link; + public void setLink(final String link) { + this._link = link; } } diff --git a/src/main/java/com/sun/syndication/feed/synd/Converter.java b/src/main/java/com/sun/syndication/feed/synd/Converter.java index 9f46b1d..962e793 100644 --- a/src/main/java/com/sun/syndication/feed/synd/Converter.java +++ b/src/main/java/com/sun/syndication/feed/synd/Converter.java @@ -17,51 +17,57 @@ package com.sun.syndication.feed.synd; import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.synd.SyndFeed; /** - * Interface that defines the functionality to convert a SyndFeedImpl - * to a real feed (RSS or Atom) and vice versa. + * Interface that defines the functionality to convert a SyndFeedImpl to a real + * feed (RSS or Atom) and vice versa. *

- * Each implementation knows how to deal with a specific type (version) - * of a real feed. + * Each implementation knows how to deal with a specific type (version) of a + * real feed. *

* Implementations must be thread safe. *

* TODO: explain how developers can plugin their own implementations. *

+ * * @author Alejandro Abdelnur - * + * */ public interface Converter { /** * Returns the type (version) of the real feed this converter handles. *

+ * * @see WireFeed for details on the format of this string. - *

+ *

* @return the real feed type. - * + * */ public String getType(); /** - * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. + * 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. - * + * @param syndFeed the SyndFeedImpl that will contain the copied/converted + * values of the real feed. + * */ - public void copyInto(WireFeed feed,SyndFeed syndFeed); + public void copyInto(WireFeed feed, SyndFeed syndFeed); /** - * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. + * 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); diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndCategory.java b/src/main/java/com/sun/syndication/feed/synd/SyndCategory.java index 6354c33..82a5170 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndCategory.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndCategory.java @@ -17,54 +17,58 @@ */ package com.sun.syndication.feed.synd; - - - /** * Bean interface for categories of SyndFeedImpl feeds and entries. *

+ * * @author Alejandro Abdelnur - * + * */ public interface SyndCategory extends Cloneable { /** * Returns the category name. *

+ * * @return the category name, null if none. - * + * */ String getName(); /** * Sets the category name. *

+ * * @param name the category name to set, null if none. - * + * */ void setName(String name); /** * Returns the category taxonomy URI. *

+ * * @return the category taxonomy URI, null if none. - * + * */ String getTaxonomyUri(); /** * Sets the category taxonomy URI. *

+ * * @param taxonomyUri the category taxonomy URI to set, null if none. - * + * */ void setTaxonomyUri(String taxonomyUri); /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndCategoryImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndCategoryImpl.java index 746eeb3..df79686 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndCategoryImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndCategoryImpl.java @@ -17,61 +17,67 @@ */ package com.sun.syndication.feed.synd; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.module.DCSubjectImpl; -import com.sun.syndication.feed.module.DCSubject; - -import java.util.AbstractList; -import java.util.List; -import java.util.ArrayList; import java.io.Serializable; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.List; + +import com.sun.syndication.feed.impl.ObjectBean; +import com.sun.syndication.feed.module.DCSubject; +import com.sun.syndication.feed.module.DCSubjectImpl; /** * Bean for categories of SyndFeedImpl feeds and entries. *

+ * * @author Alejandro Abdelnur - * + * */ public class SyndCategoryImpl implements Serializable, SyndCategory { - private ObjectBean _objBean; - private DCSubject _subject; + private final ObjectBean _objBean; + private final DCSubject _subject; /** - * For implementations extending SyndContentImpl to be able to use the ObjectBean functionality - * with extended interfaces. + * For implementations extending SyndContentImpl to be able to use the + * ObjectBean functionality with extended interfaces. *

+ * * @param subject the DC subject to wrap. */ - SyndCategoryImpl(DCSubject subject) { - _objBean = new ObjectBean(SyndCategory.class,this); - _subject = subject; + SyndCategoryImpl(final DCSubject subject) { + this._objBean = new ObjectBean(SyndCategory.class, this); + this._subject = subject; } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof SyndCategoryImpl)){ + public boolean equals(final Object other) { + if (!(other instanceof SyndCategoryImpl)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -79,39 +85,42 @@ public class SyndCategoryImpl implements Serializable, SyndCategory { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Package private constructor, used by SyndCategoryListFacade. *

+ * * @return the DC subject being wrapped. - * + * */ DCSubject getSubject() { - return _subject; + return this._subject; } /** * Default constructor. All properties are set to null. *

- * + * */ public SyndCategoryImpl() { this(new DCSubjectImpl()); @@ -120,64 +129,73 @@ public class SyndCategoryImpl implements Serializable, SyndCategory { /** * Returns the category name. *

+ * * @return the category name, null if none. - * + * */ + @Override public String getName() { - return _subject.getValue(); + return this._subject.getValue(); } /** * Sets the category name. *

+ * * @param name the category name to set, null if none. - * + * */ - public void setName(String name) { - _subject.setValue(name); + @Override + public void setName(final String name) { + this._subject.setValue(name); } /** * Returns the category taxonomy URI. *

+ * * @return the category taxonomy URI, null if none. - * + * */ + @Override public String getTaxonomyUri() { - return _subject.getTaxonomyUri(); + return this._subject.getTaxonomyUri(); } /** * Sets the category taxonomy URI. *

+ * * @param taxonomyUri the category taxonomy URI to set, null if none. - * + * */ - public void setTaxonomyUri(String taxonomyUri) { - _subject.setTaxonomyUri(taxonomyUri); + @Override + public void setTaxonomyUri(final String taxonomyUri) { + this._subject.setTaxonomyUri(taxonomyUri); } } - /** - * List implementation for SyndCategoryImpl elements. To be directly used by the SyndFeedImpl - * and SyndEntryImpl classes only. + * List implementation for SyndCategoryImpl elements. To be directly used by the + * SyndFeedImpl and SyndEntryImpl classes only. *

- * It acts as a facade on top of the DCSubjectImpl elements of the underlying list - * and remains in synch with it. It is possible to work on either list, the categories - * one or the subjects one and they remain in synch. + * It acts as a facade on top of the DCSubjectImpl elements of the underlying + * list and remains in synch with it. It is possible to work on either list, the + * categories one or the subjects one and they remain in synch. *

- * This is necessary because the SyndFeedImpl categories are just a convenience to access - * the DublinCore subjects. + * This is necessary because the SyndFeedImpl categories are just a convenience + * to access the DublinCore subjects. *

- * All this mess to avoid making DCSubjectImpl implement SyndCategory (which it would be odd). + * All this mess to avoid making DCSubjectImpl implement SyndCategory (which it + * would be odd). *

+ * * @author Alejandro Abdelnur - * + * */ class SyndCategoryListFacade extends AbstractList { - private List _subjects; + private final List _subjects; /** * Default constructor. Creates and empty list. @@ -189,93 +207,106 @@ class SyndCategoryListFacade extends AbstractList { /** * Creates a facade list of categories on top the given subject list. *

+ * * @param subjects the list of subjects to create the facade. - * + * */ - public SyndCategoryListFacade(List subjects) { - _subjects = subjects; + public SyndCategoryListFacade(final List subjects) { + this._subjects = subjects; } /** * Gets the category by index. *

+ * * @param index the index position to retrieve the category. * @return the SyndCategoryImpl in position index, null if none. - * + * */ - public SyndCategory get(int index) { - return new SyndCategoryImpl((DCSubject) _subjects.get(index)); + @Override + public SyndCategory get(final int index) { + return new SyndCategoryImpl(this._subjects.get(index)); } /** * Returns the size of the list. *

+ * * @return the size of the list. - * + * */ + @Override public int size() { - return _subjects.size(); + return this._subjects.size(); } /** * Sets a category in an existing position in the list. *

+ * * @param index position to set the category. * @param obj the SyndCategoryImpl object to set. - * @return the SyndCategoryImpl object that is being replaced, null if none. - * + * @return the SyndCategoryImpl object that is being replaced, null + * if none. + * */ @Override - public SyndCategory set(int index, SyndCategory obj) { - SyndCategoryImpl sCat = (SyndCategoryImpl) obj; - DCSubject subject = (sCat!=null) ? sCat.getSubject() : null; - subject = (DCSubject) _subjects.set(index,subject); - return (subject!=null) ? new SyndCategoryImpl(subject) : null; + public SyndCategory set(final int index, final SyndCategory obj) { + final SyndCategoryImpl sCat = (SyndCategoryImpl) obj; + DCSubject subject = sCat != null ? sCat.getSubject() : null; + subject = this._subjects.set(index, subject); + return subject != null ? new SyndCategoryImpl(subject) : null; } /** - * Adds a category to the list. - *

- * @param index position to add the category. - * @param obj the SyndCategoryImpl object to add. - * + * Adds a category to the list. + *

+ * + * @param index position to add the category. + * @param obj the SyndCategoryImpl object to add. + * */ @Override - public void add(int index,SyndCategory obj) { - SyndCategoryImpl sCat = (SyndCategoryImpl) obj; - DCSubject subject = (sCat!=null) ? sCat.getSubject() : null; - _subjects.add(index,subject); + public void add(final int index, final SyndCategory obj) { + final SyndCategoryImpl sCat = (SyndCategoryImpl) obj; + final DCSubject subject = sCat != null ? sCat.getSubject() : null; + this._subjects.add(index, subject); } /** * Removes a category element from a specific position. *

+ * * @param index position to remove the category from. - * @return the SyndCategoryImpl being removed from position index, null if none. - * + * @return the SyndCategoryImpl being removed from position index, + * null if none. + * */ @Override - public SyndCategory remove(int index) { - DCSubject subject = (DCSubject) _subjects.remove(index); - return (subject!=null) ? new SyndCategoryImpl(subject) : null; + public SyndCategory remove(final int index) { + final DCSubject subject = this._subjects.remove(index); + return subject != null ? new SyndCategoryImpl(subject) : null; } /** - * Returns a list with the DCSubject elements of the SyndCategoryImpl list facade. - * To be used by the SyndFeedImpl class only. + * Returns a list with the DCSubject elements of the SyndCategoryImpl list + * facade. To be used by the SyndFeedImpl class only. *

- * @param cList the list with SyndCategoryImpl elements to convert to subject list. - * @return a list with DCSubject elements corresponding to the categories in the given list. - * + * + * @param cList the list with SyndCategoryImpl elements to convert to + * subject list. + * @return a list with DCSubject elements corresponding to the categories in + * the given list. + * */ - public static List convertElementsSyndCategoryToSubject(List cList) { + public static List convertElementsSyndCategoryToSubject(final List cList) { List sList = null; - if (cList!=null) { + if (cList != null) { sList = new ArrayList(); - for (int i=0;i + * * @author Alejandro Abdelnur - * + * */ -public interface SyndContent extends Cloneable,CopyFrom { +public interface SyndContent extends Cloneable, CopyFrom { /** * Returns the content type. *

- * When used for the description of an entry, if null 'text/plain' must be assumed. + * When used for the description of an entry, if null 'text/plain' + * must be assumed. *

+ * * @return the content type, null if none. - * + * */ String getType(); /** * Sets the content type. *

- * When used for the description of an entry, if null 'text/plain' must be assumed. + * When used for the description of an entry, if null 'text/plain' + * must be assumed. *

+ * * @param type the content type to set, null if none. - * + * */ void setType(String type); - + /** * Gets the content mode (needed for Atom 0.3 support). + * * @return type the content, null if none. - * + * */ String getMode(); /** * Sets the content mode (needed for Atom 0.3 support). + * * @param mode the content mode to set, null if none. - * + * */ void setMode(String mode); /** * Returns the content value. *

+ * * @return the content value, null if none. - * + * */ String getValue(); /** * Sets the content value. *

+ * * @param value the content value to set, null if none. - * + * */ void setValue(String value); /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndContentImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndContentImpl.java index 7fd7f28..e5f44b6 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndContentImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndContentImpl.java @@ -16,57 +16,63 @@ */ package com.sun.syndication.feed.synd; -import com.sun.syndication.feed.CopyFrom; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.impl.CopyFromHelper; - +import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.io.Serializable; + +import com.sun.syndication.feed.CopyFrom; +import com.sun.syndication.feed.impl.CopyFromHelper; +import com.sun.syndication.feed.impl.ObjectBean; /** * Bean for content of SyndFeedImpl entries. *

+ * * @author Alejandro Abdelnur - * + * */ public class SyndContentImpl implements Serializable, SyndContent { - private ObjectBean _objBean; + private final ObjectBean _objBean; private String _type; private String _value; private String _mode; - /** * Default constructor. All properties are set to null. *

- * + * */ public SyndContentImpl() { - _objBean = new ObjectBean(SyndContent.class,this); + this._objBean = new ObjectBean(SyndContent.class, this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ + @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public boolean equals(Object other) { - return _objBean.equals(other); + @Override + public boolean equals(final Object other) { + return this._objBean.equals(other); } /** @@ -74,104 +80,123 @@ public class SyndContentImpl implements Serializable, SyndContent { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ + @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ + @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the content type. *

- * When used for the description of an entry, if null 'text/plain' must be assumed. + * When used for the description of an entry, if null 'text/plain' + * must be assumed. *

+ * * @return the content type, null if none. - * + * */ + @Override public String getType() { - return _type; + return this._type; } /** * Sets the content type. *

- * When used for the description of an entry, if null 'text/plain' must be assumed. + * When used for the description of an entry, if null 'text/plain' + * must be assumed. *

+ * * @param type the content type to set, null if none. - * + * */ - public void setType(String type) { - _type = type; + @Override + public void setType(final String type) { + this._type = type; } /** * Returns the content mode. + * * @return the content mode, null if none. - * + * */ + @Override public String getMode() { - return _mode; + return this._mode; } /** * Sets the content mode. + * * @param mode the content mode to set, null if none. - * + * */ - public void setMode(String mode) { - _mode = mode; + @Override + public void setMode(final String mode) { + this._mode = mode; } /** * Returns the content value. *

+ * * @return the content value, null if none. - * + * */ + @Override public String getValue() { - return _value; + return this._value; } /** * Sets the content value. *

+ * * @param value the content value to set, null if none. - * + * */ - public void setValue(String value) { - _value = value; + @Override + public void setValue(final String value) { + this._value = value; } - + @Override public Class getInterface() { return SyndContent.class; } - public void copyFrom(CopyFrom obj) { - COPY_FROM_HELPER.copy(this,obj); + @Override + public void copyFrom(final CopyFrom obj) { + COPY_FROM_HELPER.copy(this, obj); } private static final CopyFromHelper COPY_FROM_HELPER; static { - Map basePropInterfaceMap = new HashMap(); - basePropInterfaceMap.put("type",String.class); - basePropInterfaceMap.put("value",String.class); + final Map basePropInterfaceMap = new HashMap(); + basePropInterfaceMap.put("type", String.class); + basePropInterfaceMap.put("value", String.class); - Map basePropClassImplMap = Collections.EMPTY_MAP; + final Map basePropClassImplMap = Collections.EMPTY_MAP; - COPY_FROM_HELPER = new CopyFromHelper(SyndContent.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(SyndContent.class, basePropInterfaceMap, basePropClassImplMap); } } diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndEnclosure.java b/src/main/java/com/sun/syndication/feed/synd/SyndEnclosure.java index 34ee4e6..7ff822a 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndEnclosure.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndEnclosure.java @@ -9,48 +9,54 @@ public interface SyndEnclosure extends Cloneable, CopyFrom { /** * Returns the enclosure URL. *

+ * * @return the enclosure URL, null if none. - * + * */ public String getUrl(); /** * Sets the enclosure URL. *

+ * * @param url the enclosure URL to set, null if none. - * + * */ public void setUrl(String url); /** * Returns the enclosure length. *

+ * * @return the enclosure length, 0 if none. - * + * */ public long getLength(); /** * Sets the enclosure length. *

+ * * @param length the enclosure length to set, 0 if none. - * + * */ public void setLength(long length); /** * Returns the enclosure type. *

+ * * @return the enclosure type, null if none. - * + * */ public String getType(); /** * Sets the enclosure type. *

+ * * @param type the enclosure type to set, null if none. - * + * */ public void setType(String type); diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndEnclosureImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndEnclosureImpl.java index 2bb64ba..3fe2b34 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndEnclosureImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndEnclosureImpl.java @@ -1,52 +1,58 @@ package com.sun.syndication.feed.synd; -import com.sun.syndication.feed.CopyFrom; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.impl.CopyFromHelper; - import java.io.Serializable; -import java.util.Map; -import java.util.HashMap; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.sun.syndication.feed.CopyFrom; +import com.sun.syndication.feed.impl.CopyFromHelper; +import com.sun.syndication.feed.impl.ObjectBean; /** * @author Alejandro Abdelnur */ -public class SyndEnclosureImpl implements Serializable,SyndEnclosure { - private ObjectBean _objBean; +public class SyndEnclosureImpl implements Serializable, SyndEnclosure { + private final ObjectBean _objBean; private String _url; private String _type; - private long _length; + private long _length; /** * Default constructor. All properties are set to null. *

- * + * */ public SyndEnclosureImpl() { - _objBean = new ObjectBean(SyndEnclosure.class,this); + this._objBean = new ObjectBean(SyndEnclosure.class, this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ + @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public boolean equals(Object other) { - return _objBean.equals(other); + @Override + public boolean equals(final Object other) { + return this._objBean.equals(other); } /** @@ -54,102 +60,114 @@ public class SyndEnclosureImpl implements Serializable,SyndEnclosure { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ + @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ + @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the enclosure URL. *

- * + * * @return the enclosure URL, null if none. */ + @Override public String getUrl() { - return _url; + return this._url; } /** * Sets the enclosure URL. *

- * + * * @param url the enclosure URL to set, null if none. */ - public void setUrl(String url) { - _url = url; + @Override + public void setUrl(final String url) { + this._url = url; } /** * Returns the enclosure length. *

- * + * * @return the enclosure length, null if none. */ + @Override public long getLength() { - return _length; + return this._length; } /** * Sets the enclosure length. *

- * + * * @param length the enclosure length to set, null if none. */ - public void setLength(long length) { - _length = length; + @Override + public void setLength(final long length) { + this._length = length; } /** * Returns the enclosure type. *

- * + * * @return the enclosure type, null if none. */ + @Override public String getType() { - return _type; + return this._type; } /** * Sets the enclosure type. *

- * + * * @param type the enclosure type to set, null if none. */ - public void setType(String type) { - _type = type; + @Override + public void setType(final String type) { + this._type = type; } + @Override public Class getInterface() { return SyndEnclosure.class; } - public void copyFrom(CopyFrom obj) { - COPY_FROM_HELPER.copy(this,obj); + @Override + public void copyFrom(final CopyFrom obj) { + COPY_FROM_HELPER.copy(this, obj); } private static final CopyFromHelper COPY_FROM_HELPER; static { - Map basePropInterfaceMap = new HashMap(); - basePropInterfaceMap.put("url",String.class); - basePropInterfaceMap.put("type",String.class); - basePropInterfaceMap.put("length",Long.TYPE); + final Map basePropInterfaceMap = new HashMap(); + basePropInterfaceMap.put("url", String.class); + basePropInterfaceMap.put("type", String.class); + basePropInterfaceMap.put("length", Long.TYPE); - Map basePropClassImplMap = Collections.EMPTY_MAP; + final Map basePropClassImplMap = Collections.EMPTY_MAP; - COPY_FROM_HELPER = new CopyFromHelper(SyndEnclosure.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(SyndEnclosure.class, basePropInterfaceMap, basePropClassImplMap); } } diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java b/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java index 3f3a033..1610ed9 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java @@ -28,8 +28,9 @@ import com.sun.syndication.feed.module.Module; /** * Bean interface for entries of SyndFeedImpl feeds. *

+ * * @author Alejandro Abdelnur - * + * */ public interface SyndEntry extends Cloneable, CopyFrom, Extendable { @@ -37,13 +38,16 @@ public interface SyndEntry extends Cloneable, CopyFrom, Extendable { * Returns the entry URI. *

* How the entry URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

* The returned URI is a normalized URI as specified in RFC 2396bis. *

+ * * @return the entry URI, null if none. - * + * */ String getUri(); @@ -51,221 +55,250 @@ public interface SyndEntry extends Cloneable, CopyFrom, Extendable { * Sets the entry URI. *

* How the entry URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

+ * * @param uri the entry URI to set, null if none. - * + * */ void setUri(String uri); /** * Returns the entry title. *

+ * * @return the entry title, null if none. - * + * */ String getTitle(); /** * Sets the entry title. *

+ * * @param title the entry title to set, null if none. - * + * */ void setTitle(String title); /** * Returns the entry title as a text construct. *

+ * * @return the entry title, null if none. - * + * */ SyndContent getTitleEx(); /** * Sets the entry title as a text construct. *

+ * * @param title the entry title to set, null if none. - * + * */ void setTitleEx(SyndContent title); /** * Returns the entry link. *

+ * * @return the entry link, null if none. - * + * */ String getLink(); /** * Sets the entry link. *

+ * * @param link the entry link to set, null if none. - * + * */ void setLink(String link); /** * Returns the entry links *

+ * * @return the entry links, null if none. - * + * */ List getLinks(); /** * Sets the entry links. *

+ * * @param links the entry links to set, null if none. - * + * */ void setLinks(List links); /** * Returns the entry description. *

+ * * @return the entry description, null if none. - * + * */ SyndContent getDescription(); /** * Sets the entry description. *

+ * * @param description the entry description to set, null if none. - * + * */ void setDescription(SyndContent description); /** * Returns the entry contents. *

- * @return a list of SyndContentImpl elements with the entry contents, - * an empty list if none. - * + * + * @return a list of SyndContentImpl elements with the entry contents, an + * empty list if none. + * */ List getContents(); /** * Sets the entry contents. *

- * @param contents the list of SyndContentImpl elements with the entry contents to set, - * an empty list or null if none. - * + * + * @param contents the list of SyndContentImpl elements with the entry + * contents to set, an empty list or null if none. + * */ void setContents(List contents); /** * Returns the entry enclosures. *

- * @return a list of SyndEnclosure elements with the entry enclosures, - * an empty list if none. - * + * + * @return a list of SyndEnclosure elements with the entry enclosures, an + * empty list if none. + * */ public List getEnclosures(); /** * Sets the entry enclosures. *

- * @param enclosures the list of SyndEnclosure elements with the entry enclosures to set, - * an empty list or null if none. - * + * + * @param enclosures the list of SyndEnclosure elements with the entry + * enclosures to set, an empty list or null if none. + * */ public void setEnclosures(List enclosures); /** * Returns the entry published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

+ * * @return the entry published date, null if none. - * + * */ Date getPublishedDate(); /** * Sets the entry published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

- * @param publishedDate the entry published date to set, null if none. - * + * + * @param publishedDate the entry published date to set, null if + * none. + * */ void setPublishedDate(Date publishedDate); /** * Returns the entry updated date. *

+ * * @return the entry updated date, null if none. - * + * */ Date getUpdatedDate(); /** * Sets the entry updated date. *

+ * * @param updatedDate the entry updated date to set, null if none. - * + * */ void setUpdatedDate(Date updatedDate); /** * Returns the entry authors. *

- * For Atom feeds, this returns the authors as a list of SyndPerson objects, - * for RSS feeds this method is a convenience method, it maps to the - * Dublin Core module creator. + * For Atom feeds, this returns the authors as a list of SyndPerson objects, + * for RSS feeds this method is a convenience method, it maps to the Dublin + * Core module creator. *

+ * * @return the feed author, null if none. - * + * */ List getAuthors(); /** * Sets the entry author. *

- * For Atom feeds, this sets the authors as a list of SyndPerson - * objects, for RSS feeds this method is a convenience method, it maps - * to the Dublin Core module creator. + * For Atom feeds, this sets the authors as a list of SyndPerson objects, + * for RSS feeds this method is a convenience method, it maps to the Dublin + * Core module creator. *

+ * * @param authors the feed author to set, null if none. - * + * */ void setAuthors(List authors); - + /** * Returns the name of the first entry author in the collection of authors. *

- * For Atom feeds, this returns the authors as a list of SyndPerson objects, - * for RSS feeds this method is a convenience method, it maps to the - * Dublin Core module creator. + * For Atom feeds, this returns the authors as a list of SyndPerson objects, + * for RSS feeds this method is a convenience method, it maps to the Dublin + * Core module creator. *

+ * * @return the feed author, null if none. - * + * */ String getAuthor(); /** * Sets the entry author. *

- * For Atom feeds, this sets the feed author's name, for RSS feeds - * this method is a convenience method, it maps to the Dublin Core - * module creator. + * For Atom feeds, this sets the feed author's name, for RSS feeds this + * method is a convenience method, it maps to the Dublin Core module + * creator. *

+ * * @param author the feed author to set, null if none. */ void setAuthor(String author); - + /** * Returns the feed author. *

- * For Atom feeds, this returns the contributors as a list of - * SyndPerson objects + * For Atom feeds, this returns the contributors as a list of SyndPerson + * objects *

+ * * @return the feed author, null if none. - * + * */ List getContributors(); @@ -274,118 +307,135 @@ public interface SyndEntry extends Cloneable, CopyFrom, Extendable { *

* Returns contributors as a list of SyndPerson objects. *

+ * * @param contributors the feed contributors to set, null if none. - * + * */ void setContributors(List contributors); /** * Returns the entry categories. *

- * This method is a convenience method, it maps to the Dublin Core module subjects. + * This method is a convenience method, it maps to the Dublin Core module + * subjects. *

- * @return a list of SyndCategoryImpl elements with the entry categories, - * an empty list if none. - * + * + * @return a list of SyndCategoryImpl elements with the entry categories, an + * empty list if none. + * */ List getCategories(); /** * Sets the entry categories. *

- * This method is a convenience method, it maps to the Dublin Core module subjects. + * This method is a convenience method, it maps to the Dublin Core module + * subjects. *

- * @param categories the list of SyndCategoryImpl elements with the entry categories to set, - * an empty list or null if none. - * + * + * @param categories the list of SyndCategoryImpl elements with the entry + * categories to set, an empty list or null if none. + * */ void setCategories(List categories); - + /** * Returns the entry source. *

* This returns the entry source as a SyndFeed *

+ * * @return the SyndFeed to which this entry is attributed * */ SyndFeed getSource(); - + /** * Sets the entry source feed (for use if different from containing feed) *

+ * * @param source the original SyndFeed that contained this article * */ void setSource(SyndFeed source); - + /** - * Return the original item this SyndEntry is generated from. - * The type of the object returned depends on the original type of - * the feed. Atom 0.3/1.0 will return com.sun.syndication.feed.atom.Entry, - * while RSS will return com.sun.syndication.feed.rss.Item.java. - * If this entry was not generated from a WireFeed, or the SyndFeed - * was not set to preserve the WireFeed then it will return null + * Return the original item this SyndEntry is generated from. The type of + * the object returned depends on the original type of the feed. Atom + * 0.3/1.0 will return com.sun.syndication.feed.atom.Entry, while RSS will + * return com.sun.syndication.feed.rss.Item.java. If this entry was not + * generated from a WireFeed, or the SyndFeed was not set to preserve the + * WireFeed then it will return null * - * @return the WireFeed Item or Entry this Entry is generated from, or null + * @return the WireFeed Item or Entry this Entry is generated from, or null */ Object getWireEntry(); - /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ + @Override public Module getModule(String uri); /** * Returns the entry modules. *

- * @return a list of ModuleImpl elements with the entry modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the entry modules, an empty + * list if none. + * */ + @Override List getModules(); /** * Sets the entry modules. *

- * @param modules the list of ModuleImpl elements with the entry modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the entry modules to + * set, an empty list or null if none. + * */ + @Override void setModules(List modules); /** * Returns foreign markup found at channel level. *

+ * * @return Opaque object to discourage use - * + * */ public List getForeignMarkup(); /** * Sets foreign markup found at channel level. *

+ * * @param foreignMarkup Opaque object to discourage use - * + * */ public void setForeignMarkup(List foreignMarkup); - + /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; /** - * Returns the first instance of a SyndLink with the specified relation, or null - * + * Returns the first instance of a SyndLink with the specified relation, or + * null + * */ public SyndLink findRelatedLink(String relation); diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java index 1fac5e9..0a336c5 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java @@ -16,30 +16,42 @@ */ package com.sun.syndication.feed.synd; -import com.sun.syndication.feed.CopyFrom; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.module.*; -import com.sun.syndication.feed.module.impl.ModuleUtils; -import com.sun.syndication.feed.synd.impl.URINormalizer; -import com.sun.syndication.feed.impl.CopyFromHelper; - -import java.util.*; -import java.io.Serializable; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.jdom2.Element; +import com.sun.syndication.feed.CopyFrom; +import com.sun.syndication.feed.impl.CopyFromHelper; +import com.sun.syndication.feed.impl.ObjectBean; +import com.sun.syndication.feed.module.DCModule; +import com.sun.syndication.feed.module.DCModuleImpl; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.feed.module.SyModule; +import com.sun.syndication.feed.module.SyModuleImpl; +import com.sun.syndication.feed.module.impl.ModuleUtils; +import com.sun.syndication.feed.synd.impl.URINormalizer; + /** * Bean for entries of SyndFeedImpl feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class SyndEntryImpl implements Serializable,SyndEntry { - private ObjectBean _objBean; +public class SyndEntryImpl implements Serializable, SyndEntry { + private final ObjectBean _objBean; private String _uri; private String _link; private Date _updatedDate; - private SyndContent _title; + private SyndContent _title; private SyndContent _description; private List _links; private List _contents; // deprecated by Atom 1.0 @@ -49,18 +61,20 @@ public class SyndEntryImpl implements Serializable,SyndEntry { private List _contributors; private SyndFeed _source; private List _foreignMarkup; - private Object wireEntry; // com.sun.syndication.feed.atom.Entry or com.sun.syndication.feed.rss.Item - + private Object wireEntry; // com.sun.syndication.feed.atom.Entry or + // com.sun.syndication.feed.rss.Item + // ISSUE: some converters assume this is never null - private List _categories = new ArrayList(); + private List _categories = new ArrayList(); private static final Set IGNORE_PROPERTIES = new HashSet(); /** * Unmodifiable Set containing the convenience properties of this class. *

- * Convenience properties are mapped to Modules, for cloning the convenience properties - * can be ignored as the will be copied as part of the module cloning. + * Convenience properties are mapped to Modules, for cloning the convenience + * properties can be ignored as the will be copied as part of the module + * cloning. */ public static final Set CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES); @@ -70,60 +84,67 @@ public class SyndEntryImpl implements Serializable,SyndEntry { } /** - * For implementations extending SyndEntryImpl to be able to use the ObjectBean functionality - * with extended interfaces. + * For implementations extending SyndEntryImpl to be able to use the + * ObjectBean functionality with extended interfaces. *

+ * * @param beanClass - * @param convenienceProperties set containing the convenience properties of the SyndEntryImpl - * (the are ignored during cloning, check CloneableBean for details). - * + * @param convenienceProperties set containing the convenience properties of + * the SyndEntryImpl (the are ignored during cloning, check + * CloneableBean for details). + * */ - protected SyndEntryImpl(Class beanClass,Set convenienceProperties) { - _objBean = new ObjectBean(beanClass,this,convenienceProperties); + protected SyndEntryImpl(final Class beanClass, final Set convenienceProperties) { + this._objBean = new ObjectBean(beanClass, this, convenienceProperties); } /** * Default constructor. All properties are set to null. *

- * + * */ public SyndEntryImpl() { - this(SyndEntry.class,IGNORE_PROPERTIES); + this(SyndEntry.class, IGNORE_PROPERTIES); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { + public boolean equals(final Object other) { if (other == null) { return false; } - // while ObjectBean does this check this method does a cast to obtain the foreign markup + // while ObjectBean does this check this method does a cast to obtain + // the foreign markup // so we need to check before doing so. if (!(other instanceof SyndEntryImpl)) { return false; } // can't use foreign markup in equals, due to JDOM equals impl - List fm = getForeignMarkup(); - setForeignMarkup(((SyndEntryImpl)other).getForeignMarkup()); - boolean ret = _objBean.equals(other); + final List fm = getForeignMarkup(); + setForeignMarkup(((SyndEntryImpl) other).getForeignMarkup()); + final boolean ret = this._objBean.equals(other); // restore foreign markup setForeignMarkup(fm); return ret; @@ -134,191 +155,230 @@ public class SyndEntryImpl implements Serializable,SyndEntry { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } - /** * Returns the entry URI. *

* How the entry URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

* The returned URI is a normalized URI as specified in RFC 2396bis. *

+ * * @return the entry URI, null if none. - * + * */ + @Override public String getUri() { - return _uri; + return this._uri; } /** * Sets the entry URI. *

* How the entry URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

+ * * @param uri the entry URI to set, null if none. - * + * */ - public void setUri(String uri) { - _uri = URINormalizer.normalize(uri); + @Override + public void setUri(final String uri) { + this._uri = URINormalizer.normalize(uri); } /** * Returns the entry title. *

+ * * @return the entry title, null if none. - * + * */ + @Override public String getTitle() { - if (_title != null) return _title.getValue(); + if (this._title != null) { + return this._title.getValue(); + } return null; } /** * Sets the entry title. *

+ * * @param title the entry title to set, null if none. - * + * */ - public void setTitle(String title) { - if (_title == null) _title = new SyndContentImpl(); - _title.setValue(title); + @Override + public void setTitle(final String title) { + if (this._title == null) { + this._title = new SyndContentImpl(); + } + this._title.setValue(title); } /** * Returns the entry title as a text construct. *

+ * * @return the entry title, null if none. - * + * */ + @Override public SyndContent getTitleEx() { - return _title; + return this._title; } /** * Sets the entry title as a text construct. *

+ * * @param title the entry title to set, null if none. - * + * */ - public void setTitleEx(SyndContent title) { - _title = title; + @Override + public void setTitleEx(final SyndContent title) { + this._title = title; } /** * Returns the entry link. *

+ * * @return the entry link, null if none. - * + * */ + @Override public String getLink() { - return _link; + return this._link; } /** * Sets the entry link. *

+ * * @param link the entry link to set, null if none. - * + * */ - public void setLink(String link) { - _link = link; + @Override + public void setLink(final String link) { + this._link = link; } /** * Returns the entry description. *

+ * * @return the entry description, null if none. - * + * */ + @Override public SyndContent getDescription() { - return _description; + return this._description; } /** * Sets the entry description. *

+ * * @param description the entry description to set, null if none. - * + * */ - public void setDescription(SyndContent description) { - _description = description; + @Override + public void setDescription(final SyndContent description) { + this._description = description; } /** * Returns the entry contents. *

- * @return a list of SyndContentImpl elements with the entry contents, - * an empty list if none. - * + * + * @return a list of SyndContentImpl elements with the entry contents, an + * empty list if none. + * */ + @Override public List getContents() { - return (_contents==null) ? (_contents=new ArrayList()) : _contents; + return this._contents == null ? (this._contents = new ArrayList()) : this._contents; } /** * Sets the entry contents. *

- * @param contents the list of SyndContentImpl elements with the entry contents to set, - * an empty list or null if none. - * + * + * @param contents the list of SyndContentImpl elements with the entry + * contents to set, an empty list or null if none. + * */ - public void setContents(List contents) { - _contents = contents; + @Override + public void setContents(final List contents) { + this._contents = contents; } /** * Returns the entry enclosures. *

- * @return a list of SyndEnclosure elements with the entry enclosures, - * an empty list if none. - * + * + * @return a list of SyndEnclosure elements with the entry enclosures, an + * empty list if none. + * */ + @Override public List getEnclosures() { - return (_enclosures==null) ? (_enclosures=new ArrayList()) : _enclosures; + return this._enclosures == null ? (this._enclosures = new ArrayList()) : this._enclosures; } /** * Sets the entry enclosures. *

- * @param enclosures the list of SyndEnclosure elements with the entry enclosures to set, - * an empty list or null if none. - * + * + * @param enclosures the list of SyndEnclosure elements with the entry + * enclosures to set, an empty list or null if none. + * */ - public void setEnclosures(List enclosures) { - _enclosures = enclosures; + @Override + public void setEnclosures(final List enclosures) { + this._enclosures = enclosures; } - /** * Returns the entry published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

+ * * @return the entry published date, null if none. - * + * */ + @Override public Date getPublishedDate() { return getDCModule().getDate(); } @@ -326,259 +386,306 @@ public class SyndEntryImpl implements Serializable,SyndEntry { /** * Sets the entry published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

- * @param publishedDate the entry published date to set, null if none. - * + * + * @param publishedDate the entry published date to set, null if + * none. + * */ - public void setPublishedDate(Date publishedDate) { + @Override + public void setPublishedDate(final Date publishedDate) { getDCModule().setDate(publishedDate); } /** * Returns the entry categories. *

- * @return a list of SyndCategoryImpl elements with the entry categories, - * an empty list if none. - * + * + * @return a list of SyndCategoryImpl elements with the entry categories, an + * empty list if none. + * */ + @Override public List getCategories() { - return _categories; + return this._categories; } /** * Sets the entry categories. *

- * This method is a convenience method, it maps to the Dublin Core module subjects. + * This method is a convenience method, it maps to the Dublin Core module + * subjects. *

- * @param categories the list of SyndCategoryImpl elements with the entry categories to set, - * an empty list or null if none. - * + * + * @param categories the list of SyndCategoryImpl elements with the entry + * categories to set, an empty list or null if none. + * */ - public void setCategories(List categories) { - _categories = categories; + @Override + public void setCategories(final List categories) { + this._categories = categories; } /** * Returns the entry modules. *

- * @return a list of ModuleImpl elements with the entry modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the entry modules, an empty + * list if none. + * */ + @Override public List getModules() { - if (_modules==null) { - _modules=new ArrayList(); + if (this._modules == null) { + this._modules = new ArrayList(); } - if (ModuleUtils.getModule(_modules,DCModule.URI)==null) { - _modules.add(new DCModuleImpl()); + if (ModuleUtils.getModule(this._modules, DCModule.URI) == null) { + this._modules.add(new DCModuleImpl()); } - return _modules; + return this._modules; } /** * Sets the entry modules. *

- * @param modules the list of ModuleImpl elements with the entry modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the entry modules to + * set, an empty list or null if none. + * */ - public void setModules(List modules) { - _modules = modules; + @Override + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ - public Module getModule(String uri) { - return ModuleUtils.getModule(getModules(),uri); + @Override + public Module getModule(final String uri) { + return ModuleUtils.getModule(getModules(), uri); } /** * Returns the Dublin Core module of the feed. + * * @return the DC module, it's never null - * + * */ private DCModule getDCModule() { return (DCModule) getModule(DCModule.URI); } + @Override public Class getInterface() { return SyndEntry.class; } - public void copyFrom(CopyFrom obj) { - COPY_FROM_HELPER.copy(this,obj); + @Override + public void copyFrom(final CopyFrom obj) { + COPY_FROM_HELPER.copy(this, obj); } private static final CopyFromHelper COPY_FROM_HELPER; static { - Map basePropInterfaceMap = new HashMap(); - basePropInterfaceMap.put("uri",String.class); - basePropInterfaceMap.put("title",String.class); - basePropInterfaceMap.put("link",String.class); - basePropInterfaceMap.put("uri",String.class); - basePropInterfaceMap.put("description",SyndContent.class); - basePropInterfaceMap.put("contents",SyndContent.class); - basePropInterfaceMap.put("enclosures",SyndEnclosure.class); - basePropInterfaceMap.put("modules",Module.class); + final Map basePropInterfaceMap = new HashMap(); + basePropInterfaceMap.put("uri", String.class); + basePropInterfaceMap.put("title", String.class); + basePropInterfaceMap.put("link", String.class); + basePropInterfaceMap.put("uri", String.class); + basePropInterfaceMap.put("description", SyndContent.class); + basePropInterfaceMap.put("contents", SyndContent.class); + basePropInterfaceMap.put("enclosures", SyndEnclosure.class); + basePropInterfaceMap.put("modules", Module.class); - Map basePropClassImplMap = new HashMap(); - basePropClassImplMap.put(SyndContent.class,SyndContentImpl.class); - basePropClassImplMap.put(SyndEnclosure.class,SyndEnclosureImpl.class); - basePropClassImplMap.put(DCModule.class,DCModuleImpl.class); - basePropClassImplMap.put(SyModule.class,SyModuleImpl.class); + final Map basePropClassImplMap = new HashMap(); + basePropClassImplMap.put(SyndContent.class, SyndContentImpl.class); + basePropClassImplMap.put(SyndEnclosure.class, SyndEnclosureImpl.class); + basePropClassImplMap.put(DCModule.class, DCModuleImpl.class); + basePropClassImplMap.put(SyModule.class, SyModuleImpl.class); - COPY_FROM_HELPER = new CopyFromHelper(SyndEntry.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(SyndEntry.class, basePropInterfaceMap, basePropClassImplMap); } /** * Returns the links *

+ * * @return Returns the links. */ + @Override public List getLinks() { - return (_links==null) ? (_links=new ArrayList()) : _links; + return this._links == null ? (this._links = new ArrayList()) : this._links; } - + /** * Set the links *

+ * * @param links The links to set. */ - public void setLinks(List links) { - _links = links; - } - + @Override + public void setLinks(final List links) { + this._links = links; + } + /** * Returns the updatedDate *

+ * * @return Returns the updatedDate. */ + @Override public Date getUpdatedDate() { - return _updatedDate == null ? null : new Date(_updatedDate.getTime()); + return this._updatedDate == null ? null : new Date(this._updatedDate.getTime()); } - + /** * Set the updatedDate *

+ * * @param updatedDate The updatedDate to set. */ - public void setUpdatedDate(Date updatedDate) { - _updatedDate = new Date(updatedDate.getTime()); + @Override + public void setUpdatedDate(final Date updatedDate) { + this._updatedDate = new Date(updatedDate.getTime()); } + @Override public List getAuthors() { - return (_authors==null) ? (_authors=new ArrayList()) : _authors; + return this._authors == null ? (this._authors = new ArrayList()) : this._authors; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see com.sun.syndication.feed.synd.SyndEntry#setAuthors(java.util.List) */ - public void setAuthors(List authors) { - _authors = authors; + @Override + public void setAuthors(final List authors) { + this._authors = authors; } /** * Returns the entry author. *

- * This method is a convenience method, it maps to the Dublin Core module creator. + * This method is a convenience method, it maps to the Dublin Core module + * creator. *

+ * * @return the entry author, null if none. - * + * */ + @Override public String getAuthor() { String author; - + // Start out looking for one or more authors in _authors. For non-Atom // feeds, _authors may actually be null. - if ((_authors != null) && (_authors.size() > 0)) { - author = ((SyndPerson)_authors.get(0)).getName(); + if (this._authors != null && this._authors.size() > 0) { + author = this._authors.get(0).getName(); } else { author = getDCModule().getCreator(); } if (author == null) { author = ""; } - + return author; } /** * Sets the entry author. *

- * This method is a convenience method, it maps to the Dublin Core module creator. + * This method is a convenience method, it maps to the Dublin Core module + * creator. *

+ * * @param author the entry author to set, null if none. - * + * */ - public void setAuthor(String author) { + @Override + public void setAuthor(final String author) { // Get the DCModule so that we can check to see if "creator" is already // set. - DCModule dcModule = getDCModule(); - String currentValue = dcModule.getCreator(); - - if ((currentValue == null) || (currentValue.length() == 0)) { + final DCModule dcModule = getDCModule(); + final String currentValue = dcModule.getCreator(); + + if (currentValue == null || currentValue.length() == 0) { getDCModule().setCreator(author); } } - + + @Override public List getContributors() { - return (_contributors==null) ? (_contributors=new ArrayList()) : _contributors; + return this._contributors == null ? (this._contributors = new ArrayList()) : this._contributors; } - /* (non-Javadoc) - * @see com.sun.syndication.feed.synd.SyndEntry#setContributors(java.util.List) + /* + * (non-Javadoc) + * @see + * com.sun.syndication.feed.synd.SyndEntry#setContributors(java.util.List) */ - public void setContributors(List contributors) { - _contributors = contributors; + @Override + public void setContributors(final List contributors) { + this._contributors = contributors; } - + + @Override public SyndFeed getSource() { - return _source; + return this._source; } - - public void setSource(SyndFeed source) { - _source = source; + + @Override + public void setSource(final SyndFeed source) { + this._source = source; } - + /** * Returns foreign markup found at channel level. *

- * @return list of JDOM nodes containing channel-level foreign markup, - * an empty list if none. - * + * + * @return list of JDOM nodes containing channel-level foreign markup, an + * empty list if none. + * */ + @Override public List getForeignMarkup() { - return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup; + return this._foreignMarkup == null ? (this._foreignMarkup = new ArrayList()) : this._foreignMarkup; } /** * Sets foreign markup found at channel level. *

- * @param foreignMarkup list of JDOM nodes containing channel-level foreign markup, - * an empty list if none. - * + * + * @param foreignMarkup list of JDOM nodes containing channel-level foreign + * markup, an empty list if none. + * */ - public void setForeignMarkup(List foreignMarkup) { - _foreignMarkup = (List)foreignMarkup; + @Override + public void setForeignMarkup(final List foreignMarkup) { + this._foreignMarkup = foreignMarkup; } - public Object getWireEntry() { - return wireEntry; - } - - public void setWireEntry(Object wireEntry) { - this.wireEntry = wireEntry; - } + @Override + public Object getWireEntry() { + return this.wireEntry; + } - public SyndLink findRelatedLink(String relation) { - for(SyndLink l : this.getLinks()){ - if(relation.equals(l.getRel())){ + public void setWireEntry(final Object wireEntry) { + this.wireEntry = wireEntry; + } + + @Override + public SyndLink findRelatedLink(final String relation) { + for (final SyndLink l : getLinks()) { + if (relation.equals(l.getRel())) { return l; } } diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java b/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java index 97e0dba..96446b3 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java @@ -16,29 +16,33 @@ */ package com.sun.syndication.feed.synd; -import com.sun.syndication.feed.CopyFrom; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.module.Extendable; -import com.sun.syndication.feed.module.Module; - import java.util.Date; import java.util.List; import org.jdom2.Element; +import com.sun.syndication.feed.CopyFrom; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.module.Extendable; +import com.sun.syndication.feed.module.Module; + /** * Bean interface for all types of feeds. *

- * It handles all RSS versions and Atom 0.3, it normalizes all info, it may lose information. + * It handles all RSS versions and Atom 0.3, it normalizes all info, it may lose + * information. *

+ * * @author Alejandro Abdelnur - * + * */ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { /** - * Returns the real feed types the SyndFeedImpl supports when converting from and to. + * Returns the real feed types the SyndFeedImpl supports when converting + * from and to. *

+ * * @return the real feed type supported. */ List getSupportedFeedTypes(); @@ -46,66 +50,76 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { /** * Creates a real feed containing the information of the SyndFeedImpl. *

- * The feed type of the created WireFeed is taken from the SyndFeedImpl feedType property. + * The feed type of the created WireFeed is taken from the SyndFeedImpl + * feedType property. *

+ * * @return the real feed. - * + * */ WireFeed createWireFeed(); /** * Creates a real feed containing the information of the SyndFeedImpl. *

+ * * @param feedType the feed type for the WireFeed to be created. * @return the real feed. - * + * */ WireFeed createWireFeed(String feedType); /** - * Returns the WireFeed this SyndFeed was created from. - * Will return null if the original feed is not stored or if this SyndFeed was not created from a WireFeed + * Returns the WireFeed this SyndFeed was created from. Will return null if + * the original feed is not stored or if this SyndFeed was not created from + * a WireFeed * * @return The WireFeed this was created from, or null * */ WireFeed originalWireFeed(); - + /** * * @return true if this SyndFeed preserves the WireFeed it was created from */ - boolean isPreservingWireFeed(); + boolean isPreservingWireFeed(); /** - * Returns the wire feed type the feed had/will-have when converted from/to a WireFeed. + * Returns the wire feed type the feed had/will-have when converted from/to + * a WireFeed. *

+ * * @return the feed type, null if none. - * + * */ String getFeedType(); /** * Sets the wire feed type the feed will-have when coverted to a WireFeed. *

+ * * @param feedType the feed type to set, null if none. - * + * */ void setFeedType(String feedType); /** - * Returns the charset encoding of a the feed. This is not set by Rome parsers. + * Returns the charset encoding of a the feed. This is not set by Rome + * parsers. *

+ * * @return the charset encoding of the feed. - * + * */ public String getEncoding(); /** * Sets the charset encoding of a the feed. This is not set by Rome parsers. *

+ * * @param encoding the charset encoding of the feed. - * + * */ public void setEncoding(String encoding); @@ -113,25 +127,28 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { * Returns the feed URI. *

* How the feed URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

* The returned URI is a normalized URI as specified in RFC 2396bis. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @return the feed URI, null if none. - * + * */ String getUri(); @@ -139,55 +156,62 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { * Sets the feed URI. *

* How the feed URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @param uri the feed URI to set, null if none. - * + * */ void setUri(String uri); /** * Returns the feed title. *

+ * * @return the feed title, null if none. - * + * */ String getTitle(); /** * Sets the feed title. *

+ * * @param title the feed title to set, null if none. - * + * */ void setTitle(String title); /** * Returns the feed title. *

+ * * @return the feed title, null if none. - * + * */ SyndContent getTitleEx(); /** * Sets the feed title. *

+ * * @param title the feed title to set, null if none. - * + * */ void setTitleEx(SyndContent title); @@ -195,19 +219,20 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { * Returns the feed link. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @return the feed link, null if none. - * + * */ String getLink(); @@ -215,87 +240,98 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { * Sets the feed link. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @param link the feed link to set, null if none. - * + * */ void setLink(String link); /** * Returns the entry links *

+ * * @return the entry links, null if none. - * + * */ List getLinks(); /** * Sets the entry links. *

+ * * @param links the entry links to set, null if none. - * + * */ void setLinks(List links); /** * Returns the feed description. *

+ * * @return the feed description, null if none. - * + * */ String getDescription(); /** * Sets the feed description. *

+ * * @param description the feed description to set, null if none. - * + * */ void setDescription(String description); - + /** * Returns the feed description as a text construct. *

+ * * @return the feed description, null if none. - * + * */ SyndContent getDescriptionEx(); /** * Sets the feed description as a text construct. *

+ * * @param description the feed description to set, null if none. - * + * */ void setDescriptionEx(SyndContent description); /** * Returns the feed published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

+ * * @return the feed published date, null if none. - * + * */ Date getPublishedDate(); /** * Sets the feed published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

+ * * @param publishedDate the feed published date to set, null if none. - * + * */ void setPublishedDate(Date publishedDate); @@ -303,23 +339,25 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { * Returns the feed authors. *

* For Atom feeds, this returns the authors as a list of SyndPerson objects, - * for RSS feeds this method is a convenience method, it maps to the - * Dublin Core module creator. + * for RSS feeds this method is a convenience method, it maps to the Dublin + * Core module creator. *

+ * * @return the feed authors, null if none. - * + * */ List getAuthors(); /** * Sets the feed authors. *

- * For Atom feeds, this sets the authors as a list of SyndPerson - * objects, for RSS feeds this method is a convenience method, it maps - * to the Dublin Core module creator. + * For Atom feeds, this sets the authors as a list of SyndPerson objects, + * for RSS feeds this method is a convenience method, it maps to the Dublin + * Core module creator. *

+ * * @param authors the feed authors to set, null if none. - * + * */ void setAuthors(List authors); @@ -327,34 +365,37 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { * Returns the name of the first feed author in the collection of authors. *

* For Atom feeds, this returns the authors as a list of SyndPerson objects, - * for RSS feeds this method is a convenience method, it maps to the - * Dublin Core module creator. + * for RSS feeds this method is a convenience method, it maps to the Dublin + * Core module creator. *

+ * * @return the feed author, null if none. - * + * */ String getAuthor(); /** * Sets the feed author. *

- * For Atom feeds, this sets the feed author's name, for RSS feeds - * this method is a convenience method, it maps to the Dublin Core - * module creator. + * For Atom feeds, this sets the feed author's name, for RSS feeds this + * method is a convenience method, it maps to the Dublin Core module + * creator. *

+ * * @param author the feed author to set, null if none. - * + * */ void setAuthor(String author); /** * Returns the feed author. *

- * For Atom feeds, this returns the contributors as a list of - * SyndPerson objects + * For Atom feeds, this returns the contributors as a list of SyndPerson + * objects *

+ * * @return the feed author, null if none. - * + * */ public List getContributors(); @@ -363,155 +404,182 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { *

* Returns contributors as a list of SyndPerson objects. *

+ * * @param contributors the feed contributors to set, null if none. - * + * */ void setContributors(List contributors); /** * Returns the feed copyright. *

- * This method is a convenience method, it maps to the Dublin Core module rights. + * This method is a convenience method, it maps to the Dublin Core module + * rights. *

+ * * @return the feed copyright, null if none. - * + * */ String getCopyright(); /** * Sets the feed copyright. *

- * This method is a convenience method, it maps to the Dublin Core module rights. + * This method is a convenience method, it maps to the Dublin Core module + * rights. *

+ * * @param copyright the feed copyright to set, null if none. - * + * */ void setCopyright(String copyright); /** * Returns the feed image. *

+ * * @return the feed image, null if none. - * + * */ SyndImage getImage(); /** * Sets the feed image. *

+ * * @param image the feed image to set, null if none. - * + * */ void setImage(SyndImage image); /** * Returns the feed categories. *

- * This method is a convenience method, it maps to the Dublin Core module subjects. + * This method is a convenience method, it maps to the Dublin Core module + * subjects. *

- * @return a list of SyndCategoryImpl elements with the feed categories, - * an empty list if none. - * + * + * @return a list of SyndCategoryImpl elements with the feed categories, an + * empty list if none. + * */ List getCategories(); /** * Sets the feed categories. *

- * This method is a convenience method, it maps to the Dublin Core module subjects. + * This method is a convenience method, it maps to the Dublin Core module + * subjects. *

- * @param categories the list of SyndCategoryImpl elements with the feed categories to set, - * an empty list or null if none. - * + * + * @param categories the list of SyndCategoryImpl elements with the feed + * categories to set, an empty list or null if none. + * */ void setCategories(List categories); /** * Returns the feed entries. *

- * @return a list of SyndEntry elements with the feed entries, - * an empty list if none. - * + * + * @return a list of SyndEntry elements with the feed entries, an empty list + * if none. + * */ List getEntries(); /** * Sets the feed entries. *

- * @param entries the list of SyndEntryImpl elements with the feed entries to set, - * an empty list or null if none. - * + * + * @param entries the list of SyndEntryImpl elements with the feed entries + * to set, an empty list or null if none. + * */ void setEntries(List entries); /** * Returns the feed language. *

- * This method is a convenience method, it maps to the Dublin Core module language. + * This method is a convenience method, it maps to the Dublin Core module + * language. *

+ * * @return the feed language, null if none. - * + * */ String getLanguage(); /** * Sets the feed language. *

- * This method is a convenience method, it maps to the Dublin Core module language. + * This method is a convenience method, it maps to the Dublin Core module + * language. *

+ * * @param language the feed language to set, null if none. - * + * */ void setLanguage(String language); /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ + @Override public Module getModule(String uri); /** * Returns the feed modules. *

- * @return a list of ModuleImpl elements with the feed modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the feed modules, an empty + * list if none. + * */ + @Override List getModules(); /** * Sets the feed modules. *

- * @param modules the list of ModuleImpl elements with the feed modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the feed modules to + * set, an empty list or null if none. + * */ + @Override void setModules(List modules); /** * Returns foreign markup found at channel level. *

+ * * @return Opaque object to discourage use - * + * */ public List getForeignMarkup(); /** * Sets foreign markup found at channel level. *

+ * * @param foreignMarkup Opaque object to discourage use - * + * */ public void setForeignMarkup(List foreignMarkup); - + /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java index 5da72a9..28ada2b 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java @@ -16,38 +16,51 @@ */ package com.sun.syndication.feed.synd; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.jdom2.Element; + import com.sun.syndication.feed.CopyFrom; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.impl.CopyFromHelper; import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.module.*; +import com.sun.syndication.feed.impl.CopyFromHelper; +import com.sun.syndication.feed.impl.ObjectBean; +import com.sun.syndication.feed.module.DCModule; +import com.sun.syndication.feed.module.DCModuleImpl; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.feed.module.SyModule; +import com.sun.syndication.feed.module.SyModuleImpl; import com.sun.syndication.feed.module.impl.ModuleUtils; import com.sun.syndication.feed.synd.impl.Converters; import com.sun.syndication.feed.synd.impl.URINormalizer; -import java.util.*; -import java.io.Serializable; - -import org.jdom2.Element; - /** * Bean for all types of feeds. *

- * It handles all RSS versions, Atom 0.3 and Atom 1.0, it normalizes all info, it may lose information. + * It handles all RSS versions, Atom 0.3 and Atom 1.0, it normalizes all info, + * it may lose information. *

+ * * @author Alejandro Abdelnur - * + * */ public class SyndFeedImpl implements Serializable, SyndFeed { - - private ObjectBean _objBean; - - private String _encoding; - private String _uri; + + private final ObjectBean _objBean; + + private String _encoding; + private String _uri; private SyndContent _title; private SyndContent _description; - private String _feedType; - private String _link; + private String _feedType; + private String _link; private List _links; private SyndImage _image; private List _entries; @@ -55,7 +68,7 @@ public class SyndFeedImpl implements Serializable, SyndFeed { private List _authors; private List _contributors; private List _foreignMarkup; - + private WireFeed wireFeed = null; private boolean preserveWireFeed = false; @@ -66,8 +79,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed { /** * Unmodifiable Set containing the convenience properties of this class. *

- * Convenience properties are mapped to Modules, for cloning the convenience properties - * can be ignored as the will be copied as part of the module cloning. + * Convenience properties are mapped to Modules, for cloning the convenience + * properties can be ignored as the will be copied as part of the module + * cloning. */ public static final Set CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES); @@ -81,102 +95,115 @@ public class SyndFeedImpl implements Serializable, SyndFeed { } /** - * Returns the real feed types the SyndFeedImpl supports when converting from and to. + * Returns the real feed types the SyndFeedImpl supports when converting + * from and to. *

+ * * @return the real feed type supported. */ + @Override public List getSupportedFeedTypes() { return CONVERTERS.getSupportedFeedTypes(); } /** - * For implementations extending SyndFeedImpl to be able to use the ObjectBean functionality - * with extended interfaces. + * For implementations extending SyndFeedImpl to be able to use the + * ObjectBean functionality with extended interfaces. *

+ * * @param beanClass - * @param convenienceProperties set containing the convenience properties of the SyndEntryImpl - * (the are ignored during cloning, check CloneableBean for details). - * + * @param convenienceProperties set containing the convenience properties of + * the SyndEntryImpl (the are ignored during cloning, check + * CloneableBean for details). + * */ - protected SyndFeedImpl(Class beanClass,Set convenienceProperties) { - _objBean = new ObjectBean(beanClass,this,convenienceProperties); + protected SyndFeedImpl(final Class beanClass, final Set convenienceProperties) { + this._objBean = new ObjectBean(beanClass, this, convenienceProperties); } /** * Default constructor. All properties are set to null. *

- * + * */ public SyndFeedImpl() { this(null); } /** - * Creates a SyndFeedImpl and populates all its properties out of the - * given RSS Channel or Atom Feed properties. + * Creates a SyndFeedImpl and populates all its properties out of the given + * RSS Channel or Atom Feed properties. *

- * @param feed the RSS Channel or the Atom Feed to populate the properties from. - * + * + * @param feed the RSS Channel or the Atom Feed to populate the properties + * from. + * */ - public SyndFeedImpl(WireFeed feed) { + public SyndFeedImpl(final WireFeed feed) { this(feed, false); } - + /** - * Creates a SyndFeedImpl and populates all its properties out of the - * given RSS Channel or Atom Feed properties, while optionally preserving - * the WireFeed for access via the orignalWireFeed() method. + * Creates a SyndFeedImpl and populates all its properties out of the given + * RSS Channel or Atom Feed properties, while optionally preserving the + * WireFeed for access via the orignalWireFeed() method. * * @param feed * @param preserveWireFeed */ - public SyndFeedImpl(WireFeed feed, boolean preserveWireFeed) { - this(SyndFeed.class,IGNORE_PROPERTIES); + public SyndFeedImpl(final WireFeed feed, final boolean preserveWireFeed) { + this(SyndFeed.class, IGNORE_PROPERTIES); - if (preserveWireFeed) { - this.wireFeed = feed; - this.preserveWireFeed = preserveWireFeed; - } - - if (feed!=null) { - _feedType = feed.getFeedType(); - Converter converter = CONVERTERS.getConverter(_feedType); - if (converter==null) { - throw new IllegalArgumentException("Invalid feed type ["+_feedType+"]"); - } - converter.copyInto(feed,this); + if (preserveWireFeed) { + this.wireFeed = feed; + this.preserveWireFeed = preserveWireFeed; } - + + if (feed != null) { + this._feedType = feed.getFeedType(); + final Converter converter = CONVERTERS.getConverter(this._feedType); + if (converter == null) { + throw new IllegalArgumentException("Invalid feed type [" + this._feedType + "]"); + } + converter.copyInto(feed, this); + } + } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ + @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public boolean equals(Object other) { + @Override + public boolean equals(final Object other) { if (other == null || !(other instanceof SyndFeedImpl)) { return false; } - // can't use foreign markup in equals, due to JDOM equals impl - List fm = getForeignMarkup(); - setForeignMarkup(((SyndFeedImpl)other).getForeignMarkup()); - boolean ret = _objBean.equals(other); - setForeignMarkup(fm); // restore foreign markup - return ret; + // can't use foreign markup in equals, due to JDOM equals impl + final List fm = getForeignMarkup(); + setForeignMarkup(((SyndFeedImpl) other).getForeignMarkup()); + final boolean ret = this._objBean.equals(other); + setForeignMarkup(fm); // restore foreign markup + return ret; } /** @@ -184,297 +211,358 @@ public class SyndFeedImpl implements Serializable, SyndFeed { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ + @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ + @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Creates a real feed containing the information of the SyndFeedImpl. *

- * The feed type of the created WireFeed is taken from the SyndFeedImpl feedType property. + * The feed type of the created WireFeed is taken from the SyndFeedImpl + * feedType property. *

+ * * @return the real feed. - * + * */ + @Override public WireFeed createWireFeed() { - return createWireFeed(_feedType); + return this.createWireFeed(this._feedType); } /** * Creates a real feed containing the information of the SyndFeedImpl. *

+ * * @param feedType the feed type for the WireFeed to be created. * @return the real feed. - * + * */ - public WireFeed createWireFeed(String feedType) { - if (feedType==null) { + @Override + public WireFeed createWireFeed(final String feedType) { + if (feedType == null) { throw new IllegalArgumentException("Feed type cannot be null"); } - Converter converter = CONVERTERS.getConverter(feedType); - if (converter==null) { - throw new IllegalArgumentException("Invalid feed type ["+feedType+"]"); + final Converter converter = CONVERTERS.getConverter(feedType); + if (converter == null) { + throw new IllegalArgumentException("Invalid feed type [" + feedType + "]"); } return converter.createRealFeed(this); } - + /** - * Returns the WireFeed this SyndFeed was created from. - * Will return null if the original feed is not stored or if this SyndFeed was not created from a WireFeed. - *
- * Note: The wire feed returned here will NOT contain any modifications done on this SyndFeed since it was created. - * That is in contrast to the createWireFeed method, which will reflect the current state of the SyndFeed + * Returns the WireFeed this SyndFeed was created from. Will return null if + * the original feed is not stored or if this SyndFeed was not created from + * a WireFeed.
+ * Note: The wire feed returned here will NOT contain any modifications done + * on this SyndFeed since it was created. That is in contrast to the + * createWireFeed method, which will reflect the current state of the + * SyndFeed * * @return The WireFeed this was created from, or null * - */ + */ + @Override public WireFeed originalWireFeed() { - return wireFeed; + return this.wireFeed; } /** - * Returns the wire feed type the feed had/will-have when coverted from/to a WireFeed. + * Returns the wire feed type the feed had/will-have when coverted from/to a + * WireFeed. *

+ * * @return the feed type, null if none. - * + * */ + @Override public String getFeedType() { - return _feedType; + return this._feedType; } /** * Sets the wire feed type the feed will-have when coverted to a WireFeed. *

+ * * @param feedType the feed type to set, null if none. - * + * */ - public void setFeedType(String feedType) { - _feedType = feedType; + @Override + public void setFeedType(final String feedType) { + this._feedType = feedType; } /** - * Returns the charset encoding of a the feed. This is not set by Rome parsers. + * Returns the charset encoding of a the feed. This is not set by Rome + * parsers. *

+ * * @return the charset encoding of the feed. - * + * */ + @Override public String getEncoding() { - return _encoding; + return this._encoding; } /** * Sets the charset encoding of a the feed. This is not set by Rome parsers. *

+ * * @param encoding the charset encoding of the feed. - * + * */ - public void setEncoding(String encoding) { - _encoding = encoding; + @Override + public void setEncoding(final String encoding) { + this._encoding = encoding; } /** * Returns the feed URI. *

* How the feed URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

* The returned URI is a normalized URI as specified in RFC 2396bis. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @return the feed URI, null if none. - * + * */ + @Override public String getUri() { - return _uri; + return this._uri; } /** * Sets the feed URI. *

* How the feed URI maps to a concrete feed type (RSS or Atom) depends on - * the concrete feed type. This is explained in detail in Rome documentation, - * Feed and entry URI mapping. + * the concrete feed type. This is explained in detail in Rome + * documentation, Feed and + * entry URI mapping. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @param uri the feed URI to set, null if none. - * + * */ - public void setUri(String uri) { - _uri = URINormalizer.normalize(uri); + @Override + public void setUri(final String uri) { + this._uri = URINormalizer.normalize(uri); } /** * Returns the feed title. *

+ * * @return the feed title, null if none. - * + * */ + @Override public String getTitle() { - if (_title != null) return _title.getValue(); + if (this._title != null) { + return this._title.getValue(); + } return null; } /** * Sets the feed title. *

+ * * @param title the feed title to set, null if none. - * + * */ - public void setTitle(String title) { - if (_title == null) _title = new SyndContentImpl(); - _title.setValue(title); + @Override + public void setTitle(final String title) { + if (this._title == null) { + this._title = new SyndContentImpl(); + } + this._title.setValue(title); } /** * Returns the feed title as a text construct. *

+ * * @return the feed title, null if none. - * + * */ + @Override public SyndContent getTitleEx() { - return _title; + return this._title; } /** * Sets the feed title as a text construct. *

+ * * @param title the feed title to set, null if none. - * + * */ - public void setTitleEx(SyndContent title) { - _title = title; + @Override + public void setTitleEx(final SyndContent title) { + this._title = title; } /** * Returns the feed link. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @return the feed link, null if none. - * + * */ + @Override public String getLink() { - return _link; + return this._link; } /** * Sets the feed link. *

* Note: The URI is the unique identifier, in the RSS 2.0/atom case this is - * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link - * is the URL that the item is accessible under, the URI is the - * permanent identifier which the aggregator should use to reference - * this item. Often the URI will use some standardized identifier scheme - * such as DOI's so that items can be identified even if they appear in - * multiple feeds with different "links" (they might be on different - * hosting platforms but be the same item). Also, though rare, there - * could be multiple items with the same link but a different URI and - * associated metadata which need to be treated as distinct entities. - * In the RSS 1.0 case the URI must be a valid RDF URI reference. + * the GUID, for RSS 1.0 this is the URI attribute of the item. The Link is + * the URL that the item is accessible under, the URI is the permanent + * identifier which the aggregator should use to reference this item. Often + * the URI will use some standardized identifier scheme such as DOI's so + * that items can be identified even if they appear in multiple feeds with + * different "links" (they might be on different hosting platforms but be + * the same item). Also, though rare, there could be multiple items with the + * same link but a different URI and associated metadata which need to be + * treated as distinct entities. In the RSS 1.0 case the URI must be a valid + * RDF URI reference. *

+ * * @param link the feed link to set, null if none. - * + * */ - public void setLink(String link) { - _link = link; + @Override + public void setLink(final String link) { + this._link = link; } /** * Returns the feed description. *

+ * * @return the feed description, null if none. - * + * */ + @Override public String getDescription() { - if (_description != null) return _description.getValue(); + if (this._description != null) { + return this._description.getValue(); + } return null; } /** * Sets the feed description. *

+ * * @param description the feed description to set, null if none. - * + * */ - public void setDescription(String description) { - if (_description == null) _description = new SyndContentImpl(); - _description.setValue(description); + @Override + public void setDescription(final String description) { + if (this._description == null) { + this._description = new SyndContentImpl(); + } + this._description.setValue(description); } - + /** * Returns the feed description as a text construct. *

+ * * @return the feed description, null if none. - * + * */ + @Override public SyndContent getDescriptionEx() { - return _description; + return this._description; } /** * Sets the feed description as a text construct. *

+ * * @param description the feed description to set, null if none. - * + * */ - public void setDescriptionEx(SyndContent description) { - _description = description; + @Override + public void setDescriptionEx(final SyndContent description) { + this._description = description; } /** * Returns the feed published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

+ * * @return the feed published date, null if none. - * + * */ + @Override public Date getPublishedDate() { return getDCModule().getDate(); } @@ -482,23 +570,29 @@ public class SyndFeedImpl implements Serializable, SyndFeed { /** * Sets the feed published date. *

- * This method is a convenience method, it maps to the Dublin Core module date. + * This method is a convenience method, it maps to the Dublin Core module + * date. *

+ * * @param publishedDate the feed published date to set, null if none. - * + * */ - public void setPublishedDate(Date publishedDate) { + @Override + public void setPublishedDate(final Date publishedDate) { getDCModule().setDate(publishedDate); } /** * Returns the feed copyright. *

- * This method is a convenience method, it maps to the Dublin Core module rights. + * This method is a convenience method, it maps to the Dublin Core module + * rights. *

+ * * @return the feed copyright, null if none. - * + * */ + @Override public String getCopyright() { return getDCModule().getRights(); } @@ -506,44 +600,54 @@ public class SyndFeedImpl implements Serializable, SyndFeed { /** * Sets the feed copyright. *

- * This method is a convenience method, it maps to the Dublin Core module rights. + * This method is a convenience method, it maps to the Dublin Core module + * rights. *

+ * * @param copyright the feed copyright to set, null if none. - * + * */ - public void setCopyright(String copyright) { + @Override + public void setCopyright(final String copyright) { getDCModule().setRights(copyright); } /** * Returns the feed image. *

+ * * @return the feed image, null if none. - * + * */ + @Override public SyndImage getImage() { - return _image; + return this._image; } /** * Sets the feed image. *

+ * * @param image the feed image to set, null if none. - * + * */ - public void setImage(SyndImage image) { - _image = image; + @Override + public void setImage(final SyndImage image) { + this._image = image; } /** * Returns the feed categories. *

- * This method is a convenience method, it maps to the Dublin Core module subjects. + * This method is a convenience method, it maps to the Dublin Core module + * subjects. *

- * @return a list of SyndCategoryImpl elements with the feed categories, - * an empty list if none. - * + * + * @return a list of SyndCategoryImpl elements with the feed categories, an + * empty list if none. + * */ + @Override public List getCategories() { return new SyndCategoryListFacade(getDCModule().getSubjects()); } @@ -551,46 +655,56 @@ public class SyndFeedImpl implements Serializable, SyndFeed { /** * Sets the feed categories. *

- * This method is a convenience method, it maps to the Dublin Core module subjects. + * This method is a convenience method, it maps to the Dublin Core module + * subjects. *

- * @param categories the list of SyndCategoryImpl elements with the feed categories to set, - * an empty list or null if none. - * + * + * @param categories the list of SyndCategoryImpl elements with the feed + * categories to set, an empty list or null if none. + * */ - public void setCategories(List categories) { + @Override + public void setCategories(final List categories) { getDCModule().setSubjects(SyndCategoryListFacade.convertElementsSyndCategoryToSubject(categories)); } /** * Returns the feed entries. *

- * @return a list of SyndEntryImpl elements with the feed entries, - * an empty list if none. - * + * + * @return a list of SyndEntryImpl elements with the feed entries, an empty + * list if none. + * */ + @Override public List getEntries() { - return (_entries==null) ? (_entries=new ArrayList()) : _entries; + return this._entries == null ? (this._entries = new ArrayList()) : this._entries; } /** * Sets the feed entries. *

- * @param entries the list of SyndEntryImpl elements with the feed entries to set, - * an empty list or null if none. - * + * + * @param entries the list of SyndEntryImpl elements with the feed entries + * to set, an empty list or null if none. + * */ - public void setEntries(List entries) { - _entries = entries; + @Override + public void setEntries(final List entries) { + this._entries = entries; } /** * Returns the feed language. *

- * This method is a convenience method, it maps to the Dublin Core module language. + * This method is a convenience method, it maps to the Dublin Core module + * language. *

+ * * @return the feed language, null if none. - * + * */ + @Override public String getLanguage() { return getDCModule().getLanguage(); } @@ -598,131 +712,150 @@ public class SyndFeedImpl implements Serializable, SyndFeed { /** * Sets the feed language. *

- * This method is a convenience method, it maps to the Dublin Core module language. + * This method is a convenience method, it maps to the Dublin Core module + * language. *

+ * * @param language the feed language to set, null if none. - * + * */ - public void setLanguage(String language) { + @Override + public void setLanguage(final String language) { getDCModule().setLanguage(language); } /** * Returns the feed modules. *

- * @return a list of ModuleImpl elements with the feed modules, - * an empty list if none. - * + * + * @return a list of ModuleImpl elements with the feed modules, an empty + * list if none. + * */ + @Override public List getModules() { - if (_modules==null) { - _modules=new ArrayList(); + if (this._modules == null) { + this._modules = new ArrayList(); } - if (ModuleUtils.getModule(_modules,DCModule.URI)==null) { - _modules.add(new DCModuleImpl()); + if (ModuleUtils.getModule(this._modules, DCModule.URI) == null) { + this._modules.add(new DCModuleImpl()); } - return _modules; + return this._modules; } - /** * Sets the feed modules. *

- * @param modules the list of ModuleImpl elements with the feed modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the feed modules to + * set, an empty list or null if none. + * */ - public void setModules(List modules) { - _modules = modules; + @Override + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ - public Module getModule(String uri) { - return ModuleUtils.getModule(getModules(),uri); + @Override + public Module getModule(final String uri) { + return ModuleUtils.getModule(getModules(), uri); } /** * Returns the Dublin Core module of the feed. + * * @return the DC module, it's never null - * + * */ private DCModule getDCModule() { return (DCModule) getModule(DCModule.URI); } + @Override public Class getInterface() { return SyndFeed.class; } - public void copyFrom(CopyFrom obj) { - COPY_FROM_HELPER.copy(this,obj); + @Override + public void copyFrom(final CopyFrom obj) { + COPY_FROM_HELPER.copy(this, obj); } - // TODO We need to find out how to refactor this one in a nice reusable way. private static final CopyFromHelper COPY_FROM_HELPER; static { - Map basePropInterfaceMap = new HashMap(); - basePropInterfaceMap.put("feedType",String.class); - basePropInterfaceMap.put("encoding",String.class); - basePropInterfaceMap.put("uri",String.class); - basePropInterfaceMap.put("title",String.class); - basePropInterfaceMap.put("link",String.class); - basePropInterfaceMap.put("description",String.class); - basePropInterfaceMap.put("image",SyndImage.class); - basePropInterfaceMap.put("entries",SyndEntry.class); - basePropInterfaceMap.put("modules",Module.class); + final Map basePropInterfaceMap = new HashMap(); + basePropInterfaceMap.put("feedType", String.class); + basePropInterfaceMap.put("encoding", String.class); + basePropInterfaceMap.put("uri", String.class); + basePropInterfaceMap.put("title", String.class); + basePropInterfaceMap.put("link", String.class); + basePropInterfaceMap.put("description", String.class); + basePropInterfaceMap.put("image", SyndImage.class); + basePropInterfaceMap.put("entries", SyndEntry.class); + basePropInterfaceMap.put("modules", Module.class); - Map basePropClassImplMap = new HashMap(); - basePropClassImplMap.put(SyndEntry.class,SyndEntryImpl.class); - basePropClassImplMap.put(SyndImage.class,SyndImageImpl.class); - basePropClassImplMap.put(DCModule.class,DCModuleImpl.class); - basePropClassImplMap.put(SyModule.class,SyModuleImpl.class); + final Map basePropClassImplMap = new HashMap(); + basePropClassImplMap.put(SyndEntry.class, SyndEntryImpl.class); + basePropClassImplMap.put(SyndImage.class, SyndImageImpl.class); + basePropClassImplMap.put(DCModule.class, DCModuleImpl.class); + basePropClassImplMap.put(SyModule.class, SyModuleImpl.class); - COPY_FROM_HELPER = new CopyFromHelper(SyndFeed.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(SyndFeed.class, basePropInterfaceMap, basePropClassImplMap); } /** * Returns the links *

+ * * @return Returns the links. */ + @Override public List getLinks() { - return (_links==null) ? (_links=new ArrayList()) : _links; + return this._links == null ? (this._links = new ArrayList()) : this._links; } - + /** * Set the links *

+ * * @param links The links to set. */ - public void setLinks(List links) { - _links = links; + @Override + public void setLinks(final List links) { + this._links = links; } + @Override public List getAuthors() { - return (_authors==null) ? (_authors=new ArrayList()) : _authors; + return this._authors == null ? (this._authors = new ArrayList()) : this._authors; } - public void setAuthors(List authors) { + @Override + public void setAuthors(final List authors) { this._authors = authors; } /** * Returns the feed author. *

- * This method is a convenience method, it maps to the Dublin Core module creator. + * This method is a convenience method, it maps to the Dublin Core module + * creator. *

+ * * @return the feed author, null if none. - * + * */ + @Override public String getAuthor() { return getDCModule().getCreator(); } @@ -730,44 +863,54 @@ public class SyndFeedImpl implements Serializable, SyndFeed { /** * Sets the feed author. *

- * This method is a convenience method, it maps to the Dublin Core module creator. + * This method is a convenience method, it maps to the Dublin Core module + * creator. *

+ * * @param author the feed author to set, null if none. - * + * */ - public void setAuthor(String author) { + @Override + public void setAuthor(final String author) { getDCModule().setCreator(author); - } - - public List getContributors() { - return (_contributors==null) ? (_contributors=new ArrayList()) : _contributors; } - public void setContributors(List contributors) { + @Override + public List getContributors() { + return this._contributors == null ? (this._contributors = new ArrayList()) : this._contributors; + } + + @Override + public void setContributors(final List contributors) { this._contributors = contributors; } /** * Returns foreign markup found at channel level. *

+ * * @return Opaque object to discourage use - * + * */ + @Override public List getForeignMarkup() { - return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup; + return this._foreignMarkup == null ? (this._foreignMarkup = new ArrayList()) : this._foreignMarkup; } /** * Sets foreign markup found at channel level. *

+ * * @param foreignMarkup Opaque object to discourage use - * + * */ - public void setForeignMarkup(List foreignMarkup) { - _foreignMarkup = (List)foreignMarkup; + @Override + public void setForeignMarkup(final List foreignMarkup) { + this._foreignMarkup = foreignMarkup; } - public boolean isPreservingWireFeed() { - return preserveWireFeed; - } + @Override + public boolean isPreservingWireFeed() { + return this.preserveWireFeed; + } } diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndImage.java b/src/main/java/com/sun/syndication/feed/synd/SyndImage.java index 423530e..249302b 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndImage.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndImage.java @@ -22,80 +22,91 @@ import com.sun.syndication.feed.CopyFrom; /** * Bean interface for images of SyndFeedImpl feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public interface SyndImage extends Cloneable,CopyFrom { +public interface SyndImage extends Cloneable, CopyFrom { /** * Returns the image title. *

+ * * @return the image title, null if none. - * + * */ String getTitle(); /** * Sets the image title. *

+ * * @param title the image title to set, null if none. - * + * */ void setTitle(String title); /** * Returns the image URL. *

+ * * @return the image URL, null if none. - * + * */ String getUrl(); /** * Sets the image URL. *

+ * * @param url the image URL to set, null if none. - * + * */ void setUrl(String url); /** * Returns the image link. *

+ * * @return the image link, null if none. - * + * */ String getLink(); /** * Sets the image link. *

+ * * @param link the image link to set, null if none. - * + * */ void setLink(String link); /** * Returns the image description. *

+ * * @return the image description, null if none. - * + * */ String getDescription(); /** * Sets the image description. *

+ * * @param description the image description to set, null if none. - * + * */ void setDescription(String description); /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndImageImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndImageImpl.java index 3193c58..7f5c972 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndImageImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndImageImpl.java @@ -16,23 +16,24 @@ */ package com.sun.syndication.feed.synd; -import com.sun.syndication.feed.CopyFrom; -import com.sun.syndication.feed.impl.ObjectBean; -import com.sun.syndication.feed.impl.CopyFromHelper; - +import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.io.Serializable; + +import com.sun.syndication.feed.CopyFrom; +import com.sun.syndication.feed.impl.CopyFromHelper; +import com.sun.syndication.feed.impl.ObjectBean; /** * Bean for images of SyndFeedImpl feeds. *

+ * * @author Alejandro Abdelnur - * + * */ -public class SyndImageImpl implements Serializable,SyndImage { - private ObjectBean _objBean; +public class SyndImageImpl implements Serializable, SyndImage { + private final ObjectBean _objBean; private String _title; private String _url; private String _link; @@ -41,32 +42,38 @@ public class SyndImageImpl implements Serializable,SyndImage { /** * Default constructor. All properties are set to null. *

- * + * */ public SyndImageImpl() { - _objBean = new ObjectBean(SyndImage.class,this); + this._objBean = new ObjectBean(SyndImage.class, this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ + @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ - public boolean equals(Object other) { - return _objBean.equals(other); + @Override + public boolean equals(final Object other) { + return this._objBean.equals(other); } /** @@ -74,123 +81,145 @@ public class SyndImageImpl implements Serializable,SyndImage { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ + @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ + @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the image title. *

+ * * @return the image title, null if none. - * + * */ + @Override public String getTitle() { - return _title; + return this._title; } /** * Sets the image title. *

+ * * @param title the image title to set, null if none. - * + * */ - public void setTitle(String title) { - _title = title; + @Override + public void setTitle(final String title) { + this._title = title; } /** * Returns the image URL. *

+ * * @return the image URL, null if none. - * + * */ + @Override public String getUrl() { - return _url; + return this._url; } /** * Sets the image URL. *

+ * * @param url the image URL to set, null if none. - * + * */ - public void setUrl(String url) { - _url = url; + @Override + public void setUrl(final String url) { + this._url = url; } /** * Returns the image link. *

+ * * @return the image link, null if none. - * + * */ + @Override public String getLink() { - return _link; + return this._link; } /** * Sets the image link. *

+ * * @param link the image link to set, null if none. - * + * */ - public void setLink(String link) { - _link = link; + @Override + public void setLink(final String link) { + this._link = link; } /** * Returns the image description. *

+ * * @return the image description, null if none. - * + * */ + @Override public String getDescription() { - return _description; + return this._description; } /** * Sets the image description. *

+ * * @param description the image description to set, null if none. - * + * */ - public void setDescription(String description) { - _description = description; + @Override + public void setDescription(final String description) { + this._description = description; } + @Override public Class getInterface() { return SyndImage.class; } - public void copyFrom(CopyFrom syndImage) { - COPY_FROM_HELPER.copy(this,syndImage); + @Override + public void copyFrom(final CopyFrom syndImage) { + COPY_FROM_HELPER.copy(this, syndImage); } private static final CopyFromHelper COPY_FROM_HELPER; static { - Map basePropInterfaceMap = new HashMap(); - basePropInterfaceMap.put("title",String.class); - basePropInterfaceMap.put("url",String.class); - basePropInterfaceMap.put("link",String.class); - basePropInterfaceMap.put("description",String.class); + final Map basePropInterfaceMap = new HashMap(); + basePropInterfaceMap.put("title", String.class); + basePropInterfaceMap.put("url", String.class); + basePropInterfaceMap.put("link", String.class); + basePropInterfaceMap.put("description", String.class); - Map basePropClassImplMap = Collections.EMPTY_MAP; + final Map basePropClassImplMap = Collections.EMPTY_MAP; - COPY_FROM_HELPER = new CopyFromHelper(SyndImage.class,basePropInterfaceMap,basePropClassImplMap); + COPY_FROM_HELPER = new CopyFromHelper(SyndImage.class, basePropInterfaceMap, basePropClassImplMap); } } diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndLink.java b/src/main/java/com/sun/syndication/feed/synd/SyndLink.java index f16a3d4..2925c41 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndLink.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndLink.java @@ -19,24 +19,29 @@ package com.sun.syndication.feed.synd; /** * Represents a link or enclosure associated with entry. + * * @author Dave Johnson */ public interface SyndLink { /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public abstract Object clone() throws CloneNotSupportedException; /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override public abstract boolean equals(Object other); @@ -46,8 +51,9 @@ public interface SyndLink { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public abstract int hashCode(); @@ -55,8 +61,9 @@ public interface SyndLink { /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public abstract String toString(); @@ -64,70 +71,79 @@ public interface SyndLink { /** * Returns the link rel. *

+ * * @return the link rel, null if none. - * + * */ public abstract String getRel(); /** * Sets the link rel. *

+ * * @param rel the link rel,, null if none. - * + * */ public abstract void setRel(String rel); /** * Returns the link type. *

+ * * @return the link type, null if none. - * + * */ public abstract String getType(); /** * Sets the link type. *

+ * * @param type the link type, null if none. - * + * */ public abstract void setType(String type); /** * Returns the link href. *

+ * * @return the link href, null if none. - * + * */ public abstract String getHref(); /** * Sets the link href. *

+ * * @param href the link href, null if none. - * + * */ public abstract void setHref(String href); /** * Returns the link title. *

+ * * @return the link title, null if none. - * + * */ public abstract String getTitle(); /** * Sets the link title. *

+ * * @param title the link title, null if none. - * + * */ public abstract void setTitle(String title); /** * Returns the hreflang *

+ * * @return Returns the hreflang. */ public abstract String getHreflang(); @@ -135,6 +151,7 @@ public interface SyndLink { /** * Set the hreflang *

+ * * @param hreflang The hreflang to set. */ public abstract void setHreflang(String hreflang); @@ -142,6 +159,7 @@ public interface SyndLink { /** * Returns the length *

+ * * @return Returns the length. */ public abstract long getLength(); @@ -149,6 +167,7 @@ public interface SyndLink { /** * Set the length *

+ * * @param length The length to set. */ public abstract void setLength(long length); diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndLinkImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndLinkImpl.java index 8ab5e0e..b60a043 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndLinkImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndLinkImpl.java @@ -17,61 +17,66 @@ */ package com.sun.syndication.feed.synd; -import com.sun.syndication.feed.impl.ObjectBean; - import java.io.Serializable; +import com.sun.syndication.feed.impl.ObjectBean; + /** * Represents a link or an enclosure. *

+ * * @author Alejandro Abdelnur * @author Dave Johnson (updated for Atom 1.0) */ -public class SyndLinkImpl implements Cloneable,Serializable, SyndLink { - - private ObjectBean _objBean; - +public class SyndLinkImpl implements Cloneable, Serializable, SyndLink { + + private final ObjectBean _objBean; + private String _href; private String _rel; private String _type; - private String _hreflang; + private String _hreflang; private String _title; - private long _length; + private long _length; /** * Default constructor. All properties are set to null. *

- * + * */ public SyndLinkImpl() { - _objBean = new ObjectBean(this.getClass(),this); + this._objBean = new ObjectBean(this.getClass(), this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof SyndLinkImpl)){ + public boolean equals(final Object other) { + if (!(other instanceof SyndLinkImpl)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -79,139 +84,165 @@ public class SyndLinkImpl implements Cloneable,Serializable, SyndLink { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the link rel. *

+ * * @return the link rel, null if none. - * + * */ + @Override public String getRel() { - return _rel; + return this._rel; } /** * Sets the link rel. *

+ * * @param rel the link rel,, null if none. - * + * */ - public void setRel(String rel) { - //TODO add check, ask P@ about the check - _rel = rel; + @Override + public void setRel(final String rel) { + // TODO add check, ask P@ about the check + this._rel = rel; } /** * Returns the link type. *

+ * * @return the link type, null if none. - * + * */ + @Override public String getType() { - return _type; + return this._type; } /** * Sets the link type. *

+ * * @param type the link type, null if none. - * + * */ - public void setType(String type) { - _type = type; + @Override + public void setType(final String type) { + this._type = type; } /** * Returns the link href. *

+ * * @return the link href, null if none. - * + * */ + @Override public String getHref() { - return _href; + return this._href; } /** * Sets the link href. *

+ * * @param href the link href, null if none. - * + * */ - public void setHref(String href) { - _href = href; + @Override + public void setHref(final String href) { + this._href = href; } /** * Returns the link title. *

+ * * @return the link title, null if none. - * + * */ + @Override public String getTitle() { - return _title; + return this._title; } /** * Sets the link title. *

+ * * @param title the link title, null if none. - * + * */ - public void setTitle(String title) { - _title = title; + @Override + public void setTitle(final String title) { + this._title = title; } /** * Returns the hreflang *

+ * * @return Returns the hreflang. */ + @Override public String getHreflang() { - return _hreflang; + return this._hreflang; } - + /** * Set the hreflang *

+ * * @param hreflang The hreflang to set. */ - public void setHreflang(String hreflang) { - _hreflang = hreflang; + @Override + public void setHreflang(final String hreflang) { + this._hreflang = hreflang; } - + /** * Returns the length *

+ * * @return Returns the length. */ + @Override public long getLength() { - return _length; + return this._length; } - + /** * Set the length *

+ * * @param length The length to set. */ - public void setLength(long length) { - _length = length; + @Override + public void setLength(final long length) { + this._length = length; } } diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndPerson.java b/src/main/java/com/sun/syndication/feed/synd/SyndPerson.java index 8b22b79..349a0a6 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndPerson.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndPerson.java @@ -20,51 +20,53 @@ package com.sun.syndication.feed.synd; import com.sun.syndication.feed.module.Extendable; /** - * Bean interface for authors and contributors of SyndFeedImpl feeds and entries. + * Bean interface for authors and contributors of SyndFeedImpl feeds and + * entries. *

+ * * @author Dave Johnson - * + * */ -public interface SyndPerson extends Cloneable, Extendable -{ +public interface SyndPerson extends Cloneable, Extendable { /** - * Returns name of person + * Returns name of person */ public String getName(); - + /** * Sets name of person. */ public void setName(String name); - + /** * Returns URI of person. */ public String getUri(); - - /** + + /** * Sets URI of person. */ public void setUri(String uri); - - /** + + /** * Returns email of person. */ public String getEmail(); - + /** * Sets email of person. */ public void setEmail(String email); - - + /** * Creates a deep clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ public Object clone() throws CloneNotSupportedException; diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndPersonImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndPersonImpl.java index 19e20bc..072a88e 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndPersonImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndPersonImpl.java @@ -17,60 +17,65 @@ */ package com.sun.syndication.feed.synd; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + import com.sun.syndication.feed.impl.ObjectBean; import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.module.impl.ModuleUtils; -import java.util.List; -import java.util.ArrayList; -import java.io.Serializable; - /** * Bean for authors and contributors of SyndFeedImpl feeds and entries. *

+ * * @author Dave Johnson - * + * */ public class SyndPersonImpl implements Serializable, SyndPerson { - private ObjectBean _objBean; + private final ObjectBean _objBean; private String _name; private String _uri; private String _email; private List _modules; /** - * For implementations extending SyndContentImpl to be able to use the ObjectBean functionality - * with extended interfaces. + * For implementations extending SyndContentImpl to be able to use the + * ObjectBean functionality with extended interfaces. */ public SyndPersonImpl() { - _objBean = new ObjectBean(SyndPerson.class,this); + this._objBean = new ObjectBean(SyndPerson.class, this); } /** * Creates a deep 'bean' clone of the object. *

+ * * @return a clone of the object. - * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. - * + * @throws CloneNotSupportedException thrown if an element of the object + * cannot be cloned. + * */ @Override public Object clone() throws CloneNotSupportedException { - return _objBean.clone(); + return this._objBean.clone(); } /** - * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. + * Indicates whether some other object is "equal to" this one as defined by + * the Object equals() method. *

+ * * @param other he reference object with which to compare. * @return true if 'this' object is equal to the 'other' object. - * + * */ @Override - public boolean equals(Object other) { - if(!(other instanceof SyndPersonImpl)){ + public boolean equals(final Object other) { + if (!(other instanceof SyndPersonImpl)) { return false; } - return _objBean.equals(other); + return this._objBean.equals(other); } /** @@ -78,117 +83,136 @@ public class SyndPersonImpl implements Serializable, SyndPerson { *

* It follows the contract defined by the Object hashCode() method. *

+ * * @return the hashcode of the bean object. - * + * */ @Override public int hashCode() { - return _objBean.hashCode(); + return this._objBean.hashCode(); } /** * Returns the String representation for the object. *

+ * * @return String representation for the object. - * + * */ @Override public String toString() { - return _objBean.toString(); + return this._objBean.toString(); } /** * Returns the person name. *

+ * * @return the person name, null if none. - * + * */ + @Override public String getName() { - return _name; + return this._name; } /** * Sets the category name. *

+ * * @param name the category name to set, null if none. - * + * */ - public void setName(String name) { - _name = name; + @Override + public void setName(final String name) { + this._name = name; } /** * Returns the person's e-mail address. *

+ * * @return the person's e-mail address, null if none. - * + * */ + @Override public String getEmail() { - return _email; + return this._email; } /** * Sets the person's e-mail address. *

+ * * @param email The person's e-mail address to set, null if none. - * + * */ - public void setEmail(String email) { - _email = email; + @Override + public void setEmail(final String email) { + this._email = email; } /** * Returns the person's URI. *

+ * * @return the person's URI, null if none. - * + * */ + @Override public String getUri() { - return _uri; + return this._uri; } /** * Sets the person's URI. *

+ * * @param uri the peron's URI to set, null if none. - * + * */ - public void setUri(String uri) { - _uri = uri; + @Override + public void setUri(final String uri) { + this._uri = uri; } /** * Returns the person modules. *

- * @return a list of ModuleImpl elements with the person modules, - * an empty list if none. + * + * @return a list of ModuleImpl elements with the person modules, an empty + * list if none. */ - public List getModules() - { - if (_modules==null) { - _modules=new ArrayList(); + @Override + public List getModules() { + if (this._modules == null) { + this._modules = new ArrayList(); } - return _modules; + return this._modules; } /** * Sets the person modules. *

- * @param modules the list of ModuleImpl elements with the person modules to set, - * an empty list or null if none. - * + * + * @param modules the list of ModuleImpl elements with the person modules to + * set, an empty list or null if none. + * */ - public void setModules(List modules) { - _modules = modules; + @Override + public void setModules(final List modules) { + this._modules = modules; } /** * Returns the module identified by a given URI. *

+ * * @param uri the URI of the ModuleImpl. * @return The module with the given URI, null if none. */ - public Module getModule(String uri) { - return ModuleUtils.getModule(getModules(),uri); + @Override + public Module getModule(final String uri) { + return ModuleUtils.getModule(getModules(), uri); } } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom03.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom03.java index ff1612a..3c7cf93 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom03.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom03.java @@ -17,6 +17,10 @@ */ package com.sun.syndication.feed.synd.impl; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.atom.Content; import com.sun.syndication.feed.atom.Entry; @@ -24,52 +28,47 @@ import com.sun.syndication.feed.atom.Feed; import com.sun.syndication.feed.atom.Link; import com.sun.syndication.feed.atom.Person; import com.sun.syndication.feed.module.impl.ModuleUtils; -import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.Converter; +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; import com.sun.syndication.feed.synd.SyndEnclosure; import com.sun.syndication.feed.synd.SyndEnclosureImpl; import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndContentImpl; import com.sun.syndication.feed.synd.SyndEntryImpl; -import com.sun.syndication.feed.synd.SyndContent; +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 java.util.ArrayList; -import java.util.List; -import java.util.Date; -import java.util.Iterator; - -import org.jdom2.Element; - /** */ public class ConverterForAtom03 implements Converter { - private String _type; + private final String _type; public ConverterForAtom03() { this("atom_0.3"); } - protected ConverterForAtom03(String type) { - _type = type; + protected ConverterForAtom03(final String type) { + this._type = type; } + @Override public String getType() { - return _type; + return this._type; } - public void copyInto(WireFeed feed,SyndFeed syndFeed) { - Feed aFeed = (Feed) feed; + @Override + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + final Feed aFeed = (Feed) feed; syndFeed.setModules(ModuleUtils.cloneModules(aFeed.getModules())); - if (((List)feed.getForeignMarkup()).size() > 0) { + if (feed.getForeignMarkup().size() > 0) { syndFeed.setForeignMarkup(feed.getForeignMarkup()); } - + syndFeed.setEncoding(aFeed.getEncoding()); syndFeed.setUri(aFeed.getId()); @@ -77,162 +76,154 @@ public class ConverterForAtom03 implements Converter { syndFeed.setTitle(aFeed.getTitle()); // use first alternate links as THE link - if (aFeed.getAlternateLinks() != null - && aFeed.getAlternateLinks().size() > 0) { - Link theLink = (Link)aFeed.getAlternateLinks().get(0); + if (aFeed.getAlternateLinks() != null && aFeed.getAlternateLinks().size() > 0) { + final Link theLink = aFeed.getAlternateLinks().get(0); syndFeed.setLink(theLink.getHrefResolved()); } // lump alternate and other links together - List syndLinks = new ArrayList(); - if (aFeed.getAlternateLinks() != null - && aFeed.getAlternateLinks().size() > 0) { + final List syndLinks = new ArrayList(); + if (aFeed.getAlternateLinks() != null && aFeed.getAlternateLinks().size() > 0) { syndLinks.addAll(createSyndLinks(aFeed.getAlternateLinks())); } - if (aFeed.getOtherLinks() != null - && aFeed.getOtherLinks().size() > 0) { + if (aFeed.getOtherLinks() != null && aFeed.getOtherLinks().size() > 0) { syndLinks.addAll(createSyndLinks(aFeed.getOtherLinks())); } syndFeed.setLinks(syndLinks); - Content tagline = aFeed.getTagline(); - if (tagline!=null) { + final Content tagline = aFeed.getTagline(); + if (tagline != null) { syndFeed.setDescription(tagline.getValue()); } - - List aEntries = aFeed.getEntries(); - if (aEntries!=null) { + final List aEntries = aFeed.getEntries(); + if (aEntries != null) { syndFeed.setEntries(createSyndEntries(aEntries, syndFeed.isPreservingWireFeed())); } // Core Atom language/author/copyright/modified elements have precedence // over DC equivalent info. - String language = aFeed.getLanguage(); - if (language!=null) { + final String language = aFeed.getLanguage(); + if (language != null) { syndFeed.setLanguage(language); } - List authors = aFeed.getAuthors(); - if (authors!=null && authors.size() > 0) { + final List authors = aFeed.getAuthors(); + if (authors != null && authors.size() > 0) { syndFeed.setAuthors(createSyndPersons(authors)); } - String copyright = aFeed.getCopyright(); - if (copyright!=null) { + final String copyright = aFeed.getCopyright(); + if (copyright != null) { syndFeed.setCopyright(copyright); } - Date date = aFeed.getModified(); - if (date!=null) { + final Date date = aFeed.getModified(); + if (date != null) { syndFeed.setPublishedDate(date); } } - protected List createSyndLinks(List aLinks) { - ArrayList sLinks = new ArrayList(); - for (Iterator iter = aLinks.iterator(); iter.hasNext();) { - Link link = (Link)iter.next(); + protected List createSyndLinks(final List aLinks) { + final ArrayList sLinks = new ArrayList(); + for (final Link link2 : aLinks) { + final Link link = link2; if (!link.getRel().equals("enclosure")) { - SyndLink sLink = createSyndLink(link); + final SyndLink sLink = createSyndLink(link); sLinks.add(sLink); } } return sLinks; } - public SyndLink createSyndLink(Link link) { - SyndLink syndLink = new SyndLinkImpl(); - syndLink.setRel( link.getRel()); - syndLink.setType( link.getType()); - syndLink.setHref( link.getHrefResolved()); - syndLink.setTitle( link.getTitle()); + public SyndLink createSyndLink(final Link link) { + final SyndLink syndLink = new SyndLinkImpl(); + syndLink.setRel(link.getRel()); + syndLink.setType(link.getType()); + syndLink.setHref(link.getHrefResolved()); + syndLink.setTitle(link.getTitle()); return syndLink; } - protected List createSyndEntries(List atomEntries, boolean preserveWireItems) { - List syndEntries = new ArrayList(); - for (int i=0;i createSyndEntries(final List atomEntries, final boolean preserveWireItems) { + final List syndEntries = new ArrayList(); + for (int i = 0; i < atomEntries.size(); i++) { + syndEntries.add(createSyndEntry(atomEntries.get(i), preserveWireItems)); } return syndEntries; } - protected SyndEntry createSyndEntry(Entry entry, boolean preserveWireItem) { - SyndEntryImpl syndEntry = new SyndEntryImpl(); + protected SyndEntry createSyndEntry(final Entry entry, final boolean preserveWireItem) { + final SyndEntryImpl syndEntry = new SyndEntryImpl(); if (preserveWireItem) { - syndEntry.setWireEntry(entry); + syndEntry.setWireEntry(entry); } - + syndEntry.setModules(ModuleUtils.cloneModules(entry.getModules())); - if (((List)entry.getForeignMarkup()).size() > 0) { - syndEntry.setForeignMarkup((List)entry.getForeignMarkup()); + if (entry.getForeignMarkup().size() > 0) { + syndEntry.setForeignMarkup(entry.getForeignMarkup()); } syndEntry.setTitle(entry.getTitle()); // if there is exactly one alternate link, use that as THE link - if (entry.getAlternateLinks() != null - && entry.getAlternateLinks().size() == 1) { - Link theLink = (Link)entry.getAlternateLinks().get(0); + if (entry.getAlternateLinks() != null && entry.getAlternateLinks().size() == 1) { + final Link theLink = entry.getAlternateLinks().get(0); syndEntry.setLink(theLink.getHrefResolved()); } // Create synd enclosures from enclosure links - List syndEnclosures = new ArrayList(); + final List syndEnclosures = new ArrayList(); if (entry.getOtherLinks() != null && entry.getOtherLinks().size() > 0) { - List oLinks = entry.getOtherLinks(); - for (Iterator iter = oLinks.iterator(); iter.hasNext(); ) { - Link thisLink = (Link)iter.next(); - if ("enclosure".equals(thisLink.getRel())) + final List oLinks = entry.getOtherLinks(); + for (final Link link : oLinks) { + final Link thisLink = link; + if ("enclosure".equals(thisLink.getRel())) { syndEnclosures.add(createSyndEnclosure(entry, thisLink)); + } } } syndEntry.setEnclosures(syndEnclosures); // lump alternate and other links together - List syndLinks = new ArrayList(); - if (entry.getAlternateLinks() != null - && entry.getAlternateLinks().size() > 0) { + final List syndLinks = new ArrayList(); + if (entry.getAlternateLinks() != null && entry.getAlternateLinks().size() > 0) { syndLinks.addAll(createSyndLinks(entry.getAlternateLinks())); } - if (entry.getOtherLinks() != null - && entry.getOtherLinks().size() > 0) { + if (entry.getOtherLinks() != null && entry.getOtherLinks().size() > 0) { syndLinks.addAll(createSyndLinks(entry.getOtherLinks())); } syndEntry.setLinks(syndLinks); - - String id = entry.getId(); - if (id!=null) { + final String id = entry.getId(); + if (id != null) { syndEntry.setUri(entry.getId()); - } - else { + } else { syndEntry.setUri(syndEntry.getLink()); } Content content = entry.getSummary(); - if (content==null) { - List contents = entry.getContents(); - if (contents!=null && contents.size()>0) { - content = (Content) contents.get(0); + if (content == null) { + final List contents = entry.getContents(); + if (contents != null && contents.size() > 0) { + content = contents.get(0); } } - if (content!=null) { - SyndContent sContent = new SyndContentImpl(); + if (content != null) { + final SyndContent sContent = new SyndContentImpl(); sContent.setType(content.getType()); sContent.setValue(content.getValue()); syndEntry.setDescription(sContent); } - List contents = entry.getContents(); - if (contents.size()>0) { - List sContents = new ArrayList(); - for (int i=0;i contents = entry.getContents(); + if (contents.size() > 0) { + final List sContents = new ArrayList(); + for (int i = 0; i < contents.size(); i++) { + content = contents.get(i); + final SyndContent sContent = new SyndContentImpl(); sContent.setType(content.getType()); sContent.setValue(content.getValue()); sContent.setMode(content.getMode()); @@ -241,46 +232,47 @@ public class ConverterForAtom03 implements Converter { syndEntry.setContents(sContents); } - List authors = entry.getAuthors(); - if (authors!=null && authors.size() > 0) { + final List authors = entry.getAuthors(); + if (authors != null && authors.size() > 0) { syndEntry.setAuthors(createSyndPersons(authors)); - SyndPerson person0 = (SyndPerson)syndEntry.getAuthors().get(0); + final SyndPerson person0 = syndEntry.getAuthors().get(0); syndEntry.setAuthor(person0.getName()); } Date date = entry.getModified(); - if (date==null) { + if (date == null) { date = entry.getIssued(); - if (date==null) { + if (date == null) { date = entry.getCreated(); } } - if (date!=null) { + if (date != null) { syndEntry.setPublishedDate(date); } return syndEntry; } - public SyndEnclosure createSyndEnclosure(Entry entry, Link link) { - SyndEnclosure syndEncl = new SyndEnclosureImpl(); + public SyndEnclosure createSyndEnclosure(final Entry entry, final Link link) { + final SyndEnclosure syndEncl = new SyndEnclosureImpl(); syndEncl.setUrl(link.getHrefResolved()); syndEncl.setType(link.getType()); syndEncl.setLength(link.getLength()); return syndEncl; } - public WireFeed createRealFeed(SyndFeed syndFeed) { - Feed aFeed = new Feed(getType()); + @Override + public WireFeed createRealFeed(final SyndFeed syndFeed) { + final Feed aFeed = new Feed(getType()); aFeed.setModules(ModuleUtils.cloneModules(syndFeed.getModules())); aFeed.setEncoding(syndFeed.getEncoding()); aFeed.setId(syndFeed.getUri()); - SyndContent sTitle = syndFeed.getTitleEx(); + final SyndContent sTitle = syndFeed.getTitleEx(); if (sTitle != null) { - Content title = new Content(); + final Content title = new Content(); if (sTitle.getType() != null) { title.setType(sTitle.getType()); } @@ -294,16 +286,14 @@ public class ConverterForAtom03 implements Converter { } // separate SyndEntry's links collection into alternate and other links - List alternateLinks = new ArrayList(); - List otherLinks = new ArrayList(); - List slinks = syndFeed.getLinks(); + final List alternateLinks = new ArrayList(); + final List otherLinks = new ArrayList(); + final List slinks = syndFeed.getLinks(); if (slinks != null) { - for (Iterator iter=slinks.iterator(); iter.hasNext();) { - SyndLink syndLink = (SyndLink)iter.next(); - Link link = createAtomLink(syndLink); - if (link.getRel() == null || - "".equals(link.getRel().trim()) || - "alternate".equals(link.getRel())) { + for (final SyndLink syndLink2 : slinks) { + final SyndLink syndLink = syndLink2; + final Link link = createAtomLink(syndLink); + if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) { alternateLinks.add(link); } else { otherLinks.add(link); @@ -312,26 +302,30 @@ public class ConverterForAtom03 implements Converter { } // no alternate link? then use THE link if there is one if (alternateLinks.isEmpty() && syndFeed.getLink() != null) { - Link link = new Link(); + final Link link = new Link(); link.setRel("alternate"); link.setHref(syndFeed.getLink()); alternateLinks.add(link); } - if (alternateLinks.size() > 0) aFeed.setAlternateLinks(alternateLinks); - if (otherLinks.size() > 0) aFeed.setOtherLinks(otherLinks); + if (alternateLinks.size() > 0) { + aFeed.setAlternateLinks(alternateLinks); + } + if (otherLinks.size() > 0) { + aFeed.setOtherLinks(otherLinks); + } - String sDesc = syndFeed.getDescription(); - if (sDesc!=null) { - Content tagline = new Content(); + final String sDesc = syndFeed.getDescription(); + if (sDesc != null) { + final Content tagline = new Content(); tagline.setValue(sDesc); aFeed.setTagline(tagline); } aFeed.setLanguage(syndFeed.getLanguage()); - List authors = syndFeed.getAuthors(); - if (authors!=null && authors.size() > 0) { + final List authors = syndFeed.getAuthors(); + if (authors != null && authors.size() > 0) { aFeed.setAuthors(createAtomPersons(authors)); } @@ -339,19 +333,19 @@ public class ConverterForAtom03 implements Converter { aFeed.setModified(syndFeed.getPublishedDate()); - List sEntries = syndFeed.getEntries(); - if (sEntries!=null) { + final List sEntries = syndFeed.getEntries(); + if (sEntries != null) { aFeed.setEntries(createAtomEntries(sEntries)); } return aFeed; } - protected static List createAtomPersons(List sPersons) { - List persons = new ArrayList(); - for (Iterator iter = sPersons.iterator(); iter.hasNext(); ) { - SyndPerson sPerson = (SyndPerson)iter.next(); - Person person = new Person(); + protected static List createAtomPersons(final List sPersons) { + final List persons = new ArrayList(); + for (final SyndPerson syndPerson : sPersons) { + final SyndPerson sPerson = syndPerson; + final Person person = new Person(); person.setName(sPerson.getName()); person.setUri(sPerson.getUri()); person.setEmail(sPerson.getEmail()); @@ -360,12 +354,12 @@ public class ConverterForAtom03 implements Converter { } return persons; } - - protected static List createSyndPersons(List aPersons) { - List persons = new ArrayList(); - for (Iterator iter = aPersons.iterator(); iter.hasNext(); ) { - Person aPerson = (Person)iter.next(); - SyndPerson person = new SyndPersonImpl(); + + protected static List createSyndPersons(final List aPersons) { + final List persons = new ArrayList(); + for (final Person person2 : aPersons) { + final Person aPerson = person2; + final SyndPerson person = new SyndPersonImpl(); person.setName(aPerson.getName()); person.setUri(aPerson.getUri()); person.setEmail(aPerson.getEmail()); @@ -374,24 +368,24 @@ public class ConverterForAtom03 implements Converter { } return persons; } - - protected List createAtomEntries(List syndEntries) { - List atomEntries = new ArrayList(); - for (int i=0;i createAtomEntries(final List syndEntries) { + final List atomEntries = new ArrayList(); + for (int i = 0; i < syndEntries.size(); i++) { + atomEntries.add(createAtomEntry(syndEntries.get(i))); } return atomEntries; } - protected Entry createAtomEntry(SyndEntry sEntry) { - Entry aEntry = new Entry(); + protected Entry createAtomEntry(final SyndEntry sEntry) { + final Entry aEntry = new Entry(); aEntry.setModules(ModuleUtils.cloneModules(sEntry.getModules())); aEntry.setId(sEntry.getUri()); - SyndContent sTitle = sEntry.getTitleEx(); - if (sTitle!=null) { - Content title = new Content(); + final SyndContent sTitle = sEntry.getTitleEx(); + if (sTitle != null) { + final Content title = new Content(); if (sTitle.getType() != null) { title.setType(sTitle.getType()); } @@ -405,16 +399,14 @@ public class ConverterForAtom03 implements Converter { } // separate SyndEntry's links collection into alternate and other links - List alternateLinks = new ArrayList(); - List otherLinks = new ArrayList(); - List slinks = sEntry.getLinks(); + final List alternateLinks = new ArrayList(); + final List otherLinks = new ArrayList(); + final List slinks = sEntry.getLinks(); if (slinks != null) { - for (Iterator iter=slinks.iterator(); iter.hasNext();) { - SyndLink syndLink = (SyndLink)iter.next(); - Link link = createAtomLink(syndLink); - if (link.getRel() == null || - "".equals(link.getRel().trim()) || - "alternate".equals(link.getRel())) { + for (final SyndLink syndLink2 : slinks) { + final SyndLink syndLink = syndLink2; + final Link link = createAtomLink(syndLink); + if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) { alternateLinks.add(link); } else { otherLinks.add(link); @@ -423,40 +415,43 @@ public class ConverterForAtom03 implements Converter { } // no alternate link? then use THE link if there is one if (alternateLinks.isEmpty() && sEntry.getLink() != null) { - Link link = new Link(); + final Link link = new Link(); link.setRel("alternate"); link.setHref(sEntry.getLink()); alternateLinks.add(link); } - List sEnclosures = sEntry.getEnclosures(); + final List sEnclosures = sEntry.getEnclosures(); if (sEnclosures != null) { - for (Iterator iter=sEnclosures.iterator(); iter.hasNext();) { - SyndEnclosure syndEnclosure = (SyndEnclosure) iter.next(); - Link link = createAtomEnclosure(syndEnclosure); + for (final SyndEnclosure syndEnclosure2 : sEnclosures) { + final SyndEnclosure syndEnclosure = syndEnclosure2; + final Link link = createAtomEnclosure(syndEnclosure); otherLinks.add(link); } } - if (alternateLinks.size() > 0) aEntry.setAlternateLinks(alternateLinks); - if (otherLinks.size() > 0) aEntry.setOtherLinks(otherLinks); - + if (alternateLinks.size() > 0) { + aEntry.setAlternateLinks(alternateLinks); + } + if (otherLinks.size() > 0) { + aEntry.setOtherLinks(otherLinks); + } SyndContent sContent = sEntry.getDescription(); - if (sContent!=null) { - Content content = new Content(); + if (sContent != null) { + final Content content = new Content(); content.setType(sContent.getType()); content.setValue(sContent.getValue()); content.setMode(Content.ESCAPED); aEntry.setSummary(content); } - List contents = sEntry.getContents(); - if (contents.size()>0) { - List aContents = new ArrayList(); - for (int i=0;i contents = sEntry.getContents(); + if (contents.size() > 0) { + final List aContents = new ArrayList(); + for (int i = 0; i < contents.size(); i++) { + sContent = contents.get(i); + final Content content = new Content(); content.setType(sContent.getType()); content.setValue(sContent.getValue()); content.setMode(sContent.getMode()); @@ -466,13 +461,13 @@ public class ConverterForAtom03 implements Converter { aEntry.setContents(aContents); } - List sAuthors = sEntry.getAuthors(); - if (sAuthors!=null && sAuthors.size() > 0) { + final List sAuthors = sEntry.getAuthors(); + if (sAuthors != null && sAuthors.size() > 0) { aEntry.setAuthors(createAtomPersons(sAuthors)); } else if (sEntry.getAuthor() != null) { - Person person = new Person(); - person.setName(sEntry.getAuthor()); - List authors = new ArrayList(); + final Person person = new Person(); + person.setName(sEntry.getAuthor()); + final List authors = new ArrayList(); authors.add(person); aEntry.setAuthors(authors); } @@ -483,22 +478,22 @@ public class ConverterForAtom03 implements Converter { return aEntry; } - public Link createAtomLink(SyndLink syndLink) { - Link link = new Link(); - link.setRel( syndLink.getRel()); - link.setType( syndLink.getType()); - link.setHref( syndLink.getHref()); - link.setTitle( syndLink.getTitle()); + public Link createAtomLink(final SyndLink syndLink) { + final Link link = new Link(); + link.setRel(syndLink.getRel()); + link.setType(syndLink.getType()); + link.setHref(syndLink.getHref()); + link.setTitle(syndLink.getTitle()); return link; } - public Link createAtomEnclosure(SyndEnclosure syndEnclosure) { - Link link = new Link(); - link.setRel( "enclosure"); - link.setType( syndEnclosure.getType()); - link.setHref( syndEnclosure.getUrl()); - link.setLength( syndEnclosure.getLength()); - return link; + public Link createAtomEnclosure(final SyndEnclosure syndEnclosure) { + final Link link = new Link(); + link.setRel("enclosure"); + link.setType(syndEnclosure.getType()); + link.setHref(syndEnclosure.getUrl()); + link.setLength(syndEnclosure.getLength()); + return link; } } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom10.java index 751ceb4..1ee4e48 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForAtom10.java @@ -18,11 +18,8 @@ package com.sun.syndication.feed.synd.impl; import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; import java.util.List; -import org.jdom2.Element; - import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.atom.Category; import com.sun.syndication.feed.atom.Content; @@ -36,6 +33,8 @@ 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.SyndEnclosure; +import com.sun.syndication.feed.synd.SyndEnclosureImpl; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndEntryImpl; import com.sun.syndication.feed.synd.SyndFeed; @@ -43,316 +42,306 @@ import com.sun.syndication.feed.synd.SyndFeedImpl; 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.SyndEnclosure; -import com.sun.syndication.feed.synd.SyndEnclosureImpl; - /** */ public class ConverterForAtom10 implements Converter { - private String _type; + private final String _type; public ConverterForAtom10() { this("atom_1.0"); } - protected ConverterForAtom10(String type) { - _type = type; + protected ConverterForAtom10(final String type) { + this._type = type; } + @Override public String getType() { - return _type; + return this._type; } - public void copyInto(WireFeed feed, SyndFeed syndFeed) { - Feed aFeed = (Feed) feed; + @Override + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + final Feed aFeed = (Feed) feed; syndFeed.setModules(ModuleUtils.cloneModules(aFeed.getModules())); - - if (((List)feed.getForeignMarkup()).size() > 0) { - syndFeed.setForeignMarkup((List)feed.getForeignMarkup()); + + if (feed.getForeignMarkup().size() > 0) { + syndFeed.setForeignMarkup(feed.getForeignMarkup()); } syndFeed.setEncoding(aFeed.getEncoding()); syndFeed.setUri(aFeed.getId()); - Content aTitle = aFeed.getTitleEx(); + final Content aTitle = aFeed.getTitleEx(); if (aTitle != null) { - SyndContent c = new SyndContentImpl(); + final SyndContent c = new SyndContentImpl(); c.setType(aTitle.getType()); c.setValue(aTitle.getValue()); syndFeed.setTitleEx(c); } - Content aSubtitle = aFeed.getSubtitle(); - if (aSubtitle!=null) { - SyndContent c = new SyndContentImpl(); + final Content aSubtitle = aFeed.getSubtitle(); + if (aSubtitle != null) { + final SyndContent c = new SyndContentImpl(); c.setType(aSubtitle.getType()); c.setValue(aSubtitle.getValue()); syndFeed.setDescriptionEx(c); } // use first alternate links as THE link - if (aFeed.getAlternateLinks() != null - && aFeed.getAlternateLinks().size() > 0) { - Link theLink = (Link)aFeed.getAlternateLinks().get(0); + if (aFeed.getAlternateLinks() != null && aFeed.getAlternateLinks().size() > 0) { + final Link theLink = aFeed.getAlternateLinks().get(0); syndFeed.setLink(theLink.getHrefResolved()); } // lump alternate and other links together - List syndLinks = new ArrayList(); - if (aFeed.getAlternateLinks() != null - && aFeed.getAlternateLinks().size() > 0) { + final List syndLinks = new ArrayList(); + if (aFeed.getAlternateLinks() != null && aFeed.getAlternateLinks().size() > 0) { syndLinks.addAll(createSyndLinks(aFeed.getAlternateLinks())); } - if (aFeed.getOtherLinks() != null - && aFeed.getOtherLinks().size() > 0) { + if (aFeed.getOtherLinks() != null && aFeed.getOtherLinks().size() > 0) { syndLinks.addAll(createSyndLinks(aFeed.getOtherLinks())); } syndFeed.setLinks(syndLinks); - - List aEntries = aFeed.getEntries(); - if (aEntries!=null) { + + final List aEntries = aFeed.getEntries(); + if (aEntries != null) { syndFeed.setEntries(createSyndEntries(aFeed, aEntries, syndFeed.isPreservingWireFeed())); } // Core Atom language/author/copyright/modified elements have precedence // over DC equivalent info. - List authors = aFeed.getAuthors(); - if (authors!=null && authors.size() > 0) { + final List authors = aFeed.getAuthors(); + if (authors != null && authors.size() > 0) { syndFeed.setAuthors(ConverterForAtom03.createSyndPersons(authors)); } - List contributors = aFeed.getContributors(); - if (contributors!=null && contributors.size() > 0) { + final List contributors = aFeed.getContributors(); + if (contributors != null && contributors.size() > 0) { syndFeed.setContributors(ConverterForAtom03.createSyndPersons(contributors)); } - String rights = aFeed.getRights(); - if (rights!=null) { + final String rights = aFeed.getRights(); + if (rights != null) { syndFeed.setCopyright(rights); } - Date date = aFeed.getUpdated(); - if (date!=null) { + final Date date = aFeed.getUpdated(); + if (date != null) { syndFeed.setPublishedDate(date); } - + } - protected List createSyndLinks(List aLinks) { - ArrayList sLinks = new ArrayList(); - for (Iterator iter = aLinks.iterator(); iter.hasNext();) { - Link link = (Link)iter.next(); - SyndLink sLink = createSyndLink(link); + protected List createSyndLinks(final List aLinks) { + final ArrayList sLinks = new ArrayList(); + for (final Link link2 : aLinks) { + final Link link = link2; + final SyndLink sLink = createSyndLink(link); sLinks.add(sLink); } return sLinks; } - - protected List createSyndEntries(Feed feed, List atomEntries, boolean preserveWireItems) { - List syndEntries = new ArrayList(); - for (int i=0;i createSyndEntries(final Feed feed, final List atomEntries, final boolean preserveWireItems) { + final List syndEntries = new ArrayList(); + for (int i = 0; i < atomEntries.size(); i++) { + syndEntries.add(createSyndEntry(feed, atomEntries.get(i), preserveWireItems)); } return syndEntries; } - protected SyndEntry createSyndEntry(Feed feed, Entry entry, boolean preserveWireItem) { - SyndEntryImpl syndEntry = new SyndEntryImpl(); - if (preserveWireItem) { - syndEntry.setWireEntry(entry); - } + protected SyndEntry createSyndEntry(final Feed feed, final Entry entry, final boolean preserveWireItem) { + final SyndEntryImpl syndEntry = new SyndEntryImpl(); + if (preserveWireItem) { + syndEntry.setWireEntry(entry); + } syndEntry.setModules(ModuleUtils.cloneModules(entry.getModules())); - - if (((List)entry.getForeignMarkup()).size() > 0) { - syndEntry.setForeignMarkup((List)entry.getForeignMarkup()); + + if (entry.getForeignMarkup().size() > 0) { + syndEntry.setForeignMarkup(entry.getForeignMarkup()); } - Content eTitle = entry.getTitleEx(); + final Content eTitle = entry.getTitleEx(); if (eTitle != null) { syndEntry.setTitleEx(createSyndContent(eTitle)); } - - Content summary = entry.getSummary(); - if (summary!=null) { + + final Content summary = entry.getSummary(); + if (summary != null) { syndEntry.setDescription(createSyndContent(summary)); } - List contents = entry.getContents(); + final List contents = entry.getContents(); if (contents != null && contents.size() > 0) { - List sContents = new ArrayList(); - for (Iterator iter=contents.iterator(); iter.hasNext();) { - Content content = (Content)iter.next(); + final List sContents = new ArrayList(); + for (final Content content2 : contents) { + final Content content = content2; sContents.add(createSyndContent(content)); } syndEntry.setContents(sContents); } - List authors = entry.getAuthors(); - if (authors!=null && authors.size() > 0) { + final List authors = entry.getAuthors(); + if (authors != null && authors.size() > 0) { syndEntry.setAuthors(ConverterForAtom03.createSyndPersons(authors)); - SyndPerson person0 = (SyndPerson)syndEntry.getAuthors().get(0); + final SyndPerson person0 = syndEntry.getAuthors().get(0); syndEntry.setAuthor(person0.getName()); } - List contributors = entry.getContributors(); - if (contributors!=null && contributors.size() > 0) { + final List contributors = entry.getContributors(); + if (contributors != null && contributors.size() > 0) { syndEntry.setContributors(ConverterForAtom03.createSyndPersons(contributors)); } Date date = entry.getPublished(); - if (date!=null) { + if (date != null) { syndEntry.setPublishedDate(date); } date = entry.getUpdated(); - if (date!=null) { + if (date != null) { syndEntry.setUpdatedDate(date); } - - List categories = entry.getCategories(); - if (categories!=null) { - List syndCategories = new ArrayList(); - for (Iterator iter=categories.iterator(); iter.hasNext();) { - Category c = (Category)iter.next(); - SyndCategory syndCategory = new SyndCategoryImpl(); - syndCategory.setName(c.getTerm()); + + final List categories = entry.getCategories(); + if (categories != null) { + final List syndCategories = new ArrayList(); + for (final Category category : categories) { + final Category c = category; + final SyndCategory syndCategory = new SyndCategoryImpl(); + syndCategory.setName(c.getTerm()); syndCategory.setTaxonomyUri(c.getSchemeResolved()); - // TODO: categories MAY have labels - // syndCategory.setLabel(c.getLabel()); + // TODO: categories MAY have labels + // syndCategory.setLabel(c.getLabel()); syndCategories.add(syndCategory); } syndEntry.setCategories(syndCategories); } - + // use first alternate link as THE link - if (entry.getAlternateLinks() != null - && entry.getAlternateLinks().size() > 0) { - Link theLink = (Link)entry.getAlternateLinks().get(0); + if (entry.getAlternateLinks() != null && entry.getAlternateLinks().size() > 0) { + final Link theLink = entry.getAlternateLinks().get(0); syndEntry.setLink(theLink.getHrefResolved()); } // Create synd enclosures from enclosure links - List syndEnclosures = new ArrayList(); + final List syndEnclosures = new ArrayList(); if (entry.getOtherLinks() != null && entry.getOtherLinks().size() > 0) { - List oLinks = entry.getOtherLinks(); - for (Iterator iter = oLinks.iterator(); iter.hasNext(); ) { - Link thisLink = (Link)iter.next(); - if ("enclosure".equals(thisLink.getRel())) - syndEnclosures.add( - createSyndEnclosure(feed, entry, thisLink)); + final List oLinks = entry.getOtherLinks(); + for (final Link link : oLinks) { + final Link thisLink = link; + if ("enclosure".equals(thisLink.getRel())) { + syndEnclosures.add(createSyndEnclosure(feed, entry, thisLink)); + } } } syndEntry.setEnclosures(syndEnclosures); // lump alternate and other links together - List syndLinks = new ArrayList(); - if (entry.getAlternateLinks() != null - && entry.getAlternateLinks().size() > 0) { + final List syndLinks = new ArrayList(); + if (entry.getAlternateLinks() != null && entry.getAlternateLinks().size() > 0) { syndLinks.addAll(createSyndLinks(entry.getAlternateLinks())); } - if (entry.getOtherLinks() != null - && entry.getOtherLinks().size() > 0) { + if (entry.getOtherLinks() != null && entry.getOtherLinks().size() > 0) { syndLinks.addAll(createSyndLinks(entry.getOtherLinks())); } syndEntry.setLinks(syndLinks); - String id = entry.getId(); - if (id!=null) { + final String id = entry.getId(); + if (id != null) { syndEntry.setUri(entry.getId()); - } - else { + } else { syndEntry.setUri(syndEntry.getLink()); } // Convert source element Feed into SyndFeed and assign as SyndEntry // source - Feed source = entry.getSource(); + final Feed source = entry.getSource(); if (source != null) { - SyndFeed syndSource = new SyndFeedImpl(source); - syndEntry.setSource(syndSource); + final SyndFeed syndSource = new SyndFeedImpl(source); + syndEntry.setSource(syndSource); } return syndEntry; } - public SyndEnclosure createSyndEnclosure(Feed feed, Entry entry, - Link link) { - SyndEnclosure syndEncl = new SyndEnclosureImpl(); + public SyndEnclosure createSyndEnclosure(final Feed feed, final Entry entry, final Link link) { + final SyndEnclosure syndEncl = new SyndEnclosureImpl(); syndEncl.setUrl(link.getHrefResolved()); syndEncl.setType(link.getType()); syndEncl.setLength(link.getLength()); return syndEncl; } - - public Link createAtomEnclosure(SyndEnclosure syndEnclosure) { - Link link = new Link(); - link.setRel( "enclosure"); - link.setType( syndEnclosure.getType()); - link.setHref( syndEnclosure.getUrl()); - link.setLength( syndEnclosure.getLength()); - return link; - } - public SyndLink createSyndLink(Link link) { - SyndLink syndLink = new SyndLinkImpl(); - syndLink.setRel( link.getRel()); - syndLink.setType( link.getType()); - syndLink.setHref( link.getHrefResolved()); - syndLink.setHreflang(link.getHreflang()); - syndLink.setLength( link.getLength()); - syndLink.setTitle( link.getTitle()); - return syndLink; - } - - public Link createAtomLink(SyndLink syndLink) { - Link link = new Link(); - link.setRel( syndLink.getRel()); - link.setType( syndLink.getType()); - link.setHref( syndLink.getHref()); - link.setHreflang(syndLink.getHreflang()); - link.setLength( syndLink.getLength()); - link.setTitle( syndLink.getTitle()); + public Link createAtomEnclosure(final SyndEnclosure syndEnclosure) { + final Link link = new Link(); + link.setRel("enclosure"); + link.setType(syndEnclosure.getType()); + link.setHref(syndEnclosure.getUrl()); + link.setLength(syndEnclosure.getLength()); return link; } - - public WireFeed createRealFeed(SyndFeed syndFeed) { - Feed aFeed = new Feed(getType()); + + public SyndLink createSyndLink(final Link link) { + final SyndLink syndLink = new SyndLinkImpl(); + syndLink.setRel(link.getRel()); + syndLink.setType(link.getType()); + syndLink.setHref(link.getHrefResolved()); + syndLink.setHreflang(link.getHreflang()); + syndLink.setLength(link.getLength()); + syndLink.setTitle(link.getTitle()); + return syndLink; + } + + public Link createAtomLink(final SyndLink syndLink) { + final Link link = new Link(); + link.setRel(syndLink.getRel()); + link.setType(syndLink.getType()); + link.setHref(syndLink.getHref()); + link.setHreflang(syndLink.getHreflang()); + link.setLength(syndLink.getLength()); + link.setTitle(syndLink.getTitle()); + return link; + } + + @Override + public WireFeed createRealFeed(final SyndFeed syndFeed) { + final Feed aFeed = new Feed(getType()); aFeed.setModules(ModuleUtils.cloneModules(syndFeed.getModules())); aFeed.setEncoding(syndFeed.getEncoding()); aFeed.setId(syndFeed.getUri()); - SyndContent sTitle = syndFeed.getTitleEx(); + final SyndContent sTitle = syndFeed.getTitleEx(); if (sTitle != null) { - Content title = new Content(); + final Content title = new Content(); title.setType(sTitle.getType()); title.setValue(sTitle.getValue()); aFeed.setTitleEx(title); } - - SyndContent sDesc = syndFeed.getDescriptionEx(); + + final SyndContent sDesc = syndFeed.getDescriptionEx(); if (sDesc != null) { - Content subtitle = new Content(); + final Content subtitle = new Content(); subtitle.setType(sDesc.getType()); subtitle.setValue(sDesc.getValue()); aFeed.setSubtitle(subtitle); } // separate SyndEntry's links collection into alternate and other links - List alternateLinks = new ArrayList(); - List otherLinks = new ArrayList(); - List slinks = syndFeed.getLinks(); + final List alternateLinks = new ArrayList(); + final List otherLinks = new ArrayList(); + final List slinks = syndFeed.getLinks(); if (slinks != null) { - for (Iterator iter=slinks.iterator(); iter.hasNext();) { - SyndLink syndLink = (SyndLink)iter.next(); - Link link = createAtomLink(syndLink); - if (link.getRel() == null || - "".equals(link.getRel().trim()) || - "alternate".equals(link.getRel())) { + for (final SyndLink syndLink2 : slinks) { + final SyndLink syndLink = syndLink2; + final Link link = createAtomLink(syndLink); + if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) { alternateLinks.add(link); } else { otherLinks.add(link); @@ -361,35 +350,41 @@ public class ConverterForAtom10 implements Converter { } // no alternate link? then use THE link if there is one if (alternateLinks.isEmpty() && syndFeed.getLink() != null) { - Link link = new Link(); + final Link link = new Link(); link.setRel("alternate"); link.setHref(syndFeed.getLink()); alternateLinks.add(link); } - if (alternateLinks.size() > 0) aFeed.setAlternateLinks(alternateLinks); - if (otherLinks.size() > 0) aFeed.setOtherLinks(otherLinks); - - List sCats = syndFeed.getCategories(); - List aCats = new ArrayList(); + if (alternateLinks.size() > 0) { + aFeed.setAlternateLinks(alternateLinks); + } + if (otherLinks.size() > 0) { + aFeed.setOtherLinks(otherLinks); + } + + final List sCats = syndFeed.getCategories(); + final List aCats = new ArrayList(); if (sCats != null) { - for (Iterator iter=sCats.iterator(); iter.hasNext();) { - SyndCategory sCat = (SyndCategory)iter.next(); - Category aCat = new Category(); + for (final SyndCategory syndCategory : sCats) { + final SyndCategory sCat = syndCategory; + final Category aCat = new Category(); aCat.setTerm(sCat.getName()); // TODO: aCat.setLabel(sCat.getLabel()); aCat.setScheme(sCat.getTaxonomyUri()); aCats.add(aCat); } } - if (aCats.size() > 0) aFeed.setCategories(aCats); + if (aCats.size() > 0) { + aFeed.setCategories(aCats); + } - List authors = syndFeed.getAuthors(); - if (authors!=null && authors.size() > 0) { + final List authors = syndFeed.getAuthors(); + if (authors != null && authors.size() > 0) { aFeed.setAuthors(ConverterForAtom03.createAtomPersons(authors)); } - List contributors = syndFeed.getContributors(); - if (contributors!=null && contributors.size() > 0) { + final List contributors = syndFeed.getContributors(); + if (contributors != null && contributors.size() > 0) { aFeed.setContributors(ConverterForAtom03.createAtomPersons(contributors)); } @@ -397,89 +392,86 @@ public class ConverterForAtom10 implements Converter { aFeed.setUpdated(syndFeed.getPublishedDate()); - List sEntries = syndFeed.getEntries(); - if (sEntries!=null) { + final List sEntries = syndFeed.getEntries(); + if (sEntries != null) { aFeed.setEntries(createAtomEntries(sEntries)); } - if (((List)syndFeed.getForeignMarkup()).size() > 0) { + if (syndFeed.getForeignMarkup().size() > 0) { aFeed.setForeignMarkup(syndFeed.getForeignMarkup()); } return aFeed; } - protected SyndContent createSyndContent(Content content) { - SyndContent sContent = new SyndContentImpl(); + protected SyndContent createSyndContent(final Content content) { + final SyndContent sContent = new SyndContentImpl(); sContent.setType(content.getType()); sContent.setValue(content.getValue()); return sContent; } - protected List createAtomEntries(List syndEntries) { - List atomEntries = new ArrayList(); - for (int i=0;i createAtomEntries(final List syndEntries) { + final List atomEntries = new ArrayList(); + for (int i = 0; i < syndEntries.size(); i++) { + atomEntries.add(createAtomEntry(syndEntries.get(i))); } return atomEntries; } - protected Content createAtomContent(SyndContent sContent) { - Content content = new Content(); + protected Content createAtomContent(final SyndContent sContent) { + final Content content = new Content(); content.setType(sContent.getType()); content.setValue(sContent.getValue()); return content; } - protected List createAtomContents(List syndContents) { - List atomContents = new ArrayList(); - for (int i=0;i createAtomContents(final List syndContents) { + final List atomContents = new ArrayList(); + for (int i = 0; i < syndContents.size(); i++) { + atomContents.add(createAtomContent(syndContents.get(i))); } return atomContents; } - protected Entry createAtomEntry(SyndEntry sEntry) { - Entry aEntry = new Entry(); + protected Entry createAtomEntry(final SyndEntry sEntry) { + final Entry aEntry = new Entry(); aEntry.setModules(ModuleUtils.cloneModules(sEntry.getModules())); aEntry.setId(sEntry.getUri()); - SyndContent sTitle = sEntry.getTitleEx(); - if (sTitle!=null) { - Content title = new Content(); + final SyndContent sTitle = sEntry.getTitleEx(); + if (sTitle != null) { + final Content title = new Content(); title.setType(sTitle.getType()); title.setValue(sTitle.getValue()); aEntry.setTitleEx(title); } - - SyndContent sDescription = sEntry.getDescription(); - if (sDescription!=null) { - Content summary = new Content(); + + final SyndContent sDescription = sEntry.getDescription(); + if (sDescription != null) { + final Content summary = new Content(); summary.setType(sDescription.getType()); summary.setValue(sDescription.getValue()); aEntry.setSummary(summary); } // separate SyndEntry's links collection into alternate and other links - List alternateLinks = new ArrayList(); - List otherLinks = new ArrayList(); - List slinks = sEntry.getLinks(); - List enclosures = sEntry.getEnclosures(); + final List alternateLinks = new ArrayList(); + final List otherLinks = new ArrayList(); + final List slinks = sEntry.getLinks(); + final List enclosures = sEntry.getEnclosures(); boolean linkRelEnclosureExists = false; if (slinks != null) { - for (Iterator iter=slinks.iterator(); iter.hasNext();) { - SyndLink syndLink = (SyndLink)iter.next(); - Link link = createAtomLink(syndLink); + for (final SyndLink syndLink2 : slinks) { + final SyndLink syndLink = syndLink2; + final Link link = createAtomLink(syndLink); // Set this flag if there's a link of rel = enclosure so that // enclosures won't be duplicated when pulled from // SyndEntry.getEnclosures() - if (syndLink.getRel() != null && - "enclosure".equals(syndLink.getRel())) { + if (syndLink.getRel() != null && "enclosure".equals(syndLink.getRel())) { linkRelEnclosureExists = true; } - if (link.getRel() == null || - "".equals(link.getRel().trim()) || - "alternate".equals(syndLink.getRel())) { + if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(syndLink.getRel())) { alternateLinks.add(link); } else { otherLinks.add(link); @@ -488,7 +480,7 @@ public class ConverterForAtom10 implements Converter { } // no alternate link? then use THE link if there is one if (alternateLinks.isEmpty() && sEntry.getLink() != null) { - Link link = new Link(); + final Link link = new Link(); link.setRel("alternate"); link.setHref(sEntry.getLink()); alternateLinks.add(link); @@ -496,45 +488,51 @@ public class ConverterForAtom10 implements Converter { // add SyndEnclosures as links with rel="enclosure" ONLY if // there are no SyndEntry.getLinks() with rel="enclosure" if (enclosures != null && linkRelEnclosureExists == false) { - for (Iterator iter=enclosures.iterator(); iter.hasNext();) { - SyndEnclosure syndEncl = (SyndEnclosure)iter.next(); - Link link = createAtomEnclosure(syndEncl); + for (final SyndEnclosure syndEnclosure : enclosures) { + final SyndEnclosure syndEncl = syndEnclosure; + final Link link = createAtomEnclosure(syndEncl); otherLinks.add(link); } } - if (alternateLinks.size() > 0) aEntry.setAlternateLinks(alternateLinks); - if (otherLinks.size() > 0) aEntry.setOtherLinks(otherLinks); - - List sCats = sEntry.getCategories(); - List aCats = new ArrayList(); + if (alternateLinks.size() > 0) { + aEntry.setAlternateLinks(alternateLinks); + } + if (otherLinks.size() > 0) { + aEntry.setOtherLinks(otherLinks); + } + + final List sCats = sEntry.getCategories(); + final List aCats = new ArrayList(); if (sCats != null) { - for (Iterator iter=sCats.iterator(); iter.hasNext();) { - SyndCategory sCat = (SyndCategory)iter.next(); - Category aCat = new Category(); + for (final SyndCategory syndCategory : sCats) { + final SyndCategory sCat = syndCategory; + final Category aCat = new Category(); aCat.setTerm(sCat.getName()); // TODO: aCat.setLabel(sCat.getLabel()); aCat.setScheme(sCat.getTaxonomyUri()); aCats.add(aCat); } } - if (aCats.size() > 0) aEntry.setCategories(aCats); - - List syndContents = sEntry.getContents(); + if (aCats.size() > 0) { + aEntry.setCategories(aCats); + } + + final List syndContents = sEntry.getContents(); aEntry.setContents(createAtomContents(syndContents)); List authors = sEntry.getAuthors(); - if (authors!=null && authors.size() > 0) { + if (authors != null && authors.size() > 0) { aEntry.setAuthors(ConverterForAtom03.createAtomPersons(authors)); } else if (sEntry.getAuthor() != null) { - Person person = new Person(); - person.setName(sEntry.getAuthor()); + final Person person = new Person(); + person.setName(sEntry.getAuthor()); authors = new ArrayList(); authors.add(person); aEntry.setAuthors(authors); } - List contributors = sEntry.getContributors(); - if (contributors!=null && contributors.size() > 0) { + final List contributors = sEntry.getContributors(); + if (contributors != null && contributors.size() > 0) { aEntry.setContributors(ConverterForAtom03.createAtomPersons(contributors)); } @@ -544,19 +542,19 @@ public class ConverterForAtom10 implements Converter { // And issue #42 "Atom 1.0 Date (Updated or Published) Not Set" // Atom requires an updated date, if it's missing use the published date if (sEntry.getUpdatedDate() != null) { - aEntry.setUpdated(sEntry.getUpdatedDate()); + aEntry.setUpdated(sEntry.getUpdatedDate()); } else { aEntry.setUpdated(sEntry.getPublishedDate()); } - if (((List)sEntry.getForeignMarkup()).size() > 0) { - aEntry.setForeignMarkup((List)sEntry.getForeignMarkup()); + if (sEntry.getForeignMarkup().size() > 0) { + aEntry.setForeignMarkup(sEntry.getForeignMarkup()); } - - SyndFeed sSource = sEntry.getSource(); + + final SyndFeed sSource = sEntry.getSource(); if (sSource != null) { - Feed aSource = (Feed) sSource.createWireFeed(getType()); - aEntry.setSource(aSource); + final Feed aSource = (Feed) sSource.createWireFeed(getType()); + aEntry.setSource(aSource); } return aEntry; } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS090.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS090.java index 1915a5f..eb7241e 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS090.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS090.java @@ -16,85 +16,90 @@ */ package com.sun.syndication.feed.synd.impl; +import java.util.ArrayList; +import java.util.List; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.module.impl.ModuleUtils; import com.sun.syndication.feed.rss.Channel; import com.sun.syndication.feed.rss.Image; import com.sun.syndication.feed.rss.Item; -import com.sun.syndication.feed.synd.*; - -import java.util.ArrayList; -import java.util.List; - -import org.jdom2.Element; +import com.sun.syndication.feed.synd.Converter; +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.SyndImage; +import com.sun.syndication.feed.synd.SyndImageImpl; /** */ public class ConverterForRSS090 implements Converter { - private String _type; + private final String _type; public ConverterForRSS090() { this("rss_0.9"); } - protected ConverterForRSS090(String type) { - _type = type; + protected ConverterForRSS090(final String type) { + this._type = type; } + @Override public String getType() { - return _type; + return this._type; } - public void copyInto(WireFeed feed,SyndFeed syndFeed) { + @Override + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { syndFeed.setModules(ModuleUtils.cloneModules(feed.getModules())); - if (((List)feed.getForeignMarkup()).size() > 0) { + if (feed.getForeignMarkup().size() > 0) { syndFeed.setForeignMarkup(feed.getForeignMarkup()); } syndFeed.setEncoding(feed.getEncoding()); - Channel channel = (Channel) feed; + final Channel channel = (Channel) feed; syndFeed.setTitle(channel.getTitle()); syndFeed.setLink(channel.getLink()); syndFeed.setDescription(channel.getDescription()); - Image image = channel.getImage(); - if (image!=null) { + final Image image = channel.getImage(); + if (image != null) { syndFeed.setImage(createSyndImage(image)); } - List items = channel.getItems(); - if (items!=null) { + final List items = channel.getItems(); + if (items != null) { syndFeed.setEntries(createSyndEntries(items, syndFeed.isPreservingWireFeed())); } } - protected SyndImage createSyndImage(Image rssImage) { - SyndImage syndImage = new SyndImageImpl(); + protected SyndImage createSyndImage(final Image rssImage) { + final SyndImage syndImage = new SyndImageImpl(); syndImage.setTitle(rssImage.getTitle()); syndImage.setUrl(rssImage.getUrl()); syndImage.setLink(rssImage.getLink()); return syndImage; } - protected List createSyndEntries(List rssItems, boolean preserveWireItems) { - List syndEntries = new ArrayList(); - for (int i=0;i createSyndEntries(final List rssItems, final boolean preserveWireItems) { + final List syndEntries = new ArrayList(); + for (int i = 0; i < rssItems.size(); i++) { + syndEntries.add(createSyndEntry(rssItems.get(i), preserveWireItems)); } return syndEntries; } - protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) { - SyndEntryImpl syndEntry = new SyndEntryImpl(); - if (preserveWireItem) { - syndEntry.setWireEntry(item); - } - + protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { + final SyndEntryImpl syndEntry = new SyndEntryImpl(); + if (preserveWireItem) { + syndEntry.setWireEntry(item); + } + syndEntry.setModules(ModuleUtils.cloneModules(item.getModules())); - - if (((List)item.getForeignMarkup()).size() > 0) { + + if (item.getForeignMarkup().size() > 0) { syndEntry.setForeignMarkup(item.getForeignMarkup()); } - + syndEntry.setUri(item.getUri()); syndEntry.setLink(item.getLink()); syndEntry.setTitle(item.getTitle()); @@ -102,12 +107,13 @@ public class ConverterForRSS090 implements Converter { return syndEntry; } - public WireFeed createRealFeed(SyndFeed syndFeed) { - return createRealFeed(getType(),syndFeed); + @Override + public WireFeed createRealFeed(final SyndFeed syndFeed) { + return this.createRealFeed(getType(), syndFeed); } - protected WireFeed createRealFeed(String type,SyndFeed syndFeed) { - Channel channel = new Channel(type); + protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) { + final Channel channel = new Channel(type); channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules())); channel.setEncoding(syndFeed.getEncoding()); @@ -115,59 +121,56 @@ public class ConverterForRSS090 implements Converter { channel.setTitle(syndFeed.getTitle()); if (syndFeed.getLink() != null) { channel.setLink(syndFeed.getLink()); - } - else - if (syndFeed.getLinks().size() > 0) { - channel.setLink(((SyndLink)syndFeed.getLinks().get(0)).getHref()); + } else if (syndFeed.getLinks().size() > 0) { + channel.setLink(syndFeed.getLinks().get(0).getHref()); } channel.setDescription(syndFeed.getDescription()); - SyndImage sImage = syndFeed.getImage(); - if (sImage!=null) { + final SyndImage sImage = syndFeed.getImage(); + if (sImage != null) { channel.setImage(createRSSImage(sImage)); } - List sEntries = syndFeed.getEntries(); - if (sEntries!=null) { + final List sEntries = syndFeed.getEntries(); + if (sEntries != null) { channel.setItems(createRSSItems(sEntries)); } - if (((List)syndFeed.getForeignMarkup()).size() > 0) { + if (syndFeed.getForeignMarkup().size() > 0) { channel.setForeignMarkup(syndFeed.getForeignMarkup()); } return channel; } - protected Image createRSSImage(SyndImage sImage) { - Image image = new Image(); + protected Image createRSSImage(final SyndImage sImage) { + final Image image = new Image(); image.setTitle(sImage.getTitle()); image.setUrl(sImage.getUrl()); image.setLink(sImage.getLink()); return image; } - protected List createRSSItems(List sEntries) { - List list = new ArrayList(); - for (int i=0;i createRSSItems(final List sEntries) { + final List list = new ArrayList(); + for (int i = 0; i < sEntries.size(); i++) { + list.add(createRSSItem(sEntries.get(i))); } return list; } - protected Item createRSSItem(SyndEntry sEntry) { - Item item = new Item(); + protected Item createRSSItem(final SyndEntry sEntry) { + final Item item = new Item(); item.setModules(ModuleUtils.cloneModules(sEntry.getModules())); item.setTitle(sEntry.getTitle()); item.setLink(sEntry.getLink()); - if (((List)sEntry.getForeignMarkup()).size() > 0) { + if (sEntry.getForeignMarkup().size() > 0) { item.setForeignMarkup(sEntry.getForeignMarkup()); } - String uri = sEntry.getUri(); + final String uri = sEntry.getUri(); if (uri != null) { item.setUri(uri); } - return item; } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Netscape.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Netscape.java index fe5ce26..48e2e48 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Netscape.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Netscape.java @@ -16,8 +16,6 @@ */ package com.sun.syndication.feed.synd.impl; - - /** */ public class ConverterForRSS091Netscape extends ConverterForRSS091Userland { @@ -26,7 +24,7 @@ public class ConverterForRSS091Netscape extends ConverterForRSS091Userland { this("rss_0.91N"); } - protected ConverterForRSS091Netscape(String type) { + protected ConverterForRSS091Netscape(final String type) { super(type); } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java index cd4dbe7..b8942a6 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java @@ -16,6 +16,12 @@ */ package com.sun.syndication.feed.synd.impl; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.module.DCModule; import com.sun.syndication.feed.rss.Channel; @@ -30,13 +36,6 @@ import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndImage; import com.sun.syndication.feed.synd.SyndPerson; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - - /** */ public class ConverterForRSS091Userland extends ConverterForRSS090 { @@ -44,32 +43,34 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { this("rss_0.91U"); } - protected ConverterForRSS091Userland(String type) { + protected ConverterForRSS091Userland(final String type) { super(type); } @Override - public void copyInto(WireFeed feed, SyndFeed syndFeed) { - Channel channel = (Channel) feed; + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + final Channel channel = (Channel) feed; super.copyInto(channel, syndFeed); - syndFeed.setLanguage(channel.getLanguage()); //c - syndFeed.setCopyright(channel.getCopyright()); //c + syndFeed.setLanguage(channel.getLanguage()); // c + syndFeed.setCopyright(channel.getCopyright()); // c - Date pubDate = channel.getPubDate(); + final Date pubDate = channel.getPubDate(); if (pubDate != null) { - syndFeed.setPublishedDate(pubDate); //c + syndFeed.setPublishedDate(pubDate); // c } else if (channel.getLastBuildDate() != null) { - syndFeed.setPublishedDate(channel.getLastBuildDate()); //c + syndFeed.setPublishedDate(channel.getLastBuildDate()); // c } - String author = channel.getManagingEditor(); + final String author = channel.getManagingEditor(); if (author != null) { - List creators = ((DCModule) syndFeed.getModule(DCModule.URI)).getCreators(); + final List creators = ((DCModule) syndFeed.getModule(DCModule.URI)).getCreators(); if (!creators.contains(author)) { - Set s = new HashSet(); // using a set to remove duplicates + final Set s = new HashSet(); // using a set to + // remove + // duplicates s.addAll(creators); // DC creators s.add(author); // feed native author creators.clear(); @@ -78,8 +79,8 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { } } - protected Description createItemDescription(SyndContent sContent) { - Description desc = new Description(); + protected Description createItemDescription(final SyndContent sContent) { + final Description desc = new Description(); desc.setValue(sContent.getValue()); desc.setType(sContent.getType()); @@ -87,8 +88,8 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { } @Override - protected Image createRSSImage(SyndImage sImage) { - Image image = super.createRSSImage(sImage); + protected Image createRSSImage(final SyndImage sImage) { + final Image image = super.createRSSImage(sImage); image.setDescription(sImage.getDescription()); return image; @@ -98,20 +99,20 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { // synd.content -> rss.content // synd.description -> rss.description @Override - protected Item createRSSItem(SyndEntry sEntry) { - Item item = super.createRSSItem(sEntry); + protected Item createRSSItem(final SyndEntry sEntry) { + final Item item = super.createRSSItem(sEntry); - SyndContent sContent = sEntry.getDescription(); + final SyndContent sContent = sEntry.getDescription(); if (sContent != null) { item.setDescription(createItemDescription(sContent)); } - List contents = sEntry.getContents(); + final List contents = sEntry.getContents(); - if ((contents != null) && (contents.size() > 0)) { - SyndContent syndContent = (SyndContent) contents.get(0); - Content cont = new Content(); + if (contents != null && contents.size() > 0) { + final SyndContent syndContent = contents.get(0); + final Content cont = new Content(); cont.setValue(syndContent.getValue()); cont.setType(syndContent.getType()); item.setContent(cont); @@ -121,16 +122,14 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { } @Override - protected WireFeed createRealFeed(String type, SyndFeed syndFeed) { - Channel channel = (Channel) super.createRealFeed(type, syndFeed); - channel.setLanguage(syndFeed.getLanguage()); //c - channel.setCopyright(syndFeed.getCopyright()); //c - channel.setPubDate(syndFeed.getPublishedDate()); //c + protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) { + final Channel channel = (Channel) super.createRealFeed(type, syndFeed); + channel.setLanguage(syndFeed.getLanguage()); // c + channel.setCopyright(syndFeed.getCopyright()); // c + channel.setPubDate(syndFeed.getPublishedDate()); // c - if ((syndFeed.getAuthors() != null) && (syndFeed.getAuthors() - .size() > 0)) { - SyndPerson author = (SyndPerson) syndFeed.getAuthors() - .get(0); + if (syndFeed.getAuthors() != null && syndFeed.getAuthors().size() > 0) { + final SyndPerson author = syndFeed.getAuthors().get(0); channel.setManagingEditor(author.getName()); } @@ -141,25 +140,25 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { // rss.content -> synd.content // rss.description -> synd.description @Override - protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) { - SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); - Description desc = item.getDescription(); + protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { + final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); + final Description desc = item.getDescription(); if (desc != null) { - SyndContent descContent = new SyndContentImpl(); + final SyndContent descContent = new SyndContentImpl(); descContent.setType(desc.getType()); descContent.setValue(desc.getValue()); syndEntry.setDescription(descContent); } - Content cont = item.getContent(); + final Content cont = item.getContent(); if (cont != null) { - SyndContent content = new SyndContentImpl(); + final SyndContent content = new SyndContentImpl(); content.setType(cont.getType()); content.setValue(cont.getValue()); - List syndContents = new ArrayList(); + final List syndContents = new ArrayList(); syndContents.add(content); syndEntry.setContents(syndContents); } @@ -168,8 +167,8 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { } @Override - protected SyndImage createSyndImage(Image rssImage) { - SyndImage syndImage = super.createSyndImage(rssImage); + protected SyndImage createSyndImage(final Image rssImage) { + final SyndImage syndImage = super.createSyndImage(rssImage); syndImage.setDescription(rssImage.getDescription()); return syndImage; diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS092.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS092.java index f266dea..426053a 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS092.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS092.java @@ -38,32 +38,47 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland { this("rss_0.92"); } - protected ConverterForRSS092(String type) { + protected ConverterForRSS092(final String type) { super(type); } @Override - protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) { - SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); - List cats = item.getCategories(); - if (cats.size()>0) { - Set s = new LinkedHashSet(); // using a set to remove duplicates and use a LinkedHashSet to try to retain the document order - s.addAll(createSyndCategories(cats)); // feed native categories (as syndcat) - s.addAll(syndEntry.getCategories()); // DC subjects (as syndcat) - syndEntry.setCategories(new ArrayList(s)); //c + protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { + final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); + final List cats = item.getCategories(); + if (cats.size() > 0) { + final Set s = new LinkedHashSet(); // using + // a + // set to + // remove + // duplicates + // and use + // a + // LinkedHashSet + // to try + // to + // retain + // the + // document + // order + s.addAll(createSyndCategories(cats)); // feed native categories + // (as + // syndcat) + s.addAll(syndEntry.getCategories()); // DC subjects (as syndcat) + syndEntry.setCategories(new ArrayList(s)); // c } - List enclosures = item.getEnclosures(); - if (enclosures.size()>0) { + final List enclosures = item.getEnclosures(); + if (enclosures.size() > 0) { syndEntry.setEnclosures(createSyndEnclosures(enclosures)); } return syndEntry; } - protected List createSyndCategories(List rssCats) { - List syndCats = new ArrayList(); - for (int i=0;i createSyndCategories(final List rssCats) { + final List syndCats = new ArrayList(); + for (int i = 0; i < rssCats.size(); i++) { + final Category rssCat = rssCats.get(i); + final SyndCategory sCat = new SyndCategoryImpl(); sCat.setTaxonomyUri(rssCat.getDomain()); sCat.setName(rssCat.getValue()); syndCats.add(sCat); @@ -71,11 +86,11 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland { return syndCats; } - protected List createSyndEnclosures(List enclosures) { - List sEnclosures = new ArrayList(); - for (int i=0;i createSyndEnclosures(final List enclosures) { + final List sEnclosures = new ArrayList(); + for (int i = 0; i < enclosures.size(); i++) { + final Enclosure enc = enclosures.get(i); + final SyndEnclosure sEnc = new SyndEnclosureImpl(); sEnc.setUrl(enc.getUrl()); sEnc.setType(enc.getType()); sEnc.setLength(enc.getLength()); @@ -85,25 +100,25 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland { } @Override - protected Item createRSSItem(SyndEntry sEntry) { - Item item = super.createRSSItem(sEntry); + protected Item createRSSItem(final SyndEntry sEntry) { + final Item item = super.createRSSItem(sEntry); - List sCats = sEntry.getCategories(); //c - if (sCats.size()>0) { + final List sCats = sEntry.getCategories(); // c + if (sCats.size() > 0) { item.setCategories(createRSSCategories(sCats)); } - List sEnclosures = sEntry.getEnclosures(); - if (sEnclosures.size()>0) { + final List sEnclosures = sEntry.getEnclosures(); + if (sEnclosures.size() > 0) { item.setEnclosures(createEnclosures(sEnclosures)); } return item; } - protected List createRSSCategories(List sCats) { - List cats = new ArrayList(); - for (int i=0;i createRSSCategories(final List sCats) { + final List cats = new ArrayList(); + for (int i = 0; i < sCats.size(); i++) { + final SyndCategory sCat = sCats.get(i); + final Category cat = new Category(); cat.setDomain(sCat.getTaxonomyUri()); cat.setValue(sCat.getName()); cats.add(cat); @@ -111,11 +126,11 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland { return cats; } - protected List createEnclosures(List sEnclosures) { - List enclosures = new ArrayList(); - for (int i=0;i createEnclosures(final List sEnclosures) { + final List enclosures = new ArrayList(); + for (int i = 0; i < sEnclosures.size(); i++) { + final SyndEnclosure sEnc = sEnclosures.get(i); + final Enclosure enc = new Enclosure(); enc.setUrl(sEnc.getUrl()); enc.setType(sEnc.getType()); enc.setLength(sEnc.getLength()); diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java index 79839af..1a0309f 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java @@ -16,11 +16,11 @@ */ package com.sun.syndication.feed.synd.impl; +import java.util.Date; + import com.sun.syndication.feed.rss.Item; import com.sun.syndication.feed.synd.SyndEntry; -import java.util.Date; - /** */ public class ConverterForRSS093 extends ConverterForRSS092 { @@ -29,24 +29,24 @@ public class ConverterForRSS093 extends ConverterForRSS092 { this("rss_0.93"); } - protected ConverterForRSS093(String type) { + protected ConverterForRSS093(final String type) { super(type); } @Override - protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) { - SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); - Date pubDate = item.getPubDate(); - if (pubDate!=null) { - syndEntry.setPublishedDate(pubDate); //c + protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { + final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); + final Date pubDate = item.getPubDate(); + if (pubDate != null) { + syndEntry.setPublishedDate(pubDate); // c } return syndEntry; } @Override - protected Item createRSSItem(SyndEntry sEntry) { - Item item = super.createRSSItem(sEntry); - item.setPubDate(sEntry.getPublishedDate()); //c + protected Item createRSSItem(final SyndEntry sEntry) { + final Item item = super.createRSSItem(sEntry); + item.setPubDate(sEntry.getPublishedDate()); // c return item; } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS094.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS094.java index c2f3337..69ceb1a 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS094.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS094.java @@ -16,6 +16,11 @@ */ package com.sun.syndication.feed.synd.impl; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.module.DCModule; import com.sun.syndication.feed.rss.Category; @@ -29,11 +34,6 @@ import com.sun.syndication.feed.synd.SyndLink; import com.sun.syndication.feed.synd.SyndLinkImpl; import com.sun.syndication.feed.synd.SyndPerson; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - /** */ public class ConverterForRSS094 extends ConverterForRSS093 { @@ -42,52 +42,58 @@ public class ConverterForRSS094 extends ConverterForRSS093 { this("rss_0.94"); } - protected ConverterForRSS094(String type) { + protected ConverterForRSS094(final String type) { super(type); } @Override - public void copyInto(WireFeed feed,SyndFeed syndFeed) { - Channel channel = (Channel) feed; - super.copyInto(channel,syndFeed); - List cats = channel.getCategories(); //c - if (cats.size()>0) { - Set s = new HashSet(); // using a set to remove duplicates - s.addAll(createSyndCategories(cats)); // feed native categories (as syndcat) - s.addAll(syndFeed.getCategories()); // DC subjects (as syndcat) + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + final Channel channel = (Channel) feed; + super.copyInto(channel, syndFeed); + final List cats = channel.getCategories(); // c + if (cats.size() > 0) { + final Set s = new HashSet(); // using a + // set to + // remove + // duplicates + s.addAll(createSyndCategories(cats)); // feed native categories + // (as + // syndcat) + s.addAll(syndFeed.getCategories()); // DC subjects (as syndcat) syndFeed.setCategories(new ArrayList(s)); } } @Override - protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) { - SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); + protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { + final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); // adding native feed author to DC creators list - String author = item.getAuthor(); - if (author!=null) { - List creators = ((DCModule)syndEntry.getModule(DCModule.URI)).getCreators(); + final String author = item.getAuthor(); + if (author != null) { + final List creators = ((DCModule) syndEntry.getModule(DCModule.URI)).getCreators(); if (!creators.contains(author)) { - Set s = new HashSet(); // using a set to remove duplicates - s.addAll(creators); // DC creators - s.add(author); // feed native author + final Set s = new HashSet(); // using a set to + // remove + // duplicates + s.addAll(creators); // DC creators + s.add(author); // feed native author creators.clear(); creators.addAll(s); } } - Guid guid = item.getGuid(); - if (guid!=null) { + final Guid guid = item.getGuid(); + if (guid != null) { syndEntry.setUri(guid.getValue()); - if (item.getLink()==null && guid.isPermaLink()) { + if (item.getLink() == null && guid.isPermaLink()) { syndEntry.setLink(guid.getValue()); } - } - else { + } else { syndEntry.setUri(item.getLink()); } - if(item.getComments() != null){ - SyndLinkImpl comments = new SyndLinkImpl(); + if (item.getComments() != null) { + final SyndLinkImpl comments = new SyndLinkImpl(); comments.setRel("comments"); comments.setHref(item.getComments()); comments.setType("text/html"); @@ -95,43 +101,41 @@ public class ConverterForRSS094 extends ConverterForRSS093 { return syndEntry; } - @Override - protected WireFeed createRealFeed(String type,SyndFeed syndFeed) { - Channel channel = (Channel) super.createRealFeed(type,syndFeed); - List cats = syndFeed.getCategories(); //c - if (cats.size()>0) { + protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) { + final Channel channel = (Channel) super.createRealFeed(type, syndFeed); + final List cats = syndFeed.getCategories(); // c + if (cats.size() > 0) { channel.setCategories(createRSSCategories(cats)); } return channel; } @Override - protected Item createRSSItem(SyndEntry sEntry) { - Item item = super.createRSSItem(sEntry); - if (sEntry.getAuthors()!=null && sEntry.getAuthors().size() > 0) { - SyndPerson author = (SyndPerson)sEntry.getAuthors().get(0); - item.setAuthor(author.getEmail()); - } + protected Item createRSSItem(final SyndEntry sEntry) { + final Item item = super.createRSSItem(sEntry); + if (sEntry.getAuthors() != null && sEntry.getAuthors().size() > 0) { + final SyndPerson author = sEntry.getAuthors().get(0); + item.setAuthor(author.getEmail()); + } Guid guid = null; - String uri = sEntry.getUri(); - if (uri!=null) { + final String uri = sEntry.getUri(); + if (uri != null) { guid = new Guid(); guid.setPermaLink(false); guid.setValue(uri); - } - else { - String link = sEntry.getLink(); - if (link!=null) { + } else { + final String link = sEntry.getLink(); + if (link != null) { guid = new Guid(); guid.setPermaLink(true); guid.setValue(link); } } item.setGuid(guid); - SyndLink comments = sEntry.findRelatedLink("comments"); - if(comments != null && (comments.getType() == null || comments.getType().endsWith("html"))){ + final SyndLink comments = sEntry.findRelatedLink("comments"); + if (comments != null && (comments.getType() == null || comments.getType().endsWith("html"))) { item.setComments(comments.getHref()); } return item; diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS10.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS10.java index dee3b35..4f97832 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS10.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS10.java @@ -16,6 +16,9 @@ */ package com.sun.syndication.feed.synd.impl; +import java.util.ArrayList; +import java.util.List; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.rss.Channel; import com.sun.syndication.feed.rss.Content; @@ -25,8 +28,6 @@ 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.SyndFeed; -import java.util.ArrayList; -import java.util.List; /** */ @@ -36,97 +37,97 @@ public class ConverterForRSS10 extends ConverterForRSS090 { this("rss_1.0"); } - protected ConverterForRSS10(String type) { + protected ConverterForRSS10(final String type) { super(type); } @Override - public void copyInto(WireFeed feed,SyndFeed syndFeed) { - Channel channel = (Channel) feed; - super.copyInto(channel,syndFeed); + public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { + final Channel channel = (Channel) feed; + super.copyInto(channel, syndFeed); if (channel.getUri() != null) { - syndFeed.setUri(channel.getUri()); + syndFeed.setUri(channel.getUri()); } else { - // if URI is not set use the value for link - syndFeed.setUri(channel.getLink()); + // if URI is not set use the value for link + syndFeed.setUri(channel.getLink()); } } - + // for rss -> synd // rss.content -> synd.content // rss.description -> synd.description - - @Override - protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) { - SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); - Description desc = item.getDescription(); - if (desc!=null) { - SyndContent descContent = new SyndContentImpl(); + @Override + protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { + final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); + + final Description desc = item.getDescription(); + if (desc != null) { + final SyndContent descContent = new SyndContentImpl(); descContent.setType(desc.getType()); descContent.setValue(desc.getValue()); syndEntry.setDescription(descContent); } - Content cont = item.getContent(); - if (cont!=null) { - SyndContent contContent = new SyndContentImpl(); + final Content cont = item.getContent(); + if (cont != null) { + final SyndContent contContent = new SyndContentImpl(); contContent.setType(cont.getType()); contContent.setValue(cont.getValue()); - List contents = new ArrayList(); + final List contents = new ArrayList(); contents.add(contContent); syndEntry.setContents(contents); } - + return syndEntry; } @Override - protected WireFeed createRealFeed(String type,SyndFeed syndFeed) { - Channel channel = (Channel) super.createRealFeed(type,syndFeed); + protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) { + final Channel channel = (Channel) super.createRealFeed(type, syndFeed); if (syndFeed.getUri() != null) { - channel.setUri(syndFeed.getUri()); + channel.setUri(syndFeed.getUri()); } else { - // if URI is not set use the value for link - channel.setUri(syndFeed.getLink()); + // if URI is not set use the value for link + channel.setUri(syndFeed.getLink()); } - + return channel; } - + // for synd -> rss // synd.content -> rss.content // synd.description -> rss.description - - @Override - protected Item createRSSItem(SyndEntry sEntry) { - Item item = super.createRSSItem(sEntry); - SyndContent desc = sEntry.getDescription(); - if (desc!=null) { + @Override + protected Item createRSSItem(final SyndEntry sEntry) { + final Item item = super.createRSSItem(sEntry); + + final SyndContent desc = sEntry.getDescription(); + if (desc != null) { item.setDescription(createItemDescription(desc)); } - List contents = sEntry.getContents(); - if (contents!=null && contents.size() > 0) { - item.setContent(createItemContent((SyndContent)contents.get(0))); + final List contents = sEntry.getContents(); + if (contents != null && contents.size() > 0) { + item.setContent(createItemContent(contents.get(0))); } - - String uri = sEntry.getUri(); + + final String uri = sEntry.getUri(); if (uri != null) { item.setUri(uri); } - + return item; } - protected Description createItemDescription(SyndContent sContent) { - Description desc = new Description(); + protected Description createItemDescription(final SyndContent sContent) { + final Description desc = new Description(); desc.setValue(sContent.getValue()); desc.setType(sContent.getType()); return desc; } - protected Content createItemContent(SyndContent sContent) { - Content cont = new Content(); + protected Content createItemContent(final SyndContent sContent) { + final Content cont = new Content(); cont.setValue(sContent.getValue()); cont.setType(sContent.getType()); return cont; diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS20.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS20.java index 3e824be..f28b9d3 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS20.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS20.java @@ -16,9 +16,6 @@ */ package com.sun.syndication.feed.synd.impl; - - - /** */ public class ConverterForRSS20 extends ConverterForRSS094 { @@ -27,7 +24,7 @@ public class ConverterForRSS20 extends ConverterForRSS094 { this("rss_2.0"); } - protected ConverterForRSS20(String type) { + protected ConverterForRSS20(final String type) { super(type); } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/Converters.java b/src/main/java/com/sun/syndication/feed/synd/impl/Converters.java index 7af49a3..1b0a7f4 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/Converters.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/Converters.java @@ -16,23 +16,20 @@ */ package com.sun.syndication.feed.synd.impl; -import com.sun.syndication.io.impl.PluginManager; -import com.sun.syndication.feed.synd.Converter; - import java.util.List; +import com.sun.syndication.feed.synd.Converter; +import com.sun.syndication.io.impl.PluginManager; + /** - * Created by IntelliJ IDEA. - * User: tucu - * Date: May 21, 2004 - * Time: 5:26:04 PM - * To change this template use Options | File Templates. + * Created by IntelliJ IDEA. User: tucu Date: May 21, 2004 Time: 5:26:04 PM To + * change this template use Options | File Templates. */ public class Converters extends PluginManager { /** - * Converter.classes= [className] ... - * + * Converter.classes= [className] ... + * */ public static final String CONVERTERS_KEY = "Converter.classes"; @@ -40,12 +37,13 @@ public class Converters extends PluginManager { super(CONVERTERS_KEY); } - public Converter getConverter(String feedType) { + public Converter getConverter(final String feedType) { return (Converter) getPlugin(feedType); } - protected String getKey(Object obj) { - return ((Converter)obj).getType(); + @Override + protected String getKey(final Object obj) { + return ((Converter) obj).getType(); } public List getSupportedFeedTypes() { diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/URINormalizer.java b/src/main/java/com/sun/syndication/feed/synd/impl/URINormalizer.java index 34904e5..7cde59e 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/URINormalizer.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/URINormalizer.java @@ -3,6 +3,7 @@ package com.sun.syndication.feed.synd.impl; /** * Utility class for normalizing an URI as specified in RFC 2396bis. *

+ * * @author Alejandro Abdelnur */ public class URINormalizer { @@ -10,13 +11,15 @@ public class URINormalizer { /** * Normalizes an URI as specified in RFC 2396bis. *

+ * * @param uri to normalize. - * @return the normalized value of the given URI, or null if the given URI was null. + * @return the normalized value of the given URI, or null if the + * given URI was null. */ - public static String normalize(String uri) { + public static String normalize(final String uri) { String normalizedUri = null; - if (uri!=null) { - normalizedUri = uri; //TODO THIS HAS TO BE IMPLEMENTED + if (uri != null) { + normalizedUri = uri; // TODO THIS HAS TO BE IMPLEMENTED } return normalizedUri; } diff --git a/src/main/java/com/sun/syndication/io/DelegatingModuleGenerator.java b/src/main/java/com/sun/syndication/io/DelegatingModuleGenerator.java index 693e4c7..26a840c 100644 --- a/src/main/java/com/sun/syndication/io/DelegatingModuleGenerator.java +++ b/src/main/java/com/sun/syndication/io/DelegatingModuleGenerator.java @@ -2,15 +2,15 @@ package com.sun.syndication.io; /** * Adds the ability to give a direct wire feed generator reference to plugin - * modules that need to call back to their wire feed to complete - * generation of their particular namespace. Examples of such parsers - * include the SSE091Generator. + * modules that need to call back to their wire feed to complete generation of + * their particular namespace. Examples of such parsers include the + * SSE091Generator. */ public interface DelegatingModuleGenerator extends ModuleGenerator { /** - * Provides a parent wirefeed reference to this ModuleParser, - * or "plugin-in". - * + * Provides a parent wirefeed reference to this ModuleParser, or + * "plugin-in". + * * @param feedGenerator the parent wirefeed generator for this plugin. */ void setFeedGenerator(WireFeedGenerator feedGenerator); diff --git a/src/main/java/com/sun/syndication/io/DelegatingModuleParser.java b/src/main/java/com/sun/syndication/io/DelegatingModuleParser.java index 71d157d..f917c82 100644 --- a/src/main/java/com/sun/syndication/io/DelegatingModuleParser.java +++ b/src/main/java/com/sun/syndication/io/DelegatingModuleParser.java @@ -1,16 +1,15 @@ package com.sun.syndication.io; /** - * Adds the ability to give a direct wire feed reference to plugin - * modules that need to call back to their wire feed to complete - * parsing of their particular namespace. Examples of such parsers - * include the SSE091Parser. + * Adds the ability to give a direct wire feed reference to plugin modules that + * need to call back to their wire feed to complete parsing of their particular + * namespace. Examples of such parsers include the SSE091Parser. */ public interface DelegatingModuleParser extends ModuleParser { /** - * Provides a parent wirefeed reference to this ModuleParser, - * or "plugin-in". - * + * Provides a parent wirefeed reference to this ModuleParser, or + * "plugin-in". + * * @param feedParser the parent wirefeed parser for this plugin. */ void setFeedParser(WireFeedParser feedParser); diff --git a/src/main/java/com/sun/syndication/io/FeedException.java b/src/main/java/com/sun/syndication/io/FeedException.java index bb8ed37..7a32c71 100644 --- a/src/main/java/com/sun/syndication/io/FeedException.java +++ b/src/main/java/com/sun/syndication/io/FeedException.java @@ -17,33 +17,36 @@ package com.sun.syndication.io; /** - * Exception thrown by WireFeedInput, WireFeedOutput, WireFeedParser and WireFeedGenerator instances if they - * can not parse or generate a feed. + * Exception thrown by WireFeedInput, WireFeedOutput, WireFeedParser and + * WireFeedGenerator instances if they can not parse or generate a feed. *

+ * * @author Alejandro Abdelnur - * + * */ public class FeedException extends Exception { /** * Creates a FeedException with a message. *

+ * * @param msg exception message. - * + * */ - public FeedException(String msg) { + public FeedException(final String msg) { super(msg); } /** * Creates a FeedException with a message and a root cause exception. *

+ * * @param msg exception message. * @param rootCause root cause exception. - * + * */ - public FeedException(String msg,Throwable rootCause) { - super(msg,rootCause); + public FeedException(final String msg, final Throwable rootCause) { + super(msg, rootCause); } } diff --git a/src/main/java/com/sun/syndication/io/ModuleGenerator.java b/src/main/java/com/sun/syndication/io/ModuleGenerator.java index a1c679e..7ba3cc5 100644 --- a/src/main/java/com/sun/syndication/io/ModuleGenerator.java +++ b/src/main/java/com/sun/syndication/io/ModuleGenerator.java @@ -16,10 +16,11 @@ */ package com.sun.syndication.io; -import com.sun.syndication.feed.module.Module; +import java.util.Set; + import org.jdom2.Element; -import java.util.Set; +import com.sun.syndication.feed.module.Module; /** * Injects module metadata into a XML node (JDOM element). @@ -28,35 +29,41 @@ import java.util.Set; *

* TODO: explain how developers can plugin their own implementations. *

+ * * @author Alejandro Abdelnur - * + * */ public interface ModuleGenerator { /** * Returns the namespace URI this generator handles. *

+ * * @return the namespace URI. - * + * */ public String getNamespaceUri(); /** - * Returns a set with all the URIs (JDOM Namespace elements) this module generator uses. + * Returns a set with all the URIs (JDOM Namespace elements) this module + * generator uses. *

- * It is used by the the feed generators to add their namespace definition in - * the root element of the generated document (forward-missing of Java 5.0 Generics). + * It is used by the the feed generators to add their namespace definition + * in the root element of the generated document (forward-missing of Java + * 5.0 Generics). *

- * - * @return a set with all the URIs (JDOM Namespace elements) this module generator uses. + * + * @return a set with all the URIs (JDOM Namespace elements) this module + * generator uses. */ public Set getNamespaces(); /** * Generates and injects module metadata into an XML node (JDOM element). *

+ * * @param module the module to inject into the XML node (JDOM element). * @param element the XML node into which module meta-data will be injected. */ - public void generate(Module module,Element element); + public void generate(Module module, Element element); } diff --git a/src/main/java/com/sun/syndication/io/ModuleParser.java b/src/main/java/com/sun/syndication/io/ModuleParser.java index 0f52c59..e5aeea5 100644 --- a/src/main/java/com/sun/syndication/io/ModuleParser.java +++ b/src/main/java/com/sun/syndication/io/ModuleParser.java @@ -16,9 +16,10 @@ */ package com.sun.syndication.io; -import com.sun.syndication.feed.module.Module; import org.jdom2.Element; +import com.sun.syndication.feed.module.Module; + /** * Parses module metadata from a XML node (JDOM element). *

@@ -26,25 +27,30 @@ import org.jdom2.Element; *

* TODO: explain how developers can plugin their own implementations. *

+ * * @author Alejandro Abdelnur - * + * */ public interface ModuleParser { /** * Returns the namespace URI this parser handles. *

+ * * @return the namespace URI. - * + * */ public String getNamespaceUri(); /** * Parses the XML node (JDOM element) extracting module information. *

- * @param element the XML node (JDOM element) to extract module information from. - * @return a module instance, null if the element did not have module information. - * + * + * @param element the XML node (JDOM element) to extract module information + * from. + * @return a module instance, null if the element did not have module + * information. + * */ public Module parse(Element element); } diff --git a/src/main/java/com/sun/syndication/io/ParsingFeedException.java b/src/main/java/com/sun/syndication/io/ParsingFeedException.java index f9caf08..d4acf0f 100644 --- a/src/main/java/com/sun/syndication/io/ParsingFeedException.java +++ b/src/main/java/com/sun/syndication/io/ParsingFeedException.java @@ -21,58 +21,61 @@ import org.jdom2.input.JDOMParseException; /** * Exception thrown by WireFeedInput instance if it can not parse a feed. *

+ * * @author Elaine Chien - * + * */ public class ParsingFeedException extends FeedException { - + /** * Creates a FeedException with a message. *

+ * * @param msg exception message. - * + * */ - public ParsingFeedException(String msg) { + public ParsingFeedException(final String msg) { super(msg); } /** * Creates a FeedException with a message and a root cause exception. *

+ * * @param msg exception message. * @param rootCause root cause exception. - * + * */ - public ParsingFeedException(String msg, Throwable rootCause) { + public ParsingFeedException(final String msg, final Throwable rootCause) { super(msg, rootCause); } - - /** - * Returns the line number of the end of the text where the - * parse error occurred. - *

- * The first line in the document is line 1.

- * - * @return an integer representing the line number, or -1 - * if the information is not available. - */ - public int getLineNumber() { - return (getCause() instanceof JDOMParseException)? - ((JDOMParseException)getCause()).getLineNumber(): -1; - } /** - * Returns the column number of the end of the text where the - * parse error occurred. + * Returns the line number of the end of the text where the parse error + * occurred. *

- * The first column in a line is position 1.

- * - * @return an integer representing the column number, or -1 - * if the information is not available. + * The first line in the document is line 1. + *

+ * + * @return an integer representing the line number, or -1 if the information + * is not available. + */ + public int getLineNumber() { + return getCause() instanceof JDOMParseException ? ((JDOMParseException) getCause()).getLineNumber() : -1; + } + + /** + * Returns the column number of the end of the text where the parse error + * occurred. + *

+ * The first column in a line is position 1. + *

+ * + * @return an integer representing the column number, or -1 if the + * information is not available. */ public int getColumnNumber() { - return (getCause() instanceof JDOMParseException)? - ((JDOMParseException)getCause()).getColumnNumber(): -1; + return getCause() instanceof JDOMParseException ? ((JDOMParseException) getCause()).getColumnNumber() : -1; } } diff --git a/src/main/java/com/sun/syndication/io/SAXBuilder.java b/src/main/java/com/sun/syndication/io/SAXBuilder.java index 2a77c56..310ffee 100644 --- a/src/main/java/com/sun/syndication/io/SAXBuilder.java +++ b/src/main/java/com/sun/syndication/io/SAXBuilder.java @@ -17,21 +17,24 @@ import org.xml.sax.XMLReader; * */ public class SAXBuilder extends org.jdom2.input.SAXBuilder { - public SAXBuilder(XMLReaderJDOMFactory factory) { - super(factory); - } - - /** - * - * @deprecated use SAXBuilder(XMLReaderJDOMFactory) with either XMLReaders.DTDVALIDATING or XMLReaders.NONVALIDATING - * @param _validate - */ - public SAXBuilder(boolean _validate) { - super(_validate ? XMLReaders.DTDVALIDATING : XMLReaders.NONVALIDATING); - } + public SAXBuilder(final XMLReaderJDOMFactory factory) { + super(factory); + } + + /** + * + * @deprecated use SAXBuilder(XMLReaderJDOMFactory) with either + * XMLReaders.DTDVALIDATING or XMLReaders.NONVALIDATING + * @param _validate + */ + @Deprecated + public SAXBuilder(final boolean _validate) { + super(_validate ? XMLReaders.DTDVALIDATING : XMLReaders.NONVALIDATING); + } + + @Override + public XMLReader createParser() throws JDOMException { + return super.createParser(); + } - public XMLReader createParser() throws JDOMException { - return super.createParser(); - } - } diff --git a/src/main/java/com/sun/syndication/io/SyndFeedInput.java b/src/main/java/com/sun/syndication/io/SyndFeedInput.java index 27c324e..3f7f79e 100644 --- a/src/main/java/com/sun/syndication/io/SyndFeedInput.java +++ b/src/main/java/com/sun/syndication/io/SyndFeedInput.java @@ -16,33 +16,35 @@ */ package com.sun.syndication.io; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import org.jdom2.Document; -import org.xml.sax.InputSource; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Reader; +import org.jdom2.Document; +import org.xml.sax.InputSource; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + /** - * Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument) - * into an SyndFeedImpl. + * Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C + * DOM Document or JDom DOcument) into an SyndFeedImpl. *

* It delegates to a WireFeedInput to handle all feed types. *

+ * * @author Alejandro Abdelnur - * + * */ public class SyndFeedInput { - private WireFeedInput _feedInput; + private final WireFeedInput _feedInput; private boolean preserveWireFeed = false; /** * Creates a SyndFeedInput instance with input validation turned off. *

- * + * */ public SyndFeedInput() { this(false); @@ -51,131 +53,153 @@ public class SyndFeedInput { /** * Creates a SyndFeedInput instance. *

- * @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen) - * + * + * @param validate indicates if the input should be validated. NOT + * IMPLEMENTED YET (validation does not happen) + * */ - public SyndFeedInput(boolean validate) { - _feedInput = new WireFeedInput(validate); + public SyndFeedInput(final boolean validate) { + this._feedInput = new WireFeedInput(validate); } /** * Enables XML healing in the WiredFeedInput instance. *

- * Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog. + * Healing trims leading chars from the stream (empty spaces and comments) + * until the XML prolog. *

- * Healing resolves HTML entities (from literal to code number) in the reader. + * Healing resolves HTML entities (from literal to code number) in the + * reader. *

- * The healing is done only with the build(File) and build(Reader) signatures. + * The healing is done only with the build(File) and build(Reader) + * signatures. *

* By default is TRUE. *

+ * * @param heals TRUE enables stream healing, FALSE disables it. - * + * */ - public void setXmlHealerOn(boolean heals) { - _feedInput.setXmlHealerOn(heals); + public void setXmlHealerOn(final boolean heals) { + this._feedInput.setXmlHealerOn(heals); } /** - * Indicates if the WiredFeedInput instance will XML heal (if necessary) the character stream. + * Indicates if the WiredFeedInput instance will XML heal (if necessary) the + * character stream. *

- * Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog. + * Healing trims leading chars from the stream (empty spaces and comments) + * until the XML prolog. *

- * Healing resolves HTML entities (from literal to code number) in the reader. + * Healing resolves HTML entities (from literal to code number) in the + * reader. *

- * The healing is done only with the build(File) and build(Reader) signatures. + * The healing is done only with the build(File) and build(Reader) + * signatures. *

* By default is TRUE. *

+ * * @return TRUE if healing is enabled, FALSE if not. - * + * */ public boolean getXmlHealerOn() { - return _feedInput.getXmlHealerOn(); + return this._feedInput.getXmlHealerOn(); } - /** * Builds SyndFeedImpl from a file. *

+ * * @param file file to read to create the SyndFeedImpl. * @return the SyndFeedImpl read from the file. * @throws FileNotFoundException thrown if the file could not be found. * @throws IOException thrown if there is problem reading the file. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public SyndFeed build(File file) throws FileNotFoundException,IOException,IllegalArgumentException,FeedException { - return new SyndFeedImpl(_feedInput.build(file), preserveWireFeed); + public SyndFeed build(final File file) throws FileNotFoundException, IOException, IllegalArgumentException, FeedException { + return new SyndFeedImpl(this._feedInput.build(file), this.preserveWireFeed); } /** * Builds SyndFeedImpl from an Reader. *

+ * * @param reader Reader to read to create the SyndFeedImpl. * @return the SyndFeedImpl read from the Reader. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public SyndFeed build(Reader reader) throws IllegalArgumentException,FeedException { - return new SyndFeedImpl(_feedInput.build(reader), preserveWireFeed); + public SyndFeed build(final Reader reader) throws IllegalArgumentException, FeedException { + return new SyndFeedImpl(this._feedInput.build(reader), this.preserveWireFeed); } /** * Builds SyndFeedImpl from an W3C SAX InputSource. *

+ * * @param is W3C SAX InputSource to read to create the SyndFeedImpl. * @return the SyndFeedImpl read from the W3C SAX InputSource. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public SyndFeed build(InputSource is) throws IllegalArgumentException,FeedException { - return new SyndFeedImpl(_feedInput.build(is), preserveWireFeed); + public SyndFeed build(final InputSource is) throws IllegalArgumentException, FeedException { + return new SyndFeedImpl(this._feedInput.build(is), this.preserveWireFeed); } /** * Builds SyndFeedImpl from an W3C DOM document. *

+ * * @param document W3C DOM document to read to create the SyndFeedImpl. * @return the SyndFeedImpl read from the W3C DOM document. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public SyndFeed build(org.w3c.dom.Document document) throws IllegalArgumentException,FeedException { - return new SyndFeedImpl(_feedInput.build(document), preserveWireFeed); + public SyndFeed build(final org.w3c.dom.Document document) throws IllegalArgumentException, FeedException { + return new SyndFeedImpl(this._feedInput.build(document), this.preserveWireFeed); } /** * Builds SyndFeedImpl from an JDOM document. *

+ * * @param document JDOM document to read to create the SyndFeedImpl. * @return the SyndFeedImpl read from the JDOM document. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public SyndFeed build(Document document) throws IllegalArgumentException,FeedException { - return new SyndFeedImpl(_feedInput.build(document), preserveWireFeed); + public SyndFeed build(final Document document) throws IllegalArgumentException, FeedException { + return new SyndFeedImpl(this._feedInput.build(document), this.preserveWireFeed); } /** * - * @return true if the WireFeed is made available in the SyndFeed. False by default. + * @return true if the WireFeed is made available in the SyndFeed. False by + * default. */ - public boolean isPreserveWireFeed() { - return preserveWireFeed; - } + public boolean isPreserveWireFeed() { + return this.preserveWireFeed; + } - /** - * - * @param preserveWireFeed set to true to make the WireFeed is made available in the SyndFeed. False by default. - */ - public void setPreserveWireFeed(boolean preserveWireFeed) { - this.preserveWireFeed = preserveWireFeed; - } + /** + * + * @param preserveWireFeed set to true to make the WireFeed is made + * available in the SyndFeed. False by default. + */ + public void setPreserveWireFeed(final boolean preserveWireFeed) { + this.preserveWireFeed = preserveWireFeed; + } } diff --git a/src/main/java/com/sun/syndication/io/SyndFeedOutput.java b/src/main/java/com/sun/syndication/io/SyndFeedOutput.java index 27c48b8..698a1fc 100644 --- a/src/main/java/com/sun/syndication/io/SyndFeedOutput.java +++ b/src/main/java/com/sun/syndication/io/SyndFeedOutput.java @@ -16,141 +16,175 @@ */ package com.sun.syndication.io; -import com.sun.syndication.feed.synd.SyndFeed; -import org.jdom2.Document; - import java.io.File; import java.io.IOException; import java.io.Writer; +import org.jdom2.Document; + +import com.sun.syndication.feed.synd.SyndFeed; + /** - * Generates an XML document (String, File, OutputStream, Writer, W3C DOM document or JDOM document) - * out of an SyndFeedImpl.. + * Generates an XML document (String, File, OutputStream, Writer, W3C DOM + * document or JDOM document) out of an SyndFeedImpl.. *

* It delegates to a WireFeedOutput to generate all feed types. *

+ * * @author Alejandro Abdelnur - * + * */ public class SyndFeedOutput { - private WireFeedOutput _feedOutput; + private final WireFeedOutput _feedOutput; /** * Creates a SyndFeedOutput instance. *

- * + * */ public SyndFeedOutput() { - _feedOutput = new WireFeedOutput(); + this._feedOutput = new WireFeedOutput(); } /** * Creates a String with the XML representation for the given SyndFeedImpl. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure that if the String is written to a character stream the stream charset is the same as - * the feed encoding property. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * that if the String is written to a character stream the stream charset is + * the same as the feed encoding property. *

- * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create XML representation from. The type of + * the SyndFeedImpl must match the type given to the FeedOuptut + * constructor. * @return a String with the XML representation for the given SyndFeedImpl. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public String outputString(SyndFeed feed) throws FeedException { - return _feedOutput.outputString(feed.createWireFeed()); + public String outputString(final SyndFeed feed) throws FeedException { + return this._feedOutput.outputString(feed.createWireFeed()); } /** * Creates a String with the XML representation for the given SyndFeedImpl. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure that if the String is written to a character stream the stream charset is the same as - * the feed encoding property. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * that if the String is written to a character stream the stream charset is + * the same as the feed encoding property. *

- * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create XML representation from. The type of + * the SyndFeedImpl must match the type given to the FeedOuptut + * constructor. * @param prettyPrint pretty-print XML (true) oder collapsed * @return a String with the XML representation for the given SyndFeedImpl. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public String outputString(SyndFeed feed,boolean prettyPrint) throws FeedException { - return _feedOutput.outputString(feed.createWireFeed(),prettyPrint); + public String outputString(final SyndFeed feed, final boolean prettyPrint) throws FeedException { + return this._feedOutput.outputString(feed.createWireFeed(), prettyPrint); } /** - * Creates a File containing with the XML representation for the given SyndFeedImpl. + * Creates a File containing with the XML representation for the given + * SyndFeedImpl. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform - * default charset encoding is used to write the feed to the file. It is the responsibility - * of the developer to ensure the feed encoding is set to the platform charset encoding. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. The platform default charset encoding is used to + * write the feed to the file. It is the responsibility of the developer to + * ensure the feed encoding is set to the platform charset encoding. *

- * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. - * @param file the file where to write the XML representation for the given SyndFeedImpl. + * + * @param feed Abstract feed to create XML representation from. The type of + * the SyndFeedImpl must match the type given to the FeedOuptut + * constructor. + * @param file the file where to write the XML representation for the given + * SyndFeedImpl. * @throws IOException thrown if there was some problem writing to the File. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(SyndFeed feed,File file) throws IOException, FeedException { - _feedOutput.output(feed.createWireFeed(),file); + public void output(final SyndFeed feed, final File file) throws IOException, FeedException { + this._feedOutput.output(feed.createWireFeed(), file); } /** - * Creates a File containing with the XML representation for the given SyndFeedImpl. + * Creates a File containing with the XML representation for the given + * SyndFeedImpl. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform - * default charset encoding is used to write the feed to the file. It is the responsibility - * of the developer to ensure the feed encoding is set to the platform charset encoding. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. The platform default charset encoding is used to + * write the feed to the file. It is the responsibility of the developer to + * ensure the feed encoding is set to the platform charset encoding. *

- * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create XML representation from. The type of + * the SyndFeedImpl must match the type given to the FeedOuptut + * constructor. * @param prettyPrint pretty-print XML (true) oder collapsed - * @param file the file where to write the XML representation for the given SyndFeedImpl. + * @param file the file where to write the XML representation for the given + * SyndFeedImpl. * @throws IOException thrown if there was some problem writing to the File. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(SyndFeed feed,File file,boolean prettyPrint) throws IOException, FeedException { - _feedOutput.output(feed.createWireFeed(),file,prettyPrint); + public void output(final SyndFeed feed, final File file, final boolean prettyPrint) throws IOException, FeedException { + this._feedOutput.output(feed.createWireFeed(), file, prettyPrint); } /** * Writes to an Writer the XML representation for the given SyndFeedImpl. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure that if the String is written to a character stream the stream charset is the same as - * the feed encoding property. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * that if the String is written to a character stream the stream charset is + * the same as the feed encoding property. *

- * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. - * @param writer Writer to write the XML representation for the given SyndFeedImpl. - * @throws IOException thrown if there was some problem writing to the Writer. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * + * @param feed Abstract feed to create XML representation from. The type of + * the SyndFeedImpl must match the type given to the FeedOuptut + * constructor. + * @param writer Writer to write the XML representation for the given + * SyndFeedImpl. + * @throws IOException thrown if there was some problem writing to the + * Writer. + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(SyndFeed feed,Writer writer) throws IOException, FeedException { - _feedOutput.output(feed.createWireFeed(),writer); + public void output(final SyndFeed feed, final Writer writer) throws IOException, FeedException { + this._feedOutput.output(feed.createWireFeed(), writer); } /** * Writes to an Writer the XML representation for the given SyndFeedImpl. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure that if the String is written to a character stream the stream charset is the same as - * the feed encoding property. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * that if the String is written to a character stream the stream charset is + * the same as the feed encoding property. *

- * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create XML representation from. The type of + * the SyndFeedImpl must match the type given to the FeedOuptut + * constructor. * @param prettyPrint pretty-print XML (true) oder collapsed - * @param writer Writer to write the XML representation for the given SyndFeedImpl. - * @throws IOException thrown if there was some problem writing to the Writer. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @param writer Writer to write the XML representation for the given + * SyndFeedImpl. + * @throws IOException thrown if there was some problem writing to the + * Writer. + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(SyndFeed feed,Writer writer,boolean prettyPrint) throws IOException, FeedException { - _feedOutput.output(feed.createWireFeed(),writer,prettyPrint); + public void output(final SyndFeed feed, final Writer writer, final boolean prettyPrint) throws IOException, FeedException { + this._feedOutput.output(feed.createWireFeed(), writer, prettyPrint); } /** @@ -158,14 +192,17 @@ public class SyndFeedOutput { *

* This method does not use the feed encoding property. *

- * @param feed Abstract feed to create W3C DOM document from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create W3C DOM document from. The type of + * the SyndFeedImpl must match the type given to the FeedOuptut + * constructor. * @return the W3C DOM document for the given SyndFeedImpl. - * @throws FeedException thrown if the W3C DOM document for the feed could not be created. - * + * @throws FeedException thrown if the W3C DOM document for the feed could + * not be created. + * */ - public org.w3c.dom.Document outputW3CDom(SyndFeed feed) throws FeedException { - return _feedOutput.outputW3CDom(feed.createWireFeed()); + public org.w3c.dom.Document outputW3CDom(final SyndFeed feed) throws FeedException { + return this._feedOutput.outputW3CDom(feed.createWireFeed()); } /** @@ -173,14 +210,17 @@ public class SyndFeedOutput { *

* This method does not use the feed encoding property. *

- * @param feed Abstract feed to create JDOM document from. The type of the SyndFeedImpl must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create JDOM document from. The type of the + * SyndFeedImpl must match the type given to the FeedOuptut + * constructor. * @return the JDOM document for the given SyndFeedImpl. - * @throws FeedException thrown if the JDOM document for the feed could not be created. - * + * @throws FeedException thrown if the JDOM document for the feed could not + * be created. + * */ - public Document outputJDom(SyndFeed feed) throws FeedException { - return _feedOutput.outputJDom(feed.createWireFeed()); + public Document outputJDom(final SyndFeed feed) throws FeedException { + return this._feedOutput.outputJDom(feed.createWireFeed()); } } diff --git a/src/main/java/com/sun/syndication/io/WireFeedGenerator.java b/src/main/java/com/sun/syndication/io/WireFeedGenerator.java index 960b486..2fc66cb 100644 --- a/src/main/java/com/sun/syndication/io/WireFeedGenerator.java +++ b/src/main/java/com/sun/syndication/io/WireFeedGenerator.java @@ -16,10 +16,10 @@ */ package com.sun.syndication.io; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.io.FeedException; import org.jdom2.Document; +import com.sun.syndication.feed.WireFeed; + /** * Generates an XML document (JDOM) out of a feed for a specific real feed type. *

@@ -27,31 +27,34 @@ import org.jdom2.Document; *

* TODO: explain how developers can plugin their own implementations. *

+ * * @author Alejandro Abdelnur - * + * */ public interface WireFeedGenerator { /** * Returns the type of feed the generator creates. *

+ * * @see WireFeed for details on the format of this string. - *

+ *

* @return the type of feed the generator creates. - * + * */ public String getType(); /** * 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. - * + * */ - public Document generate(WireFeed feed) throws IllegalArgumentException,FeedException; + public Document generate(WireFeed feed) throws IllegalArgumentException, FeedException; } diff --git a/src/main/java/com/sun/syndication/io/WireFeedInput.java b/src/main/java/com/sun/syndication/io/WireFeedInput.java index 2a311e9..d7bca05 100644 --- a/src/main/java/com/sun/syndication/io/WireFeedInput.java +++ b/src/main/java/com/sun/syndication/io/WireFeedInput.java @@ -30,6 +30,7 @@ import org.jdom2.Document; import org.jdom2.JDOMException; import org.jdom2.input.DOMBuilder; import org.jdom2.input.JDOMParseException; +import org.jdom2.input.sax.XMLReaders; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXNotRecognizedException; @@ -39,28 +40,28 @@ import org.xml.sax.XMLReader; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.io.impl.FeedParsers; import com.sun.syndication.io.impl.XmlFixerReader; -import org.jdom2.input.sax.XMLReaders; /** - * Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument) - * into an WireFeed (RSS/Atom). + * Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C + * DOM Document or JDom DOcument) into an WireFeed (RSS/Atom). *

* It accepts all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and - * Atom 0.3 feeds. Parsers are plugable (they must implement the WireFeedParser interface). + * Atom 0.3 feeds. Parsers are plugable (they must implement the WireFeedParser + * interface). *

* The WireFeedInput useds liberal parsers. *

+ * * @author Alejandro Abdelnur - * + * */ public class WireFeedInput { private static Map clMap = new WeakHashMap(); private static FeedParsers getFeedParsers() { - synchronized(WireFeedInput.class) { - FeedParsers parsers = (FeedParsers) - clMap.get(Thread.currentThread().getContextClassLoader()); + synchronized (WireFeedInput.class) { + FeedParsers parsers = (FeedParsers) clMap.get(Thread.currentThread().getContextClassLoader()); if (parsers == null) { parsers = new FeedParsers(); clMap.put(Thread.currentThread().getContextClassLoader(), parsers); @@ -73,23 +74,27 @@ public class WireFeedInput { private static final EntityResolver RESOLVER = new EmptyEntityResolver(); private static class EmptyEntityResolver implements EntityResolver { - public InputSource resolveEntity(String publicId, String systemId) { - if(systemId != null && systemId.endsWith(".dtd")) return EMPTY_INPUTSOURCE; + @Override + public InputSource resolveEntity(final String publicId, final String systemId) { + if (systemId != null && systemId.endsWith(".dtd")) { + return EMPTY_INPUTSOURCE; + } return null; } } - private boolean _validate; + private final boolean _validate; private boolean _xmlHealerOn; /** * Returns the list of supported input feed types. *

+ * * @see WireFeed for details on the format of these strings. - *

+ *

* @return a list of String elements with the supported input feed types. - * + * */ public static List getSupportedFeedTypes() { return getFeedParsers().getSupportedFeedTypes(); @@ -98,79 +103,93 @@ public class WireFeedInput { /** * Creates a WireFeedInput instance with input validation turned off. *

- * + * */ public WireFeedInput() { - this (false); + this(false); } /** * Creates a WireFeedInput instance. *

- * @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen) - * + * + * @param validate indicates if the input should be validated. NOT + * IMPLEMENTED YET (validation does not happen) + * */ - public WireFeedInput(boolean validate) { - _validate = false; // TODO FIX THIS THINGY - _xmlHealerOn = true; + public WireFeedInput(final boolean validate) { + this._validate = false; // TODO FIX THIS THINGY + this._xmlHealerOn = true; } /** * Enables XML healing in the WiredFeedInput instance. *

- * Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog. + * Healing trims leading chars from the stream (empty spaces and comments) + * until the XML prolog. *

- * Healing resolves HTML entities (from literal to code number) in the reader. + * Healing resolves HTML entities (from literal to code number) in the + * reader. *

- * The healing is done only with the build(File) and build(Reader) signatures. + * The healing is done only with the build(File) and build(Reader) + * signatures. *

* By default is TRUE. *

+ * * @param heals TRUE enables stream healing, FALSE disables it. - * + * */ - public void setXmlHealerOn(boolean heals) { - _xmlHealerOn = heals; + public void setXmlHealerOn(final boolean heals) { + this._xmlHealerOn = heals; } /** - * Indicates if the WiredFeedInput instance will XML heal (if necessary) the character stream. + * Indicates if the WiredFeedInput instance will XML heal (if necessary) the + * character stream. *

- * Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog. + * Healing trims leading chars from the stream (empty spaces and comments) + * until the XML prolog. *

- * Healing resolves HTML entities (from literal to code number) in the reader. + * Healing resolves HTML entities (from literal to code number) in the + * reader. *

- * The healing is done only with the build(File) and build(Reader) signatures. + * The healing is done only with the build(File) and build(Reader) + * signatures. *

* By default is TRUE. *

+ * * @return TRUE if healing is enabled, FALSE if not. - * + * */ public boolean getXmlHealerOn() { - return _xmlHealerOn; + return this._xmlHealerOn; } /** * Builds an WireFeed (RSS or Atom) from a file. *

- * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. + * NOTE: This method delages to the 'AsbtractFeed + * WireFeedInput#build(org.jdom2.Document)'. *

+ * * @param file file to read to create the WireFeed. * @return the WireFeed read from the file. * @throws FileNotFoundException thrown if the file could not be found. * @throws IOException thrown if there is problem reading the file. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public WireFeed build(File file) throws FileNotFoundException,IOException,IllegalArgumentException,FeedException { + public WireFeed build(final File file) throws FileNotFoundException, IOException, IllegalArgumentException, FeedException { WireFeed feed; Reader reader = new FileReader(file); - if (_xmlHealerOn) { + if (this._xmlHealerOn) { reader = new XmlFixerReader(reader); } - feed = build(reader); + feed = this.build(reader); reader.close(); return feed; } @@ -178,84 +197,85 @@ public class WireFeedInput { /** * Builds an WireFeed (RSS or Atom) from an Reader. *

- * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. + * NOTE: This method delages to the 'AsbtractFeed + * WireFeedInput#build(org.jdom2.Document)'. *

+ * * @param reader Reader to read to create the WireFeed. * @return the WireFeed read from the Reader. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public WireFeed build(Reader reader) throws IllegalArgumentException,FeedException { - SAXBuilder saxBuilder = createSAXBuilder(); + public WireFeed build(Reader reader) throws IllegalArgumentException, FeedException { + final SAXBuilder saxBuilder = createSAXBuilder(); try { - if (_xmlHealerOn) { + if (this._xmlHealerOn) { reader = new XmlFixerReader(reader); - } - Document document = saxBuilder.build(reader); - return build(document); - } - catch (JDOMParseException ex) { + } + final Document document = saxBuilder.build(reader); + return this.build(document); + } catch (final JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); - } - catch (IllegalArgumentException ex) { + } catch (final IllegalArgumentException ex) { throw ex; - } - catch (Exception ex) { - throw new ParsingFeedException("Invalid XML",ex); + } catch (final Exception ex) { + throw new ParsingFeedException("Invalid XML", ex); } } /** * Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource. *

- * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. + * NOTE: This method delages to the 'AsbtractFeed + * WireFeedInput#build(org.jdom2.Document)'. *

+ * * @param is W3C SAX InputSource to read to create the WireFeed. * @return the WireFeed read from the W3C SAX InputSource. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public WireFeed build(InputSource is) throws IllegalArgumentException,FeedException { - SAXBuilder saxBuilder = createSAXBuilder(); + public WireFeed build(final InputSource is) throws IllegalArgumentException, FeedException { + final SAXBuilder saxBuilder = createSAXBuilder(); try { - Document document = saxBuilder.build(is); - return build(document); - } - catch (JDOMParseException ex) { + final Document document = saxBuilder.build(is); + return this.build(document); + } catch (final JDOMParseException ex) { throw new ParsingFeedException("Invalid XML: " + ex.getMessage(), ex); - } - catch (IllegalArgumentException ex) { + } catch (final IllegalArgumentException ex) { throw ex; - } - catch (Exception ex) { - throw new ParsingFeedException("Invalid XML",ex); + } catch (final Exception ex) { + throw new ParsingFeedException("Invalid XML", ex); } } /** * Builds an WireFeed (RSS or Atom) from an W3C DOM document. *

- * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'. + * NOTE: This method delages to the 'AsbtractFeed + * WireFeedInput#build(org.jdom2.Document)'. *

+ * * @param document W3C DOM document to read to create the WireFeed. * @return the WireFeed read from the W3C DOM document. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public WireFeed build(org.w3c.dom.Document document) throws IllegalArgumentException,FeedException { - DOMBuilder domBuilder = new DOMBuilder(); + public WireFeed build(final org.w3c.dom.Document document) throws IllegalArgumentException, FeedException { + final DOMBuilder domBuilder = new DOMBuilder(); try { - Document jdomDoc = domBuilder.build(document); - return build(jdomDoc); - } - catch (IllegalArgumentException ex) { + final Document jdomDoc = domBuilder.build(document); + return this.build(jdomDoc); + } catch (final IllegalArgumentException ex) { throw ex; - } - catch (Exception ex) { - throw new ParsingFeedException("Invalid XML",ex); + } catch (final Exception ex) { + throw new ParsingFeedException("Invalid XML", ex); } } @@ -264,18 +284,20 @@ public class WireFeedInput { *

* NOTE: All other build methods delegate to this method. *

+ * * @param document JDOM document to read to create the WireFeed. * @return the WireFeed read from the JDOM document. - * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. + * @throws IllegalArgumentException thrown if feed type could not be + * understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed - * + * */ - public WireFeed build(Document document) throws IllegalArgumentException,FeedException { - WireFeedParser parser = getFeedParsers().getParserFor(document); - if (parser==null) { + public WireFeed build(final Document document) throws IllegalArgumentException, FeedException { + final WireFeedParser parser = getFeedParsers().getParserFor(document); + if (parser == null) { throw new IllegalArgumentException("Invalid document"); } - return parser.parse(document, _validate); + return parser.parse(document, this._validate); } /** @@ -284,52 +306,57 @@ public class WireFeedInput { * @return a new org.jdom2.input.SAXBuilder object */ protected SAXBuilder createSAXBuilder() { - SAXBuilder saxBuilder = new SAXBuilder(_validate ? XMLReaders.DTDVALIDATING : XMLReaders.NONVALIDATING); + final SAXBuilder saxBuilder = new SAXBuilder(this._validate ? XMLReaders.DTDVALIDATING : XMLReaders.NONVALIDATING); saxBuilder.setEntityResolver(RESOLVER); // - // This code is needed to fix the security problem outlined in http://www.securityfocus.com/archive/1/297714 + // This code is needed to fix the security problem outlined in + // http://www.securityfocus.com/archive/1/297714 // - // Unfortunately there isn't an easy way to check if an XML parser supports a particular feature, so - // we need to set it and catch the exception if it fails. We also need to subclass the JDom SAXBuilder - // class in order to get access to the underlying SAX parser - otherwise the features don't get set until - // we are already building the document, by which time it's too late to fix the problem. + // Unfortunately there isn't an easy way to check if an XML parser + // supports a particular feature, so + // we need to set it and catch the exception if it fails. We also need + // to subclass the JDom SAXBuilder + // class in order to get access to the underlying SAX parser - otherwise + // the features don't get set until + // we are already building the document, by which time it's too late to + // fix the problem. // // Crimson is one parser which is known not to support these features. - try { - XMLReader parser = saxBuilder.createParser(); - try { - parser.setFeature("http://xml.org/sax/features/external-general-entities", false); - saxBuilder.setFeature("http://xml.org/sax/features/external-general-entities", false); - } catch (SAXNotRecognizedException e) { - // ignore - } catch (SAXNotSupportedException e) { - // ignore - } - - try { - parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - saxBuilder.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - } catch (SAXNotRecognizedException e) { - // ignore - } catch (SAXNotSupportedException e) { - // ignore - } + try { + final XMLReader parser = saxBuilder.createParser(); + try { + parser.setFeature("http://xml.org/sax/features/external-general-entities", false); + saxBuilder.setFeature("http://xml.org/sax/features/external-general-entities", false); + } catch (final SAXNotRecognizedException e) { + // ignore + } catch (final SAXNotSupportedException e) { + // ignore + } - try { - parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); - saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); - } catch (SAXNotRecognizedException e) { - // ignore - } catch (SAXNotSupportedException e) { - // ignore - } - - } catch (JDOMException e) { - throw new IllegalStateException("JDOM could not create a SAX parser"); - } + try { + parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + saxBuilder.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + } catch (final SAXNotRecognizedException e) { + // ignore + } catch (final SAXNotSupportedException e) { + // ignore + } - saxBuilder.setExpandEntities(false); + try { + parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + } catch (final SAXNotRecognizedException e) { + // ignore + } catch (final SAXNotSupportedException e) { + // ignore + } + + } catch (final JDOMException e) { + throw new IllegalStateException("JDOM could not create a SAX parser"); + } + + saxBuilder.setExpandEntities(false); return saxBuilder; } } diff --git a/src/main/java/com/sun/syndication/io/WireFeedOutput.java b/src/main/java/com/sun/syndication/io/WireFeedOutput.java index 736aa82..d5c4038 100644 --- a/src/main/java/com/sun/syndication/io/WireFeedOutput.java +++ b/src/main/java/com/sun/syndication/io/WireFeedOutput.java @@ -16,39 +16,41 @@ */ package com.sun.syndication.io; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.io.impl.FeedGenerators; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; + import org.jdom2.Document; import org.jdom2.JDOMException; import org.jdom2.output.DOMOutputter; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; -import java.io.IOException; -import java.io.Writer; -import java.io.File; -import java.io.FileWriter; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.io.impl.FeedGenerators; /** - * Generates an XML document (String, File, OutputStream, Writer, W3C DOM document or JDOM document) - * out of an WireFeed (RSS/Atom). + * Generates an XML document (String, File, OutputStream, Writer, W3C DOM + * document or JDOM document) out of an WireFeed (RSS/Atom). *

- * It generates all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and - * Atom 0.3 feeds. Generators are plugable (they must implement the ModuleParser interface). + * It generates all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) + * and Atom 0.3 feeds. Generators are plugable (they must implement the + * ModuleParser interface). *

+ * * @author Alejandro Abdelnur - * + * */ public class WireFeedOutput { private static Map clMap = new WeakHashMap(); private static FeedGenerators getFeedGenerators() { - synchronized(WireFeedOutput.class) { - FeedGenerators generators = (FeedGenerators) - clMap.get(Thread.currentThread().getContextClassLoader()); + synchronized (WireFeedOutput.class) { + FeedGenerators generators = (FeedGenerators) clMap.get(Thread.currentThread().getContextClassLoader()); if (generators == null) { generators = new FeedGenerators(); clMap.put(Thread.currentThread().getContextClassLoader(), generators); @@ -60,10 +62,11 @@ public class WireFeedOutput { /** * Returns the list of supported output feed types. *

+ * * @see WireFeed for details on the format of these strings. - *

+ *

* @return a list of String elements with the supported output feed types. - * + * */ public static List getSupportedFeedTypes() { return getFeedGenerators().getSupportedFeedTypes(); @@ -72,7 +75,7 @@ public class WireFeedOutput { /** * Creates a FeedOuput instance. *

- * + * */ public WireFeedOutput() { } @@ -80,142 +83,186 @@ public class WireFeedOutput { /** * Creates a String with the XML representation for the given WireFeed. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure that if the String is written to a character stream the stream charset is the same as - * the feed encoding property. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * that if the String is written to a character stream the stream charset is + * the same as the feed encoding property. *

- * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. + * NOTE: This method delages to the 'Document + * WireFeedOutput#outputJDom(WireFeed)'. *

- * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create XML representation from. The type of + * the WireFeed must match the type given to the FeedOuptut + * constructor. * @return a String with the XML representation for the given WireFeed. - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public String outputString(WireFeed feed) throws IllegalArgumentException,FeedException { - return outputString(feed, true); + public String outputString(final WireFeed feed) throws IllegalArgumentException, FeedException { + return this.outputString(feed, true); } /** * Creates a String with the XML representation for the given WireFeed. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure that if the String is written to a character stream the stream charset is the same as - * the feed encoding property. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * that if the String is written to a character stream the stream charset is + * the same as the feed encoding property. *

- * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. + * NOTE: This method delages to the 'Document + * WireFeedOutput#outputJDom(WireFeed)'. *

- * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create XML representation from. The type of + * the WireFeed must match the type given to the FeedOuptut + * constructor. * @param prettyPrint pretty-print XML (true) oder collapsed * @return a String with the XML representation for the given WireFeed. - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException { - Document doc = outputJDom(feed); - String encoding = feed.getEncoding(); - Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); - if (encoding!=null) { + public String outputString(final WireFeed feed, final boolean prettyPrint) throws IllegalArgumentException, FeedException { + final Document doc = outputJDom(feed); + final String encoding = feed.getEncoding(); + final Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); + if (encoding != null) { format.setEncoding(encoding); } - XMLOutputter outputter = new XMLOutputter(format); + final XMLOutputter outputter = new XMLOutputter(format); return outputter.outputString(doc); } /** - * Creates a File containing with the XML representation for the given WireFeed. + * Creates a File containing with the XML representation for the given + * WireFeed. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform - * default charset encoding is used to write the feed to the file. It is the responsibility - * of the developer to ensure the feed encoding is set to the platform charset encoding. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. The platform default charset encoding is used to + * write the feed to the file. It is the responsibility of the developer to + * ensure the feed encoding is set to the platform charset encoding. *

- * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. + * NOTE: This method delages to the 'Document + * WireFeedOutput#outputJDom(WireFeed)'. *

- * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. - * @param file the file where to write the XML representation for the given WireFeed. - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. + * + * @param feed Abstract feed to create XML representation from. The type of + * the WireFeed must match the type given to the FeedOuptut + * constructor. + * @param file the file where to write the XML representation for the given + * WireFeed. + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. * @throws IOException thrown if there was some problem writing to the File. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(WireFeed feed,File file) throws IllegalArgumentException,IOException,FeedException { - output(feed,file,true); + public void output(final WireFeed feed, final File file) throws IllegalArgumentException, IOException, FeedException { + this.output(feed, file, true); } /** - * Creates a File containing with the XML representation for the given WireFeed. + * Creates a File containing with the XML representation for the given + * WireFeed. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The platform - * default charset encoding is used to write the feed to the file. It is the responsibility - * of the developer to ensure the feed encoding is set to the platform charset encoding. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. The platform default charset encoding is used to + * write the feed to the file. It is the responsibility of the developer to + * ensure the feed encoding is set to the platform charset encoding. *

- * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. + * NOTE: This method delages to the 'Document + * WireFeedOutput#outputJDom(WireFeed)'. *

- * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. - * @param file the file where to write the XML representation for the given WireFeed. + * + * @param feed Abstract feed to create XML representation from. The type of + * the WireFeed must match the type given to the FeedOuptut + * constructor. + * @param file the file where to write the XML representation for the given + * WireFeed. * @param prettyPrint pretty-print XML (true) oder collapsed - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. * @throws IOException thrown if there was some problem writing to the File. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(WireFeed feed,File file,boolean prettyPrint) throws IllegalArgumentException,IOException,FeedException { - Writer writer = new FileWriter(file); - output(feed,writer,prettyPrint); + public void output(final WireFeed feed, final File file, final boolean prettyPrint) throws IllegalArgumentException, IOException, FeedException { + final Writer writer = new FileWriter(file); + this.output(feed, writer, prettyPrint); writer.close(); } /** * Writes to an Writer the XML representation for the given WireFeed. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure the Writer instance is using the same charset encoding. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * the Writer instance is using the same charset encoding. *

- * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. + * NOTE: This method delages to the 'Document + * WireFeedOutput#outputJDom(WireFeed)'. *

- * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. - * @param writer Writer to write the XML representation for the given WireFeed. - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. - * @throws IOException thrown if there was some problem writing to the Writer. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * + * @param feed Abstract feed to create XML representation from. The type of + * the WireFeed must match the type given to the FeedOuptut + * constructor. + * @param writer Writer to write the XML representation for the given + * WireFeed. + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. + * @throws IOException thrown if there was some problem writing to the + * Writer. + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(WireFeed feed,Writer writer) throws IllegalArgumentException,IOException, FeedException { - output(feed,writer,true); + public void output(final WireFeed feed, final Writer writer) throws IllegalArgumentException, IOException, FeedException { + this.output(feed, writer, true); } /** * Writes to an Writer the XML representation for the given WireFeed. *

- * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility - * of the developer to ensure the Writer instance is using the same charset encoding. + * If the feed encoding is not NULL, it will be used in the XML prolog + * encoding attribute. It is the responsibility of the developer to ensure + * the Writer instance is using the same charset encoding. *

- * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. + * NOTE: This method delages to the 'Document + * WireFeedOutput#outputJDom(WireFeed)'. *

- * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. - * @param writer Writer to write the XML representation for the given WireFeed. + * + * @param feed Abstract feed to create XML representation from. The type of + * the WireFeed must match the type given to the FeedOuptut + * constructor. + * @param writer Writer to write the XML representation for the given + * WireFeed. * @param prettyPrint pretty-print XML (true) oder collapsed - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. - * @throws IOException thrown if there was some problem writing to the Writer. - * @throws FeedException thrown if the XML representation for the feed could not be created. - * + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. + * @throws IOException thrown if there was some problem writing to the + * Writer. + * @throws FeedException thrown if the XML representation for the feed could + * not be created. + * */ - public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException { - Document doc = outputJDom(feed); - String encoding = feed.getEncoding(); - Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); - if (encoding!=null) { + public void output(final WireFeed feed, final Writer writer, final boolean prettyPrint) throws IllegalArgumentException, IOException, FeedException { + final Document doc = outputJDom(feed); + final String encoding = feed.getEncoding(); + final Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); + if (encoding != null) { format.setEncoding(encoding); } - XMLOutputter outputter = new XMLOutputter(format); - outputter.output(doc,writer); + final XMLOutputter outputter = new XMLOutputter(format); + outputter.output(doc, writer); } /** @@ -223,23 +270,27 @@ public class WireFeedOutput { *

* This method does not use the feed encoding property. *

- * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. + * NOTE: This method delages to the 'Document + * WireFeedOutput#outputJDom(WireFeed)'. *

- * @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create W3C DOM document from. The type of + * the WireFeed must match the type given to the FeedOuptut + * constructor. * @return the W3C DOM document for the given WireFeed. - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. - * @throws FeedException thrown if the W3C DOM document for the feed could not be created. - * + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. + * @throws FeedException thrown if the W3C DOM document for the feed could + * not be created. + * */ - public org.w3c.dom.Document outputW3CDom(WireFeed feed) throws IllegalArgumentException,FeedException { - Document doc = outputJDom(feed); - DOMOutputter outputter = new DOMOutputter(); + public org.w3c.dom.Document outputW3CDom(final WireFeed feed) throws IllegalArgumentException, FeedException { + final Document doc = outputJDom(feed); + final DOMOutputter outputter = new DOMOutputter(); try { return outputter.output(doc); - } - catch (JDOMException jdomEx) { - throw new FeedException("Could not create DOM",jdomEx); + } catch (final JDOMException jdomEx) { + throw new FeedException("Could not create DOM", jdomEx); } } @@ -250,23 +301,26 @@ public class WireFeedOutput { *

* NOTE: All other output methods delegate to this method. *

- * @param feed Abstract feed to create JDOM document from. The type of the WireFeed must match - * the type given to the FeedOuptut constructor. + * + * @param feed Abstract feed to create JDOM document from. The type of the + * WireFeed must match the type given to the FeedOuptut + * constructor. * @return the JDOM document for the given WireFeed. - * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. - * @throws FeedException thrown if the JDOM document for the feed could not be created. - * + * @throws IllegalArgumentException thrown if the feed type of the + * WireFeedOutput and WireFeed don't match. + * @throws FeedException thrown if the JDOM document for the feed could not + * be created. + * */ - public Document outputJDom(WireFeed feed) throws IllegalArgumentException,FeedException { - String type = feed.getFeedType(); - WireFeedGenerator generator = getFeedGenerators().getGenerator(type); - if (generator==null) { - throw new IllegalArgumentException("Invalid feed type ["+type+"]"); + public Document outputJDom(final WireFeed feed) throws IllegalArgumentException, FeedException { + final String type = feed.getFeedType(); + final WireFeedGenerator generator = getFeedGenerators().getGenerator(type); + if (generator == null) { + throw new IllegalArgumentException("Invalid feed type [" + type + "]"); } if (!generator.getType().equals(type)) { - throw new IllegalArgumentException("WireFeedOutput type["+type+"] and WireFeed type ["+ - type+"] don't match"); + throw new IllegalArgumentException("WireFeedOutput type[" + type + "] and WireFeed type [" + type + "] don't match"); } return generator.generate(feed); } diff --git a/src/main/java/com/sun/syndication/io/WireFeedParser.java b/src/main/java/com/sun/syndication/io/WireFeedParser.java index 486ecff..d01c82b 100644 --- a/src/main/java/com/sun/syndication/io/WireFeedParser.java +++ b/src/main/java/com/sun/syndication/io/WireFeedParser.java @@ -16,10 +16,10 @@ */ package com.sun.syndication.io; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.io.FeedException; import org.jdom2.Document; +import com.sun.syndication.feed.WireFeed; + /** * Parses an XML document (JDOM) into a feed bean. *

@@ -27,43 +27,52 @@ import org.jdom2.Document; *

* TODO: explain how developers can plugin their own implementations. *

+ * * @author Alejandro Abdelnur - * + * */ public interface WireFeedParser { /** * Returns the type of feed the parser handles. *

+ * * @see WireFeed for details on the format of this string. - *

+ *

* @return the type of feed the parser handles. - * + * */ public String getType(); /** * 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. + * 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. - * + * + * @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); /** * 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). + * @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). - * + * @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; - + public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException; } diff --git a/src/main/java/com/sun/syndication/io/XmlReader.java b/src/main/java/com/sun/syndication/io/XmlReader.java index 07c7915..d90866c 100644 --- a/src/main/java/com/sun/syndication/io/XmlReader.java +++ b/src/main/java/com/sun/syndication/io/XmlReader.java @@ -16,37 +16,47 @@ */ package com.sun.syndication.io; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; -import java.net.HttpURLConnection; -import java.util.regex.Pattern; -import java.util.regex.Matcher; import java.text.MessageFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** - * Character stream that handles (or at least attemtps to) all the necessary Voodo to figure out - * the charset encoding of the XML document within the stream. + * Character stream that handles (or at least attemtps to) all the necessary + * Voodo to figure out the charset encoding of the XML document within the + * stream. *

- * IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader. This one IS a - * character stream. + * IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader. + * This one IS a character stream. *

- * All this has to be done without consuming characters from the stream, if not the XML parser - * will not recognized the document as a valid XML. This is not 100% true, but it's close enough - * (UTF-8 BOM is not handled by all parsers right now, XmlReader handles it and things work in all - * parsers). + * All this has to be done without consuming characters from the stream, if not + * the XML parser will not recognized the document as a valid XML. This is not + * 100% true, but it's close enough (UTF-8 BOM is not handled by all parsers + * right now, XmlReader handles it and things work in all parsers). *

- * The XmlReader class handles the charset encoding of XML documents in Files, raw streams and - * HTTP streams by offering a wide set of constructors. + * The XmlReader class handles the charset encoding of XML documents in Files, + * raw streams and HTTP streams by offering a wide set of constructors. *

- * By default the charset encoding detection is lenient, the constructor with the lenient flag - * can be used for an script (following HTTP MIME and XML specifications). - * All this is nicely explained by Mark Pilgrim in his blog, - * + * By default the charset encoding detection is lenient, the constructor with + * the lenient flag can be used for an script (following HTTP MIME and XML + * specifications). All this is nicely explained by Mark Pilgrim in his blog, * Determining the character encoding of a feed. *

+ * * @author Alejandro Abdelnur - * + * */ public class XmlReader extends Reader { private static final int BUFFER_SIZE = 4096; @@ -61,20 +71,20 @@ public class XmlReader extends Reader { private Reader _reader; private String _encoding; - private String _defaultEncoding; + private final String _defaultEncoding; /** - * Sets the default encoding to use if none is set in HTTP content-type, - * XML prolog and the rules based on content-type are not adequate. + * Sets the default encoding to use if none is set in HTTP content-type, XML + * prolog and the rules based on content-type are not adequate. *

* If it is set to NULL the content-type based rules are used. *

* By default it is NULL. *

- * + * * @param encoding charset encoding to default to. */ - public static void setDefaultEncoding(String encoding) { + public static void setDefaultEncoding(final String encoding) { _staticDefaultEncoding = encoding; } @@ -84,7 +94,7 @@ public class XmlReader extends Reader { *

* If it is NULL the content-type based rules are used. *

- * + * * @return the default encoding to use. */ public static String getDefaultEncoding() { @@ -94,17 +104,18 @@ public class XmlReader extends Reader { /** * Creates a Reader for a File. *

- * It looks for the UTF-8 BOM first, if none sniffs the XML prolog charset, if this is also - * missing defaults to UTF-8. + * It looks for the UTF-8 BOM first, if none sniffs the XML prolog charset, + * if this is also missing defaults to UTF-8. *

- * It does a lenient charset encoding detection, check the constructor with the lenient parameter - * for details. + * It does a lenient charset encoding detection, check the constructor with + * the lenient parameter for details. *

+ * * @param file File to create a Reader from. * @throws IOException thrown if there is a problem reading the file. - * + * */ - public XmlReader(File file) throws IOException { + public XmlReader(final File file) throws IOException { this(new FileInputStream(file)); } @@ -113,26 +124,29 @@ public class XmlReader extends Reader { *

* It follows the same logic used for files. *

- * It does a lenient charset encoding detection, check the constructor with the lenient parameter - * for details. + * It does a lenient charset encoding detection, check the constructor with + * the lenient parameter for details. *

+ * * @param is InputStream to create a Reader from. * @throws IOException thrown if there is a problem reading the stream. - * + * */ - public XmlReader(InputStream is) throws IOException { - this(is,true); + public XmlReader(final InputStream is) throws IOException { + this(is, true); } /** - * Creates a Reader for a raw InputStream and uses the provided default encoding if none is determined. + * Creates a Reader for a raw InputStream and uses the provided default + * encoding if none is determined. *

* It follows the same logic used for files. *

- * If lenient detection is indicated and the detection above fails as per specifications it then attempts - * the following: + * If lenient detection is indicated and the detection above fails as per + * specifications it then attempts the following: *

- * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. + * If the content type was 'text/html' it replaces it with 'text/xml' and + * tries the detection again. *

* Else if the XML prolog had a charset encoding that encoding is used. *

@@ -142,25 +156,25 @@ public class XmlReader extends Reader { *

* If lenient detection is indicated an XmlReaderException is never thrown. *

+ * * @param is InputStream to create a Reader from. - * @param lenient indicates if the charset encoding detection should be relaxed. + * @param lenient indicates if the charset encoding detection should be + * relaxed. * @param defaultEncoding default encoding to use if one cannot be detected. * @throws IOException thrown if there is a problem reading the stream. - * @throws XmlReaderException thrown if the charset encoding could not be determined according to the specs. - * + * @throws XmlReaderException thrown if the charset encoding could not be + * determined according to the specs. + * */ - public XmlReader(InputStream is, boolean lenient, String defaultEncoding) - throws IOException, XmlReaderException { - _defaultEncoding = (defaultEncoding == null) ? _staticDefaultEncoding : defaultEncoding; + public XmlReader(final InputStream is, final boolean lenient, final String defaultEncoding) throws IOException, XmlReaderException { + this._defaultEncoding = defaultEncoding == null ? _staticDefaultEncoding : defaultEncoding; try { - doRawStream(is,lenient); - } - catch (XmlReaderException ex) { + doRawStream(is, lenient); + } catch (final XmlReaderException ex) { if (!lenient) { throw ex; - } - else { - doLenientDetection(null,ex); + } else { + doLenientDetection(null, ex); } } } @@ -170,10 +184,11 @@ public class XmlReader extends Reader { *

* It follows the same logic used for files. *

- * If lenient detection is indicated and the detection above fails as per specifications it then attempts - * the following: + * If lenient detection is indicated and the detection above fails as per + * specifications it then attempts the following: *

- * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. + * If the content type was 'text/html' it replaces it with 'text/xml' and + * tries the detection again. *

* Else if the XML prolog had a charset encoding that encoding is used. *

@@ -183,33 +198,39 @@ public class XmlReader extends Reader { *

* If lenient detection is indicated an XmlReaderException is never thrown. *

+ * * @param is InputStream to create a Reader from. - * @param lenient indicates if the charset encoding detection should be relaxed. + * @param lenient indicates if the charset encoding detection should be + * relaxed. * @throws IOException thrown if there is a problem reading the stream. - * @throws XmlReaderException thrown if the charset encoding could not be determined according to the specs. - * + * @throws XmlReaderException thrown if the charset encoding could not be + * determined according to the specs. + * */ - public XmlReader(InputStream is,boolean lenient) throws IOException, XmlReaderException { + public XmlReader(final InputStream is, final boolean lenient) throws IOException, XmlReaderException { this(is, lenient, null); } /** * Creates a Reader using the InputStream of a URL. *

- * If the URL is not of type HTTP and there is not 'content-type' header in the fetched - * data it uses the same logic used for Files. + * If the URL is not of type HTTP and there is not 'content-type' header in + * the fetched data it uses the same logic used for Files. *

- * If the URL is a HTTP Url or there is a 'content-type' header in the fetched - * data it uses the same logic used for an InputStream with content-type. + * If the URL is a HTTP Url or there is a 'content-type' header in the + * fetched data it uses the same logic used for an InputStream with + * content-type. *

- * It does a lenient charset encoding detection, check the constructor with the lenient parameter - * for details. + * It does a lenient charset encoding detection, check the constructor with + * the lenient parameter for details. *

+ * * @param url URL to create a Reader from. - * @throws IOException thrown if there is a problem reading the stream of the URL. - * + * @throws IOException thrown if there is a problem reading the stream of + * the URL. + * */ - public XmlReader(URL url) throws IOException { + public XmlReader(final URL url) throws IOException { this(url.openConnection()); } @@ -217,78 +238,83 @@ public class XmlReader extends Reader { * Creates a Reader using the InputStream of a URLConnection. *

* If the URLConnection is not of type HttpURLConnection and there is not - * 'content-type' header in the fetched data it uses the same logic used for files. + * 'content-type' header in the fetched data it uses the same logic used for + * files. *

- * If the URLConnection is a HTTP Url or there is a 'content-type' header in the fetched - * data it uses the same logic used for an InputStream with content-type. + * If the URLConnection is a HTTP Url or there is a 'content-type' header in + * the fetched data it uses the same logic used for an InputStream with + * content-type. *

- * It does a lenient charset encoding detection, check the constructor with the lenient parameter - * for details. + * It does a lenient charset encoding detection, check the constructor with + * the lenient parameter for details. *

+ * * @param conn URLConnection to create a Reader from. - * @throws IOException thrown if there is a problem reading the stream of the URLConnection. - * + * @throws IOException thrown if there is a problem reading the stream of + * the URLConnection. + * */ - public XmlReader(URLConnection conn) throws IOException { - _defaultEncoding = _staticDefaultEncoding; - boolean lenient = true; + public XmlReader(final URLConnection conn) throws IOException { + this._defaultEncoding = _staticDefaultEncoding; + final boolean lenient = true; if (conn instanceof HttpURLConnection) { try { - doHttpStream(conn.getInputStream(),conn.getContentType(),lenient); + doHttpStream(conn.getInputStream(), conn.getContentType(), lenient); + } catch (final XmlReaderException ex) { + doLenientDetection(conn.getContentType(), ex); } - catch (XmlReaderException ex) { - doLenientDetection(conn.getContentType(),ex); - } - } - else - if (conn.getContentType()!=null) { + } else if (conn.getContentType() != null) { try { - doHttpStream(conn.getInputStream(),conn.getContentType(),lenient); + doHttpStream(conn.getInputStream(), conn.getContentType(), lenient); + } catch (final XmlReaderException ex) { + doLenientDetection(conn.getContentType(), ex); } - catch (XmlReaderException ex) { - doLenientDetection(conn.getContentType(),ex); - } - } - else { + } else { try { - doRawStream(conn.getInputStream(),lenient); - } - catch (XmlReaderException ex) { - doLenientDetection(null,ex); + doRawStream(conn.getInputStream(), lenient); + } catch (final XmlReaderException ex) { + doLenientDetection(null, ex); } } } /** - * Creates a Reader using an InputStream and the associated content-type header. + * Creates a Reader using an InputStream and the associated content-type + * header. *

- * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. - * If there is not content-type encoding checks the XML prolog encoding. If there is not XML - * prolog encoding uses the default encoding mandated by the content-type MIME type. + * First it checks if the stream has BOM. If there is not BOM checks the + * content-type encoding. If there is not content-type encoding checks the + * XML prolog encoding. If there is not XML prolog encoding uses the default + * encoding mandated by the content-type MIME type. *

- * It does a lenient charset encoding detection, check the constructor with the lenient parameter - * for details. + * It does a lenient charset encoding detection, check the constructor with + * the lenient parameter for details. *

+ * * @param is InputStream to create the reader from. - * @param httpContentType content-type header to use for the resolution of the charset encoding. + * @param httpContentType content-type header to use for the resolution of + * the charset encoding. * @throws IOException thrown if there is a problem reading the file. - * + * */ - public XmlReader(InputStream is,String httpContentType) throws IOException { - this(is,httpContentType,true); + public XmlReader(final InputStream is, final String httpContentType) throws IOException { + this(is, httpContentType, true); } /** - * Creates a Reader using an InputStream and the associated content-type header. + * Creates a Reader using an InputStream and the associated content-type + * header. *

- * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. - * If there is not content-type encoding checks the XML prolog encoding. If there is not XML - * prolog encoding uses the default encoding mandated by the content-type MIME type. + * First it checks if the stream has BOM. If there is not BOM checks the + * content-type encoding. If there is not content-type encoding checks the + * XML prolog encoding. If there is not XML prolog encoding uses the default + * encoding mandated by the content-type MIME type. *

- * If lenient detection is indicated and the detection above fails as per specifications it then attempts - * the following: + * If lenient detection is indicated and the detection above fails as per + * specifications it then attempts the following: *

- * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. + * If the content type was 'text/html' it replaces it with 'text/xml' and + * tries the detection again. *

* Else if the XML prolog had a charset encoding that encoding is used. *

@@ -298,41 +324,46 @@ public class XmlReader extends Reader { *

* If lenient detection is indicated and XmlReaderException is never thrown. *

+ * * @param is InputStream to create the reader from. - * @param httpContentType content-type header to use for the resolution of the charset encoding. - * @param lenient indicates if the charset encoding detection should be relaxed. + * @param httpContentType content-type header to use for the resolution of + * the charset encoding. + * @param lenient indicates if the charset encoding detection should be + * relaxed. * @param defaultEncoding default encoding to use if one cannot be detected. * @throws IOException thrown if there is a problem reading the file. - * @throws XmlReaderException thrown if the charset encoding could not be determined according to the specs. - * + * @throws XmlReaderException thrown if the charset encoding could not be + * determined according to the specs. + * */ - public XmlReader(InputStream is,String httpContentType,boolean lenient, String defaultEncoding) - throws IOException, XmlReaderException { - _defaultEncoding = (defaultEncoding == null) ? _staticDefaultEncoding : defaultEncoding; + public XmlReader(final InputStream is, final String httpContentType, final boolean lenient, final String defaultEncoding) throws IOException, + XmlReaderException { + this._defaultEncoding = defaultEncoding == null ? _staticDefaultEncoding : defaultEncoding; try { - doHttpStream(is,httpContentType,lenient); - } - catch (XmlReaderException ex) { + doHttpStream(is, httpContentType, lenient); + } catch (final XmlReaderException ex) { if (!lenient) { throw ex; - } - else { - doLenientDetection(httpContentType,ex); + } else { + doLenientDetection(httpContentType, ex); } } } /** - * Creates a Reader using an InputStream and the associated content-type header. + * Creates a Reader using an InputStream and the associated content-type + * header. *

- * First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. - * If there is not content-type encoding checks the XML prolog encoding. If there is not XML - * prolog encoding uses the default encoding mandated by the content-type MIME type. + * First it checks if the stream has BOM. If there is not BOM checks the + * content-type encoding. If there is not content-type encoding checks the + * XML prolog encoding. If there is not XML prolog encoding uses the default + * encoding mandated by the content-type MIME type. *

- * If lenient detection is indicated and the detection above fails as per specifications it then attempts - * the following: + * If lenient detection is indicated and the detection above fails as per + * specifications it then attempts the following: *

- * If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again. + * If the content type was 'text/html' it replaces it with 'text/xml' and + * tries the detection again. *

* Else if the XML prolog had a charset encoding that encoding is used. *

@@ -342,210 +373,194 @@ public class XmlReader extends Reader { *

* If lenient detection is indicated and XmlReaderException is never thrown. *

+ * * @param is InputStream to create the reader from. - * @param httpContentType content-type header to use for the resolution of the charset encoding. - * @param lenient indicates if the charset encoding detection should be relaxed. + * @param httpContentType content-type header to use for the resolution of + * the charset encoding. + * @param lenient indicates if the charset encoding detection should be + * relaxed. * @throws IOException thrown if there is a problem reading the file. - * @throws XmlReaderException thrown if the charset encoding could not be determined according to the specs. - * + * @throws XmlReaderException thrown if the charset encoding could not be + * determined according to the specs. + * */ - public XmlReader(InputStream is, String httpContentType, boolean lenient) - throws IOException, XmlReaderException { + public XmlReader(final InputStream is, final String httpContentType, final boolean lenient) throws IOException, XmlReaderException { this(is, httpContentType, lenient, null); } - private void doLenientDetection(String httpContentType,XmlReaderException ex) throws IOException { - if (httpContentType!=null) { + private void doLenientDetection(String httpContentType, XmlReaderException ex) throws IOException { + if (httpContentType != null) { if (httpContentType.startsWith("text/html")) { httpContentType = httpContentType.substring("text/html".length()); httpContentType = "text/xml" + httpContentType; try { - doHttpStream(ex.getInputStream(),httpContentType,true); + doHttpStream(ex.getInputStream(), httpContentType, true); ex = null; - } - catch (XmlReaderException ex2) { + } catch (final XmlReaderException ex2) { ex = ex2; } } } - if (ex!=null) { + if (ex != null) { String encoding = ex.getXmlEncoding(); - if (encoding==null) { + if (encoding == null) { encoding = ex.getContentTypeEncoding(); } - if (encoding==null) { - encoding = (_defaultEncoding == null) ? UTF_8 : _defaultEncoding; + if (encoding == null) { + encoding = this._defaultEncoding == null ? UTF_8 : this._defaultEncoding; } - prepareReader(ex.getInputStream(),encoding); + prepareReader(ex.getInputStream(), encoding); } } /** * Returns the charset encoding of the XmlReader. *

+ * * @return charset encoding. - * + * */ public String getEncoding() { - return _encoding; + return this._encoding; } - public int read(char[] buf,int offset,int len) throws IOException { - return _reader.read(buf,offset,len); + @Override + public int read(final char[] buf, final int offset, final int len) throws IOException { + return this._reader.read(buf, offset, len); } /** * Closes the XmlReader stream. *

+ * * @throws IOException thrown if there was a problem closing the stream. - * + * */ + @Override public void close() throws IOException { - _reader.close(); + this._reader.close(); } - private void doRawStream(InputStream is,boolean lenient) throws IOException { - BufferedInputStream pis = new BufferedInputStream(is, BUFFER_SIZE); - String bomEnc = getBOMEncoding(pis); - String xmlGuessEnc = getXMLGuessEncoding(pis); - String xmlEnc = getXmlProlog(pis,xmlGuessEnc); - String encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, pis); - prepareReader(pis,encoding); + private void doRawStream(final InputStream is, final boolean lenient) throws IOException { + final BufferedInputStream pis = new BufferedInputStream(is, BUFFER_SIZE); + final String bomEnc = getBOMEncoding(pis); + final String xmlGuessEnc = getXMLGuessEncoding(pis); + final String xmlEnc = getXmlProlog(pis, xmlGuessEnc); + final String encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, pis); + prepareReader(pis, encoding); } - private void doHttpStream(InputStream is,String httpContentType,boolean lenient) throws IOException { - BufferedInputStream pis = new BufferedInputStream(is, BUFFER_SIZE); - String cTMime = getContentTypeMime(httpContentType); - String cTEnc = getContentTypeEncoding(httpContentType); - String bomEnc = getBOMEncoding(pis); - String xmlGuessEnc = getXMLGuessEncoding(pis); - String xmlEnc = getXmlProlog(pis,xmlGuessEnc); - String encoding = calculateHttpEncoding(cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, pis,lenient); - prepareReader(pis,encoding); + private void doHttpStream(final InputStream is, final String httpContentType, final boolean lenient) throws IOException { + final BufferedInputStream pis = new BufferedInputStream(is, BUFFER_SIZE); + final String cTMime = getContentTypeMime(httpContentType); + final String cTEnc = getContentTypeEncoding(httpContentType); + final String bomEnc = getBOMEncoding(pis); + final String xmlGuessEnc = getXMLGuessEncoding(pis); + final String xmlEnc = getXmlProlog(pis, xmlGuessEnc); + final String encoding = calculateHttpEncoding(cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc, pis, lenient); + prepareReader(pis, encoding); } - private void prepareReader(InputStream is,String encoding) throws IOException { - _reader = new InputStreamReader(is,encoding); - _encoding = encoding; + private void prepareReader(final InputStream is, final String encoding) throws IOException { + this._reader = new InputStreamReader(is, encoding); + this._encoding = encoding; } // InputStream is passed for XmlReaderException creation only - private String calculateRawEncoding(String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is) throws IOException { + private String calculateRawEncoding(final String bomEnc, final String xmlGuessEnc, final String xmlEnc, final InputStream is) throws IOException { String encoding; - if (bomEnc==null) { - if (xmlGuessEnc==null || xmlEnc==null) { - encoding = (_defaultEncoding == null) ? UTF_8 : _defaultEncoding; - } - else - if (xmlEnc.equals(UTF_16) && (xmlGuessEnc.equals(UTF_16BE) || xmlGuessEnc.equals(UTF_16LE))) { + if (bomEnc == null) { + if (xmlGuessEnc == null || xmlEnc == null) { + encoding = this._defaultEncoding == null ? UTF_8 : this._defaultEncoding; + } else if (xmlEnc.equals(UTF_16) && (xmlGuessEnc.equals(UTF_16BE) || xmlGuessEnc.equals(UTF_16LE))) { encoding = xmlGuessEnc; - } - else { + } else { encoding = xmlEnc; } - } - else - if (bomEnc.equals(UTF_8)) { - if (xmlGuessEnc!=null && !xmlGuessEnc.equals(UTF_8)) { - throw new XmlReaderException(RAW_EX_1.format(new Object[]{bomEnc,xmlGuessEnc,xmlEnc}), - bomEnc,xmlGuessEnc,xmlEnc,is); + } else if (bomEnc.equals(UTF_8)) { + if (xmlGuessEnc != null && !xmlGuessEnc.equals(UTF_8)) { + throw new XmlReaderException(RAW_EX_1.format(new Object[] { bomEnc, xmlGuessEnc, xmlEnc }), bomEnc, xmlGuessEnc, xmlEnc, is); } - if (xmlEnc!=null && !xmlEnc.equals(UTF_8)) { - throw new XmlReaderException(RAW_EX_1.format(new Object[]{bomEnc,xmlGuessEnc,xmlEnc}), - bomEnc,xmlGuessEnc,xmlEnc,is); + if (xmlEnc != null && !xmlEnc.equals(UTF_8)) { + throw new XmlReaderException(RAW_EX_1.format(new Object[] { bomEnc, xmlGuessEnc, xmlEnc }), bomEnc, xmlGuessEnc, xmlEnc, is); } encoding = UTF_8; - } - else - if (bomEnc.equals(UTF_16BE) || bomEnc.equals(UTF_16LE)) { - if (xmlGuessEnc!=null && !xmlGuessEnc.equals(bomEnc)) { - throw new IOException(RAW_EX_1.format(new Object[]{bomEnc,xmlGuessEnc,xmlEnc})); + } else if (bomEnc.equals(UTF_16BE) || bomEnc.equals(UTF_16LE)) { + if (xmlGuessEnc != null && !xmlGuessEnc.equals(bomEnc)) { + throw new IOException(RAW_EX_1.format(new Object[] { bomEnc, xmlGuessEnc, xmlEnc })); } - if (xmlEnc!=null && !xmlEnc.equals(UTF_16) && !xmlEnc.equals(bomEnc)) { - throw new XmlReaderException(RAW_EX_1.format(new Object[]{bomEnc,xmlGuessEnc,xmlEnc}), - bomEnc,xmlGuessEnc,xmlEnc,is); + if (xmlEnc != null && !xmlEnc.equals(UTF_16) && !xmlEnc.equals(bomEnc)) { + throw new XmlReaderException(RAW_EX_1.format(new Object[] { bomEnc, xmlGuessEnc, xmlEnc }), bomEnc, xmlGuessEnc, xmlEnc, is); } - encoding =bomEnc; - } - else { - throw new XmlReaderException(RAW_EX_2.format(new Object[]{bomEnc,xmlGuessEnc,xmlEnc}), - bomEnc,xmlGuessEnc,xmlEnc,is); + encoding = bomEnc; + } else { + throw new XmlReaderException(RAW_EX_2.format(new Object[] { bomEnc, xmlGuessEnc, xmlEnc }), bomEnc, xmlGuessEnc, xmlEnc, is); } return encoding; } // InputStream is passed for XmlReaderException creation only - private String calculateHttpEncoding(String cTMime, String cTEnc, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is,boolean lenient) throws IOException { + private String calculateHttpEncoding(final String cTMime, final String cTEnc, final String bomEnc, final String xmlGuessEnc, final String xmlEnc, + final InputStream is, final boolean lenient) throws IOException { String encoding; - if (lenient & xmlEnc!=null) { + if (lenient & xmlEnc != null) { encoding = xmlEnc; - } - else { - boolean appXml = isAppXml(cTMime); - boolean textXml = isTextXml(cTMime); + } else { + final boolean appXml = isAppXml(cTMime); + final boolean textXml = isTextXml(cTMime); if (appXml || textXml) { - if (cTEnc==null) { + if (cTEnc == null) { if (appXml) { encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, is); + } else { + encoding = this._defaultEncoding == null ? US_ASCII : this._defaultEncoding; } - else { - encoding = (_defaultEncoding == null) ? US_ASCII : _defaultEncoding; - } - } - else - if (bomEnc!=null && (cTEnc.equals(UTF_16BE) || cTEnc.equals(UTF_16LE))) { - throw new XmlReaderException(HTTP_EX_1.format(new Object[]{cTMime,cTEnc,bomEnc,xmlGuessEnc,xmlEnc}), - cTMime,cTEnc,bomEnc,xmlGuessEnc,xmlEnc,is); - } - else - if (cTEnc.equals(UTF_16)) { - if (bomEnc!=null && bomEnc.startsWith(UTF_16)) { + } else if (bomEnc != null && (cTEnc.equals(UTF_16BE) || cTEnc.equals(UTF_16LE))) { + throw new XmlReaderException(HTTP_EX_1.format(new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc }), cTMime, cTEnc, bomEnc, + xmlGuessEnc, xmlEnc, is); + } else if (cTEnc.equals(UTF_16)) { + if (bomEnc != null && bomEnc.startsWith(UTF_16)) { encoding = bomEnc; + } else { + throw new XmlReaderException(HTTP_EX_2.format(new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc }), cTMime, cTEnc, bomEnc, + xmlGuessEnc, xmlEnc, is); } - else { - throw new XmlReaderException(HTTP_EX_2.format(new Object[]{cTMime,cTEnc,bomEnc,xmlGuessEnc,xmlEnc}), - cTMime,cTEnc,bomEnc,xmlGuessEnc,xmlEnc,is); - } - } - else { + } else { encoding = cTEnc; } - } - else { - throw new XmlReaderException(HTTP_EX_3.format(new Object[]{cTMime,cTEnc,bomEnc,xmlGuessEnc,xmlEnc}), - cTMime,cTEnc,bomEnc,xmlGuessEnc,xmlEnc,is); + } else { + throw new XmlReaderException(HTTP_EX_3.format(new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc }), cTMime, cTEnc, bomEnc, xmlGuessEnc, + xmlEnc, is); } } return encoding; } // returns MIME type or NULL if httpContentType is NULL - private static String getContentTypeMime(String httpContentType) { + private static String getContentTypeMime(final String httpContentType) { String mime = null; - if (httpContentType!=null) { - int i = httpContentType.indexOf(";"); - mime = ((i==-1) ? httpContentType : httpContentType.substring(0,i)).trim(); + if (httpContentType != null) { + final int i = httpContentType.indexOf(";"); + mime = (i == -1 ? httpContentType : httpContentType.substring(0, i)).trim(); } return mime; } private static final Pattern CHARSET_PATTERN = Pattern.compile("charset=([.[^; ]]*)"); - // returns charset parameter value, NULL if not present, NULL if httpContentType is NULL - private static String getContentTypeEncoding(String httpContentType) { + // returns charset parameter value, NULL if not present, NULL if + // httpContentType is NULL + private static String getContentTypeEncoding(final String httpContentType) { String encoding = null; - if (httpContentType!=null) { - int i = httpContentType.indexOf(";"); - if (i>-1) { - String postMime = httpContentType.substring(i+1); - Matcher m = CHARSET_PATTERN.matcher(postMime); - encoding = (m.find()) ? m.group(1) : null; - encoding = (encoding!=null) ? encoding.toUpperCase() : null; + if (httpContentType != null) { + final int i = httpContentType.indexOf(";"); + if (i > -1) { + final String postMime = httpContentType.substring(i + 1); + final Matcher m = CHARSET_PATTERN.matcher(postMime); + encoding = m.find() ? m.group(1) : null; + encoding = encoding != null ? encoding.toUpperCase() : null; } - if (encoding != null && - ((encoding.startsWith("\"") && encoding.endsWith("\"")) || - (encoding.startsWith("'") && encoding.endsWith("'")) - )) { + if (encoding != null && (encoding.startsWith("\"") && encoding.endsWith("\"") || encoding.startsWith("'") && encoding.endsWith("'"))) { encoding = encoding.substring(1, encoding.length() - 1); } } @@ -554,9 +569,9 @@ public class XmlReader extends Reader { // returns the BOM in the stream, NULL if not present, // if there was BOM the in the stream it is consumed - private static String getBOMEncoding(BufferedInputStream is) throws IOException { + private static String getBOMEncoding(final BufferedInputStream is) throws IOException { String encoding = null; - int[] bytes = new int[3]; + final int[] bytes = new int[3]; is.mark(3); bytes[0] = is.read(); bytes[1] = is.read(); @@ -567,28 +582,24 @@ public class XmlReader extends Reader { is.reset(); is.read(); is.read(); - } - else - if (bytes[0] == 0xFF && bytes[1] == 0xFE) { + } else if (bytes[0] == 0xFF && bytes[1] == 0xFE) { encoding = UTF_16LE; is.reset(); is.read(); is.read(); - } - else - if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) { + } else if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) { encoding = UTF_8; - } - else { + } else { is.reset(); } return encoding; } - // returns the best guess for the encoding by looking the first bytes of the stream, ', NULL if none - private static String getXmlProlog(BufferedInputStream is,String guessedEnc) throws IOException { + // returns the encoding declared in the , NULL if none + private static String getXmlProlog(final BufferedInputStream is, final String guessedEnc) throws IOException { String encoding = null; - if (guessedEnc!=null) { - byte[] bytes = new byte[BUFFER_SIZE]; + if (guessedEnc != null) { + final byte[] bytes = new byte[BUFFER_SIZE]; is.mark(BUFFER_SIZE); int offset = 0; int max = BUFFER_SIZE; - int c = is.read(bytes,offset,max); + int c = is.read(bytes, offset, max); int firstGT = -1; - while (c!=-1 && firstGT==-1 && offset< BUFFER_SIZE) { + while (c != -1 && firstGT == -1 && offset < BUFFER_SIZE) { offset += c; max -= c; - c = is.read(bytes,offset,max); + c = is.read(bytes, offset, max); firstGT = new String(bytes, 0, offset).indexOf(">"); } if (firstGT == -1) { if (c == -1) { throw new IOException("Unexpected end of XML stream"); - } - else { + } else { throw new IOException("XML prolog or ROOT element not found on first " + offset + " bytes"); } } - int bytesRead = offset; - if (bytesRead>0) { + final int bytesRead = offset; + if (bytesRead > 0) { is.reset(); - Reader reader = new InputStreamReader(new ByteArrayInputStream(bytes,0,firstGT + 1), guessedEnc); - BufferedReader bReader = new BufferedReader(reader); - StringBuffer prolog = new StringBuffer(); + final Reader reader = new InputStreamReader(new ByteArrayInputStream(bytes, 0, firstGT + 1), guessedEnc); + final BufferedReader bReader = new BufferedReader(reader); + final StringBuffer prolog = new StringBuffer(); String line = bReader.readLine(); while (line != null) { prolog.append(line); line = bReader.readLine(); } - Matcher m = ENCODING_PATTERN.matcher(prolog); + final Matcher m = ENCODING_PATTERN.matcher(prolog); if (m.find()) { encoding = m.group(1).toUpperCase(); - encoding = encoding.substring(1,encoding.length()-1); + encoding = encoding.substring(1, encoding.length() - 1); } } } @@ -660,27 +664,20 @@ public class XmlReader extends Reader { } // indicates if the MIME type belongs to the APPLICATION XML family - private static boolean isAppXml(String mime) { - return mime!=null && - (mime.equals("application/xml") || - mime.equals("application/xml-dtd") || - mime.equals("application/xml-external-parsed-entity") || - (mime.startsWith("application/") && mime.endsWith("+xml"))); + private static boolean isAppXml(final String mime) { + return mime != null + && (mime.equals("application/xml") || mime.equals("application/xml-dtd") || mime.equals("application/xml-external-parsed-entity") || mime + .startsWith("application/") && mime.endsWith("+xml")); } // indicates if the MIME type belongs to the TEXT XML family - private static boolean isTextXml(String mime) { - return mime!=null && - (mime.equals("text/xml") || - mime.equals("text/xml-external-parsed-entity") || - (mime.startsWith("text/") && mime.endsWith("+xml"))); + private static boolean isTextXml(final String mime) { + return mime != null && (mime.equals("text/xml") || mime.equals("text/xml-external-parsed-entity") || mime.startsWith("text/") && mime.endsWith("+xml")); } - private static final MessageFormat RAW_EX_1 = new MessageFormat( - "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch"); + private static final MessageFormat RAW_EX_1 = new MessageFormat("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch"); - private static final MessageFormat RAW_EX_2 = new MessageFormat( - "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM"); + private static final MessageFormat RAW_EX_2 = new MessageFormat("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM"); private static final MessageFormat HTTP_EX_1 = new MessageFormat( "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL"); diff --git a/src/main/java/com/sun/syndication/io/XmlReaderException.java b/src/main/java/com/sun/syndication/io/XmlReaderException.java index 62c51c6..5b4a012 100644 --- a/src/main/java/com/sun/syndication/io/XmlReaderException.java +++ b/src/main/java/com/sun/syndication/io/XmlReaderException.java @@ -1,49 +1,55 @@ package com.sun.syndication.io; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; /** - * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding - * can not be determined according to the XML 1.0 specification and RFC 3023. + * The XmlReaderException is thrown by the XmlReader constructors if the charset + * encoding can not be determined according to the XML 1.0 specification and RFC + * 3023. *

- * The exception returns the unconsumed InputStream to allow the application to do an - * alternate processing with the stream. Note that the original InputStream given to the - * XmlReader cannot be used as that one has been already read. + * The exception returns the unconsumed InputStream to allow the application to + * do an alternate processing with the stream. Note that the original + * InputStream given to the XmlReader cannot be used as that one has been + * already read. *

- * + * * @author Alejandro Abdelnur - * + * */ public class XmlReaderException extends IOException { - private String _bomEncoding; - private String _xmlGuessEncoding; - private String _xmlEncoding; - private String _contentTypeMime; - private String _contentTypeEncoding; - private InputStream _is; + private final String _bomEncoding; + private final String _xmlGuessEncoding; + private final String _xmlEncoding; + private final String _contentTypeMime; + private final String _contentTypeEncoding; + private final InputStream _is; /** - * Creates an exception instance if the charset encoding could not be determined. + * Creates an exception instance if the charset encoding could not be + * determined. *

* Instances of this exception are thrown by the XmlReader. *

+ * * @param msg message describing the reason for the exception. * @param bomEnc BOM encoding. * @param xmlGuessEnc XML guess encoding. * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. - * + * */ - public XmlReaderException(String msg,String bomEnc,String xmlGuessEnc,String xmlEnc,InputStream is) { - this(msg,null,null,bomEnc,xmlGuessEnc,xmlEnc,is); + public XmlReaderException(final String msg, final String bomEnc, final String xmlGuessEnc, final String xmlEnc, final InputStream is) { + this(msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is); } /** - * Creates an exception instance if the charset encoding could not be determined. + * Creates an exception instance if the charset encoding could not be + * determined. *

* Instances of this exception are thrown by the XmlReader. *

+ * * @param msg message describing the reason for the exception. * @param ctMime MIME type in the content-type. * @param ctEnc encoding in the content-type. @@ -51,79 +57,88 @@ public class XmlReaderException extends IOException { * @param xmlGuessEnc XML guess encoding. * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. - * + * */ - public XmlReaderException(String msg,String ctMime,String ctEnc, - String bomEnc,String xmlGuessEnc,String xmlEnc,InputStream is) { + public XmlReaderException(final String msg, final String ctMime, final String ctEnc, final String bomEnc, final String xmlGuessEnc, final String xmlEnc, + final InputStream is) { super(msg); - _contentTypeMime = ctMime; - _contentTypeEncoding = ctEnc; - _bomEncoding = bomEnc; - _xmlGuessEncoding = xmlGuessEnc; - _xmlEncoding = xmlEnc; - _is = is; + this._contentTypeMime = ctMime; + this._contentTypeEncoding = ctEnc; + this._bomEncoding = bomEnc; + this._xmlGuessEncoding = xmlGuessEnc; + this._xmlEncoding = xmlEnc; + this._is = is; } /** * Returns the BOM encoding found in the InputStream. *

+ * * @return the BOM encoding, null if none. - * + * */ public String getBomEncoding() { - return _bomEncoding; + return this._bomEncoding; } /** * Returns the encoding guess based on the first bytes of the InputStream. *

+ * * @return the encoding guess, null if it couldn't be guessed. - * + * */ public String getXmlGuessEncoding() { - return _xmlGuessEncoding; + return this._xmlGuessEncoding; } /** * Returns the encoding found in the XML prolog of the InputStream. *

+ * * @return the encoding of the XML prolog, null if none. - * + * */ public String getXmlEncoding() { - return _xmlEncoding; + return this._xmlEncoding; } /** - * Returns the MIME type in the content-type used to attempt determining the encoding. + * Returns the MIME type in the content-type used to attempt determining the + * encoding. *

- * @return the MIME type in the content-type, null if there was not content-type or the encoding detection - * did not involve HTTP. - * + * + * @return the MIME type in the content-type, null if there was not + * content-type or the encoding detection did not involve HTTP. + * */ public String getContentTypeMime() { - return _contentTypeMime; + return this._contentTypeMime; } /** - * Returns the encoding in the content-type used to attempt determining the encoding. + * Returns the encoding in the content-type used to attempt determining the + * encoding. *

- * @return the encoding in the content-type, null if there was not content-type, no encoding in it - * or the encoding detection did not involve HTTP. - * + * + * @return the encoding in the content-type, null if there was not + * content-type, no encoding in it or the encoding detection did not + * involve HTTP. + * */ public String getContentTypeEncoding() { - return _contentTypeEncoding; + return this._contentTypeEncoding; } /** - * Returns the unconsumed InputStream to allow the application to do an alternate - * encoding detection on the InputStream. + * Returns the unconsumed InputStream to allow the application to do an + * alternate encoding detection on the InputStream. *

+ * * @return the unconsumed InputStream. - * + * */ public InputStream getInputStream() { - return _is; + return this._is; } } diff --git a/src/main/java/com/sun/syndication/io/impl/Atom03Generator.java b/src/main/java/com/sun/syndication/io/impl/Atom03Generator.java index a9e6b90..d5f426f 100644 --- a/src/main/java/com/sun/syndication/io/impl/Atom03Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/Atom03Generator.java @@ -16,130 +16,137 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.atom.*; -import com.sun.syndication.io.FeedException; +import java.io.StringReader; +import java.util.List; + import org.jdom2.Attribute; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.Namespace; import org.jdom2.input.SAXBuilder; -import java.io.StringReader; -import java.util.List; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.atom.Generator; +import com.sun.syndication.feed.atom.Link; +import com.sun.syndication.feed.atom.Person; +import com.sun.syndication.io.FeedException; /** * Feed Generator for Atom *

- * + * * @author Elaine Chien - * + * */ public class Atom03Generator extends BaseWireFeedGenerator { private static final String ATOM_03_URI = "http://purl.org/atom/ns#"; private static final Namespace ATOM_NS = Namespace.getNamespace(ATOM_03_URI); - private String _version; + private final String _version; public Atom03Generator() { - this("atom_0.3","0.3"); + this("atom_0.3", "0.3"); } - protected Atom03Generator(String type,String version) { + protected Atom03Generator(final String type, final String version) { super(type); - _version = version; + this._version = version; } protected String getVersion() { - return _version; + return this._version; } protected Namespace getFeedNamespace() { return ATOM_NS; } - public Document generate(WireFeed wFeed) throws FeedException { - Feed feed = (Feed) wFeed; - Element root = createRootElement(feed); - populateFeed(feed,root); - purgeUnusedNamespaceDeclarations(root); + @Override + public Document generate(final WireFeed wFeed) throws FeedException { + final Feed feed = (Feed) wFeed; + final Element root = createRootElement(feed); + populateFeed(feed, root); + purgeUnusedNamespaceDeclarations(root); return createDocument(root); } - protected Document createDocument(Element root) { + protected Document createDocument(final Element root) { return new Document(root); } - protected Element createRootElement(Feed feed) { - Element root = new Element("feed",getFeedNamespace()); + protected Element createRootElement(final Feed feed) { + final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); - Attribute version = new Attribute("version", getVersion()); + final Attribute version = new Attribute("version", getVersion()); root.setAttribute(version); generateModuleNamespaceDefs(root); return root; } - protected void populateFeed(Feed feed,Element parent) throws FeedException { - addFeed(feed,parent); - addEntries(feed,parent); + protected void populateFeed(final Feed feed, final Element parent) throws FeedException { + addFeed(feed, parent); + addEntries(feed, parent); } - protected void addFeed(Feed feed, Element parent) throws FeedException { - Element eFeed = parent; - populateFeedHeader(feed,eFeed); + protected void addFeed(final Feed feed, final Element parent) throws FeedException { + final Element eFeed = parent; + populateFeedHeader(feed, eFeed); checkFeedHeaderConstraints(eFeed); - generateFeedModules(feed.getModules(),eFeed); - generateForeignMarkup(eFeed, (List)feed.getForeignMarkup()); + generateFeedModules(feed.getModules(), eFeed); + generateForeignMarkup(eFeed, feed.getForeignMarkup()); } - protected void addEntries(Feed feed,Element parent) throws FeedException { - List items = feed.getEntries(); - for (int i=0;i items = feed.getEntries(); + for (int i = 0; i < items.size(); i++) { + addEntry(items.get(i), parent); } checkEntriesConstraints(parent); } - protected void addEntry(Entry entry,Element parent) throws FeedException { - Element eEntry = new Element("entry", getFeedNamespace()); - populateEntry(entry,eEntry); + protected void addEntry(final Entry entry, final Element parent) throws FeedException { + final Element eEntry = new Element("entry", getFeedNamespace()); + populateEntry(entry, eEntry); checkEntryConstraints(eEntry); - generateItemModules(entry.getModules(),eEntry); + generateItemModules(entry.getModules(), eEntry); parent.addContent(eEntry); } - protected void populateFeedHeader(Feed feed, Element eFeed) throws FeedException { + protected void populateFeedHeader(final Feed feed, final Element eFeed) throws FeedException { if (feed.getTitleEx() != null) { - Element titleElement = new Element("title", getFeedNamespace()); + final Element titleElement = new Element("title", getFeedNamespace()); fillContentElement(titleElement, feed.getTitleEx()); eFeed.addContent(titleElement); } List links = feed.getAlternateLinks(); for (int i = 0; i < links.size(); i++) { - eFeed.addContent(generateLinkElement((Link)links.get(i))); + eFeed.addContent(generateLinkElement(links.get(i))); } links = feed.getOtherLinks(); for (int i = 0; i < links.size(); i++) { - eFeed.addContent(generateLinkElement((Link)links.get(i))); + eFeed.addContent(generateLinkElement(links.get(i))); } - if (feed.getAuthors()!=null && feed.getAuthors().size() > 0) { - Element authorElement = new Element("author", getFeedNamespace()); - fillPersonElement(authorElement, (Person)feed.getAuthors().get(0)); + if (feed.getAuthors() != null && feed.getAuthors().size() > 0) { + final Element authorElement = new Element("author", getFeedNamespace()); + fillPersonElement(authorElement, feed.getAuthors().get(0)); eFeed.addContent(authorElement); } - List contributors = feed.getContributors(); + final List contributors = feed.getContributors(); for (int i = 0; i < contributors.size(); i++) { - Element contributorElement = new Element("contributor", getFeedNamespace()); - fillPersonElement(contributorElement, (Person)contributors.get(i)); + final Element contributorElement = new Element("contributor", getFeedNamespace()); + fillPersonElement(contributorElement, contributors.get(i)); eFeed.addContent(contributorElement); } if (feed.getTagline() != null) { - Element taglineElement = new Element("tagline", getFeedNamespace()); + final Element taglineElement = new Element("tagline", getFeedNamespace()); fillContentElement(taglineElement, feed.getTagline()); eFeed.addContent(taglineElement); } @@ -157,44 +164,44 @@ public class Atom03Generator extends BaseWireFeedGenerator { } if (feed.getInfo() != null) { - Element infoElement = new Element("info", getFeedNamespace()); + final Element infoElement = new Element("info", getFeedNamespace()); fillContentElement(infoElement, feed.getInfo()); eFeed.addContent(infoElement); } if (feed.getModified() != null) { - Element modifiedElement = new Element("modified", getFeedNamespace()); + final Element modifiedElement = new Element("modified", getFeedNamespace()); modifiedElement.addContent(DateParser.formatW3CDateTime(feed.getModified())); eFeed.addContent(modifiedElement); } } - protected void populateEntry(Entry entry, Element eEntry) throws FeedException { + protected void populateEntry(final Entry entry, final Element eEntry) throws FeedException { if (entry.getTitleEx() != null) { - Element titleElement = new Element("title", getFeedNamespace()); + final Element titleElement = new Element("title", getFeedNamespace()); fillContentElement(titleElement, entry.getTitleEx()); eEntry.addContent(titleElement); } List links = entry.getAlternateLinks(); for (int i = 0; i < links.size(); i++) { - eEntry.addContent(generateLinkElement((Link)links.get(i))); + eEntry.addContent(generateLinkElement(links.get(i))); } links = entry.getOtherLinks(); for (int i = 0; i < links.size(); i++) { - eEntry.addContent(generateLinkElement((Link)links.get(i))); + eEntry.addContent(generateLinkElement(links.get(i))); } - if (entry.getAuthors()!=null && entry.getAuthors().size() > 0) { - Element authorElement = new Element("author", getFeedNamespace()); - fillPersonElement(authorElement, (Person)entry.getAuthors().get(0)); + if (entry.getAuthors() != null && entry.getAuthors().size() > 0) { + final Element authorElement = new Element("author", getFeedNamespace()); + fillPersonElement(authorElement, entry.getAuthors().get(0)); eEntry.addContent(authorElement); } - List contributors = entry.getContributors(); + final List contributors = entry.getContributors(); for (int i = 0; i < contributors.size(); i++) { - Element contributorElement = new Element("contributor", getFeedNamespace()); - fillPersonElement(contributorElement, (Person)contributors.get(i)); + final Element contributorElement = new Element("contributor", getFeedNamespace()); + fillPersonElement(contributorElement, contributors.get(i)); eEntry.addContent(contributorElement); } if (entry.getId() != null) { @@ -202,71 +209,69 @@ public class Atom03Generator extends BaseWireFeedGenerator { } if (entry.getModified() != null) { - Element modifiedElement = new Element("modified", getFeedNamespace()); + final Element modifiedElement = new Element("modified", getFeedNamespace()); modifiedElement.addContent(DateParser.formatW3CDateTime(entry.getModified())); eEntry.addContent(modifiedElement); } if (entry.getIssued() != null) { - Element issuedElement = new Element("issued", getFeedNamespace()); + final Element issuedElement = new Element("issued", getFeedNamespace()); issuedElement.addContent(DateParser.formatW3CDateTime(entry.getIssued())); eEntry.addContent(issuedElement); } if (entry.getCreated() != null) { - Element createdElement = new Element("created", getFeedNamespace()); + final Element createdElement = new Element("created", getFeedNamespace()); createdElement.addContent(DateParser.formatW3CDateTime(entry.getCreated())); eEntry.addContent(createdElement); } if (entry.getSummary() != null) { - Element summaryElement = new Element("summary", getFeedNamespace()); + final Element summaryElement = new Element("summary", getFeedNamespace()); fillContentElement(summaryElement, entry.getSummary()); eEntry.addContent(summaryElement); } - List contents = entry.getContents(); + final List contents = entry.getContents(); for (int i = 0; i < contents.size(); i++) { - Element contentElement = new Element("content", getFeedNamespace()); - fillContentElement(contentElement, (Content)contents.get(i)); + final Element contentElement = new Element("content", getFeedNamespace()); + fillContentElement(contentElement, contents.get(i)); eEntry.addContent(contentElement); } - - generateForeignMarkup(eEntry, (List)entry.getForeignMarkup()); + + generateForeignMarkup(eEntry, entry.getForeignMarkup()); } - protected void checkFeedHeaderConstraints(Element eFeed) throws FeedException { + protected void checkFeedHeaderConstraints(final Element eFeed) throws FeedException { } - protected void checkEntriesConstraints(Element parent) throws FeedException { + protected void checkEntriesConstraints(final Element parent) throws FeedException { } - protected void checkEntryConstraints(Element eEntry) throws FeedException { + protected void checkEntryConstraints(final Element eEntry) throws FeedException { } - - protected Element generateLinkElement(Link link) { - Element linkElement = new Element("link", getFeedNamespace()); + protected Element generateLinkElement(final Link link) { + final Element linkElement = new Element("link", getFeedNamespace()); if (link.getRel() != null) { - Attribute relAttribute = new Attribute("rel", link.getRel().toString()); + final Attribute relAttribute = new Attribute("rel", link.getRel().toString()); linkElement.setAttribute(relAttribute); } if (link.getType() != null) { - Attribute typeAttribute = new Attribute("type", link.getType()); + final Attribute typeAttribute = new Attribute("type", link.getType()); linkElement.setAttribute(typeAttribute); } if (link.getHref() != null) { - Attribute hrefAttribute = new Attribute("href", link.getHref()); + final Attribute hrefAttribute = new Attribute("href", link.getHref()); linkElement.setAttribute(hrefAttribute); } return linkElement; } - - protected void fillPersonElement(Element element, Person person) { + protected void fillPersonElement(final Element element, final Person person) { if (person.getName() != null) { element.addContent(generateSimpleElement("name", person.getName())); } @@ -279,11 +284,11 @@ public class Atom03Generator extends BaseWireFeedGenerator { } } - protected Element generateTagLineElement(Content tagline) { - Element taglineElement = new Element("tagline", getFeedNamespace()); + protected Element generateTagLineElement(final Content tagline) { + final Element taglineElement = new Element("tagline", getFeedNamespace()); if (tagline.getType() != null) { - Attribute typeAttribute = new Attribute("type", tagline.getType()); + final Attribute typeAttribute = new Attribute("type", tagline.getType()); taglineElement.setAttribute(typeAttribute); } @@ -293,17 +298,16 @@ public class Atom03Generator extends BaseWireFeedGenerator { return taglineElement; } - protected void fillContentElement(Element contentElement, Content content) - throws FeedException { + protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { if (content.getType() != null) { - Attribute typeAttribute = new Attribute("type", content.getType()); + final Attribute typeAttribute = new Attribute("type", content.getType()); contentElement.setAttribute(typeAttribute); } - String mode = content.getMode(); + final String mode = content.getMode(); if (mode != null) { - Attribute modeAttribute = new Attribute("mode", content.getMode().toString()); + final Attribute modeAttribute = new Attribute("mode", content.getMode().toString()); contentElement.setAttribute(modeAttribute); } @@ -315,36 +319,35 @@ public class Atom03Generator extends BaseWireFeedGenerator { contentElement.addContent(Base64.encode(content.getValue())); } else if (mode.equals(Content.XML)) { - StringBuffer tmpDocString = new StringBuffer(""); + final StringBuffer tmpDocString = new StringBuffer(""); tmpDocString.append(content.getValue()); tmpDocString.append(""); - StringReader tmpDocReader = new StringReader(tmpDocString.toString()); + final StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { - SAXBuilder saxBuilder = new SAXBuilder(); + final SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); - } - catch (Exception ex) { - throw new FeedException("Invalid XML",ex); + } catch (final Exception ex) { + throw new FeedException("Invalid XML", ex); } - List children = tmpDoc.getRootElement().removeContent(); + final List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } } } - protected Element generateGeneratorElement(Generator generator) { - Element generatorElement = new Element("generator", getFeedNamespace()); + protected Element generateGeneratorElement(final Generator generator) { + final Element generatorElement = new Element("generator", getFeedNamespace()); if (generator.getUrl() != null) { - Attribute urlAttribute = new Attribute("url", generator.getUrl()); + final Attribute urlAttribute = new Attribute("url", generator.getUrl()); generatorElement.setAttribute(urlAttribute); } if (generator.getVersion() != null) { - Attribute versionAttribute = new Attribute("version", generator.getVersion()); + final Attribute versionAttribute = new Attribute("version", generator.getVersion()); generatorElement.setAttribute(versionAttribute); } @@ -356,8 +359,8 @@ public class Atom03Generator extends BaseWireFeedGenerator { } - protected Element generateSimpleElement(String name, String value) { - Element element = new Element(name, getFeedNamespace()); + protected Element generateSimpleElement(final String name, final String value) { + final Element element = new Element(name, getFeedNamespace()); element.addContent(value); return element; } diff --git a/src/main/java/com/sun/syndication/io/impl/Atom03Parser.java b/src/main/java/com/sun/syndication/io/impl/Atom03Parser.java index 0b002b9..6a3cb0a 100644 --- a/src/main/java/com/sun/syndication/io/impl/Atom03Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/Atom03Parser.java @@ -16,15 +16,22 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.atom.*; -import com.sun.syndication.io.FeedException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.Namespace; import org.jdom2.output.XMLOutputter; -import java.util.*; +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Generator; +import com.sun.syndication.feed.atom.Link; +import com.sun.syndication.feed.atom.Person; +import com.sun.syndication.io.FeedException; /** */ @@ -36,7 +43,7 @@ public class Atom03Parser extends BaseWireFeedParser { this("atom_0.3", ATOM_03_NS); } - protected Atom03Parser(String type, Namespace ns) { + protected Atom03Parser(final String type, final Namespace ns) { super(type, ns); } @@ -44,186 +51,187 @@ public class Atom03Parser extends BaseWireFeedParser { return ATOM_03_NS; } - public boolean isMyType(Document document) { - Element rssRoot = document.getRootElement(); - Namespace defaultNS = rssRoot.getNamespace(); - return (defaultNS!=null) && defaultNS.equals(getAtomNamespace()); + @Override + public boolean isMyType(final Document document) { + final Element rssRoot = document.getRootElement(); + final Namespace defaultNS = rssRoot.getNamespace(); + return defaultNS != null && defaultNS.equals(getAtomNamespace()); } - public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException,FeedException { + @Override + public WireFeed parse(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { if (validate) { validateFeed(document); } - Element rssRoot = document.getRootElement(); + final Element rssRoot = document.getRootElement(); return parseFeed(rssRoot); } - protected void validateFeed(Document document) throws FeedException { + protected void validateFeed(final Document document) throws FeedException { // TBD // here we have to validate the Feed against a schema or whatever // not sure how to do it - // one posibility would be to produce an ouput and attempt to parse it again + // one posibility would be to produce an ouput and attempt to parse it + // again // with validation turned on. // otherwise will have to check the document elements by hand. } - protected WireFeed parseFeed(Element eFeed) { + protected WireFeed parseFeed(final Element eFeed) { - com.sun.syndication.feed.atom.Feed feed = new com.sun.syndication.feed.atom.Feed(getType()); + final com.sun.syndication.feed.atom.Feed feed = new com.sun.syndication.feed.atom.Feed(getType()); - Element e = eFeed.getChild("title",getAtomNamespace()); - if (e!=null) { + Element e = eFeed.getChild("title", getAtomNamespace()); + if (e != null) { feed.setTitleEx(parseContent(e)); } - List eList = eFeed.getChildren("link",getAtomNamespace()); + List eList = eFeed.getChildren("link", getAtomNamespace()); feed.setAlternateLinks(parseAlternateLinks(eList)); feed.setOtherLinks(parseOtherLinks(eList)); - e = eFeed.getChild("author",getAtomNamespace()); - if (e!=null) { - List authors = new ArrayList(); + e = eFeed.getChild("author", getAtomNamespace()); + if (e != null) { + final List authors = new ArrayList(); authors.add(parsePerson(e)); feed.setAuthors(authors); } - eList = eFeed.getChildren("contributor",getAtomNamespace()); - if (eList.size()>0) { + eList = eFeed.getChildren("contributor", getAtomNamespace()); + if (eList.size() > 0) { feed.setContributors(parsePersons(eList)); } - e = eFeed.getChild("tagline",getAtomNamespace()); - if (e!=null) { + e = eFeed.getChild("tagline", getAtomNamespace()); + if (e != null) { feed.setTagline(parseContent(e)); } - e = eFeed.getChild("id",getAtomNamespace()); - if (e!=null) { + e = eFeed.getChild("id", getAtomNamespace()); + if (e != null) { feed.setId(e.getText()); } - e = eFeed.getChild("generator",getAtomNamespace()); - if (e!=null) { - Generator gen = new Generator(); + e = eFeed.getChild("generator", getAtomNamespace()); + if (e != null) { + final Generator gen = new Generator(); gen.setValue(e.getText()); String att = getAttributeValue(e, "url"); - if (att!=null) { + if (att != null) { gen.setUrl(att); } att = getAttributeValue(e, "version"); - if (att!=null) { + if (att != null) { gen.setVersion(att); } feed.setGenerator(gen); } - e = eFeed.getChild("copyright",getAtomNamespace()); - if (e!=null) { + e = eFeed.getChild("copyright", getAtomNamespace()); + if (e != null) { feed.setCopyright(e.getText()); } - e = eFeed.getChild("info",getAtomNamespace()); - if (e!=null) { + e = eFeed.getChild("info", getAtomNamespace()); + if (e != null) { feed.setInfo(parseContent(e)); } - e = eFeed.getChild("modified",getAtomNamespace()); - if (e!=null) { + e = eFeed.getChild("modified", getAtomNamespace()); + if (e != null) { feed.setModified(DateParser.parseDate(e.getText())); } feed.setModules(parseFeedModules(eFeed)); - - eList = eFeed.getChildren("entry",getAtomNamespace()); - if (eList.size()>0) { + + eList = eFeed.getChildren("entry", getAtomNamespace()); + if (eList.size() > 0) { feed.setEntries(parseEntries(eList)); } - List foreignMarkup = - extractForeignMarkup(eFeed, feed, getAtomNamespace()); + final List foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace()); if (foreignMarkup.size() > 0) { feed.setForeignMarkup(foreignMarkup); - } + } return feed; } - private Link parseLink(Element eLink) { - Link link = new Link(); + private Link parseLink(final Element eLink) { + final Link link = new Link(); String att = getAttributeValue(eLink, "rel"); - if (att!=null) { + if (att != null) { link.setRel(att); } att = getAttributeValue(eLink, "type"); - if (att!=null) { + if (att != null) { link.setType(att); } att = getAttributeValue(eLink, "href"); - if (att!=null) { + if (att != null) { link.setHref(att); } return link; } // List(Elements) -> List(Link) - private List parseLinks(List eLinks,boolean alternate) { - List links = new ArrayList(); - for (int i=0;i parseLinks(final List eLinks, final boolean alternate) { + final List links = new ArrayList(); + for (int i = 0; i < eLinks.size(); i++) { + final Element eLink = eLinks.get(i); + final String rel = getAttributeValue(eLink, "rel"); if (alternate) { if ("alternate".equals(rel)) { links.add(parseLink(eLink)); } - } - else { - if (!("alternate".equals(rel))) { + } else { + if (!"alternate".equals(rel)) { links.add(parseLink(eLink)); } } } - return (links.size()>0) ? links : null; + return links.size() > 0 ? links : null; } // List(Elements) -> List(Link) - private List parseAlternateLinks(List eLinks) { - return parseLinks(eLinks,true); + private List parseAlternateLinks(final List eLinks) { + return parseLinks(eLinks, true); } // List(Elements) -> List(Link) - private List parseOtherLinks(List eLinks) { - return parseLinks(eLinks,false); + private List parseOtherLinks(final List eLinks) { + return parseLinks(eLinks, false); } - private Person parsePerson(Element ePerson) { - Person person = new Person(); - Element e = ePerson.getChild("name",getAtomNamespace()); - if (e!=null) { + private Person parsePerson(final Element ePerson) { + final Person person = new Person(); + Element e = ePerson.getChild("name", getAtomNamespace()); + if (e != null) { person.setName(e.getText()); } - e = ePerson.getChild("url",getAtomNamespace()); - if (e!=null) { + e = ePerson.getChild("url", getAtomNamespace()); + if (e != null) { person.setUrl(e.getText()); } - e = ePerson.getChild("email",getAtomNamespace()); - if (e!=null) { + e = ePerson.getChild("email", getAtomNamespace()); + if (e != null) { person.setEmail(e.getText()); } return person; } // List(Elements) -> List(Persons) - private List parsePersons(List ePersons) { - List persons = new ArrayList(); - for (int i=0;i parsePersons(final List ePersons) { + final List persons = new ArrayList(); + for (int i = 0; i < ePersons.size(); i++) { + persons.add(parsePerson(ePersons.get(i))); } - return (persons.size()>0) ? persons : null; + return persons.size() > 0 ? persons : null; } - private Content parseContent(Element e) { + private Content parseContent(final Element e) { String value = null; String type = getAttributeValue(e, "type"); - type = (type!=null) ? type : "text/plain"; + type = type != null ? type : "text/plain"; String mode = getAttributeValue(e, "mode"); if (mode == null) { mode = Content.XML; // default to xml content @@ -231,29 +239,25 @@ public class Atom03Parser extends BaseWireFeedParser { if (mode.equals(Content.ESCAPED)) { // do nothing XML Parser took care of this value = e.getText(); - } - else - if (mode.equals(Content.BASE64)) { - value = Base64.decode(e.getText()); - } - else - if (mode.equals(Content.XML)) { - XMLOutputter outputter = new XMLOutputter(); - List eContent = e.getContent(); - Iterator i = eContent.iterator(); + } else if (mode.equals(Content.BASE64)) { + value = Base64.decode(e.getText()); + } else if (mode.equals(Content.XML)) { + final XMLOutputter outputter = new XMLOutputter(); + final List eContent = e.getContent(); + final Iterator i = eContent.iterator(); while (i.hasNext()) { - org.jdom2.Content c = (org.jdom2.Content) i.next(); + final org.jdom2.Content c = i.next(); if (c instanceof Element) { - Element eC = (Element) c; + final Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { - ((Element)c).setNamespace(Namespace.NO_NAMESPACE); + ((Element) c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } - Content content = new Content(); + final Content content = new Content(); content.setType(type); content.setMode(mode); content.setValue(value); @@ -261,81 +265,79 @@ public class Atom03Parser extends BaseWireFeedParser { } // List(Elements) -> List(Entries) - private List parseEntries(List eEntries) { - List entries = new ArrayList(); - for (int i=0;i parseEntries(final List eEntries) { + final List entries = new ArrayList(); + for (int i = 0; i < eEntries.size(); i++) { + entries.add(parseEntry(eEntries.get(i))); } - return (entries.size()>0) ? entries : null; + return entries.size() > 0 ? entries : null; } - private Entry parseEntry(Element eEntry) { - Entry entry = new Entry(); + private Entry parseEntry(final Element eEntry) { + final Entry entry = new Entry(); - Element e = eEntry.getChild("title",getAtomNamespace()); - if (e!=null) { + Element e = eEntry.getChild("title", getAtomNamespace()); + if (e != null) { entry.setTitleEx(parseContent(e)); } - List eList = eEntry.getChildren("link",getAtomNamespace()); + List eList = eEntry.getChildren("link", getAtomNamespace()); entry.setAlternateLinks(parseAlternateLinks(eList)); entry.setOtherLinks(parseOtherLinks(eList)); - e = eEntry.getChild("author",getAtomNamespace()); - if (e!=null) { - List authors = new ArrayList(); + e = eEntry.getChild("author", getAtomNamespace()); + if (e != null) { + final List authors = new ArrayList(); authors.add(parsePerson(e)); entry.setAuthors(authors); } - eList = eEntry.getChildren("contributor",getAtomNamespace()); - if (eList.size()>0) { + eList = eEntry.getChildren("contributor", getAtomNamespace()); + if (eList.size() > 0) { entry.setContributors(parsePersons(eList)); } - e = eEntry.getChild("id",getAtomNamespace()); - if (e!=null) { + e = eEntry.getChild("id", getAtomNamespace()); + if (e != null) { entry.setId(e.getText()); } - e = eEntry.getChild("modified",getAtomNamespace()); - if (e!=null) { + e = eEntry.getChild("modified", getAtomNamespace()); + if (e != null) { entry.setModified(DateParser.parseDate(e.getText())); } - e = eEntry.getChild("issued",getAtomNamespace()); - if (e!=null) { + e = eEntry.getChild("issued", getAtomNamespace()); + if (e != null) { entry.setIssued(DateParser.parseDate(e.getText())); } - e = eEntry.getChild("created",getAtomNamespace()); - if (e!=null) { + e = eEntry.getChild("created", getAtomNamespace()); + if (e != null) { entry.setCreated(DateParser.parseDate(e.getText())); } - e = eEntry.getChild("summary",getAtomNamespace()); - if (e!=null) { + e = eEntry.getChild("summary", getAtomNamespace()); + if (e != null) { entry.setSummary(parseContent(e)); } - eList = eEntry.getChildren("content",getAtomNamespace()); - if (eList.size()>0) { - List content = new ArrayList(); - for (int i=0;i 0) { + final List content = new ArrayList(); + for (int i = 0; i < eList.size(); i++) { + content.add(parseContent(eList.get(i))); } entry.setContents(content); } entry.setModules(parseItemModules(eEntry)); - List foreignMarkup = - extractForeignMarkup(eEntry, entry, getAtomNamespace()); + final List foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace()); if (foreignMarkup.size() > 0) { entry.setForeignMarkup(foreignMarkup); - } + } return entry; } - } diff --git a/src/main/java/com/sun/syndication/io/impl/Atom10Generator.java b/src/main/java/com/sun/syndication/io/impl/Atom10Generator.java index b8ab76d..123e509 100644 --- a/src/main/java/com/sun/syndication/io/impl/Atom10Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/Atom10Generator.java @@ -16,8 +16,10 @@ */ package com.sun.syndication.io.impl; +import java.io.IOException; import java.io.StringReader; -import java.util.Iterator; +import java.io.Writer; +import java.util.ArrayList; import java.util.List; import org.jdom2.Attribute; @@ -25,6 +27,7 @@ import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.Namespace; import org.jdom2.input.SAXBuilder; +import org.jdom2.output.XMLOutputter; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.atom.Category; @@ -36,60 +39,57 @@ import com.sun.syndication.feed.atom.Link; import com.sun.syndication.feed.atom.Person; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedOutput; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import org.jdom2.output.XMLOutputter; /** * Feed Generator for Atom *

- * + * * @author Elaine Chien * @author Dave Johnson (updated for Atom 1.0) - * + * */ public class Atom10Generator extends BaseWireFeedGenerator { private static final String ATOM_10_URI = "http://www.w3.org/2005/Atom"; private static final Namespace ATOM_NS = Namespace.getNamespace(ATOM_10_URI); - private String _version; + private final String _version; public Atom10Generator() { - this("atom_1.0","1.0"); + this("atom_1.0", "1.0"); } - protected Atom10Generator(String type,String version) { + protected Atom10Generator(final String type, final String version) { super(type); - _version = version; + this._version = version; } protected String getVersion() { - return _version; + return this._version; } protected Namespace getFeedNamespace() { return ATOM_NS; } - public Document generate(WireFeed wFeed) throws FeedException { - Feed feed = (Feed) wFeed; - Element root = createRootElement(feed); - populateFeed(feed,root); + @Override + public Document generate(final WireFeed wFeed) throws FeedException { + final Feed feed = (Feed) wFeed; + final Element root = createRootElement(feed); + populateFeed(feed, root); purgeUnusedNamespaceDeclarations(root); return createDocument(root); } - protected Document createDocument(Element root) { + protected Document createDocument(final Element root) { return new Document(root); } - protected Element createRootElement(Feed feed) { - Element root = new Element("feed",getFeedNamespace()); + protected Element createRootElement(final Feed feed) { + final Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); - //Attribute version = new Attribute("version", getVersion()); - //root.setAttribute(version); + // Attribute version = new Attribute("version", getVersion()); + // root.setAttribute(version); if (feed.getXmlBase() != null) { root.setAttribute("base", feed.getXmlBase(), Namespace.XML_NAMESPACE); } @@ -97,82 +97,88 @@ public class Atom10Generator extends BaseWireFeedGenerator { return root; } - protected void populateFeed(Feed feed,Element parent) throws FeedException { - addFeed(feed,parent); - addEntries(feed,parent); + protected void populateFeed(final Feed feed, final Element parent) throws FeedException { + addFeed(feed, parent); + addEntries(feed, parent); } - protected void addFeed(Feed feed,Element parent) throws FeedException { - Element eFeed = parent; - populateFeedHeader(feed,eFeed); - generateForeignMarkup(eFeed, (List)feed.getForeignMarkup()); + protected void addFeed(final Feed feed, final Element parent) throws FeedException { + final Element eFeed = parent; + populateFeedHeader(feed, eFeed); + generateForeignMarkup(eFeed, feed.getForeignMarkup()); checkFeedHeaderConstraints(eFeed); - generateFeedModules(feed.getModules(),eFeed); + generateFeedModules(feed.getModules(), eFeed); } - protected void addEntries(Feed feed,Element parent) throws FeedException { - List items = feed.getEntries(); - for (int i=0;i items = feed.getEntries(); + for (int i = 0; i < items.size(); i++) { + addEntry(items.get(i), parent); } checkEntriesConstraints(parent); } - protected void addEntry(Entry entry,Element parent) throws FeedException { - Element eEntry = new Element("entry", getFeedNamespace()); + protected void addEntry(final Entry entry, final Element parent) throws FeedException { + final Element eEntry = new Element("entry", getFeedNamespace()); if (entry.getXmlBase() != null) { eEntry.setAttribute("base", entry.getXmlBase(), Namespace.XML_NAMESPACE); } - populateEntry(entry,eEntry); - generateForeignMarkup(eEntry, (List)entry.getForeignMarkup()); + populateEntry(entry, eEntry); + generateForeignMarkup(eEntry, entry.getForeignMarkup()); checkEntryConstraints(eEntry); - generateItemModules(entry.getModules(),eEntry); + generateItemModules(entry.getModules(), eEntry); parent.addContent(eEntry); } - protected void populateFeedHeader(Feed feed,Element eFeed) throws FeedException { + protected void populateFeedHeader(final Feed feed, final Element eFeed) throws FeedException { if (feed.getTitleEx() != null) { - Element titleElement = new Element("title", getFeedNamespace()); + final Element titleElement = new Element("title", getFeedNamespace()); fillContentElement(titleElement, feed.getTitleEx()); eFeed.addContent(titleElement); } List links = feed.getAlternateLinks(); - if (links != null) for (int i = 0; i < links.size(); i++) { - eFeed.addContent(generateLinkElement((Link)links.get(i))); + if (links != null) { + for (int i = 0; i < links.size(); i++) { + eFeed.addContent(generateLinkElement(links.get(i))); + } } links = feed.getOtherLinks(); - if (links != null) for (int j = 0; j < links.size(); j++) { - eFeed.addContent(generateLinkElement((Link)links.get(j))); + if (links != null) { + for (int j = 0; j < links.size(); j++) { + eFeed.addContent(generateLinkElement(links.get(j))); + } } - List cats = feed.getCategories(); - if (cats != null) for (Iterator iter=cats.iterator(); iter.hasNext();) { - eFeed.addContent(generateCategoryElement((Category)iter.next())); + final List cats = feed.getCategories(); + if (cats != null) { + for (final Category category : cats) { + eFeed.addContent(generateCategoryElement(category)); + } } - - List authors = feed.getAuthors(); + + final List authors = feed.getAuthors(); if (authors != null && authors.size() > 0) { for (int i = 0; i < authors.size(); i++) { - Element authorElement = new Element("author", getFeedNamespace()); - fillPersonElement(authorElement, (Person)feed.getAuthors().get(i)); + final Element authorElement = new Element("author", getFeedNamespace()); + fillPersonElement(authorElement, feed.getAuthors().get(i)); eFeed.addContent(authorElement); } } - List contributors = feed.getContributors(); + final List contributors = feed.getContributors(); if (contributors != null && contributors.size() > 0) { for (int i = 0; i < contributors.size(); i++) { - Element contributorElement = new Element("contributor", getFeedNamespace()); - fillPersonElement(contributorElement, (Person)contributors.get(i)); + final Element contributorElement = new Element("contributor", getFeedNamespace()); + fillPersonElement(contributorElement, contributors.get(i)); eFeed.addContent(contributorElement); } } if (feed.getSubtitle() != null) { - Element subtitleElement = new Element("subtitle", getFeedNamespace()); - fillContentElement(subtitleElement, feed.getSubtitle()); - eFeed.addContent(subtitleElement); + final Element subtitleElement = new Element("subtitle", getFeedNamespace()); + fillContentElement(subtitleElement, feed.getSubtitle()); + eFeed.addContent(subtitleElement); } if (feed.getId() != null) { @@ -188,60 +194,60 @@ public class Atom10Generator extends BaseWireFeedGenerator { } if (feed.getIcon() != null) { - eFeed.addContent(generateSimpleElement("icon", feed.getIcon())); + eFeed.addContent(generateSimpleElement("icon", feed.getIcon())); } if (feed.getLogo() != null) { - eFeed.addContent(generateSimpleElement("logo", feed.getLogo())); + eFeed.addContent(generateSimpleElement("logo", feed.getLogo())); } if (feed.getUpdated() != null) { - Element updatedElement = new Element("updated", getFeedNamespace()); + final Element updatedElement = new Element("updated", getFeedNamespace()); updatedElement.addContent(DateParser.formatW3CDateTime(feed.getUpdated())); eFeed.addContent(updatedElement); } } - protected void populateEntry(Entry entry, Element eEntry) throws FeedException { + protected void populateEntry(final Entry entry, final Element eEntry) throws FeedException { if (entry.getTitleEx() != null) { - Element titleElement = new Element("title", getFeedNamespace()); + final Element titleElement = new Element("title", getFeedNamespace()); fillContentElement(titleElement, entry.getTitleEx()); eEntry.addContent(titleElement); } List links = entry.getAlternateLinks(); if (links != null) { for (int i = 0; i < links.size(); i++) { - eEntry.addContent(generateLinkElement((Link)links.get(i))); + eEntry.addContent(generateLinkElement(links.get(i))); } } links = entry.getOtherLinks(); if (links != null) { for (int i = 0; i < links.size(); i++) { - eEntry.addContent(generateLinkElement((Link)links.get(i))); + eEntry.addContent(generateLinkElement(links.get(i))); } } - List cats = entry.getCategories(); + final List cats = entry.getCategories(); if (cats != null) { for (int i = 0; i < cats.size(); i++) { - eEntry.addContent(generateCategoryElement((Category)cats.get(i))); - } - } - - List authors = entry.getAuthors(); - if (authors != null && authors.size() > 0) { - for (int i = 0; i < authors.size(); i++) { - Element authorElement = new Element("author", getFeedNamespace()); - fillPersonElement(authorElement, (Person)entry.getAuthors().get(i)); - eEntry.addContent(authorElement); + eEntry.addContent(generateCategoryElement(cats.get(i))); } } - List contributors = entry.getContributors(); + final List authors = entry.getAuthors(); + if (authors != null && authors.size() > 0) { + for (int i = 0; i < authors.size(); i++) { + final Element authorElement = new Element("author", getFeedNamespace()); + fillPersonElement(authorElement, entry.getAuthors().get(i)); + eEntry.addContent(authorElement); + } + } + + final List contributors = entry.getContributors(); if (contributors != null && contributors.size() > 0) { for (int i = 0; i < contributors.size(); i++) { - Element contributorElement = new Element("contributor", getFeedNamespace()); - fillPersonElement(contributorElement, (Person)contributors.get(i)); + final Element contributorElement = new Element("contributor", getFeedNamespace()); + fillPersonElement(contributorElement, contributors.get(i)); eEntry.addContent(contributorElement); } } @@ -250,102 +256,100 @@ public class Atom10Generator extends BaseWireFeedGenerator { } if (entry.getUpdated() != null) { - Element updatedElement = new Element("updated", getFeedNamespace()); + final Element updatedElement = new Element("updated", getFeedNamespace()); updatedElement.addContent(DateParser.formatW3CDateTime(entry.getUpdated())); eEntry.addContent(updatedElement); } if (entry.getPublished() != null) { - Element publishedElement = new Element("published", getFeedNamespace()); + final Element publishedElement = new Element("published", getFeedNamespace()); publishedElement.addContent(DateParser.formatW3CDateTime(entry.getPublished())); eEntry.addContent(publishedElement); } if (entry.getContents() != null && entry.getContents().size() > 0) { - Element contentElement = new Element("content", getFeedNamespace()); - Content content = (Content)entry.getContents().get(0); + final Element contentElement = new Element("content", getFeedNamespace()); + final Content content = entry.getContents().get(0); fillContentElement(contentElement, content); eEntry.addContent(contentElement); } if (entry.getSummary() != null) { - Element summaryElement = new Element("summary", getFeedNamespace()); + final Element summaryElement = new Element("summary", getFeedNamespace()); fillContentElement(summaryElement, entry.getSummary()); eEntry.addContent(summaryElement); } if (entry.getSource() != null) { - Element sourceElement = new Element("source", getFeedNamespace()); + final Element sourceElement = new Element("source", getFeedNamespace()); populateFeedHeader(entry.getSource(), sourceElement); eEntry.addContent(sourceElement); } } - protected void checkFeedHeaderConstraints(Element eFeed) throws FeedException { + protected void checkFeedHeaderConstraints(final Element eFeed) throws FeedException { } - protected void checkEntriesConstraints(Element parent) throws FeedException { + protected void checkEntriesConstraints(final Element parent) throws FeedException { } - protected void checkEntryConstraints(Element eEntry) throws FeedException { + protected void checkEntryConstraints(final Element eEntry) throws FeedException { } - - protected Element generateCategoryElement(Category cat) { - Element catElement = new Element("category", getFeedNamespace()); + protected Element generateCategoryElement(final Category cat) { + final Element catElement = new Element("category", getFeedNamespace()); if (cat.getTerm() != null) { - Attribute termAttribute = new Attribute("term", cat.getTerm()); + final Attribute termAttribute = new Attribute("term", cat.getTerm()); catElement.setAttribute(termAttribute); } if (cat.getLabel() != null) { - Attribute labelAttribute = new Attribute("label", cat.getLabel()); + final Attribute labelAttribute = new Attribute("label", cat.getLabel()); catElement.setAttribute(labelAttribute); } if (cat.getScheme() != null) { - Attribute schemeAttribute = new Attribute("scheme", cat.getScheme()); + final Attribute schemeAttribute = new Attribute("scheme", cat.getScheme()); catElement.setAttribute(schemeAttribute); } return catElement; } - protected Element generateLinkElement(Link link) { - Element linkElement = new Element("link", getFeedNamespace()); + protected Element generateLinkElement(final Link link) { + final Element linkElement = new Element("link", getFeedNamespace()); if (link.getRel() != null) { - Attribute relAttribute = new Attribute("rel", link.getRel()); + final Attribute relAttribute = new Attribute("rel", link.getRel()); linkElement.setAttribute(relAttribute); } if (link.getType() != null) { - Attribute typeAttribute = new Attribute("type", link.getType()); + final Attribute typeAttribute = new Attribute("type", link.getType()); linkElement.setAttribute(typeAttribute); } if (link.getHref() != null) { - Attribute hrefAttribute = new Attribute("href", link.getHref()); + final Attribute hrefAttribute = new Attribute("href", link.getHref()); linkElement.setAttribute(hrefAttribute); } - + if (link.getHreflang() != null) { - Attribute hreflangAttribute = new Attribute("hreflang", link.getHreflang()); + final Attribute hreflangAttribute = new Attribute("hreflang", link.getHreflang()); linkElement.setAttribute(hreflangAttribute); } if (link.getTitle() != null) { - Attribute title = new Attribute("title", link.getTitle()); + final Attribute title = new Attribute("title", link.getTitle()); linkElement.setAttribute(title); } if (link.getLength() != 0) { - Attribute lenght = new Attribute("length", Long.toString(link.getLength())); + final Attribute lenght = new Attribute("length", Long.toString(link.getLength())); linkElement.setAttribute(lenght); } return linkElement; } - - protected void fillPersonElement(Element element, Person person) { + protected void fillPersonElement(final Element element, final Person person) { if (person.getName() != null) { element.addContent(generateSimpleElement("name", person.getName())); } @@ -359,11 +363,11 @@ public class Atom10Generator extends BaseWireFeedGenerator { generatePersonModules(person.getModules(), element); } - protected Element generateTagLineElement(Content tagline) { - Element taglineElement = new Element("subtitle", getFeedNamespace()); + protected Element generateTagLineElement(final Content tagline) { + final Element taglineElement = new Element("subtitle", getFeedNamespace()); if (tagline.getType() != null) { - Attribute typeAttribute = new Attribute("type", tagline.getType()); + final Attribute typeAttribute = new Attribute("type", tagline.getType()); taglineElement.setAttribute(typeAttribute); } @@ -373,45 +377,46 @@ public class Atom10Generator extends BaseWireFeedGenerator { return taglineElement; } - protected void fillContentElement(Element contentElement, Content content) - throws FeedException { + protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { - String type = content.getType(); - String atomType = type; + final String type = content.getType(); + String atomType = type; if (type != null) { // Fix for issue #39 "Atom 1.0 Text Types Not Set Correctly" // we're not sure who set this value, so ensure Atom types are used - if ("text/plain".equals(type)) atomType = Content.TEXT; - else if ("text/html".equals(type)) atomType = Content.HTML; - else if ("application/xhtml+xml".equals(type)) atomType = Content.XHTML; - - Attribute typeAttribute = new Attribute("type", atomType); + if ("text/plain".equals(type)) { + atomType = Content.TEXT; + } else if ("text/html".equals(type)) { + atomType = Content.HTML; + } else if ("application/xhtml+xml".equals(type)) { + atomType = Content.XHTML; + } + + final Attribute typeAttribute = new Attribute("type", atomType); contentElement.setAttribute(typeAttribute); } - String href = content.getSrc(); + final String href = content.getSrc(); if (href != null) { - Attribute srcAttribute = new Attribute("src", href); + final Attribute srcAttribute = new Attribute("src", href); contentElement.setAttribute(srcAttribute); } if (content.getValue() != null) { - if (atomType != null && (atomType.equals(Content.XHTML) || (atomType.indexOf("/xml")) != -1 || - (atomType.indexOf("+xml")) != -1)) { + if (atomType != null && (atomType.equals(Content.XHTML) || atomType.indexOf("/xml") != -1 || atomType.indexOf("+xml") != -1)) { - StringBuffer tmpDocString = new StringBuffer(""); + final StringBuffer tmpDocString = new StringBuffer(""); tmpDocString.append(content.getValue()); tmpDocString.append(""); - StringReader tmpDocReader = new StringReader(tmpDocString.toString()); + final StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { - SAXBuilder saxBuilder = new SAXBuilder(); + final SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); + } catch (final Exception ex) { + throw new FeedException("Invalid XML", ex); } - catch (Exception ex) { - throw new FeedException("Invalid XML",ex); - } - List children = tmpDoc.getRootElement().removeContent(); + final List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); - } else { + } else { // must be type html, text or some other non-XML format // JDOM will escape property for XML contentElement.addContent(content.getValue()); @@ -419,16 +424,16 @@ public class Atom10Generator extends BaseWireFeedGenerator { } } - protected Element generateGeneratorElement(Generator generator) { - Element generatorElement = new Element("generator", getFeedNamespace()); + protected Element generateGeneratorElement(final Generator generator) { + final Element generatorElement = new Element("generator", getFeedNamespace()); if (generator.getUrl() != null) { - Attribute urlAttribute = new Attribute("uri", generator.getUrl()); + final Attribute urlAttribute = new Attribute("uri", generator.getUrl()); generatorElement.setAttribute(urlAttribute); } if (generator.getVersion() != null) { - Attribute versionAttribute = new Attribute("version", generator.getVersion()); + final Attribute versionAttribute = new Attribute("version", generator.getVersion()); generatorElement.setAttribute(versionAttribute); } @@ -440,33 +445,32 @@ public class Atom10Generator extends BaseWireFeedGenerator { } - protected Element generateSimpleElement(String name, String value) { - Element element = new Element(name, getFeedNamespace()); + protected Element generateSimpleElement(final String name, final String value) { + final Element element = new Element(name, getFeedNamespace()); element.addContent(value); return element; } - + /** * Utility method to serialize an entry to writer. */ - public static void serializeEntry(Entry entry, Writer writer) - throws IllegalArgumentException, FeedException, IOException { - + public static void serializeEntry(final Entry entry, final Writer writer) throws IllegalArgumentException, FeedException, IOException { + // Build a feed containing only the entry - List entries = new ArrayList(); + final List entries = new ArrayList(); entries.add(entry); - Feed feed1 = new Feed(); + final Feed feed1 = new Feed(); feed1.setFeedType("atom_1.0"); feed1.setEntries(entries); // Get Rome to output feed as a JDOM document - WireFeedOutput wireFeedOutput = new WireFeedOutput(); - Document feedDoc = wireFeedOutput.outputJDom(feed1); + final WireFeedOutput wireFeedOutput = new WireFeedOutput(); + final Document feedDoc = wireFeedOutput.outputJDom(feed1); // Grab entry element from feed and get JDOM to serialize it - Element entryElement= (Element)feedDoc.getRootElement().getChildren().get(0); + final Element entryElement = feedDoc.getRootElement().getChildren().get(0); - XMLOutputter outputter = new XMLOutputter(); + final XMLOutputter outputter = new XMLOutputter(); outputter.output(entryElement, writer); } diff --git a/src/main/java/com/sun/syndication/io/impl/Atom10Parser.java b/src/main/java/com/sun/syndication/io/impl/Atom10Parser.java index 32b685c..4f68894 100644 --- a/src/main/java/com/sun/syndication/io/impl/Atom10Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/Atom10Parser.java @@ -16,14 +16,22 @@ */ package com.sun.syndication.io.impl; +import java.io.IOException; +import java.io.Reader; +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.regex.Pattern; -import org.jdom2.Document; +import org.jdom2.Attribute; +import org.jdom2.Document; import org.jdom2.Element; +import org.jdom2.JDOMException; import org.jdom2.Namespace; -import org.jdom2.output.XMLOutputter; +import org.jdom2.Parent; +import org.jdom2.input.SAXBuilder; +import org.jdom2.output.XMLOutputter; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.atom.Category; @@ -36,17 +44,10 @@ import com.sun.syndication.feed.atom.Person; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.WireFeedInput; import com.sun.syndication.io.WireFeedOutput; -import java.io.IOException; -import java.io.Reader; -import java.net.MalformedURLException; -import java.util.regex.Pattern; -import org.jdom2.Attribute; -import org.jdom2.JDOMException; -import org.jdom2.Parent; -import org.jdom2.input.SAXBuilder; /** * Parser for Atom 1.0 + * * @author Dave Johnson */ public class Atom10Parser extends BaseWireFeedParser { @@ -55,7 +56,7 @@ public class Atom10Parser extends BaseWireFeedParser { private static boolean resolveURIs = false; - public static void setResolveURIs(boolean resolveURIs) { + public static void setResolveURIs(final boolean resolveURIs) { Atom10Parser.resolveURIs = resolveURIs; } @@ -66,268 +67,266 @@ public class Atom10Parser extends BaseWireFeedParser { public Atom10Parser() { this("atom_1.0"); } - - protected Atom10Parser(String type) { + + protected Atom10Parser(final String type) { super(type, ATOM_10_NS); } - + protected Namespace getAtomNamespace() { return ATOM_10_NS; } - - public boolean isMyType(Document document) { - Element rssRoot = document.getRootElement(); - Namespace defaultNS = rssRoot.getNamespace(); - return (defaultNS!=null) && defaultNS.equals(getAtomNamespace()); + + @Override + public boolean isMyType(final Document document) { + final Element rssRoot = document.getRootElement(); + final Namespace defaultNS = rssRoot.getNamespace(); + return defaultNS != null && defaultNS.equals(getAtomNamespace()); } - - public WireFeed parse(Document document, boolean validate) - throws IllegalArgumentException,FeedException { + + @Override + public WireFeed parse(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { if (validate) { validateFeed(document); } - Element rssRoot = document.getRootElement(); + final Element rssRoot = document.getRootElement(); return parseFeed(rssRoot); } - - protected void validateFeed(Document document) throws FeedException { + + protected void validateFeed(final Document document) throws FeedException { // TBD // here we have to validate the Feed against a schema or whatever // not sure how to do it - // one posibility would be to produce an ouput and attempt to parse it again + // one posibility would be to produce an ouput and attempt to parse it + // again // with validation turned on. // otherwise will have to check the document elements by hand. } - - protected WireFeed parseFeed(Element eFeed) throws FeedException { - + + protected WireFeed parseFeed(final Element eFeed) throws FeedException { + String baseURI = null; try { baseURI = findBaseURI(eFeed); - } catch (Exception e) { + } catch (final Exception e) { throw new FeedException("ERROR while finding base URI of feed", e); } - - Feed feed = parseFeedMetadata(baseURI, eFeed); - String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE); + final Feed feed = parseFeedMetadata(baseURI, eFeed); + + final String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE); if (xmlBase != null) { feed.setXmlBase(xmlBase); } - + feed.setModules(parseFeedModules(eFeed)); - List eList = eFeed.getChildren("entry",getAtomNamespace()); - if (eList.size()>0) { + final List eList = eFeed.getChildren("entry", getAtomNamespace()); + if (eList.size() > 0) { feed.setEntries(parseEntries(feed, baseURI, eList)); } - List foreignMarkup = - extractForeignMarkup(eFeed, feed, getAtomNamespace()); + final List foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace()); if (foreignMarkup.size() > 0) { feed.setForeignMarkup(foreignMarkup); } return feed; } - private Feed parseFeedMetadata(String baseURI, Element eFeed) { - com.sun.syndication.feed.atom.Feed feed = - new com.sun.syndication.feed.atom.Feed(getType()); + private Feed parseFeedMetadata(final String baseURI, final Element eFeed) { + final com.sun.syndication.feed.atom.Feed feed = new com.sun.syndication.feed.atom.Feed(getType()); - Element e = eFeed.getChild("title",getAtomNamespace()); - if (e!=null) { - Content c = new Content(); + Element e = eFeed.getChild("title", getAtomNamespace()); + if (e != null) { + final Content c = new Content(); c.setValue(parseTextConstructToString(e)); c.setType(getAttributeValue(e, "type")); feed.setTitleEx(c); } - - List eList = eFeed.getChildren("link",getAtomNamespace()); + + List eList = eFeed.getChildren("link", getAtomNamespace()); feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, eList)); feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, eList)); - - List cList = eFeed.getChildren("category",getAtomNamespace()); + + final List cList = eFeed.getChildren("category", getAtomNamespace()); feed.setCategories(parseCategories(baseURI, cList)); - + eList = eFeed.getChildren("author", getAtomNamespace()); - if (eList.size()>0) { + if (eList.size() > 0) { feed.setAuthors(parsePersons(baseURI, eList)); } - - eList = eFeed.getChildren("contributor",getAtomNamespace()); - if (eList.size()>0) { + + eList = eFeed.getChildren("contributor", getAtomNamespace()); + if (eList.size() > 0) { feed.setContributors(parsePersons(baseURI, eList)); } - - e = eFeed.getChild("subtitle",getAtomNamespace()); - if (e!=null) { - Content subtitle = new Content(); + + e = eFeed.getChild("subtitle", getAtomNamespace()); + if (e != null) { + final Content subtitle = new Content(); subtitle.setValue(parseTextConstructToString(e)); subtitle.setType(getAttributeValue(e, "type")); feed.setSubtitle(subtitle); } - - e = eFeed.getChild("id",getAtomNamespace()); - if (e!=null) { + + e = eFeed.getChild("id", getAtomNamespace()); + if (e != null) { feed.setId(e.getText()); } - - e = eFeed.getChild("generator",getAtomNamespace()); - if (e!=null) { - Generator gen = new Generator(); + + e = eFeed.getChild("generator", getAtomNamespace()); + if (e != null) { + final Generator gen = new Generator(); gen.setValue(e.getText()); String att = getAttributeValue(e, "uri"); - if (att!=null) { + if (att != null) { gen.setUrl(att); } att = getAttributeValue(e, "version"); - if (att!=null) { + if (att != null) { gen.setVersion(att); } feed.setGenerator(gen); } - - e = eFeed.getChild("rights",getAtomNamespace()); - if (e!=null) { + + e = eFeed.getChild("rights", getAtomNamespace()); + if (e != null) { feed.setRights(parseTextConstructToString(e)); } - - e = eFeed.getChild("icon",getAtomNamespace()); - if (e!=null) { + + e = eFeed.getChild("icon", getAtomNamespace()); + if (e != null) { feed.setIcon(e.getText()); } - - e = eFeed.getChild("logo",getAtomNamespace()); - if (e!=null) { + + e = eFeed.getChild("logo", getAtomNamespace()); + if (e != null) { feed.setLogo(e.getText()); } - - e = eFeed.getChild("updated",getAtomNamespace()); - if (e!=null) { + + e = eFeed.getChild("updated", getAtomNamespace()); + if (e != null) { feed.setUpdated(DateParser.parseDate(e.getText())); } - + return feed; } - private Link parseLink(Feed feed , Entry entry, String baseURI, Element eLink) { - Link link = new Link(); + private Link parseLink(final Feed feed, final Entry entry, final String baseURI, final Element eLink) { + final Link link = new Link(); String att = getAttributeValue(eLink, "rel"); - if (att!=null) { + if (att != null) { link.setRel(att); } att = getAttributeValue(eLink, "type"); - if (att!=null) { + if (att != null) { link.setType(att); } att = getAttributeValue(eLink, "href"); - if (att!=null) { + if (att != null) { link.setHref(att); if (isRelativeURI(att)) { link.setHrefResolved(resolveURI(baseURI, eLink, att)); - } + } } att = getAttributeValue(eLink, "title"); - if (att!=null) { + if (att != null) { link.setTitle(att); } att = getAttributeValue(eLink, "hreflang"); - if (att!=null) { + if (att != null) { link.setHreflang(att); } att = getAttributeValue(eLink, "length"); - if (att!=null) { - Long val = NumberParser.parseLong(att); - if (val != null) { - link.setLength(val.longValue()); - } + if (att != null) { + final Long val = NumberParser.parseLong(att); + if (val != null) { + link.setLength(val.longValue()); + } } return link; } - + // List(Elements) -> List(Link) - private List parseAlternateLinks(Feed feed, Entry entry, String baseURI, List eLinks) { - List links = new ArrayList(); - for (int i=0;i parseAlternateLinks(final Feed feed, final Entry entry, final String baseURI, final List eLinks) { + final List links = new ArrayList(); + for (int i = 0; i < eLinks.size(); i++) { + final Element eLink = eLinks.get(i); + final Link link = parseLink(feed, entry, baseURI, eLink); + if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) { links.add(link); } } - return (links.size()>0) ? links : null; + return links.size() > 0 ? links : null; } - - private List parseOtherLinks(Feed feed, Entry entry, String baseURI, List eLinks) { - List links = new ArrayList(); - for (int i=0;i parseOtherLinks(final Feed feed, final Entry entry, final String baseURI, final List eLinks) { + final List links = new ArrayList(); + for (int i = 0; i < eLinks.size(); i++) { + final Element eLink = eLinks.get(i); + final Link link = parseLink(feed, entry, baseURI, eLink); if (!"alternate".equals(link.getRel())) { links.add(link); } } - return (links.size()>0) ? links : null; + return links.size() > 0 ? links : null; } - - private Person parsePerson(String baseURI, Element ePerson) { - Person person = new Person(); - Element e = ePerson.getChild("name",getAtomNamespace()); - if (e!=null) { + + private Person parsePerson(final String baseURI, final Element ePerson) { + final Person person = new Person(); + Element e = ePerson.getChild("name", getAtomNamespace()); + if (e != null) { person.setName(e.getText()); } - e = ePerson.getChild("uri",getAtomNamespace()); - if (e!=null) { + e = ePerson.getChild("uri", getAtomNamespace()); + if (e != null) { person.setUri(e.getText()); if (isRelativeURI(e.getText())) { - person.setUriResolved(resolveURI(baseURI, ePerson, e.getText())); + person.setUriResolved(resolveURI(baseURI, ePerson, e.getText())); } } - e = ePerson.getChild("email",getAtomNamespace()); - if (e!=null) { + e = ePerson.getChild("email", getAtomNamespace()); + if (e != null) { person.setEmail(e.getText()); } - person.setModules(parsePersonModules(ePerson)); + person.setModules(parsePersonModules(ePerson)); return person; } - + // List(Elements) -> List(Persons) - private List parsePersons(String baseURI, List ePersons) { - List persons = new ArrayList(); - for (int i=0;i parsePersons(final String baseURI, final List ePersons) { + final List persons = new ArrayList(); + for (int i = 0; i < ePersons.size(); i++) { + persons.add(parsePerson(baseURI, ePersons.get(i))); } - return (persons.size()>0) ? persons : null; + return persons.size() > 0 ? persons : null; } - - private Content parseContent(Element e) { - String value = parseTextConstructToString(e); - String src = getAttributeValue(e, "src"); - String type = getAttributeValue(e, "type"); - Content content = new Content(); + + private Content parseContent(final Element e) { + final String value = parseTextConstructToString(e); + final String src = getAttributeValue(e, "src"); + final String type = getAttributeValue(e, "type"); + final Content content = new Content(); content.setSrc(src); content.setType(type); content.setValue(value); return content; } - - private String parseTextConstructToString(Element e) { + + private String parseTextConstructToString(final Element e) { String value = null; String type = getAttributeValue(e, "type"); - type = (type!=null) ? type : Content.TEXT; - if (type.equals(Content.XHTML) || (type.indexOf("/xml")) != -1 || (type.indexOf("+xml")) != -1) { + type = type != null ? type : Content.TEXT; + if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) { // XHTML content needs special handling - XMLOutputter outputter = new XMLOutputter(); - List eContent = e.getContent(); - Iterator i = eContent.iterator(); + final XMLOutputter outputter = new XMLOutputter(); + final List eContent = e.getContent(); + final Iterator i = eContent.iterator(); while (i.hasNext()) { - org.jdom2.Content c = (org.jdom2.Content) i.next(); + final org.jdom2.Content c = i.next(); if (c instanceof Element) { - Element eC = (Element) c; + final Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { - ((Element)c).setNamespace(Namespace.NO_NAMESPACE); + ((Element) c).setNamespace(Namespace.NO_NAMESPACE); } } } @@ -338,237 +337,244 @@ public class Atom10Parser extends BaseWireFeedParser { } return value; } - + // List(Elements) -> List(Entries) - protected List parseEntries(Feed feed, String baseURI, List eEntries) { - List entries = new ArrayList(); - for (int i=0;i parseEntries(final Feed feed, final String baseURI, final List eEntries) { + final List entries = new ArrayList(); + for (int i = 0; i < eEntries.size(); i++) { + entries.add(this.parseEntry(feed, eEntries.get(i), baseURI)); } - return (entries.size()>0) ? entries : null; + return entries.size() > 0 ? entries : null; } - - protected Entry parseEntry(Feed feed, Element eEntry, String baseURI) { - Entry entry = new Entry(); - - String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE); + + protected Entry parseEntry(final Feed feed, final Element eEntry, final String baseURI) { + final Entry entry = new Entry(); + + final String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE); if (xmlBase != null) { entry.setXmlBase(xmlBase); } - - Element e = eEntry.getChild("title",getAtomNamespace()); - if (e!=null) { - Content c = new Content(); + + Element e = eEntry.getChild("title", getAtomNamespace()); + if (e != null) { + final Content c = new Content(); c.setValue(parseTextConstructToString(e)); c.setType(getAttributeValue(e, "type")); entry.setTitleEx(c); } - - List eList = eEntry.getChildren("link",getAtomNamespace()); + + List eList = eEntry.getChildren("link", getAtomNamespace()); entry.setAlternateLinks(parseAlternateLinks(feed, entry, baseURI, eList)); entry.setOtherLinks(parseOtherLinks(feed, entry, baseURI, eList)); - + eList = eEntry.getChildren("author", getAtomNamespace()); - if (eList.size()>0) { + if (eList.size() > 0) { entry.setAuthors(parsePersons(baseURI, eList)); } - - eList = eEntry.getChildren("contributor",getAtomNamespace()); - if (eList.size()>0) { + + eList = eEntry.getChildren("contributor", getAtomNamespace()); + if (eList.size() > 0) { entry.setContributors(parsePersons(baseURI, eList)); } - - e = eEntry.getChild("id",getAtomNamespace()); - if (e!=null) { + + e = eEntry.getChild("id", getAtomNamespace()); + if (e != null) { entry.setId(e.getText()); } - - e = eEntry.getChild("updated",getAtomNamespace()); - if (e!=null) { + + e = eEntry.getChild("updated", getAtomNamespace()); + if (e != null) { entry.setUpdated(DateParser.parseDate(e.getText())); } - - e = eEntry.getChild("published",getAtomNamespace()); - if (e!=null) { + + e = eEntry.getChild("published", getAtomNamespace()); + if (e != null) { entry.setPublished(DateParser.parseDate(e.getText())); } - - e = eEntry.getChild("summary",getAtomNamespace()); - if (e!=null) { + + e = eEntry.getChild("summary", getAtomNamespace()); + if (e != null) { entry.setSummary(parseContent(e)); } - - e = eEntry.getChild("content",getAtomNamespace()); - if (e!=null) { - List contents = new ArrayList(); + + e = eEntry.getChild("content", getAtomNamespace()); + if (e != null) { + final List contents = new ArrayList(); contents.add(parseContent(e)); entry.setContents(contents); } - - e = eEntry.getChild("rights",getAtomNamespace()); - if (e!=null) { + + e = eEntry.getChild("rights", getAtomNamespace()); + if (e != null) { entry.setRights(e.getText()); } - - List cList = eEntry.getChildren("category",getAtomNamespace()); + + final List cList = eEntry.getChildren("category", getAtomNamespace()); entry.setCategories(parseCategories(baseURI, cList)); - + // TODO: SHOULD handle Atom entry source element e = eEntry.getChild("source", getAtomNamespace()); - if (e!=null) { + if (e != null) { entry.setSource(parseFeedMetadata(baseURI, e)); } - + entry.setModules(parseItemModules(eEntry)); - - List foreignMarkup = - extractForeignMarkup(eEntry, entry, getAtomNamespace()); + + final List foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace()); if (foreignMarkup.size() > 0) { entry.setForeignMarkup(foreignMarkup); } return entry; } - - private List parseCategories(String baseURI, List eCategories) { - List cats = new ArrayList(); - for (int i=0;i parseCategories(final String baseURI, final List eCategories) { + final List cats = new ArrayList(); + for (int i = 0; i < eCategories.size(); i++) { + final Element eCategory = eCategories.get(i); cats.add(parseCategory(baseURI, eCategory)); } - return (cats.size()>0) ? cats : null; + return cats.size() > 0 ? cats : null; } - - private Category parseCategory(String baseURI, Element eCategory) { - Category category = new Category(); + + private Category parseCategory(final String baseURI, final Element eCategory) { + final Category category = new Category(); String att = getAttributeValue(eCategory, "term"); - if (att!=null) { + if (att != null) { category.setTerm(att); } att = getAttributeValue(eCategory, "scheme"); - if (att!=null) { + if (att != null) { category.setScheme(att); if (isRelativeURI(att)) { category.setSchemeResolved(resolveURI(baseURI, eCategory, att)); } } att = getAttributeValue(eCategory, "label"); - if (att!=null) { + if (att != null) { category.setLabel(att); } return category; - + } - - // Once following relative URI methods are made public in the ROME + + // Once following relative URI methods are made public in the ROME // Atom10Parser, then use them instead and delete these. - - + // Fix for issue #34 "valid IRI href attributes are stripped for atom:link" // URI's that didn't start with http were being treated as relative URIs. // So now consider an absolute URI to be any alpha-numeric string followed // by a colon, followed by anything -- specified by this regex: static Pattern absoluteURIPattern = Pattern.compile("^[a-z0-9]*:.*$"); - - public static boolean isAbsoluteURI(String uri) { + + public static boolean isAbsoluteURI(final String uri) { return absoluteURIPattern.matcher(uri).find(); } - + /** Returns true if URI is relative. */ - public static boolean isRelativeURI(String uri) { + public static boolean isRelativeURI(final String uri) { return !isAbsoluteURI(uri); } - + /** - * Resolve URI via base URL and parent element. - * Resolve URI based considering xml:base and baseURI. + * Resolve URI via base URL and parent element. Resolve URI based + * considering xml:base and baseURI. + * * @param baseURI Base URI used to fetch the XML document - * @param parent Parent element from which to consider xml:base - * @param url URL to be resolved + * @param parent Parent element from which to consider xml:base + * @param url URL to be resolved */ - public static String resolveURI(String baseURI, Parent parent, String url) { + public static String resolveURI(final String baseURI, final Parent parent, String url) { if (!resolveURIs) { return url; } if (isRelativeURI(url)) { - url = (!".".equals(url) && !"./".equals(url)) ? url : ""; - + url = !".".equals(url) && !"./".equals(url) ? url : ""; + if (url.startsWith("/") && baseURI != null) { String base = null; - int slashslash = baseURI.indexOf("//"); - int nextslash = baseURI.indexOf("/", slashslash + 2); - if (nextslash != -1) base = baseURI.substring(0, nextslash); - return formURI(base, url); - } + final int slashslash = baseURI.indexOf("//"); + final int nextslash = baseURI.indexOf("/", slashslash + 2); + if (nextslash != -1) { + base = baseURI.substring(0, nextslash); + } + return formURI(base, url); + } // Relative URI with parent if (parent != null && parent instanceof Element) { - // Do we have an xml:base? - String xmlbase = ((Element)parent).getAttributeValue( - "base", Namespace.XML_NAMESPACE); + // Do we have an xml:base? + String xmlbase = ((Element) parent).getAttributeValue("base", Namespace.XML_NAMESPACE); if (xmlbase != null && xmlbase.trim().length() > 0) { if (isAbsoluteURI(xmlbase)) { - // Absolute xml:base, so form URI right now - if (url.startsWith("/")) { + // Absolute xml:base, so form URI right now + if (url.startsWith("/")) { // Host relative URI - int slashslash = xmlbase.indexOf("//"); - int nextslash = xmlbase.indexOf("/", slashslash + 2); - if (nextslash != -1) xmlbase = xmlbase.substring(0, nextslash); - return formURI(xmlbase, url); + final int slashslash = xmlbase.indexOf("//"); + final int nextslash = xmlbase.indexOf("/", slashslash + 2); + if (nextslash != -1) { + xmlbase = xmlbase.substring(0, nextslash); + } + return formURI(xmlbase, url); } if (!xmlbase.endsWith("/")) { - // Base URI is filename, strip it off + // Base URI is filename, strip it off xmlbase = xmlbase.substring(0, xmlbase.lastIndexOf("/")); } return formURI(xmlbase, url); } else { // Relative xml:base, so walk up tree - return resolveURI(baseURI, parent.getParent(), - stripTrailingSlash(xmlbase) + "/"+ stripStartingSlash(url)); + return resolveURI(baseURI, parent.getParent(), stripTrailingSlash(xmlbase) + "/" + stripStartingSlash(url)); } } // No xml:base so walk up tree return resolveURI(baseURI, parent.getParent(), url); - // Relative URI with no parent (i.e. top of tree), so form URI right now + // Relative URI with no parent (i.e. top of tree), so form URI + // right now } else if (parent == null || parent instanceof Document) { - return formURI(baseURI, url); - } - } + return formURI(baseURI, url); + } + } return url; } - + /** * Find base URI of feed considering relative URIs. + * * @param root Root element of feed. */ - private String findBaseURI(Element root) throws MalformedURLException { + private String findBaseURI(final Element root) throws MalformedURLException { String ret = null; if (findAtomLink(root, "self") != null) { ret = findAtomLink(root, "self"); - if (".".equals(ret) || "./".equals(ret)) ret = ""; - if (ret.indexOf("/") != -1) ret = ret.substring(0, ret.lastIndexOf("/")); + if (".".equals(ret) || "./".equals(ret)) { + ret = ""; + } + if (ret.indexOf("/") != -1) { + ret = ret.substring(0, ret.lastIndexOf("/")); + } ret = resolveURI(null, root, ret); } return ret; } - - /** - * Return URL string of Atom link element under parent element. - * Link with no rel attribute is considered to be rel="alternate" + + /** + * Return URL string of Atom link element under parent element. Link with no + * rel attribute is considered to be rel="alternate" + * * @param parent Consider only children of this parent element - * @param rel Consider only links with this relationship + * @param rel Consider only links with this relationship */ - private String findAtomLink(Element parent, String rel) { + private String findAtomLink(final Element parent, final String rel) { String ret = null; - List linksList = parent.getChildren("link", ATOM_10_NS); + final List linksList = parent.getChildren("link", ATOM_10_NS); if (linksList != null) { - for (Iterator links = linksList.iterator(); links.hasNext(); ) { - Element link = (Element)links.next(); - Attribute relAtt = getAttribute(link, "rel"); - Attribute hrefAtt = getAttribute(link, "href"); - if ( (relAtt == null && "alternate".equals(rel)) - || (relAtt != null && relAtt.getValue().equals(rel))) { + for (final Element element : linksList) { + final Element link = element; + final Attribute relAtt = getAttribute(link, "rel"); + final Attribute hrefAtt = getAttribute(link, "href"); + if (relAtt == null && "alternate".equals(rel) || relAtt != null && relAtt.getValue().equals(rel)) { ret = hrefAtt.getValue(); break; } @@ -576,34 +582,36 @@ public class Atom10Parser extends BaseWireFeedParser { } return ret; } - - /** - * Form URI by combining base with append portion and giving - * special consideration to append portions that begin with ".." - * @param base Base of URI, may end with trailing slash + + /** + * Form URI by combining base with append portion and giving special + * consideration to append portions that begin with ".." + * + * @param base Base of URI, may end with trailing slash * @param append String to append, may begin with slash or ".." */ private static String formURI(String base, String append) { base = stripTrailingSlash(base); append = stripStartingSlash(append); if (append.startsWith("..")) { - String ret = null; - String[] parts = append.split("/"); - for (int i=0; i + * * @author Alejandro Abdelnur - * + * */ public class Base64 { /** - * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes. + * Encodes a String into a base 64 String. The resulting encoding is chunked + * at 76 bytes. *

+ * * @param s String to encode. * @return encoded string. - * + * */ public static String encode(String s) { - byte[] sBytes = s.getBytes(); + byte[] sBytes = s.getBytes(); sBytes = encode(sBytes); s = new String(sBytes); return s; @@ -42,10 +45,12 @@ public class Base64 { /** * Decodes a base 64 String into a String. *

+ * * @param s String to decode. * @return encoded string. - * @throws java.lang.IllegalArgumentException thrown if the given byte array was not valid com.sun.syndication.io.impl.Base64 encoding. - * + * @throws java.lang.IllegalArgumentException thrown if the given byte array + * was not valid com.sun.syndication.io.impl.Base64 encoding. + * */ public static String decode(String s) throws IllegalArgumentException { s = s.replaceAll("\n", ""); @@ -56,9 +61,7 @@ public class Base64 { return s; } - - private static final byte[] ALPHASET = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".getBytes(); + private static final byte[] ALPHASET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".getBytes(); private static final int I6O2 = 255 - 3; private static final int O6I2 = 3; @@ -70,50 +73,49 @@ public class Base64 { /** * Encodes a byte array into a base 64 byte array. *

+ * * @param dData byte array to encode. * @return encoded byte array. - * + * */ - public static byte[] encode(byte[] dData) { - if (dData==null) { + public static byte[] encode(final byte[] dData) { + if (dData == null) { throw new IllegalArgumentException("Cannot encode null"); } - byte[] eData = new byte[((dData.length+2)/3)*4]; + final byte[] eData = new byte[(dData.length + 2) / 3 * 4]; int eIndex = 0; - for (int i = 0; i>2]; - e2 = ALPHASET[(d1&O6I2)<<4 | (d2&I4O4)>>4]; - e3 = ALPHASET[(d2&O4I4)<<2 | (d3&I2O6)>>6]; - e4 = ALPHASET[(d3&O2I6)]; + e1 = ALPHASET[(d1 & I6O2) >> 2]; + e2 = ALPHASET[(d1 & O6I2) << 4 | (d2 & I4O4) >> 4]; + e3 = ALPHASET[(d2 & O4I4) << 2 | (d3 & I2O6) >> 6]; + e4 = ALPHASET[d3 & O2I6]; - eData[eIndex++] = (byte)e1; - eData[eIndex++] = (byte)e2; - eData[eIndex++] = (pad<2) ?(byte)e3 : (byte)'='; - eData[eIndex++] = (pad<1) ?(byte)e4 : (byte)'='; + eData[eIndex++] = (byte) e1; + eData[eIndex++] = (byte) e2; + eData[eIndex++] = pad < 2 ? (byte) e3 : (byte) '='; + eData[eIndex++] = pad < 1 ? (byte) e4 : (byte) '='; } return eData; @@ -122,10 +124,10 @@ public class Base64 { private final static int[] CODES = new int[256]; static { - for (int i=0;i + * * @param eData byte array to decode. * @return decoded byte array. - * @throws java.lang.IllegalArgumentException thrown if the given byte array was not valid com.sun.syndication.io.impl.Base64 encoding. - * + * @throws java.lang.IllegalArgumentException thrown if the given byte array + * was not valid com.sun.syndication.io.impl.Base64 encoding. + * */ - public static byte[] decode(byte[] eData) { - if (eData==null) { + public static byte[] decode(final byte[] eData) { + if (eData == null) { throw new IllegalArgumentException("Cannot decode null"); } - byte[] cleanEData = (byte[]) eData.clone(); + final byte[] cleanEData = eData.clone(); int cleanELength = 0; - for (int i=0;i eData.length) { + if (i + 3 > eData.length) { throw new IllegalArgumentException("byte array is not a valid com.sun.syndication.io.impl.Base64 encoding"); } - int e1 = CODES[cleanEData[i]]; - int e2 = CODES[cleanEData[i+1]]; - int e3 = CODES[cleanEData[i+2]]; - int e4 = CODES[cleanEData[i+3]]; - dData[dIndex++] = (byte) ((e1<<2)|(e2>>4)); - if (dIndex>2)); + final int e1 = CODES[cleanEData[i]]; + final int e2 = CODES[cleanEData[i + 1]]; + final int e3 = CODES[cleanEData[i + 2]]; + final int e4 = CODES[cleanEData[i + 3]]; + dData[dIndex++] = (byte) (e1 << 2 | e2 >> 4); + if (dIndex < dData.length) { + dData[dIndex++] = (byte) (e2 << 4 | e3 >> 2); } - if (dIndex - * Note that the calling app could still add declarations/modules to the Feed tree after this. Which is fine. But - * those modules are then responsible for crawling to the root of the tree, at generate() time, to make sure their - * namespace declarations are present. + * Note that the calling app could still add declarations/modules to the + * Feed tree after this. Which is fine. But those modules are then + * responsible for crawling to the root of the tree, at generate() time, to + * make sure their namespace declarations are present. */ - protected static void purgeUnusedNamespaceDeclarations(Element root) { - java.util.Set usedPrefixes = new java.util.HashSet(); + protected static void purgeUnusedNamespaceDeclarations(final Element root) { + final java.util.Set usedPrefixes = new java.util.HashSet(); collectUsedPrefixes(root, usedPrefixes); - List list = root.getAdditionalNamespaces(); - List additionalNamespaces = new java.util.ArrayList(); - additionalNamespaces.addAll(list); // the duplication will prevent a ConcurrentModificationException below + final List list = root.getAdditionalNamespaces(); + final List additionalNamespaces = new java.util.ArrayList(); + additionalNamespaces.addAll(list); // the duplication will prevent a + // ConcurrentModificationException + // below for (int i = 0; i < additionalNamespaces.size(); i++) { - Namespace ns = (Namespace) additionalNamespaces.get(i); - String prefix = ns.getPrefix(); + final Namespace ns = (Namespace) additionalNamespaces.get(i); + final String prefix = ns.getPrefix(); if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) { root.removeNamespaceDeclaration(ns); } } } - private static void collectUsedPrefixes(Element el, java.util.Set collector) { - String prefix = el.getNamespacePrefix(); + private static void collectUsedPrefixes(final Element el, final java.util.Set collector) { + final String prefix = el.getNamespacePrefix(); if (prefix != null && prefix.length() > 0 && !collector.contains(prefix)) { collector.add(prefix); } - List kids = el.getChildren(); + final List kids = el.getChildren(); for (int i = 0; i < kids.size(); i++) { - collectUsedPrefixes((Element) kids.get(i), collector); // recursion - worth it + collectUsedPrefixes((Element) kids.get(i), collector); // recursion + // - worth it } } diff --git a/src/main/java/com/sun/syndication/io/impl/BaseWireFeedParser.java b/src/main/java/com/sun/syndication/io/impl/BaseWireFeedParser.java index fc90a07..9834a7f 100644 --- a/src/main/java/com/sun/syndication/io/impl/BaseWireFeedParser.java +++ b/src/main/java/com/sun/syndication/io/impl/BaseWireFeedParser.java @@ -1,115 +1,116 @@ package com.sun.syndication.io.impl; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.jdom2.Attribute; +import org.jdom2.Element; +import org.jdom2.Namespace; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.module.Extendable; import com.sun.syndication.feed.module.Module; import com.sun.syndication.io.WireFeedParser; -import java.util.ArrayList; -import java.util.Iterator; -import org.jdom2.Element; - -import java.util.List; -import org.jdom2.Namespace; -import org.jdom2.Attribute; /** * @author Alejandro Abdelnur */ public abstract class BaseWireFeedParser implements WireFeedParser { /** - * [TYPE].feed.ModuleParser.classes= [className] ... - * + * [TYPE].feed.ModuleParser.classes= [className] ... + * */ private static final String FEED_MODULE_PARSERS_POSFIX_KEY = ".feed.ModuleParser.classes"; /** * [TYPE].item.ModuleParser.classes= [className] ... - * + * */ private static final String ITEM_MODULE_PARSERS_POSFIX_KEY = ".item.ModuleParser.classes"; /** * [TYPE].person.ModuleParser.classes= [className] ... - * + * */ private static final String PERSON_MODULE_PARSERS_POSFIX_KEY = ".person.ModuleParser.classes"; + private final String _type; + private final ModuleParsers _feedModuleParsers; + private final ModuleParsers _itemModuleParsers; + private final ModuleParsers _personModuleParsers; + private final Namespace _namespace; - private String _type; - private ModuleParsers _feedModuleParsers; - private ModuleParsers _itemModuleParsers; - private ModuleParsers _personModuleParsers; - private Namespace _namespace; - - protected BaseWireFeedParser(String type, Namespace namespace) { - _type = type; - _namespace = namespace; - _feedModuleParsers = new ModuleParsers(type+FEED_MODULE_PARSERS_POSFIX_KEY, this); - _itemModuleParsers = new ModuleParsers(type+ITEM_MODULE_PARSERS_POSFIX_KEY, this); - _personModuleParsers = new ModuleParsers(type+PERSON_MODULE_PARSERS_POSFIX_KEY, this); + protected BaseWireFeedParser(final String type, final Namespace namespace) { + this._type = type; + this._namespace = namespace; + this._feedModuleParsers = new ModuleParsers(type + FEED_MODULE_PARSERS_POSFIX_KEY, this); + this._itemModuleParsers = new ModuleParsers(type + ITEM_MODULE_PARSERS_POSFIX_KEY, this); + this._personModuleParsers = new ModuleParsers(type + PERSON_MODULE_PARSERS_POSFIX_KEY, this); } /** * Returns the type of feed the parser handles. *

+ * * @see WireFeed for details on the format of this string. - *

+ *

* @return the type of feed the parser handles. - * + * */ + @Override public String getType() { - return _type; + return this._type; } - protected List parseFeedModules(Element feedElement) { - return _feedModuleParsers.parseModules(feedElement); + protected List parseFeedModules(final Element feedElement) { + return this._feedModuleParsers.parseModules(feedElement); } - protected List parseItemModules(Element itemElement) { - return _itemModuleParsers.parseModules(itemElement); + protected List parseItemModules(final Element itemElement) { + return this._itemModuleParsers.parseModules(itemElement); } - protected List parsePersonModules(Element itemElement) { - return _personModuleParsers.parseModules(itemElement); + protected List parsePersonModules(final Element itemElement) { + return this._personModuleParsers.parseModules(itemElement); } - protected List extractForeignMarkup(Element e, Extendable ext, Namespace basens) { - ArrayList foreignMarkup = new ArrayList(); - Iterator children = e.getChildren().iterator(); + protected List extractForeignMarkup(final Element e, final Extendable ext, final Namespace basens) { + final ArrayList foreignMarkup = new ArrayList(); + final Iterator children = e.getChildren().iterator(); while (children.hasNext()) { - Element elem = (Element)children.next(); - if ( - // if elemet not in the RSS namespace - !basens.equals(elem.getNamespace()) - // and elem was not handled by a module - && null == ext.getModule(elem.getNamespaceURI())) { + final Element elem = children.next(); + if ( + // if elemet not in the RSS namespace + !basens.equals(elem.getNamespace()) + // and elem was not handled by a module + && null == ext.getModule(elem.getNamespaceURI())) { - // save it as foreign markup, - // but we can't detach it while we're iterating - foreignMarkup.add(elem.clone()); + // save it as foreign markup, + // but we can't detach it while we're iterating + foreignMarkup.add(elem.clone()); } } // Now we can detach the foreign markup elements - Iterator fm = foreignMarkup.iterator(); + final Iterator fm = foreignMarkup.iterator(); while (fm.hasNext()) { - Element elem = (Element)fm.next(); + final Element elem = fm.next(); elem.detach(); } return foreignMarkup; } - protected Attribute getAttribute(Element e, String attributeName) { + protected Attribute getAttribute(final Element e, final String attributeName) { Attribute attribute = e.getAttribute(attributeName); if (attribute == null) { - attribute = e.getAttribute(attributeName, _namespace); + attribute = e.getAttribute(attributeName, this._namespace); } return attribute; } - protected String getAttributeValue(Element e, String attributeName) { - Attribute attr = getAttribute(e, attributeName); - return (attr != null) ? attr.getValue() : null; + protected String getAttributeValue(final Element e, final String attributeName) { + final Attribute attr = getAttribute(e, attributeName); + return attr != null ? attr.getValue() : null; } } - diff --git a/src/main/java/com/sun/syndication/io/impl/DCModuleGenerator.java b/src/main/java/com/sun/syndication/io/impl/DCModuleGenerator.java index 12a3edc..76874d2 100644 --- a/src/main/java/com/sun/syndication/io/impl/DCModuleGenerator.java +++ b/src/main/java/com/sun/syndication/io/impl/DCModuleGenerator.java @@ -16,54 +16,54 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.module.Module; -import com.sun.syndication.feed.module.DCModule; -import com.sun.syndication.feed.module.DCSubject; -import com.sun.syndication.io.ModuleGenerator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.jdom2.Attribute; import org.jdom2.Element; import org.jdom2.Namespace; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.HashSet; -import java.util.Collections; - +import com.sun.syndication.feed.module.DCModule; +import com.sun.syndication.feed.module.DCSubject; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.io.ModuleGenerator; /** * Feed Generator for DublinCore Module. *

- * + * * @author Elaine Chien - * + * */ public class DCModuleGenerator implements ModuleGenerator { - private static final String DC_URI = "http://purl.org/dc/elements/1.1/"; + private static final String DC_URI = "http://purl.org/dc/elements/1.1/"; private static final String TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"; private static final String RDF_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; - private static final Namespace DC_NS = Namespace.getNamespace("dc", DC_URI); + private static final Namespace DC_NS = Namespace.getNamespace("dc", DC_URI); private static final Namespace TAXO_NS = Namespace.getNamespace("taxo", TAXO_URI); private static final Namespace RDF_NS = Namespace.getNamespace("rdf", RDF_URI); private static final Set NAMESPACES; static { - Set nss = new HashSet(); + final Set nss = new HashSet(); nss.add(DC_NS); nss.add(TAXO_NS); nss.add(RDF_NS); NAMESPACES = Collections.unmodifiableSet(nss); } + @Override public final String getNamespaceUri() { return DC_URI; } - + private final Namespace getDCNamespace() { return DC_NS; } @@ -81,12 +81,13 @@ public class DCModuleGenerator implements ModuleGenerator { * generator uses. *

* It is used by the the feed generators to add their namespace definition - * in the root element of the generated document (forward-missing of - * Java 5.0 Generics). + * in the root element of the generated document (forward-missing of Java + * 5.0 Generics). *

- * + * * @return a set with all the URIs this module generator uses. */ + @Override public final Set getNamespaces() { return NAMESPACES; } @@ -94,11 +95,13 @@ public class DCModuleGenerator implements ModuleGenerator { /** * Populate an element tree with elements for a module. *

+ * * @param module the module to populate from. * @param element the root element to attach child elements to. */ - public final void generate(Module module, Element element) { - DCModule dcModule = (DCModule) module; + @Override + public final void generate(final Module module, final Element element) { + final DCModule dcModule = (DCModule) module; if (dcModule.getTitle() != null) { element.addContent(generateSimpleElementList("title", dcModule.getTitles())); @@ -106,9 +109,9 @@ public class DCModuleGenerator implements ModuleGenerator { if (dcModule.getCreator() != null) { element.addContent(generateSimpleElementList("creator", dcModule.getCreators())); } - List subjects = dcModule.getSubjects(); + final List subjects = dcModule.getSubjects(); for (int i = 0; i < subjects.size(); i++) { - element.addContent(generateSubjectElement((DCSubject) subjects.get(i))); + element.addContent(generateSubjectElement(subjects.get(i))); } if (dcModule.getDescription() != null) { element.addContent(generateSimpleElementList("description", dcModule.getDescriptions())); @@ -120,9 +123,8 @@ public class DCModuleGenerator implements ModuleGenerator { element.addContent(generateSimpleElementList("contributor", dcModule.getContributors())); } if (dcModule.getDate() != null) { - for (Iterator i = dcModule.getDates().iterator(); i.hasNext();) { - element.addContent(generateSimpleElement("date", - DateParser.formatW3CDateTime((Date) i.next()))); + for (final Date date : dcModule.getDates()) { + element.addContent(generateSimpleElement("date", DateParser.formatW3CDateTime(date))); } } if (dcModule.getType() != null) { @@ -154,21 +156,22 @@ public class DCModuleGenerator implements ModuleGenerator { /** * Utility method to generate an element for a subject. *

+ * * @param subject the subject to generate an element for. * @return the element for the subject. */ - protected final Element generateSubjectElement(DCSubject subject) { - Element subjectElement = new Element("subject", getDCNamespace()); + protected final Element generateSubjectElement(final DCSubject subject) { + final Element subjectElement = new Element("subject", getDCNamespace()); if (subject.getTaxonomyUri() != null) { - Element descriptionElement = new Element("Description", getRDFNamespace()); - Element topicElement = new Element("topic", getTaxonomyNamespace()); - Attribute resourceAttribute = new Attribute("resource", subject.getTaxonomyUri(), getRDFNamespace()); + final Element descriptionElement = new Element("Description", getRDFNamespace()); + final Element topicElement = new Element("topic", getTaxonomyNamespace()); + final Attribute resourceAttribute = new Attribute("resource", subject.getTaxonomyUri(), getRDFNamespace()); topicElement.setAttribute(resourceAttribute); descriptionElement.addContent(topicElement); if (subject.getValue() != null) { - Element valueElement = new Element("value", getRDFNamespace()); + final Element valueElement = new Element("value", getRDFNamespace()); valueElement.addContent(subject.getValue()); descriptionElement.addContent(valueElement); } @@ -179,16 +182,16 @@ public class DCModuleGenerator implements ModuleGenerator { return subjectElement; } - /** * Utility method to generate a single element containing a string. *

+ * * @param name the name of the elment to generate. * @param value the value of the text in the element. * @return the element generated. */ - protected final Element generateSimpleElement(String name, String value) { - Element element = new Element(name, getDCNamespace()); + protected final Element generateSimpleElement(final String name, final String value) { + final Element element = new Element(name, getDCNamespace()); element.addContent(value); return element; @@ -197,14 +200,15 @@ public class DCModuleGenerator implements ModuleGenerator { /** * Utility method to generate a list of simple elements. *

+ * * @param name the name of the element list to generate. * @param value the list of values for the elements. * @return a list of Elements created. */ - protected final List generateSimpleElementList(String name, List value) { - List elements = new ArrayList(); - for (Iterator i = value.iterator(); i.hasNext();) { - elements.add(generateSimpleElement(name, (String) i.next())); + protected final List generateSimpleElementList(final String name, final List value) { + final List elements = new ArrayList(); + for (final String string : value) { + elements.add(generateSimpleElement(name, string)); } return elements; diff --git a/src/main/java/com/sun/syndication/io/impl/DCModuleParser.java b/src/main/java/com/sun/syndication/io/impl/DCModuleParser.java index aecaf41..8d1997c 100644 --- a/src/main/java/com/sun/syndication/io/impl/DCModuleParser.java +++ b/src/main/java/com/sun/syndication/io/impl/DCModuleParser.java @@ -16,20 +16,20 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.module.DCModuleImpl; -import com.sun.syndication.feed.module.DCSubjectImpl; -import com.sun.syndication.feed.module.Module; -import com.sun.syndication.feed.module.DCModule; -import com.sun.syndication.feed.module.DCSubject; -import com.sun.syndication.io.ModuleParser; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import org.jdom2.Attribute; import org.jdom2.Element; import org.jdom2.Namespace; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; +import com.sun.syndication.feed.module.DCModule; +import com.sun.syndication.feed.module.DCModuleImpl; +import com.sun.syndication.feed.module.DCSubject; +import com.sun.syndication.feed.module.DCSubjectImpl; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.io.ModuleParser; /** * Parser for the Dublin Core module. @@ -43,6 +43,7 @@ public class DCModuleParser implements ModuleParser { private static final Namespace RDF_NS = Namespace.getNamespace(RDF_URI); private static final Namespace TAXO_NS = Namespace.getNamespace(TAXO_URI); + @Override public final String getNamespaceUri() { return DCModule.URI; } @@ -62,12 +63,14 @@ public class DCModuleParser implements ModuleParser { /** * Parse an element tree and return the module found in it. *

+ * * @param dcRoot the root element containing the module elements. * @return the module parsed from the element tree, null if none. */ - public Module parse(Element dcRoot) { + @Override + public Module parse(final Element dcRoot) { boolean foundSomething = false; - DCModule dcm = new DCModuleImpl(); + final DCModule dcm = new DCModuleImpl(); List eList = dcRoot.getChildren("title", getDCNamespace()); if (eList.size() > 0) { @@ -145,21 +148,22 @@ public class DCModuleParser implements ModuleParser { dcm.setRightsList(parseElementList(eList)); } - return (foundSomething) ? dcm : null; + return foundSomething ? dcm : null; } /** * Utility method to parse a taxonomy from an element. *

+ * * @param desc the taxonomy description element. * @return the string contained in the resource of the element. */ - protected final String getTaxonomy(Element desc) { + protected final String getTaxonomy(final Element desc) { String d = null; - Element taxo = desc.getChild("topic", getTaxonomyNamespace()); - if (taxo!=null) { - Attribute a = taxo.getAttribute("resource", getRDFNamespace()); - if (a!=null) { + final Element taxo = desc.getChild("topic", getTaxonomyNamespace()); + if (taxo != null) { + final Attribute a = taxo.getAttribute("resource", getRDFNamespace()); + if (a != null) { d = a.getValue(); } } @@ -169,26 +173,27 @@ public class DCModuleParser implements ModuleParser { /** * Utility method to parse a list of subjects out of a list of elements. *

+ * * @param eList the element list to parse. * @return a list of subjects parsed from the elements. */ - protected final List parseSubjects(List eList) { - List subjects = new ArrayList(); - for (Iterator i = eList.iterator(); i.hasNext();) { - Element eSubject = (Element) i.next(); - Element eDesc = eSubject.getChild("Description", getRDFNamespace()); + protected final List parseSubjects(final List eList) { + final List subjects = new ArrayList(); + for (final Element element : eList) { + final Element eSubject = element; + final Element eDesc = eSubject.getChild("Description", getRDFNamespace()); if (eDesc != null) { - String taxonomy = getTaxonomy(eDesc); - List eValues = eDesc.getChildren("value", getRDFNamespace()); - for (Iterator v = eValues.iterator(); v.hasNext();) { - Element eValue = (Element) v.next(); - DCSubject subject = new DCSubjectImpl(); + final String taxonomy = getTaxonomy(eDesc); + final List eValues = eDesc.getChildren("value", getRDFNamespace()); + for (final Element element2 : eValues) { + final Element eValue = element2; + final DCSubject subject = new DCSubjectImpl(); subject.setTaxonomyUri(taxonomy); subject.setValue(eValue.getText()); subjects.add(subject); } } else { - DCSubject subject = new DCSubjectImpl(); + final DCSubject subject = new DCSubjectImpl(); subject.setValue(eSubject.getText()); subjects.add(subject); } @@ -200,13 +205,14 @@ public class DCModuleParser implements ModuleParser { /** * Utility method to parse a list of strings out of a list of elements. *

+ * * @param eList the list of elements to parse. * @return the list of strings */ - protected final List parseElementList(List eList) { - List values= new ArrayList(); - for (Iterator i = eList.iterator(); i.hasNext();) { - Element e = (Element) i.next(); + protected final List parseElementList(final List eList) { + final List values = new ArrayList(); + for (final Element element : eList) { + final Element e = element; values.add(e.getText()); } @@ -216,13 +222,14 @@ public class DCModuleParser implements ModuleParser { /** * Utility method to parse a list of dates out of a list of elements. *

+ * * @param eList the list of elements to parse. * @return the list of dates. */ - protected final List parseElementListDate(List eList) { - List values = new ArrayList(); - for (Iterator i = eList.iterator(); i.hasNext();) { - Element e = (Element) i.next(); + protected final List parseElementListDate(final List eList) { + final List values = new ArrayList(); + for (final Element element : eList) { + final Element e = element; values.add(DateParser.parseDate(e.getText())); } diff --git a/src/main/java/com/sun/syndication/io/impl/DateParser.java b/src/main/java/com/sun/syndication/io/impl/DateParser.java index a55e5e7..0252a75 100644 --- a/src/main/java/com/sun/syndication/io/impl/DateParser.java +++ b/src/main/java/com/sun/syndication/io/impl/DateParser.java @@ -17,96 +17,73 @@ package com.sun.syndication.io.impl; import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.text.ParsePosition; +import java.text.SimpleDateFormat; import java.util.Date; -import java.util.TimeZone; import java.util.Locale; +import java.util.TimeZone; /** - * A helper class that parses Dates out of Strings with date time in RFC822 and W3CDateTime - * formats plus the variants Atom (0.3) and RSS (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) - * specificators added to those formats. + * A helper class that parses Dates out of Strings with date time in RFC822 and + * W3CDateTime formats plus the variants Atom (0.3) and RSS (0.9, 0.91, 0.92, + * 0.93, 0.94, 1.0 and 2.0) specificators added to those formats. *

- * It uses the JDK java.text.SimpleDateFormat class attemtping the parse using a mask for - * each one of the possible formats. + * It uses the JDK java.text.SimpleDateFormat class attemtping the parse using a + * mask for each one of the possible formats. *

- * + * * @author Alejandro Abdelnur - * + * */ public class DateParser { private static String[] ADDITIONAL_MASKS; static { - ADDITIONAL_MASKS = PropertiesLoader.getPropertiesLoader().getTokenizedProperty("datetime.extra.masks","|"); + ADDITIONAL_MASKS = PropertiesLoader.getPropertiesLoader().getTokenizedProperty("datetime.extra.masks", "|"); } - // order is like this because the SimpleDateFormat.parse does not fail with exception - // if it can parse a valid date out of a substring of the full string given the mask - // so we have to check the most complete format first, then it fails with exception - private static final String[] RFC822_MASKS = { - "EEE, dd MMM yy HH:mm:ss z", - "EEE, dd MMM yy HH:mm z", - "dd MMM yy HH:mm:ss z", - "dd MMM yy HH:mm z" - }; + // order is like this because the SimpleDateFormat.parse does not fail with + // exception + // if it can parse a valid date out of a substring of the full string given + // the mask + // so we have to check the most complete format first, then it fails with + // exception + private static final String[] RFC822_MASKS = { "EEE, dd MMM yy HH:mm:ss z", "EEE, dd MMM yy HH:mm z", "dd MMM yy HH:mm:ss z", "dd MMM yy HH:mm z" }; + // order is like this because the SimpleDateFormat.parse does not fail with + // exception + // if it can parse a valid date out of a substring of the full string given + // the mask + // so we have to check the most complete format first, then it fails with + // exception + private static final String[] W3CDATETIME_MASKS = { "yyyy-MM-dd'T'HH:mm:ss.SSSz", "yyyy-MM-dd't'HH:mm:ss.SSSz", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", + "yyyy-MM-dd't'HH:mm:ss.SSS'z'", "yyyy-MM-dd'T'HH:mm:ssz", "yyyy-MM-dd't'HH:mm:ssz", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd't'HH:mm:ssZ", + "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd't'HH:mm:ss'z'", "yyyy-MM-dd'T'HH:mmz", // together + // with + // logic + // in + // the + // parseW3CDateTime + // they + "yyyy-MM'T'HH:mmz", // handle W3C dates without time forcing them to + // be GMT + "yyyy'T'HH:mmz", "yyyy-MM-dd't'HH:mmz", "yyyy-MM-dd'T'HH:mm'Z'", "yyyy-MM-dd't'HH:mm'z'", "yyyy-MM-dd", "yyyy-MM", "yyyy" }; - - // order is like this because the SimpleDateFormat.parse does not fail with exception - // if it can parse a valid date out of a substring of the full string given the mask - // so we have to check the most complete format first, then it fails with exception - private static final String[] W3CDATETIME_MASKS = { - "yyyy-MM-dd'T'HH:mm:ss.SSSz", - "yyyy-MM-dd't'HH:mm:ss.SSSz", - "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", - "yyyy-MM-dd't'HH:mm:ss.SSS'z'", - "yyyy-MM-dd'T'HH:mm:ssz", - "yyyy-MM-dd't'HH:mm:ssz", - "yyyy-MM-dd'T'HH:mm:ssZ", - "yyyy-MM-dd't'HH:mm:ssZ", - "yyyy-MM-dd'T'HH:mm:ss'Z'", - "yyyy-MM-dd't'HH:mm:ss'z'", - "yyyy-MM-dd'T'HH:mmz", // together with logic in the parseW3CDateTime they - "yyyy-MM'T'HH:mmz", // handle W3C dates without time forcing them to be GMT - "yyyy'T'HH:mmz", - "yyyy-MM-dd't'HH:mmz", - "yyyy-MM-dd'T'HH:mm'Z'", - "yyyy-MM-dd't'HH:mm'z'", - "yyyy-MM-dd", - "yyyy-MM", - "yyyy" - }; - - - - /** - * The masks used to validate and parse the input to this Atom date. - * These are a lot more forgiving than what the Atom spec allows. - * The forms that are invalid according to the spec are indicated. - */ - private static final String[] masks = { - "yyyy-MM-dd'T'HH:mm:ss.SSSz", - "yyyy-MM-dd't'HH:mm:ss.SSSz", // invalid - "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", - "yyyy-MM-dd't'HH:mm:ss.SSS'z'", // invalid - "yyyy-MM-dd'T'HH:mm:ssz", - "yyyy-MM-dd't'HH:mm:ssz", // invalid - "yyyy-MM-dd'T'HH:mm:ss'Z'", - "yyyy-MM-dd't'HH:mm:ss'z'", // invalid - "yyyy-MM-dd'T'HH:mmz", // invalid - "yyyy-MM-dd't'HH:mmz", // invalid - "yyyy-MM-dd'T'HH:mm'Z'", // invalid - "yyyy-MM-dd't'HH:mm'z'", // invalid - "yyyy-MM-dd", - "yyyy-MM", - "yyyy" - }; - - - + /** + * The masks used to validate and parse the input to this Atom date. These + * are a lot more forgiving than what the Atom spec allows. The forms that + * are invalid according to the spec are indicated. + */ + private static final String[] masks = { "yyyy-MM-dd'T'HH:mm:ss.SSSz", "yyyy-MM-dd't'HH:mm:ss.SSSz", // invalid + "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd't'HH:mm:ss.SSS'z'", // invalid + "yyyy-MM-dd'T'HH:mm:ssz", "yyyy-MM-dd't'HH:mm:ssz", // invalid + "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd't'HH:mm:ss'z'", // invalid + "yyyy-MM-dd'T'HH:mmz", // invalid + "yyyy-MM-dd't'HH:mmz", // invalid + "yyyy-MM-dd'T'HH:mm'Z'", // invalid + "yyyy-MM-dd't'HH:mm'z'", // invalid + "yyyy-MM-dd", "yyyy-MM", "yyyy" }; /** * Private constructor to avoid DateParser instances creation. @@ -119,31 +96,31 @@ public class DateParser { *

* It uses the masks in order until one of them succedes or all fail. *

- * + * * @param masks array of masks to use for parsing the string * @param sDate string to parse for a date. - * @return the Date represented by the given string using one of the given masks. - * It returns null if it was not possible to parse the the string with any of the masks. - * + * @return the Date represented by the given string using one of the given + * masks. It returns null if it was not possible to parse the + * the string with any of the masks. + * */ - private static Date parseUsingMask(String[] masks,String sDate) { - sDate = (sDate!=null) ? sDate.trim() : null; + private static Date parseUsingMask(final String[] masks, String sDate) { + sDate = sDate != null ? sDate.trim() : null; ParsePosition pp = null; Date d = null; - for (int i=0;d==null && i * It parsers the following formats: *

*

- * Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element. + * Refer to the java.text.SimpleDateFormat javadocs for details on the + * format of each element. *

+ * * @param sDate string to parse for a date. - * @return the Date represented by the given RFC822 string. - * It returns null if it was not possible to parse the given string into a Date. - * + * @return the Date represented by the given RFC822 string. It returns + * null if it was not possible to parse the given string into + * a Date. + * */ public static Date parseRFC822(String sDate) { - int utIndex = sDate.indexOf(" UT"); - if (utIndex>-1) { - String pre = sDate.substring(0,utIndex); - String post = sDate.substring(utIndex+3); + final int utIndex = sDate.indexOf(" UT"); + if (utIndex > -1) { + final String pre = sDate.substring(0, utIndex); + final String post = sDate.substring(utIndex + 3); sDate = pre + " GMT" + post; } - return parseUsingMask(RFC822_MASKS,sDate); + return parseUsingMask(RFC822_MASKS, sDate); } - /** * Parses a Date out of a String with a date in W3C date-time format. *

* It parsers the following formats: *

*

- * Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element. + * Refer to the java.text.SimpleDateFormat javadocs for details on the + * format of each element. *

+ * * @param sDate string to parse for a date. - * @return the Date represented by the given W3C date-time string. - * It returns null if it was not possible to parse the given string into a Date. - * + * @return the Date represented by the given W3C date-time string. It + * returns null if it was not possible to parse the given + * string into a Date. + * */ public static Date parseW3CDateTime(String sDate) { - // if sDate has time on it, it injects 'GTM' before de TZ displacement to + // if sDate has time on it, it injects 'GTM' before de TZ displacement + // to // allow the SimpleDateFormat parser to parse it properly - int tIndex = sDate.indexOf("T"); - if (tIndex>-1) { + final int tIndex = sDate.indexOf("T"); + if (tIndex > -1) { if (sDate.endsWith("Z")) { - sDate = sDate.substring(0,sDate.length()-1)+"+00:00"; + sDate = sDate.substring(0, sDate.length() - 1) + "+00:00"; } - int tzdIndex = sDate.indexOf("+",tIndex); - if (tzdIndex==-1) { - tzdIndex = sDate.indexOf("-",tIndex); + int tzdIndex = sDate.indexOf("+", tIndex); + if (tzdIndex == -1) { + tzdIndex = sDate.indexOf("-", tIndex); } - if (tzdIndex>-1) { - String pre = sDate.substring(0,tzdIndex); - int secFraction = pre.indexOf(","); - if (secFraction>-1) { - pre = pre.substring(0,secFraction); + if (tzdIndex > -1) { + String pre = sDate.substring(0, tzdIndex); + final int secFraction = pre.indexOf(","); + if (secFraction > -1) { + pre = pre.substring(0, secFraction); } - String post = sDate.substring(tzdIndex); + final String post = sDate.substring(tzdIndex); sDate = pre + "GMT" + post; } - } - else { + } else { sDate += "T00:00GMT"; } - return parseUsingMask(W3CDATETIME_MASKS,sDate); + return parseUsingMask(W3CDATETIME_MASKS, sDate); } - /** - * Parses a Date out of a String with a date in W3C date-time format or - * in a RFC822 format. + * Parses a Date out of a String with a date in W3C date-time format or in a + * RFC822 format. *

+ * * @param sDate string to parse for a date. - * @return the Date represented by the given W3C date-time string. - * It returns null if it was not possible to parse the given string into a Date. - * + * @return the Date represented by the given W3C date-time string. It + * returns null if it was not possible to parse the given + * string into a Date. + * * */ - public static Date parseDate(String sDate) { + public static Date parseDate(final String sDate) { Date d = parseW3CDateTime(sDate); - if (d==null) { + if (d == null) { d = parseRFC822(sDate); - if (d==null && ADDITIONAL_MASKS.length>0) { - d = parseUsingMask(ADDITIONAL_MASKS,sDate); + if (d == null && ADDITIONAL_MASKS.length > 0) { + d = parseUsingMask(ADDITIONAL_MASKS, sDate); } } return d; @@ -253,15 +236,17 @@ public class DateParser { /** * create a RFC822 representation of a date. *

- * Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element. + * Refer to the java.text.SimpleDateFormat javadocs for details on the + * format of each element. *

+ * * @param date Date to parse - * @return the RFC822 represented by the given Date - * It returns null if it was not possible to parse the date. - * + * @return the RFC822 represented by the given Date It returns null + * if it was not possible to parse the date. + * */ - public static String formatRFC822(Date date) { - SimpleDateFormat dateFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'",Locale.US); + public static String formatRFC822(final Date date) { + final SimpleDateFormat dateFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); dateFormater.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormater.format(date); } @@ -269,15 +254,17 @@ public class DateParser { /** * create a W3C Date Time representation of a date. *

- * Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element. + * Refer to the java.text.SimpleDateFormat javadocs for details on the + * format of each element. *

+ * * @param date Date to parse - * @return the W3C Date Time represented by the given Date - * It returns null if it was not possible to parse the date. - * + * @return the W3C Date Time represented by the given Date It returns + * null if it was not possible to parse the date. + * */ - public static String formatW3CDateTime(Date date) { - SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'",Locale.US); + public static String formatW3CDateTime(final Date date) { + final SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); dateFormater.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormater.format(date); } diff --git a/src/main/java/com/sun/syndication/io/impl/FeedGenerators.java b/src/main/java/com/sun/syndication/io/impl/FeedGenerators.java index f6e1a71..6d76bed 100644 --- a/src/main/java/com/sun/syndication/io/impl/FeedGenerators.java +++ b/src/main/java/com/sun/syndication/io/impl/FeedGenerators.java @@ -16,43 +16,45 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.io.WireFeedGenerator; - import java.util.List; +import com.sun.syndication.io.WireFeedGenerator; + /** * Generates an XML document (JDOM Document) out of a Feed. *

- * It can generate all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and - * Atom 0.3 feed. + * It can generate all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and + * 2.0) and Atom 0.3 feed. *

* WireFeedGenerator instances are thread safe. *

- * Generators for a specific type must extend this class and register in the generator list. - * (Right now registration is hardcoded in the WireFeedGenerator constructor). + * Generators for a specific type must extend this class and register in the + * generator list. (Right now registration is hardcoded in the WireFeedGenerator + * constructor). *

+ * * @author Alejandro Abdelnur - * + * */ public class FeedGenerators extends PluginManager { /** - * WireFeedGenerator.classes= [className] ... - * + * WireFeedGenerator.classes= [className] ... + * */ public static final String FEED_GENERATORS_KEY = "WireFeedGenerator.classes"; - public FeedGenerators() { super(FEED_GENERATORS_KEY); } - public WireFeedGenerator getGenerator(String feedType) { + public WireFeedGenerator getGenerator(final String feedType) { return (WireFeedGenerator) getPlugin(feedType); } - protected String getKey(Object obj) { - return ((WireFeedGenerator)obj).getType(); + @Override + protected String getKey(final Object obj) { + return ((WireFeedGenerator) obj).getType(); } public List getSupportedFeedTypes() { diff --git a/src/main/java/com/sun/syndication/io/impl/FeedParsers.java b/src/main/java/com/sun/syndication/io/impl/FeedParsers.java index 2aaa1fe..a4a48ae 100644 --- a/src/main/java/com/sun/syndication/io/impl/FeedParsers.java +++ b/src/main/java/com/sun/syndication/io/impl/FeedParsers.java @@ -16,10 +16,12 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.io.WireFeedParser; -import org.jdom2.Document; import java.util.List; +import org.jdom2.Document; + +import com.sun.syndication.io.WireFeedParser; + /** * Parses an XML document (JDOM Document) into a Feed. *

@@ -30,24 +32,26 @@ import java.util.List; *

* WireFeedParser instances are thread safe. *

- * Parsers for a specific type must extend this class and register in the parser list. - * (Right now registration is hardcoded in the WireFeedParser constructor). + * Parsers for a specific type must extend this class and register in the parser + * list. (Right now registration is hardcoded in the WireFeedParser + * constructor). *

+ * * @author Alejandro Abdelnur - * + * */ public class FeedParsers extends PluginManager { /** - * WireFeedParser.classes= [className] ... - * + * WireFeedParser.classes= [className] ... + * */ public static final String FEED_PARSERS_KEY = "WireFeedParser.classes"; /** * Creates a parser instance. *

- * + * */ public FeedParsers() { super(FEED_PARSERS_KEY); @@ -60,14 +64,16 @@ public class FeedParsers extends PluginManager { /** * Finds the real parser type for the given document feed. *

+ * * @param document document feed to find the parser for. - * @return the parser for the given document or null if there is no parser for that document. - * + * @return the parser for the given document or null if there is no + * parser for that document. + * */ - public WireFeedParser getParserFor(Document document) { - List parsers = getPlugins(); + public WireFeedParser getParserFor(final Document document) { + final List parsers = getPlugins(); WireFeedParser parser = null; - for (int i=0;parser==null && i parseModules(Element root) { - List parsers = getPlugins(); + public List parseModules(final Element root) { + final List parsers = getPlugins(); List modules = null; - for (int i=0;i(); @@ -60,14 +62,14 @@ public class ModuleParsers extends PluginManager { return modules; } - private boolean hasElementsFrom(Element root, Namespace namespace) { + private boolean hasElementsFrom(final Element root, final Namespace namespace) { boolean hasElements = false; -// boolean hasElements = namespace.equals(root.getNamespace()); + // boolean hasElements = namespace.equals(root.getNamespace()); if (!hasElements) { - List children = root.getChildren(); - for (int i=0;!hasElements && i < children.size();i++) { - Element child = (Element) children.get(i); + final List children = root.getChildren(); + for (int i = 0; !hasElements && i < children.size(); i++) { + final Element child = children.get(i); hasElements = namespace.equals(child.getNamespace()); } } diff --git a/src/main/java/com/sun/syndication/io/impl/NumberParser.java b/src/main/java/com/sun/syndication/io/impl/NumberParser.java index 6076b7b..ec955a1 100644 --- a/src/main/java/com/sun/syndication/io/impl/NumberParser.java +++ b/src/main/java/com/sun/syndication/io/impl/NumberParser.java @@ -1,15 +1,12 @@ - package com.sun.syndication.io.impl; - /** * A helper class that parses Numbers out of Strings in a lenient manner. - * + * *

- * No method will throw any sort of Exception when parsing a string. - * All methods accept any Java String or null as legal input, if the - * input is non null, whitespace will be trimmed first, and then parsing - * will be attempted. + * No method will throw any sort of Exception when parsing a string. All methods + * accept any Java String or null as legal input, if the input is non null, + * whitespace will be trimmed first, and then parsing will be attempted. *

*

* :TODO: Add Integer, Float, and Double methods as needed. @@ -25,57 +22,60 @@ public class NumberParser { /** * Parses a Long out of a string. - * + * * @param str string to parse for a Long. - * @return the Long represented by the given string, - * It returns null if it was not possible to parse the the string. + * @return the Long represented by the given string, It returns null + * if it was not possible to parse the the string. */ - public static Long parseLong(String str) { + public static Long parseLong(final String str) { if (null != str) { try { return new Long(Long.parseLong(str.trim())); - } catch (Exception e) { + } catch (final Exception e) { // :IGNORE: } } return null; } - + /** - * Parse an Integer from a String. If the String is not an integer null is returned - * and no exception is thrown. + * Parse an Integer from a String. If the String is not an integer + * null is returned and no exception is thrown. * * @param str the String to parse - * @return The Integer represented by the String, or null if it could not be parsed. + * @return The Integer represented by the String, or null if it could not be + * parsed. */ - public static Integer parseInt(String str) { + public static Integer parseInt(final String str) { if (null != str) { try { return new Integer(Integer.parseInt(str.trim())); - } catch (Exception e) { + } catch (final Exception e) { // :IGNORE: } } - return null; + return null; } /** - * Parse a Float from a String without exceptions. If the String is not a Float then null is returned + * Parse a Float from a String without exceptions. If the String is not a + * Float then null is returned * * @param str the String to parse - * @return The Float represented by the String, or null if it could not be parsed. + * @return The Float represented by the String, or null if it could not be + * parsed. */ - public static Float parseFloat(String str) { + public static Float parseFloat(final String str) { if (null != str) { try { return new Float(Float.parseFloat(str.trim())); - } catch (Exception e) { + } catch (final Exception e) { // :IGNORE: } } - return null; + return null; } - + /** * Parse a float from a String, with a default value * @@ -83,22 +83,22 @@ public class NumberParser { * @param def the value to return if the String cannot be parsed * @return */ - public static float parseFloat(String str, float def) { - Float result = parseFloat(str); - return (result == null) ? def : result.floatValue(); + public static float parseFloat(final String str, final float def) { + final Float result = parseFloat(str); + return result == null ? def : result.floatValue(); } - + /** * Parses a long out of a string. - * + * * @param str string to parse for a long. - * @param def default value to return if it is not possible to parse the the string. + * @param def default value to return if it is not possible to parse the the + * string. * @return the long represented by the given string, or the default. */ - public static long parseLong(String str, long def) { - Long ret = parseLong(str); - return (null == ret) ? def : ret.longValue(); + public static long parseLong(final String str, final long def) { + final Long ret = parseLong(str); + return null == ret ? def : ret.longValue(); } - } diff --git a/src/main/java/com/sun/syndication/io/impl/PluginManager.java b/src/main/java/com/sun/syndication/io/impl/PluginManager.java index f10e5cc..8fdbcf1 100644 --- a/src/main/java/com/sun/syndication/io/impl/PluginManager.java +++ b/src/main/java/com/sun/syndication/io/impl/PluginManager.java @@ -16,127 +16,139 @@ */ package com.sun.syndication.io.impl; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import com.sun.syndication.io.DelegatingModuleGenerator; import com.sun.syndication.io.DelegatingModuleParser; import com.sun.syndication.io.WireFeedGenerator; import com.sun.syndication.io.WireFeedParser; -import java.util.*; - /** *

+ * * @author Alejandro Abdelnur - * + * */ public abstract class PluginManager { - private String[] _propertyValues; + private final String[] _propertyValues; private Map _pluginsMap; private List _pluginsList; - private List _keys; - private WireFeedParser _parentParser; - private WireFeedGenerator _parentGenerator; + private final List _keys; + private final WireFeedParser _parentParser; + private final WireFeedGenerator _parentGenerator; /** * Creates a PluginManager *

+ * * @param propertyKey property key defining the plugins classes - * + * */ - protected PluginManager(String propertyKey) { + protected PluginManager(final String propertyKey) { this(propertyKey, null, null); } - protected PluginManager(String propertyKey, WireFeedParser parentParser, - WireFeedGenerator parentGenerator) - { - _parentParser = parentParser; - _parentGenerator = parentGenerator; - _propertyValues = PropertiesLoader.getPropertiesLoader().getTokenizedProperty(propertyKey,", "); + protected PluginManager(final String propertyKey, final WireFeedParser parentParser, final WireFeedGenerator parentGenerator) { + this._parentParser = parentParser; + this._parentGenerator = parentGenerator; + this._propertyValues = PropertiesLoader.getPropertiesLoader().getTokenizedProperty(propertyKey, ", "); loadPlugins(); - _pluginsMap = Collections.unmodifiableMap(_pluginsMap); - _pluginsList = Collections.unmodifiableList(_pluginsList); - _keys = Collections.unmodifiableList(new ArrayList(_pluginsMap.keySet())); + this._pluginsMap = Collections.unmodifiableMap(this._pluginsMap); + this._pluginsList = Collections.unmodifiableList(this._pluginsList); + this._keys = Collections.unmodifiableList(new ArrayList(this._pluginsMap.keySet())); } protected abstract String getKey(Object obj); protected List getKeys() { - return _keys; + return this._keys; } protected List getPlugins() { - return _pluginsList; + return this._pluginsList; } protected Map getPluginMap() { - return _pluginsMap; + return this._pluginsMap; } - protected Object getPlugin(String key) { - return _pluginsMap.get(key); + protected Object getPlugin(final String key) { + return this._pluginsMap.get(key); } // PRIVATE - LOADER PART private void loadPlugins() { - List finalPluginsList = new ArrayList(); - _pluginsList = new ArrayList(); - _pluginsMap = new HashMap(); + final List finalPluginsList = new ArrayList(); + this._pluginsList = new ArrayList(); + this._pluginsMap = new HashMap(); String className = null; try { - Class[] classes = getClasses(); - for (int i=0;i + * * @return array containing the classes defined in the properties files. - * @throws java.lang.ClassNotFoundException thrown if one of the classes defined in the properties file cannot be loaded - * and hard failure is ON. - * + * @throws java.lang.ClassNotFoundException thrown if one of the classes + * defined in the properties file cannot be loaded and hard + * failure is ON. + * */ private Class[] getClasses() throws ClassNotFoundException { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - List classes = new ArrayList(); - boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue(); - for (int i = 0; i <_propertyValues.length; i++) { - Class mClass = (useLoadClass ? classLoader.loadClass(_propertyValues[i]) : Class.forName(_propertyValues[i], true, classLoader)); + final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + final List classes = new ArrayList(); + final boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue(); + for (final String _propertyValue : this._propertyValues) { + final Class mClass = useLoadClass ? classLoader.loadClass(_propertyValue) : Class.forName(_propertyValue, true, classLoader); classes.add(mClass); } - Class[] array = new Class[classes.size()]; + final Class[] array = new Class[classes.size()]; classes.toArray(array); return array; } diff --git a/src/main/java/com/sun/syndication/io/impl/PropertiesLoader.java b/src/main/java/com/sun/syndication/io/impl/PropertiesLoader.java index 7c7c6b3..9493f56 100644 --- a/src/main/java/com/sun/syndication/io/impl/PropertiesLoader.java +++ b/src/main/java/com/sun/syndication/io/impl/PropertiesLoader.java @@ -3,50 +3,52 @@ package com.sun.syndication.io.impl; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.util.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.WeakHashMap; /** - * Properties loader that aggregates a master properties file and several extra properties files, - * all from the current classpath. + * Properties loader that aggregates a master properties file and several extra + * properties files, all from the current classpath. *

- * The master properties file has to be in a distinct location than the extra properties files. - * First the master properties file is loaded, then all the extra properties files in their order - * of appearance in the classpath. + * The master properties file has to be in a distinct location than the extra + * properties files. First the master properties file is loaded, then all the + * extra properties files in their order of appearance in the classpath. *

- * Current use cases (plugin manager for parsers/converters/generators for feeds and modules - * and date formats) assume properties are list of tokens, that why the only method to get - * property values is the getTokenizedProperty(). + * Current use cases (plugin manager for parsers/converters/generators for feeds + * and modules and date formats) assume properties are list of tokens, that why + * the only method to get property values is the getTokenizedProperty(). *

- * + * * @author Alejandro Abdelnur - * + * */ public class PropertiesLoader { private static final String MASTER_PLUGIN_FILE = "com/sun/syndication/rome.properties"; private static final String EXTRA_PLUGIN_FILE = "rome.properties"; - - private static Map clMap = - new WeakHashMap(); - + private static Map clMap = new WeakHashMap(); /** - * Returns the PropertiesLoader singleton used by ROME to load plugin components. - * + * Returns the PropertiesLoader singleton used by ROME to load plugin + * components. + * * @return PropertiesLoader singleton. - * + * */ public static PropertiesLoader getPropertiesLoader() { - synchronized(PropertiesLoader.class) { - PropertiesLoader loader = (PropertiesLoader) - clMap.get(Thread.currentThread().getContextClassLoader()); + synchronized (PropertiesLoader.class) { + PropertiesLoader loader = clMap.get(Thread.currentThread().getContextClassLoader()); if (loader == null) { try { loader = new PropertiesLoader(MASTER_PLUGIN_FILE, EXTRA_PLUGIN_FILE); clMap.put(Thread.currentThread().getContextClassLoader(), loader); - } - catch (IOException ex) { + } catch (final IOException ex) { throw new RuntimeException(ex); } } @@ -54,100 +56,104 @@ public class PropertiesLoader { } } - private Properties[] _properties; + private final Properties[] _properties; /** * Creates a PropertiesLoader. *

+ * * @param masterFileLocation master file location, there must be only one. * @param extraFileLocation extra file location, there may be many. - * @throws IOException thrown if one of the properties file could not be read. - * + * @throws IOException thrown if one of the properties file could not be + * read. + * */ - private PropertiesLoader(String masterFileLocation,String extraFileLocation) throws IOException { - List propertiesList = new ArrayList(); - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + private PropertiesLoader(final String masterFileLocation, final String extraFileLocation) throws IOException { + final List propertiesList = new ArrayList(); + final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { - InputStream is = classLoader.getResourceAsStream(masterFileLocation); - Properties p = new Properties(); + final InputStream is = classLoader.getResourceAsStream(masterFileLocation); + final Properties p = new Properties(); p.load(is); is.close(); propertiesList.add(p); - } - catch (IOException ioex) { - IOException ex = new IOException("could not load ROME master plugins file ["+masterFileLocation+"], "+ - ioex.getMessage()); + } catch (final IOException ioex) { + final IOException ex = new IOException("could not load ROME master plugins file [" + masterFileLocation + "], " + ioex.getMessage()); ex.setStackTrace(ioex.getStackTrace()); throw ex; } - Enumeration urls = classLoader.getResources(extraFileLocation); + final Enumeration urls = classLoader.getResources(extraFileLocation); while (urls.hasMoreElements()) { - URL url = (URL) urls.nextElement(); - Properties p = new Properties(); + final URL url = urls.nextElement(); + final Properties p = new Properties(); try { - InputStream is = url.openStream(); + final InputStream is = url.openStream(); p.load(is); is.close(); - } - catch (IOException ioex) { - IOException ex = new IOException("could not load ROME extensions plugins file ["+url.toString()+"], "+ - ioex.getMessage()); + } catch (final IOException ioex) { + final IOException ex = new IOException("could not load ROME extensions plugins file [" + url.toString() + "], " + ioex.getMessage()); ex.setStackTrace(ioex.getStackTrace()); throw ex; } propertiesList.add(p); } - _properties = new Properties[propertiesList.size()]; - propertiesList.toArray(_properties); + this._properties = new Properties[propertiesList.size()]; + propertiesList.toArray(this._properties); } /** - * Returns an array of tokenized values stored under a property key in all properties files. - * If the master file has this property its tokens will be the first ones in the array. + * Returns an array of tokenized values stored under a property key in all + * properties files. If the master file has this property its tokens will be + * the first ones in the array. *

+ * * @param key property key to retrieve values - * @param separator String with all separator characters to tokenize from the values in all - * properties files. - * @return all the tokens for the given property key from all the properties files. - * + * @param separator String with all separator characters to tokenize from + * the values in all properties files. + * @return all the tokens for the given property key from all the properties + * files. + * */ - public String[] getTokenizedProperty(String key,String separator) { - List entriesList = new ArrayList(); - for (int i=0;i<_properties.length;i++) { - String values = _properties[i].getProperty(key); - if (values!=null) { - StringTokenizer st = new StringTokenizer(values,separator); + public String[] getTokenizedProperty(final String key, final String separator) { + final List entriesList = new ArrayList(); + for (final Properties _propertie : this._properties) { + final String values = _propertie.getProperty(key); + if (values != null) { + final StringTokenizer st = new StringTokenizer(values, separator); while (st.hasMoreTokens()) { - String token = st.nextToken(); + final String token = st.nextToken(); entriesList.add(token); } } } - String[] entries = new String[entriesList.size()]; + final String[] entries = new String[entriesList.size()]; entriesList.toArray(entries); return entries; } /** - * Returns an array of values stored under a property key in all properties files. - * If the master file has this property it will be the first ones in the array. + * Returns an array of values stored under a property key in all properties + * files. If the master file has this property it will be the first ones in + * the array. *

+ * * @param key property key to retrieve values - * @return all the values for the given property key from all the properties files. - * + * @return all the values for the given property key from all the properties + * files. + * */ - public String[] getProperty(String key) { - List entriesList = new ArrayList(); - for (int i=0;i<_properties.length;i++) { - String values = _properties[i].getProperty(key); - if (values!=null) { + public String[] getProperty(final String key) { + final List entriesList = new ArrayList(); + for (final Properties _propertie : this._properties) { + final String values = _propertie.getProperty(key); + if (values != null) { entriesList.add(values); } } - String[] entries = new String[entriesList.size()]; + final String[] entries = new String[entriesList.size()]; entriesList.toArray(entries); return entries; } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS090Generator.java b/src/main/java/com/sun/syndication/io/impl/RSS090Generator.java index 848c5bd..ce49ad1 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS090Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS090Generator.java @@ -16,20 +16,23 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.WireFeed; -import com.sun.syndication.feed.rss.*; -import com.sun.syndication.io.FeedException; +import java.util.List; + import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.Namespace; -import java.util.List; - +import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.rss.Channel; +import com.sun.syndication.feed.rss.Image; +import com.sun.syndication.feed.rss.Item; +import com.sun.syndication.feed.rss.TextInput; +import com.sun.syndication.io.FeedException; /** * Feed Generator for RSS 0.90 *

- * + * * @author Elaine Chien */ public class RSS090Generator extends BaseWireFeedGenerator { @@ -46,14 +49,15 @@ public class RSS090Generator extends BaseWireFeedGenerator { this("rss_0.9"); } - protected RSS090Generator(String type) { + protected RSS090Generator(final String type) { super(type); } - public Document generate(WireFeed feed) throws FeedException { - Channel channel = (Channel)feed; - Element root = createRootElement(channel); - populateFeed(channel,root); + @Override + public Document generate(final WireFeed feed) throws FeedException { + final Channel channel = (Channel) feed; + final Element root = createRootElement(channel); + populateFeed(channel, root); purgeUnusedNamespaceDeclarations(root); return createDocument(root); } @@ -70,12 +74,12 @@ public class RSS090Generator extends BaseWireFeedGenerator { return CONTENT_NS; } - protected Document createDocument(Element root) { + protected Document createDocument(final Element root) { return new Document(root); } - protected Element createRootElement(Channel channel) { - Element root = new Element("RDF",getRDFNamespace()); + protected Element createRootElement(final Channel channel) { + final Element root = new Element("RDF", getRDFNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); root.addNamespaceDeclaration(getRDFNamespace()); root.addNamespaceDeclaration(getContentNamespace()); @@ -83,89 +87,88 @@ public class RSS090Generator extends BaseWireFeedGenerator { return root; } - protected void populateFeed(Channel channel, Element parent) throws FeedException { - addChannel(channel,parent); - addImage(channel,parent); - addTextInput(channel,parent); - addItems(channel,parent); - generateForeignMarkup(parent, (List)channel.getForeignMarkup()); + protected void populateFeed(final Channel channel, final Element parent) throws FeedException { + addChannel(channel, parent); + addImage(channel, parent); + addTextInput(channel, parent); + addItems(channel, parent); + generateForeignMarkup(parent, channel.getForeignMarkup()); } - protected void addChannel(Channel channel,Element parent) throws FeedException { - Element eChannel = new Element("channel", getFeedNamespace()); - populateChannel(channel,eChannel); + protected void addChannel(final Channel channel, final Element parent) throws FeedException { + final Element eChannel = new Element("channel", getFeedNamespace()); + populateChannel(channel, eChannel); checkChannelConstraints(eChannel); parent.addContent(eChannel); - generateFeedModules(channel.getModules(),eChannel); + generateFeedModules(channel.getModules(), eChannel); } /** - * Populates the given channel with parsed data from the ROME element that holds the - * channel data. - * + * Populates the given channel with parsed data from the ROME element that + * holds the channel data. + * * @param channel the channel into which parsed data will be added. * @param eChannel the XML element that holds the data for the channel. */ - protected void populateChannel(Channel channel,Element eChannel) { - String title = channel.getTitle(); - if (title!=null) { - eChannel.addContent(generateSimpleElement("title",title)); + protected void populateChannel(final Channel channel, final Element eChannel) { + final String title = channel.getTitle(); + if (title != null) { + eChannel.addContent(generateSimpleElement("title", title)); } - String link = channel.getLink(); - if (link!=null) { - eChannel.addContent(generateSimpleElement("link",link)); + final String link = channel.getLink(); + if (link != null) { + eChannel.addContent(generateSimpleElement("link", link)); } - String description = channel.getDescription(); - if (description!=null) { - eChannel.addContent(generateSimpleElement("description",description)); + final String description = channel.getDescription(); + if (description != null) { + eChannel.addContent(generateSimpleElement("description", description)); } } // maxLen == -1 means unlimited. - protected void checkNotNullAndLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { - Element child = parent.getChild(childName,getFeedNamespace()); + protected void checkNotNullAndLength(final Element parent, final String childName, final int minLen, final int maxLen) throws FeedException { + final Element child = parent.getChild(childName, getFeedNamespace()); if (child == null) { - throw new FeedException("Invalid "+getType()+" feed, missing "+parent.getName()+" "+childName); + throw new FeedException("Invalid " + getType() + " feed, missing " + parent.getName() + " " + childName); } - checkLength(parent,childName,minLen,maxLen); + checkLength(parent, childName, minLen, maxLen); } // maxLen == -1 means unlimited. - protected void checkLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { - Element child = parent.getChild(childName,getFeedNamespace()); + protected void checkLength(final Element parent, final String childName, final int minLen, final int maxLen) throws FeedException { + final Element child = parent.getChild(childName, getFeedNamespace()); if (child != null) { - if (minLen>0 && child.getText().length() 0 && child.getText().length() < minLen) { + throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName + "short of " + minLen + " length"); } - if (maxLen>-1 && child.getText().length()>maxLen) { - throw new FeedException("Invalid "+getType()+" feed, "+parent.getName()+" "+childName + "exceeds "+maxLen+" length"); + if (maxLen > -1 && child.getText().length() > maxLen) { + throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName + "exceeds " + maxLen + " length"); } } } - - protected void addImage(Channel channel,Element parent) throws FeedException { - Image image = channel.getImage(); - if (image!=null) { - Element eImage = new Element("image", getFeedNamespace()); - populateImage(image,eImage); + protected void addImage(final Channel channel, final Element parent) throws FeedException { + final Image image = channel.getImage(); + if (image != null) { + final Element eImage = new Element("image", getFeedNamespace()); + populateImage(image, eImage); checkImageConstraints(eImage); parent.addContent(eImage); } } - protected void populateImage(Image image,Element eImage) { - String title = image.getTitle(); - if (title!=null) { - eImage.addContent(generateSimpleElement("title",title)); + protected void populateImage(final Image image, final Element eImage) { + final String title = image.getTitle(); + if (title != null) { + eImage.addContent(generateSimpleElement("title", title)); } - String url = image.getUrl(); - if (url!=null) { - eImage.addContent(generateSimpleElement("url",url)); + final String url = image.getUrl(); + if (url != null) { + eImage.addContent(generateSimpleElement("url", url)); } - String link = image.getLink(); - if (link!=null) { - eImage.addContent(generateSimpleElement("link",link)); + final String link = image.getLink(); + if (link != null) { + eImage.addContent(generateSimpleElement("link", link)); } } @@ -174,98 +177,98 @@ public class RSS090Generator extends BaseWireFeedGenerator { return "textInput"; } - protected void addTextInput(Channel channel,Element parent) throws FeedException { - TextInput textInput = channel.getTextInput(); - if (textInput!=null) { - Element eTextInput = new Element(getTextInputLabel(), getFeedNamespace()); - populateTextInput(textInput,eTextInput); + protected void addTextInput(final Channel channel, final Element parent) throws FeedException { + final TextInput textInput = channel.getTextInput(); + if (textInput != null) { + final Element eTextInput = new Element(getTextInputLabel(), getFeedNamespace()); + populateTextInput(textInput, eTextInput); checkTextInputConstraints(eTextInput); parent.addContent(eTextInput); } } - protected void populateTextInput(TextInput textInput,Element eTextInput) { - String title = textInput.getTitle(); - if (title!=null) { - eTextInput.addContent(generateSimpleElement("title",title)); + protected void populateTextInput(final TextInput textInput, final Element eTextInput) { + final String title = textInput.getTitle(); + if (title != null) { + eTextInput.addContent(generateSimpleElement("title", title)); } - String description = textInput.getDescription(); - if (description!=null) { - eTextInput.addContent(generateSimpleElement("description",description)); + final String description = textInput.getDescription(); + if (description != null) { + eTextInput.addContent(generateSimpleElement("description", description)); } - String name = textInput.getName(); - if (name!=null) { - eTextInput.addContent(generateSimpleElement("name",name)); + final String name = textInput.getName(); + if (name != null) { + eTextInput.addContent(generateSimpleElement("name", name)); } - String link = textInput.getLink(); - if (link!=null) { - eTextInput.addContent(generateSimpleElement("link",link)); + final String link = textInput.getLink(); + if (link != null) { + eTextInput.addContent(generateSimpleElement("link", link)); } } - protected void addItems(Channel channel,Element parent) throws FeedException { - List items = channel.getItems(); - for (int i=0;i items = channel.getItems(); + for (int i = 0; i < items.size(); i++) { + addItem(items.get(i), parent, i); } checkItemsConstraints(parent); } - protected void addItem(Item item, Element parent, int index) throws FeedException { - Element eItem = new Element("item", getFeedNamespace()); - populateItem(item,eItem, index); + protected void addItem(final Item item, final Element parent, final int index) throws FeedException { + final Element eItem = new Element("item", getFeedNamespace()); + populateItem(item, eItem, index); checkItemConstraints(eItem); - generateItemModules(item.getModules(),eItem); + generateItemModules(item.getModules(), eItem); parent.addContent(eItem); } - protected void populateItem(Item item, Element eItem, int index) { - String title = item.getTitle(); - if (title!=null) { - eItem.addContent(generateSimpleElement("title",title)); + protected void populateItem(final Item item, final Element eItem, final int index) { + final String title = item.getTitle(); + if (title != null) { + eItem.addContent(generateSimpleElement("title", title)); } - String link = item.getLink(); - if (link!=null) { - eItem.addContent(generateSimpleElement("link",link)); + final String link = item.getLink(); + if (link != null) { + eItem.addContent(generateSimpleElement("link", link)); } - generateForeignMarkup(eItem, (List)item.getForeignMarkup()); + generateForeignMarkup(eItem, item.getForeignMarkup()); } - protected Element generateSimpleElement(String name, String value) { - Element element = new Element(name, getFeedNamespace()); + protected Element generateSimpleElement(final String name, final String value) { + final Element element = new Element(name, getFeedNamespace()); element.addContent(value); return element; } - protected void checkChannelConstraints(Element eChannel) throws FeedException { - checkNotNullAndLength(eChannel,"title", 0, 40); - checkNotNullAndLength(eChannel,"description", 0, 500); - checkNotNullAndLength(eChannel,"link", 0, 500); + protected void checkChannelConstraints(final Element eChannel) throws FeedException { + checkNotNullAndLength(eChannel, "title", 0, 40); + checkNotNullAndLength(eChannel, "description", 0, 500); + checkNotNullAndLength(eChannel, "link", 0, 500); } - protected void checkImageConstraints(Element eImage) throws FeedException { - checkNotNullAndLength(eImage,"title", 0, 40); - checkNotNullAndLength(eImage,"url", 0, 500); - checkNotNullAndLength(eImage,"link", 0, 500); + protected void checkImageConstraints(final Element eImage) throws FeedException { + checkNotNullAndLength(eImage, "title", 0, 40); + checkNotNullAndLength(eImage, "url", 0, 500); + checkNotNullAndLength(eImage, "link", 0, 500); } - protected void checkTextInputConstraints(Element eTextInput) throws FeedException { - checkNotNullAndLength(eTextInput,"title", 0, 40); - checkNotNullAndLength(eTextInput,"description", 0, 100); - checkNotNullAndLength(eTextInput,"name", 0, 500); - checkNotNullAndLength(eTextInput,"link", 0, 500); + protected void checkTextInputConstraints(final Element eTextInput) throws FeedException { + checkNotNullAndLength(eTextInput, "title", 0, 40); + checkNotNullAndLength(eTextInput, "description", 0, 100); + checkNotNullAndLength(eTextInput, "name", 0, 500); + checkNotNullAndLength(eTextInput, "link", 0, 500); } - protected void checkItemsConstraints(Element parent) throws FeedException { - int count = parent.getChildren("item",getFeedNamespace()).size(); - if (count<1 || count>15) { - throw new FeedException("Invalid "+getType()+" feed, item count is "+count+" it must be between 1 an 15"); + protected void checkItemsConstraints(final Element parent) throws FeedException { + final int count = parent.getChildren("item", getFeedNamespace()).size(); + if (count < 1 || count > 15) { + throw new FeedException("Invalid " + getType() + " feed, item count is " + count + " it must be between 1 an 15"); } } - protected void checkItemConstraints(Element eItem) throws FeedException { - checkNotNullAndLength(eItem,"title", 0, 100); - checkNotNullAndLength(eItem,"link", 0, 500); + protected void checkItemConstraints(final Element eItem) throws FeedException { + checkNotNullAndLength(eItem, "title", 0, 100); + checkNotNullAndLength(eItem, "link", 0, 500); } } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS090Parser.java b/src/main/java/com/sun/syndication/io/impl/RSS090Parser.java index d3ef333..87d9970 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS090Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS090Parser.java @@ -16,6 +16,15 @@ */ package com.sun.syndication.io.impl; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.rss.Channel; @@ -23,14 +32,6 @@ import com.sun.syndication.feed.rss.Image; import com.sun.syndication.feed.rss.Item; import com.sun.syndication.feed.rss.TextInput; import com.sun.syndication.io.FeedException; -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.Namespace; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; /** */ @@ -39,35 +40,34 @@ public class RSS090Parser extends BaseWireFeedParser { private static final String RDF_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; private static final String RSS_URI = "http://my.netscape.com/rdf/simple/0.9/"; private static final String CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"; - + private static final Namespace RDF_NS = Namespace.getNamespace(RDF_URI); private static final Namespace RSS_NS = Namespace.getNamespace(RSS_URI); private static final Namespace CONTENT_NS = Namespace.getNamespace(CONTENT_URI); - public RSS090Parser() { this("rss_0.9", RSS_NS); } - protected RSS090Parser(String type, Namespace ns) { + protected RSS090Parser(final String type, final Namespace ns) { super(type, ns); } - public boolean isMyType(Document document) { + @Override + public boolean isMyType(final Document document) { boolean ok = false; - Element rssRoot = document.getRootElement(); - Namespace defaultNS = rssRoot.getNamespace(); - List additionalNSs = rssRoot.getAdditionalNamespaces(); + final Element rssRoot = document.getRootElement(); + final Namespace defaultNS = rssRoot.getNamespace(); + final List additionalNSs = rssRoot.getAdditionalNamespaces(); - ok = defaultNS!=null && defaultNS.equals(getRDFNamespace()); + ok = defaultNS != null && defaultNS.equals(getRDFNamespace()); if (ok) { - if (additionalNSs==null) { + if (additionalNSs == null) { ok = false; - } - else { + } else { ok = false; - for (int i=0;!ok && i * This implementation returns the EMTPY namespace. *

- * + * * @return returns the EMPTY namespace. */ protected Namespace getRSSNamespace() { @@ -105,11 +109,12 @@ public class RSS090Parser extends BaseWireFeedParser { } /** - * Returns the namespace used by RDF elements in document of the RSS version the parser supports. + * Returns the namespace used by RDF elements in document of the RSS version + * the parser supports. *

* This implementation returns the EMTPY namespace. *

- * + * * @return returns the EMPTY namespace. */ protected Namespace getRDFNamespace() { @@ -121,7 +126,7 @@ public class RSS090Parser extends BaseWireFeedParser { *

* This implementation returns the EMTPY namespace. *

- * + * * @return returns the EMPTY namespace. */ protected Namespace getContentNamespace() { @@ -131,30 +136,31 @@ public class RSS090Parser extends BaseWireFeedParser { /** * Parses the root element of an RSS document into a Channel bean. *

- * It reads title, link and description and delegates to parseImage, parseItems - * and parseTextInput. This delegation always passes the root element of the RSS - * document as different RSS version may have this information in different parts - * of the XML tree (no assumptions made thanks to the specs variaty) + * It reads title, link and description and delegates to parseImage, + * parseItems and parseTextInput. This delegation always passes the root + * element of the RSS document as different RSS version may have this + * information in different parts of the XML tree (no assumptions made + * thanks to the specs variaty) *

- * + * * @param rssRoot the root element of the RSS document to parse. * @return the parsed Channel bean. */ - protected WireFeed parseChannel(Element rssRoot) { - Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); + protected WireFeed parseChannel(final Element rssRoot) { + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); - Channel channel = new Channel(getType()); + final Channel channel = new Channel(getType()); - Element e = eChannel.getChild("title",getRSSNamespace()); - if (e!=null) { + Element e = eChannel.getChild("title", getRSSNamespace()); + if (e != null) { channel.setTitle(e.getText()); } - e = eChannel.getChild("link",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("link", getRSSNamespace()); + if (e != null) { channel.setLink(e.getText()); } - e = eChannel.getChild("description",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("description", getRSSNamespace()); + if (e != null) { channel.setDescription(e.getText()); } @@ -162,13 +168,13 @@ public class RSS090Parser extends BaseWireFeedParser { channel.setTextInput(parseTextInput(rssRoot)); - // Unfortunately Microsoft's SSE extension has a special case of - // effectively putting the sharing channel module inside the RSS tag - // and not inside the channel itself. So we also need to look for + // Unfortunately Microsoft's SSE extension has a special case of + // effectively putting the sharing channel module inside the RSS tag + // and not inside the channel itself. So we also need to look for // channel modules from the root RSS element. - List allFeedModules = new ArrayList(); - List rootModules = parseFeedModules(rssRoot); - List channelModules = parseFeedModules(eChannel); + final List allFeedModules = new ArrayList(); + final List rootModules = parseFeedModules(rssRoot); + final List channelModules = parseFeedModules(eChannel); if (rootModules != null) { allFeedModules.addAll(rootModules); } @@ -178,67 +184,69 @@ public class RSS090Parser extends BaseWireFeedParser { channel.setModules(allFeedModules); channel.setItems(parseItems(rssRoot)); - List foreignMarkup = - extractForeignMarkup(eChannel, channel, getRSSNamespace()); + final List foreignMarkup = extractForeignMarkup(eChannel, channel, getRSSNamespace()); if (foreignMarkup.size() > 0) { channel.setForeignMarkup(foreignMarkup); - } + } return channel; } - /** - * This method exists because RSS0.90 and RSS1.0 have the 'item' elements under the root elemment. - * And RSS0.91, RSS0.02, RSS0.93, RSS0.94 and RSS2.0 have the item elements under the 'channel' element. + * This method exists because RSS0.90 and RSS1.0 have the 'item' elements + * under the root elemment. And RSS0.91, RSS0.02, RSS0.93, RSS0.94 and + * RSS2.0 have the item elements under the 'channel' element. *

*/ - protected List getItems(Element rssRoot) { - return rssRoot.getChildren("item",getRSSNamespace()); + protected List getItems(final Element rssRoot) { + return rssRoot.getChildren("item", getRSSNamespace()); } /** - * This method exists because RSS0.90 and RSS1.0 have the 'image' element under the root elemment. - * And RSS0.91, RSS0.02, RSS0.93, RSS0.94 and RSS2.0 have it under the 'channel' element. + * This method exists because RSS0.90 and RSS1.0 have the 'image' element + * under the root elemment. And RSS0.91, RSS0.02, RSS0.93, RSS0.94 and + * RSS2.0 have it under the 'channel' element. *

*/ - protected Element getImage(Element rssRoot) { - return rssRoot.getChild("image",getRSSNamespace()); + protected Element getImage(final Element rssRoot) { + return rssRoot.getChild("image", getRSSNamespace()); } /** - * This method exists because RSS0.90 and RSS1.0 have the 'textinput' element under the root elemment. - * And RSS0.91, RSS0.02, RSS0.93, RSS0.94 and RSS2.0 have it under the 'channel' element. + * This method exists because RSS0.90 and RSS1.0 have the 'textinput' + * element under the root elemment. And RSS0.91, RSS0.02, RSS0.93, RSS0.94 + * and RSS2.0 have it under the 'channel' element. *

*/ - protected Element getTextInput(Element rssRoot) { - return rssRoot.getChild("textinput",getRSSNamespace()); + protected Element getTextInput(final Element rssRoot) { + return rssRoot.getChild("textinput", getRSSNamespace()); } /** - * Parses the root element of an RSS document looking for image information. + * Parses the root element of an RSS document looking for image information. *

* It reads title and url out of the 'image' element. *

- * - * @param rssRoot the root element of the RSS document to parse for image information. + * + * @param rssRoot the root element of the RSS document to parse for image + * information. * @return the parsed image bean. */ - protected Image parseImage(Element rssRoot) { + protected Image parseImage(final Element rssRoot) { Image image = null; - Element eImage = getImage(rssRoot); - if (eImage!=null) { + final Element eImage = getImage(rssRoot); + if (eImage != null) { image = new Image(); - Element e = eImage.getChild("title",getRSSNamespace()); - if (e!=null) { + Element e = eImage.getChild("title", getRSSNamespace()); + if (e != null) { image.setTitle(e.getText()); } - e = eImage.getChild("url",getRSSNamespace()); - if (e!=null) { + e = eImage.getChild("url", getRSSNamespace()); + if (e != null) { image.setUrl(e.getText()); } - e = eImage.getChild("link",getRSSNamespace()); - if (e!=null) { + e = eImage.getChild("link", getRSSNamespace()); + if (e != null) { image.setLink(e.getText()); } } @@ -246,22 +254,25 @@ public class RSS090Parser extends BaseWireFeedParser { } /** - * Parses the root element of an RSS document looking for all items information. + * Parses the root element of an RSS document looking for all items + * information. *

- * It iterates through the item elements list, obtained from the getItems() method, and invoke parseItem() - * for each item element. The resulting RSSItem of each item element is stored in a list. + * It iterates through the item elements list, obtained from the getItems() + * method, and invoke parseItem() for each item element. The resulting + * RSSItem of each item element is stored in a list. *

- * - * @param rssRoot the root element of the RSS document to parse for all items information. + * + * @param rssRoot the root element of the RSS document to parse for all + * items information. * @return a list with all the parsed RSSItem beans. */ - protected List parseItems(Element rssRoot) { - Collection eItems = getItems(rssRoot); + protected List parseItems(final Element rssRoot) { + final Collection eItems = getItems(rssRoot); - List items = new ArrayList(); - for (Iterator i=eItems.iterator();i.hasNext();) { - Element eItem = (Element) i.next(); - items.add(parseItem(rssRoot,eItem)); + final List items = new ArrayList(); + for (final Element element : eItems) { + final Element eItem = element; + items.add(parseItem(rssRoot, eItem)); } return items; } @@ -271,33 +282,35 @@ public class RSS090Parser extends BaseWireFeedParser { *

* It reads title and link out of the 'item' element. *

- * - * @param rssRoot the root element of the RSS document in case it's needed for context. + * + * @param rssRoot the root element of the RSS document in case it's needed + * for context. * @param eItem the item element to parse. * @return the parsed RSSItem bean. */ - protected Item parseItem(Element rssRoot,Element eItem) { - Item item = new Item(); - Element e = eItem.getChild("title",getRSSNamespace()); - if (e!=null) { + protected Item parseItem(final Element rssRoot, final Element eItem) { + final Item item = new Item(); + Element e = eItem.getChild("title", getRSSNamespace()); + if (e != null) { item.setTitle(e.getText()); } - e = eItem.getChild("link",getRSSNamespace()); - if (e!=null) { + e = eItem.getChild("link", getRSSNamespace()); + if (e != null) { item.setLink(e.getText()); item.setUri(e.getText()); } - + item.setModules(parseItemModules(eItem)); - - List foreignMarkup = - extractForeignMarkup(eItem, item, getRSSNamespace()); - //content:encoded elements are treated special, without a module, they have to be removed from the foreign - //markup to avoid duplication in case of read/write. Note that this fix will break if a content module is - //used - Iterator iterator = foreignMarkup.iterator(); + + final List foreignMarkup = extractForeignMarkup(eItem, item, getRSSNamespace()); + // content:encoded elements are treated special, without a module, they + // have to be removed from the foreign + // markup to avoid duplication in case of read/write. Note that this fix + // will break if a content module is + // used + final Iterator iterator = foreignMarkup.iterator(); while (iterator.hasNext()) { - Element ie = (Element)iterator.next(); + final Element ie = iterator.next(); if (getContentNamespace().equals(ie.getNamespace()) && ie.getName().equals("encoded")) { iterator.remove(); } @@ -308,40 +321,41 @@ public class RSS090Parser extends BaseWireFeedParser { return item; } - /** - * Parses the root element of an RSS document looking for text-input information. + * Parses the root element of an RSS document looking for text-input + * information. *

- * It reads title, description, name and link out of the 'textinput' or 'textInput' element. + * It reads title, description, name and link out of the 'textinput' or + * 'textInput' element. *

- * - * @param rssRoot the root element of the RSS document to parse for text-input information. + * + * @param rssRoot the root element of the RSS document to parse for + * text-input information. * @return the parsed RSSTextInput bean. */ - protected TextInput parseTextInput(Element rssRoot) { + protected TextInput parseTextInput(final Element rssRoot) { TextInput textInput = null; - Element eTextInput = getTextInput(rssRoot); - if (eTextInput!=null) { + final Element eTextInput = getTextInput(rssRoot); + if (eTextInput != null) { textInput = new TextInput(); - Element e = eTextInput.getChild("title",getRSSNamespace()); - if (e!=null) { + Element e = eTextInput.getChild("title", getRSSNamespace()); + if (e != null) { textInput.setTitle(e.getText()); } - e = eTextInput.getChild("description",getRSSNamespace()); - if (e!=null) { + e = eTextInput.getChild("description", getRSSNamespace()); + if (e != null) { textInput.setDescription(e.getText()); } - e = eTextInput.getChild("name",getRSSNamespace()); - if (e!=null) { + e = eTextInput.getChild("name", getRSSNamespace()); + if (e != null) { textInput.setName(e.getText()); } - e = eTextInput.getChild("link",getRSSNamespace()); - if (e!=null) { + e = eTextInput.getChild("link", getRSSNamespace()); + if (e != null) { textInput.setLink(e.getText()); } } return textInput; } - } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeGenerator.java b/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeGenerator.java index e86cd2c..060c2ba 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeGenerator.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeGenerator.java @@ -23,30 +23,30 @@ import org.jdom2.Element; /** * Feed Generator for RSS 0.91 *

- * + * * @author Elaine Chien - * + * */ public class RSS091NetscapeGenerator extends RSS091UserlandGenerator { private String _version; public RSS091NetscapeGenerator() { - this("rss_0.91N","0.91"); + this("rss_0.91N", "0.91"); } - protected RSS091NetscapeGenerator(String type,String version) { - super(type,version); + protected RSS091NetscapeGenerator(final String type, final String version) { + super(type, version); } - protected Document createDocument(Element root) { - Document doc = new Document(root); - DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, - RSS091NetscapeParser.PUBLIC_ID, - RSS091NetscapeParser.SYSTEM_ID); + @Override + protected Document createDocument(final Element root) { + final Document doc = new Document(root); + final DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType); return doc; } + @Override protected String getTextInputLabel() { return "textinput"; } @@ -54,6 +54,7 @@ public class RSS091NetscapeGenerator extends RSS091UserlandGenerator { /** * To be overriden by RSS 0.91 Netscape and RSS 0.94 */ + @Override protected boolean isHourFormat24() { return false; } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeParser.java b/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeParser.java index 5de4b7f..7e6c3f5 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeParser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS091NetscapeParser.java @@ -16,7 +16,10 @@ */ package com.sun.syndication.io.impl; -import org.jdom2.*; +import org.jdom2.Attribute; +import org.jdom2.DocType; +import org.jdom2.Document; +import org.jdom2.Element; /** */ @@ -26,7 +29,7 @@ public class RSS091NetscapeParser extends RSS091UserlandParser { this("rss_0.91N"); } - protected RSS091NetscapeParser(String type) { + protected RSS091NetscapeParser(final String type) { super(type); } @@ -34,20 +37,21 @@ public class RSS091NetscapeParser extends RSS091UserlandParser { static final String PUBLIC_ID = "-//Netscape Communications//DTD RSS 0.91//EN"; static final String SYSTEM_ID = "http://my.netscape.com/publish/formats/rss-0.91.dtd"; - public boolean isMyType(Document document) { + @Override + public boolean isMyType(final Document document) { boolean ok = false; - Element rssRoot = document.getRootElement(); + final Element rssRoot = document.getRootElement(); ok = rssRoot.getName().equals("rss"); if (ok) { ok = false; - Attribute version = rssRoot.getAttribute("version"); - if (version!=null) { + final Attribute version = rssRoot.getAttribute("version"); + if (version != null) { ok = version.getValue().equals(getRSSVersion()); if (ok) { ok = false; - DocType docType = document.getDocType(); + final DocType docType = document.getDocType(); - if (docType!=null) { + if (docType != null) { ok = ELEMENT_NAME.equals(docType.getElementName()); ok = ok && PUBLIC_ID.equals(docType.getPublicID()); ok = ok && SYSTEM_ID.equals(docType.getSystemID()); @@ -58,10 +62,12 @@ public class RSS091NetscapeParser extends RSS091UserlandParser { return ok; } - protected boolean isHourFormat24(Element rssRoot) { + @Override + protected boolean isHourFormat24(final Element rssRoot) { return false; } + @Override protected String getTextInputLabel() { return "textinput"; } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java b/src/main/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java index 3924152..cce9e7e 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS091UserlandGenerator.java @@ -16,40 +16,40 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.rss.Channel; -import com.sun.syndication.feed.rss.Description; -import com.sun.syndication.feed.rss.Image; -import com.sun.syndication.feed.rss.Item; -import com.sun.syndication.io.FeedException; +import java.util.Date; +import java.util.List; import org.jdom2.Attribute; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.Namespace; -import java.util.Date; -import java.util.List; - +import com.sun.syndication.feed.rss.Channel; +import com.sun.syndication.feed.rss.Description; +import com.sun.syndication.feed.rss.Image; +import com.sun.syndication.feed.rss.Item; +import com.sun.syndication.io.FeedException; /** * Feed Generator for RSS 0.91 *

- * + * * @author Elaine Chien - * + * */ public class RSS091UserlandGenerator extends RSS090Generator { - private String _version; + private final String _version; public RSS091UserlandGenerator() { this("rss_0.91U", "0.91"); } - protected RSS091UserlandGenerator(String type, String version) { + protected RSS091UserlandGenerator(final String type, final String version) { super(type); - _version = version; + this._version = version; } + @Override protected Namespace getFeedNamespace() { return Namespace.NO_NAMESPACE; } @@ -62,22 +62,22 @@ public class RSS091UserlandGenerator extends RSS090Generator { } protected String getVersion() { - return _version; + return this._version; } - protected void addChannel(Channel channel, Element parent) - throws FeedException { + @Override + protected void addChannel(final Channel channel, final Element parent) throws FeedException { super.addChannel(channel, parent); - Element eChannel = parent.getChild("channel", getFeedNamespace()); + final Element eChannel = parent.getChild("channel", getFeedNamespace()); addImage(channel, eChannel); addTextInput(channel, eChannel); addItems(channel, eChannel); } - protected void checkChannelConstraints(Element eChannel) - throws FeedException { + @Override + protected void checkChannelConstraints(final Element eChannel) throws FeedException { checkNotNullAndLength(eChannel, "title", 1, 100); checkNotNullAndLength(eChannel, "description", 1, 500); checkNotNullAndLength(eChannel, "link", 1, 500); @@ -91,21 +91,21 @@ public class RSS091UserlandGenerator extends RSS090Generator { checkLength(eChannel, "managingEditor", 1, 100); checkLength(eChannel, "webMaster", 1, 100); - Element skipHours = eChannel.getChild("skipHours"); + final Element skipHours = eChannel.getChild("skipHours"); if (skipHours != null) { - List hours = skipHours.getChildren(); + final List hours = skipHours.getChildren(); for (int i = 0; i < hours.size(); i++) { - Element hour = (Element) hours.get(i); - int value = Integer.parseInt(hour.getText().trim()); + final Element hour = hours.get(i); + final int value = Integer.parseInt(hour.getText().trim()); if (isHourFormat24()) { - if ((value < 1) || (value > 24)) { + if (value < 1 || value > 24) { throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24"); } } else { - if ((value < 0) || (value > 23)) { + if (value < 0 || value > 23) { throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23"); } } @@ -113,8 +113,8 @@ public class RSS091UserlandGenerator extends RSS090Generator { } } - protected void checkImageConstraints(Element eImage) - throws FeedException { + @Override + protected void checkImageConstraints(final Element eImage) throws FeedException { checkNotNullAndLength(eImage, "title", 1, 100); checkNotNullAndLength(eImage, "url", 1, 500); @@ -124,29 +124,31 @@ public class RSS091UserlandGenerator extends RSS090Generator { checkLength(eImage, "description", 1, 100); } - protected void checkItemConstraints(Element eItem) - throws FeedException { + @Override + protected void checkItemConstraints(final Element eItem) throws FeedException { checkNotNullAndLength(eItem, "title", 1, 100); checkNotNullAndLength(eItem, "link", 1, 500); checkLength(eItem, "description", 1, 500); } - protected void checkTextInputConstraints(Element eTextInput) - throws FeedException { + @Override + protected void checkTextInputConstraints(final Element eTextInput) throws FeedException { checkNotNullAndLength(eTextInput, "title", 1, 100); checkNotNullAndLength(eTextInput, "description", 1, 500); checkNotNullAndLength(eTextInput, "name", 1, 20); checkNotNullAndLength(eTextInput, "link", 1, 500); } - protected Document createDocument(Element root) { + @Override + protected Document createDocument(final Element root) { return new Document(root); } - protected Element createRootElement(Channel channel) { - Element root = new Element("rss", getFeedNamespace()); - Attribute version = new Attribute("version", getVersion()); + @Override + protected Element createRootElement(final Channel channel) { + final Element root = new Element("rss", getFeedNamespace()); + final Attribute version = new Attribute("version", getVersion()); root.setAttribute(version); root.addNamespaceDeclaration(getContentNamespace()); generateModuleNamespaceDefs(root); @@ -154,8 +156,8 @@ public class RSS091UserlandGenerator extends RSS090Generator { return root; } - protected Element generateSkipDaysElement(List days) { - Element skipDaysElement = new Element("skipDays"); + protected Element generateSkipDaysElement(final List days) { + final Element skipDaysElement = new Element("skipDays"); for (int i = 0; i < days.size(); i++) { skipDaysElement.addContent(generateSimpleElement("day", days.get(i).toString())); @@ -164,8 +166,8 @@ public class RSS091UserlandGenerator extends RSS090Generator { return skipDaysElement; } - protected Element generateSkipHoursElement(List hours) { - Element skipHoursElement = new Element("skipHours", getFeedNamespace()); + protected Element generateSkipHoursElement(final List hours) { + final Element skipHoursElement = new Element("skipHours", getFeedNamespace()); for (int i = 0; i < hours.size(); i++) { skipHoursElement.addContent(generateSimpleElement("hour", hours.get(i).toString())); @@ -174,108 +176,111 @@ public class RSS091UserlandGenerator extends RSS090Generator { return skipHoursElement; } - protected void populateChannel(Channel channel, Element eChannel) { + @Override + protected void populateChannel(final Channel channel, final Element eChannel) { super.populateChannel(channel, eChannel); - String language = channel.getLanguage(); + final String language = channel.getLanguage(); if (language != null) { eChannel.addContent(generateSimpleElement("language", language)); } - String rating = channel.getRating(); + final String rating = channel.getRating(); if (rating != null) { eChannel.addContent(generateSimpleElement("rating", rating)); } - String copyright = channel.getCopyright(); + final String copyright = channel.getCopyright(); if (copyright != null) { eChannel.addContent(generateSimpleElement("copyright", copyright)); } - Date pubDate = channel.getPubDate(); + final Date pubDate = channel.getPubDate(); if (pubDate != null) { eChannel.addContent(generateSimpleElement("pubDate", DateParser.formatRFC822(pubDate))); } - Date lastBuildDate = channel.getLastBuildDate(); + final Date lastBuildDate = channel.getLastBuildDate(); if (lastBuildDate != null) { eChannel.addContent(generateSimpleElement("lastBuildDate", DateParser.formatRFC822(lastBuildDate))); } - String docs = channel.getDocs(); + final String docs = channel.getDocs(); if (docs != null) { eChannel.addContent(generateSimpleElement("docs", docs)); } - String managingEditor = channel.getManagingEditor(); + final String managingEditor = channel.getManagingEditor(); if (managingEditor != null) { eChannel.addContent(generateSimpleElement("managingEditor", managingEditor)); } - String webMaster = channel.getWebMaster(); + final String webMaster = channel.getWebMaster(); if (webMaster != null) { eChannel.addContent(generateSimpleElement("webMaster", webMaster)); } - List skipHours = channel.getSkipHours(); + final List skipHours = channel.getSkipHours(); - if ((skipHours != null) && (skipHours.size() > 0)) { + if (skipHours != null && skipHours.size() > 0) { eChannel.addContent(generateSkipHoursElement(skipHours)); } - List skipDays = channel.getSkipDays(); + final List skipDays = channel.getSkipDays(); - if ((skipDays != null) && (skipDays.size() > 0)) { + if (skipDays != null && skipDays.size() > 0) { eChannel.addContent(generateSkipDaysElement(skipDays)); } } - protected void populateFeed(Channel channel, Element parent) - throws FeedException { + @Override + protected void populateFeed(final Channel channel, final Element parent) throws FeedException { addChannel(channel, parent); } - protected void populateImage(Image image, Element eImage) { + @Override + protected void populateImage(final Image image, final Element eImage) { super.populateImage(image, eImage); - Integer width = image.getWidth(); + final Integer width = image.getWidth(); if (width != null) { eImage.addContent(generateSimpleElement("width", String.valueOf(width))); } - Integer height = image.getHeight(); + final Integer height = image.getHeight(); if (height != null) { eImage.addContent(generateSimpleElement("height", String.valueOf(height))); } - String description = image.getDescription(); + final String description = image.getDescription(); if (description != null) { eImage.addContent(generateSimpleElement("description", description)); } } - protected void populateItem(Item item, Element eItem, int index) { + @Override + protected void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); - Description description = item.getDescription(); + final Description description = item.getDescription(); if (description != null) { eItem.addContent(generateSimpleElement("description", description.getValue())); } - if ((item.getModule(getContentNamespace().getURI()) == null) && (item.getContent() != null)) { - Element elem = new Element("encoded", getContentNamespace()); + if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) { + final Element elem = new Element("encoded", getContentNamespace()); elem.addContent(item.getContent().getValue()); eItem.addContent(elem); } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java b/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java index 8077cb7..4a7d7fd 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java @@ -16,18 +16,21 @@ */ package com.sun.syndication.io.impl; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.jdom2.Attribute; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.rss.Channel; import com.sun.syndication.feed.rss.Content; import com.sun.syndication.feed.rss.Description; import com.sun.syndication.feed.rss.Image; import com.sun.syndication.feed.rss.Item; -import org.jdom2.Attribute; -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.Namespace; - -import java.util.*; /** */ @@ -37,18 +40,19 @@ public class RSS091UserlandParser extends RSS090Parser { this("rss_0.91U"); } - protected RSS091UserlandParser(String type) { + protected RSS091UserlandParser(final String type) { super(type, null); } - public boolean isMyType(Document document) { + @Override + public boolean isMyType(final Document document) { boolean ok; - Element rssRoot = document.getRootElement(); + final Element rssRoot = document.getRootElement(); ok = rssRoot.getName().equals("rss"); if (ok) { ok = false; - Attribute version = rssRoot.getAttribute("version"); - if (version!=null) { + final Attribute version = rssRoot.getAttribute("version"); + if (version != null) { ok = version.getValue().equals(getRSSVersion()); } } @@ -56,9 +60,10 @@ public class RSS091UserlandParser extends RSS090Parser { } protected String getRSSVersion() { - return "0.91"; + return "0.91"; } + @Override protected Namespace getRSSNamespace() { return Namespace.getNamespace(""); } @@ -66,78 +71,79 @@ public class RSS091UserlandParser extends RSS090Parser { /** * To be overriden by RSS 0.91 Netscape and RSS 0.94 */ - protected boolean isHourFormat24(Element rssRoot) { + protected boolean isHourFormat24(final Element rssRoot) { return true; } /** * Parses the root element of an RSS document into a Channel bean. *

- * It first invokes super.parseChannel and then parses and injects the following - * properties if present: language, pubDate, rating and copyright. + * It first invokes super.parseChannel and then parses and injects the + * following properties if present: language, pubDate, rating and copyright. *

- * + * * @param rssRoot the root element of the RSS document to parse. * @return the parsed Channel bean. */ - protected WireFeed parseChannel(Element rssRoot) { - Channel channel = (Channel) super.parseChannel(rssRoot); + @Override + protected WireFeed parseChannel(final Element rssRoot) { + final Channel channel = (Channel) super.parseChannel(rssRoot); - Element eChannel = rssRoot.getChild("channel",getRSSNamespace()); + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); - Element e = eChannel.getChild("language",getRSSNamespace()); - if (e!=null) { + Element e = eChannel.getChild("language", getRSSNamespace()); + if (e != null) { channel.setLanguage(e.getText()); } - e = eChannel.getChild("rating",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("rating", getRSSNamespace()); + if (e != null) { channel.setRating(e.getText()); } - e = eChannel.getChild("copyright",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("copyright", getRSSNamespace()); + if (e != null) { channel.setCopyright(e.getText()); } - e = eChannel.getChild("pubDate",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("pubDate", getRSSNamespace()); + if (e != null) { channel.setPubDate(DateParser.parseDate(e.getText())); } - e = eChannel.getChild("lastBuildDate",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("lastBuildDate", getRSSNamespace()); + if (e != null) { channel.setLastBuildDate(DateParser.parseDate(e.getText())); } - e = eChannel.getChild("docs",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("docs", getRSSNamespace()); + if (e != null) { channel.setDocs(e.getText()); } - e = eChannel.getChild("docs",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("docs", getRSSNamespace()); + if (e != null) { channel.setDocs(e.getText()); } - e = eChannel.getChild("managingEditor",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("managingEditor", getRSSNamespace()); + if (e != null) { channel.setManagingEditor(e.getText()); } - e = eChannel.getChild("webMaster",getRSSNamespace()); - if (e!=null) { + e = eChannel.getChild("webMaster", getRSSNamespace()); + if (e != null) { channel.setWebMaster(e.getText()); } e = eChannel.getChild("skipHours"); - if (e!=null) { - List skipHours = new ArrayList(); - List eHours = e.getChildren("hour",getRSSNamespace()); - for (int i=0;i skipHours = new ArrayList(); + final List eHours = e.getChildren("hour", getRSSNamespace()); + for (int i = 0; i < eHours.size(); i++) { + final Element eHour = eHours.get(i); skipHours.add(new Integer(eHour.getText().trim())); } channel.setSkipHours(skipHours); } e = eChannel.getChild("skipDays"); - if (e!=null) { - List skipDays = new ArrayList(); - List eDays = e.getChildren("day",getRSSNamespace()); - for (int i=0;i skipDays = new ArrayList(); + final List eDays = e.getChildren("day", getRSSNamespace()); + for (int i = 0; i < eDays.size(); i++) { + final Element eDay = eDays.get(i); skipDays.add(eDay.getText().trim()); } channel.setSkipDays(skipDays); @@ -146,57 +152,61 @@ public class RSS091UserlandParser extends RSS090Parser { } /** - * Parses the root element of an RSS document looking for image information. + * Parses the root element of an RSS document looking for image information. *

- * It first invokes super.parseImage and then parses and injects the following - * properties if present: url, link, width, height and description. + * It first invokes super.parseImage and then parses and injects the + * following properties if present: url, link, width, height and + * description. *

- * - * @param rssRoot the root element of the RSS document to parse for image information. + * + * @param rssRoot the root element of the RSS document to parse for image + * information. * @return the parsed RSSImage bean. */ - protected Image parseImage(Element rssRoot) { - Image image = super.parseImage(rssRoot); - if (image!=null) { - Element eImage = getImage(rssRoot); - Element e = eImage.getChild("width",getRSSNamespace()); - if (e!=null) { - Integer val = NumberParser.parseInt(e.getText()); - if (val != null) { - image.setWidth(val.intValue()); - } + @Override + protected Image parseImage(final Element rssRoot) { + final Image image = super.parseImage(rssRoot); + if (image != null) { + final Element eImage = getImage(rssRoot); + Element e = eImage.getChild("width", getRSSNamespace()); + if (e != null) { + final Integer val = NumberParser.parseInt(e.getText()); + if (val != null) { + image.setWidth(val.intValue()); + } } - e = eImage.getChild("height",getRSSNamespace()); - if (e!=null) { - Integer val = NumberParser.parseInt(e.getText()); - if (val != null) { - image.setHeight(val.intValue()); - } + e = eImage.getChild("height", getRSSNamespace()); + if (e != null) { + final Integer val = NumberParser.parseInt(e.getText()); + if (val != null) { + image.setHeight(val.intValue()); + } } - e = eImage.getChild("description",getRSSNamespace()); - if (e!=null) { + e = eImage.getChild("description", getRSSNamespace()); + if (e != null) { image.setDescription(e.getText()); } } return image; } - /** * It looks for the 'item' elements under the 'channel' elemment. */ - protected List getItems(Element rssRoot) { - Element eChannel = rssRoot.getChild("channel",getRSSNamespace()); - List emptyList = Collections.emptyList(); - return (eChannel!=null) ? eChannel.getChildren("item",getRSSNamespace()) : emptyList; + @Override + protected List getItems(final Element rssRoot) { + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); + final List emptyList = Collections.emptyList(); + return eChannel != null ? eChannel.getChildren("item", getRSSNamespace()) : emptyList; } /** * It looks for the 'image' elements under the 'channel' elemment. */ - protected Element getImage(Element rssRoot) { - Element eChannel = rssRoot.getChild("channel",getRSSNamespace()); - return (eChannel!=null) ? eChannel.getChild("image",getRSSNamespace()) : null; + @Override + protected Element getImage(final Element rssRoot) { + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); + return eChannel != null ? eChannel.getChild("image", getRSSNamespace()) : null; } /** @@ -209,31 +219,35 @@ public class RSS091UserlandParser extends RSS090Parser { /** * It looks for the 'textinput' elements under the 'channel' elemment. */ - protected Element getTextInput(Element rssRoot) { - String elementName = getTextInputLabel(); - Element eChannel = rssRoot.getChild("channel",getRSSNamespace()); - return (eChannel!=null) ? eChannel.getChild(elementName,getRSSNamespace()) : null; + @Override + protected Element getTextInput(final Element rssRoot) { + final String elementName = getTextInputLabel(); + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); + return eChannel != null ? eChannel.getChild(elementName, getRSSNamespace()) : null; } /** * Parses an item element of an RSS document looking for item information. *

- * It first invokes super.parseItem and then parses and injects the description property if present. + * It first invokes super.parseItem and then parses and injects the + * description property if present. *

- * - * @param rssRoot the root element of the RSS document in case it's needed for context. + * + * @param rssRoot the root element of the RSS document in case it's needed + * for context. * @param eItem the item element to parse. * @return the parsed RSSItem bean. */ - protected Item parseItem(Element rssRoot, Element eItem) { - Item item = super.parseItem(rssRoot,eItem); - Element e = eItem.getChild("description", getRSSNamespace()); - if (e!=null) { - item.setDescription(parseItemDescription(rssRoot,e)); + @Override + protected Item parseItem(final Element rssRoot, final Element eItem) { + final Item item = super.parseItem(rssRoot, eItem); + final Element e = eItem.getChild("description", getRSSNamespace()); + if (e != null) { + item.setDescription(parseItemDescription(rssRoot, e)); } - Element ce = eItem.getChild("encoded", getContentNamespace()); + final Element ce = eItem.getChild("encoded", getContentNamespace()); if (ce != null) { - Content content = new Content(); + final Content content = new Content(); content.setType(Content.HTML); content.setValue(ce.getText()); item.setContent(content); @@ -241,8 +255,8 @@ public class RSS091UserlandParser extends RSS090Parser { return item; } - protected Description parseItemDescription(Element rssRoot,Element eDesc) { - Description desc = new Description(); + protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { + final Description desc = new Description(); desc.setType("text/plain"); desc.setValue(eDesc.getText()); return desc; diff --git a/src/main/java/com/sun/syndication/io/impl/RSS092Generator.java b/src/main/java/com/sun/syndication/io/impl/RSS092Generator.java index 9e1e1a3..14633e5 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS092Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS092Generator.java @@ -16,43 +16,49 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.rss.*; -import com.sun.syndication.io.FeedException; +import java.util.List; + import org.jdom2.Attribute; import org.jdom2.Element; -import java.util.List; - +import com.sun.syndication.feed.rss.Category; +import com.sun.syndication.feed.rss.Channel; +import com.sun.syndication.feed.rss.Cloud; +import com.sun.syndication.feed.rss.Enclosure; +import com.sun.syndication.feed.rss.Item; +import com.sun.syndication.feed.rss.Source; +import com.sun.syndication.io.FeedException; /** * Feed Generator for RSS 0.92 *

- * + * * @author Elaine Chien - * + * */ public class RSS092Generator extends RSS091UserlandGenerator { public RSS092Generator() { - this("rss_0.92","0.92"); + this("rss_0.92", "0.92"); } - protected RSS092Generator(String type,String version) { - super(type,version); + protected RSS092Generator(final String type, final String version) { + super(type, version); } - protected void populateChannel(Channel channel,Element eChannel) { - super.populateChannel(channel,eChannel); + @Override + protected void populateChannel(final Channel channel, final Element eChannel) { + super.populateChannel(channel, eChannel); - Cloud cloud = channel.getCloud(); - if (cloud!=null) { + final Cloud cloud = channel.getCloud(); + if (cloud != null) { eChannel.addContent(generateCloud(cloud)); } } - protected Element generateCloud(Cloud cloud) { - Element eCloud = new Element("cloud",getFeedNamespace()); + protected Element generateCloud(final Cloud cloud) { + final Element eCloud = new Element("cloud", getFeedNamespace()); if (cloud.getDomain() != null) { eCloud.setAttribute(new Attribute("domain", cloud.getDomain())); @@ -77,31 +83,32 @@ public class RSS092Generator extends RSS091UserlandGenerator { } // Another one to thanks DW for - protected int getNumberOfEnclosures(List enclosures) { - return (enclosures.size()>0) ? 1 : 0; + protected int getNumberOfEnclosures(final List enclosures) { + return enclosures.size() > 0 ? 1 : 0; } - protected void populateItem(Item item, Element eItem, int index) { - super.populateItem(item,eItem, index); + @Override + protected void populateItem(final Item item, final Element eItem, final int index) { + super.populateItem(item, eItem, index); - Source source =item.getSource(); + final Source source = item.getSource(); if (source != null) { eItem.addContent(generateSourceElement(source)); } - List enclosures = item.getEnclosures(); - for(int i = 0; i < getNumberOfEnclosures(enclosures); i++) { - eItem.addContent(generateEnclosure((Enclosure)enclosures.get(i))); + final List enclosures = item.getEnclosures(); + for (int i = 0; i < getNumberOfEnclosures(enclosures); i++) { + eItem.addContent(generateEnclosure(enclosures.get(i))); } - List categories = item.getCategories(); - for(int i = 0; i < categories.size(); i++) { - eItem.addContent(generateCategoryElement((Category)categories.get(i))); + final List categories = item.getCategories(); + for (int i = 0; i < categories.size(); i++) { + eItem.addContent(generateCategoryElement(categories.get(i))); } } - protected Element generateSourceElement(Source source) { - Element sourceElement = new Element("source",getFeedNamespace()); + protected Element generateSourceElement(final Source source) { + final Element sourceElement = new Element("source", getFeedNamespace()); if (source.getUrl() != null) { sourceElement.setAttribute(new Attribute("url", source.getUrl())); } @@ -109,8 +116,8 @@ public class RSS092Generator extends RSS091UserlandGenerator { return sourceElement; } - protected Element generateEnclosure(Enclosure enclosure) { - Element enclosureElement = new Element("enclosure",getFeedNamespace()); + protected Element generateEnclosure(final Enclosure enclosure) { + final Element enclosureElement = new Element("enclosure", getFeedNamespace()); if (enclosure.getUrl() != null) { enclosureElement.setAttribute("url", enclosure.getUrl()); } @@ -123,8 +130,8 @@ public class RSS092Generator extends RSS091UserlandGenerator { return enclosureElement; } - protected Element generateCategoryElement(Category category) { - Element categoryElement = new Element("category",getFeedNamespace()); + protected Element generateCategoryElement(final Category category) { + final Element categoryElement = new Element("category", getFeedNamespace()); if (category.getDomain() != null) { categoryElement.setAttribute("domain", category.getDomain()); } @@ -132,29 +139,33 @@ public class RSS092Generator extends RSS091UserlandGenerator { return categoryElement; } - - protected void checkChannelConstraints(Element eChannel) throws FeedException { - checkNotNullAndLength(eChannel,"title", 0, -1); - checkNotNullAndLength(eChannel,"description", 0, -1); - checkNotNullAndLength(eChannel,"link", 0, -1); + @Override + protected void checkChannelConstraints(final Element eChannel) throws FeedException { + checkNotNullAndLength(eChannel, "title", 0, -1); + checkNotNullAndLength(eChannel, "description", 0, -1); + checkNotNullAndLength(eChannel, "link", 0, -1); } - protected void checkImageConstraints(Element eImage) throws FeedException { - checkNotNullAndLength(eImage,"title", 0, -1); - checkNotNullAndLength(eImage,"url", 0, -1); + @Override + protected void checkImageConstraints(final Element eImage) throws FeedException { + checkNotNullAndLength(eImage, "title", 0, -1); + checkNotNullAndLength(eImage, "url", 0, -1); } - protected void checkTextInputConstraints(Element eTextInput) throws FeedException { - checkNotNullAndLength(eTextInput,"title", 0, -1); - checkNotNullAndLength(eTextInput,"description", 0, -1); - checkNotNullAndLength(eTextInput,"name", 0, -1); - checkNotNullAndLength(eTextInput,"link", 0, -1); + @Override + protected void checkTextInputConstraints(final Element eTextInput) throws FeedException { + checkNotNullAndLength(eTextInput, "title", 0, -1); + checkNotNullAndLength(eTextInput, "description", 0, -1); + checkNotNullAndLength(eTextInput, "name", 0, -1); + checkNotNullAndLength(eTextInput, "link", 0, -1); } - protected void checkItemsConstraints(Element parent) throws FeedException { + @Override + protected void checkItemsConstraints(final Element parent) throws FeedException { } - protected void checkItemConstraints(Element eItem) throws FeedException { + @Override + protected void checkItemConstraints(final Element eItem) throws FeedException { } } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS092Parser.java b/src/main/java/com/sun/syndication/io/impl/RSS092Parser.java index 50eb04c..b90acaf 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS092Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS092Parser.java @@ -16,6 +16,11 @@ */ package com.sun.syndication.io.impl; +import java.util.ArrayList; +import java.util.List; + +import org.jdom2.Element; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.rss.Category; import com.sun.syndication.feed.rss.Channel; @@ -24,10 +29,6 @@ import com.sun.syndication.feed.rss.Description; import com.sun.syndication.feed.rss.Enclosure; import com.sun.syndication.feed.rss.Item; import com.sun.syndication.feed.rss.Source; -import org.jdom2.Element; - -import java.util.ArrayList; -import java.util.List; /** */ @@ -37,39 +38,49 @@ public class RSS092Parser extends RSS091UserlandParser { this("rss_0.92"); } - protected RSS092Parser(String type) { + protected RSS092Parser(final String type) { super(type); } + @Override protected String getRSSVersion() { - return "0.92"; + return "0.92"; } - protected WireFeed parseChannel(Element rssRoot) { - Channel channel = (Channel) super.parseChannel(rssRoot); + @Override + protected WireFeed parseChannel(final Element rssRoot) { + final Channel channel = (Channel) super.parseChannel(rssRoot); - Element eChannel = rssRoot.getChild("channel",getRSSNamespace()); - Element eCloud = eChannel.getChild("cloud",getRSSNamespace()); - if (eCloud!=null) { - Cloud cloud = new Cloud(); - String att = eCloud.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); + final Element eCloud = eChannel.getChild("cloud", getRSSNamespace()); + if (eCloud != null) { + final Cloud cloud = new Cloud(); + String att = eCloud.getAttributeValue("domain");// getRSSNamespace()); + // DONT KNOW WHY + // DOESN'T WORK + if (att != null) { cloud.setDomain(att); } - att = eCloud.getAttributeValue("port");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + att = eCloud.getAttributeValue("port");// getRSSNamespace()); DONT + // KNOW WHY DOESN'T WORK + if (att != null) { cloud.setPort(Integer.parseInt(att.trim())); } - att = eCloud.getAttributeValue("path");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + att = eCloud.getAttributeValue("path");// getRSSNamespace()); DONT + // KNOW WHY DOESN'T WORK + if (att != null) { cloud.setPath(att); } - att = eCloud.getAttributeValue("registerProcedure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + att = eCloud.getAttributeValue("registerProcedure");// getRSSNamespace()); + // DONT KNOW WHY + // DOESN'T WORK + if (att != null) { cloud.setRegisterProcedure(att); } - att = eCloud.getAttributeValue("protocol");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + att = eCloud.getAttributeValue("protocol");// getRSSNamespace()); + // DONT KNOW WHY DOESN'T + // WORK + if (att != null) { cloud.setProtocol(att); } channel.setCloud(cloud); @@ -77,13 +88,16 @@ public class RSS092Parser extends RSS091UserlandParser { return channel; } - protected Item parseItem(Element rssRoot,Element eItem) { - Item item = super.parseItem(rssRoot,eItem); + @Override + protected Item parseItem(final Element rssRoot, final Element eItem) { + final Item item = super.parseItem(rssRoot, eItem); - Element e = eItem.getChild("source",getRSSNamespace()); - if (e!=null) { - Source source = new Source(); - String url = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK + Element e = eItem.getChild("source", getRSSNamespace()); + if (e != null) { + final Source source = new Source(); + final String url = e.getAttributeValue("url");// getRSSNamespace()); + // DONT + // KNOW WHY DOESN'T WORK source.setUrl(url); source.setValue(e.getText()); item.setSource(source); @@ -91,22 +105,30 @@ public class RSS092Parser extends RSS091UserlandParser { // 0.92 allows one enclosure occurrence, 0.93 multiple // just saving to write some code. - List eEnclosures = eItem.getChildren("enclosure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (eEnclosures.size()>0) { - List enclosures = new ArrayList(); - for (int i=0;i eEnclosures = eItem.getChildren("enclosure");// getRSSNamespace()); + // DONT KNOW + // WHY + // DOESN'T + // WORK + if (eEnclosures.size() > 0) { + final List enclosures = new ArrayList(); + for (int i = 0; i < eEnclosures.size(); i++) { + e = eEnclosures.get(i); - Enclosure enclosure = new Enclosure(); - String att = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + final Enclosure enclosure = new Enclosure(); + String att = e.getAttributeValue("url");// getRSSNamespace()); + // DONT KNOW WHY DOESN'T + // WORK + if (att != null) { enclosure.setUrl(att); } - att = e.getAttributeValue("length");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - enclosure.setLength(NumberParser.parseLong(att,0L)); + att = e.getAttributeValue("length");// getRSSNamespace()); DONT + // KNOW WHY DOESN'T WORK + enclosure.setLength(NumberParser.parseLong(att, 0L)); - att = e.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + att = e.getAttributeValue("type");// getRSSNamespace()); DONT + // KNOW WHY DOESN'T WORK + if (att != null) { enclosure.setType(att); } enclosures.add(enclosure); @@ -114,21 +136,25 @@ public class RSS092Parser extends RSS091UserlandParser { item.setEnclosures(enclosures); } - List eCats = eItem.getChildren("category");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK + final List eCats = eItem.getChildren("category");// getRSSNamespace()); + // DONT KNOW WHY + // DOESN'T WORK item.setCategories(parseCategories(eCats)); return item; } - protected List parseCategories(List eCats) { + protected List parseCategories(final List eCats) { List cats = null; - if (eCats.size()>0) { + if (eCats.size() > 0) { cats = new ArrayList(); - for (int i=0;i - * + * * @author Elaine Chien - * + * */ public class RSS093Generator extends RSS092Generator { public RSS093Generator() { - this("rss_0.93","0.93"); + this("rss_0.93", "0.93"); } - protected RSS093Generator(String feedType,String version) { - super(feedType,version); + protected RSS093Generator(final String feedType, final String version) { + super(feedType, version); } - protected void populateItem(Item item, Element eItem, int index) { - super.populateItem(item,eItem, index); + @Override + protected void populateItem(final Item item, final Element eItem, final int index) { + super.populateItem(item, eItem, index); - Date pubDate = item.getPubDate(); + final Date pubDate = item.getPubDate(); if (pubDate != null) { eItem.addContent(generateSimpleElement("pubDate", DateParser.formatRFC822(pubDate))); } - Date expirationDate = item.getExpirationDate(); + final Date expirationDate = item.getExpirationDate(); if (expirationDate != null) { eItem.addContent(generateSimpleElement("expirationDate", DateParser.formatRFC822(expirationDate))); } } // Another one to thanks DW for - protected int getNumberOfEnclosures(List enclosures) { + @Override + protected int getNumberOfEnclosures(final List enclosures) { return enclosures.size(); } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS093Parser.java b/src/main/java/com/sun/syndication/io/impl/RSS093Parser.java index f5aaaee..18053bf 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS093Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS093Parser.java @@ -16,9 +16,10 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.rss.Item; import org.jdom2.Element; +import com.sun.syndication.feed.rss.Item; + /** */ public class RSS093Parser extends RSS092Parser { @@ -27,28 +28,30 @@ public class RSS093Parser extends RSS092Parser { this("rss_0.93"); } - protected RSS093Parser(String type) { + protected RSS093Parser(final String type) { super(type); } + @Override protected String getRSSVersion() { - return "0.93"; + return "0.93"; } - protected Item parseItem(Element rssRoot,Element eItem) { - Item item = super.parseItem(rssRoot,eItem); - Element e = eItem.getChild("pubDate",getRSSNamespace()); - if (e!=null) { + @Override + protected Item parseItem(final Element rssRoot, final Element eItem) { + final Item item = super.parseItem(rssRoot, eItem); + Element e = eItem.getChild("pubDate", getRSSNamespace()); + if (e != null) { item.setPubDate(DateParser.parseDate(e.getText())); } - e = eItem.getChild("expirationDate",getRSSNamespace()); - if (e!=null) { + e = eItem.getChild("expirationDate", getRSSNamespace()); + if (e != null) { item.setExpirationDate(DateParser.parseDate(e.getText())); } - e = eItem.getChild("description",getRSSNamespace()); - if (e!=null) { - String type = e.getAttributeValue("type"); - if (type!=null) { + e = eItem.getChild("description", getRSSNamespace()); + if (e != null) { + final String type = e.getAttributeValue("type"); + if (type != null) { item.getDescription().setType(type); } } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS094Generator.java b/src/main/java/com/sun/syndication/io/impl/RSS094Generator.java index 5009beb..3bf5041 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS094Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS094Generator.java @@ -16,38 +16,40 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.rss.Description; -import com.sun.syndication.feed.rss.Item; import org.jdom2.Attribute; import org.jdom2.Element; +import com.sun.syndication.feed.rss.Description; +import com.sun.syndication.feed.rss.Item; + /** * Feed Generator for RSS 0.94 *

- * + * * @author Elaine Chien - * + * */ public class RSS094Generator extends RSS093Generator { public RSS094Generator() { - this("rss_0.94","0.94"); + this("rss_0.94", "0.94"); } - protected RSS094Generator(String feedType,String version) { - super(feedType,version); + protected RSS094Generator(final String feedType, final String version) { + super(feedType, version); } - protected void populateItem(Item item, Element eItem, int index) { - super.populateItem(item,eItem, index); + @Override + protected void populateItem(final Item item, final Element eItem, final int index) { + super.populateItem(item, eItem, index); - Description description = item.getDescription(); - if (description!=null && description.getType()!=null) { - Element eDescription = eItem.getChild("description",getFeedNamespace()); - eDescription.setAttribute(new Attribute("type",description.getType())); + final Description description = item.getDescription(); + if (description != null && description.getType() != null) { + final Element eDescription = eItem.getChild("description", getFeedNamespace()); + eDescription.setAttribute(new Attribute("type", description.getType())); } - eItem.removeChild("expirationDate",getFeedNamespace()); + eItem.removeChild("expirationDate", getFeedNamespace()); } } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS094Parser.java b/src/main/java/com/sun/syndication/io/impl/RSS094Parser.java index 7479e36..3a68c63 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS094Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS094Parser.java @@ -16,14 +16,15 @@ */ package com.sun.syndication.io.impl; +import java.util.List; + +import org.jdom2.Element; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.rss.Channel; import com.sun.syndication.feed.rss.Description; import com.sun.syndication.feed.rss.Guid; import com.sun.syndication.feed.rss.Item; -import org.jdom2.Element; - -import java.util.List; /** */ @@ -33,28 +34,30 @@ public class RSS094Parser extends RSS093Parser { this("rss_0.94"); } - protected RSS094Parser(String type) { + protected RSS094Parser(final String type) { super(type); } + @Override protected String getRSSVersion() { - return "0.94"; + return "0.94"; } - protected WireFeed parseChannel(Element rssRoot) { - Channel channel = (Channel) super.parseChannel(rssRoot); - Element eChannel = rssRoot.getChild("channel",getRSSNamespace()); + @Override + protected WireFeed parseChannel(final Element rssRoot) { + final Channel channel = (Channel) super.parseChannel(rssRoot); + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); - List eCats = eChannel.getChildren("category",getRSSNamespace()); + final List eCats = eChannel.getChildren("category", getRSSNamespace()); channel.setCategories(parseCategories(eCats)); - Element eTtl = eChannel.getChild("ttl",getRSSNamespace()); - if (eTtl!=null && eTtl.getText() != null ) { - Integer ttlValue = null; - try{ - ttlValue = new Integer(eTtl.getText()); - } catch(NumberFormatException nfe ){ - ; //let it go by + final Element eTtl = eChannel.getChild("ttl", getRSSNamespace()); + if (eTtl != null && eTtl.getText() != null) { + Integer ttlValue = null; + try { + ttlValue = new Integer(eTtl.getText()); + } catch (final NumberFormatException nfe) { + ; // let it go by } if (ttlValue != null) { channel.setTtl(ttlValue.intValue()); @@ -64,38 +67,43 @@ public class RSS094Parser extends RSS093Parser { return channel; } - public Item parseItem(Element rssRoot,Element eItem) { - Item item = super.parseItem(rssRoot,eItem); + @Override + public Item parseItem(final Element rssRoot, final Element eItem) { + final Item item = super.parseItem(rssRoot, eItem); item.setExpirationDate(null); - Element e = eItem.getChild("author",getRSSNamespace()); - if (e!=null) { + Element e = eItem.getChild("author", getRSSNamespace()); + if (e != null) { item.setAuthor(e.getText()); } - e = eItem.getChild("guid",getRSSNamespace()); - if (e!=null) { - Guid guid = new Guid(); - String att = e.getAttributeValue("isPermaLink");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att!=null) { + e = eItem.getChild("guid", getRSSNamespace()); + if (e != null) { + final Guid guid = new Guid(); + final String att = e.getAttributeValue("isPermaLink");// getRSSNamespace()); + // DONT KNOW WHY + // DOESN'T WORK + if (att != null) { guid.setPermaLink(att.equalsIgnoreCase("true")); } guid.setValue(e.getText()); item.setGuid(guid); } - e = eItem.getChild("comments",getRSSNamespace()); - if (e!=null) { + e = eItem.getChild("comments", getRSSNamespace()); + if (e != null) { item.setComments(e.getText()); } return item; } - protected Description parseItemDescription(Element rssRoot,Element eDesc) { - Description desc = super.parseItemDescription(rssRoot,eDesc); - String att = eDesc.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK - if (att==null) { + @Override + protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { + final Description desc = super.parseItemDescription(rssRoot, eDesc); + String att = eDesc.getAttributeValue("type");// getRSSNamespace()); DONT + // KNOW WHY DOESN'T WORK + if (att == null) { att = "text/html"; } desc.setType(att); diff --git a/src/main/java/com/sun/syndication/io/impl/RSS10Generator.java b/src/main/java/com/sun/syndication/io/impl/RSS10Generator.java index 0532f7e..2d541a0 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS10Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS10Generator.java @@ -16,55 +16,58 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.rss.Description; -import com.sun.syndication.feed.rss.Item; -import com.sun.syndication.feed.rss.Channel; -import com.sun.syndication.io.FeedException; +import java.util.List; + import org.jdom2.Element; import org.jdom2.Namespace; -import java.util.List; +import com.sun.syndication.feed.rss.Channel; +import com.sun.syndication.feed.rss.Description; +import com.sun.syndication.feed.rss.Item; +import com.sun.syndication.io.FeedException; /** * Feed Generator for RSS 1.0 *

- * + * * @author Elaine Chien - * + * */ public class RSS10Generator extends RSS090Generator { - + private static final String RSS_URI = "http://purl.org/rss/1.0/"; private static final Namespace RSS_NS = Namespace.getNamespace(RSS_URI); - + public RSS10Generator() { super("rss_1.0"); } - protected RSS10Generator(String feedType) { + protected RSS10Generator(final String feedType) { super(feedType); } + @Override protected Namespace getFeedNamespace() { return RSS_NS; } - protected void populateChannel(Channel channel,Element eChannel) { - super.populateChannel(channel,eChannel); + @Override + protected void populateChannel(final Channel channel, final Element eChannel) { + super.populateChannel(channel, eChannel); if (channel.getUri() != null) { eChannel.setAttribute("about", channel.getUri(), getRDFNamespace()); } - List items = channel.getItems(); - if (items.size()>0) { - Element eItems = new Element("items",getFeedNamespace()); - Element eSeq = new Element("Seq",getRDFNamespace()); - for (int i=0;i items = channel.getItems(); + if (items.size() > 0) { + final Element eItems = new Element("items", getFeedNamespace()); + final Element eSeq = new Element("Seq", getRDFNamespace()); + for (int i = 0; i < items.size(); i++) { + final Item item = items.get(i); + final Element eLi = new Element("li", getRDFNamespace()); + final String uri = item.getUri(); + if (uri != null) { + eLi.setAttribute("resource", uri, getRDFNamespace()); } eSeq.addContent(eLi); } @@ -72,55 +75,60 @@ public class RSS10Generator extends RSS090Generator { eChannel.addContent(eItems); } } - - protected void populateItem(Item item, Element eItem, int index) { - super.populateItem(item,eItem, index); - String link = item.getLink(); - String uri = item.getUri(); - + + @Override + protected void populateItem(final Item item, final Element eItem, final int index) { + super.populateItem(item, eItem, index); + final String link = item.getLink(); + final String uri = item.getUri(); + if (uri != null) { eItem.setAttribute("about", uri, getRDFNamespace()); } else if (link != null) { eItem.setAttribute("about", link, getRDFNamespace()); } - - Description description = item.getDescription(); - if (description!=null) { + + final Description description = item.getDescription(); + if (description != null) { eItem.addContent(generateSimpleElement("description", description.getValue())); } if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) { - Element elem = new Element("encoded", getContentNamespace()); + final Element elem = new Element("encoded", getContentNamespace()); elem.addContent(item.getContent().getValue()); eItem.addContent(elem); } } - protected void checkChannelConstraints(Element eChannel) throws FeedException { - checkNotNullAndLength(eChannel,"title", 0, -1); - checkNotNullAndLength(eChannel,"description", 0, -1); - checkNotNullAndLength(eChannel,"link", 0, -1); + @Override + protected void checkChannelConstraints(final Element eChannel) throws FeedException { + checkNotNullAndLength(eChannel, "title", 0, -1); + checkNotNullAndLength(eChannel, "description", 0, -1); + checkNotNullAndLength(eChannel, "link", 0, -1); } - protected void checkImageConstraints(Element eImage) throws FeedException { - checkNotNullAndLength(eImage,"title", 0, -1); - checkNotNullAndLength(eImage,"url", 0, -1); - checkNotNullAndLength(eImage,"link", 0, -1); + @Override + protected void checkImageConstraints(final Element eImage) throws FeedException { + checkNotNullAndLength(eImage, "title", 0, -1); + checkNotNullAndLength(eImage, "url", 0, -1); + checkNotNullAndLength(eImage, "link", 0, -1); } - protected void checkTextInputConstraints(Element eTextInput) throws FeedException { - checkNotNullAndLength(eTextInput,"title", 0, -1); - checkNotNullAndLength(eTextInput,"description", 0, -1); - checkNotNullAndLength(eTextInput,"name", 0, -1); - checkNotNullAndLength(eTextInput,"link", 0, -1); + @Override + protected void checkTextInputConstraints(final Element eTextInput) throws FeedException { + checkNotNullAndLength(eTextInput, "title", 0, -1); + checkNotNullAndLength(eTextInput, "description", 0, -1); + checkNotNullAndLength(eTextInput, "name", 0, -1); + checkNotNullAndLength(eTextInput, "link", 0, -1); } - protected void checkItemsConstraints(Element parent) throws FeedException { + @Override + protected void checkItemsConstraints(final Element parent) throws FeedException { } - protected void checkItemConstraints(Element eItem) throws FeedException { - checkNotNullAndLength(eItem,"title", 0, -1); - checkNotNullAndLength(eItem,"link", 0, -1); + @Override + protected void checkItemConstraints(final Element eItem) throws FeedException { + checkNotNullAndLength(eItem, "title", 0, -1); + checkNotNullAndLength(eItem, "link", 0, -1); } } - diff --git a/src/main/java/com/sun/syndication/io/impl/RSS10Parser.java b/src/main/java/com/sun/syndication/io/impl/RSS10Parser.java index e992a0a..6b165cb 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS10Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS10Parser.java @@ -16,16 +16,17 @@ */ package com.sun.syndication.io.impl; +import java.util.List; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; + import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.rss.Channel; import com.sun.syndication.feed.rss.Content; import com.sun.syndication.feed.rss.Description; import com.sun.syndication.feed.rss.Item; -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.Namespace; - -import java.util.List; /** */ @@ -38,34 +39,37 @@ public class RSS10Parser extends RSS090Parser { this("rss_1.0", RSS_NS); } - protected RSS10Parser(String type, Namespace ns) { + protected RSS10Parser(final String type, final Namespace ns) { super(type, ns); } /** - * Indicates if a JDom document is an RSS instance that can be parsed with the parser. + * Indicates if a JDom document is an RSS instance that can be parsed with + * the parser. *

- * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and - * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element. - * - * @param document document to check if it can be parsed with this parser implementation. + * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and RSS + * ("http://purl.org/rss/1.0/") namespaces being defined in the root + * element. + * + * @param document document to check if it can be parsed with this parser + * implementation. * @return true if the document is RSS1., false otherwise. */ - public boolean isMyType(Document document) { + @Override + public boolean isMyType(final Document document) { boolean ok = false; - Element rssRoot = document.getRootElement(); - Namespace defaultNS = rssRoot.getNamespace(); - List additionalNSs = rssRoot.getAdditionalNamespaces(); + final Element rssRoot = document.getRootElement(); + final Namespace defaultNS = rssRoot.getNamespace(); + final List additionalNSs = rssRoot.getAdditionalNamespaces(); - ok = defaultNS!=null && defaultNS.equals(getRDFNamespace()); + ok = defaultNS != null && defaultNS.equals(getRDFNamespace()); if (ok) { - if (additionalNSs==null) { + if (additionalNSs == null) { ok = false; - } - else { + } else { ok = false; - for (int i=0;!ok && i - * + * * @return returns "http://purl.org/rss/1.0/". */ + @Override protected Namespace getRSSNamespace() { return Namespace.getNamespace(RSS_URI); } @@ -86,28 +91,31 @@ public class RSS10Parser extends RSS090Parser { /** * Parses an item element of an RSS document looking for item information. *

- * It first invokes super.parseItem and then parses and injects the description property if present. + * It first invokes super.parseItem and then parses and injects the + * description property if present. *

- * - * @param rssRoot the root element of the RSS document in case it's needed for context. + * + * @param rssRoot the root element of the RSS document in case it's needed + * for context. * @param eItem the item element to parse. * @return the parsed RSSItem bean. */ - protected Item parseItem(Element rssRoot,Element eItem) { - Item item = super.parseItem(rssRoot,eItem); - Element e = eItem.getChild("description", getRSSNamespace()); - if (e!=null) { - item.setDescription(parseItemDescription(rssRoot,e)); + @Override + protected Item parseItem(final Element rssRoot, final Element eItem) { + final Item item = super.parseItem(rssRoot, eItem); + final Element e = eItem.getChild("description", getRSSNamespace()); + if (e != null) { + item.setDescription(parseItemDescription(rssRoot, e)); } - Element ce = eItem.getChild("encoded", getContentNamespace()); + final Element ce = eItem.getChild("encoded", getContentNamespace()); if (ce != null) { - Content content = new Content(); + final Content content = new Content(); content.setType(Content.HTML); content.setValue(ce.getText()); item.setContent(content); } - String uri = eItem.getAttributeValue("about", getRDFNamespace()); + final String uri = eItem.getAttributeValue("about", getRDFNamespace()); if (uri != null) { item.setUri(uri); } @@ -115,11 +123,12 @@ public class RSS10Parser extends RSS090Parser { return item; } - protected WireFeed parseChannel(Element rssRoot) { - Channel channel = (Channel) super.parseChannel(rssRoot); + @Override + protected WireFeed parseChannel(final Element rssRoot) { + final Channel channel = (Channel) super.parseChannel(rssRoot); - Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); - String uri = eChannel.getAttributeValue("about", getRDFNamespace()); + final Element eChannel = rssRoot.getChild("channel", getRSSNamespace()); + final String uri = eChannel.getAttributeValue("about", getRDFNamespace()); if (uri != null) { channel.setUri(uri); } @@ -127,8 +136,8 @@ public class RSS10Parser extends RSS090Parser { return channel; } - protected Description parseItemDescription(Element rssRoot,Element eDesc) { - Description desc = new Description(); + protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { + final Description desc = new Description(); desc.setType("text/plain"); desc.setValue(eDesc.getText()); return desc; diff --git a/src/main/java/com/sun/syndication/io/impl/RSS20Generator.java b/src/main/java/com/sun/syndication/io/impl/RSS20Generator.java index 5d48fbd..fff29ed 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS20Generator.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS20Generator.java @@ -16,72 +16,76 @@ */ package com.sun.syndication.io.impl; +import java.util.List; + +import org.jdom2.Element; + import com.sun.syndication.feed.rss.Category; import com.sun.syndication.feed.rss.Channel; import com.sun.syndication.feed.rss.Guid; import com.sun.syndication.feed.rss.Item; -import org.jdom2.Element; - -import java.util.List; - /** * Feed Generator for RSS 2.0 *

- * + * * @author Elaine Chien - * + * */ public class RSS20Generator extends RSS094Generator { public RSS20Generator() { - this("rss_2.0","2.0"); + this("rss_2.0", "2.0"); } - protected RSS20Generator(String feedType,String version) { - super(feedType,version); + protected RSS20Generator(final String feedType, final String version) { + super(feedType, version); } - protected void populateChannel(Channel channel,Element eChannel) { - super.populateChannel(channel,eChannel); + @Override + protected void populateChannel(final Channel channel, final Element eChannel) { + super.populateChannel(channel, eChannel); - String generator = channel.getGenerator(); + final String generator = channel.getGenerator(); if (generator != null) { eChannel.addContent(generateSimpleElement("generator", generator)); } - int ttl = channel.getTtl(); - if (ttl>-1) { + final int ttl = channel.getTtl(); + if (ttl > -1) { eChannel.addContent(generateSimpleElement("ttl", String.valueOf(ttl))); } - List categories = channel.getCategories(); - for(int i = 0; i < categories.size(); i++) { - eChannel.addContent(generateCategoryElement((Category)categories.get(i))); + final List categories = channel.getCategories(); + for (int i = 0; i < categories.size(); i++) { + eChannel.addContent(generateCategoryElement(categories.get(i))); } } - public void populateItem(Item item, Element eItem, int index) { - super.populateItem(item,eItem, index); + @Override + public void populateItem(final Item item, final Element eItem, final int index) { + super.populateItem(item, eItem, index); - Element eDescription = eItem.getChild("description",getFeedNamespace()); - if (eDescription != null) eDescription.removeAttribute("type"); + final Element eDescription = eItem.getChild("description", getFeedNamespace()); + if (eDescription != null) { + eDescription.removeAttribute("type"); + } - String author = item.getAuthor(); + final String author = item.getAuthor(); if (author != null) { eItem.addContent(generateSimpleElement("author", author)); } - String comments = item.getComments(); + final String comments = item.getComments(); if (comments != null) { eItem.addContent(generateSimpleElement("comments", comments)); } - Guid guid = item.getGuid(); + final Guid guid = item.getGuid(); if (guid != null) { - Element eGuid = generateSimpleElement("guid",guid.getValue()); + final Element eGuid = generateSimpleElement("guid", guid.getValue()); if (!guid.isPermaLink()) { eGuid.setAttribute("isPermaLink", "false"); } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS20Parser.java b/src/main/java/com/sun/syndication/io/impl/RSS20Parser.java index e3e6e66..9051c13 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS20Parser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS20Parser.java @@ -16,11 +16,12 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.rss.Description; import org.jdom2.Attribute; import org.jdom2.Document; import org.jdom2.Element; +import com.sun.syndication.feed.rss.Description; + /** */ public class RSS20Parser extends RSS094Parser { @@ -29,33 +30,38 @@ public class RSS20Parser extends RSS094Parser { this("rss_2.0"); } - protected RSS20Parser(String type) { + protected RSS20Parser(final String type) { super(type); } + @Override protected String getRSSVersion() { - return "2.0"; + return "2.0"; } - protected boolean isHourFormat24(Element rssRoot) { + @Override + protected boolean isHourFormat24(final Element rssRoot) { return false; } - protected Description parseItemDescription(Element rssRoot,Element eDesc) { - Description desc = super.parseItemDescription(rssRoot,eDesc); - desc.setType("text/html"); // change as per https://rome.dev.java.net/issues/show_bug.cgi?id=26 + @Override + protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { + final Description desc = super.parseItemDescription(rssRoot, eDesc); + desc.setType("text/html"); // change as per + // https://rome.dev.java.net/issues/show_bug.cgi?id=26 return desc; } - - public boolean isMyType(Document document) { + + @Override + public boolean isMyType(final Document document) { boolean ok; - Element rssRoot = document.getRootElement(); + final Element rssRoot = document.getRootElement(); ok = rssRoot.getName().equals("rss"); if (ok) { ok = false; - Attribute version = rssRoot.getAttribute("version"); - if (version!=null) { - // At this point, as far ROME is concerned RSS 2.0, 2.00 and + final Attribute version = rssRoot.getAttribute("version"); + if (version != null) { + // At this point, as far ROME is concerned RSS 2.0, 2.00 and // 2.0.X are all the same, so let's use startsWith for leniency. ok = version.getValue().startsWith(getRSSVersion()); } diff --git a/src/main/java/com/sun/syndication/io/impl/RSS20wNSParser.java b/src/main/java/com/sun/syndication/io/impl/RSS20wNSParser.java index d981f0f..8ffa75e 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS20wNSParser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS20wNSParser.java @@ -19,19 +19,20 @@ package com.sun.syndication.io.impl; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.Namespace; -import com.sun.syndication.feed.WireFeed; +import com.sun.syndication.feed.WireFeed; /** * To address issue with certain feeds (brought up by Charles Miller): - * + * * "During the debacle that was the rollout of RSS2.0, this namespace was tried, * and even appeared in Dave Winer's Scripting News feed for a while. It was * then withdrawn, but the wonderful thing about standards is the moment you * roll one out, even if it's marked as unfinished and subject to change, * someone will end up stuck with it forever." - * - * Note that there is not counter part on the generator, we only generate the final RSS2 + * + * Note that there is not counter part on the generator, we only generate the + * final RSS2 * */ public class RSS20wNSParser extends RSS20Parser { @@ -41,31 +42,34 @@ public class RSS20wNSParser extends RSS20Parser { this("rss_2.0wNS"); } - protected RSS20wNSParser(String type) { + protected RSS20wNSParser(final String type) { super(type); } - public boolean isMyType(Document document) { - Element rssRoot = document.getRootElement(); - Namespace defaultNS = rssRoot.getNamespace(); - boolean ok = defaultNS!=null && defaultNS.equals(getRSSNamespace()); + @Override + public boolean isMyType(final Document document) { + final Element rssRoot = document.getRootElement(); + final Namespace defaultNS = rssRoot.getNamespace(); + boolean ok = defaultNS != null && defaultNS.equals(getRSSNamespace()); if (ok) { ok = super.isMyType(document); } return ok; } + @Override protected Namespace getRSSNamespace() { return Namespace.getNamespace(RSS20_URI); } /** - * After we parse the feed we put "rss_2.0" in it (so converters and generators work) - * this parser is a phantom. - * + * After we parse the feed we put "rss_2.0" in it (so converters and + * generators work) this parser is a phantom. + * */ - protected WireFeed parseChannel(Element rssRoot) { - WireFeed wFeed = super.parseChannel(rssRoot); + @Override + protected WireFeed parseChannel(final Element rssRoot) { + final WireFeed wFeed = super.parseChannel(rssRoot); wFeed.setFeedType("rss_2.0"); return wFeed; } diff --git a/src/main/java/com/sun/syndication/io/impl/SyModuleGenerator.java b/src/main/java/com/sun/syndication/io/impl/SyModuleGenerator.java index 42abeee..88aeed7 100644 --- a/src/main/java/com/sun/syndication/io/impl/SyModuleGenerator.java +++ b/src/main/java/com/sun/syndication/io/impl/SyModuleGenerator.java @@ -16,70 +16,77 @@ */ package com.sun.syndication.io.impl; -import com.sun.syndication.feed.module.Module; -import com.sun.syndication.feed.module.SyModule; -import com.sun.syndication.io.ModuleGenerator; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + import org.jdom2.Element; import org.jdom2.Namespace; -import java.util.Set; -import java.util.HashSet; -import java.util.Collections; +import com.sun.syndication.feed.module.Module; +import com.sun.syndication.feed.module.SyModule; +import com.sun.syndication.io.ModuleGenerator; /** * Feed Generator for SY ModuleImpl *

- * + * * @author Elaine Chien - * + * */ public class SyModuleGenerator implements ModuleGenerator { - private static final String SY_URI = "http://purl.org/rss/1.0/modules/syndication/"; - private static final Namespace SY_NS = Namespace.getNamespace("sy", SY_URI); + private static final String SY_URI = "http://purl.org/rss/1.0/modules/syndication/"; + private static final Namespace SY_NS = Namespace.getNamespace("sy", SY_URI); private static final Set NAMESPACES; static { - Set nss = new HashSet(); + final Set nss = new HashSet(); nss.add(SY_NS); NAMESPACES = Collections.unmodifiableSet(nss); } + @Override public String getNamespaceUri() { return SY_URI; } /** - * Returns a set with all the URIs (JDOM Namespace elements) this module generator uses. + * Returns a set with all the URIs (JDOM Namespace elements) this module + * generator uses. *

- * It is used by the the feed generators to add their namespace definition in - * the root element of the generated document (forward-missing of Java 5.0 Generics). + * It is used by the the feed generators to add their namespace definition + * in the root element of the generated document (forward-missing of Java + * 5.0 Generics). *

- * - * @return a set with all the URIs (JDOM Namespace elements) this module generator uses. + * + * @return a set with all the URIs (JDOM Namespace elements) this module + * generator uses. */ + @Override public Set getNamespaces() { return NAMESPACES; } - public void generate(Module module, Element element) { + @Override + public void generate(final Module module, final Element element) { - SyModule syModule = (SyModule)module; + final SyModule syModule = (SyModule) module; if (syModule.getUpdatePeriod() != null) { - Element updatePeriodElement = new Element("updatePeriod", SY_NS); + final Element updatePeriodElement = new Element("updatePeriod", SY_NS); updatePeriodElement.addContent(syModule.getUpdatePeriod()); element.addContent(updatePeriodElement); } - Element updateFrequencyElement = new Element("updateFrequency", SY_NS); + final Element updateFrequencyElement = new Element("updateFrequency", SY_NS); updateFrequencyElement.addContent(String.valueOf(syModule.getUpdateFrequency())); element.addContent(updateFrequencyElement); if (syModule.getUpdateBase() != null) { - Element updateBaseElement = new Element("updateBase", SY_NS); + final Element updateBaseElement = new Element("updateBase", SY_NS); updateBaseElement.addContent(DateParser.formatW3CDateTime(syModule.getUpdateBase())); element.addContent(updateBaseElement); } diff --git a/src/main/java/com/sun/syndication/io/impl/SyModuleParser.java b/src/main/java/com/sun/syndication/io/impl/SyModuleParser.java index ac1961a..012b5b0 100644 --- a/src/main/java/com/sun/syndication/io/impl/SyModuleParser.java +++ b/src/main/java/com/sun/syndication/io/impl/SyModuleParser.java @@ -16,16 +16,18 @@ */ package com.sun.syndication.io.impl; +import org.jdom2.Element; +import org.jdom2.Namespace; + import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.module.SyModule; import com.sun.syndication.feed.module.SyModuleImpl; import com.sun.syndication.io.ModuleParser; -import org.jdom2.Element; -import org.jdom2.Namespace; /** */ public class SyModuleParser implements ModuleParser { + @Override public String getNamespaceUri() { return SyModule.URI; } @@ -34,26 +36,27 @@ public class SyModuleParser implements ModuleParser { return Namespace.getNamespace(SyModule.URI); } - public Module parse(Element syndRoot) { + @Override + public Module parse(final Element syndRoot) { boolean foundSomething = false; - SyModule sm = new SyModuleImpl(); + final SyModule sm = new SyModuleImpl(); - Element e = syndRoot.getChild("updatePeriod",getDCNamespace()); - if (e!=null) { + Element e = syndRoot.getChild("updatePeriod", getDCNamespace()); + if (e != null) { foundSomething = true; sm.setUpdatePeriod(e.getText()); } - e = syndRoot.getChild("updateFrequency",getDCNamespace()); - if (e!=null) { + e = syndRoot.getChild("updateFrequency", getDCNamespace()); + if (e != null) { foundSomething = true; sm.setUpdateFrequency(Integer.parseInt(e.getText().trim())); } - e = syndRoot.getChild("updateBase",getDCNamespace()); - if (e!=null) { + e = syndRoot.getChild("updateBase", getDCNamespace()); + if (e != null) { foundSomething = true; sm.setUpdateBase(DateParser.parseDate(e.getText())); } - return (foundSomething) ? sm : null; + return foundSomething ? sm : null; } } diff --git a/src/main/java/com/sun/syndication/io/impl/XmlFixerReader.java b/src/main/java/com/sun/syndication/io/impl/XmlFixerReader.java index b5a2d12..89f1e9f 100644 --- a/src/main/java/com/sun/syndication/io/impl/XmlFixerReader.java +++ b/src/main/java/com/sun/syndication/io/impl/XmlFixerReader.java @@ -20,8 +20,8 @@ import java.io.IOException; import java.io.Reader; import java.util.HashMap; import java.util.Map; -import java.util.regex.Pattern; import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author Alejandro Abdelnur @@ -30,15 +30,15 @@ public class XmlFixerReader extends Reader { protected Reader in; - public XmlFixerReader(Reader in) { + public XmlFixerReader(final Reader in) { super(in); this.in = in; - _buffer = new StringBuffer(); - _state = 0; + this._buffer = new StringBuffer(); + this._state = 0; } private boolean trimmed; - private StringBuffer _buffer; + private final StringBuffer _buffer; private int _bufferPos; private int _state = 0; @@ -50,145 +50,122 @@ public class XmlFixerReader extends Reader { do { switch (state) { case 0: - c = in.read(); - if (c==-1) { + c = this.in.read(); + if (c == -1) { loop = false; hasContent = false; - } - else - if (c==' ' || c=='\n' || c=='\r' || c=='\t') { + } else if (c == ' ' || c == '\n' || c == '\r' || c == '\t') { loop = true; - } - else - if (c=='<') { + } else if (c == '<') { state = 1; - _buffer.setLength(0); - _bufferPos = 0; - _buffer.append((char)c); + this._buffer.setLength(0); + this._bufferPos = 0; + this._buffer.append((char) c); loop = true; - } - else { - _buffer.setLength(0); - _bufferPos = 0; - _buffer.append((char)c); + } else { + this._buffer.setLength(0); + this._bufferPos = 0; + this._buffer.append((char) c); loop = false; hasContent = true; - _state = 3; + this._state = 3; } break; case 1: - c = in.read(); - if (c==-1) { + c = this.in.read(); + if (c == -1) { loop = false; hasContent = true; - _state = 3; - } - else - if (c!='!') { - _buffer.append((char)c); - _state = 3; + this._state = 3; + } else if (c != '!') { + this._buffer.append((char) c); + this._state = 3; loop = false; hasContent = true; - _state = 3; - } - else { - _buffer.append((char)c); + this._state = 3; + } else { + this._buffer.append((char) c); state = 2; loop = true; } break; case 2: - c = in.read(); - if (c==-1) { + c = this.in.read(); + if (c == -1) { loop = false; hasContent = true; - _state = 3; - } - else - if (c=='-') { - _buffer.append((char)c); + this._state = 3; + } else if (c == '-') { + this._buffer.append((char) c); state = 3; loop = true; - } - else { - _buffer.append((char)c); + } else { + this._buffer.append((char) c); loop = false; hasContent = true; - _state = 3; + this._state = 3; } break; case 3: - c = in.read(); - if (c==-1) { + c = this.in.read(); + if (c == -1) { loop = false; hasContent = true; - _state = 3; - } - else - if (c=='-') { - _buffer.append((char)c); + this._state = 3; + } else if (c == '-') { + this._buffer.append((char) c); state = 4; loop = true; - } - else { - _buffer.append((char)c); + } else { + this._buffer.append((char) c); loop = false; hasContent = true; - _state = 3; + this._state = 3; } break; case 4: - c = in.read(); - if (c==-1) { + c = this.in.read(); + if (c == -1) { loop = false; hasContent = true; - _state = 3; - } - else - if (c!='-') { - _buffer.append((char)c); + this._state = 3; + } else if (c != '-') { + this._buffer.append((char) c); loop = true; - } - else { - _buffer.append((char)c); + } else { + this._buffer.append((char) c); state = 5; loop = true; } break; case 5: - c = in.read(); - if (c==-1) { + c = this.in.read(); + if (c == -1) { loop = false; hasContent = true; - _state = 3; - } - else - if (c!='-') { - _buffer.append((char)c); + this._state = 3; + } else if (c != '-') { + this._buffer.append((char) c); loop = true; state = 4; - } - else { - _buffer.append((char)c); + } else { + this._buffer.append((char) c); state = 6; loop = true; } break; case 6: - c = in.read(); - if (c==-1) { + c = this.in.read(); + if (c == -1) { loop = false; hasContent = true; - _state = 3; - } - else - if (c!='>') { - _buffer.append((char)c); + this._state = 3; + } else if (c != '>') { + this._buffer.append((char) c); loop = true; state = 4; - } - else { - _buffer.setLength(0); + } else { + this._buffer.setLength(0); state = 0; loop = true; } @@ -200,143 +177,142 @@ public class XmlFixerReader extends Reader { return hasContent; } + @Override public int read() throws IOException { boolean loop; - if (!trimmed) { // trims XML stream - trimmed = true; + if (!this.trimmed) { // trims XML stream + this.trimmed = true; if (!trimStream()) { return -1; } } int c; do { // converts literal entities to coded entities - switch (_state) { + switch (this._state) { case 0: // reading chars from stream - c = in.read(); - if (c>-1) { - if (c=='&') { - _state = 1; - _buffer.setLength(0); - _bufferPos = 0; - _buffer.append((char)c); - _state = 1; + c = this.in.read(); + if (c > -1) { + if (c == '&') { + this._state = 1; + this._buffer.setLength(0); + this._bufferPos = 0; + this._buffer.append((char) c); + this._state = 1; loop = true; - } - else { + } else { loop = false; } - } - else { + } else { loop = false; } break; case 1: // reading entity from stream - c = in.read(); - if (c>-1) { - if (c==';') { - _buffer.append((char)c); - _state = 2; + c = this.in.read(); + if (c > -1) { + if (c == ';') { + this._buffer.append((char) c); + this._state = 2; loop = true; - } - else - if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c=='#') || (c>='0' && c<='9')) { - _buffer.append((char)c); + } else if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '#' || c >= '0' && c <= '9') { + this._buffer.append((char) c); loop = true; - } - else { + } else { // no ';' to match the '&' lets just make the '&' // a legal xml character entity '&' - _buffer.insert(1, "amp;"); - _buffer.append((char)c); - _state = 3; + this._buffer.insert(1, "amp;"); + this._buffer.append((char) c); + this._state = 3; loop = true; } - } - else { + } else { // no ';' to match the '&' lets just make the '&' // a legal xml character entity '&' - _buffer.insert(1, "amp;"); - _state = 3; + this._buffer.insert(1, "amp;"); + this._state = 3; loop = true; } break; case 2: // replacing entity c = 0; - String literalEntity = _buffer.toString(); - String codedEntity = (String) CODED_ENTITIES.get(literalEntity); - if (codedEntity!=null) { - _buffer.setLength(0); - _buffer.append(codedEntity); + final String literalEntity = this._buffer.toString(); + final String codedEntity = CODED_ENTITIES.get(literalEntity); + if (codedEntity != null) { + this._buffer.setLength(0); + this._buffer.append(codedEntity); } // else we leave what was in the stream - _state = 3; + this._state = 3; loop = true; break; case 3: // consuming buffer - if (_bufferPos<_buffer.length()) { - c = _buffer.charAt(_bufferPos++); + if (this._bufferPos < this._buffer.length()) { + c = this._buffer.charAt(this._bufferPos++); loop = false; - } - else { + } else { c = 0; - _state = 0; + this._state = 0; loop = true; } break; - default: + default: throw new IOException("It shouldn't happen"); } } while (loop); return c; } - public int read(char[] buffer,int offset,int len) throws IOException { + @Override + public int read(final char[] buffer, final int offset, final int len) throws IOException { int charsRead = 0; - int c = read(); - if (c==-1) { + int c = this.read(); + if (c == -1) { return -1; } - buffer[offset+(charsRead++)] = (char) c; - while (charsRead-1) { - buffer[offset+(charsRead++)] = (char) c; + buffer[offset + charsRead++] = (char) c; + while (charsRead < len && (c = this.read()) > -1) { + buffer[offset + charsRead++] = (char) c; } return charsRead; } - public long skip(long n) throws IOException { - if (n==0) { + @Override + public long skip(final long n) throws IOException { + if (n == 0) { return 0; - } - else - if (n<0) { + } else if (n < 0) { throw new IllegalArgumentException("'n' cannot be negative"); } - int c = read(); + int c = this.read(); long counter = 1; - while (c>-1 && counter -1 && counter < n) { + c = this.read(); counter++; } return counter; } + @Override public boolean ready() throws IOException { - return (_state!=0) || in.ready(); + return this._state != 0 || this.in.ready(); } + @Override public boolean markSupported() { return false; } - public void mark(int readAheadLimit) throws IOException { + @Override + public void mark(final int readAheadLimit) throws IOException { throw new IOException("Stream does not support mark"); } + @Override public void reset() throws IOException { throw new IOException("Stream does not support mark"); } + @Override public void close() throws IOException { - in.close(); + this.in.close(); } private static Map CODED_ENTITIES = new HashMap(); @@ -345,303 +321,301 @@ public class XmlFixerReader extends Reader { // note: refer to Character entity references in HTML 4 // at http://www.w3.org/TR/REC-html40/sgml/entities.html - // Character entity set. - // HTMLlat1 "-//W3C//ENTITIES Latin 1//EN//HTML" + // Character entity set. + // HTMLlat1 "-//W3C//ENTITIES Latin 1//EN//HTML" - CODED_ENTITIES.put(" ", " "); + CODED_ENTITIES.put(" ", " "); CODED_ENTITIES.put("¡", "¡"); - CODED_ENTITIES.put("¢", "¢"); + CODED_ENTITIES.put("¢", "¢"); CODED_ENTITIES.put("£", "£"); - CODED_ENTITIES.put("¤","¤"); - CODED_ENTITIES.put("¥", "¥"); - CODED_ENTITIES.put("¦","¦"); - CODED_ENTITIES.put("§", "§"); - CODED_ENTITIES.put("¨", "¨"); - CODED_ENTITIES.put("©", "©"); - CODED_ENTITIES.put("ª", "ª"); + CODED_ENTITIES.put("¤", "¤"); + CODED_ENTITIES.put("¥", "¥"); + CODED_ENTITIES.put("¦", "¦"); + CODED_ENTITIES.put("§", "§"); + CODED_ENTITIES.put("¨", "¨"); + CODED_ENTITIES.put("©", "©"); + CODED_ENTITIES.put("ª", "ª"); CODED_ENTITIES.put("«", "«"); - CODED_ENTITIES.put("¬", "¬"); - CODED_ENTITIES.put("­", "­"); - CODED_ENTITIES.put("®", "®"); - CODED_ENTITIES.put("¯", "¯"); - CODED_ENTITIES.put("°", "°"); - CODED_ENTITIES.put("±","±"); - CODED_ENTITIES.put("²", "²"); - CODED_ENTITIES.put("³", "³"); + CODED_ENTITIES.put("¬", "¬"); + CODED_ENTITIES.put("­", "­"); + CODED_ENTITIES.put("®", "®"); + CODED_ENTITIES.put("¯", "¯"); + CODED_ENTITIES.put("°", "°"); + CODED_ENTITIES.put("±", "±"); + CODED_ENTITIES.put("²", "²"); + CODED_ENTITIES.put("³", "³"); CODED_ENTITIES.put("´", "´"); CODED_ENTITIES.put("µ", "µ"); - CODED_ENTITIES.put("¶", "¶"); - CODED_ENTITIES.put("·","·"); + CODED_ENTITIES.put("¶", "¶"); + CODED_ENTITIES.put("·", "·"); CODED_ENTITIES.put("¸", "¸"); - CODED_ENTITIES.put("¹", "¹"); - CODED_ENTITIES.put("º", "º"); + CODED_ENTITIES.put("¹", "¹"); + CODED_ENTITIES.put("º", "º"); CODED_ENTITIES.put("»", "»"); - CODED_ENTITIES.put("¼","¼"); - CODED_ENTITIES.put("½","½"); - CODED_ENTITIES.put("¾","¾"); - CODED_ENTITIES.put("¿","¿"); - CODED_ENTITIES.put("À","À"); - CODED_ENTITIES.put("Á","Á"); + CODED_ENTITIES.put("¼", "¼"); + CODED_ENTITIES.put("½", "½"); + CODED_ENTITIES.put("¾", "¾"); + CODED_ENTITIES.put("¿", "¿"); + CODED_ENTITIES.put("À", "À"); + CODED_ENTITIES.put("Á", "Á"); CODED_ENTITIES.put("Â", "Â"); - CODED_ENTITIES.put("Ã","Ã"); - CODED_ENTITIES.put("Ä", "Ä"); + CODED_ENTITIES.put("Ã", "Ã"); + CODED_ENTITIES.put("Ä", "Ä"); CODED_ENTITIES.put("Å", "Å"); CODED_ENTITIES.put("Æ", "Æ"); - CODED_ENTITIES.put("Ç","Ç"); - CODED_ENTITIES.put("È","È"); - CODED_ENTITIES.put("É","É"); + CODED_ENTITIES.put("Ç", "Ç"); + CODED_ENTITIES.put("È", "È"); + CODED_ENTITIES.put("É", "É"); CODED_ENTITIES.put("Ê", "Ê"); - CODED_ENTITIES.put("Ë", "Ë"); - CODED_ENTITIES.put("Ì","Ì"); - CODED_ENTITIES.put("Í","Í"); + CODED_ENTITIES.put("Ë", "Ë"); + CODED_ENTITIES.put("Ì", "Ì"); + CODED_ENTITIES.put("Í", "Í"); CODED_ENTITIES.put("Î", "Î"); - CODED_ENTITIES.put("Ï", "Ï"); - CODED_ENTITIES.put("Ð", "Ð"); - CODED_ENTITIES.put("Ñ","Ñ"); - CODED_ENTITIES.put("Ò","Ò"); - CODED_ENTITIES.put("Ó","Ó"); + CODED_ENTITIES.put("Ï", "Ï"); + CODED_ENTITIES.put("Ð", "Ð"); + CODED_ENTITIES.put("Ñ", "Ñ"); + CODED_ENTITIES.put("Ò", "Ò"); + CODED_ENTITIES.put("Ó", "Ó"); CODED_ENTITIES.put("Ô", "Ô"); - CODED_ENTITIES.put("Õ","Õ"); - CODED_ENTITIES.put("Ö", "Ö"); + CODED_ENTITIES.put("Õ", "Õ"); + CODED_ENTITIES.put("Ö", "Ö"); CODED_ENTITIES.put("×", "×"); - CODED_ENTITIES.put("Ø","Ø"); - CODED_ENTITIES.put("Ù","Ù"); - CODED_ENTITIES.put("Ú","Ú"); + CODED_ENTITIES.put("Ø", "Ø"); + CODED_ENTITIES.put("Ù", "Ù"); + CODED_ENTITIES.put("Ú", "Ú"); CODED_ENTITIES.put("Û", "Û"); - CODED_ENTITIES.put("Ü", "Ü"); - CODED_ENTITIES.put("Ý","Ý"); + CODED_ENTITIES.put("Ü", "Ü"); + CODED_ENTITIES.put("Ý", "Ý"); CODED_ENTITIES.put("Þ", "Þ"); CODED_ENTITIES.put("ß", "ß"); - CODED_ENTITIES.put("à","à"); - CODED_ENTITIES.put("á","á"); + CODED_ENTITIES.put("à", "à"); + CODED_ENTITIES.put("á", "á"); CODED_ENTITIES.put("â", "â"); - CODED_ENTITIES.put("ã","ã"); - CODED_ENTITIES.put("ä", "ä"); + CODED_ENTITIES.put("ã", "ã"); + CODED_ENTITIES.put("ä", "ä"); CODED_ENTITIES.put("å", "å"); CODED_ENTITIES.put("æ", "æ"); - CODED_ENTITIES.put("ç","ç"); - CODED_ENTITIES.put("è","è"); - CODED_ENTITIES.put("é","é"); + CODED_ENTITIES.put("ç", "ç"); + CODED_ENTITIES.put("è", "è"); + CODED_ENTITIES.put("é", "é"); CODED_ENTITIES.put("ê", "ê"); - CODED_ENTITIES.put("ë", "ë"); - CODED_ENTITIES.put("ì","ì"); - CODED_ENTITIES.put("í","í"); + CODED_ENTITIES.put("ë", "ë"); + CODED_ENTITIES.put("ì", "ì"); + CODED_ENTITIES.put("í", "í"); CODED_ENTITIES.put("î", "î"); - CODED_ENTITIES.put("ï", "ï"); - CODED_ENTITIES.put("ð", "ð"); - CODED_ENTITIES.put("ñ","ñ"); - CODED_ENTITIES.put("ò","ò"); - CODED_ENTITIES.put("ó","ó"); + CODED_ENTITIES.put("ï", "ï"); + CODED_ENTITIES.put("ð", "ð"); + CODED_ENTITIES.put("ñ", "ñ"); + CODED_ENTITIES.put("ò", "ò"); + CODED_ENTITIES.put("ó", "ó"); CODED_ENTITIES.put("ô", "ô"); - CODED_ENTITIES.put("õ","õ"); - CODED_ENTITIES.put("ö", "ö"); - CODED_ENTITIES.put("÷","÷"); - CODED_ENTITIES.put("ø","ø"); - CODED_ENTITIES.put("ù","ù"); - CODED_ENTITIES.put("ú","ú"); + CODED_ENTITIES.put("õ", "õ"); + CODED_ENTITIES.put("ö", "ö"); + CODED_ENTITIES.put("÷", "÷"); + CODED_ENTITIES.put("ø", "ø"); + CODED_ENTITIES.put("ù", "ù"); + CODED_ENTITIES.put("ú", "ú"); CODED_ENTITIES.put("û", "û"); - CODED_ENTITIES.put("ü", "ü"); - CODED_ENTITIES.put("ý","ý"); + CODED_ENTITIES.put("ü", "ü"); + CODED_ENTITIES.put("ý", "ý"); CODED_ENTITIES.put("þ", "þ"); - CODED_ENTITIES.put("ÿ", "ÿ"); + CODED_ENTITIES.put("ÿ", "ÿ"); // Mathematical, Greek and Symbolic characters for HTML. // HTMLsymbol "-//W3C//ENTITIES Symbols//EN//HTML" - CODED_ENTITIES.put("ƒ", "ƒ"); - CODED_ENTITIES.put("Α", "Α"); - CODED_ENTITIES.put("Β", "Β"); - CODED_ENTITIES.put("Γ", "Γ"); - CODED_ENTITIES.put("Δ", "Δ"); - CODED_ENTITIES.put("Ε", "Ε"); - CODED_ENTITIES.put("Ζ", "Ζ"); - CODED_ENTITIES.put("Η", "Η"); - CODED_ENTITIES.put("Θ", "Θ"); - CODED_ENTITIES.put("Ι", "Ι"); - CODED_ENTITIES.put("Κ", "Κ"); - CODED_ENTITIES.put("Λ", "Λ"); - CODED_ENTITIES.put("Μ", "Μ"); - CODED_ENTITIES.put("Ν", "Ν"); - CODED_ENTITIES.put("Ξ", "Ξ"); - CODED_ENTITIES.put("Ο", "Ο"); - CODED_ENTITIES.put("Π", "Π"); - CODED_ENTITIES.put("Ρ", "Ρ"); - CODED_ENTITIES.put("Σ", "Σ"); - CODED_ENTITIES.put("Τ", "Τ"); - CODED_ENTITIES.put("Υ", "Υ"); - CODED_ENTITIES.put("Φ", "Φ"); - CODED_ENTITIES.put("Χ", "Χ"); - CODED_ENTITIES.put("Ψ", "Ψ"); - CODED_ENTITIES.put("Ω", "Ω"); - CODED_ENTITIES.put("α", "α"); - CODED_ENTITIES.put("β", "β"); - CODED_ENTITIES.put("γ", "γ"); - CODED_ENTITIES.put("δ", "δ"); - CODED_ENTITIES.put("ε", "ε"); - CODED_ENTITIES.put("ζ", "ζ"); - CODED_ENTITIES.put("η", "η"); - CODED_ENTITIES.put("θ", "θ"); - CODED_ENTITIES.put("ι", "ι"); - CODED_ENTITIES.put("κ", "κ"); - CODED_ENTITIES.put("λ", "λ"); - CODED_ENTITIES.put("μ", "μ"); - CODED_ENTITIES.put("ν", "ν"); - CODED_ENTITIES.put("ξ", "ξ"); - CODED_ENTITIES.put("ο", "ο"); - CODED_ENTITIES.put("π", "π"); - CODED_ENTITIES.put("ρ", "ρ"); - CODED_ENTITIES.put("ς", "ς"); - CODED_ENTITIES.put("σ", "σ"); - CODED_ENTITIES.put("τ", "τ"); - CODED_ENTITIES.put("υ", "υ"); - CODED_ENTITIES.put("φ", "φ"); - CODED_ENTITIES.put("χ", "χ"); - CODED_ENTITIES.put("ψ", "ψ"); - CODED_ENTITIES.put("ω", "ω"); + CODED_ENTITIES.put("ƒ", "ƒ"); + CODED_ENTITIES.put("Α", "Α"); + CODED_ENTITIES.put("Β", "Β"); + CODED_ENTITIES.put("Γ", "Γ"); + CODED_ENTITIES.put("Δ", "Δ"); + CODED_ENTITIES.put("Ε", "Ε"); + CODED_ENTITIES.put("Ζ", "Ζ"); + CODED_ENTITIES.put("Η", "Η"); + CODED_ENTITIES.put("Θ", "Θ"); + CODED_ENTITIES.put("Ι", "Ι"); + CODED_ENTITIES.put("Κ", "Κ"); + CODED_ENTITIES.put("Λ", "Λ"); + CODED_ENTITIES.put("Μ", "Μ"); + CODED_ENTITIES.put("Ν", "Ν"); + CODED_ENTITIES.put("Ξ", "Ξ"); + CODED_ENTITIES.put("Ο", "Ο"); + CODED_ENTITIES.put("Π", "Π"); + CODED_ENTITIES.put("Ρ", "Ρ"); + CODED_ENTITIES.put("Σ", "Σ"); + CODED_ENTITIES.put("Τ", "Τ"); + CODED_ENTITIES.put("Υ", "Υ"); + CODED_ENTITIES.put("Φ", "Φ"); + CODED_ENTITIES.put("Χ", "Χ"); + CODED_ENTITIES.put("Ψ", "Ψ"); + CODED_ENTITIES.put("Ω", "Ω"); + CODED_ENTITIES.put("α", "α"); + CODED_ENTITIES.put("β", "β"); + CODED_ENTITIES.put("γ", "γ"); + CODED_ENTITIES.put("δ", "δ"); + CODED_ENTITIES.put("ε", "ε"); + CODED_ENTITIES.put("ζ", "ζ"); + CODED_ENTITIES.put("η", "η"); + CODED_ENTITIES.put("θ", "θ"); + CODED_ENTITIES.put("ι", "ι"); + CODED_ENTITIES.put("κ", "κ"); + CODED_ENTITIES.put("λ", "λ"); + CODED_ENTITIES.put("μ", "μ"); + CODED_ENTITIES.put("ν", "ν"); + CODED_ENTITIES.put("ξ", "ξ"); + CODED_ENTITIES.put("ο", "ο"); + CODED_ENTITIES.put("π", "π"); + CODED_ENTITIES.put("ρ", "ρ"); + CODED_ENTITIES.put("ς", "ς"); + CODED_ENTITIES.put("σ", "σ"); + CODED_ENTITIES.put("τ", "τ"); + CODED_ENTITIES.put("υ", "υ"); + CODED_ENTITIES.put("φ", "φ"); + CODED_ENTITIES.put("χ", "χ"); + CODED_ENTITIES.put("ψ", "ψ"); + CODED_ENTITIES.put("ω", "ω"); CODED_ENTITIES.put("ϑ", "ϑ"); - CODED_ENTITIES.put("ϒ", "ϒ"); - CODED_ENTITIES.put("ϖ", "ϖ"); - CODED_ENTITIES.put("•", "•"); - CODED_ENTITIES.put("…", "…"); - CODED_ENTITIES.put("′", "′"); - CODED_ENTITIES.put("″", "″"); - CODED_ENTITIES.put("‾", "‾"); - CODED_ENTITIES.put("⁄", "⁄"); - CODED_ENTITIES.put("℘", "℘"); - CODED_ENTITIES.put("ℑ", "ℑ"); - CODED_ENTITIES.put("ℜ", "ℜ"); - CODED_ENTITIES.put("™", "™"); - CODED_ENTITIES.put("ℵ", "ℵ"); - CODED_ENTITIES.put("←", "←"); - CODED_ENTITIES.put("↑", "↑"); - CODED_ENTITIES.put("→", "→"); - CODED_ENTITIES.put("↓", "↓"); - CODED_ENTITIES.put("↔", "↔"); - CODED_ENTITIES.put("↵", "↵"); - CODED_ENTITIES.put("⇐", "⇐"); - CODED_ENTITIES.put("⇑", "⇑"); - CODED_ENTITIES.put("⇒", "⇒"); - CODED_ENTITIES.put("⇓", "⇓"); - CODED_ENTITIES.put("⇔", "⇔"); - CODED_ENTITIES.put("∀", "∀"); - CODED_ENTITIES.put("∂", "∂"); - CODED_ENTITIES.put("∃", "∃"); - CODED_ENTITIES.put("∅", "∅"); - CODED_ENTITIES.put("∇", "∇"); - CODED_ENTITIES.put("∈", "∈"); - CODED_ENTITIES.put("∉", "∉"); - CODED_ENTITIES.put("∋", "∋"); - CODED_ENTITIES.put("∏", "∏"); - CODED_ENTITIES.put("∑", "∑"); - CODED_ENTITIES.put("−", "−"); - CODED_ENTITIES.put("∗", "∗"); - CODED_ENTITIES.put("√", "√"); - CODED_ENTITIES.put("∝", "∝"); - CODED_ENTITIES.put("∞", "∞"); - CODED_ENTITIES.put("∠", "∠"); - CODED_ENTITIES.put("∧", "∧"); - CODED_ENTITIES.put("∨", "∨"); - CODED_ENTITIES.put("∩", "∩"); - CODED_ENTITIES.put("∪", "∪"); - CODED_ENTITIES.put("∫", "∫"); - CODED_ENTITIES.put("∴", "∴"); - CODED_ENTITIES.put("∼", "∼"); - CODED_ENTITIES.put("≅", "≅"); - CODED_ENTITIES.put("≈", "≈"); - CODED_ENTITIES.put("≠", "≠"); - CODED_ENTITIES.put("≡", "≡"); - CODED_ENTITIES.put("≤", "≤"); - CODED_ENTITIES.put("≥", "≥"); - CODED_ENTITIES.put("⊂", "⊂"); - CODED_ENTITIES.put("⊃", "⊃"); - CODED_ENTITIES.put("⊄", "⊄"); - CODED_ENTITIES.put("⊆", "⊆"); - CODED_ENTITIES.put("⊇", "⊇"); - CODED_ENTITIES.put("⊕", "⊕"); - CODED_ENTITIES.put("⊗", "⊗"); - CODED_ENTITIES.put("⊥", "⊥"); - CODED_ENTITIES.put("⋅", "⋅"); - CODED_ENTITIES.put("⌈", "⌈"); - CODED_ENTITIES.put("⌉", "⌉"); - CODED_ENTITIES.put("⌊", "⌊"); - CODED_ENTITIES.put("⌋", "⌋"); - CODED_ENTITIES.put("⟨", "〈"); - CODED_ENTITIES.put("⟩", "〉"); - CODED_ENTITIES.put("◊", "◊"); - CODED_ENTITIES.put("♠", "♠"); - CODED_ENTITIES.put("♣", "♣"); - CODED_ENTITIES.put("♥", "♥"); - CODED_ENTITIES.put("♦", "♦"); + CODED_ENTITIES.put("ϒ", "ϒ"); + CODED_ENTITIES.put("ϖ", "ϖ"); + CODED_ENTITIES.put("•", "•"); + CODED_ENTITIES.put("…", "…"); + CODED_ENTITIES.put("′", "′"); + CODED_ENTITIES.put("″", "″"); + CODED_ENTITIES.put("‾", "‾"); + CODED_ENTITIES.put("⁄", "⁄"); + CODED_ENTITIES.put("℘", "℘"); + CODED_ENTITIES.put("ℑ", "ℑ"); + CODED_ENTITIES.put("ℜ", "ℜ"); + CODED_ENTITIES.put("™", "™"); + CODED_ENTITIES.put("ℵ", "ℵ"); + CODED_ENTITIES.put("←", "←"); + CODED_ENTITIES.put("↑", "↑"); + CODED_ENTITIES.put("→", "→"); + CODED_ENTITIES.put("↓", "↓"); + CODED_ENTITIES.put("↔", "↔"); + CODED_ENTITIES.put("↵", "↵"); + CODED_ENTITIES.put("⇐", "⇐"); + CODED_ENTITIES.put("⇑", "⇑"); + CODED_ENTITIES.put("⇒", "⇒"); + CODED_ENTITIES.put("⇓", "⇓"); + CODED_ENTITIES.put("⇔", "⇔"); + CODED_ENTITIES.put("∀", "∀"); + CODED_ENTITIES.put("∂", "∂"); + CODED_ENTITIES.put("∃", "∃"); + CODED_ENTITIES.put("∅", "∅"); + CODED_ENTITIES.put("∇", "∇"); + CODED_ENTITIES.put("∈", "∈"); + CODED_ENTITIES.put("∉", "∉"); + CODED_ENTITIES.put("∋", "∋"); + CODED_ENTITIES.put("∏", "∏"); + CODED_ENTITIES.put("∑", "∑"); + CODED_ENTITIES.put("−", "−"); + CODED_ENTITIES.put("∗", "∗"); + CODED_ENTITIES.put("√", "√"); + CODED_ENTITIES.put("∝", "∝"); + CODED_ENTITIES.put("∞", "∞"); + CODED_ENTITIES.put("∠", "∠"); + CODED_ENTITIES.put("∧", "∧"); + CODED_ENTITIES.put("∨", "∨"); + CODED_ENTITIES.put("∩", "∩"); + CODED_ENTITIES.put("∪", "∪"); + CODED_ENTITIES.put("∫", "∫"); + CODED_ENTITIES.put("∴", "∴"); + CODED_ENTITIES.put("∼", "∼"); + CODED_ENTITIES.put("≅", "≅"); + CODED_ENTITIES.put("≈", "≈"); + CODED_ENTITIES.put("≠", "≠"); + CODED_ENTITIES.put("≡", "≡"); + CODED_ENTITIES.put("≤", "≤"); + CODED_ENTITIES.put("≥", "≥"); + CODED_ENTITIES.put("⊂", "⊂"); + CODED_ENTITIES.put("⊃", "⊃"); + CODED_ENTITIES.put("⊄", "⊄"); + CODED_ENTITIES.put("⊆", "⊆"); + CODED_ENTITIES.put("⊇", "⊇"); + CODED_ENTITIES.put("⊕", "⊕"); + CODED_ENTITIES.put("⊗", "⊗"); + CODED_ENTITIES.put("⊥", "⊥"); + CODED_ENTITIES.put("⋅", "⋅"); + CODED_ENTITIES.put("⌈", "⌈"); + CODED_ENTITIES.put("⌉", "⌉"); + CODED_ENTITIES.put("⌊", "⌊"); + CODED_ENTITIES.put("⌋", "⌋"); + CODED_ENTITIES.put("⟨", "〈"); + CODED_ENTITIES.put("⟩", "〉"); + CODED_ENTITIES.put("◊", "◊"); + CODED_ENTITIES.put("♠", "♠"); + CODED_ENTITIES.put("♣", "♣"); + CODED_ENTITIES.put("♥", "♥"); + CODED_ENTITIES.put("♦", "♦"); - // Special characters for HTML. - // HTMLspecial "-//W3C//ENTITIES Special//EN//HTML" + // Special characters for HTML. + // HTMLspecial "-//W3C//ENTITIES Special//EN//HTML" - CODED_ENTITIES.put(""", """); - CODED_ENTITIES.put("&", "&"); - CODED_ENTITIES.put("<", "<"); - CODED_ENTITIES.put(">", ">"); - CODED_ENTITIES.put("Œ", "Œ"); - CODED_ENTITIES.put("œ", "œ"); - CODED_ENTITIES.put("Š", "Š"); - CODED_ENTITIES.put("š", "š"); - CODED_ENTITIES.put("Ÿ", "Ÿ"); - CODED_ENTITIES.put("ˆ", "ˆ"); - CODED_ENTITIES.put("˜", "˜"); - CODED_ENTITIES.put(" ", " "); - CODED_ENTITIES.put(" ", " "); - CODED_ENTITIES.put(" ", " "); - CODED_ENTITIES.put("‌", "‌"); - CODED_ENTITIES.put("‍", "‍"); - CODED_ENTITIES.put("‎", "‎"); - CODED_ENTITIES.put("‏", "‏"); - CODED_ENTITIES.put("–", "–"); - CODED_ENTITIES.put("—", "—"); - CODED_ENTITIES.put("‘", "‘"); - CODED_ENTITIES.put("’", "’"); - CODED_ENTITIES.put("‚", "‚"); - CODED_ENTITIES.put("“", "“"); - CODED_ENTITIES.put("”", "”"); - CODED_ENTITIES.put("„", "„"); - CODED_ENTITIES.put("†", "†"); - CODED_ENTITIES.put("‡", "‡"); - CODED_ENTITIES.put("‰", "‰"); - CODED_ENTITIES.put("‹", "‹"); - CODED_ENTITIES.put("›", "›"); - CODED_ENTITIES.put("€", "€"); + CODED_ENTITIES.put(""", """); + CODED_ENTITIES.put("&", "&"); + CODED_ENTITIES.put("<", "<"); + CODED_ENTITIES.put(">", ">"); + CODED_ENTITIES.put("Œ", "Œ"); + CODED_ENTITIES.put("œ", "œ"); + CODED_ENTITIES.put("Š", "Š"); + CODED_ENTITIES.put("š", "š"); + CODED_ENTITIES.put("Ÿ", "Ÿ"); + CODED_ENTITIES.put("ˆ", "ˆ"); + CODED_ENTITIES.put("˜", "˜"); + CODED_ENTITIES.put(" ", " "); + CODED_ENTITIES.put(" ", " "); + CODED_ENTITIES.put(" ", " "); + CODED_ENTITIES.put("‌", "‌"); + CODED_ENTITIES.put("‍", "‍"); + CODED_ENTITIES.put("‎", "‎"); + CODED_ENTITIES.put("‏", "‏"); + CODED_ENTITIES.put("–", "–"); + CODED_ENTITIES.put("—", "—"); + CODED_ENTITIES.put("‘", "‘"); + CODED_ENTITIES.put("’", "’"); + CODED_ENTITIES.put("‚", "‚"); + CODED_ENTITIES.put("“", "“"); + CODED_ENTITIES.put("”", "”"); + CODED_ENTITIES.put("„", "„"); + CODED_ENTITIES.put("†", "†"); + CODED_ENTITIES.put("‡", "‡"); + CODED_ENTITIES.put("‰", "‰"); + CODED_ENTITIES.put("‹", "‹"); + CODED_ENTITIES.put("›", "›"); + CODED_ENTITIES.put("€", "€"); } // // It shouldn't be here but well, just reusing the CODED_ENTITIES Map :) // - private static Pattern ENTITIES_PATTERN = Pattern.compile( "&[A-Za-z^#]+;" ); + private static Pattern ENTITIES_PATTERN = Pattern.compile("&[A-Za-z^#]+;"); - - public String processHtmlEntities(String s) { - if (s.indexOf('&')==-1) { + public String processHtmlEntities(final String s) { + if (s.indexOf('&') == -1) { return s; } - StringBuffer sb = new StringBuffer(s.length()); + final StringBuffer sb = new StringBuffer(s.length()); int pos = 0; - while (pospos) { - sb.append(s.substring(pos,b)); + final int b = pos + m.start(); + final int e = pos + m.end(); + if (b > pos) { + sb.append(s.substring(pos, b)); pos = b; } - chunck = s.substring(pos,e); - String codedEntity = (String) CODED_ENTITIES.get(chunck); - if (codedEntity==null) { + chunck = s.substring(pos, e); + String codedEntity = CODED_ENTITIES.get(chunck); + if (codedEntity == null) { codedEntity = chunck; } sb.append(codedEntity); pos = e; - } - else { + } else { sb.append(chunck); pos += chunck.length(); } diff --git a/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java b/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java index 81cfd29..e69083b 100644 --- a/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java +++ b/src/test/java/com/sun/syndication/unittest/FeedOpsTest.java @@ -1,61 +1,63 @@ package com.sun.syndication.unittest; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +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.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"); + System.out.println("Testing " + feedType + ".xml"); } - //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)); @@ -63,47 +65,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 = this.getCachedSyndFeed(); + final WireFeed wFeed1 = sFeed1.createWireFeed(); + final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1); assertTrue(sFeed1.equals(sFeed2)); } - //1.7a + // 1.7a public void testSyndFeedEquals() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(false); + final SyndFeed feed1 = this.getCachedSyndFeed(); + final SyndFeed feed2 = getSyndFeed(false); assertTrue(feed1.equals(feed2)); } - //1.7b + // 1.7b public void testSyndFeedNotEqual() throws Exception { - SyndFeed feed1 = getCachedSyndFeed(); - SyndFeed feed2 = getSyndFeed(false); + final SyndFeed feed1 = this.getCachedSyndFeed(); + final SyndFeed feed2 = getSyndFeed(false); 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 = this.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 = this.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/com/sun/syndication/unittest/FeedTest.java b/src/test/java/com/sun/syndication/unittest/FeedTest.java index 8a4104e..aeb14a8 100644 --- a/src/test/java/com/sun/syndication/unittest/FeedTest.java +++ b/src/test/java/com/sun/syndication/unittest/FeedTest.java @@ -1,88 +1,87 @@ 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.InputStream; import java.io.InputStreamReader; import java.io.Reader; -import java.io.InputStream; + +import junit.framework.TestCase; 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; + /** * @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; - + private boolean preservingWireFeed = false; - protected FeedTest(String feedFileName) { - _feedFileName = feedFileName; + protected FeedTest(final String feedFileName) { + this._feedFileName = feedFileName; } protected String getFeedFileName() { - return _feedFileName; + return this._feedFileName; } 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(boolean preserveWireFeed) throws Exception { - SyndFeedInput in = new SyndFeedInput(); + protected SyndFeed getSyndFeed(final boolean preserveWireFeed) throws Exception { + final SyndFeedInput in = new SyndFeedInput(); in.setPreserveWireFeed(preserveWireFeed); return in.build(getFeedReader()); } protected Document getCachedJDomDoc() throws Exception { - if (_jDomDoc==null) { - _jDomDoc = getJDomDoc(); + if (this._jDomDoc == null) { + this._jDomDoc = getJDomDoc(); } - return _jDomDoc; + return this._jDomDoc; } protected WireFeed getCachedWireFeed() throws Exception { - if (_wireFeed==null) { - _wireFeed = getWireFeed(); + if (this._wireFeed == null) { + this._wireFeed = getWireFeed(); } - return _wireFeed; + return this._wireFeed; } - protected SyndFeed getCachedSyndFeed(boolean preserveWireFeed) throws Exception { - - if (_syndFeed==null || preservingWireFeed != preserveWireFeed) { - _syndFeed = getSyndFeed(preserveWireFeed); - preservingWireFeed = preserveWireFeed; + protected SyndFeed getCachedSyndFeed(final boolean preserveWireFeed) throws Exception { + + if (this._syndFeed == null || this.preservingWireFeed != preserveWireFeed) { + this._syndFeed = getSyndFeed(preserveWireFeed); + this.preservingWireFeed = preserveWireFeed; } - return _syndFeed; - + return this._syndFeed; + } - + protected SyndFeed getCachedSyndFeed() throws Exception { - return getCachedSyndFeed(false); + return this.getCachedSyndFeed(false); } } diff --git a/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java b/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java index 4130521..94b6f0e 100644 --- a/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java +++ b/src/test/java/com/sun/syndication/unittest/SyndFeedTest.java @@ -13,269 +13,211 @@ import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndImage; import com.sun.syndication.io.impl.DateParser; - /** * @author pat - * + * */ public abstract class SyndFeedTest extends FeedTest { - private String _prefix = null; + private String _prefix = null; - protected SyndFeedTest(String feedType) { - this(feedType,feedType+".xml"); + 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; + this._prefix = feedType; } protected String getPrefix() { - return _prefix; + return this._prefix; } - protected void assertProperty(String property, String value) { - assertEquals(property,getPrefix() + "." + value); - } - - protected void assertEqualsStr(String expected, String actual) { - assertEquals(_prefix + "." + expected, actual); - } - - public void testPreserveWireFeed() throws Exception { - assertNotNull(getCachedSyndFeed(true).originalWireFeed()); - } + protected void assertProperty(final String property, final String value) { + assertEquals(property, getPrefix() + "." + value); + } + + protected void assertEqualsStr(final String expected, final String actual) { + assertEquals(this._prefix + "." + expected, actual); + } + + public void testPreserveWireFeed() throws Exception { + assertNotNull(this.getCachedSyndFeed(true).originalWireFeed()); + } public void testType() throws Exception { - assertEquals(getCachedSyndFeed().getFeedType(),getPrefix()); + assertEquals(this.getCachedSyndFeed().getFeedType(), getPrefix()); } + public void testTitle() throws Exception { + assertEqualsStr("channel.title", this.getCachedSyndFeed().getTitle()); + } - public void testTitle() throws Exception { - assertEqualsStr("channel.title", getCachedSyndFeed().getTitle()); - } + public void testLink() throws Exception { + assertEqualsStr("channel.link", this.getCachedSyndFeed().getLink()); + } - public void testLink() throws Exception { - assertEqualsStr("channel.link", getCachedSyndFeed().getLink()); - } + public void testDescription() throws Exception { + assertEqualsStr("channel.description", this.getCachedSyndFeed().getDescription()); + } - public void testDescription() throws Exception { - assertEqualsStr("channel.description", getCachedSyndFeed().getDescription()); - } + public void testLanguage() throws Exception { + assertEqualsStr("channel.language", this.getCachedSyndFeed().getLanguage()); + } - 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); assertEquals("channel.category[0]", + * cat.getName()); assertEquals("channel.category[0]^domain", + * cat.getTaxonomyUri()); cat = (SyndCategory)catlist.get(1); + * assertEquals("channel.category[1]", cat.getName()); + * assertEquals("channel.category[1]^domain", cat.getTaxonomyUri()); } + */ - /* - 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); - assertEquals("channel.category[0]", cat.getName()); - assertEquals("channel.category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEquals("channel.category[1]", cat.getName()); - assertEquals("channel.category[1]^domain", cat.getTaxonomyUri()); - } - */ + public void testPublishedDate() throws Exception { + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), this.getCachedSyndFeed().getPublishedDate()); + } - 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 { + final SyndImage img = this.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()); + } - //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 { + final List entrylist = this.getCachedSyndFeed().getEntries(); + assertEquals(2, entrylist.size()); + } - public void testEntries() throws Exception { - List entrylist = getCachedSyndFeed().getEntries(); - assertEquals(2, entrylist.size()); - } + public void testEntryTitle() throws Exception { + assertEqualsStr("channel.item[0].title", getEntryTitle(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].title", getEntryTitle(this.getCachedSyndFeed().getEntries().get(1))); + } - 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(final Object o) throws Exception { + final SyndEntry e = (SyndEntry) o; + return e.getTitle(); + } - 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(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].description", getEntryDescription(this.getCachedSyndFeed().getEntries().get(1))); + } - 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(final Object o) throws Exception { + final SyndEntry e = (SyndEntry) o; + return e.getDescription().getValue(); + } - 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(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("channel.item[1].link", getEntryLink(this.getCachedSyndFeed().getEntries().get(1))); + } - 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(final Object o) { + final SyndEntry e = (SyndEntry) o; + return e.getLink(); + } - public String getEntryLink(Object o) { - SyndEntry e = (SyndEntry) o; - return e.getLink(); - } + public void testEntryPublishedDate() throws Exception { + // this only works for RSS 0.93+ + // assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), + // getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); + // assertEquals(DateParser.parseRFC822("Tue, 02 Jan 2001 00:00:00 GMT"), + // getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); + } - public void testEntryPublishedDate() throws Exception { - // this only works for RSS 0.93+ - //assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); - //assertEquals(DateParser.parseRFC822("Tue, 02 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); - } + public Date getEntryPublishedDate(final Object o) { + final SyndEntry e = (SyndEntry) o; + return e.getPublishedDate(); + } - 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); - assertEquals("channel.item[0].category[0]", cat.getName()); - assertEquals("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); - cat = (SyndCategory)catlist.get(1); - assertEquals("channel.item[0].category[1]", cat.getName()); - assertEquals("channel.item[0].category[1]^domain", cat.getTaxonomyUri()); - //DO 2nd set of items - } - */ + /* + * 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); + * assertEquals("channel.item[0].category[0]", cat.getName()); + * assertEquals("channel.item[0].category[0]^domain", cat.getTaxonomyUri()); + * cat = (SyndCategory)catlist.get(1); + * assertEquals("channel.item[0].category[1]", cat.getName()); + * assertEquals("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 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 - (PICS-1.1 �http://www.classify.org/safesurf/� l r (SS~~000 1)) - - - 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 String getEntryAuthor(final Object o) { + final 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 (PICS-1.1 + * �http://www.classify.org/safesurf/� l r (SS~~000 1)) + * 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/com/sun/syndication/unittest/TestAtomContent.java b/src/test/java/com/sun/syndication/unittest/TestAtomContent.java index 7824f4e..ce248d4 100644 --- a/src/test/java/com/sun/syndication/unittest/TestAtomContent.java +++ b/src/test/java/com/sun/syndication/unittest/TestAtomContent.java @@ -1,19 +1,20 @@ package com.sun.syndication.unittest; -import com.sun.syndication.feed.atom.Feed; -import com.sun.syndication.feed.atom.Content; -import com.sun.syndication.io.WireFeedOutput; -import com.sun.syndication.io.WireFeedInput; +import java.io.StringReader; +import java.io.StringWriter; + import junit.framework.TestCase; -import java.io.StringWriter; -import java.io.StringReader; +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.WireFeedOutput; public class TestAtomContent extends TestCase { private Feed createFeed() { - Feed feed = new Feed(); - Content content = new Content(); + final Feed feed = new Feed(); + final Content content = new Content(); content.setType("application/xml"); content.setValue("Hello Hello"); feed.setTitleEx(content); @@ -23,21 +24,21 @@ public class TestAtomContent extends TestCase { public void testReadWrite() throws Exception { Feed feed = createFeed(); - StringWriter sw = new StringWriter(); - WireFeedOutput output = new WireFeedOutput(); + final StringWriter sw = new StringWriter(); + final WireFeedOutput output = new WireFeedOutput(); output.output(feed, sw); sw.close(); - StringReader reader = new StringReader(sw.toString()); - WireFeedInput input = new WireFeedInput(); + final StringReader reader = new StringReader(sw.toString()); + final WireFeedInput input = new WireFeedInput(); feed = (Feed) input.build(reader); reader.close(); assertEquals("Hello Hello", feed.getTitleEx().getValue().trim()); } public void testXML() throws Exception { - Feed feed = createFeed(); - StringWriter sw = new StringWriter(); - WireFeedOutput output = new WireFeedOutput(); + final Feed feed = createFeed(); + final StringWriter sw = new StringWriter(); + final WireFeedOutput output = new WireFeedOutput(); output.output(feed, sw); sw.close(); assertTrue(sw.toString().contains("Hello Hello")); diff --git a/src/test/java/com/sun/syndication/unittest/TestBase64.java b/src/test/java/com/sun/syndication/unittest/TestBase64.java index c373c2c..c3df536 100644 --- a/src/test/java/com/sun/syndication/unittest/TestBase64.java +++ b/src/test/java/com/sun/syndication/unittest/TestBase64.java @@ -1,13 +1,14 @@ package com.sun.syndication.unittest; import junit.framework.TestCase; + import com.sun.syndication.io.impl.Base64; public class TestBase64 extends TestCase { - private void _testEncodeDecode(String s) { - String encoded = Base64.encode(s); - String decoded = Base64.decode(encoded); + private void _testEncodeDecode(final String s) { + final String encoded = Base64.encode(s); + final String decoded = Base64.decode(encoded); assertEquals(s, decoded); } @@ -27,11 +28,11 @@ public class TestBase64 extends TestCase { } public void testDecodeWithEnters() { - String s = "Hello World!"; + final String s = "Hello World!"; String encoded = Base64.encode(s); encoded = encoded.substring(0, 3) + "\n\r\n" + encoded.substring(3); System.out.println(encoded); - String decoded = Base64.decode(encoded); + final String decoded = Base64.decode(encoded); assertEquals(s, decoded); } diff --git a/src/test/java/com/sun/syndication/unittest/TestDateParser.java b/src/test/java/com/sun/syndication/unittest/TestDateParser.java index 79ec6d5..3b285ed 100644 --- a/src/test/java/com/sun/syndication/unittest/TestDateParser.java +++ b/src/test/java/com/sun/syndication/unittest/TestDateParser.java @@ -16,24 +16,25 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.io.impl.DateParser; -import junit.framework.TestCase; - import java.util.Calendar; +import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; -import java.util.Date; + +import junit.framework.TestCase; + +import com.sun.syndication.io.impl.DateParser; /** - * + * * Start of tests for DateParser - * + * * @author Nick Lothian - * + * */ public class TestDateParser extends TestCase { public void testParse() { - Calendar cal = new GregorianCalendar(); + final Calendar cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); // four-digit year @@ -84,43 +85,43 @@ public class TestDateParser extends TestCase { assertEquals(0, cal.get(Calendar.MINUTE)); assertEquals(51, cal.get(Calendar.SECOND)); - //RFC822 + // RFC822 sDate = "Tue, 19 Jul 2005 23:00:51 GMT"; assertNotNull(DateParser.parseDate(sDate)); - //RFC822 + // RFC822 sDate = "Tue, 19 Jul 05 23:00:51 GMT"; assertNotNull(DateParser.parseDate(sDate)); - Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); - c.set(2000,Calendar.JANUARY,01,0,0,0); - Date expectedDate = c.getTime(); + final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c.set(2000, Calendar.JANUARY, 01, 0, 0, 0); + final Date expectedDate = c.getTime(); - //W3C + // W3C sDate = "2000-01-01T00:00:00Z"; - assertEquals(expectedDate.getTime()/1000,DateParser.parseDate(sDate).getTime()/1000); + assertEquals(expectedDate.getTime() / 1000, DateParser.parseDate(sDate).getTime() / 1000); - //W3C + // W3C sDate = "2000-01-01T00:00Z"; - assertEquals(expectedDate.getTime()/1000,DateParser.parseDate(sDate).getTime()/1000); + assertEquals(expectedDate.getTime() / 1000, DateParser.parseDate(sDate).getTime() / 1000); - //W3C + // W3C sDate = "2000-01-01"; - assertEquals(expectedDate.getTime()/1000,DateParser.parseDate(sDate).getTime()/1000); + assertEquals(expectedDate.getTime() / 1000, DateParser.parseDate(sDate).getTime() / 1000); - //W3C + // W3C sDate = "2000-01"; - assertEquals(expectedDate.getTime()/1000,DateParser.parseDate(sDate).getTime()/1000); + assertEquals(expectedDate.getTime() / 1000, DateParser.parseDate(sDate).getTime() / 1000); - //W3C + // W3C sDate = "2000"; - assertEquals(expectedDate.getTime()/1000,DateParser.parseDate(sDate).getTime()/1000); + assertEquals(expectedDate.getTime() / 1000, DateParser.parseDate(sDate).getTime() / 1000); - //EXTRA + // EXTRA sDate = "18:10 2000/10/10"; assertNotNull(DateParser.parseDate(sDate)); - //INVALID + // INVALID sDate = "X20:10 2000-10-10"; assertNull(DateParser.parseDate(sDate)); diff --git a/src/test/java/com/sun/syndication/unittest/TestEqualsBean.java b/src/test/java/com/sun/syndication/unittest/TestEqualsBean.java index 092d1af..6b14d24 100644 --- a/src/test/java/com/sun/syndication/unittest/TestEqualsBean.java +++ b/src/test/java/com/sun/syndication/unittest/TestEqualsBean.java @@ -1,28 +1,29 @@ package com.sun.syndication.unittest; -import com.sun.syndication.feed.atom.Feed; import junit.framework.TestCase; +import com.sun.syndication.feed.atom.Feed; + public class TestEqualsBean extends TestCase { public void testEquals() { - Feed feed1 = new Feed(); - Feed feed2 = new Feed(); - Feed feed3 = new Feed(); - Feed feed4 = new Feed(); + final Feed feed1 = new Feed(); + final Feed feed2 = new Feed(); + final Feed feed3 = new Feed(); + final Feed feed4 = new Feed(); feed4.setId("a"); - //reflexive + // reflexive assertTrue(feed1.equals(feed1)); - //symmetric + // symmetric assertTrue(feed1.equals(feed2)); assertTrue(feed2.equals(feed1)); assertFalse(feed1.equals(feed4)); assertFalse(feed4.equals(feed1)); - //transitive + // transitive assertTrue(feed1.equals(feed2)); assertTrue(feed2.equals(feed3)); assertTrue(feed1.equals(feed3)); @@ -31,14 +32,14 @@ public class TestEqualsBean extends TestCase { assertFalse(feed2.equals(feed4)); assertFalse(feed1.equals(feed4)); - //consistent + // consistent assertTrue(feed1.equals(feed2)); assertTrue(feed1.equals(feed2)); assertFalse(feed1.equals(feed4)); assertFalse(feed1.equals(feed4)); - //not-null to null is FALSE + // not-null to null is FALSE assertFalse(feed1.equals(null)); } diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsAtom03.java b/src/test/java/com/sun/syndication/unittest/TestOpsAtom03.java index a3b62c0..6bfda23 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsAtom03.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsAtom03.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsAtom03 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsAtom10.java b/src/test/java/com/sun/syndication/unittest/TestOpsAtom10.java index 76bed30..b6c87e7 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsAtom10.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsAtom10.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Dave Johnson - * + * */ public class TestOpsAtom10 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS090.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS090.java index 3bc08a5..85aec54 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS090.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS090.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS090 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS091N.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS091N.java index a90afd2..ffb2d13 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS091N.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS091N.java @@ -1,15 +1,16 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS091N extends FeedOpsTest { - public static void main(String[] args) throws Exception { - FeedOpsTest test = new TestOpsRSS091N(); + public static void main(final String[] args) throws Exception { + final FeedOpsTest test = new TestOpsRSS091N(); test.testWireFeedSyndFeedConversion(); } diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS091U.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS091U.java index e3f8192..cf9ceea 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS091U.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS091U.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS091U extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS092.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS092.java index d8aed17..d830956 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS092.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS092.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS092 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS093.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS093.java index c85135b..5c2c854 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS093.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS093.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS093 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS094.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS094.java index cf1e013..57ced90 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS094.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS094.java @@ -1,15 +1,16 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS094 extends FeedOpsTest { - public static void main(String[] args) throws Exception { - FeedOpsTest test = new TestOpsRSS094(); + public static void main(final String[] args) throws Exception { + final FeedOpsTest test = new TestOpsRSS094(); test.testWireFeedSyndFeedConversion(); } diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS10.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS10.java index 57ec6b6..6141995 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS10.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS10.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS10 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestOpsRSS20.java b/src/test/java/com/sun/syndication/unittest/TestOpsRSS20.java index 54c9064..82a13bc 100644 --- a/src/test/java/com/sun/syndication/unittest/TestOpsRSS20.java +++ b/src/test/java/com/sun/syndication/unittest/TestOpsRSS20.java @@ -1,10 +1,11 @@ package com.sun.syndication.unittest; /** - * + * *

+ * * @author Alejandro Abdelnur - * + * */ public class TestOpsRSS20 extends FeedOpsTest { diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03.java index 70ae98e..817cf25 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03.java @@ -4,64 +4,65 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndContent; -import com.sun.syndication.io.impl.DateParser; - -import java.util.List; import java.util.Date; +import java.util.List; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.io.impl.DateParser; /** * @author pat - * + * */ public class TestSyndFeedAtom03 extends SyndFeedTest { - public TestSyndFeedAtom03() { - super("atom_0.3"); - } + public TestSyndFeedAtom03() { + super("atom_0.3"); + } - protected TestSyndFeedAtom03(String type) { + protected TestSyndFeedAtom03(final String type) { super(type); } - protected TestSyndFeedAtom03(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedAtom03(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } + @Override public void testTitle() throws Exception { - assertProperty(getCachedSyndFeed().getTitle(),"feed.title"); + assertProperty(this.getCachedSyndFeed().getTitle(), "feed.title"); } + @Override public void testLink() throws Exception { - assertProperty( getCachedSyndFeed().getLink(),"feed.link^href"); + assertProperty(this.getCachedSyndFeed().getLink(), "feed.link^href"); } public void getAuthor() throws Exception { - assertProperty(getCachedSyndFeed().getAuthor(),"feed.author.name"); + assertProperty(this.getCachedSyndFeed().getAuthor(), "feed.author.name"); } public void testCopyright() throws Exception { - assertProperty(getCachedSyndFeed().getCopyright(),"feed.copyright"); + assertProperty(this.getCachedSyndFeed().getCopyright(), "feed.copyright"); } + @Override public void testPublishedDate() throws Exception { - Date d = DateParser.parseW3CDateTime("2000-01-01T00:00:00Z"); - assertEquals(getCachedSyndFeed().getPublishedDate(),d); + final Date d = DateParser.parseW3CDateTime("2000-01-01T00:00:00Z"); + assertEquals(this.getCachedSyndFeed().getPublishedDate(), d); } - - protected void _testEntry(int i) throws Exception { - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); - assertProperty(entry.getTitle(),"feed.entry["+i+"].title"); - assertProperty(entry.getLink(),"feed.entry["+i+"].link^href"); - assertProperty(entry.getAuthor(),"feed.entry["+i+"].author.name"); - Date d = DateParser.parseW3CDateTime("2000-0"+(i+1)+"-01T00:00:00Z"); - assertEquals(entry.getPublishedDate(),d); - assertProperty(entry.getDescription().getValue(),"feed.entry["+i+"].summary"); - assertProperty(((SyndContent)entry.getContents().get(0)).getValue(),"feed.entry["+i+"].content[0]"); - assertProperty(((SyndContent)entry.getContents().get(1)).getValue(),"feed.entry["+i+"].content[1]"); + protected void _testEntry(final int i) throws Exception { + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); + assertProperty(entry.getTitle(), "feed.entry[" + i + "].title"); + assertProperty(entry.getLink(), "feed.entry[" + i + "].link^href"); + assertProperty(entry.getAuthor(), "feed.entry[" + i + "].author.name"); + final Date d = DateParser.parseW3CDateTime("2000-0" + (i + 1) + "-01T00:00:00Z"); + assertEquals(entry.getPublishedDate(), d); + assertProperty(entry.getDescription().getValue(), "feed.entry[" + i + "].summary"); + assertProperty(entry.getContents().get(0).getValue(), "feed.entry[" + i + "].content[0]"); + assertProperty(entry.getContents().get(1).getValue(), "feed.entry[" + i + "].content[1]"); } public void testEntry0() throws Exception { @@ -72,32 +73,37 @@ public class TestSyndFeedAtom03 extends SyndFeedTest { _testEntry(1); } - public void testDescription() throws Exception { - assertEqualsStr("feed.tagline", getCachedSyndFeed().getDescription()); - } + @Override + public void testDescription() throws Exception { + assertEqualsStr("feed.tagline", this.getCachedSyndFeed().getDescription()); + } - public void testEntryLink() throws Exception { - assertEqualsStr("feed.entry[0].link^href", getEntryLink(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("feed.entry[1].link^href", getEntryLink(getCachedSyndFeed().getEntries().get(1))); - } - - public void testLanguage() throws Exception { - // not supported - } - - public void testImage() throws Exception { - // not supported - } - - public void testEntryTitle() throws Exception { - assertEqualsStr("feed.entry[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("feed.entry[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); - } - - public void testEntryDescription() throws Exception { - assertEqualsStr("feed.entry[0].summary", getEntryDescription(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("feed.entry[1].summary", getEntryDescription(getCachedSyndFeed().getEntries().get(1))); - } - + @Override + public void testEntryLink() throws Exception { + assertEqualsStr("feed.entry[0].link^href", getEntryLink(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("feed.entry[1].link^href", getEntryLink(this.getCachedSyndFeed().getEntries().get(1))); + } + + @Override + public void testLanguage() throws Exception { + // not supported + } + + @Override + public void testImage() throws Exception { + // not supported + } + + @Override + public void testEntryTitle() throws Exception { + assertEqualsStr("feed.entry[0].title", getEntryTitle(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("feed.entry[1].title", getEntryTitle(this.getCachedSyndFeed().getEntries().get(1))); + } + + @Override + public void testEntryDescription() throws Exception { + assertEqualsStr("feed.entry[0].summary", getEntryDescription(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("feed.entry[1].summary", getEntryDescription(this.getCachedSyndFeed().getEntries().get(1))); + } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03DCSyModules.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03DCSyModules.java index a37f447..64bd3b6 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03DCSyModules.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom03DCSyModules.java @@ -6,21 +6,19 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.feed.module.DCModule; -import com.sun.syndication.feed.module.SyModule; -import com.sun.syndication.feed.module.DCSubject; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.io.impl.DateParser; - import java.util.Date; import java.util.List; +import com.sun.syndication.feed.module.DCModule; +import com.sun.syndication.feed.module.SyModule; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.io.impl.DateParser; /** * @author pat - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments */ public class TestSyndFeedAtom03DCSyModules extends TestSyndFeedAtom03 { @@ -28,71 +26,75 @@ public class TestSyndFeedAtom03DCSyModules extends TestSyndFeedAtom03 { super("atom_0.3", "atom_0.3_DC_Sy.xml"); } - protected TestSyndFeedAtom03DCSyModules(String type) { + protected TestSyndFeedAtom03DCSyModules(final String type) { super(type); } - protected TestSyndFeedAtom03DCSyModules(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedAtom03DCSyModules(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } public void testModules() throws Exception { - DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI); + final DCModule dc = (DCModule) this.getCachedSyndFeed().getModule(DCModule.URI); assertNotNull(dc); - SyModule sy = (SyModule) getCachedSyndFeed().getModule(SyModule.URI); + final SyModule sy = (SyModule) this.getCachedSyndFeed().getModule(SyModule.URI); assertNotNull(sy); } public void testFeedDCModule() throws Exception { - DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI); - _testDCModule(dc,"feed.",false,0); + final DCModule dc = (DCModule) this.getCachedSyndFeed().getModule(DCModule.URI); + _testDCModule(dc, "feed.", false, 0); } - protected void _testDCModule(DCModule dc,String prefix,boolean isEntry,int index) throws Exception { + protected void _testDCModule(final DCModule dc, final String prefix, final boolean isEntry, final int index) throws Exception { assertNotNull(dc); - assertProperty(dc.getTitle(),prefix+"dc:title"); + assertProperty(dc.getTitle(), prefix + "dc:title"); - assertProperty(dc.getCreator(),prefix+"dc:creator"); // Convenience method + assertProperty(dc.getCreator(), prefix + "dc:creator"); // Convenience + // method - assertProperty(((DCSubject)dc.getSubjects().get(0)).getValue(),prefix+"dc:subject[0]"); - String taxo0 = ((DCSubject)dc.getSubjects().get(0)).getTaxonomyUri(); - if (taxo0!=null) { - assertProperty(taxo0,prefix+"dc:subject[0].taxo:topic^resource"); + assertProperty(dc.getSubjects().get(0).getValue(), prefix + "dc:subject[0]"); + final String taxo0 = dc.getSubjects().get(0).getTaxonomyUri(); + if (taxo0 != null) { + assertProperty(taxo0, prefix + "dc:subject[0].taxo:topic^resource"); } - assertProperty(((DCSubject)dc.getSubjects().get(1)).getValue(),prefix+"dc:subject[1]"); - String taxo1 = ((DCSubject)dc.getSubjects().get(1)).getTaxonomyUri(); - if (taxo1!=null) { - assertProperty(taxo1,prefix+"dc:subject[1].taxo:topic^resource"); + assertProperty(dc.getSubjects().get(1).getValue(), prefix + "dc:subject[1]"); + final String taxo1 = dc.getSubjects().get(1).getTaxonomyUri(); + if (taxo1 != null) { + assertProperty(taxo1, prefix + "dc:subject[1].taxo:topic^resource"); } - assertProperty(dc.getDescription(),prefix+"dc:description"); - assertProperty(dc.getPublisher(),prefix+"dc:publisher"); - assertProperty((String)dc.getContributors().get(0),prefix+"dc:contributor[0]"); - assertProperty((String)dc.getContributors().get(1),prefix+"dc:contributor[1]"); - Date date = DateParser.parseW3CDateTime("2000-0"+(index+1)+"-01T00:00:00Z"); - assertEquals(dc.getDate(),date); - assertProperty(dc.getType(),prefix+"dc:type"); - assertProperty(dc.getFormat(),prefix+"dc:format"); - assertProperty(dc.getIdentifier(),prefix+"dc:identifier"); - assertProperty(dc.getSource(),prefix+"dc:source"); - assertProperty(dc.getLanguage(),prefix+"dc:language"); - assertProperty(dc.getRelation(),prefix+"dc:relation"); - assertProperty(dc.getCoverage(),prefix+"dc:coverage"); + assertProperty(dc.getDescription(), prefix + "dc:description"); + assertProperty(dc.getPublisher(), prefix + "dc:publisher"); + assertProperty(dc.getContributors().get(0), prefix + "dc:contributor[0]"); + assertProperty(dc.getContributors().get(1), prefix + "dc:contributor[1]"); + final Date date = DateParser.parseW3CDateTime("2000-0" + (index + 1) + "-01T00:00:00Z"); + assertEquals(dc.getDate(), date); + assertProperty(dc.getType(), prefix + "dc:type"); + assertProperty(dc.getFormat(), prefix + "dc:format"); + assertProperty(dc.getIdentifier(), prefix + "dc:identifier"); + assertProperty(dc.getSource(), prefix + "dc:source"); + assertProperty(dc.getLanguage(), prefix + "dc:language"); + assertProperty(dc.getRelation(), prefix + "dc:relation"); + assertProperty(dc.getCoverage(), prefix + "dc:coverage"); if (isEntry) { - assertProperty(dc.getRights(),prefix+"dc:rights"); - } - else { - assertProperty(dc.getRights(),prefix+"copyright"); // in header is convenience method + assertProperty(dc.getRights(), prefix + "dc:rights"); + } else { + assertProperty(dc.getRights(), prefix + "copyright"); // in + // header + // is + // convenience + // method } } public void testFeedSyModule() throws Exception { - SyModule sy = (SyModule) getCachedSyndFeed().getModule(SyModule.URI); + final SyModule sy = (SyModule) this.getCachedSyndFeed().getModule(SyModule.URI); assertNotNull(sy); - assertEquals(sy.getUpdatePeriod(),SyModule.HOURLY); - assertEquals(sy.getUpdateFrequency(),100); - Date date = DateParser.parseW3CDateTime("2001-01-01T01:00+00:00"); - assertEquals(sy.getUpdateBase(),date); + assertEquals(sy.getUpdatePeriod(), SyModule.HOURLY); + assertEquals(sy.getUpdateFrequency(), 100); + final Date date = DateParser.parseW3CDateTime("2001-01-01T01:00+00:00"); + assertEquals(sy.getUpdateBase(), date); } public void testEntriesDCModule() throws Exception { @@ -100,15 +102,16 @@ public class TestSyndFeedAtom03DCSyModules extends TestSyndFeedAtom03 { _testEntryDCModule(1); } - protected void _testEntryDCModule(int i) throws Exception { - List entries = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) entries.get(i); - DCModule dc = (DCModule) entry.getModule(DCModule.URI); - _testDCModule(dc,"feed.entry["+i+"].",true,i); + protected void _testEntryDCModule(final int i) throws Exception { + final List entries = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = entries.get(i); + final DCModule dc = (DCModule) entry.getModule(DCModule.URI); + _testDCModule(dc, "feed.entry[" + i + "].", true, i); } - public void testLanguage() throws Exception { - assertEqualsStr("feed.dc:language", getCachedSyndFeed().getLanguage()); - } + @Override + public void testLanguage() throws Exception { + assertEqualsStr("feed.dc:language", this.getCachedSyndFeed().getLanguage()); + } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10.java index a553cc0..d2a4f93 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10.java @@ -7,11 +7,7 @@ package com.sun.syndication.unittest; import java.util.Date; import java.util.List; -import org.jdom2.Element; - import com.sun.syndication.feed.atom.Entry; -import com.sun.syndication.feed.synd.SyndContent; -import com.sun.syndication.feed.synd.SyndEnclosure; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndLink; import com.sun.syndication.io.impl.DateParser; @@ -19,117 +15,125 @@ import com.sun.syndication.io.impl.DateParser; /** * @author pat * @author Dave Johnson (modified for Atom 1.0) - * + * */ public class TestSyndFeedAtom10 extends TestSyndFeedAtom03 { - public TestSyndFeedAtom10() { - super("atom_1.0"); - } + public TestSyndFeedAtom10() { + super("atom_1.0"); + } - protected TestSyndFeedAtom10(String type) { + protected TestSyndFeedAtom10(final String type) { super(type); } - protected TestSyndFeedAtom10(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedAtom10(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } + @Override public void testTitle() throws Exception { - assertProperty(getCachedSyndFeed().getTitle(),"feed.title"); - assertProperty(getCachedSyndFeed().getTitleEx().getValue(),"feed.title"); - assertEquals("html", getCachedSyndFeed().getTitleEx().getType()); - - List altLinks = getCachedSyndFeed().getLinks(); + assertProperty(this.getCachedSyndFeed().getTitle(), "feed.title"); + assertProperty(this.getCachedSyndFeed().getTitleEx().getValue(), "feed.title"); + assertEquals("html", this.getCachedSyndFeed().getTitleEx().getType()); + + final List altLinks = this.getCachedSyndFeed().getLinks(); assertEquals(3, altLinks.size()); - - assertEquals("http://example.com/blog", ((SyndLink)altLinks.get(0)).getHref()); - assertEquals("text/html", ((SyndLink)altLinks.get(0)).getType()); - - assertEquals("http://example.com/blog_plain", ((SyndLink)altLinks.get(1)).getHref()); - assertEquals("text/plain", ((SyndLink)altLinks.get(1)).getType()); + + assertEquals("http://example.com/blog", altLinks.get(0).getHref()); + assertEquals("text/html", altLinks.get(0).getType()); + + assertEquals("http://example.com/blog_plain", altLinks.get(1).getHref()); + assertEquals("text/plain", altLinks.get(1).getType()); } + @Override public void testLink() throws Exception { - assertEquals( getCachedSyndFeed().getLink(),"http://example.com/blog"); + assertEquals(this.getCachedSyndFeed().getLink(), "http://example.com/blog"); } + @Override public void getAuthor() throws Exception { - assertProperty(getCachedSyndFeed().getAuthor(),"feed.author.name"); + assertProperty(this.getCachedSyndFeed().getAuthor(), "feed.author.name"); } + @Override public void testCopyright() throws Exception { - assertProperty(getCachedSyndFeed().getCopyright(),"feed.copyright"); + assertProperty(this.getCachedSyndFeed().getCopyright(), "feed.copyright"); } public void testForeignMarkup() throws Exception { - assertEquals(1, ((List)getCachedSyndFeed().getForeignMarkup()).size()); + assertEquals(1, this.getCachedSyndFeed().getForeignMarkup().size()); } + @Override public void testPublishedDate() throws Exception { - Date d = DateParser.parseW3CDateTime("2000-01-01T00:00:00Z"); - assertEquals(getCachedSyndFeed().getPublishedDate(),d); + final Date d = DateParser.parseW3CDateTime("2000-01-01T00:00:00Z"); + assertEquals(this.getCachedSyndFeed().getPublishedDate(), d); } + @Override + protected void _testEntry(final int i) throws Exception { + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); - protected void _testEntry(int i) throws Exception { - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); + assertProperty(entry.getTitle(), "feed.entry[" + i + "].title"); + assertProperty(entry.getTitleEx().getValue(), "feed.entry[" + i + "].title"); + assertEquals("text", entry.getTitleEx().getType()); - assertProperty(entry.getTitle(),"feed.entry["+i+"].title"); - assertProperty(entry.getTitleEx().getValue(),"feed.entry["+i+"].title"); - assertEquals("text",entry.getTitleEx().getType()); - assertEquals("http://example.com/blog/entry" + (i + 1), entry.getLink()); - assertEquals(((SyndEnclosure)entry.getEnclosures().get(0)).getUrl(),"http://example.com/blog/enclosure"+(i+1)+".gif"); - assertProperty(entry.getAuthor(),"feed.entry["+i+"].author.name"); - Date d = DateParser.parseW3CDateTime("2000-0"+(i+1)+"-01T01:00:00Z"); - assertEquals(entry.getPublishedDate(),d); - assertProperty(entry.getDescription().getValue(),"feed.entry["+i+"].summary"); - assertProperty(((SyndContent)entry.getContents().get(0)).getValue(),"feed.entry["+i+"].content[0]"); - assertEquals(1, ((List)entry.getForeignMarkup()).size()); - + assertEquals(entry.getEnclosures().get(0).getUrl(), "http://example.com/blog/enclosure" + (i + 1) + ".gif"); + assertProperty(entry.getAuthor(), "feed.entry[" + i + "].author.name"); + final Date d = DateParser.parseW3CDateTime("2000-0" + (i + 1) + "-01T01:00:00Z"); + assertEquals(entry.getPublishedDate(), d); + assertProperty(entry.getDescription().getValue(), "feed.entry[" + i + "].summary"); + assertProperty(entry.getContents().get(0).getValue(), "feed.entry[" + i + "].content[0]"); + assertEquals(1, entry.getForeignMarkup().size()); + if (i == 0) { - List links = entry.getLinks(); + final List links = entry.getLinks(); assertEquals(4, links.size()); - assertEquals("http://example.com/blog/entry1", ((SyndLink)links.get(0)).getHref()); - assertEquals("text/html", ((SyndLink)links.get(0)).getType()); + assertEquals("http://example.com/blog/entry1", links.get(0).getHref()); + assertEquals("text/html", links.get(0).getType()); - assertEquals("http://example.com/blog/entry1_plain", ((SyndLink)links.get(1)).getHref()); - assertEquals("text/plain", ((SyndLink)links.get(1)).getType()); - - SyndLink slink = (SyndLink)entry.getLinks().get(3); - assertTrue(slink.getHref().startsWith("tag:")); + assertEquals("http://example.com/blog/entry1_plain", links.get(1).getHref()); + assertEquals("text/plain", links.get(1).getType()); + + final SyndLink slink = entry.getLinks().get(3); + assertTrue(slink.getHref().startsWith("tag:")); } else { - SyndLink slink = (SyndLink)entry.getLinks().get(2); - assertTrue(slink.getHref().startsWith("tag:")); - + final SyndLink slink = entry.getLinks().get(2); + assertTrue(slink.getHref().startsWith("tag:")); + } } + @Override public void testEntry0() throws Exception { _testEntry(0); } + @Override public void testEntry1() throws Exception { _testEntry(1); } - public void testEntryLink() throws Exception { - assertEquals("http://example.com/blog/entry1", getEntryLink(getCachedSyndFeed().getEntries().get(0))); - assertEquals("http://example.com/blog/entry2", getEntryLink(getCachedSyndFeed().getEntries().get(1))); - } - + @Override + public void testEntryLink() throws Exception { + assertEquals("http://example.com/blog/entry1", getEntryLink(this.getCachedSyndFeed().getEntries().get(0))); + assertEquals("http://example.com/blog/entry2", getEntryLink(this.getCachedSyndFeed().getEntries().get(1))); + } + public void testPreservedWireItems() throws Exception { - SyndEntry syndEntry1 = (SyndEntry) getCachedSyndFeed(true).getEntries().get(0); - Object o = syndEntry1.getWireEntry(); - assertNotNull(o); - assertTrue(o instanceof Entry); - if (o instanceof Entry) { - Entry entry = (Entry) o; - assertEquals("atom_1.0.feed.entry[0].rights", entry.getRights()); - } - } - + final SyndEntry syndEntry1 = this.getCachedSyndFeed(true).getEntries().get(0); + final Object o = syndEntry1.getWireEntry(); + assertNotNull(o); + assertTrue(o instanceof Entry); + if (o instanceof Entry) { + final Entry entry = (Entry) o; + assertEquals("atom_1.0.feed.entry[0].rights", entry.getRights()); + } + } + } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Bray.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Bray.java index 7852259..c489e46 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Bray.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Bray.java @@ -6,32 +6,36 @@ import com.sun.syndication.io.impl.Atom10Parser; public class TestSyndFeedAtom10Bray extends FeedTest { + @Override protected void setUp() throws Exception { super.setUp(); Atom10Parser.setResolveURIs(true); } + @Override protected void tearDown() throws Exception { Atom10Parser.setResolveURIs(false); super.tearDown(); } - - public TestSyndFeedAtom10Bray() { - super("atom_1.0_bray.xml"); - } - public void testFeedURI() throws Exception { - SyndFeed feed = getSyndFeed(false); - assertEquals("Bad URL: "+feed.getUri(), "http://www.example.com/blog", feed.getUri()); - } - public void testEntry1URI() throws Exception { - SyndFeed feed = getSyndFeed(false); - SyndEntry entry = (SyndEntry)feed.getEntries().get(0); - assertEquals("Bad URL: "+entry.getLink(), "http://www.example.com/blog/2006-11-05/entry1", entry.getLink()); - } - public void testEntry2URI() throws Exception { - SyndFeed feed = getSyndFeed(false); - SyndEntry entry = (SyndEntry)feed.getEntries().get(1); - assertEquals("Bad URL: "+entry.getLink(), "http://www.example.com/blog/2006-11-02/entry2", entry.getLink()); - } + public TestSyndFeedAtom10Bray() { + super("atom_1.0_bray.xml"); + } + + public void testFeedURI() throws Exception { + final SyndFeed feed = getSyndFeed(false); + assertEquals("Bad URL: " + feed.getUri(), "http://www.example.com/blog", feed.getUri()); + } + + public void testEntry1URI() throws Exception { + final SyndFeed feed = getSyndFeed(false); + final SyndEntry entry = feed.getEntries().get(0); + assertEquals("Bad URL: " + entry.getLink(), "http://www.example.com/blog/2006-11-05/entry1", entry.getLink()); + } + + public void testEntry2URI() throws Exception { + final SyndFeed feed = getSyndFeed(false); + final SyndEntry entry = feed.getEntries().get(1); + assertEquals("Bad URL: " + entry.getLink(), "http://www.example.com/blog/2006-11-02/entry2", entry.getLink()); + } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Ruby.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Ruby.java index fa3743d..b44652f 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Ruby.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10Ruby.java @@ -6,32 +6,36 @@ import com.sun.syndication.io.impl.Atom10Parser; public class TestSyndFeedAtom10Ruby extends FeedTest { + @Override protected void setUp() throws Exception { super.setUp(); Atom10Parser.setResolveURIs(true); } + @Override protected void tearDown() throws Exception { Atom10Parser.setResolveURIs(false); super.tearDown(); } - - public TestSyndFeedAtom10Ruby() { - super("atom_1.0_ruby.xml"); - } - public void testFeedURI() throws Exception { - SyndFeed feed = getSyndFeed(false); - assertEquals("http://www.example.com/blog", feed.getUri()); - } - public void testEntry1URI() throws Exception { - SyndFeed feed = getSyndFeed(false); - SyndEntry entry = (SyndEntry)feed.getEntries().get(0); + public TestSyndFeedAtom10Ruby() { + super("atom_1.0_ruby.xml"); + } + + public void testFeedURI() throws Exception { + final SyndFeed feed = getSyndFeed(false); + assertEquals("http://www.example.com/blog", feed.getUri()); + } + + public void testEntry1URI() throws Exception { + final SyndFeed feed = getSyndFeed(false); + final SyndEntry entry = feed.getEntries().get(0); assertEquals("http://www.example.com/blog/bloggy-blog", entry.getLink()); - } - public void testEntry2URI() throws Exception { - SyndFeed feed = getSyndFeed(false); - SyndEntry entry = (SyndEntry)feed.getEntries().get(1); + } + + public void testEntry2URI() throws Exception { + final SyndFeed feed = getSyndFeed(false); + final SyndEntry entry = feed.getEntries().get(1); assertEquals("http://www.example.com/frog/froggy-frog", entry.getLink()); - } + } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10b.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10b.java index fbff42f..c9016ba 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10b.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10b.java @@ -1,36 +1,36 @@ package com.sun.syndication.unittest; +import java.util.List; + import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.impl.Atom10Parser; -import java.util.List; - public class TestSyndFeedAtom10b extends FeedTest { - + @Override protected void setUp() throws Exception { super.setUp(); Atom10Parser.setResolveURIs(true); } + @Override protected void tearDown() throws Exception { Atom10Parser.setResolveURIs(false); super.tearDown(); } public TestSyndFeedAtom10b() { - super("atom_1.0_b.xml"); - } + super("atom_1.0_b.xml"); + } - public void testXmlBaseConformance() throws Exception { - SyndFeed feed = getSyndFeed(false); - List entries = feed.getEntries(); - for (int index = 0; index < entries.size(); index++) { - SyndEntry entry = (SyndEntry) entries.get(index); - assertEquals( - "Incorrect URI: " + entry.getLink() + " in entry [" + entry.getTitle() + "]", - "http://example.org/tests/base/result.html", entry.getLink()); - } - } + public void testXmlBaseConformance() throws Exception { + final SyndFeed feed = getSyndFeed(false); + final List entries = feed.getEntries(); + for (int index = 0; index < entries.size(); index++) { + final SyndEntry entry = entries.get(index); + assertEquals("Incorrect URI: " + entry.getLink() + " in entry [" + entry.getTitle() + "]", "http://example.org/tests/base/result.html", + entry.getLink()); + } + } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10prefix.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10prefix.java index 01c2b0b..a09fb34 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10prefix.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedAtom10prefix.java @@ -1,23 +1,22 @@ package com.sun.syndication.unittest; import com.sun.syndication.feed.atom.Feed; -import com.sun.syndication.feed.atom.Link; public class TestSyndFeedAtom10prefix extends FeedTest { - public TestSyndFeedAtom10prefix() { - super("atom_1.0_prefix.xml"); - } + public TestSyndFeedAtom10prefix() { + super("atom_1.0_prefix.xml"); + } public void testTitle() throws Exception { - Feed feed = (Feed) getWireFeed(); + final Feed feed = (Feed) getWireFeed(); assertEquals("1", feed.getId()); - assertEquals("xxx1", ((Link)feed.getOtherLinks().get(0)).getRel()); - assertEquals("xxx2", ((Link)feed.getOtherLinks().get(1)).getRel()); - assertEquals("xxx11", ((Link)feed.getOtherLinks().get(0)).getType()); - assertEquals("xxx22", ((Link)feed.getOtherLinks().get(1)).getType()); - assertEquals("http://foo.com/1", ((Link)feed.getOtherLinks().get(0)).getHref()); - assertEquals("http://foo.com/2", ((Link)feed.getOtherLinks().get(1)).getHref()); + assertEquals("xxx1", feed.getOtherLinks().get(0).getRel()); + assertEquals("xxx2", feed.getOtherLinks().get(1).getRel()); + assertEquals("xxx11", feed.getOtherLinks().get(0).getType()); + assertEquals("xxx22", feed.getOtherLinks().get(1).getType()); + assertEquals("http://foo.com/1", feed.getOtherLinks().get(0).getHref()); + assertEquals("http://foo.com/2", feed.getOtherLinks().get(1).getHref()); } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS090.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS090.java index f1a1806..e719029 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS090.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS090.java @@ -4,13 +4,13 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.feed.synd.SyndEntry; - import java.util.List; +import com.sun.syndication.feed.synd.SyndEntry; + /** * @author pat - * + * */ public class TestSyndFeedRSS090 extends SyndFeedTest { @@ -18,45 +18,48 @@ public class TestSyndFeedRSS090 extends SyndFeedTest { super("rss_0.9"); } - protected TestSyndFeedRSS090(String type) { + protected TestSyndFeedRSS090(final String type) { super(type); } - protected TestSyndFeedRSS090(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS090(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } + @Override public void testTitle() throws Exception { - assertProperty(getCachedSyndFeed().getTitle(),"channel.title"); + assertProperty(this.getCachedSyndFeed().getTitle(), "channel.title"); } + @Override public void testLink() throws Exception { - assertProperty( getCachedSyndFeed().getLink(),"channel.link"); + assertProperty(this.getCachedSyndFeed().getLink(), "channel.link"); } + @Override public void testDescription() throws Exception { - assertProperty(getCachedSyndFeed().getDescription(),"channel.description"); + assertProperty(this.getCachedSyndFeed().getDescription(), "channel.description"); } public void testImageTitle() throws Exception { - assertProperty(getCachedSyndFeed().getImage().getTitle(),"image.title"); + assertProperty(this.getCachedSyndFeed().getImage().getTitle(), "image.title"); } public void testImageUrl() throws Exception { - assertProperty(getCachedSyndFeed().getImage().getUrl(),"image.url"); + assertProperty(this.getCachedSyndFeed().getImage().getUrl(), "image.url"); } public void testImageLink() throws Exception { - assertProperty(getCachedSyndFeed().getImage().getLink(),"image.link"); + assertProperty(this.getCachedSyndFeed().getImage().getLink(), "image.link"); } - protected void _testItem(int i) throws Exception { - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); - assertProperty(entry.getTitle(),"item["+i+"].title"); - assertProperty(entry.getLink(),"item["+i+"].link"); + protected void _testItem(final int i) throws Exception { + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); + assertProperty(entry.getTitle(), "item[" + i + "].title"); + assertProperty(entry.getLink(), "item[" + i + "].link"); - _testUri(entry,i); + _testUri(entry, i); } public void testItem0() throws Exception { @@ -67,39 +70,47 @@ public class TestSyndFeedRSS090 extends SyndFeedTest { _testItem(1); } - protected void _testUri(SyndEntry entry,int i) throws Exception { - assertProperty(entry.getUri(),"item["+i+"].link"); + protected void _testUri(final SyndEntry entry, final int i) throws Exception { + assertProperty(entry.getUri(), "item[" + i + "].link"); } - + + @Override public void testLanguage() throws Exception { - // not supported + // not supported } - + + @Override public void testPublishedDate() throws Exception { - // not supported + // not supported } + @Override public void testImage() throws Exception { - // not supported + // not supported + } + + @Override + public void testEntryTitle() throws Exception { + assertEqualsStr("item[0].title", getEntryTitle(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("item[1].title", getEntryTitle(this.getCachedSyndFeed().getEntries().get(1))); + } + + @Override + public void testEntryDescription() throws Exception { + // I think this should be should work, but it can't seem to find the + // description + // System.out.println(((SyndEntry)getCachedSyndFeed().getEntries().get(0)).getDescription()); + } + + @Override + public void testEntryLink() throws Exception { + assertEqualsStr("item[0].link", getEntryLink(this.getCachedSyndFeed().getEntries().get(0))); + assertEqualsStr("item[1].link", getEntryLink(this.getCachedSyndFeed().getEntries().get(1))); + } + + @Override + public void testEntryPublishedDate() throws Exception { + // not supported } - public void testEntryTitle() throws Exception { - assertEqualsStr("item[0].title", getEntryTitle(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("item[1].title", getEntryTitle(getCachedSyndFeed().getEntries().get(1))); - } - - public void testEntryDescription() throws Exception { - // I think this should be should work, but it can't seem to find the description - //System.out.println(((SyndEntry)getCachedSyndFeed().getEntries().get(0)).getDescription()); - } - - public void testEntryLink() throws Exception { - assertEqualsStr("item[0].link", getEntryLink(getCachedSyndFeed().getEntries().get(0))); - assertEqualsStr("item[1].link", getEntryLink(getCachedSyndFeed().getEntries().get(1))); - } - - public void testEntryPublishedDate() throws Exception { - // not supported - } - } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091N.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091N.java index a8e9b40..403435b 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091N.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091N.java @@ -4,75 +4,75 @@ */ package com.sun.syndication.unittest; +import java.util.Date; +import java.util.List; + import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.io.impl.DateParser; -import java.util.List; -import java.util.Date; - /** * @author pat - * + * */ public class TestSyndFeedRSS091N extends SyndFeedTest { - public TestSyndFeedRSS091N() { - super("rss_0.91N", "rss_0.91N.xml"); - } + public TestSyndFeedRSS091N() { + super("rss_0.91N", "rss_0.91N.xml"); + } - protected TestSyndFeedRSS091N(String type) { + protected TestSyndFeedRSS091N(final String type) { super(type); } - protected TestSyndFeedRSS091N(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS091N(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } + @Override public void testLanguage() throws Exception { - assertProperty(getCachedSyndFeed().getLanguage(),"channel.language"); + assertProperty(this.getCachedSyndFeed().getLanguage(), "channel.language"); } public void testCopyright() throws Exception { - assertProperty(getCachedSyndFeed().getCopyright(),"channel.copyright"); + assertProperty(this.getCachedSyndFeed().getCopyright(), "channel.copyright"); } + @Override public void testPublishedDate() throws Exception { - Date d = DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"); - assertEquals(getCachedSyndFeed().getPublishedDate(),d); + final Date d = DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"); + assertEquals(this.getCachedSyndFeed().getPublishedDate(), d); } public void testAuthor() throws Exception { - assertProperty(getCachedSyndFeed().getAuthor(),"channel.managingEditor"); + assertProperty(this.getCachedSyndFeed().getAuthor(), "channel.managingEditor"); } public void testImageTitle() throws Exception { - assertProperty(getCachedSyndFeed().getImage().getTitle(),"channel.image.title"); + assertProperty(this.getCachedSyndFeed().getImage().getTitle(), "channel.image.title"); } public void testImageUrl() throws Exception { - assertProperty(getCachedSyndFeed().getImage().getUrl(),"channel.image.url"); + assertProperty(this.getCachedSyndFeed().getImage().getUrl(), "channel.image.url"); } public void testImageLink() throws Exception { - assertProperty(getCachedSyndFeed().getImage().getLink(),"channel.image.link"); + assertProperty(this.getCachedSyndFeed().getImage().getLink(), "channel.image.link"); } public void testImageDescription() throws Exception { - assertProperty(getCachedSyndFeed().getImage().getDescription(),"channel.image.description"); + assertProperty(this.getCachedSyndFeed().getImage().getDescription(), "channel.image.description"); } - protected void _testItem(int i) throws Exception { - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); - assertProperty(entry.getTitle(),"channel.item["+i+"].title"); - assertProperty(entry.getLink(),"channel.item["+i+"].link"); - assertProperty(entry.getDescription().getValue(),"channel.item["+i+"].description"); + protected void _testItem(final int i) throws Exception { + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); + assertProperty(entry.getTitle(), "channel.item[" + i + "].title"); + assertProperty(entry.getLink(), "channel.item[" + i + "].link"); + assertProperty(entry.getDescription().getValue(), "channel.item[" + i + "].description"); } - protected void _testUri(SyndEntry entry,int i) throws Exception { - assertProperty(entry.getUri(),"channel.item["+i+"].link"); + protected void _testUri(final SyndEntry entry, final int i) throws Exception { + assertProperty(entry.getUri(), "channel.item[" + i + "].link"); } - - } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091U.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091U.java index a09c37b..5555226 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091U.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS091U.java @@ -6,7 +6,7 @@ package com.sun.syndication.unittest; /** * @author pat - * + * */ public class TestSyndFeedRSS091U extends TestSyndFeedRSS091N { diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092.java index 8c89b27..7a4cdef 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092.java @@ -4,17 +4,17 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.feed.synd.SyndCategory; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndEnclosure; - +import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.HashSet; + +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndEnclosure; +import com.sun.syndication.feed.synd.SyndEntry; /** * @author pat - * + * */ public class TestSyndFeedRSS092 extends TestSyndFeedRSS091N { @@ -22,46 +22,45 @@ public class TestSyndFeedRSS092 extends TestSyndFeedRSS091N { super("rss_0.92"); } - protected TestSyndFeedRSS092(String type) { + protected TestSyndFeedRSS092(final String type) { super(type); } - protected TestSyndFeedRSS092(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS092(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } - protected void _testItem(int i) throws Exception { + @Override + protected void _testItem(final int i) throws Exception { super._testItem(i); - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); - assertProperty(entry.getTitle(),"channel.item["+i+"].title"); - assertProperty(entry.getLink(),"channel.item["+i+"].link"); - assertProperty(entry.getDescription().getValue(),"channel.item["+i+"].description"); - _testCategories(entry.getCategories(),"channel.item["+i+"]"); - _testEnclosures(entry.getEnclosures(),"channel.item["+i+"]"); + assertProperty(entry.getTitle(), "channel.item[" + i + "].title"); + assertProperty(entry.getLink(), "channel.item[" + i + "].link"); + assertProperty(entry.getDescription().getValue(), "channel.item[" + i + "].description"); + _testCategories(entry.getCategories(), "channel.item[" + i + "]"); + _testEnclosures(entry.getEnclosures(), "channel.item[" + i + "]"); } - protected void _testCategories(List cats,String prefix) throws Exception { - Set s1 = new HashSet(); - Set s2 = new HashSet(); - for (int i=0;i cats, final String prefix) throws Exception { + final Set s1 = new HashSet(); + final Set s2 = new HashSet(); + for (int i = 0; i < cats.size(); i++) { + final SyndCategory cat = cats.get(i); + s1.add(cat.getTaxonomyUri() + " " + cat.getName()); + s2.add(getPrefix() + "." + prefix + ".category[" + i + "]^domain" + " " + getPrefix() + "." + prefix + ".category[" + i + "]"); } assertTrue(s1.equals(s2)); } - protected void _testEnclosures(List encs,String prefix) throws Exception { - Set s1 = new HashSet(); - Set s2 = new HashSet(); - for (int i=0;i encs, final String prefix) throws Exception { + final Set s1 = new HashSet(); + final Set s2 = new HashSet(); + for (int i = 0; i < encs.size(); i++) { + final SyndEnclosure enc = encs.get(i); + s1.add(enc.getUrl() + " " + enc.getType() + " " + enc.getLength()); + s2.add(getPrefix() + "." + prefix + ".enclousure[" + i + "]^url" + " " + getPrefix() + "." + prefix + ".enclousure[" + i + "]^type" + " " + "100"); } assertTrue(s1.equals(s2)); } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092Alt.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092Alt.java index 8d27db4..a1ff584 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092Alt.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS092Alt.java @@ -1,31 +1,29 @@ - package com.sun.syndication.unittest; -import com.sun.syndication.feed.synd.SyndEnclosure; - +import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.HashSet; + +import com.sun.syndication.feed.synd.SyndEnclosure; public class TestSyndFeedRSS092Alt extends TestSyndFeedRSS092 { public TestSyndFeedRSS092Alt() { - this("rss_0.92","rss_0.92_alt.xml"); + this("rss_0.92", "rss_0.92_alt.xml"); } - protected TestSyndFeedRSS092Alt(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS092Alt(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } - protected void _testEnclosures(List encs,String prefix) throws Exception { - Set s1 = new HashSet(); - Set s2 = new HashSet(); - for (int i=0;i encs, final String prefix) throws Exception { + final Set s1 = new HashSet(); + final Set s2 = new HashSet(); + for (int i = 0; i < encs.size(); i++) { + final SyndEnclosure enc = encs.get(i); + s1.add(enc.getUrl() + " " + enc.getType() + " " + enc.getLength()); + s2.add(getPrefix() + "." + prefix + ".enclousure[" + i + "]^url" + " " + getPrefix() + "." + prefix + ".enclousure[" + i + "]^type" + " " + "0"); } assertTrue(s1.equals(s2)); } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS093.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS093.java index 8020d91..38b9c89 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS093.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS093.java @@ -4,46 +4,48 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.io.impl.DateParser; -import com.sun.syndication.feed.synd.SyndEntry; - import java.util.Date; import java.util.List; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.io.impl.DateParser; + /** * @author pat - * + * */ public class TestSyndFeedRSS093 extends TestSyndFeedRSS092 { - public TestSyndFeedRSS093() { - super("rss_0.93"); - } + public TestSyndFeedRSS093() { + super("rss_0.93"); + } - protected TestSyndFeedRSS093(String type) { + protected TestSyndFeedRSS093(final String type) { super(type); } - protected TestSyndFeedRSS093(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS093(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } - protected void _testItem(int i) throws Exception { + @Override + protected void _testItem(final int i) throws Exception { super._testItem(i); - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); - Date d = DateParser.parseRFC822("Mon, 0"+(i+1)+" Jan 2001 00:00:00 GMT"); - assertEquals(entry.getPublishedDate(),d); - _testDescriptionType(entry,i); + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); + final Date d = DateParser.parseRFC822("Mon, 0" + (i + 1) + " Jan 2001 00:00:00 GMT"); + assertEquals(entry.getPublishedDate(), d); + _testDescriptionType(entry, i); } - protected void _testDescriptionType(SyndEntry entry,int i) throws Exception { - assertProperty(entry.getDescription().getType(),"channel.item["+i+"].description^type"); + protected void _testDescriptionType(final SyndEntry entry, final int i) throws Exception { + assertProperty(entry.getDescription().getType(), "channel.item[" + i + "].description^type"); + } + + @Override + public void testEntryPublishedDate() throws Exception { + assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(this.getCachedSyndFeed().getEntries().get(0))); + assertEquals(DateParser.parseRFC822("Tue, 02 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(this.getCachedSyndFeed().getEntries().get(1))); } - public void testEntryPublishedDate() throws Exception { - assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(0))); - assertEquals(DateParser.parseRFC822("Tue, 02 Jan 2001 00:00:00 GMT"), getEntryPublishedDate(getCachedSyndFeed().getEntries().get(1))); - } - } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS094.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS094.java index 9ada491..8e8e038 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS094.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS094.java @@ -4,53 +4,48 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.feed.synd.SyndEntry; - import java.util.List; +import com.sun.syndication.feed.synd.SyndEntry; /** * @author pat - * + * */ public class TestSyndFeedRSS094 extends TestSyndFeedRSS093 { public TestSyndFeedRSS094() { super("rss_0.94"); } - protected TestSyndFeedRSS094(String type) { + protected TestSyndFeedRSS094(final String type) { super(type); } - protected TestSyndFeedRSS094(String feedType, String feedFileName) { + protected TestSyndFeedRSS094(final String feedType, final String feedFileName) { super(feedType, feedFileName); } public void testCategories() throws Exception { - _testCategories(getCachedSyndFeed().getCategories(), "channel"); - } - - - - @Override - protected void _testDescriptionType(SyndEntry entry, int i) - throws Exception { + _testCategories(this.getCachedSyndFeed().getCategories(), "channel"); } @Override - protected void _testItem(int i) throws Exception { + protected void _testDescriptionType(final SyndEntry entry, final int i) throws Exception { + } + + @Override + protected void _testItem(final int i) throws Exception { super._testItem(i); - List items = getCachedSyndFeed() - .getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); assertProperty(entry.getAuthor(), "channel.item[" + i + "].author"); - + } @Override - protected void _testUri(SyndEntry entry, int i) throws Exception { + protected void _testUri(final SyndEntry entry, final int i) throws Exception { assertProperty(entry.getUri(), "channel.item[" + i + "].guid"); } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10.java index fbb9113..7cc864c 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10.java @@ -4,43 +4,43 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.feed.synd.SyndContent; -import com.sun.syndication.feed.synd.SyndEntry; - import java.util.List; +import com.sun.syndication.feed.synd.SyndEntry; /** * @author pat - * + * */ public class TestSyndFeedRSS10 extends TestSyndFeedRSS090 { - public TestSyndFeedRSS10() { - super("rss_1.0"); - } + public TestSyndFeedRSS10() { + super("rss_1.0"); + } - protected TestSyndFeedRSS10(String type) { + protected TestSyndFeedRSS10(final String type) { super(type); } - protected TestSyndFeedRSS10(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS10(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } public void testUri() throws Exception { - assertProperty(getCachedSyndFeed().getUri(),"channel.uri"); + assertProperty(this.getCachedSyndFeed().getUri(), "channel.uri"); } - protected void _testItem(int i) throws Exception { + @Override + protected void _testItem(final int i) throws Exception { super._testItem(i); - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); - assertProperty(entry.getDescription().getValue(),"item["+i+"].description"); - assertProperty(((SyndContent)entry.getContents().get(0)).getValue(), "item["+i+"].content"); + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); + assertProperty(entry.getDescription().getValue(), "item[" + i + "].description"); + assertProperty(entry.getContents().get(0).getValue(), "item[" + i + "].content"); } - - protected void _testUri(SyndEntry entry, int i) throws Exception { - assertProperty(entry.getUri(),"channel.items["+i+"]^rdf:resource"); + + @Override + protected void _testUri(final SyndEntry entry, final int i) throws Exception { + assertProperty(entry.getUri(), "channel.items[" + i + "]^rdf:resource"); } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCMulti.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCMulti.java index 1af2f00..c4bf998 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCMulti.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCMulti.java @@ -1,17 +1,16 @@ package com.sun.syndication.unittest; +import java.util.Date; +import java.util.List; + import com.sun.syndication.feed.module.DCModule; -import com.sun.syndication.feed.module.DCSubject; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.io.impl.DateParser; -import java.util.List; -import java.util.Date; - - /** * Test case for the multi-valued DublinCore module elements. *

+ * * @author Paul Dlug */ public class TestSyndFeedRSS10DCMulti extends TestSyndFeedRSS10 { @@ -20,74 +19,74 @@ public class TestSyndFeedRSS10DCMulti extends TestSyndFeedRSS10 { super("rss_1.0", "rss_1.0_DC_multi.xml"); } - protected TestSyndFeedRSS10DCMulti(String type) { + protected TestSyndFeedRSS10DCMulti(final String type) { super(type); } - protected TestSyndFeedRSS10DCMulti(String feedType, String feedFileName) { + protected TestSyndFeedRSS10DCMulti(final String feedType, final String feedFileName) { super(feedType, feedFileName); } public void testChannelDCModule() throws Exception { - DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI); + final DCModule dc = (DCModule) this.getCachedSyndFeed().getModule(DCModule.URI); _testDCModule(dc, "channel."); } - protected void _testDCModule(DCModule dc,String prefix) throws Exception { + protected void _testDCModule(final DCModule dc, final String prefix) throws Exception { assertNotNull(dc); - - assertProperty((String)dc.getTitles().get(0), prefix + "dc:title[0]"); - assertProperty((String)dc.getTitles().get(1), prefix + "dc:title[1]"); - - assertProperty((String)dc.getCreators().get(0), prefix + "dc:creator[0]"); - assertProperty((String)dc.getCreators().get(1), prefix + "dc:creator[1]"); - - assertProperty(((DCSubject)dc.getSubjects().get(0)).getValue(), prefix + "dc:subject[0]"); - String taxo0 = ((DCSubject)dc.getSubjects().get(0)).getTaxonomyUri(); + + assertProperty(dc.getTitles().get(0), prefix + "dc:title[0]"); + assertProperty(dc.getTitles().get(1), prefix + "dc:title[1]"); + + assertProperty(dc.getCreators().get(0), prefix + "dc:creator[0]"); + assertProperty(dc.getCreators().get(1), prefix + "dc:creator[1]"); + + assertProperty(dc.getSubjects().get(0).getValue(), prefix + "dc:subject[0]"); + final String taxo0 = dc.getSubjects().get(0).getTaxonomyUri(); if (taxo0 != null) { assertProperty(taxo0, prefix + "dc:subject[0].taxo:topic^resource"); } - assertProperty(((DCSubject)dc.getSubjects().get(1)).getValue(), prefix + "dc:subject[1]"); - String taxo1 = ((DCSubject)dc.getSubjects().get(1)).getTaxonomyUri(); + assertProperty(dc.getSubjects().get(1).getValue(), prefix + "dc:subject[1]"); + final String taxo1 = dc.getSubjects().get(1).getTaxonomyUri(); if (taxo1 != null) { assertProperty(taxo1, prefix + "dc:subject[1].taxo:topic^resource"); } - - assertProperty((String)dc.getDescriptions().get(0), prefix + "dc:description[0]"); - assertProperty((String)dc.getDescriptions().get(1), prefix + "dc:description[1]"); - - assertProperty((String)dc.getPublishers().get(0), prefix + "dc:publisher[0]"); - assertProperty((String)dc.getPublishers().get(1), prefix + "dc:publisher[1]"); - - assertProperty((String)dc.getContributors().get(0),prefix + "dc:contributor[0]"); - assertProperty((String)dc.getContributors().get(1),prefix + "dc:contributor[1]"); - Date date = DateParser.parseW3CDateTime("2001-01-01T00:00+00:00"); - assertEquals((Date)dc.getDates().get(0), date); - assertEquals((Date)dc.getDates().get(1), date); - - assertProperty((String)dc.getTypes().get(0), prefix + "dc:type[0]"); - assertProperty((String)dc.getTypes().get(1), prefix +"dc:type[1]"); - - assertProperty((String)dc.getFormats().get(0), prefix + "dc:format[0]"); - assertProperty((String)dc.getFormats().get(1), prefix + "dc:format[1]"); - - assertProperty((String)dc.getIdentifiers().get(0), prefix + "dc:identifier[0]"); - assertProperty((String)dc.getIdentifiers().get(1), prefix + "dc:identifier[1]"); - - assertProperty((String)dc.getSources().get(0), prefix + "dc:source[0]"); - assertProperty((String)dc.getSources().get(1), prefix + "dc:source[1]"); - - assertProperty((String)dc.getLanguages().get(0), prefix + "dc:language[0]"); - assertProperty((String)dc.getLanguages().get(1), prefix + "dc:language[1]"); - - assertProperty((String)dc.getRelations().get(0), prefix + "dc:relation[0]"); - assertProperty((String)dc.getRelations().get(1), prefix + "dc:relation[1]"); - - assertProperty((String)dc.getCoverages().get(0), prefix + "dc:coverage[0]"); - assertProperty((String)dc.getCoverages().get(1), prefix + "dc:coverage[1]"); - - assertProperty((String)dc.getRightsList().get(0), prefix + "dc:rights[0]"); - assertProperty((String)dc.getRightsList().get(1), prefix + "dc:rights[1]"); + + assertProperty(dc.getDescriptions().get(0), prefix + "dc:description[0]"); + assertProperty(dc.getDescriptions().get(1), prefix + "dc:description[1]"); + + assertProperty(dc.getPublishers().get(0), prefix + "dc:publisher[0]"); + assertProperty(dc.getPublishers().get(1), prefix + "dc:publisher[1]"); + + assertProperty(dc.getContributors().get(0), prefix + "dc:contributor[0]"); + assertProperty(dc.getContributors().get(1), prefix + "dc:contributor[1]"); + final Date date = DateParser.parseW3CDateTime("2001-01-01T00:00+00:00"); + assertEquals(dc.getDates().get(0), date); + assertEquals(dc.getDates().get(1), date); + + assertProperty(dc.getTypes().get(0), prefix + "dc:type[0]"); + assertProperty(dc.getTypes().get(1), prefix + "dc:type[1]"); + + assertProperty(dc.getFormats().get(0), prefix + "dc:format[0]"); + assertProperty(dc.getFormats().get(1), prefix + "dc:format[1]"); + + assertProperty(dc.getIdentifiers().get(0), prefix + "dc:identifier[0]"); + assertProperty(dc.getIdentifiers().get(1), prefix + "dc:identifier[1]"); + + assertProperty(dc.getSources().get(0), prefix + "dc:source[0]"); + assertProperty(dc.getSources().get(1), prefix + "dc:source[1]"); + + assertProperty(dc.getLanguages().get(0), prefix + "dc:language[0]"); + assertProperty(dc.getLanguages().get(1), prefix + "dc:language[1]"); + + assertProperty(dc.getRelations().get(0), prefix + "dc:relation[0]"); + assertProperty(dc.getRelations().get(1), prefix + "dc:relation[1]"); + + assertProperty(dc.getCoverages().get(0), prefix + "dc:coverage[0]"); + assertProperty(dc.getCoverages().get(1), prefix + "dc:coverage[1]"); + + assertProperty(dc.getRightsList().get(0), prefix + "dc:rights[0]"); + assertProperty(dc.getRightsList().get(1), prefix + "dc:rights[1]"); } public void testItemsDCModule() throws Exception { @@ -95,10 +94,10 @@ public class TestSyndFeedRSS10DCMulti extends TestSyndFeedRSS10 { _testItemDCModule(1); } - protected void _testItemDCModule(int i) throws Exception { - List entries = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) entries.get(i); - DCModule dc = (DCModule) entry.getModule(DCModule.URI); + protected void _testItemDCModule(final int i) throws Exception { + final List entries = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = entries.get(i); + final DCModule dc = (DCModule) entry.getModule(DCModule.URI); _testDCModule(dc, "item[" + i + "]."); } } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCSyModules.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCSyModules.java index 8f141d4..c276512 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCSyModules.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS10DCSyModules.java @@ -6,21 +6,19 @@ */ package com.sun.syndication.unittest; +import java.util.Date; +import java.util.List; + import com.sun.syndication.feed.module.DCModule; import com.sun.syndication.feed.module.SyModule; -import com.sun.syndication.feed.module.DCSubject; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.io.impl.DateParser; -import java.util.List; -import java.util.Date; - - /** * @author pat - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments */ public class TestSyndFeedRSS10DCSyModules extends TestSyndFeedRSS10 { @@ -28,56 +26,56 @@ public class TestSyndFeedRSS10DCSyModules extends TestSyndFeedRSS10 { super("rss_1.0", "rss_1.0_DC_Sy.xml"); } - protected TestSyndFeedRSS10DCSyModules(String type) { + protected TestSyndFeedRSS10DCSyModules(final String type) { super(type); } - protected TestSyndFeedRSS10DCSyModules(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS10DCSyModules(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } public void testChannelDCModule() throws Exception { - DCModule dc = (DCModule) getCachedSyndFeed().getModule(DCModule.URI); - _testDCModule(dc,"channel."); + final DCModule dc = (DCModule) this.getCachedSyndFeed().getModule(DCModule.URI); + _testDCModule(dc, "channel."); } - protected void _testDCModule(DCModule dc,String prefix) throws Exception { + protected void _testDCModule(final DCModule dc, final String prefix) throws Exception { assertNotNull(dc); - assertProperty(dc.getTitle(),prefix+"dc:title"); - assertProperty(dc.getCreator(),prefix+"dc:creator"); - assertProperty(((DCSubject)dc.getSubjects().get(0)).getValue(),prefix+"dc:subject[0]"); - String taxo0 = ((DCSubject)dc.getSubjects().get(0)).getTaxonomyUri(); - if (taxo0!=null) { - assertProperty(taxo0,prefix+"dc:subject[0].taxo:topic^resource"); + assertProperty(dc.getTitle(), prefix + "dc:title"); + assertProperty(dc.getCreator(), prefix + "dc:creator"); + assertProperty(dc.getSubjects().get(0).getValue(), prefix + "dc:subject[0]"); + final String taxo0 = dc.getSubjects().get(0).getTaxonomyUri(); + if (taxo0 != null) { + assertProperty(taxo0, prefix + "dc:subject[0].taxo:topic^resource"); } - assertProperty(((DCSubject)dc.getSubjects().get(1)).getValue(),prefix+"dc:subject[1]"); - String taxo1 = ((DCSubject)dc.getSubjects().get(1)).getTaxonomyUri(); - if (taxo1!=null) { - assertProperty(taxo1,prefix+"dc:subject[1].taxo:topic^resource"); + assertProperty(dc.getSubjects().get(1).getValue(), prefix + "dc:subject[1]"); + final String taxo1 = dc.getSubjects().get(1).getTaxonomyUri(); + if (taxo1 != null) { + assertProperty(taxo1, prefix + "dc:subject[1].taxo:topic^resource"); } - assertProperty(dc.getDescription(),prefix+"dc:description"); - assertProperty(dc.getPublisher(),prefix+"dc:publisher"); - assertProperty((String)dc.getContributors().get(0),prefix+"dc:contributor[0]"); - assertProperty((String)dc.getContributors().get(1),prefix+"dc:contributor[1]"); - Date date = DateParser.parseW3CDateTime("2001-01-01T00:00+00:00"); - assertEquals(dc.getDate(),date); - assertProperty(dc.getType(),prefix+"dc:type"); - assertProperty(dc.getFormat(),prefix+"dc:format"); - assertProperty(dc.getIdentifier(),prefix+"dc:identifier"); - assertProperty(dc.getSource(),prefix+"dc:source"); - assertProperty(dc.getLanguage(),prefix+"dc:language"); - assertProperty(dc.getRelation(),prefix+"dc:relation"); - assertProperty(dc.getCoverage(),prefix+"dc:coverage"); - assertProperty(dc.getRights(),prefix+"dc:rights"); + assertProperty(dc.getDescription(), prefix + "dc:description"); + assertProperty(dc.getPublisher(), prefix + "dc:publisher"); + assertProperty(dc.getContributors().get(0), prefix + "dc:contributor[0]"); + assertProperty(dc.getContributors().get(1), prefix + "dc:contributor[1]"); + final Date date = DateParser.parseW3CDateTime("2001-01-01T00:00+00:00"); + assertEquals(dc.getDate(), date); + assertProperty(dc.getType(), prefix + "dc:type"); + assertProperty(dc.getFormat(), prefix + "dc:format"); + assertProperty(dc.getIdentifier(), prefix + "dc:identifier"); + assertProperty(dc.getSource(), prefix + "dc:source"); + assertProperty(dc.getLanguage(), prefix + "dc:language"); + assertProperty(dc.getRelation(), prefix + "dc:relation"); + assertProperty(dc.getCoverage(), prefix + "dc:coverage"); + assertProperty(dc.getRights(), prefix + "dc:rights"); } public void testChannelSyModule() throws Exception { - SyModule sy = (SyModule) getCachedSyndFeed().getModule(SyModule.URI); + final SyModule sy = (SyModule) this.getCachedSyndFeed().getModule(SyModule.URI); assertNotNull(sy); - assertEquals(sy.getUpdatePeriod(),SyModule.HOURLY); - assertEquals(sy.getUpdateFrequency(),100); - Date date = DateParser.parseW3CDateTime("2001-01-01T01:00+00:00"); - assertEquals(sy.getUpdateBase(),date); + assertEquals(sy.getUpdatePeriod(), SyModule.HOURLY); + assertEquals(sy.getUpdateFrequency(), 100); + final Date date = DateParser.parseW3CDateTime("2001-01-01T01:00+00:00"); + assertEquals(sy.getUpdateBase(), date); } public void testItemsDCModule() throws Exception { @@ -85,13 +83,12 @@ public class TestSyndFeedRSS10DCSyModules extends TestSyndFeedRSS10 { _testItemDCModule(1); } - protected void _testItemDCModule(int i) throws Exception { - List entries = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) entries.get(i); - DCModule dc = (DCModule) entry.getModule(DCModule.URI); - _testDCModule(dc,"item["+i+"]."); + protected void _testItemDCModule(final int i) throws Exception { + final List entries = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = entries.get(i); + final DCModule dc = (DCModule) entry.getModule(DCModule.URI); + _testDCModule(dc, "item[" + i + "]."); } - } diff --git a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS20.java b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS20.java index 1f7338c..1fa3579 100644 --- a/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS20.java +++ b/src/test/java/com/sun/syndication/unittest/TestSyndFeedRSS20.java @@ -9,58 +9,60 @@ import java.util.List; import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.rss.Channel; import com.sun.syndication.feed.rss.Item; -import com.sun.syndication.feed.synd.SyndContent; import com.sun.syndication.feed.synd.SyndEntry; /** * @author pat - * + * */ public class TestSyndFeedRSS20 extends TestSyndFeedRSS094 { - public TestSyndFeedRSS20() { - super("rss_2.0"); - } + public TestSyndFeedRSS20() { + super("rss_2.0"); + } - protected TestSyndFeedRSS20(String type) { + protected TestSyndFeedRSS20(final String type) { super(type); } - protected TestSyndFeedRSS20(String feedType,String feedFileName) { - super(feedType,feedFileName); + protected TestSyndFeedRSS20(final String feedType, final String feedFileName) { + super(feedType, feedFileName); } - - protected void _testItem(int i) throws Exception { + + @Override + protected void _testItem(final int i) throws Exception { super._testItem(i); - List items = getCachedSyndFeed().getEntries(); - SyndEntry entry = (SyndEntry) items.get(i); - assertProperty(((SyndContent)entry.getContents().get(0)).getValue(), "channel.item["+i+"].content"); + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); + assertProperty(entry.getContents().get(0).getValue(), "channel.item[" + i + "].content"); } - + /** - * Test we can get to RSS attributes which aren't exposed in the SyndEntry object + * Test we can get to RSS attributes which aren't exposed in the SyndEntry + * object + * * @throws Exception */ public void testPreservedWireItems() throws Exception { - SyndEntry syndEntry1 = (SyndEntry) getCachedSyndFeed(true).getEntries().get(0); - Object o = syndEntry1.getWireEntry(); - assertNotNull(o); - assertTrue(o instanceof Item); - if (o instanceof Item) { - Item item = (Item) o; - assertEquals("rss_2.0.channel.item[0].comments", item.getComments()); - } + final SyndEntry syndEntry1 = this.getCachedSyndFeed(true).getEntries().get(0); + final Object o = syndEntry1.getWireEntry(); + assertNotNull(o); + assertTrue(o instanceof Item); + if (o instanceof Item) { + final Item item = (Item) o; + assertEquals("rss_2.0.channel.item[0].comments", item.getComments()); + } } - + public void testPreserveWireFeedComments() throws Exception { - WireFeed wf = getCachedSyndFeed(true).originalWireFeed(); - assertNotNull(wf); - assertTrue(wf instanceof Channel); - if (wf instanceof Channel) { - Channel channel = (Channel) wf; - assertEquals("rss_2.0.channel.item[0].comments", ((Item)channel.getItems().get(0)).getComments()); - assertEquals("rss_2.0.channel.item[1].comments", ((Item)channel.getItems().get(1)).getComments()); - } + final WireFeed wf = this.getCachedSyndFeed(true).originalWireFeed(); + assertNotNull(wf); + assertTrue(wf instanceof Channel); + if (wf instanceof Channel) { + final Channel channel = (Channel) wf; + assertEquals("rss_2.0.channel.item[0].comments", channel.getItems().get(0).getComments()); + assertEquals("rss_2.0.channel.item[1].comments", channel.getItems().get(1).getComments()); + } } } diff --git a/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java b/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java index 443b520..256955e 100644 --- a/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java +++ b/src/test/java/com/sun/syndication/unittest/TestXmlFixerReader.java @@ -16,142 +16,149 @@ */ package com.sun.syndication.unittest; -import com.sun.syndication.io.XmlReader; -import com.sun.syndication.io.impl.XmlFixerReader; +import java.io.BufferedReader; +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.StringReader; +import java.io.Writer; + import junit.framework.TestCase; + import org.jdom2.input.SAXBuilder; -import java.io.*; +import com.sun.syndication.io.XmlReader; +import com.sun.syndication.io.impl.XmlFixerReader; /** * @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 testAmpHandling() throws Exception { - String input = "& &aa &"; - BufferedReader reader = new BufferedReader(new XmlFixerReader(new StringReader(input))); - String output = reader.readLine(); + final String input = "& &aa &"; + final BufferedReader reader = new BufferedReader(new XmlFixerReader(new StringReader(input))); + final String output = reader.readLine(); reader.close(); assertEquals("& &aa &", output); } 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 + "'¥ú¥"); _testValidEntities("ΠΡ#913;Ρ"); - _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("Π&Rhox;#913;Ρ"); - _testInvalidEntities(XML_PROLOG+"Π&Rhox;ΑΡ"); - _testInvalidEntities(" \n"+XML_PROLOG+"Π&Rhox;ΑΡ"); - + _testInvalidEntities(XML_PROLOG + "Π&Rhox;ΑΡ"); + _testInvalidEntities(" \n" + XML_PROLOG + "Π&Rhox;ΑΡ"); + _testInvalidEntities("'¥x50;¥"); - _testInvalidEntities(XML_PROLOG+"'¥x50;¥"); - _testInvalidEntities(" \n"+XML_PROLOG+"'¥x50;¥"); + _testInvalidEntities(XML_PROLOG + "'¥x50;¥"); + _testInvalidEntities(" \n" + XML_PROLOG + "'¥x50;¥"); _testInvalidEntities("ΠΡ x13;Ρ"); - _testInvalidEntities(XML_PROLOG+"ΠΡ x13;Ρ"); - _testInvalidEntities(" \n"+XML_PROLOG+"ΠΡ x13;Ρ"); + _testInvalidEntities(XML_PROLOG + "ΠΡ x13;Ρ"); + _testInvalidEntities(" \n" + XML_PROLOG + "ΠΡ x13;Ρ"); } - 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/com/sun/syndication/unittest/TestXmlReader.java b/src/test/java/com/sun/syndication/unittest/TestXmlReader.java index 63c68d6..98ed21e 100644 --- a/src/test/java/com/sun/syndication/unittest/TestXmlReader.java +++ b/src/test/java/com/sun/syndication/unittest/TestXmlReader.java @@ -16,17 +16,23 @@ */ package com.sun.syndication.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 { private static final String XML5 = "xml-prolog-encoding-spaced-single-quotes"; @@ -35,25 +41,25 @@ public class TestXmlReader extends TestCase { private static final String XML2 = "xml-prolog"; private static final String XML1 = "xml"; - 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",XML1,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", XML1, encoding, encoding); + XmlReader xmlReader = new XmlReader(is, false); + assertEquals(xmlReader.getEncoding(), "UTF-8"); - is = getXmlStream("no-bom",XML2,encoding,encoding); + is = getXmlStream("no-bom", XML2, encoding, encoding); xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),"UTF-8"); + assertEquals(xmlReader.getEncoding(), "UTF-8"); - is = getXmlStream("no-bom",XML3,encoding,encoding); + is = getXmlStream("no-bom", XML3, encoding, encoding); xmlReader = new XmlReader(is); - assertEquals(xmlReader.getEncoding(),encoding); + assertEquals(xmlReader.getEncoding(), encoding); is = getXmlStream("no-bom", XML4, encoding, encoding); xmlReader = new XmlReader(is); @@ -64,16 +70,15 @@ public class TestXmlReader extends TestCase { assertEquals(xmlReader.getEncoding(), encoding); } - protected void _testRawNoBomInvalid(String encoding) throws Exception { - InputStream is = getXmlStream("no-bom",XML3,encoding,encoding); + protected void _testRawNoBomInvalid(final String encoding) throws Exception { + final InputStream is = getXmlStream("no-bom", XML3, 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"); @@ -81,27 +86,25 @@ public class TestXmlReader extends TestCase { _testRawNoBomValid("ISO-8859-1"); } - protected void _testRawBomValid(String encoding) throws Exception { - InputStream is = getXmlStream(encoding+"-bom",XML3,encoding,encoding); - XmlReader xmlReader = new XmlReader(is,false); + protected void _testRawBomValid(final String encoding) throws Exception { + final InputStream is = getXmlStream(encoding + "-bom", XML3, 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,XML3,streamEnc,prologEnc); + protected void _testRawBomInvalid(final String bomEnc, final String streamEnc, final String prologEnc) throws Exception { + final InputStream is = getXmlStream(bomEnc, XML3, 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"); @@ -109,43 +112,43 @@ 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",null); - _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", null); + _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); _testAlternateDefaultEncoding("application/xml", "UTF-8-bom", "UTF-8", null, null); _testAlternateDefaultEncoding("application/xml", "no-bom", "US-ASCII", null, "US-ASCII"); @@ -154,122 +157,114 @@ public class TestXmlReader extends TestCase { _testAlternateDefaultEncoding("text/xml", "no-bom", "US-ASCII", null, "US-ASCII"); _testAlternateDefaultEncoding("text/xml", "no-bom", "US-ASCII", null, "UTF-8"); - _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 _testAlternateDefaultEncoding(String cT, String bomEnc, String streamEnc, String prologEnc, String alternateEnc) throws Exception { + public void _testAlternateDefaultEncoding(final String cT, final String bomEnc, final String streamEnc, final String prologEnc, final String alternateEnc) + throws Exception { try { - InputStream is = getXmlStream(bomEnc, (prologEnc == null) ? XML1 : XML3, streamEnc, prologEnc); + final InputStream is = getXmlStream(bomEnc, prologEnc == null ? XML1 : XML3, streamEnc, prologEnc); XmlReader.setDefaultEncoding(alternateEnc); - XmlReader xmlReader = new XmlReader(is, cT, false); + 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 { - String enc = (alternateEnc != null) ? alternateEnc : streamEnc; + // we can not assert things here becuase UTF-8, US-ASCII and + // ISO-8859-1 look alike for the chars used for detection + } else { + final String enc = alternateEnc != null ? alternateEnc : streamEnc; assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); } - } - finally { + } finally { XmlReader.setDefaultEncoding(null); } } - public void _testHttpValid(String cT, String bomEnc, String streamEnc, String prologEnc) throws Exception { - InputStream is = getXmlStream(bomEnc,(prologEnc==null)?XML1 :XML3,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 ? XML1 : XML3, 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); + // 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)?XML2 :XML3,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 ? XML2 : XML3, streamEnc, prologEnc); try { - new XmlReader(is,cT,false); - fail("It should have failed for HTTP Content-type "+cT+", BOM "+bomEnc+", streamEnc "+streamEnc+" and prologEnc "+prologEnc); + 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)?XML2 :XML3,streamEnc,prologEnc); - XmlReader xmlReader = new XmlReader(is,cT,true); - assertEquals(xmlReader.getEncoding(),shouldbe); } - private static final String ENCODING_ATTRIBUTE_XML = - " \n" + - "\n" + - "\n" + - " \n" + - " \n" + "\n" + "\n" + + " \n" + " 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 = new MessageFormat("{2}"); + private static final MessageFormat XML_WITH_PROLOG = new MessageFormat("\n{2}"); private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING_DOUBLE_QUOTES = new MessageFormat( "\n{2}"); private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING_SINGLE_QUOTES = new MessageFormat( "\n{2}"); - private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING_SPACED_SINGLE_QUOTES = new MessageFormat( + private static final MessageFormat XML_WITH_PROLOG_AND_ENCODING_SPACED_SINGLE_QUOTES = 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(); @@ -282,29 +277,29 @@ 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(String bomType,String xmlType,String streamEnc,String prologEnc) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - int[] bom = (int[]) BOMs.get(bomType); - if (bom==null) { + 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 = 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++) { + for (int i = 0; i < 10000; i++) { writer.write("\n"); } writer.write("\n"); @@ -313,5 +308,4 @@ public class TestXmlReader extends TestCase { return new ByteArrayInputStream(baos.toByteArray()); } - } diff --git a/src/test/java/com/sun/syndication/unittest/issues/Issue1Test.java b/src/test/java/com/sun/syndication/unittest/issues/Issue1Test.java index 4868ee2..d8d401f 100644 --- a/src/test/java/com/sun/syndication/unittest/issues/Issue1Test.java +++ b/src/test/java/com/sun/syndication/unittest/issues/Issue1Test.java @@ -16,12 +16,6 @@ */ package com.sun.syndication.unittest.issues; -import com.sun.syndication.io.impl.XmlFixerReader; -import com.sun.syndication.io.XmlReader; -import com.sun.syndication.unittest.SyndFeedTest; - -import org.jdom2.input.SAXBuilder; - import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -32,9 +26,14 @@ import java.io.Reader; import java.io.StringReader; import java.io.Writer; +import org.jdom2.input.SAXBuilder; + +import com.sun.syndication.io.XmlReader; +import com.sun.syndication.io.impl.XmlFixerReader; +import com.sun.syndication.unittest.SyndFeedTest; /** - * + * * @author robert.cooper */ public class Issue1Test extends SyndFeedTest { @@ -45,9 +44,9 @@ public class Issue1Test extends SyndFeedTest { } public void testAmpHandling() throws Exception { - String input = "& &aa &"; - BufferedReader reader = new BufferedReader(new XmlFixerReader(new StringReader(input))); - String output = reader.readLine(); + final String input = "& &aa &"; + final BufferedReader reader = new BufferedReader(new XmlFixerReader(new StringReader(input))); + final String output = reader.readLine(); reader.close(); assertEquals("& &aa &", output); } @@ -104,7 +103,8 @@ public class Issue1Test extends SyndFeedTest { _testValidTrim(" \n ", ""); _testValidTrim(" \n ", XML_PROLOG + ""); - //TODO lorenzo.sm: This test was added to trim \r char (as with \n). Source of "bad" RSS http://www.diariohorizonte.com/rss/71/deportes + // TODO lorenzo.sm: This test was added to trim \r char (as with \n). + // Source of "bad" RSS http://www.diariohorizonte.com/rss/71/deportes _testValidTrim("\r\n", XML_PROLOG + ""); _testInvalidTrim("x", ""); @@ -126,10 +126,9 @@ public class Issue1Test extends SyndFeedTest { } // 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(); @@ -137,40 +136,36 @@ public class Issue1Test extends SyndFeedTest { return new ByteArrayInputStream(baos.toByteArray()); } - protected void _testInvalidEntities(String xmlDoc) - throws Exception { + protected void _testInvalidEntities(final String xmlDoc) throws Exception { try { _testXmlParse("", xmlDoc); assertTrue(false); - } catch (Exception ex) { + } catch (final Exception ex) { } } - protected void _testInvalidTrim(String garbish, String xmlDoc) - throws Exception { + protected void _testInvalidTrim(final String garbish, final String xmlDoc) throws Exception { try { _testXmlParse(garbish, xmlDoc); assertTrue(false); - } catch (Exception ex) { + } catch (final Exception ex) { } } - protected void _testValidEntities(String xmlDoc) throws Exception { + protected void _testValidEntities(final String xmlDoc) throws Exception { _testXmlParse("", xmlDoc); } - protected void _testValidTrim(String garbish, String xmlDoc) - throws Exception { + protected void _testValidTrim(final String garbish, final String xmlDoc) throws Exception { _testXmlParse(garbish, xmlDoc); } - 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); } } diff --git a/src/test/java/com/sun/syndication/unittest/issues/Issue2Test.java b/src/test/java/com/sun/syndication/unittest/issues/Issue2Test.java index fbe1032..0a16501 100644 --- a/src/test/java/com/sun/syndication/unittest/issues/Issue2Test.java +++ b/src/test/java/com/sun/syndication/unittest/issues/Issue2Test.java @@ -17,27 +17,26 @@ package com.sun.syndication.unittest.issues; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.unittest.TestSyndFeedRSS094; import java.util.List; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.unittest.TestSyndFeedRSS094; + /** - * + * * @author robert.cooper */ public class Issue2Test extends TestSyndFeedRSS094 { @Override - protected void _testItem(int i) throws Exception { + protected void _testItem(final int i) throws Exception { super._testItem(i); - List items = getCachedSyndFeed() - .getEntries(); - SyndEntry entry = items.get(i); + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); _testComments(entry, i); } - protected void _testComments(SyndEntry entry, int i) - throws Exception { + protected void _testComments(final SyndEntry entry, final int i) throws Exception { assertProperty(entry.findRelatedLink("comments").getHref(), "rss_0.94.channel.item[" + i + "].comments"); }