Refactored code

This commit is contained in:
Patrick Gotthard 2014-04-17 23:11:59 +02:00
parent ef9345d55e
commit bc845fe0aa
61 changed files with 3204 additions and 3069 deletions

View file

@ -97,6 +97,10 @@
</build>
<dependencies>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-utils</artifactId>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>

View file

@ -18,11 +18,11 @@
package com.sun.syndication.feed;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.jdom2.Element;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.module.Extendable;
import com.sun.syndication.feed.module.Module;
@ -38,13 +38,16 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
* 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
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public abstract class WireFeed implements Cloneable, Serializable, Extendable {
private static final long serialVersionUID = -3608120400805691829L;
private final ObjectBean objBean;
private String feedType;
private String encoding;
private String styleSheet;
@ -53,8 +56,6 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Default constructor, for bean cloning purposes only.
* <p>
*
*/
protected WireFeed() {
objBean = new ObjectBean(this.getClass(), this);
@ -62,10 +63,9 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Creates a feed for a given type.
* <p>
*
*
* @param type of the feed to create.
*
*
*/
protected WireFeed(final String type) {
this();
@ -74,11 +74,10 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -88,20 +87,22 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
if (other == null) {
return false;
}
if (!(other instanceof WireFeed)) {
return false;
}
// can't use foreign markup in equals, due to JDOM equals impl
final List<Element> fm = getForeignMarkup();
setForeignMarkup(((WireFeed) other).getForeignMarkup());
@ -109,6 +110,7 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
// restore foreign markup
setForeignMarkup(fm);
return ret;
}
/**
@ -116,9 +118,9 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -128,9 +130,9 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -140,9 +142,9 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Sets the feedType of a the feed. <b>Do not use</b>, for bean cloning purposes only.
* <p>
*
*
* @param feedType the feedType of the feed.
*
*
*/
public void setFeedType(final String feedType) {
this.feedType = feedType;
@ -150,7 +152,7 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Returns the type of the feed.
*
*
* @return the type of the feed.
*/
public String getFeedType() {
@ -163,9 +165,9 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
* This property is not set by feed parsers. But it is used by feed generators to set the
* encoding in the XML prolog.
* <p>
*
*
* @return the charset encoding of the feed.
*
*
*/
public String getEncoding() {
return encoding;
@ -177,9 +179,9 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
* This property is not set by feed parsers. But it is used by feed generators to set the
* encoding in the XML prolog.
* <p>
*
*
* @param encoding the charset encoding of the feed.
*
*
*/
public void setEncoding(final String encoding) {
this.encoding = encoding;
@ -188,25 +190,22 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Returns the channel modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the channel modules, an empty list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
return modules;
return modules = Lists.createWhenNull(modules);
}
/**
* Sets the channel modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the channel modules to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -216,7 +215,7 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/
@ -228,23 +227,20 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* Returns foreign markup found at channel level.
* <p>
*
*
* @return Opaque object to discourage use
*
*
*/
public List<Element> getForeignMarkup() {
if (foreignMarkup == null) {
foreignMarkup = new ArrayList<Element>();
}
return foreignMarkup;
return foreignMarkup = Lists.createWhenNull(foreignMarkup);
}
/**
* Sets foreign markup found at channel level.
* <p>
*
*
* @param foreignMarkup Opaque object to discourage use
*
*
*/
public void setForeignMarkup(final List<Element> foreignMarkup) {
this.foreignMarkup = foreignMarkup;
@ -252,7 +248,7 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* URL of XSL-Stylesheet.
*
*
* @since 2.0.0
* @return styleSheet URL or {@code null}
*/
@ -262,11 +258,12 @@ public abstract class WireFeed implements Cloneable, Serializable, Extendable {
/**
* URL of XSL-Stylesheet.
*
*
* @since 2.0.0
* @param styleSheet URL or {@code null}
*/
public void setStyleSheet(final String styleSheet) {
this.styleSheet = styleSheet;
}
}

View file

@ -18,15 +18,17 @@ package com.sun.syndication.feed.atom;
import java.io.Serializable;
import com.rometools.utils.Alternatives;
import com.sun.syndication.feed.impl.ObjectBean;
/**
* Bean for category elements of Atom feeds.
* <p>
*
*
* @author Dave Johnson (added for Atom 1.0)
*/
public class Category implements Cloneable, Serializable {
private static final long serialVersionUID = -2034251366664065410L;
private final ObjectBean objBean;
@ -39,7 +41,7 @@ public class Category implements Cloneable, Serializable {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public Category() {
objBean = new ObjectBean(this.getClass(), this);
@ -48,10 +50,10 @@ public class Category implements Cloneable, Serializable {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -62,10 +64,10 @@ public class Category implements Cloneable, Serializable {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -80,9 +82,9 @@ public class Category implements Cloneable, Serializable {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -92,9 +94,9 @@ public class Category implements Cloneable, Serializable {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -104,7 +106,7 @@ public class Category implements Cloneable, Serializable {
/**
* Get label for category.
* <p>
*
*
* @return Label for category.
*/
public String getLabel() {
@ -114,7 +116,7 @@ public class Category implements Cloneable, Serializable {
/**
* Set label for category.
* <p>
*
*
* @param label Label for category.
*/
public void setLabel(final String label) {
@ -124,7 +126,7 @@ public class Category implements Cloneable, Serializable {
/**
* Get Scheme URI for category.
* <p>
*
*
* @return Scheme URI for category.
*/
public String getScheme() {
@ -134,7 +136,7 @@ public class Category implements Cloneable, Serializable {
/**
* Set scheme URI for category.
* <p>
*
*
* @param scheme Scheme URI for category.
*/
public void setScheme(final String scheme) {
@ -146,17 +148,13 @@ public class Category implements Cloneable, Serializable {
}
public String getSchemeResolved() {
if (schemeResolved != null) {
return schemeResolved;
} else {
return scheme;
}
return Alternatives.firstNotNull(schemeResolved, scheme);
}
/**
* Return term for category.
* <p>
*
*
* @return Term for category.
*/
public String getTerm() {
@ -166,10 +164,11 @@ public class Category implements Cloneable, Serializable {
/**
* Set term for category.
* <p>
*
*
* @param term Term for category.
*/
public void setTerm(final String term) {
this.term = term;
}
}

View file

@ -20,16 +20,18 @@ import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import com.rometools.utils.Strings;
import com.sun.syndication.feed.impl.ObjectBean;
/**
* Bean for content elements of Atom feeds.
* <p>
*
*
* @author Alejandro Abdelnur
* @author Dave Johnson (updated for Atom 1.0)
*/
public class Content implements Cloneable, Serializable {
private static final long serialVersionUID = 2036205883043031310L;
private final ObjectBean objBean;
@ -67,7 +69,7 @@ public class Content implements Cloneable, Serializable {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public Content() {
objBean = new ObjectBean(this.getClass(), this);
@ -76,10 +78,10 @@ public class Content implements Cloneable, Serializable {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -90,10 +92,10 @@ public class Content implements Cloneable, Serializable {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -108,9 +110,9 @@ public class Content implements Cloneable, Serializable {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -120,9 +122,9 @@ public class Content implements Cloneable, Serializable {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -134,7 +136,7 @@ public class Content implements Cloneable, Serializable {
* <p>
* The type indicates how the value was/will-be encoded in the XML feed.
* </p>
*
*
* @since Atom 1.0
*/
public String getType() {
@ -146,7 +148,7 @@ public class Content implements Cloneable, Serializable {
* <p>
* The type indicates how the value was/will-be encoded in the XML feed.
* </p>
*
*
* @since Atom 1.0
*/
public void setType(final String type) {
@ -158,7 +160,7 @@ public class Content implements Cloneable, Serializable {
* <p>
* The mode indicates how the value was/will-be encoded in the XML feed.
* <p>
*
*
* @return the content mode, <b>null</b> if none.
*/
public String getMode() {
@ -170,17 +172,14 @@ public class Content implements Cloneable, Serializable {
* <p>
* The mode indicates how the value was/will-be encoded in the XML feed.
* <p>
*
*
* @param mode the content mode, <b>null</b> if none.
*/
public void setMode(String mode) {
if (mode != null) {
mode = mode.toLowerCase();
}
public void setMode(final String mode) {
this.mode = Strings.toLowerCase(mode);
if (mode == null || !MODES.contains(mode)) {
throw new IllegalArgumentException("Invalid mode [" + mode + "]");
}
this.mode = mode;
}
/**
@ -188,9 +187,9 @@ public class Content implements Cloneable, Serializable {
* <p>
* The return value should be decoded.
* <p>
*
*
* @return the content value, <b>null</b> if none.
*
*
*/
public String getValue() {
return value;
@ -201,9 +200,9 @@ public class Content implements Cloneable, Serializable {
* <p>
* The value being set should be decoded.
* <p>
*
*
* @param value the content value, <b>null</b> if none.
*
*
*/
public void setValue(final String value) {
this.value = value;
@ -212,7 +211,7 @@ public class Content implements Cloneable, Serializable {
/**
* Returns the src
* <p>
*
*
* @return Returns the src.
* @since Atom 1.0
*/
@ -223,7 +222,7 @@ public class Content implements Cloneable, Serializable {
/**
* Set the src
* <p>
*
*
* @param src The src to set.
* @since Atom 1.0
*/

View file

@ -17,12 +17,13 @@
package com.sun.syndication.feed.atom;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.jdom2.Element;
import com.rometools.utils.Dates;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.module.Extendable;
import com.sun.syndication.feed.module.Module;
@ -32,12 +33,14 @@ import com.sun.syndication.feed.synd.SyndPerson;
/**
* Bean for entry elements of Atom feeds.
* <p>
*
*
* @author Alejandro Abdelnur
* @author Dave Johnson (updated for Atom 1.0)
*/
public class Entry implements Cloneable, Serializable, Extendable {
private static final long serialVersionUID = 4874483180016783939L;
private Content summary;
private Content title;
private Date created; // Atom 0.3 only
@ -60,7 +63,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public Entry() {
objBean = new ObjectBean(this.getClass(), this);
@ -69,7 +72,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Sets the entry alternate links.
* <p>
*
*
* @param alternateLinks the list of Link elements with the entry alternate links to set, an
* empty list or <b>null</b> if none.
*/
@ -80,22 +83,19 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry alternate links.
* <p>
*
*
* @return a list of Link elements with the entry alternate links, an empty list if none.
*/
public List<Link> getAlternateLinks() {
if (alternateLinks == null) {
alternateLinks = new ArrayList<Link>();
}
return alternateLinks;
return alternateLinks = Lists.createWhenNull(alternateLinks);
}
/**
* Sets the author of the entry.
* <p>
*
*
* @param authors the author of the entry, <b>null</b> if none.
*
*
*/
public void setAuthors(final List<SyndPerson> authors) {
this.authors = authors;
@ -104,21 +104,18 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry author.
* <p>
*
*
* @return the entry author, <b>null</b> if none.
*
*
*/
public List<SyndPerson> getAuthors() {
if (authors == null) {
authors = new ArrayList<SyndPerson>();
}
return authors;
return authors = Lists.createWhenNull(authors);
}
/**
* Set the categories
* <p>
*
*
* @param categories The categories to set.
* @since Atom 1.0
*/
@ -129,21 +126,18 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the categories
* <p>
*
*
* @return Returns the categories.
* @since Atom 1.0
*/
public List<Category> getCategories() {
if (categories == null) {
categories = new ArrayList<Category>();
}
return categories;
return categories = Lists.createWhenNull(categories);
}
/**
* Sets the entry contents.
* <p>
*
*
* @param contents the list of Content elements with the entry contents to set, an empty list or
* <b>null</b> if none.
*/
@ -154,23 +148,20 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry contents.
* <p>
*
*
* @return a list of Content elements with the entry contents, an empty list if none.
*/
public List<Content> getContents() {
if (contents == null) {
contents = new ArrayList<Content>();
}
return contents;
return contents = Lists.createWhenNull(contents);
}
/**
* Sets the entry contributors.
* <p>
*
*
* @param contributors the list of Person elements with the entry contributors to set, an empty
* list or <b>null</b> if none.
*
*
*/
public void setContributors(final List<SyndPerson> contributors) {
this.contributors = contributors;
@ -179,47 +170,40 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry contributors.
* <p>
*
*
* @return a list of Person elements with the entry contributors, an empty list if none.
*
*
*/
public List<SyndPerson> getContributors() {
if (contributors == null) {
contributors = new ArrayList<SyndPerson>();
}
return contributors;
return contributors = Lists.createWhenNull(contributors);
}
/**
* Sets the entry created date (Atom 0.3 only)
* <p>
*
*
* @param created the entry created date, <b>null</b> if none.
*/
public void setCreated(final Date created) {
this.created = new Date(created.getTime());
this.created = Dates.copy(created);
}
/**
* Returns the entry created date (Atom 0.3 only)
* <p>
*
*
* @return the entry created date, <b>null</b> if none.
*/
public Date getCreated() {
if (created == null) {
return null;
} else {
return new Date(created.getTime());
}
return Dates.copy(created);
}
/**
* Sets foreign markup found at entry level.
* <p>
*
*
* @param foreignMarkup Opaque object to discourage use
*
*
*/
public void setForeignMarkup(final List<Element> foreignMarkup) {
this.foreignMarkup = foreignMarkup;
@ -228,23 +212,20 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns foreign markup found at entry level.
* <p>
*
*
* @return list of Opaque object to discourage use
*
*
*/
public List<Element> getForeignMarkup() {
if (foreignMarkup == null) {
foreignMarkup = new ArrayList<Element>();
}
return foreignMarkup;
return foreignMarkup = Lists.createWhenNull(foreignMarkup);
}
/**
* Sets the entry ID.
* <p>
*
*
* @param id the entry ID, <b>null</b> if none.
*
*
*/
public void setId(final String id) {
this.id = id;
@ -253,9 +234,9 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry ID.
* <p>
*
*
* @return the entry ID, <b>null</b> if none.
*
*
*/
public String getId() {
return id;
@ -264,83 +245,64 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Sets the entry issued date (Atom 0.3, maps to {@link #setPublished(java.util.Date)}).
* <p>
*
*
* @param issued the entry issued date, <b>null</b> if none.
*/
public void setIssued(final Date issued) {
if (issued == null) {
published = null;
} else {
published = new Date(issued.getTime());
}
published = Dates.copy(issued);
}
/**
* Returns the entry issued date (Atom 0.3, maps to {@link #getPublished()} ).
* <p>
*
*
* @return the entry issued date, <b>null</b> if none.
*/
public Date getIssued() {
if (published == null) {
return null;
} else {
return new Date(published.getTime());
}
return Dates.copy(published);
}
/**
* 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;
final List<Link> links = getOtherLinks();
for (final Link link : links) {
if ("edit-media".equals(link.getRel())) {
mediaEntry = true;
break;
}
}
return mediaEntry;
}
/**
* Sets the entry modified date (Atom 0.3, maps to {@link #setUpdated(java.util.Date)}).
* <p>
*
*
* @param modified the entry modified date, <b>null</b> if none.
*/
public void setModified(final Date modified) {
if (modified == null) {
updated = null;
} else {
updated = new Date(modified.getTime());
}
updated = Dates.copy(modified);
}
/**
* Returns the entry modified date (Atom 0.3, maps to {@link #getUpdated()} ).
* <p>
*
*
* @return the entry modified date, <b>null</b> if none.
*/
public Date getModified() {
if (updated == null) {
return null;
} else {
return new Date(updated.getTime());
}
return Dates.copy(updated);
}
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/
@ -352,10 +314,10 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Sets the entry modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the entry modules to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -365,22 +327,19 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the entry modules, an emtpy list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
return modules;
return modules = Lists.createWhenNull(modules);
}
/**
* Sets the entry non-alternate links.
* <p>
*
*
* @param otherLinks the list Link elements with the entry non-alternate links to set, an empty
* list or <b>null</b> if none.
*/
@ -391,51 +350,40 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry non-alternate links.
* <p>
*
*
* @return the list of Link elements with the entry non-alternate links to set, an empty list if
* none.
*/
public List<Link> getOtherLinks() {
if (otherLinks == null) {
otherLinks = new ArrayList<Link>();
}
return otherLinks;
return otherLinks = Lists.createWhenNull(otherLinks);
}
/**
* Set the published
* <p>
*
*
* @param published The published to set.
* @since Atom 1.0
*/
public void setPublished(final Date published) {
if (published == null) {
this.published = null;
} else {
this.published = new Date(published.getTime());
}
this.published = Dates.copy(published);
}
/**
* Returns the published
* <p>
*
*
* @return Returns the published.
* @since Atom 1.0
*/
public Date getPublished() {
if (published == null) {
return null;
} else {
return new Date(published.getTime());
}
return Dates.copy(published);
}
/**
* Set the rights
* <p>
*
*
* @param rights The rights to set.
* @since Atom 1.0
*/
@ -446,7 +394,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the rights
* <p>
*
*
* @return Returns the rights.
* @since Atom 1.0
*/
@ -457,7 +405,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Set the source
* <p>
*
*
* @param source The source to set.
*/
public void setSource(final Feed source) {
@ -467,7 +415,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the source
* <p>
*
*
* @return Returns the source.
*/
public Feed getSource() {
@ -477,9 +425,9 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Sets the entry summary.
* <p>
*
*
* @param summary the entry summary, <b>null</b> if none.
*
*
*/
public void setSummary(final Content summary) {
this.summary = summary;
@ -488,9 +436,9 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry summary.
* <p>
*
*
* @return the entry summary, <b>null</b> if none.
*
*
*/
public Content getSummary() {
return summary;
@ -499,39 +447,37 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Sets the entry title.
* <p>
*
*
* @param title the entry title, <b>null</b> if none.
*
*
*/
public void setTitle(final String title) {
if (this.title == null) {
this.title = new Content();
}
this.title.setValue(title);
}
/**
* Returns the entry title.
* <p>
*
*
* @return the entry title, <b>null</b> if none.
*
*
*/
public String getTitle() {
if (title != null) {
return title.getValue();
}
return null;
}
/**
* Sets the entry title as a text construct.
* <p>
*
*
* @param title the entry title, <b>null</b> if none.
*
*
*/
public void setTitleEx(final Content title) {
this.title = title;
@ -540,9 +486,9 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the entry title as a text construct.
* <p>
*
*
* @return the entry title, <b>null</b> if none.
*
*
*/
public Content getTitleEx() {
return title;
@ -551,37 +497,29 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Set the updated
* <p>
*
*
* @param updated The updated to set.
* @since Atom 1.0
*/
public void setUpdated(final Date updated) {
if (updated == null) {
this.updated = null;
} else {
this.updated = new Date(updated.getTime());
}
this.updated = Dates.copy(updated);
}
/**
* Returns the updated
* <p>
*
*
* @return Returns the updated.
* @since Atom 1.0
*/
public Date getUpdated() {
if (updated == null) {
return null;
} else {
return new Date(updated.getTime());
}
return Dates.copy(updated);
}
/**
* Set the xmlBase
* <p>
*
*
* @param xmlBase The xmlBase to set.
* @since Atom 1.0
*/
@ -592,7 +530,7 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the xmlBase
* <p>
*
*
* @return Returns the xmlBase.
* @since Atom 1.0
*/
@ -603,10 +541,10 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -617,10 +555,10 @@ public class Entry implements Cloneable, Serializable, Extendable {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -646,9 +584,9 @@ public class Entry implements Cloneable, Serializable, Extendable {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -658,9 +596,9 @@ public class Entry implements Cloneable, Serializable, Extendable {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -668,11 +606,12 @@ public class Entry implements Cloneable, Serializable, Extendable {
}
public Link findRelatedLink(final String relation) {
for (final Link l : otherLinks) {
if (relation.equals(l.getRel())) {
return l;
for (final Link link : otherLinks) {
if (relation.equals(link.getRel())) {
return link;
}
}
return null;
}
}

View file

@ -16,10 +16,10 @@
*/
package com.sun.syndication.feed.atom;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.impl.ModuleUtils;
@ -30,12 +30,14 @@ import com.sun.syndication.feed.synd.SyndPerson;
* <p>
* It handles Atom feeds version 0.3 without loosing any feed information.
* <p>
*
*
* @author Alejandro Abdelnur
* @author Dave Johnson (updated for Atom 1.0)
*/
public class Feed extends WireFeed {
private static final long serialVersionUID = -9175445106675422528L;
private String xmlBase;
private List<Category> categories;
private List<SyndPerson> authors;
@ -59,7 +61,7 @@ public class Feed extends WireFeed {
/**
* Default constructor, for bean cloning purposes only.
*
*
*/
public Feed() {
}
@ -67,9 +69,9 @@ public class Feed extends WireFeed {
/**
* Feed Constructor. All properties, except the type, are set to <b>null</b>.
* <p>
*
*
* @param type the type of the Atom feed.
*
*
*/
public Feed(final String type) {
super(type);
@ -78,9 +80,9 @@ public class Feed extends WireFeed {
/**
* Returns the feed language (Atom 0.3 only)
* <p>
*
*
* @return the feed language, <b>null</b> if none.
*
*
*/
public String getLanguage() {
return language;
@ -89,9 +91,9 @@ public class Feed extends WireFeed {
/**
* Sets the feed language (Atom 0.3 only)
* <p>
*
*
* @param language the feed language to set, <b>null</b> if none.
*
*
*/
public void setLanguage(final String language) {
this.language = language;
@ -100,9 +102,9 @@ public class Feed extends WireFeed {
/**
* Returns the feed title.
* <p>
*
*
* @return the feed title, <b>null</b> if none.
*
*
*/
public String getTitle() {
if (title != null) {
@ -114,9 +116,9 @@ public class Feed extends WireFeed {
/**
* Sets the feed title.
* <p>
*
*
* @param title the feed title to set, <b>null</b> if none.
*
*
*/
public void setTitle(final String title) {
if (this.title == null) {
@ -128,9 +130,9 @@ public class Feed extends WireFeed {
/**
* Returns the feed title.
* <p>
*
*
* @return the feed title, <b>null</b> if none.
*
*
*/
public Content getTitleEx() {
return title;
@ -139,9 +141,9 @@ public class Feed extends WireFeed {
/**
* Sets the feed title.
* <p>
*
*
* @param title the feed title to set, <b>null</b> if none.
*
*
*/
public void setTitleEx(final Content title) {
this.title = title;
@ -150,20 +152,17 @@ public class Feed extends WireFeed {
/**
* Returns the feed alternate links.
* <p>
*
*
* @return a list of Link elements with the feed alternate links, an empty list if none.
*/
public List<Link> getAlternateLinks() {
if (alternateLinks == null) {
alternateLinks = new ArrayList<Link>();
}
return alternateLinks;
return alternateLinks = Lists.createWhenNull(alternateLinks);
}
/**
* Sets the feed alternate links.
* <p>
*
*
* @param alternateLinks the list of Link elements with the feed alternate links to set, an
* empty list or <b>null</b> if none.
*/
@ -174,21 +173,18 @@ public class Feed extends WireFeed {
/**
* Returns the feed other links (non-alternate ones).
* <p>
*
*
* @return a list of Link elements with the feed other links (non-alternate ones), an empty list
* if none.
*/
public List<Link> getOtherLinks() {
if (otherLinks == null) {
otherLinks = new ArrayList<Link>();
}
return otherLinks;
return otherLinks = Lists.createWhenNull(otherLinks);
}
/**
* Sets the feed other links (non-alternate ones).
* <p>
*
*
* @param otherLinks the list of Link elements with the feed other links (non-alternate ones) to
* set, an empty list or <b>null</b> if none.
*/
@ -199,23 +195,20 @@ public class Feed extends WireFeed {
/**
* Returns the feed author.
* <p>
*
*
* @return the feed author, <b>null</b> if none.
*
*
*/
public List<SyndPerson> getAuthors() {
if (authors == null) {
authors = new ArrayList<SyndPerson>();
}
return authors;
return authors = Lists.createWhenNull(authors);
}
/**
* Sets the feed author.
* <p>
*
*
* @param authors the feed author to set, <b>null</b> if none.
*
*
*/
public void setAuthors(final List<SyndPerson> authors) {
this.authors = authors;
@ -224,24 +217,21 @@ public class Feed extends WireFeed {
/**
* Returns the feed contributors.
* <p>
*
*
* @return a list of Person elements with the feed contributors, an empty list if none.
*
*
*/
public List<SyndPerson> getContributors() {
if (contributors == null) {
contributors = new ArrayList<SyndPerson>();
}
return contributors;
return contributors = Lists.createWhenNull(contributors);
}
/**
* Sets the feed contributors.
* <p>
*
*
* @param contributors the list of Person elements with the feed contributors to set, an empty
* list or <b>null</b> if none.
*
*
*/
public void setContributors(final List<SyndPerson> contributors) {
this.contributors = contributors;
@ -250,7 +240,7 @@ public class Feed extends WireFeed {
/**
* Returns the feed tag line (Atom 0.3, maps to {@link #getSubtitle()}).
* <p>
*
*
* @return the feed tag line, <b>null</b> if none.
*/
public Content getTagline() {
@ -261,7 +251,7 @@ public class Feed extends WireFeed {
* Sets the feed tagline (Atom 0.3, maps to
* {@link #setSubtitle(com.sun.syndication.feed.atom.Content)}).
* <p>
*
*
* @param tagline the feed tagline to set, <b>null</b> if none.
*/
public void setTagline(final Content tagline) {
@ -271,9 +261,9 @@ public class Feed extends WireFeed {
/**
* Returns the feed ID.
* <p>
*
*
* @return the feed ID, <b>null</b> if none.
*
*
*/
public String getId() {
return id;
@ -282,9 +272,9 @@ public class Feed extends WireFeed {
/**
* Sets the feed ID.
* <p>
*
*
* @param id the feed ID to set, <b>null</b> if none.
*
*
*/
public void setId(final String id) {
this.id = id;
@ -293,9 +283,9 @@ public class Feed extends WireFeed {
/**
* Returns the feed generator.
* <p>
*
*
* @return the feed generator, <b>null</b> if none.
*
*
*/
public Generator getGenerator() {
return generator;
@ -304,9 +294,9 @@ public class Feed extends WireFeed {
/**
* Sets the feed generator.
* <p>
*
*
* @param generator the feed generator to set, <b>null</b> if none.
*
*
*/
public void setGenerator(final Generator generator) {
this.generator = generator;
@ -315,7 +305,7 @@ public class Feed extends WireFeed {
/**
* Returns the feed copyright (Atom 0.3, maps to {@link #getRights()}).
* <p>
*
*
* @return the feed copyright, <b>null</b> if none.
*/
public String getCopyright() {
@ -325,7 +315,7 @@ public class Feed extends WireFeed {
/**
* Sets the feed copyright (Atom 0.3, maps to {@link #setRights(java.lang.String)}).
* <p>
*
*
* @param copyright the feed copyright to set, <b>null</b> if none.
*/
public void setCopyright(final String copyright) {
@ -335,7 +325,7 @@ public class Feed extends WireFeed {
/**
* Returns the feed info (Atom 0.3 only)
* <p>
*
*
* @return the feed info, <b>null</b> if none.
*/
public Content getInfo() {
@ -345,7 +335,7 @@ public class Feed extends WireFeed {
/**
* Sets the feed info (Atom 0.3 only)
* <p>
*
*
* @param info the feed info to set, <b>null</b> if none.
*/
public void setInfo(final Content info) {
@ -355,7 +345,7 @@ public class Feed extends WireFeed {
/**
* Returns the feed modified date (Atom 0.3, maps to {@link #getUpdated()}).
* <p>
*
*
* @return the feed modified date, <b>null</b> if none.
*/
public Date getModified() {
@ -365,7 +355,7 @@ public class Feed extends WireFeed {
/**
* Sets the feed modified date (Atom 0.3, maps to {@link #setUpdated(java.util.Date)}).
* <p>
*
*
* @param modified the feed modified date to set, <b>null</b> if none.
*/
public void setModified(final Date modified) {
@ -375,24 +365,21 @@ public class Feed extends WireFeed {
/**
* Returns the feed entries.
* <p>
*
*
* @return a list of Entry elements with the feed entries, an empty list if none.
*
*
*/
public List<Entry> getEntries() {
if (entries == null) {
entries = new ArrayList<Entry>();
}
return entries;
return entries = Lists.createWhenNull(entries);
}
/**
* Sets the feed entries.
* <p>
*
*
* @param entries the list of Entry elements with the feed entries to set, an empty list or
* <b>null</b> if none.
*
*
*/
public void setEntries(final List<Entry> entries) {
this.entries = entries;
@ -401,25 +388,22 @@ public class Feed extends WireFeed {
/**
* Returns the feed modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the feed modules, an empty list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
return modules;
return modules = Lists.createWhenNull(modules);
}
/**
* Sets the feed moduless.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the feed moduless to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -429,7 +413,7 @@ public class Feed extends WireFeed {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/
@ -441,21 +425,18 @@ public class Feed extends WireFeed {
/**
* Returns the categories
* <p>
*
*
* @return Returns the categories.
* @since Atom 1.0
*/
public List<Category> getCategories() {
if (categories == null) {
categories = new ArrayList<Category>();
}
return categories;
return categories = Lists.createWhenNull(categories);
}
/**
* Set the categories
* <p>
*
*
* @param categories The categories to set.
* @since Atom 1.0
*/
@ -466,7 +447,7 @@ public class Feed extends WireFeed {
/**
* Returns the icon
* <p>
*
*
* @return Returns the icon.
* @since Atom 1.0
*/
@ -477,7 +458,7 @@ public class Feed extends WireFeed {
/**
* Set the icon
* <p>
*
*
* @param icon The icon to set.
* @since Atom 1.0
*/
@ -488,7 +469,7 @@ public class Feed extends WireFeed {
/**
* Returns the logo
* <p>
*
*
* @return Returns the logo.
* @since Atom 1.0
*/
@ -499,7 +480,7 @@ public class Feed extends WireFeed {
/**
* Set the logo
* <p>
*
*
* @param logo The logo to set.
* @since Atom 1.0
*/
@ -510,7 +491,7 @@ public class Feed extends WireFeed {
/**
* Returns the rights
* <p>
*
*
* @return Returns the rights.
* @since Atom 1.0
*/
@ -521,7 +502,7 @@ public class Feed extends WireFeed {
/**
* Set the rights
* <p>
*
*
* @param rights The rights to set.
* @since Atom 1.0
*/
@ -532,7 +513,7 @@ public class Feed extends WireFeed {
/**
* Returns the subtitle
* <p>
*
*
* @return Returns the subtitle.
* @since Atom 1.0
*/
@ -543,7 +524,7 @@ public class Feed extends WireFeed {
/**
* Set the subtitle
* <p>
*
*
* @param subtitle The subtitle to set.
* @since Atom 1.0
*/
@ -554,7 +535,7 @@ public class Feed extends WireFeed {
/**
* Returns the updated
* <p>
*
*
* @return Returns the updated.
* @since Atom 1.0
*/
@ -565,7 +546,7 @@ public class Feed extends WireFeed {
/**
* Set the updated
* <p>
*
*
* @param updated The updated to set.
* @since Atom 1.0
*/
@ -576,7 +557,7 @@ public class Feed extends WireFeed {
/**
* Returns the xmlBase
* <p>
*
*
* @return Returns the xmlBase.
* @since Atom 1.0
*/
@ -587,7 +568,7 @@ public class Feed extends WireFeed {
/**
* Set the xmlBase
* <p>
*
*
* @param xmlBase The xmlBase to set.
* @since Atom 1.0
*/

View file

@ -18,16 +18,18 @@ package com.sun.syndication.feed.atom;
import java.io.Serializable;
import com.rometools.utils.Alternatives;
import com.sun.syndication.feed.impl.ObjectBean;
/**
* Bean for link elements of Atom feeds.
* <p>
*
*
* @author Alejandro Abdelnur
* @author Dave Johnson (updated for Atom 1.0)
*/
public class Link implements Cloneable, Serializable {
private static final long serialVersionUID = 670365139518027828L;
private final ObjectBean objBean;
@ -43,7 +45,7 @@ public class Link implements Cloneable, Serializable {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public Link() {
objBean = new ObjectBean(this.getClass(), this);
@ -52,10 +54,10 @@ public class Link implements Cloneable, Serializable {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -66,10 +68,10 @@ public class Link implements Cloneable, Serializable {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -81,9 +83,9 @@ public class Link implements Cloneable, Serializable {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -93,9 +95,9 @@ public class Link implements Cloneable, Serializable {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -105,9 +107,9 @@ public class Link implements Cloneable, Serializable {
/**
* Returns the link rel.
* <p>
*
*
* @return the link rel, <b>null</b> if none.
*
*
*/
public String getRel() {
return rel;
@ -116,9 +118,9 @@ public class Link implements Cloneable, Serializable {
/**
* Sets the link rel.
* <p>
*
*
* @param rel the link rel,, <b>null</b> if none.
*
*
*/
public void setRel(final String rel) {
// TODO add check, ask P@ about the check
@ -128,9 +130,9 @@ public class Link implements Cloneable, Serializable {
/**
* Returns the link type.
* <p>
*
*
* @return the link type, <b>null</b> if none.
*
*
*/
public String getType() {
return type;
@ -139,9 +141,9 @@ public class Link implements Cloneable, Serializable {
/**
* Sets the link type.
* <p>
*
*
* @param type the link type, <b>null</b> if none.
*
*
*/
public void setType(final String type) {
this.type = type;
@ -150,9 +152,9 @@ public class Link implements Cloneable, Serializable {
/**
* Returns the link href.
* <p>
*
*
* @return the link href, <b>null</b> if none.
*
*
*/
public String getHref() {
return href;
@ -161,9 +163,9 @@ public class Link implements Cloneable, Serializable {
/**
* Sets the link href.
* <p>
*
*
* @param href the link href, <b>null</b> if none.
*
*
*/
public void setHref(final String href) {
this.href = href;
@ -174,19 +176,15 @@ public class Link implements Cloneable, Serializable {
}
public String getHrefResolved() {
if (hrefResolved != null) {
return hrefResolved;
} else {
return href;
}
return Alternatives.firstNotNull(hrefResolved, href);
}
/**
* Returns the link title.
* <p>
*
*
* @return the link title, <b>null</b> if none.
*
*
*/
public String getTitle() {
return title;
@ -195,9 +193,9 @@ public class Link implements Cloneable, Serializable {
/**
* Sets the link title.
* <p>
*
*
* @param title the link title, <b>null</b> if none.
*
*
*/
public void setTitle(final String title) {
this.title = title;
@ -206,7 +204,7 @@ public class Link implements Cloneable, Serializable {
/**
* Returns the hreflang
* <p>
*
*
* @return Returns the hreflang.
* @since Atom 1.0
*/
@ -217,7 +215,7 @@ public class Link implements Cloneable, Serializable {
/**
* Set the hreflang
* <p>
*
*
* @param hreflang The hreflang to set.
* @since Atom 1.0
*/
@ -228,7 +226,7 @@ public class Link implements Cloneable, Serializable {
/**
* Returns the length
* <p>
*
*
* @return Returns the length.
*/
public long getLength() {
@ -238,7 +236,7 @@ public class Link implements Cloneable, Serializable {
/**
* Set the length
* <p>
*
*
* @param length The length to set.
*/
public void setLength(final long length) {

View file

@ -17,9 +17,10 @@
package com.sun.syndication.feed.atom;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.rometools.utils.Alternatives;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.module.Extendable;
import com.sun.syndication.feed.module.Module;
@ -29,7 +30,7 @@ import com.sun.syndication.feed.synd.SyndPerson;
/**
* Bean for person elements of Atom feeds.
* <p>
*
*
* @author Alejandro Abdelnur
* @author Dave Johnson (updated for Atom 1.0)
*/
@ -48,7 +49,7 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public Person() {
objBean = new ObjectBean(this.getClass(), this);
@ -57,10 +58,10 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -71,10 +72,10 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -86,9 +87,9 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -98,9 +99,9 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -110,9 +111,9 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Returns the person name.
* <p>
*
*
* @return the person name, <b>null</b> if none.
*
*
*/
@Override
public String getName() {
@ -122,9 +123,9 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Sets the personname.
* <p>
*
*
* @param name the person name, <b>null</b> if none.
*
*
*/
@Override
public void setName(final String name) {
@ -134,7 +135,7 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Returns the person URL (same as {@link #getUri()})
* <p>
*
*
* @return the person URL, <b>null</b> if none.
*/
public String getUrl() {
@ -144,7 +145,7 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Sets the person URL (same as {@link #setUri(java.lang.String)})
* <p>
*
*
* @param url the person URL, <b>null</b> if none.
*/
public void setUrl(final String url) {
@ -156,19 +157,15 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
}
public String getUriResolved(final String resolveURI) {
if (uriResolved != null) {
return uriResolved;
} else {
return uri;
}
return Alternatives.firstNotNull(uriResolved, uri);
}
/**
* Returns the person email.
* <p>
*
*
* @return the person email, <b>null</b> if none.
*
*
*/
@Override
public String getEmail() {
@ -178,9 +175,9 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Sets the person email.
* <p>
*
*
* @param email the person email, <b>null</b> if none.
*
*
*/
@Override
public void setEmail(final String email) {
@ -190,7 +187,7 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Returns the uri
* <p>
*
*
* @return Returns the uri.
* @since Atom 1.0
*/
@ -202,7 +199,7 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Set the uri
* <p>
*
*
* @param uri The uri to set.
* @since Atom 1.0
*/
@ -214,25 +211,22 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Returns the entry modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the entry modules, an emtpy list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
return modules;
return modules = Lists.createWhenNull(modules);
}
/**
* Sets the entry modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the entry modules to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -242,7 +236,7 @@ public class Person implements SyndPerson, Cloneable, Serializable, Extendable {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/

View file

@ -28,21 +28,34 @@ import com.sun.syndication.feed.impl.ObjectBean;
/**
* Subject of the Dublin Core ModuleImpl, default implementation.
* <p>
*
*
* @see <a href="http://web.resource.org/rss/1.0/modules/dc/">Dublin Core module</a>.
* @author Alejandro Abdelnur
*
*
*/
public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
private static final long serialVersionUID = 6276396184267118968L;
private static final CopyFromHelper COPY_FROM_HELPER;
private final ObjectBean objBean;
private String taxonomyUri;
private String value;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("taxonomyUri", String.class);
basePropInterfaceMap.put("value", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(DCSubject.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public DCSubjectImpl() {
objBean = new ObjectBean(this.getClass(), this);
@ -51,10 +64,10 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -65,10 +78,10 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -83,9 +96,9 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -95,9 +108,9 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -107,9 +120,9 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
/**
* Returns the DublinCore subject taxonomy URI.
* <p>
*
*
* @return the DublinCore subject taxonomy URI, <b>null</b> if none.
*
*
*/
@Override
public String getTaxonomyUri() {
@ -119,9 +132,9 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
/**
* Sets the DublinCore subject taxonomy URI.
* <p>
*
*
* @param taxonomyUri the DublinCore subject taxonomy URI to set, <b>null</b> if none.
*
*
*/
@Override
public void setTaxonomyUri(final String taxonomyUri) {
@ -131,9 +144,9 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
/**
* Returns the DublinCore subject value.
* <p>
*
*
* @return the DublinCore subject value, <b>null</b> if none.
*
*
*/
@Override
public String getValue() {
@ -143,9 +156,9 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
/**
* Sets the DublinCore subject value.
* <p>
*
*
* @param value the DublinCore subject value to set, <b>null</b> if none.
*
*
*/
@Override
public void setValue(final String value) {
@ -162,16 +175,4 @@ public class DCSubjectImpl implements Cloneable, Serializable, DCSubject {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("taxonomyUri", String.class);
basePropInterfaceMap.put("value", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(DCSubject.class, basePropInterfaceMap, basePropClassImplMap);
}
}

View file

@ -23,37 +23,50 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.rometools.utils.Dates;
import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.impl.CopyFromHelper;
/**
* Syndication ModuleImpl, default implementation.
* <p>
*
*
* @see <a href="http://web.resource.org/rss/1.0/modules/syndication/">Syndication module</a>.
* @author Alejandro Abdelnur
*
*
*/
public class SyModuleImpl extends ModuleImpl implements SyModule {
private static final long serialVersionUID = -8345879299577437933L;
private static final Set<String> PERIODS = new HashSet<String>();
static {
PERIODS.add(HOURLY);
PERIODS.add(DAILY);
PERIODS.add(WEEKLY);
PERIODS.add(MONTHLY);
PERIODS.add(YEARLY);
}
private static final long serialVersionUID = -8345879299577437933L;
private static final Set<String> PERIODS = new HashSet<String>();
private static final CopyFromHelper COPY_FROM_HELPER;
private String updatePeriod;
private int updateFrequency;
private Date updateBase;
static {
PERIODS.add(HOURLY);
PERIODS.add(DAILY);
PERIODS.add(WEEKLY);
PERIODS.add(MONTHLY);
PERIODS.add(YEARLY);
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("updatePeriod", String.class);
basePropInterfaceMap.put("updateFrequency", Integer.TYPE);
basePropInterfaceMap.put("updateBase", Date.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyModule.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public SyModuleImpl() {
super(SyModule.class, URI);
@ -62,9 +75,9 @@ public class SyModuleImpl extends ModuleImpl implements SyModule {
/**
* Returns the Syndication module update period.
* <p>
*
*
* @return the Syndication module update period, <b>null</b> if none.
*
*
*/
@Override
public String getUpdatePeriod() {
@ -74,9 +87,9 @@ public class SyModuleImpl extends ModuleImpl implements SyModule {
/**
* Sets the Syndication module update period.
* <p>
*
*
* @param updatePeriod the Syndication module update period to set, <b>null</b> if none.
*
*
*/
@Override
public void setUpdatePeriod(final String updatePeriod) {
@ -89,9 +102,9 @@ public class SyModuleImpl extends ModuleImpl implements SyModule {
/**
* Returns the Syndication module update frequency.
* <p>
*
*
* @return the Syndication module update frequency, <b>null</b> if none.
*
*
*/
@Override
public int getUpdateFrequency() {
@ -101,9 +114,9 @@ public class SyModuleImpl extends ModuleImpl implements SyModule {
/**
* Sets the Syndication module update frequency.
* <p>
*
*
* @param updateFrequency the Syndication module update frequency to set, <b>null</b> if none.
*
*
*/
@Override
public void setUpdateFrequency(final int updateFrequency) {
@ -113,25 +126,25 @@ public class SyModuleImpl extends ModuleImpl implements SyModule {
/**
* Returns the Syndication module update base date.
* <p>
*
*
* @return the Syndication module update base date, <b>null</b> if none.
*
*
*/
@Override
public Date getUpdateBase() {
return updateBase != null ? new Date(updateBase.getTime()) : null;
return Dates.copy(updateBase);
}
/**
* Sets the Syndication module update base date.
* <p>
*
*
* @param updateBase the Syndication module update base date to set, <b>null</b> if none.
*
*
*/
@Override
public void setUpdateBase(final Date updateBase) {
this.updateBase = new Date(updateBase.getTime());
this.updateBase = Dates.copy(updateBase);
}
@Override
@ -144,17 +157,4 @@ public class SyModuleImpl extends ModuleImpl implements SyModule {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("updatePeriod", String.class);
basePropInterfaceMap.put("updateFrequency", Integer.TYPE);
basePropInterfaceMap.put("updateBase", Date.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyModule.class, basePropInterfaceMap, basePropClassImplMap);
}
}

View file

@ -17,13 +17,14 @@
*/
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.rometools.utils.Dates;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.impl.ModuleUtils;
@ -34,12 +35,14 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
* It handles all RSS versions (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) without losing
* information.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class Channel extends WireFeed {
private static final long serialVersionUID = 745207486449728472L;
public static final String SUNDAY = "sunday";
public static final String MONDAY = "monday";
public static final String TUESDAY = "tuesday";
@ -87,7 +90,7 @@ public class Channel extends WireFeed {
/**
* Default constructor, for bean cloning purposes only.
*
*
*/
public Channel() {
}
@ -95,9 +98,9 @@ public class Channel extends WireFeed {
/**
* Channel Constructor. All properties, except the type, are set to <b>null</b>.
* <p>
*
*
* @param type the type of the RSS feed.
*
*
*/
public Channel(final String type) {
super(type);
@ -106,9 +109,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel title.
* <p>
*
*
* @return the channel title, <b>null</b> if none.
*
*
*/
public String getTitle() {
return title;
@ -117,9 +120,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel title.
* <p>
*
*
* @param title the channel title to set, <b>null</b> if none.
*
*
*/
public void setTitle(final String title) {
this.title = title;
@ -128,9 +131,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel description.
* <p>
*
*
* @return the channel description, <b>null</b> if none.
*
*
*/
public String getDescription() {
return description;
@ -139,9 +142,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel description.
* <p>
*
*
* @param description the channel description to set, <b>null</b> if none.
*
*
*/
public void setDescription(final String description) {
this.description = description;
@ -150,9 +153,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel link.
* <p>
*
*
* @return the channel link, <b>null</b> if none.
*
*
*/
public String getLink() {
return link;
@ -161,9 +164,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel link.
* <p>
*
*
* @param link the channel link to set, <b>null</b> if none.
*
*
*/
public void setLink(final String link) {
this.link = link;
@ -172,7 +175,7 @@ public class Channel extends WireFeed {
/**
* Returns the channel uri.
* <p>
*
*
* @return the channel uri, <b>null</b> if none.
*/
public String getUri() {
@ -182,7 +185,7 @@ public class Channel extends WireFeed {
/**
* Sets the channel uri.
* <p>
*
*
* @param uri the channel uri, <b>null</b> if none.
*/
public void setUri(final String uri) {
@ -192,9 +195,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel image.
* <p>
*
*
* @return the channel image, <b>null</b> if none.
*
*
*/
public Image getImage() {
return image;
@ -203,9 +206,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel image.
* <p>
*
*
* @param image the channel image to set, <b>null</b> if none.
*
*
*/
public void setImage(final Image image) {
this.image = image;
@ -214,24 +217,21 @@ public class Channel extends WireFeed {
/**
* Returns the channel items.
* <p>
*
*
* @return a list of Item elements with the channel items, an empty list if none.
*
*
*/
public List<Item> getItems() {
if (items == null) {
items = new ArrayList<Item>();
}
return items;
return items = Lists.createWhenNull(items);
}
/**
* Sets the channel items.
* <p>
*
*
* @param items the list of Item elements with the channel items to set, an empty list or
* <b>null</b> if none.
*
*
*/
public void setItems(final List<Item> items) {
this.items = items;
@ -240,9 +240,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel text input.
* <p>
*
*
* @return the channel text input, <b>null</b> if none.
*
*
*/
public TextInput getTextInput() {
return textInput;
@ -251,9 +251,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel text input.
* <p>
*
*
* @param textInput the channel text input to set, <b>null</b> if none.
*
*
*/
public void setTextInput(final TextInput textInput) {
this.textInput = textInput;
@ -262,9 +262,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel language.
* <p>
*
*
* @return the channel language, <b>null</b> if none.
*
*
*/
public String getLanguage() {
return language;
@ -273,9 +273,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel language.
* <p>
*
*
* @param language the channel language to set, <b>null</b> if none.
*
*
*/
public void setLanguage(final String language) {
this.language = language;
@ -284,9 +284,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel rating.
* <p>
*
*
* @return the channel rating, <b>null</b> if none.
*
*
*/
public String getRating() {
return rating;
@ -295,9 +295,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel rating.
* <p>
*
*
* @param rating the channel rating to set, <b>null</b> if none.
*
*
*/
public void setRating(final String rating) {
this.rating = rating;
@ -306,9 +306,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel copyright.
* <p>
*
*
* @return the channel copyright, <b>null</b> if none.
*
*
*/
public String getCopyright() {
return copyright;
@ -317,9 +317,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel copyright.
* <p>
*
*
* @param copyright the channel copyright to set, <b>null</b> if none.
*
*
*/
public void setCopyright(final String copyright) {
this.copyright = copyright;
@ -328,69 +328,53 @@ public class Channel extends WireFeed {
/**
* Returns the channel publishing date.
* <p>
*
*
* @return the channel publishing date, <b>null</b> if none.
*
*
*/
public Date getPubDate() {
if (pubDate == null) {
return null;
} else {
return new Date(pubDate.getTime());
}
return Dates.copy(pubDate);
}
/**
* Sets the channel publishing date.
* <p>
*
*
* @param pubDate the channel publishing date to set, <b>null</b> if none.
*
*
*/
public void setPubDate(final Date pubDate) {
if (pubDate == null) {
this.pubDate = null;
} else {
this.pubDate = new Date(pubDate.getTime());
}
this.pubDate = Dates.copy(pubDate);
}
/**
* Returns the channel last build date.
* <p>
*
*
* @return the channel last build date, <b>null</b> if none.
*
*
*/
public Date getLastBuildDate() {
if (lastBuildDate == null) {
return null;
} else {
return new Date(lastBuildDate.getTime());
}
return Dates.copy(lastBuildDate);
}
/**
* Sets the channel last build date.
* <p>
*
*
* @param lastBuildDate the channel last build date to set, <b>null</b> if none.
*
*
*/
public void setLastBuildDate(final Date lastBuildDate) {
if (lastBuildDate == null) {
this.lastBuildDate = null;
} else {
this.lastBuildDate = new Date(lastBuildDate.getTime());
}
this.lastBuildDate = Dates.copy(lastBuildDate);
}
/**
* Returns the channel docs.
* <p>
*
*
* @return the channel docs, <b>null</b> if none.
*
*
*/
public String getDocs() {
return docs;
@ -399,9 +383,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel docs.
* <p>
*
*
* @param docs the channel docs to set, <b>null</b> if none.
*
*
*/
public void setDocs(final String docs) {
this.docs = docs;
@ -410,9 +394,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel managing editor.
* <p>
*
*
* @return the channel managing editor, <b>null</b> if none.
*
*
*/
public String getManagingEditor() {
return managingEditor;
@ -421,9 +405,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel managing editor.
* <p>
*
*
* @param managingEditor the channel managing editor to set, <b>null</b> if none.
*
*
*/
public void setManagingEditor(final String managingEditor) {
this.managingEditor = managingEditor;
@ -432,9 +416,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel web master.
* <p>
*
*
* @return the channel web master, <b>null</b> if none.
*
*
*/
public String getWebMaster() {
return webMaster;
@ -443,9 +427,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel web master.
* <p>
*
*
* @param webMaster the channel web master to set, <b>null</b> if none.
*
*
*/
public void setWebMaster(final String webMaster) {
this.webMaster = webMaster;
@ -454,25 +438,21 @@ public class Channel extends WireFeed {
/**
* Returns the channel skip hours.
* <p>
*
*
* @return a list of Integer elements with the channel skip hours, an empty list if none.
*
*
*/
public List<Integer> getSkipHours() {
if (skipHours != null) {
return skipHours;
} else {
return new ArrayList<Integer>();
}
return Lists.createWhenNull(skipHours);
}
/**
* Sets the channel skip hours.
* <p>
*
*
* @param skipHours the list of Integer elements with the channel skip hours to set, an empty
* list or <b>null</b> if none.
*
*
*/
public void setSkipHours(final List<Integer> skipHours) {
if (skipHours != null) {
@ -494,25 +474,21 @@ public class Channel extends WireFeed {
/**
* Returns the channel skip days.
* <p>
*
*
* @return a list of Day elements with the channel skip days, an empty list if none.
*
*
*/
public List<String> getSkipDays() {
if (skipDays != null) {
return skipDays;
} else {
return new ArrayList<String>();
}
return Lists.createWhenNull(skipDays);
}
/**
* Sets the channel skip days.
* <p>
*
*
* @param skipDays the list of Day elements with the channel skip days to set, an empty list or
* <b>null</b> if none.
*
*
*/
public void setSkipDays(final List<String> skipDays) {
if (skipDays != null) {
@ -535,9 +511,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel cloud.
* <p>
*
*
* @return the channel cloud, <b>null</b> if none.
*
*
*/
public Cloud getCloud() {
return cloud;
@ -546,9 +522,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel cloud.
* <p>
*
*
* @param cloud the channel cloud to set, <b>null</b> if none.
*
*
*/
public void setCloud(final Cloud cloud) {
this.cloud = cloud;
@ -557,24 +533,21 @@ public class Channel extends WireFeed {
/**
* Returns the channel categories.
* <p>
*
*
* @return a list of Category elements with the channel categories, an empty list if none.
*
*
*/
public List<Category> getCategories() {
if (categories == null) {
categories = new ArrayList<Category>();
}
return categories;
return categories = Lists.createWhenNull(categories);
}
/**
* Sets the channel categories.
* <p>
*
*
* @param categories the list of Category elements with the channel categories to set, an empty
* list or <b>null</b> if none.
*
*
*/
public void setCategories(final List<Category> categories) {
this.categories = categories;
@ -583,9 +556,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel generator.
* <p>
*
*
* @return the channel generator, <b>null</b> if none.
*
*
*/
public String getGenerator() {
return generator;
@ -594,9 +567,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel generator.
* <p>
*
*
* @param generator the channel generator to set, <b>null</b> if none.
*
*
*/
public void setGenerator(final String generator) {
this.generator = generator;
@ -605,9 +578,9 @@ public class Channel extends WireFeed {
/**
* Returns the channel time to live.
* <p>
*
*
* @return the channel time to live, <b>null</b> if none.
*
*
*/
public int getTtl() {
return ttl;
@ -616,9 +589,9 @@ public class Channel extends WireFeed {
/**
* Sets the channel time to live.
* <p>
*
*
* @param ttl the channel time to live to set, <b>null</b> if none.
*
*
*/
public void setTtl(final int ttl) {
this.ttl = ttl;
@ -627,25 +600,22 @@ public class Channel extends WireFeed {
/**
* Returns the channel modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the channel modules, an empty list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
return modules;
return modules = Lists.createWhenNull(modules);
}
/**
* Sets the channel modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the channel modules to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -655,7 +625,7 @@ public class Channel extends WireFeed {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/

View file

@ -18,12 +18,13 @@
package com.sun.syndication.feed.rss;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.jdom2.Element;
import com.rometools.utils.Dates;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.module.Extendable;
import com.sun.syndication.feed.module.Module;
@ -37,13 +38,16 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
* For RSS1.0 it supports Dublin Core and Syndication modules. Note that those modules currently
* support simple syntax format only.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class Item implements Cloneable, Serializable, Extendable {
private static final long serialVersionUID = 3741763947754555947L;
private final ObjectBean objBean;
private String title;
private String link;
private String uri;
@ -63,7 +67,7 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public Item() {
objBean = new ObjectBean(this.getClass(), this);
@ -72,10 +76,10 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -86,10 +90,10 @@ public class Item implements Cloneable, Serializable, Extendable {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -110,9 +114,9 @@ public class Item implements Cloneable, Serializable, Extendable {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -122,9 +126,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -134,9 +138,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item title.
* <p>
*
*
* @return the item title, <b>null</b> if none.
*
*
*/
public String getTitle() {
return title;
@ -145,9 +149,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item title.
* <p>
*
*
* @param title the item title to set, <b>null</b> if none.
*
*
*/
public void setTitle(final String title) {
this.title = title;
@ -156,9 +160,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item link.
* <p>
*
*
* @return the item link, <b>null</b> if none.
*
*
*/
public String getLink() {
return link;
@ -167,9 +171,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item link.
* <p>
*
*
* @param link the item link to set, <b>null</b> if none.
*
*
*/
public void setLink(final String link) {
this.link = link;
@ -178,7 +182,7 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item uri.
* <p>
*
*
* @return the item uri, <b>null</b> if none.
*/
public String getUri() {
@ -188,7 +192,7 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item uri.
* <p>
*
*
* @param uri the item uri to set, <b>null</b> if none.
*/
public void setUri(final String uri) {
@ -198,9 +202,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item description.
* <p>
*
*
* @return the item description, <b>null</b> if none.
*
*
*/
public Description getDescription() {
return description;
@ -209,9 +213,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item description.
* <p>
*
*
* @param description the item description to set, <b>null</b> if none.
*
*
*/
public void setDescription(final Description description) {
this.description = description;
@ -220,9 +224,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item content.
* <p>
*
*
* @return the item content, <b>null</b> if none.
*
*
*/
public Content getContent() {
return content;
@ -231,9 +235,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item content.
* <p>
*
*
* @param content the item content to set, <b>null</b> if none.
*
*
*/
public void setContent(final Content content) {
this.content = content;
@ -242,9 +246,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item source.
* <p>
*
*
* @return the item source, <b>null</b> if none.
*
*
*/
public Source getSource() {
return source;
@ -253,9 +257,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item source.
* <p>
*
*
* @param source the item source to set, <b>null</b> if none.
*
*
*/
public void setSource(final Source source) {
this.source = source;
@ -264,24 +268,21 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item enclosures.
* <p>
*
*
* @return a list of Enclosure elements with the item enclosures, an empty list if none.
*
*
*/
public List<Enclosure> getEnclosures() {
if (enclosures == null) {
enclosures = new ArrayList<Enclosure>();
}
return enclosures;
return enclosures = Lists.createWhenNull(enclosures);
}
/**
* Sets the item enclosures.
* <p>
*
*
* @param enclosures the list of Enclosure elements with the item enclosures to set, an empty
* list or <b>null</b> if none.
*
*
*/
public void setEnclosures(final List<Enclosure> enclosures) {
this.enclosures = enclosures;
@ -290,24 +291,21 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item categories.
* <p>
*
*
* @return a list of Category elements with the item categories, an empty list if none.
*
*
*/
public List<Category> getCategories() {
if (categories == null) {
categories = new ArrayList<Category>();
}
return categories;
return categories = Lists.createWhenNull(categories);
}
/**
* Sets the item categories.
* <p>
*
*
* @param categories the list of Categories elements with the item categories to set, an empty
* list or <b>null</b> if none.
*
*
*/
public void setCategories(final List<Category> categories) {
this.categories = categories;
@ -316,9 +314,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item GUID.
* <p>
*
*
* @return the item GUID, <b>null</b> if none.
*
*
*/
public Guid getGuid() {
return guid;
@ -327,9 +325,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item GUID.
* <p>
*
*
* @param guid the item GUID to set, <b>null</b> if none.
*
*
*/
public void setGuid(final Guid guid) {
this.guid = guid;
@ -338,9 +336,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item comments.
* <p>
*
*
* @return the item comments, <b>null</b> if none.
*
*
*/
public String getComments() {
return comments;
@ -349,9 +347,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item comments.
* <p>
*
*
* @param comments the item comments to set, <b>null</b> if none.
*
*
*/
public void setComments(final String comments) {
this.comments = comments;
@ -360,9 +358,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item author.
* <p>
*
*
* @return the item author, <b>null</b> if none.
*
*
*/
public String getAuthor() {
return author;
@ -371,9 +369,9 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Sets the item author.
* <p>
*
*
* @param author the item author to set, <b>null</b> if none.
*
*
*/
public void setAuthor(final String author) {
this.author = author;
@ -382,25 +380,22 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the item modules, an empty list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
return modules;
return modules = Lists.createWhenNull(modules);
}
/**
* Sets the item modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the item modules to set, an empty list or
* <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -410,7 +405,7 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/
@ -422,83 +417,64 @@ public class Item implements Cloneable, Serializable, Extendable {
/**
* Returns the item publishing date.
* <p>
*
*
* @return the item publishing date, <b>null</b> if none.
*
*
*/
public Date getPubDate() {
if (pubDate == null) {
return null;
} else {
return new Date(pubDate.getTime());
}
return Dates.copy(pubDate);
}
/**
* Sets the item publishing date.
* <p>
*
*
* @param pubDate the item publishing date to set, <b>null</b> if none.
*
*
*/
public void setPubDate(final Date pubDate) {
if (pubDate == null) {
this.pubDate = null;
} else {
this.pubDate = new Date(pubDate.getTime());
}
this.pubDate = Dates.copy(pubDate);
}
/**
* Returns the item expiration date.
* <p>
*
*
* @return the item expiration date, <b>null</b> if none.
*
*
*/
public Date getExpirationDate() {
if (expirationDate == null) {
return null;
} else {
return new Date(expirationDate.getTime());
}
return Dates.copy(expirationDate);
}
/**
* Sets the item expiration date.
* <p>
*
*
* @param expirationDate the item expiration date to set, <b>null</b> if none.
*
*
*/
public void setExpirationDate(final Date expirationDate) {
if (expirationDate == null) {
this.expirationDate = null;
} else {
this.expirationDate = new Date(expirationDate.getTime());
}
this.expirationDate = Dates.copy(expirationDate);
}
/**
* Returns foreign markup found at item level.
* <p>
*
*
* @return Opaque object to discourage use
*
*
*/
public List<Element> getForeignMarkup() {
if (foreignMarkup == null) {
foreignMarkup = new ArrayList<Element>();
}
return foreignMarkup;
return foreignMarkup = Lists.createWhenNull(foreignMarkup);
}
/**
* Sets foreign markup found at item level.
* <p>
*
*
* @param foreignMarkup Opaque object to discourage use
*
*
*/
public void setForeignMarkup(final List<Element> foreignMarkup) {
this.foreignMarkup = foreignMarkup;

View file

@ -1,7 +1,7 @@
/*
* Copyright 2004 Sun Microsystems, Inc.
* Copyright 2011 ROME Team
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -18,11 +18,8 @@
package com.sun.syndication.feed.synd;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sun.syndication.feed.CopyFrom;
@ -34,20 +31,32 @@ import com.sun.syndication.feed.module.DCSubjectImpl;
/**
* Bean for categories of SyndFeedImpl feeds and entries.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class SyndCategoryImpl implements Serializable, SyndCategory {
private static final long serialVersionUID = -2151815243404151131L;
private static final CopyFromHelper COPY_FROM_HELPER;
private final ObjectBean objBean;
private final DCSubject subject;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("name", String.class);
basePropInterfaceMap.put("taxonomyUri", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndCategory.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* For implementations extending SyndContentImpl to be able to use the ObjectBean functionality
* with extended interfaces.
* <p>
*
*
* @param subject the DC subject to wrap.
*/
SyndCategoryImpl(final DCSubject subject) {
@ -58,10 +67,10 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -72,10 +81,10 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -90,9 +99,9 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -102,9 +111,9 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -114,9 +123,9 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Package private constructor, used by SyndCategoryListFacade.
* <p>
*
*
* @return the DC subject being wrapped.
*
*
*/
DCSubject getSubject() {
return subject;
@ -125,7 +134,7 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public SyndCategoryImpl() {
this(new DCSubjectImpl());
@ -134,9 +143,9 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Returns the category name.
* <p>
*
*
* @return the category name, <b>null</b> if none.
*
*
*/
@Override
public String getName() {
@ -146,9 +155,9 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Sets the category name.
* <p>
*
*
* @param name the category name to set, <b>null</b> if none.
*
*
*/
@Override
public void setName(final String name) {
@ -158,9 +167,9 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Returns the category taxonomy URI.
* <p>
*
*
* @return the category taxonomy URI, <b>null</b> if none.
*
*
*/
@Override
public String getTaxonomyUri() {
@ -170,9 +179,9 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
/**
* Sets the category taxonomy URI.
* <p>
*
*
* @param taxonomyUri the category taxonomy URI to set, <b>null</b> if none.
*
*
*/
@Override
public void setTaxonomyUri(final String taxonomyUri) {
@ -189,168 +198,4 @@ public class SyndCategoryImpl implements Serializable, SyndCategory {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("name", String.class);
basePropInterfaceMap.put("taxonomyUri", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndCategory.class, basePropInterfaceMap, basePropClassImplMap);
}
}
/**
* List implementation for SyndCategoryImpl elements. To be directly used by the SyndFeedImpl and
* SyndEntryImpl classes only.
* <p>
* 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.
* <p>
* This is necessary because the SyndFeedImpl categories are just a convenience to access the
* DublinCore subjects.
* <P>
* All this mess to avoid making DCSubjectImpl implement SyndCategory (which it would be odd).
* <p>
*
* @author Alejandro Abdelnur
*
*/
class SyndCategoryListFacade extends AbstractList<SyndCategory> {
private final List<DCSubject> subjects;
/**
* Default constructor. Creates and empty list.
*/
public SyndCategoryListFacade() {
this(new ArrayList<DCSubject>());
}
/**
* Creates a facade list of categories on top the given subject list.
* <P>
*
* @param subjects the list of subjects to create the facade.
*
*/
public SyndCategoryListFacade(final List<DCSubject> subjects) {
this.subjects = subjects;
}
/**
* Gets the category by index.
* <p>
*
* @param index the index position to retrieve the category.
* @return the SyndCategoryImpl in position index, <b>null</b> if none.
*
*/
@Override
public SyndCategory get(final int index) {
return new SyndCategoryImpl(subjects.get(index));
}
/**
* Returns the size of the list.
* <p>
*
* @return the size of the list.
*
*/
@Override
public int size() {
return subjects.size();
}
/**
* Sets a category in an existing position in the list.
* <p>
*
* @param index position to set the category.
* @param obj the SyndCategoryImpl object to set.
* @return the SyndCategoryImpl object that is being replaced, <b>null</b> if none.
*
*/
@Override
public SyndCategory set(final int index, final SyndCategory obj) {
final SyndCategoryImpl sCat = (SyndCategoryImpl) obj;
DCSubject subject;
if (sCat != null) {
subject = sCat.getSubject();
} else {
subject = null;
}
subject = subjects.set(index, subject);
if (subject != null) {
return new SyndCategoryImpl(subject);
} else {
return null;
}
}
/**
* Adds a category to the list.
* <p>
*
* @param index position to add the category.
* @param obj the SyndCategoryImpl object to add.
*
*/
@Override
public void add(final int index, final SyndCategory obj) {
final SyndCategoryImpl sCat = (SyndCategoryImpl) obj;
DCSubject subject;
if (sCat != null) {
subject = sCat.getSubject();
} else {
subject = null;
}
subjects.add(index, subject);
}
/**
* Removes a category element from a specific position.
* <p>
*
* @param index position to remove the category from.
* @return the SyndCategoryImpl being removed from position index, <b>null</b> if none.
*
*/
@Override
public SyndCategory remove(final int index) {
final DCSubject subject = subjects.remove(index);
if (subject != null) {
return new SyndCategoryImpl(subject);
} else {
return null;
}
}
/**
* Returns a list with the DCSubject elements of the SyndCategoryImpl list facade. To be used by
* the SyndFeedImpl class only.
* <p>
*
* @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<DCSubject> convertElementsSyndCategoryToSubject(final List<SyndCategory> cList) {
List<DCSubject> sList = null;
if (cList != null) {
sList = new ArrayList<DCSubject>();
for (int i = 0; i < cList.size(); i++) {
final SyndCategoryImpl sCat = (SyndCategoryImpl) cList.get(i);
DCSubject subject = null;
if (sCat != null) {
subject = sCat.getSubject();
}
sList.add(subject);
}
}
return sList;
}
}

View file

@ -0,0 +1,162 @@
package com.sun.syndication.feed.synd;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import com.sun.syndication.feed.module.DCSubject;
/**
* List implementation for SyndCategoryImpl elements. To be directly used by the SyndFeedImpl and
* SyndEntryImpl classes only.
* <p>
* 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.
* <p>
* This is necessary because the SyndFeedImpl categories are just a convenience to access the
* DublinCore subjects.
* <P>
* All this mess to avoid making DCSubjectImpl implement SyndCategory (which it would be odd).
* <p>
*
* @author Alejandro Abdelnur
*
*/
class SyndCategoryListFacade extends AbstractList<SyndCategory> {
private final List<DCSubject> subjects;
/**
* Default constructor. Creates and empty list.
*/
public SyndCategoryListFacade() {
this(new ArrayList<DCSubject>());
}
/**
* Creates a facade list of categories on top the given subject list.
* <P>
*
* @param subjects the list of subjects to create the facade.
*
*/
public SyndCategoryListFacade(final List<DCSubject> subjects) {
this.subjects = subjects;
}
/**
* Gets the category by index.
* <p>
*
* @param index the index position to retrieve the category.
* @return the SyndCategoryImpl in position index, <b>null</b> if none.
*
*/
@Override
public SyndCategory get(final int index) {
return new SyndCategoryImpl(subjects.get(index));
}
/**
* Returns the size of the list.
* <p>
*
* @return the size of the list.
*
*/
@Override
public int size() {
return subjects.size();
}
/**
* Sets a category in an existing position in the list.
* <p>
*
* @param index position to set the category.
* @param obj the SyndCategoryImpl object to set.
* @return the SyndCategoryImpl object that is being replaced, <b>null</b> if none.
*
*/
@Override
public SyndCategory set(final int index, final SyndCategory obj) {
final SyndCategoryImpl sCat = (SyndCategoryImpl) obj;
DCSubject subject;
if (sCat != null) {
subject = sCat.getSubject();
} else {
subject = null;
}
subject = subjects.set(index, subject);
if (subject != null) {
return new SyndCategoryImpl(subject);
} else {
return null;
}
}
/**
* Adds a category to the list.
* <p>
*
* @param index position to add the category.
* @param obj the SyndCategoryImpl object to add.
*
*/
@Override
public void add(final int index, final SyndCategory obj) {
final SyndCategoryImpl sCat = (SyndCategoryImpl) obj;
DCSubject subject;
if (sCat != null) {
subject = sCat.getSubject();
} else {
subject = null;
}
subjects.add(index, subject);
}
/**
* Removes a category element from a specific position.
* <p>
*
* @param index position to remove the category from.
* @return the SyndCategoryImpl being removed from position index, <b>null</b> if none.
*
*/
@Override
public SyndCategory remove(final int index) {
final DCSubject subject = subjects.remove(index);
if (subject != null) {
return new SyndCategoryImpl(subject);
} else {
return null;
}
}
/**
* Returns a list with the DCSubject elements of the SyndCategoryImpl list facade. To be used by
* the SyndFeedImpl class only.
* <p>
*
* @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<DCSubject> convertElementsSyndCategoryToSubject(final List<SyndCategory> cList) {
List<DCSubject> sList = null;
if (cList != null) {
sList = new ArrayList<DCSubject>();
for (int i = 0; i < cList.size(); i++) {
final SyndCategoryImpl sCat = (SyndCategoryImpl) cList.get(i);
DCSubject subject = null;
if (sCat != null) {
subject = sCat.getSubject();
}
sList.add(subject);
}
}
return sList;
}
}

View file

@ -28,21 +28,36 @@ import com.sun.syndication.feed.impl.ObjectBean;
/**
* Bean for content of SyndFeedImpl entries.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class SyndContentImpl implements Serializable, SyndContent {
private static final long serialVersionUID = -8831050456661121113L;
private static final CopyFromHelper COPY_FROM_HELPER;
private final ObjectBean objBean;
private String type;
private String value;
private String mode;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("type", String.class);
basePropInterfaceMap.put("value", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndContent.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public SyndContentImpl() {
objBean = new ObjectBean(SyndContent.class, this);
@ -51,10 +66,10 @@ public class SyndContentImpl implements Serializable, SyndContent {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -65,10 +80,10 @@ public class SyndContentImpl implements Serializable, SyndContent {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -80,9 +95,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -92,9 +107,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -106,9 +121,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
* <p>
* When used for the description of an entry, if <b>null</b> 'text/plain' must be assumed.
* <p>
*
*
* @return the content type, <b>null</b> if none.
*
*
*/
@Override
public String getType() {
@ -120,9 +135,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
* <p>
* When used for the description of an entry, if <b>null</b> 'text/plain' must be assumed.
* <p>
*
*
* @param type the content type to set, <b>null</b> if none.
*
*
*/
@Override
public void setType(final String type) {
@ -131,9 +146,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
/**
* Returns the content mode.
*
*
* @return the content mode, <b>null</b> if none.
*
*
*/
@Override
public String getMode() {
@ -142,9 +157,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
/**
* Sets the content mode.
*
*
* @param mode the content mode to set, <b>null</b> if none.
*
*
*/
@Override
public void setMode(final String mode) {
@ -154,9 +169,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
/**
* Returns the content value.
* <p>
*
*
* @return the content value, <b>null</b> if none.
*
*
*/
@Override
public String getValue() {
@ -166,9 +181,9 @@ public class SyndContentImpl implements Serializable, SyndContent {
/**
* Sets the content value.
* <p>
*
*
* @param value the content value to set, <b>null</b> if none.
*
*
*/
@Override
public void setValue(final String value) {
@ -185,16 +200,4 @@ public class SyndContentImpl implements Serializable, SyndContent {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("type", String.class);
basePropInterfaceMap.put("value", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndContent.class, basePropInterfaceMap, basePropClassImplMap);
}
}

View file

@ -13,16 +13,32 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author Alejandro Abdelnur
*/
public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
private static final long serialVersionUID = -5813049622142257411L;
private static final CopyFromHelper COPY_FROM_HELPER;
private final ObjectBean objBean;
private String url;
private String type;
private long length;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("url", String.class);
basePropInterfaceMap.put("type", String.class);
basePropInterfaceMap.put("length", Long.TYPE);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndEnclosure.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public SyndEnclosureImpl() {
objBean = new ObjectBean(SyndEnclosure.class, this);
@ -31,10 +47,10 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -45,10 +61,10 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -60,9 +76,9 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -72,9 +88,9 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -84,7 +100,7 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Returns the enclosure URL.
* <p/>
*
*
* @return the enclosure URL, <b>null</b> if none.
*/
@Override
@ -95,7 +111,7 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Sets the enclosure URL.
* <p/>
*
*
* @param url the enclosure URL to set, <b>null</b> if none.
*/
@Override
@ -106,7 +122,7 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Returns the enclosure length.
* <p/>
*
*
* @return the enclosure length, <b>null</b> if none.
*/
@Override
@ -117,7 +133,7 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Sets the enclosure length.
* <p/>
*
*
* @param length the enclosure length to set, <b>null</b> if none.
*/
@Override
@ -128,7 +144,7 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Returns the enclosure type.
* <p/>
*
*
* @return the enclosure type, <b>null</b> if none.
*/
@Override
@ -139,7 +155,7 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
/**
* Sets the enclosure type.
* <p/>
*
*
* @param type the enclosure type to set, <b>null</b> if none.
*/
@Override
@ -157,17 +173,4 @@ public class SyndEnclosureImpl implements Serializable, SyndEnclosure {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("url", String.class);
basePropInterfaceMap.put("type", String.class);
basePropInterfaceMap.put("length", Long.TYPE);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndEnclosure.class, basePropInterfaceMap, basePropClassImplMap);
}
}

View file

@ -28,6 +28,9 @@ import java.util.Set;
import org.jdom2.Element;
import com.rometools.utils.Dates;
import com.rometools.utils.Lists;
import com.rometools.utils.Strings;
import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.impl.CopyFromHelper;
import com.sun.syndication.feed.impl.ObjectBean;
@ -42,13 +45,18 @@ import com.sun.syndication.feed.synd.impl.URINormalizer;
/**
* Bean for entries of SyndFeedImpl feeds.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class SyndEntryImpl implements Serializable, SyndEntry {
private static final long serialVersionUID = 1944144041409866698L;
private static final CopyFromHelper COPY_FROM_HELPER;
private final ObjectBean objBean;
private String uri;
private String link;
private String comments;
@ -63,8 +71,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
private List<SyndPerson> contributors;
private SyndFeed source;
private List<Element> foreignMarkup;
private Object wireEntry; // com.sun.syndication.feed.atom.Entry or
// com.sun.syndication.feed.rss.Item
// com.sun.syndication.feed.atom.Entry or com.sun.syndication.feed.rss.Item
private Object wireEntry;
// ISSUE: some converters assume this is never null
private List<SyndCategory> categories = new ArrayList<SyndCategory>();
@ -80,19 +89,41 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
public static final Set<String> CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES);
static {
IGNORE_PROPERTIES.add("publishedDate");
IGNORE_PROPERTIES.add("author");
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
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);
basePropInterfaceMap.put("categories", SyndCategory.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom>, Class<?>>();
basePropClassImplMap.put(SyndContent.class, SyndContentImpl.class);
basePropClassImplMap.put(SyndEnclosure.class, SyndEnclosureImpl.class);
basePropClassImplMap.put(SyndCategory.class, SyndCategoryImpl.class);
basePropClassImplMap.put(DCModule.class, DCModuleImpl.class);
basePropClassImplMap.put(SyModule.class, SyModuleImpl.class);
COPY_FROM_HELPER = new CopyFromHelper(SyndEntry.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* For implementations extending SyndEntryImpl to be able to use the ObjectBean functionality
* with extended interfaces.
* <p>
*
*
* @param beanClass
* @param convenienceProperties set containing the convenience properties of the SyndEntryImpl
* (the are ignored during cloning, check CloneableBean for details).
*
*
*/
protected SyndEntryImpl(final Class<?> beanClass, final Set<String> convenienceProperties) {
objBean = new ObjectBean(beanClass, this, convenienceProperties);
@ -101,7 +132,7 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public SyndEntryImpl() {
this(SyndEntry.class, IGNORE_PROPERTIES);
@ -110,10 +141,10 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -124,10 +155,10 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -154,9 +185,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -166,9 +197,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -185,9 +216,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* <p>
* The returned URI is a normalized URI as specified in RFC 2396bis.
* <p>
*
*
* @return the entry URI, <b>null</b> if none.
*
*
*/
@Override
public String getUri() {
@ -202,9 +233,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* href="http://wiki.java.net/bin/edit/Javawsxml/Rome04URIMapping">Feed and entry URI
* mapping</a>.
* <p>
*
*
* @param uri the entry URI to set, <b>null</b> if none.
*
*
*/
@Override
public void setUri(final String uri) {
@ -214,9 +245,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry title.
* <p>
*
*
* @return the entry title, <b>null</b> if none.
*
*
*/
@Override
public String getTitle() {
@ -229,9 +260,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Sets the entry title.
* <p>
*
*
* @param title the entry title to set, <b>null</b> if none.
*
*
*/
@Override
public void setTitle(final String title) {
@ -244,9 +275,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry title as a text construct.
* <p>
*
*
* @return the entry title, <b>null</b> if none.
*
*
*/
@Override
public SyndContent getTitleEx() {
@ -256,9 +287,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Sets the entry title as a text construct.
* <p>
*
*
* @param title the entry title to set, <b>null</b> if none.
*
*
*/
@Override
public void setTitleEx(final SyndContent title) {
@ -268,9 +299,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry link.
* <p>
*
*
* @return the entry link, <b>null</b> if none.
*
*
*/
@Override
public String getLink() {
@ -280,9 +311,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Sets the entry link.
* <p>
*
*
* @param link the entry link to set, <b>null</b> if none.
*
*
*/
@Override
public void setLink(final String link) {
@ -292,9 +323,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry description.
* <p>
*
*
* @return the entry description, <b>null</b> if none.
*
*
*/
@Override
public SyndContent getDescription() {
@ -304,9 +335,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Sets the entry description.
* <p>
*
*
* @param description the entry description to set, <b>null</b> if none.
*
*
*/
@Override
public void setDescription(final SyndContent description) {
@ -316,25 +347,22 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry contents.
* <p>
*
*
* @return a list of SyndContentImpl elements with the entry contents, an empty list if none.
*
*
*/
@Override
public List<SyndContent> getContents() {
if (contents == null) {
contents = new ArrayList<SyndContent>();
}
return contents;
return contents = Lists.createWhenNull(contents);
}
/**
* Sets the entry contents.
* <p>
*
*
* @param contents the list of SyndContentImpl elements with the entry contents to set, an empty
* list or <b>null</b> if none.
*
*
*/
@Override
public void setContents(final List<SyndContent> contents) {
@ -344,25 +372,22 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry enclosures.
* <p>
*
*
* @return a list of SyndEnclosure elements with the entry enclosures, an empty list if none.
*
*
*/
@Override
public List<SyndEnclosure> getEnclosures() {
if (enclosures == null) {
enclosures = new ArrayList<SyndEnclosure>();
}
return enclosures;
return enclosures = Lists.createWhenNull(enclosures);
}
/**
* Sets the entry enclosures.
* <p>
*
*
* @param enclosures the list of SyndEnclosure elements with the entry enclosures to set, an
* empty list or <b>null</b> if none.
*
*
*/
@Override
public void setEnclosures(final List<SyndEnclosure> enclosures) {
@ -374,9 +399,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* <p>
* This method is a convenience method, it maps to the Dublin Core module date.
* <p>
*
*
* @return the entry published date, <b>null</b> if none.
*
*
*/
@Override
public Date getPublishedDate() {
@ -388,9 +413,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* <p>
* This method is a convenience method, it maps to the Dublin Core module date.
* <p>
*
*
* @param publishedDate the entry published date to set, <b>null</b> if none.
*
*
*/
@Override
public void setPublishedDate(final Date publishedDate) {
@ -400,9 +425,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry categories.
* <p>
*
*
* @return a list of SyndCategoryImpl elements with the entry categories, an empty list if none.
*
*
*/
@Override
public List<SyndCategory> getCategories() {
@ -414,10 +439,10 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* <p>
* This method is a convenience method, it maps to the Dublin Core module subjects.
* <p>
*
*
* @param categories the list of SyndCategoryImpl elements with the entry categories to set, an
* empty list or <b>null</b> if none.
*
*
*/
@Override
public void setCategories(final List<SyndCategory> categories) {
@ -427,15 +452,13 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the entry modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the entry modules, an empty list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
modules = Lists.createWhenNull(modules);
if (ModuleUtils.getModule(modules, DCModule.URI) == null) {
modules.add(new DCModuleImpl());
}
@ -445,10 +468,10 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Sets the entry modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the entry modules to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -458,7 +481,7 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/
@ -469,9 +492,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the Dublin Core module of the feed.
*
*
* @return the DC module, it's never <b>null</b>
*
*
*/
private DCModule getDCModule() {
return (DCModule) getModule(DCModule.URI);
@ -487,48 +510,21 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
COPY_FROM_HELPER.copy(this, obj);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
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);
basePropInterfaceMap.put("categories", SyndCategory.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom>, Class<?>>();
basePropClassImplMap.put(SyndContent.class, SyndContentImpl.class);
basePropClassImplMap.put(SyndEnclosure.class, SyndEnclosureImpl.class);
basePropClassImplMap.put(SyndCategory.class, SyndCategoryImpl.class);
basePropClassImplMap.put(DCModule.class, DCModuleImpl.class);
basePropClassImplMap.put(SyModule.class, SyModuleImpl.class);
COPY_FROM_HELPER = new CopyFromHelper(SyndEntry.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Returns the links
* <p>
*
*
* @return Returns the links.
*/
@Override
public List<SyndLink> getLinks() {
if (links == null) {
links = new ArrayList<SyndLink>();
}
return links;
return links = Lists.createWhenNull(links);
}
/**
* Set the links
* <p>
*
*
* @param links The links to set.
*/
@Override
@ -539,22 +535,18 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns the updatedDate
* <p>
*
*
* @return Returns the updatedDate.
*/
@Override
public Date getUpdatedDate() {
if (updatedDate == null) {
return null;
} else {
return new Date(updatedDate.getTime());
}
return Dates.copy(updatedDate);
}
/**
* Set the updatedDate
* <p>
*
*
* @param updatedDate The updatedDate to set.
*/
@Override
@ -564,16 +556,9 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
@Override
public List<SyndPerson> getAuthors() {
if (authors == null) {
authors = new ArrayList<SyndPerson>();
}
return authors;
return authors = Lists.createWhenNull(authors);
}
/*
* (non-Javadoc)
* @see com.sun.syndication.feed.synd.SyndEntry#setAuthors(java.util.List)
*/
@Override
public void setAuthors(final List<SyndPerson> authors) {
this.authors = authors;
@ -584,26 +569,29 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* <p>
* This method is a convenience method, it maps to the Dublin Core module creator.
* <p>
*
*
* @return the entry author, <b>null</b> 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.isEmpty()) {
if (Lists.isNotEmpty(authors)) {
author = authors.get(0).getName();
} else {
author = getDCModule().getCreator();
}
if (author == null) {
author = "";
}
return author;
}
/**
@ -611,28 +599,24 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
* <p>
* This method is a convenience method, it maps to the Dublin Core module creator.
* <p>
*
*
* @param author the entry author to set, <b>null</b> if none.
*
*
*/
@Override
public void setAuthor(final String author) {
// Get the DCModule so that we can check to see if "creator" is already
// set.
// Get the DCModule so that we can check to see if "creator" is already set.
final DCModule dcModule = getDCModule();
final String currentValue = dcModule.getCreator();
if (currentValue == null || currentValue.length() == 0) {
if (Strings.isEmpty(currentValue)) {
getDCModule().setCreator(author);
}
}
@Override
public List<SyndPerson> getContributors() {
if (contributors == null) {
contributors = new ArrayList<SyndPerson>();
}
return contributors;
return contributors = Lists.createWhenNull(contributors);
}
@Override
@ -653,42 +637,33 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
/**
* Returns foreign markup found at channel level.
* <p>
*
*
* @return list of JDOM nodes containing channel-level foreign markup, an empty list if none.
*
*
*/
@Override
public List<Element> getForeignMarkup() {
if (foreignMarkup == null) {
foreignMarkup = new ArrayList<Element>();
}
return foreignMarkup;
return foreignMarkup = Lists.createWhenNull(foreignMarkup);
}
/**
* Sets foreign markup found at channel level.
* <p>
*
*
* @param foreignMarkup list of JDOM nodes containing channel-level foreign markup, an empty
* list if none.
*
*
*/
@Override
public void setForeignMarkup(final List<Element> foreignMarkup) {
this.foreignMarkup = foreignMarkup;
}
/**
* {@inheritDoc}
*/
@Override
public String getComments() {
return comments;
}
/**
* {@inheritDoc}
*/
@Override
public void setComments(final String comments) {
this.comments = comments;
@ -705,11 +680,13 @@ public class SyndEntryImpl implements Serializable, SyndEntry {
@Override
public SyndLink findRelatedLink(final String relation) {
for (final SyndLink l : getLinks()) {
if (relation.equals(l.getRel())) {
return l;
final List<SyndLink> syndLinks = getLinks();
for (final SyndLink syndLink : syndLinks) {
if (relation.equals(syndLink.getRel())) {
return syndLink;
}
}
return null;
}
}

View file

@ -17,7 +17,6 @@
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;
@ -28,6 +27,7 @@ import java.util.Set;
import org.jdom2.Element;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.impl.CopyFromHelper;
@ -47,13 +47,16 @@ import com.sun.syndication.feed.synd.impl.URINormalizer;
* It handles all RSS versions, Atom 0.3 and Atom 1.0, it normalizes all info, it may lose
* information.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class SyndFeedImpl implements Serializable, SyndFeed {
private static final long serialVersionUID = -2529165503200548045L;
private static final CopyFromHelper COPY_FROM_HELPER;
private final ObjectBean objBean;
private String encoding;
@ -92,17 +95,40 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
public static final Set<String> CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES);
static {
IGNORE_PROPERTIES.add("publishedDate");
IGNORE_PROPERTIES.add("author");
IGNORE_PROPERTIES.add("copyright");
IGNORE_PROPERTIES.add("categories");
IGNORE_PROPERTIES.add("language");
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
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);
basePropInterfaceMap.put("categories", SyndCategory.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom>, Class<?>>();
basePropClassImplMap.put(SyndEntry.class, SyndEntryImpl.class);
basePropClassImplMap.put(SyndImage.class, SyndImageImpl.class);
basePropClassImplMap.put(SyndCategory.class, SyndCategoryImpl.class);
basePropClassImplMap.put(DCModule.class, DCModuleImpl.class);
basePropClassImplMap.put(SyModule.class, SyModuleImpl.class);
COPY_FROM_HELPER = new CopyFromHelper(SyndFeed.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Returns the real feed types the SyndFeedImpl supports when converting from and to.
* <p>
*
*
* @return the real feed type supported.
*/
@Override
@ -114,11 +140,11 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* For implementations extending SyndFeedImpl to be able to use the ObjectBean functionality
* with extended interfaces.
* <p>
*
*
* @param beanClass
* @param convenienceProperties set containing the convenience properties of the SyndEntryImpl
* (the are ignored during cloning, check CloneableBean for details).
*
*
*/
protected SyndFeedImpl(final Class<?> beanClass, final Set<String> convenienceProperties) {
objBean = new ObjectBean(beanClass, this, convenienceProperties);
@ -127,7 +153,7 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public SyndFeedImpl() {
this(null);
@ -137,9 +163,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* Creates a SyndFeedImpl and populates all its properties out of the given RSS Channel or Atom
* Feed properties.
* <p>
*
*
* @param feed the RSS Channel or the Atom Feed to populate the properties from.
*
*
*/
public SyndFeedImpl(final WireFeed feed) {
this(feed, false);
@ -149,7 +175,7 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* 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
*/
@ -175,10 +201,10 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -189,10 +215,10 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -212,9 +238,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -224,9 +250,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -238,9 +264,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* The feed type of the created WireFeed is taken from the SyndFeedImpl feedType property.
* <p>
*
*
* @return the real feed.
*
*
*/
@Override
public WireFeed createWireFeed() {
@ -250,21 +276,25 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Creates a real feed containing the information of the SyndFeedImpl.
* <p>
*
*
* @param feedType the feed type for the WireFeed to be created.
* @return the real feed.
*
*
*/
@Override
public WireFeed createWireFeed(final String feedType) {
if (feedType == null) {
throw new IllegalArgumentException("Feed type cannot be null");
}
final Converter converter = CONVERTERS.getConverter(feedType);
if (converter == null) {
throw new IllegalArgumentException("Invalid feed type [" + feedType + "]");
}
return converter.createRealFeed(this);
}
/**
@ -273,9 +303,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* 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() {
@ -285,9 +315,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the wire feed type the feed had/will-have when coverted from/to a WireFeed.
* <p>
*
*
* @return the feed type, <b>null</b> if none.
*
*
*/
@Override
public String getFeedType() {
@ -297,9 +327,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the wire feed type the feed will-have when coverted to a WireFeed.
* <p>
*
*
* @param feedType the feed type to set, <b>null</b> if none.
*
*
*/
@Override
public void setFeedType(final String feedType) {
@ -309,9 +339,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the charset encoding of a the feed. This is not set by Rome parsers.
* <p>
*
*
* @return the charset encoding of the feed.
*
*
*/
@Override
public String getEncoding() {
@ -321,9 +351,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the charset encoding of a the feed. This is not set by Rome parsers.
* <p>
*
*
* @param encoding the charset encoding of the feed.
*
*
*/
@Override
public void setEncoding(final String encoding) {
@ -350,9 +380,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* be treated as distinct entities. In the RSS 1.0 case the URI must be a valid RDF URI
* reference.
* <p>
*
*
* @return the feed URI, <b>null</b> if none.
*
*
*/
@Override
public String getUri() {
@ -377,9 +407,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* be treated as distinct entities. In the RSS 1.0 case the URI must be a valid RDF URI
* reference.
* <p>
*
*
* @param uri the feed URI to set, <b>null</b> if none.
*
*
*/
@Override
public void setUri(final String uri) {
@ -389,9 +419,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the feed title.
* <p>
*
*
* @return the feed title, <b>null</b> if none.
*
*
*/
@Override
public String getTitle() {
@ -404,9 +434,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the feed title.
* <p>
*
*
* @param title the feed title to set, <b>null</b> if none.
*
*
*/
@Override
public void setTitle(final String title) {
@ -419,9 +449,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the feed title as a text construct.
* <p>
*
*
* @return the feed title, <b>null</b> if none.
*
*
*/
@Override
public SyndContent getTitleEx() {
@ -431,9 +461,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the feed title as a text construct.
* <p>
*
*
* @param title the feed title to set, <b>null</b> if none.
*
*
*/
@Override
public void setTitleEx(final SyndContent title) {
@ -453,9 +483,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* be treated as distinct entities. In the RSS 1.0 case the URI must be a valid RDF URI
* reference.
* <p>
*
*
* @return the feed link, <b>null</b> if none.
*
*
*/
@Override
public String getLink() {
@ -475,9 +505,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* be treated as distinct entities. In the RSS 1.0 case the URI must be a valid RDF URI
* reference.
* <p>
*
*
* @param link the feed link to set, <b>null</b> if none.
*
*
*/
@Override
public void setLink(final String link) {
@ -487,9 +517,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the feed description.
* <p>
*
*
* @return the feed description, <b>null</b> if none.
*
*
*/
@Override
public String getDescription() {
@ -502,9 +532,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the feed description.
* <p>
*
*
* @param description the feed description to set, <b>null</b> if none.
*
*
*/
@Override
public void setDescription(final String description) {
@ -517,9 +547,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the feed description as a text construct.
* <p>
*
*
* @return the feed description, <b>null</b> if none.
*
*
*/
@Override
public SyndContent getDescriptionEx() {
@ -529,9 +559,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the feed description as a text construct.
* <p>
*
*
* @param description the feed description to set, <b>null</b> if none.
*
*
*/
@Override
public void setDescriptionEx(final SyndContent description) {
@ -543,9 +573,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module date.
* <p>
*
*
* @return the feed published date, <b>null</b> if none.
*
*
*/
@Override
public Date getPublishedDate() {
@ -557,9 +587,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module date.
* <p>
*
*
* @param publishedDate the feed published date to set, <b>null</b> if none.
*
*
*/
@Override
public void setPublishedDate(final Date publishedDate) {
@ -571,9 +601,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module rights.
* <p>
*
*
* @return the feed copyright, <b>null</b> if none.
*
*
*/
@Override
public String getCopyright() {
@ -585,9 +615,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module rights.
* <p>
*
*
* @param copyright the feed copyright to set, <b>null</b> if none.
*
*
*/
@Override
public void setCopyright(final String copyright) {
@ -597,9 +627,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the feed image.
* <p>
*
*
* @return the feed image, <b>null</b> if none.
*
*
*/
@Override
public SyndImage getImage() {
@ -609,9 +639,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the feed image.
* <p>
*
*
* @param image the feed image to set, <b>null</b> if none.
*
*
*/
@Override
public void setImage(final SyndImage image) {
@ -623,9 +653,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module subjects.
* <p>
*
*
* @return a list of SyndCategoryImpl elements with the feed categories, an empty list if none.
*
*
*/
@Override
public List<SyndCategory> getCategories() {
@ -637,10 +667,10 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module subjects.
* <p>
*
*
* @param categories the list of SyndCategoryImpl elements with the feed categories to set, an
* empty list or <b>null</b> if none.
*
*
*/
@Override
public void setCategories(final List<SyndCategory> categories) {
@ -650,25 +680,22 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the feed entries.
* <p>
*
*
* @return a list of SyndEntryImpl elements with the feed entries, an empty list if none.
*
*
*/
@Override
public List<SyndEntry> getEntries() {
if (entries == null) {
entries = new ArrayList<SyndEntry>();
}
return entries;
return entries = Lists.createWhenNull(entries);
}
/**
* Sets the feed entries.
* <p>
*
*
* @param entries the list of SyndEntryImpl elements with the feed entries to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setEntries(final List<SyndEntry> entries) {
@ -680,9 +707,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module language.
* <p>
*
*
* @return the feed language, <b>null</b> if none.
*
*
*/
@Override
public String getLanguage() {
@ -694,9 +721,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module language.
* <p>
*
*
* @param language the feed language to set, <b>null</b> if none.
*
*
*/
@Override
public void setLanguage(final String language) {
@ -706,15 +733,13 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the feed modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the feed modules, an empty list if none.
*
*
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
modules = Lists.createWhenNull(modules);
if (ModuleUtils.getModule(modules, DCModule.URI) == null) {
modules.add(new DCModuleImpl());
}
@ -724,10 +749,10 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Sets the feed modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the feed modules to set, an empty list or
* <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -737,7 +762,7 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/
@ -748,9 +773,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns the Dublin Core module of the feed.
*
*
* @return the DC module, it's never <b>null</b>
*
*
*/
private DCModule getDCModule() {
return (DCModule) getModule(DCModule.URI);
@ -766,51 +791,21 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
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 {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
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);
basePropInterfaceMap.put("categories", SyndCategory.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = new HashMap<Class<? extends CopyFrom>, Class<?>>();
basePropClassImplMap.put(SyndEntry.class, SyndEntryImpl.class);
basePropClassImplMap.put(SyndImage.class, SyndImageImpl.class);
basePropClassImplMap.put(SyndCategory.class, SyndCategoryImpl.class);
basePropClassImplMap.put(DCModule.class, DCModuleImpl.class);
basePropClassImplMap.put(SyModule.class, SyModuleImpl.class);
COPY_FROM_HELPER = new CopyFromHelper(SyndFeed.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Returns the links
* <p>
*
*
* @return Returns the links.
*/
@Override
public List<SyndLink> getLinks() {
if (links == null) {
links = new ArrayList<SyndLink>();
}
return links;
return links = Lists.createWhenNull(links);
}
/**
* Set the links
* <p>
*
*
* @param links The links to set.
*/
@Override
@ -820,10 +815,7 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
@Override
public List<SyndPerson> getAuthors() {
if (authors == null) {
authors = new ArrayList<SyndPerson>();
}
return authors;
return authors = Lists.createWhenNull(authors);
}
@Override
@ -836,9 +828,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module creator.
* <p>
*
*
* @return the feed author, <b>null</b> if none.
*
*
*/
@Override
public String getAuthor() {
@ -850,9 +842,9 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
* <p>
* This method is a convenience method, it maps to the Dublin Core module creator.
* <p>
*
*
* @param author the feed author to set, <b>null</b> if none.
*
*
*/
@Override
public void setAuthor(final String author) {
@ -861,10 +853,7 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
@Override
public List<SyndPerson> getContributors() {
if (contributors == null) {
contributors = new ArrayList<SyndPerson>();
}
return contributors;
return contributors = Lists.createWhenNull(contributors);
}
@Override
@ -875,24 +864,21 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
/**
* Returns foreign markup found at channel level.
* <p>
*
*
* @return Opaque object to discourage use
*
*
*/
@Override
public List<Element> getForeignMarkup() {
if (foreignMarkup == null) {
foreignMarkup = new ArrayList<Element>();
}
return foreignMarkup;
return foreignMarkup = Lists.createWhenNull(foreignMarkup);
}
/**
* Sets foreign markup found at channel level.
* <p>
*
*
* @param foreignMarkup Opaque object to discourage use
*
*
*/
@Override
public void setForeignMarkup(final List<Element> foreignMarkup) {
@ -904,83 +890,54 @@ public class SyndFeedImpl implements Serializable, SyndFeed {
return preserveWireFeed;
}
/**
* {@inheritDoc}
*/
@Override
public String getDocs() {
return docs;
}
/**
* {@inheritDoc}
*/
@Override
public void setDocs(final String docs) {
this.docs = docs;
}
/**
* {@inheritDoc}
*/
@Override
public String getGenerator() {
return generator;
}
/**
* {@inheritDoc}
*/
@Override
public void setGenerator(final String generator) {
this.generator = generator;
}
/**
* {@inheritDoc}
*/
@Override
public String getManagingEditor() {
return managingEditor;
}
/**
* {@inheritDoc}
*/
@Override
public void setManagingEditor(final String managingEditor) {
this.managingEditor = managingEditor;
}
/**
* {@inheritDoc}
*/
@Override
public String getWebMaster() {
return webMaster;
}
/**
* {@inheritDoc}
*/
@Override
public void setWebMaster(final String webMaster) {
this.webMaster = webMaster;
}
/**
* {@inheritDoc}
*/
@Override
public String getStyleSheet() {
return styleSheet;
}
/**
* {@inheritDoc}
*/
@Override
public void setStyleSheet(final String styleSheet) {
this.styleSheet = styleSheet;
}
}

View file

@ -28,22 +28,39 @@ import com.sun.syndication.feed.impl.ObjectBean;
/**
* Bean for images of SyndFeedImpl feeds.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class SyndImageImpl implements Serializable, SyndImage {
private static final long serialVersionUID = 5078981553559513247L;
private static final CopyFromHelper COPY_FROM_HELPER;
private final ObjectBean objBean;
private String title;
private String url;
private String link;
private String description;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("title", String.class);
basePropInterfaceMap.put("url", String.class);
basePropInterfaceMap.put("link", String.class);
basePropInterfaceMap.put("description", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndImage.class, basePropInterfaceMap, basePropClassImplMap);
}
/**
* Default constructor. All properties are set to <b>null</b>.
* <p>
*
*
*/
public SyndImageImpl() {
objBean = new ObjectBean(SyndImage.class, this);
@ -52,10 +69,10 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -66,10 +83,10 @@ public class SyndImageImpl implements Serializable, SyndImage {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -81,9 +98,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -93,9 +110,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -105,9 +122,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Returns the image title.
* <p>
*
*
* @return the image title, <b>null</b> if none.
*
*
*/
@Override
public String getTitle() {
@ -117,9 +134,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Sets the image title.
* <p>
*
*
* @param title the image title to set, <b>null</b> if none.
*
*
*/
@Override
public void setTitle(final String title) {
@ -129,9 +146,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Returns the image URL.
* <p>
*
*
* @return the image URL, <b>null</b> if none.
*
*
*/
@Override
public String getUrl() {
@ -141,9 +158,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Sets the image URL.
* <p>
*
*
* @param url the image URL to set, <b>null</b> if none.
*
*
*/
@Override
public void setUrl(final String url) {
@ -153,9 +170,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Returns the image link.
* <p>
*
*
* @return the image link, <b>null</b> if none.
*
*
*/
@Override
public String getLink() {
@ -165,9 +182,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Sets the image link.
* <p>
*
*
* @param link the image link to set, <b>null</b> if none.
*
*
*/
@Override
public void setLink(final String link) {
@ -177,9 +194,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Returns the image description.
* <p>
*
*
* @return the image description, <b>null</b> if none.
*
*
*/
@Override
public String getDescription() {
@ -189,9 +206,9 @@ public class SyndImageImpl implements Serializable, SyndImage {
/**
* Sets the image description.
* <p>
*
*
* @param description the image description to set, <b>null</b> if none.
*
*
*/
@Override
public void setDescription(final String description) {
@ -208,18 +225,4 @@ public class SyndImageImpl implements Serializable, SyndImage {
COPY_FROM_HELPER.copy(this, syndImage);
}
private static final CopyFromHelper COPY_FROM_HELPER;
static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
basePropInterfaceMap.put("title", String.class);
basePropInterfaceMap.put("url", String.class);
basePropInterfaceMap.put("link", String.class);
basePropInterfaceMap.put("description", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
COPY_FROM_HELPER = new CopyFromHelper(SyndImage.class, basePropInterfaceMap, basePropClassImplMap);
}
}

View file

@ -18,9 +18,9 @@
package com.sun.syndication.feed.synd;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.impl.ModuleUtils;
@ -28,13 +28,16 @@ import com.sun.syndication.feed.module.impl.ModuleUtils;
/**
* Bean for authors and contributors of SyndFeedImpl feeds and entries.
* <p>
*
*
* @author Dave Johnson
*
*
*/
public class SyndPersonImpl implements Serializable, SyndPerson {
private static final long serialVersionUID = 8523373264589239335L;
private final ObjectBean objBean;
private String name;
private String uri;
private String email;
@ -51,10 +54,10 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Creates a deep 'bean' clone of the object.
* <p>
*
*
* @return a clone of the object.
* @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
*
*
*/
@Override
public Object clone() throws CloneNotSupportedException {
@ -65,10 +68,10 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
* Indicates whether some other object is "equal to" this one as defined by the Object equals()
* method.
* <p>
*
*
* @param other he reference object with which to compare.
* @return <b>true</b> if 'this' object is equal to the 'other' object.
*
*
*/
@Override
public boolean equals(final Object other) {
@ -83,9 +86,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
* <p>
* It follows the contract defined by the Object hashCode() method.
* <p>
*
*
* @return the hashcode of the bean object.
*
*
*/
@Override
public int hashCode() {
@ -95,9 +98,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Returns the String representation for the object.
* <p>
*
*
* @return String representation for the object.
*
*
*/
@Override
public String toString() {
@ -107,9 +110,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Returns the person name.
* <p>
*
*
* @return the person name, <b>null</b> if none.
*
*
*/
@Override
public String getName() {
@ -119,9 +122,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Sets the category name.
* <p>
*
*
* @param name the category name to set, <b>null</b> if none.
*
*
*/
@Override
public void setName(final String name) {
@ -131,9 +134,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Returns the person's e-mail address.
* <p>
*
*
* @return the person's e-mail address, <b>null</b> if none.
*
*
*/
@Override
public String getEmail() {
@ -143,9 +146,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Sets the person's e-mail address.
* <p>
*
*
* @param email The person's e-mail address to set, <b>null</b> if none.
*
*
*/
@Override
public void setEmail(final String email) {
@ -155,9 +158,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Returns the person's URI.
* <p>
*
*
* @return the person's URI, <b>null</b> if none.
*
*
*/
@Override
public String getUri() {
@ -167,9 +170,9 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Sets the person's URI.
* <p>
*
*
* @param uri the peron's URI to set, <b>null</b> if none.
*
*
*/
@Override
public void setUri(final String uri) {
@ -179,24 +182,21 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Returns the person modules.
* <p>
*
*
* @return a list of ModuleImpl elements with the person modules, an empty list if none.
*/
@Override
public List<Module> getModules() {
if (modules == null) {
modules = new ArrayList<Module>();
}
return modules;
return modules = Lists.createWhenNull(modules);
}
/**
* Sets the person modules.
* <p>
*
*
* @param modules the list of ModuleImpl elements with the person modules to set, an empty list
* or <b>null</b> if none.
*
*
*/
@Override
public void setModules(final List<Module> modules) {
@ -206,7 +206,7 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
/**
* Returns the module identified by a given URI.
* <p>
*
*
* @param uri the URI of the ModuleImpl.
* @return The module with the given URI, <b>null</b> if none.
*/
@ -214,4 +214,5 @@ public class SyndPersonImpl implements Serializable, SyndPerson {
public Module getModule(final String uri) {
return ModuleUtils.getModule(getModules(), uri);
}
}

View file

@ -21,6 +21,11 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.jdom2.Element;
import com.rometools.utils.Alternatives;
import com.rometools.utils.Lists;
import com.rometools.utils.Strings;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.atom.Content;
import com.sun.syndication.feed.atom.Entry;
@ -46,6 +51,7 @@ import com.sun.syndication.feed.synd.SyndPersonImpl;
/**
*/
public class ConverterForAtom03 implements Converter {
private final String type;
public ConverterForAtom03() {
@ -63,24 +69,29 @@ public class ConverterForAtom03 implements Converter {
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {
final Feed aFeed = (Feed) feed;
syndFeed.setModules(ModuleUtils.cloneModules(aFeed.getModules()));
if (!feed.getForeignMarkup().isEmpty()) {
syndFeed.setForeignMarkup(feed.getForeignMarkup());
final List<Element> foreignMarkup = feed.getForeignMarkup();
if (Lists.isNotEmpty(foreignMarkup)) {
syndFeed.setForeignMarkup(foreignMarkup);
}
syndFeed.setEncoding(aFeed.getEncoding());
syndFeed.setStyleSheet(aFeed.getStyleSheet());
if (aFeed.getLogo() != null) {
final String logo = aFeed.getLogo();
final String icon = aFeed.getIcon();
if (logo != null) {
final SyndImage image = new SyndImageImpl();
image.setUrl(aFeed.getLogo());
image.setUrl(logo);
syndFeed.setImage(image);
} else if (aFeed.getIcon() != null) {
} else if (icon != null) {
final SyndImage image = new SyndImageImpl();
image.setUrl(aFeed.getIcon());
image.setUrl(icon);
syndFeed.setImage(image);
}
@ -89,17 +100,19 @@ public class ConverterForAtom03 implements Converter {
syndFeed.setTitle(aFeed.getTitle());
// use first alternate links as THE link
if (aFeed.getAlternateLinks() != null && !aFeed.getAlternateLinks().isEmpty()) {
final Link theLink = aFeed.getAlternateLinks().get(0);
syndFeed.setLink(theLink.getHrefResolved());
final List<Link> alternateLinks = aFeed.getAlternateLinks();
if (Lists.isNotEmpty(alternateLinks)) {
final Link link = alternateLinks.get(0);
syndFeed.setLink(link.getHrefResolved());
}
// lump alternate and other links together
final List<SyndLink> syndLinks = new ArrayList<SyndLink>();
if (aFeed.getAlternateLinks() != null && !aFeed.getAlternateLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(aFeed.getAlternateLinks()));
if (Lists.isNotEmpty(alternateLinks)) {
syndLinks.addAll(createSyndLinks(alternateLinks));
}
if (aFeed.getOtherLinks() != null && !aFeed.getOtherLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(aFeed.getOtherLinks()));
final List<Link> otherLinks = aFeed.getOtherLinks();
if (Lists.isNotEmpty(otherLinks)) {
syndLinks.addAll(createSyndLinks(otherLinks));
}
syndFeed.setLinks(syndLinks);
@ -109,7 +122,7 @@ public class ConverterForAtom03 implements Converter {
}
final List<Entry> aEntries = aFeed.getEntries();
if (aEntries != null) {
if (Lists.isNotEmpty(aEntries)) {
syndFeed.setEntries(createSyndEntries(aEntries, syndFeed.isPreservingWireFeed()));
}
@ -122,7 +135,7 @@ public class ConverterForAtom03 implements Converter {
}
final List<SyndPerson> authors = aFeed.getAuthors();
if (authors != null && !authors.isEmpty()) {
if (Lists.isNotEmpty(authors)) {
syndFeed.setAuthors(createSyndPersons(authors));
}
@ -138,16 +151,16 @@ public class ConverterForAtom03 implements Converter {
}
protected List<SyndLink> createSyndLinks(final List<Link> aLinks) {
final ArrayList<SyndLink> sLinks = new ArrayList<SyndLink>();
for (final Link link2 : aLinks) {
final Link link = link2;
protected List<SyndLink> createSyndLinks(final List<Link> atomLinks) {
final ArrayList<SyndLink> syndLinks = new ArrayList<SyndLink>();
for (final Link atomLink : atomLinks) {
final Link link = atomLink;
if (!link.getRel().equals("enclosure")) {
final SyndLink sLink = createSyndLink(link);
sLinks.add(sLink);
final SyndLink syndLink = createSyndLink(link);
syndLinks.add(syndLink);
}
}
return sLinks;
return syndLinks;
}
public SyndLink createSyndLink(final Link link) {
@ -161,38 +174,42 @@ public class ConverterForAtom03 implements Converter {
protected List<SyndEntry> createSyndEntries(final List<Entry> atomEntries, final boolean preserveWireItems) {
final List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
for (int i = 0; i < atomEntries.size(); i++) {
syndEntries.add(createSyndEntry(atomEntries.get(i), preserveWireItems));
for (final Entry atomEntry : atomEntries) {
syndEntries.add(createSyndEntry(atomEntry, preserveWireItems));
}
return syndEntries;
}
protected SyndEntry createSyndEntry(final Entry entry, final boolean preserveWireItem) {
final SyndEntryImpl syndEntry = new SyndEntryImpl();
if (preserveWireItem) {
syndEntry.setWireEntry(entry);
}
syndEntry.setModules(ModuleUtils.cloneModules(entry.getModules()));
if (!entry.getForeignMarkup().isEmpty()) {
syndEntry.setForeignMarkup(entry.getForeignMarkup());
final List<Element> foreignMarkup = entry.getForeignMarkup();
if (Lists.isNotEmpty(foreignMarkup)) {
syndEntry.setForeignMarkup(foreignMarkup);
}
syndEntry.setTitle(entry.getTitle());
// if there is exactly one alternate link, use that as THE link
if (entry.getAlternateLinks() != null && entry.getAlternateLinks().size() == 1) {
final Link theLink = entry.getAlternateLinks().get(0);
final List<Link> alternateLinks = entry.getAlternateLinks();
if (Lists.sizeIs(alternateLinks, 1)) {
final Link theLink = alternateLinks.get(0);
syndEntry.setLink(theLink.getHrefResolved());
}
// Create synd enclosures from enclosure links
final List<SyndEnclosure> syndEnclosures = new ArrayList<SyndEnclosure>();
if (entry.getOtherLinks() != null && !entry.getOtherLinks().isEmpty()) {
final List<Link> oLinks = entry.getOtherLinks();
for (final Link link : oLinks) {
final Link thisLink = link;
final List<Link> otherLinks = entry.getOtherLinks();
if (Lists.isNotEmpty(otherLinks)) {
for (final Link otherLink : otherLinks) {
final Link thisLink = otherLink;
if ("enclosure".equals(thisLink.getRel())) {
syndEnclosures.add(createSyndEnclosure(entry, thisLink));
}
@ -202,63 +219,64 @@ public class ConverterForAtom03 implements Converter {
// lump alternate and other links together
final List<SyndLink> syndLinks = new ArrayList<SyndLink>();
if (entry.getAlternateLinks() != null && !entry.getAlternateLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(entry.getAlternateLinks()));
if (Lists.isNotEmpty(alternateLinks)) {
syndLinks.addAll(createSyndLinks(alternateLinks));
}
if (entry.getOtherLinks() != null && !entry.getOtherLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(entry.getOtherLinks()));
if (Lists.isNotEmpty(otherLinks)) {
syndLinks.addAll(createSyndLinks(otherLinks));
}
syndEntry.setLinks(syndLinks);
final String id = entry.getId();
if (id != null) {
syndEntry.setUri(entry.getId());
syndEntry.setUri(id);
} else {
syndEntry.setUri(syndEntry.getLink());
final String link = syndEntry.getLink();
syndEntry.setUri(link);
}
Content content = entry.getSummary();
if (content == null) {
Content summary = entry.getSummary();
if (summary == null) {
final List<Content> contents = entry.getContents();
if (contents != null && !contents.isEmpty()) {
content = contents.get(0);
if (Lists.isNotEmpty(contents)) {
summary = contents.get(0);
}
}
if (content != null) {
} else {
final SyndContent sContent = new SyndContentImpl();
sContent.setType(content.getType());
sContent.setValue(content.getValue());
sContent.setType(summary.getType());
sContent.setValue(summary.getValue());
syndEntry.setDescription(sContent);
}
final List<Content> contents = entry.getContents();
if (!contents.isEmpty()) {
if (Lists.isNotEmpty(contents)) {
final List<SyndContent> sContents = new ArrayList<SyndContent>();
for (int i = 0; i < contents.size(); i++) {
content = contents.get(i);
for (final Content content : contents) {
final SyndContent sContent = new SyndContentImpl();
sContent.setType(content.getType());
sContent.setValue(content.getValue());
sContent.setMode(content.getMode());
sContents.add(sContent);
}
syndEntry.setContents(sContents);
}
final List<SyndPerson> authors = entry.getAuthors();
if (authors != null && !authors.isEmpty()) {
if (Lists.isNotEmpty(authors)) {
syndEntry.setAuthors(createSyndPersons(authors));
final SyndPerson person0 = syndEntry.getAuthors().get(0);
syndEntry.setAuthor(person0.getName());
final SyndPerson firstPerson = syndEntry.getAuthors().get(0);
syndEntry.setAuthor(firstPerson.getName());
}
Date date = entry.getModified();
if (date == null) {
date = entry.getIssued();
if (date == null) {
date = entry.getCreated();
}
date = Alternatives.firstNotNull(entry.getIssued(), entry.getCreated());
}
if (date != null) {
syndEntry.setPublishedDate(date);
}
@ -286,13 +304,16 @@ public class ConverterForAtom03 implements Converter {
final SyndContent sTitle = syndFeed.getTitleEx();
if (sTitle != null) {
final Content title = new Content();
if (sTitle.getType() != null) {
title.setType(sTitle.getType());
final String type = sTitle.getType();
if (type != null) {
title.setType(type);
}
if (sTitle.getMode() != null) {
title.setMode(sTitle.getMode());
final String mode = sTitle.getMode();
if (mode != null) {
title.setMode(mode);
}
title.setValue(sTitle.getValue());
@ -302,12 +323,14 @@ public class ConverterForAtom03 implements Converter {
// separate SyndEntry's links collection into alternate and other links
final List<Link> alternateLinks = new ArrayList<Link>();
final List<Link> otherLinks = new ArrayList<Link>();
final List<SyndLink> slinks = syndFeed.getLinks();
if (slinks != null) {
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())) {
final String rel = link.getRel();
if (Strings.isBlank(rel) || "alternate".equals(rel)) {
alternateLinks.add(link);
} else {
otherLinks.add(link);
@ -315,10 +338,11 @@ public class ConverterForAtom03 implements Converter {
}
}
// no alternate link? then use THE link if there is one
if (alternateLinks.isEmpty() && syndFeed.getLink() != null) {
final String sLink = syndFeed.getLink();
if (alternateLinks.isEmpty() && sLink != null) {
final Link link = new Link();
link.setRel("alternate");
link.setHref(syndFeed.getLink());
link.setHref(sLink);
alternateLinks.add(link);
}
@ -339,7 +363,7 @@ public class ConverterForAtom03 implements Converter {
aFeed.setLanguage(syndFeed.getLanguage());
final List<SyndPerson> authors = syndFeed.getAuthors();
if (authors != null && !authors.isEmpty()) {
if (Lists.isNotEmpty(authors)) {
aFeed.setAuthors(createAtomPersons(authors));
}
@ -384,8 +408,8 @@ public class ConverterForAtom03 implements Converter {
protected List<Entry> createAtomEntries(final List<SyndEntry> syndEntries) {
final List<Entry> atomEntries = new ArrayList<Entry>();
for (int i = 0; i < syndEntries.size(); i++) {
atomEntries.add(createAtomEntry(syndEntries.get(i)));
for (final SyndEntry syndEntry : syndEntries) {
atomEntries.add(createAtomEntry(syndEntry));
}
return atomEntries;
}
@ -399,12 +423,14 @@ public class ConverterForAtom03 implements Converter {
final SyndContent sTitle = sEntry.getTitleEx();
if (sTitle != null) {
final Content title = new Content();
if (sTitle.getType() != null) {
title.setType(sTitle.getType());
final String type = sTitle.getType();
if (type != null) {
title.setType(type);
}
if (sTitle.getMode() != null) {
title.setMode(sTitle.getMode());
final String mode = sTitle.getMode();
if (mode != null) {
title.setMode(mode);
}
title.setValue(sTitle.getValue());
@ -414,12 +440,13 @@ public class ConverterForAtom03 implements Converter {
// separate SyndEntry's links collection into alternate and other links
final List<Link> alternateLinks = new ArrayList<Link>();
final List<Link> otherLinks = new ArrayList<Link>();
final List<SyndLink> slinks = sEntry.getLinks();
if (slinks != null) {
for (final SyndLink syndLink2 : slinks) {
final SyndLink syndLink = syndLink2;
final List<SyndLink> syndLinks = sEntry.getLinks();
if (syndLinks != null) {
for (final SyndLink syndLink : syndLinks) {
final Link link = createAtomLink(syndLink);
if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) {
final String rel = link.getRel();
if (Strings.isBlank(rel) || "alternate".equals(rel)) {
alternateLinks.add(link);
} else {
otherLinks.add(link);
@ -427,17 +454,17 @@ public class ConverterForAtom03 implements Converter {
}
}
// no alternate link? then use THE link if there is one
if (alternateLinks.isEmpty() && sEntry.getLink() != null) {
final String sLink = sEntry.getLink();
if (alternateLinks.isEmpty() && sLink != null) {
final Link link = new Link();
link.setRel("alternate");
link.setHref(sEntry.getLink());
link.setHref(sLink);
alternateLinks.add(link);
}
final List<SyndEnclosure> sEnclosures = sEntry.getEnclosures();
if (sEnclosures != null) {
for (final SyndEnclosure syndEnclosure2 : sEnclosures) {
final SyndEnclosure syndEnclosure = syndEnclosure2;
for (final SyndEnclosure syndEnclosure : sEnclosures) {
final Link link = createAtomEnclosure(syndEnclosure);
otherLinks.add(link);
}
@ -450,7 +477,7 @@ public class ConverterForAtom03 implements Converter {
aEntry.setOtherLinks(otherLinks);
}
SyndContent sContent = sEntry.getDescription();
final SyndContent sContent = sEntry.getDescription();
if (sContent != null) {
final Content content = new Content();
content.setType(sContent.getType());
@ -462,24 +489,23 @@ public class ConverterForAtom03 implements Converter {
final List<SyndContent> contents = sEntry.getContents();
if (!contents.isEmpty()) {
final List<Content> aContents = new ArrayList<Content>();
for (int i = 0; i < contents.size(); i++) {
sContent = contents.get(i);
for (final SyndContent syndContent : contents) {
final Content content = new Content();
content.setType(sContent.getType());
content.setValue(sContent.getValue());
content.setMode(sContent.getMode());
content.setType(syndContent.getType());
content.setValue(syndContent.getValue());
content.setMode(syndContent.getMode());
aContents.add(content);
}
aEntry.setContents(aContents);
}
final List<SyndPerson> sAuthors = sEntry.getAuthors();
if (sAuthors != null && !sAuthors.isEmpty()) {
final String author = sEntry.getAuthor();
if (Lists.isNotEmpty(sAuthors)) {
aEntry.setAuthors(createAtomPersons(sAuthors));
} else if (sEntry.getAuthor() != null) {
} else if (author != null) {
final Person person = new Person();
person.setName(sEntry.getAuthor());
person.setName(author);
final List<SyndPerson> authors = new ArrayList<SyndPerson>();
authors.add(person);
aEntry.setAuthors(authors);

View file

@ -20,6 +20,10 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.jdom2.Element;
import com.rometools.utils.Lists;
import com.rometools.utils.Strings;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.atom.Category;
import com.sun.syndication.feed.atom.Content;
@ -48,6 +52,7 @@ import com.sun.syndication.feed.synd.SyndPerson;
/**
*/
public class ConverterForAtom10 implements Converter {
private final String type;
public ConverterForAtom10() {
@ -65,24 +70,29 @@ public class ConverterForAtom10 implements Converter {
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {
final Feed aFeed = (Feed) feed;
syndFeed.setModules(ModuleUtils.cloneModules(aFeed.getModules()));
if (!feed.getForeignMarkup().isEmpty()) {
syndFeed.setForeignMarkup(feed.getForeignMarkup());
final List<Element> foreignMarkup = feed.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
syndFeed.setForeignMarkup(foreignMarkup);
}
syndFeed.setEncoding(aFeed.getEncoding());
syndFeed.setStyleSheet(aFeed.getStyleSheet());
if (aFeed.getLogo() != null) {
final String logo = aFeed.getLogo();
final String icon = aFeed.getIcon();
if (logo != null) {
final SyndImage image = new SyndImageImpl();
image.setUrl(aFeed.getLogo());
image.setUrl(logo);
syndFeed.setImage(image);
} else if (aFeed.getIcon() != null) {
} else if (icon != null) {
final SyndImage image = new SyndImageImpl();
image.setUrl(aFeed.getIcon());
image.setUrl(icon);
syndFeed.setImage(image);
}
@ -105,18 +115,24 @@ public class ConverterForAtom10 implements Converter {
}
// use first alternate links as THE link
if (aFeed.getAlternateLinks() != null && !aFeed.getAlternateLinks().isEmpty()) {
final Link theLink = aFeed.getAlternateLinks().get(0);
final List<Link> alternateLinks = aFeed.getAlternateLinks();
if (Lists.isNotEmpty(alternateLinks)) {
final Link theLink = alternateLinks.get(0);
syndFeed.setLink(theLink.getHrefResolved());
}
// lump alternate and other links together
final List<SyndLink> syndLinks = new ArrayList<SyndLink>();
if (aFeed.getAlternateLinks() != null && !aFeed.getAlternateLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(aFeed.getAlternateLinks()));
if (Lists.isNotEmpty(alternateLinks)) {
syndLinks.addAll(createSyndLinks(alternateLinks));
}
if (aFeed.getOtherLinks() != null && !aFeed.getOtherLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(aFeed.getOtherLinks()));
final List<Link> otherLinks = aFeed.getOtherLinks();
if (Lists.isNotEmpty(otherLinks)) {
syndLinks.addAll(createSyndLinks(otherLinks));
}
syndFeed.setLinks(syndLinks);
final List<Entry> aEntries = aFeed.getEntries();
@ -128,12 +144,12 @@ public class ConverterForAtom10 implements Converter {
// over DC equivalent info.
final List<SyndPerson> authors = aFeed.getAuthors();
if (authors != null && !authors.isEmpty()) {
if (Lists.isNotEmpty(authors)) {
syndFeed.setAuthors(ConverterForAtom03.createSyndPersons(authors));
}
final List<SyndPerson> contributors = aFeed.getContributors();
if (contributors != null && !contributors.isEmpty()) {
if (Lists.isNotEmpty(contributors)) {
syndFeed.setContributors(ConverterForAtom03.createSyndPersons(contributors));
}
@ -149,20 +165,19 @@ public class ConverterForAtom10 implements Converter {
}
protected List<SyndLink> createSyndLinks(final List<Link> aLinks) {
final ArrayList<SyndLink> sLinks = new ArrayList<SyndLink>();
for (final Link link2 : aLinks) {
final Link link = link2;
final SyndLink sLink = createSyndLink(link);
sLinks.add(sLink);
protected List<SyndLink> createSyndLinks(final List<Link> atomLinks) {
final ArrayList<SyndLink> syndLinks = new ArrayList<SyndLink>();
for (final Link atomLink : atomLinks) {
final SyndLink syndLink = createSyndLink(atomLink);
syndLinks.add(syndLink);
}
return sLinks;
return syndLinks;
}
protected List<SyndEntry> createSyndEntries(final Feed feed, final List<Entry> atomEntries, final boolean preserveWireItems) {
final List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
for (int i = 0; i < atomEntries.size(); i++) {
syndEntries.add(createSyndEntry(feed, atomEntries.get(i), preserveWireItems));
for (final Entry atomEntry : atomEntries) {
syndEntries.add(createSyndEntry(feed, atomEntry, preserveWireItems));
}
return syndEntries;
}
@ -174,8 +189,9 @@ public class ConverterForAtom10 implements Converter {
}
syndEntry.setModules(ModuleUtils.cloneModules(entry.getModules()));
if (!entry.getForeignMarkup().isEmpty()) {
syndEntry.setForeignMarkup(entry.getForeignMarkup());
final List<Element> foreignMarkup = entry.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
syndEntry.setForeignMarkup(foreignMarkup);
}
final Content eTitle = entry.getTitleEx();
@ -189,24 +205,23 @@ public class ConverterForAtom10 implements Converter {
}
final List<Content> contents = entry.getContents();
if (contents != null && !contents.isEmpty()) {
if (Lists.isNotEmpty(contents)) {
final List<SyndContent> sContents = new ArrayList<SyndContent>();
for (final Content content2 : contents) {
final Content content = content2;
for (final Content content : contents) {
sContents.add(createSyndContent(content));
}
syndEntry.setContents(sContents);
}
final List<SyndPerson> authors = entry.getAuthors();
if (authors != null && !authors.isEmpty()) {
if (Lists.isNotEmpty(authors)) {
syndEntry.setAuthors(ConverterForAtom03.createSyndPersons(authors));
final SyndPerson person0 = syndEntry.getAuthors().get(0);
syndEntry.setAuthor(person0.getName());
}
final List<SyndPerson> contributors = entry.getContributors();
if (contributors != null && !contributors.isEmpty()) {
if (Lists.isNotEmpty(contributors)) {
syndEntry.setContributors(ConverterForAtom03.createSyndPersons(contributors));
}
@ -224,10 +239,9 @@ public class ConverterForAtom10 implements Converter {
if (categories != null) {
final List<SyndCategory> syndCategories = new ArrayList<SyndCategory>();
for (final Category category : categories) {
final Category c = category;
final SyndCategory syndCategory = new SyndCategoryImpl();
syndCategory.setName(c.getTerm());
syndCategory.setTaxonomyUri(c.getSchemeResolved());
syndCategory.setName(category.getTerm());
syndCategory.setTaxonomyUri(category.getSchemeResolved());
// TODO: categories MAY have labels
// syndCategory.setLabel(c.getLabel());
syndCategories.add(syndCategory);
@ -236,19 +250,20 @@ public class ConverterForAtom10 implements Converter {
}
// use first alternate link as THE link
if (entry.getAlternateLinks() != null && !entry.getAlternateLinks().isEmpty()) {
final Link theLink = entry.getAlternateLinks().get(0);
final List<Link> alternateLinks = entry.getAlternateLinks();
if (Lists.isNotEmpty(alternateLinks)) {
final Link theLink = alternateLinks.get(0);
syndEntry.setLink(theLink.getHrefResolved());
}
// Create synd enclosures from enclosure links
final List<SyndEnclosure> syndEnclosures = new ArrayList<SyndEnclosure>();
if (entry.getOtherLinks() != null && !entry.getOtherLinks().isEmpty()) {
final List<Link> oLinks = entry.getOtherLinks();
final List<Link> otherLinks = entry.getOtherLinks();
if (Lists.isNotEmpty(otherLinks)) {
final List<Link> oLinks = otherLinks;
for (final Link link : oLinks) {
final Link thisLink = link;
if ("enclosure".equals(thisLink.getRel())) {
syndEnclosures.add(createSyndEnclosure(feed, entry, thisLink));
if ("enclosure".equals(link.getRel())) {
syndEnclosures.add(createSyndEnclosure(feed, entry, link));
}
}
}
@ -256,11 +271,11 @@ public class ConverterForAtom10 implements Converter {
// lump alternate and other links together
final List<SyndLink> syndLinks = new ArrayList<SyndLink>();
if (entry.getAlternateLinks() != null && !entry.getAlternateLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(entry.getAlternateLinks()));
if (Lists.isNotEmpty(alternateLinks)) {
syndLinks.addAll(createSyndLinks(alternateLinks));
}
if (entry.getOtherLinks() != null && !entry.getOtherLinks().isEmpty()) {
syndLinks.addAll(createSyndLinks(entry.getOtherLinks()));
if (Lists.isNotEmpty(otherLinks)) {
syndLinks.addAll(createSyndLinks(otherLinks));
}
syndEntry.setLinks(syndLinks);
@ -352,10 +367,10 @@ public class ConverterForAtom10 implements Converter {
final List<Link> otherLinks = new ArrayList<Link>();
final List<SyndLink> slinks = syndFeed.getLinks();
if (slinks != null) {
for (final SyndLink syndLink2 : slinks) {
final SyndLink syndLink = syndLink2;
for (final SyndLink syndLink : slinks) {
final Link link = createAtomLink(syndLink);
if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) {
final String rel = link.getRel();
if (Strings.isBlank(rel) || "alternate".equals(rel)) {
alternateLinks.add(link);
} else {
otherLinks.add(link);
@ -379,8 +394,7 @@ public class ConverterForAtom10 implements Converter {
final List<SyndCategory> sCats = syndFeed.getCategories();
final List<Category> aCats = new ArrayList<Category>();
if (sCats != null) {
for (final SyndCategory syndCategory : sCats) {
final SyndCategory sCat = syndCategory;
for (final SyndCategory sCat : sCats) {
final Category aCat = new Category();
aCat.setTerm(sCat.getName());
// TODO: aCat.setLabel(sCat.getLabel());
@ -393,12 +407,12 @@ public class ConverterForAtom10 implements Converter {
}
final List<SyndPerson> authors = syndFeed.getAuthors();
if (authors != null && !authors.isEmpty()) {
if (Lists.isNotEmpty(authors)) {
aFeed.setAuthors(ConverterForAtom03.createAtomPersons(authors));
}
final List<SyndPerson> contributors = syndFeed.getContributors();
if (contributors != null && !contributors.isEmpty()) {
if (Lists.isNotEmpty(contributors)) {
aFeed.setContributors(ConverterForAtom03.createAtomPersons(contributors));
}
@ -411,10 +425,13 @@ public class ConverterForAtom10 implements Converter {
aFeed.setEntries(createAtomEntries(sEntries));
}
if (!syndFeed.getForeignMarkup().isEmpty()) {
aFeed.setForeignMarkup(syndFeed.getForeignMarkup());
final List<Element> foreignMarkup = syndFeed.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
aFeed.setForeignMarkup(foreignMarkup);
}
return aFeed;
}
protected SyndContent createSyndContent(final Content content) {
@ -426,8 +443,8 @@ public class ConverterForAtom10 implements Converter {
protected List<Entry> createAtomEntries(final List<SyndEntry> syndEntries) {
final List<Entry> atomEntries = new ArrayList<Entry>();
for (int i = 0; i < syndEntries.size(); i++) {
atomEntries.add(createAtomEntry(syndEntries.get(i)));
for (final SyndEntry syndEntry : syndEntries) {
atomEntries.add(createAtomEntry(syndEntry));
}
return atomEntries;
}
@ -441,14 +458,16 @@ public class ConverterForAtom10 implements Converter {
protected List<Content> createAtomContents(final List<SyndContent> syndContents) {
final List<Content> atomContents = new ArrayList<Content>();
for (int i = 0; i < syndContents.size(); i++) {
atomContents.add(createAtomContent(syndContents.get(i)));
for (final SyndContent syndContent : syndContents) {
atomContents.add(createAtomContent(syndContent));
}
return atomContents;
}
protected Entry createAtomEntry(final SyndEntry sEntry) {
final Entry aEntry = new Entry();
aEntry.setModules(ModuleUtils.cloneModules(sEntry.getModules()));
aEntry.setId(sEntry.getUri());
@ -472,26 +491,31 @@ public class ConverterForAtom10 implements Converter {
// separate SyndEntry's links collection into alternate and other links
final List<Link> alternateLinks = new ArrayList<Link>();
final List<Link> otherLinks = new ArrayList<Link>();
boolean linkRelEnclosureExists = false;
final List<SyndLink> slinks = sEntry.getLinks();
final List<SyndEnclosure> enclosures = sEntry.getEnclosures();
boolean linkRelEnclosureExists = false;
if (slinks != null) {
for (final SyndLink syndLink2 : slinks) {
final SyndLink syndLink = syndLink2;
for (final SyndLink syndLink : slinks) {
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())) {
final String sRel = syndLink.getRel();
if (sRel != null && "enclosure".equals(sRel)) {
linkRelEnclosureExists = true;
}
if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(syndLink.getRel())) {
final String lRel = link.getRel();
if (Strings.isBlank(lRel) || "alternate".equals(sRel)) {
alternateLinks.add(link);
} else {
otherLinks.add(link);
}
}
}
// no alternate link? then use THE link if there is one
if (alternateLinks.isEmpty() && sEntry.getLink() != null) {
final Link link = new Link();
@ -499,6 +523,7 @@ public class ConverterForAtom10 implements Converter {
link.setHref(sEntry.getLink());
alternateLinks.add(link);
}
// add SyndEnclosures as links with rel="enclosure" ONLY if
// there are no SyndEntry.getLinks() with rel="enclosure"
if (enclosures != null && linkRelEnclosureExists == false) {
@ -508,9 +533,11 @@ public class ConverterForAtom10 implements Converter {
otherLinks.add(link);
}
}
if (!alternateLinks.isEmpty()) {
aEntry.setAlternateLinks(alternateLinks);
}
if (!otherLinks.isEmpty()) {
aEntry.setOtherLinks(otherLinks);
}
@ -518,8 +545,7 @@ public class ConverterForAtom10 implements Converter {
final List<SyndCategory> sCats = sEntry.getCategories();
final List<Category> aCats = new ArrayList<Category>();
if (sCats != null) {
for (final SyndCategory syndCategory : sCats) {
final SyndCategory sCat = syndCategory;
for (final SyndCategory sCat : sCats) {
final Category aCat = new Category();
aCat.setTerm(sCat.getName());
// TODO: aCat.setLabel(sCat.getLabel());
@ -527,6 +553,7 @@ public class ConverterForAtom10 implements Converter {
aCats.add(aCat);
}
}
if (!aCats.isEmpty()) {
aEntry.setCategories(aCats);
}
@ -535,18 +562,19 @@ public class ConverterForAtom10 implements Converter {
aEntry.setContents(createAtomContents(syndContents));
List<SyndPerson> authors = sEntry.getAuthors();
if (authors != null && !authors.isEmpty()) {
final String author = sEntry.getAuthor();
if (Lists.isNotEmpty(authors)) {
aEntry.setAuthors(ConverterForAtom03.createAtomPersons(authors));
} else if (sEntry.getAuthor() != null) {
} else if (author != null) {
final Person person = new Person();
person.setName(sEntry.getAuthor());
person.setName(author);
authors = new ArrayList<SyndPerson>();
authors.add(person);
aEntry.setAuthors(authors);
}
final List<SyndPerson> contributors = sEntry.getContributors();
if (contributors != null && !contributors.isEmpty()) {
if (Lists.isNotEmpty(contributors)) {
aEntry.setContributors(ConverterForAtom03.createAtomPersons(contributors));
}
@ -561,8 +589,9 @@ public class ConverterForAtom10 implements Converter {
aEntry.setUpdated(sEntry.getPublishedDate());
}
if (!sEntry.getForeignMarkup().isEmpty()) {
aEntry.setForeignMarkup(sEntry.getForeignMarkup());
final List<Element> foreignMarkup = sEntry.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
aEntry.setForeignMarkup(foreignMarkup);
}
final SyndFeed sSource = sEntry.getSource();

View file

@ -19,6 +19,8 @@ package com.sun.syndication.feed.synd.impl;
import java.util.ArrayList;
import java.util.List;
import org.jdom2.Element;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.module.impl.ModuleUtils;
import com.sun.syndication.feed.rss.Channel;
@ -32,6 +34,7 @@ import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.feed.synd.SyndImage;
import com.sun.syndication.feed.synd.SyndImageImpl;
import com.sun.syndication.feed.synd.SyndLink;
/**
*/
@ -53,13 +56,20 @@ public class ConverterForRSS090 implements Converter {
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {
syndFeed.setModules(ModuleUtils.cloneModules(feed.getModules()));
if (!feed.getForeignMarkup().isEmpty()) {
syndFeed.setForeignMarkup(feed.getForeignMarkup());
final List<Element> foreignMarkup = feed.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
syndFeed.setForeignMarkup(foreignMarkup);
}
syndFeed.setStyleSheet(feed.getStyleSheet());
syndFeed.setEncoding(feed.getEncoding());
final Channel channel = (Channel) feed;
syndFeed.setTitle(channel.getTitle());
syndFeed.setLink(channel.getLink());
syndFeed.setDescription(channel.getDescription());
@ -85,22 +95,25 @@ public class ConverterForRSS090 implements Converter {
protected List<SyndEntry> createSyndEntries(final List<Item> rssItems, final boolean preserveWireItems) {
final List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
for (int i = 0; i < rssItems.size(); i++) {
syndEntries.add(createSyndEntry(rssItems.get(i), preserveWireItems));
for (final Item item : rssItems) {
syndEntries.add(createSyndEntry(item, preserveWireItems));
}
return syndEntries;
}
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 (!item.getForeignMarkup().isEmpty()) {
syndEntry.setForeignMarkup(item.getForeignMarkup());
final List<Element> foreignMarkup = item.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
syndEntry.setForeignMarkup(foreignMarkup);
}
syndEntry.setUri(item.getUri());
@ -134,12 +147,16 @@ public class ConverterForRSS090 implements Converter {
channel.setEncoding(syndFeed.getEncoding());
channel.setTitle(syndFeed.getTitle());
if (syndFeed.getLink() != null) {
channel.setLink(syndFeed.getLink());
} else if (!syndFeed.getLinks().isEmpty()) {
channel.setLink(syndFeed.getLinks().get(0).getHref());
final String link = syndFeed.getLink();
final List<SyndLink> links = syndFeed.getLinks();
if (link != null) {
channel.setLink(link);
} else if (!links.isEmpty()) {
channel.setLink(links.get(0).getHref());
}
channel.setDescription(syndFeed.getDescription());
final SyndImage sImage = syndFeed.getImage();
if (sImage != null) {
channel.setImage(createRSSImage(sImage));
@ -150,9 +167,11 @@ public class ConverterForRSS090 implements Converter {
channel.setItems(createRSSItems(sEntries));
}
if (!syndFeed.getForeignMarkup().isEmpty()) {
channel.setForeignMarkup(syndFeed.getForeignMarkup());
final List<Element> foreignMarkup = syndFeed.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
channel.setForeignMarkup(foreignMarkup);
}
return channel;
}
@ -166,22 +185,29 @@ public class ConverterForRSS090 implements Converter {
protected List<Item> createRSSItems(final List<SyndEntry> sEntries) {
final List<Item> list = new ArrayList<Item>();
for (int i = 0; i < sEntries.size(); i++) {
list.add(createRSSItem(sEntries.get(i)));
for (final SyndEntry syndEntry : sEntries) {
list.add(createRSSItem(syndEntry));
}
return list;
}
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 (!sEntry.getForeignMarkup().isEmpty()) {
item.setForeignMarkup(sEntry.getForeignMarkup());
final List<Element> foreignMarkup = sEntry.getForeignMarkup();
if (!foreignMarkup.isEmpty()) {
item.setForeignMarkup(foreignMarkup);
}
item.setSource(createSource(sEntry.getSource()));
final String uri = sEntry.getUri();
if (uri != null) {
item.setUri(uri);

View file

@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.module.DCModule;
import com.sun.syndication.feed.rss.Channel;
@ -36,9 +37,8 @@ import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndImage;
import com.sun.syndication.feed.synd.SyndPerson;
/**
*/
public class ConverterForRSS091Userland extends ConverterForRSS090 {
public ConverterForRSS091Userland() {
this("rss_0.91U");
}
@ -49,13 +49,21 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
@Override
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.setDocs(channel.getDocs());
syndFeed.setManagingEditor(channel.getManagingEditor());
syndFeed.setWebMaster(channel.getWebMaster());
syndFeed.setGenerator(channel.getGenerator());
final Date pubDate = channel.getPubDate();
@ -69,12 +77,12 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
final String author = channel.getManagingEditor();
if (author != null) {
final List<String> creators = ((DCModule) syndFeed.getModule(DCModule.URI)).getCreators();
if (!creators.contains(author)) {
final Set<String> s = new LinkedHashSet<String>(); // using a set to
// remove
// duplicates
// using a set to remove duplicates
final Set<String> s = new LinkedHashSet<String>();
s.addAll(creators); // DC creators
s.add(author); // feed native author
creators.clear();
@ -87,7 +95,6 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
final Description desc = new Description();
desc.setValue(sContent.getValue());
desc.setType(sContent.getType());
return desc;
}
@ -95,7 +102,6 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
protected Image createRSSImage(final SyndImage sImage) {
final Image image = super.createRSSImage(sImage);
image.setDescription(sImage.getDescription());
return image;
}
@ -104,8 +110,11 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
// synd.description -> rss.description
@Override
protected Item createRSSItem(final SyndEntry sEntry) {
final Item item = super.createRSSItem(sEntry);
item.setComments(sEntry.getComments());
final SyndContent sContent = sEntry.getDescription();
if (sContent != null) {
@ -114,7 +123,7 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
final List<SyndContent> contents = sEntry.getContents();
if (contents != null && !contents.isEmpty()) {
if (Lists.isNotEmpty(contents)) {
final SyndContent syndContent = contents.get(0);
final Content cont = new Content();
cont.setValue(syndContent.getValue());
@ -136,8 +145,9 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
channel.setWebMaster(syndFeed.getWebMaster());
channel.setGenerator(syndFeed.getGenerator());
if (syndFeed.getAuthors() != null && !syndFeed.getAuthors().isEmpty()) {
final SyndPerson author = syndFeed.getAuthors().get(0);
final List<SyndPerson> authors = syndFeed.getAuthors();
if (Lists.isNotEmpty(authors)) {
final SyndPerson author = authors.get(0);
channel.setManagingEditor(author.getName());
}
@ -149,8 +159,11 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
// rss.description -> synd.description
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {
final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);
final Description desc = item.getDescription();
syndEntry.setComments(item.getComments());
if (desc != null) {
@ -179,7 +192,7 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 {
protected SyndImage createSyndImage(final Image rssImage) {
final SyndImage syndImage = super.createSyndImage(rssImage);
syndImage.setDescription(rssImage.getDescription());
return syndImage;
}
}

View file

@ -44,40 +44,38 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland {
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {
final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);
final List<Category> cats = item.getCategories();
if (!cats.isEmpty()) {
final Set<SyndCategory> s = new LinkedHashSet<SyndCategory>(); // 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)
// using a set to remove duplicates and use a LinkedHashSet to try to retain the
// document order
final Set<SyndCategory> s = new LinkedHashSet<SyndCategory>();
// feed native categories (as syndcat)
s.addAll(createSyndCategories(cats));
// DC subjects (as syndcat)
s.addAll(syndEntry.getCategories());
syndEntry.setCategories(new ArrayList<SyndCategory>(s)); // c
}
final List<Enclosure> enclosures = item.getEnclosures();
if (!enclosures.isEmpty()) {
syndEntry.setEnclosures(createSyndEnclosures(enclosures));
}
return syndEntry;
}
protected List<SyndCategory> createSyndCategories(final List<Category> rssCats) {
final List<SyndCategory> syndCats = new ArrayList<SyndCategory>();
for (int i = 0; i < rssCats.size(); i++) {
final Category rssCat = rssCats.get(i);
for (final Category rssCat : rssCats) {
final SyndCategory sCat = new SyndCategoryImpl();
sCat.setTaxonomyUri(rssCat.getDomain());
sCat.setName(rssCat.getValue());
@ -88,8 +86,7 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland {
protected List<SyndEnclosure> createSyndEnclosures(final List<Enclosure> enclosures) {
final List<SyndEnclosure> sEnclosures = new ArrayList<SyndEnclosure>();
for (int i = 0; i < enclosures.size(); i++) {
final Enclosure enc = enclosures.get(i);
for (final Enclosure enc : enclosures) {
final SyndEnclosure sEnc = new SyndEnclosureImpl();
sEnc.setUrl(enc.getUrl());
sEnc.setType(enc.getType());
@ -101,23 +98,26 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland {
@Override
protected Item createRSSItem(final SyndEntry sEntry) {
final Item item = super.createRSSItem(sEntry);
final List<SyndCategory> sCats = sEntry.getCategories(); // c
if (!sCats.isEmpty()) {
item.setCategories(createRSSCategories(sCats));
}
final List<SyndEnclosure> sEnclosures = sEntry.getEnclosures();
if (!sEnclosures.isEmpty()) {
item.setEnclosures(createEnclosures(sEnclosures));
}
return item;
}
protected List<Category> createRSSCategories(final List<SyndCategory> sCats) {
final List<Category> cats = new ArrayList<Category>();
for (int i = 0; i < sCats.size(); i++) {
final SyndCategory sCat = sCats.get(i);
for (final SyndCategory sCat : sCats) {
final Category cat = new Category();
cat.setDomain(sCat.getTaxonomyUri());
cat.setValue(sCat.getName());
@ -128,8 +128,7 @@ public class ConverterForRSS092 extends ConverterForRSS091Userland {
protected List<Enclosure> createEnclosures(final List<SyndEnclosure> sEnclosures) {
final List<Enclosure> enclosures = new ArrayList<Enclosure>();
for (int i = 0; i < sEnclosures.size(); i++) {
final SyndEnclosure sEnc = sEnclosures.get(i);
for (final SyndEnclosure sEnc : sEnclosures) {
final Enclosure enc = new Enclosure();
enc.setUrl(sEnc.getUrl());
enc.setType(sEnc.getType());

View file

@ -21,8 +21,6 @@ import java.util.Date;
import com.sun.syndication.feed.rss.Item;
import com.sun.syndication.feed.synd.SyndEntry;
/**
*/
public class ConverterForRSS093 extends ConverterForRSS092 {
public ConverterForRSS093() {
@ -35,11 +33,15 @@ public class ConverterForRSS093 extends ConverterForRSS092 {
@Override
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.getPublishedDate() == null) {
final Date publishedDate = syndEntry.getPublishedDate();
if (pubDate != null && publishedDate == null) {
syndEntry.setPublishedDate(pubDate); // c
}
return syndEntry;
}

View file

@ -21,6 +21,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.module.DCModule;
import com.sun.syndication.feed.rss.Category;
@ -34,8 +35,6 @@ import com.sun.syndication.feed.synd.SyndLink;
import com.sun.syndication.feed.synd.SyndLinkImpl;
import com.sun.syndication.feed.synd.SyndPerson;
/**
*/
public class ConverterForRSS094 extends ConverterForRSS093 {
public ConverterForRSS094() {
@ -48,24 +47,32 @@ public class ConverterForRSS094 extends ConverterForRSS093 {
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {
final Channel channel = (Channel) feed;
super.copyInto(channel, syndFeed);
final List<Category> cats = channel.getCategories(); // c
if (!cats.isEmpty()) {
final Set<SyndCategory> s = new LinkedHashSet<SyndCategory>(); // using a
// set to
// remove
// duplicates
s.addAll(createSyndCategories(cats)); // feed native categories
// (as
// syndcat)
s.addAll(syndFeed.getCategories()); // DC subjects (as syndcat)
// using a set to remove duplicates
final Set<SyndCategory> s = new LinkedHashSet<SyndCategory>();
// feed native categories (as syndcat)
s.addAll(createSyndCategories(cats));
// DC subjects (as syndcat)
s.addAll(syndFeed.getCategories());
syndFeed.setCategories(new ArrayList<SyndCategory>(s));
}
}
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {
final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);
// adding native feed author to DC creators list
@ -73,32 +80,42 @@ public class ConverterForRSS094 extends ConverterForRSS093 {
if (author != null) {
final List<String> creators = ((DCModule) syndEntry.getModule(DCModule.URI)).getCreators();
if (!creators.contains(author)) {
final Set<String> s = new LinkedHashSet<String>(); // using a set to
// remove
// duplicates
s.addAll(creators); // DC creators
s.add(author); // feed native author
// using a set to remove duplicates
final Set<String> s = new LinkedHashSet<String>();
// DC creators
s.addAll(creators);
// feed native author
s.add(author);
creators.clear();
creators.addAll(s);
}
}
final Guid guid = item.getGuid();
final String itemLink = item.getLink();
if (guid != null) {
syndEntry.setUri(guid.getValue());
if (item.getLink() == null && guid.isPermaLink()) {
syndEntry.setLink(guid.getValue());
final String guidValue = guid.getValue();
syndEntry.setUri(guidValue);
if (itemLink == null && guid.isPermaLink()) {
syndEntry.setLink(guidValue);
}
} else {
syndEntry.setUri(item.getLink());
syndEntry.setUri(itemLink);
}
if (item.getComments() != null) {
final SyndLinkImpl comments = new SyndLinkImpl();
comments.setRel("comments");
comments.setHref(item.getComments());
comments.setType("text/html");
}
return syndEntry;
}
@Override
@ -113,32 +130,36 @@ public class ConverterForRSS094 extends ConverterForRSS093 {
@Override
protected Item createRSSItem(final SyndEntry sEntry) {
final Item item = super.createRSSItem(sEntry);
if (sEntry.getAuthors() != null && !sEntry.getAuthors().isEmpty()) {
final SyndPerson author = sEntry.getAuthors().get(0);
final List<SyndPerson> authors = sEntry.getAuthors();
if (Lists.isNotEmpty(authors)) {
final SyndPerson author = authors.get(0);
item.setAuthor(author.getEmail());
}
Guid guid = null;
final String uri = sEntry.getUri();
final String link = sEntry.getLink();
if (uri != null) {
guid = new Guid();
guid.setPermaLink(false);
guid.setValue(uri);
} else {
final String link = sEntry.getLink();
if (link != null) {
guid = new Guid();
guid.setPermaLink(true);
guid.setValue(link);
}
} else if (link != null) {
guid = new Guid();
guid.setPermaLink(true);
guid.setValue(link);
}
item.setGuid(guid);
final SyndLink comments = sEntry.findRelatedLink("comments");
if (comments != null && (comments.getType() == null || comments.getType().endsWith("html"))) {
item.setComments(comments.getHref());
}
return item;
}
}

View file

@ -19,6 +19,7 @@ package com.sun.syndication.feed.synd.impl;
import java.util.ArrayList;
import java.util.List;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.rss.Channel;
import com.sun.syndication.feed.rss.Content;
@ -29,8 +30,6 @@ import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
/**
*/
public class ConverterForRSS10 extends ConverterForRSS090 {
public ConverterForRSS10() {
@ -43,13 +42,18 @@ public class ConverterForRSS10 extends ConverterForRSS090 {
@Override
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());
final String uri = channel.getUri();
if (uri != null) {
syndFeed.setUri(uri);
} else {
// if URI is not set use the value for link
syndFeed.setUri(channel.getLink());
final String link = channel.getLink();
syndFeed.setUri(link);
}
}
@ -59,6 +63,7 @@ public class ConverterForRSS10 extends ConverterForRSS090 {
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {
final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);
final Description desc = item.getDescription();
@ -68,27 +73,36 @@ public class ConverterForRSS10 extends ConverterForRSS090 {
descContent.setValue(desc.getValue());
syndEntry.setDescription(descContent);
}
final Content cont = item.getContent();
if (cont != null) {
final SyndContent contContent = new SyndContentImpl();
contContent.setType(cont.getType());
contContent.setValue(cont.getValue());
final List<SyndContent> contents = new ArrayList<SyndContent>();
contents.add(contContent);
syndEntry.setContents(contents);
}
return syndEntry;
}
@Override
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());
final String uri = syndFeed.getUri();
if (uri != null) {
channel.setUri(uri);
} else {
// if URI is not set use the value for link
channel.setUri(syndFeed.getLink());
final String link = syndFeed.getLink();
channel.setUri(link);
}
return channel;
@ -100,14 +114,16 @@ public class ConverterForRSS10 extends ConverterForRSS090 {
@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));
}
final List<SyndContent> contents = sEntry.getContents();
if (contents != null && !contents.isEmpty()) {
if (Lists.isNotEmpty(contents)) {
item.setContent(createItemContent(contents.get(0)));
}

View file

@ -16,8 +16,6 @@
*/
package com.sun.syndication.feed.synd.impl;
/**
*/
public class ConverterForRSS20 extends ConverterForRSS094 {
public ConverterForRSS20() {

View file

@ -19,10 +19,9 @@ package com.sun.syndication.io;
/**
* Exception thrown by WireFeedInput, WireFeedOutput, WireFeedParser and WireFeedGenerator instances
* if they can not parse or generate a feed.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class FeedException extends Exception {
@ -30,10 +29,9 @@ public class FeedException extends Exception {
/**
* Creates a FeedException with a message.
* <p>
*
*
* @param msg exception message.
*
*
*/
public FeedException(final String msg) {
super(msg);
@ -41,11 +39,10 @@ public class FeedException extends Exception {
/**
* Creates a FeedException with a message and a root cause exception.
* <p>
*
*
* @param msg exception message.
* @param rootCause root cause exception.
*
*
*/
public FeedException(final String msg, final Throwable rootCause) {
super(msg, rootCause);

View file

@ -20,10 +20,9 @@ import org.jdom2.input.JDOMParseException;
/**
* Exception thrown by WireFeedInput instance if it can not parse a feed.
* <p>
*
*
* @author Elaine Chien
*
*
*/
public class ParsingFeedException extends FeedException {
@ -31,10 +30,9 @@ public class ParsingFeedException extends FeedException {
/**
* Creates a FeedException with a message.
* <p>
*
*
* @param msg exception message.
*
*
*/
public ParsingFeedException(final String msg) {
super(msg);
@ -42,11 +40,10 @@ public class ParsingFeedException extends FeedException {
/**
* Creates a FeedException with a message and a root cause exception.
* <p>
*
*
* @param msg exception message.
* @param rootCause root cause exception.
*
*
*/
public ParsingFeedException(final String msg, final Throwable rootCause) {
super(msg, rootCause);
@ -57,7 +54,7 @@ public class ParsingFeedException extends FeedException {
* <p>
* The first line in the document is line 1.
* </p>
*
*
* @return an integer representing the line number, or -1 if the information is not available.
*/
public int getLineNumber() {
@ -73,7 +70,7 @@ public class ParsingFeedException extends FeedException {
* <p>
* The first column in a line is position 1.
* </p>
*
*
* @return an integer representing the column number, or -1 if the information is not available.
*/
public int getColumnNumber() {

View file

@ -30,21 +30,13 @@ import com.sun.syndication.feed.synd.SyndFeed;
* <p>
* It delegates to a WireFeedOutput to generate all feed types.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class SyndFeedOutput {
private final WireFeedOutput feedOutput;
/**
* Creates a SyndFeedOutput instance.
* <p>
*
*/
public SyndFeedOutput() {
feedOutput = new WireFeedOutput();
}
private final WireFeedOutput feedOutput = new WireFeedOutput();
/**
* Creates a String with the XML representation for the given SyndFeedImpl.
@ -53,12 +45,12 @@ public class SyndFeedOutput {
* 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.
* <p>
*
*
* @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.
*
*
*/
public String outputString(final SyndFeed feed) throws FeedException {
return feedOutput.outputString(feed.createWireFeed());
@ -71,13 +63,13 @@ public class SyndFeedOutput {
* 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.
* <p>
*
*
* @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.
*
*
*/
public String outputString(final SyndFeed feed, final boolean prettyPrint) throws FeedException {
return feedOutput.outputString(feed.createWireFeed(), prettyPrint);
@ -91,13 +83,13 @@ public class SyndFeedOutput {
* responsibility of the developer to ensure the feed encoding is set to the platform charset
* encoding.
* <p>
*
*
* @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.
*
*
*/
public void output(final SyndFeed feed, final File file) throws IOException, FeedException {
feedOutput.output(feed.createWireFeed(), file);
@ -111,14 +103,14 @@ public class SyndFeedOutput {
* responsibility of the developer to ensure the feed encoding is set to the platform charset
* encoding.
* <p>
*
*
* @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.
* @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.
*
*
*/
public void output(final SyndFeed feed, final File file, final boolean prettyPrint) throws IOException, FeedException {
feedOutput.output(feed.createWireFeed(), file, prettyPrint);
@ -131,13 +123,13 @@ public class SyndFeedOutput {
* 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.
* <p>
*
*
* @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(final SyndFeed feed, final Writer writer) throws IOException, FeedException {
feedOutput.output(feed.createWireFeed(), writer);
@ -150,14 +142,14 @@ public class SyndFeedOutput {
* 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.
* <p>
*
*
* @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.
*
*
*/
public void output(final SyndFeed feed, final Writer writer, final boolean prettyPrint) throws IOException, FeedException {
feedOutput.output(feed.createWireFeed(), writer, prettyPrint);
@ -168,12 +160,12 @@ public class SyndFeedOutput {
* <p>
* This method does not use the feed encoding property.
* <p>
*
*
* @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.
*
*
*/
public org.w3c.dom.Document outputW3CDom(final SyndFeed feed) throws FeedException {
return feedOutput.outputW3CDom(feed.createWireFeed());
@ -184,12 +176,12 @@ public class SyndFeedOutput {
* <p>
* This method does not use the feed encoding property.
* <p>
*
*
* @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.
*
*
*/
public Document outputJDom(final SyndFeed feed) throws FeedException {
return feedOutput.outputJDom(feed.createWireFeed());

View file

@ -52,14 +52,22 @@ import com.sun.syndication.io.impl.XmlFixerReader;
* <p>
* The WireFeedInput useds liberal parsers.
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class WireFeedInput {
private static final InputSource EMPTY_INPUTSOURCE = new InputSource(new ByteArrayInputStream(new byte[0]));
private static final EntityResolver RESOLVER = new EmptyEntityResolver();
private static Map<ClassLoader, FeedParsers> clMap = new WeakHashMap<ClassLoader, FeedParsers>();
private final boolean validate;
private final Locale locale;
private boolean xmlHealerOn;
private static FeedParsers getFeedParsers() {
synchronized (WireFeedInput.class) {
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
@ -72,9 +80,6 @@ public class WireFeedInput {
}
}
private static final InputSource EMPTY_INPUTSOURCE = new InputSource(new ByteArrayInputStream(new byte[0]));
private static final EntityResolver RESOLVER = new EmptyEntityResolver();
private static class EmptyEntityResolver implements EntityResolver {
@Override
public InputSource resolveEntity(final String publicId, final String systemId) {
@ -85,19 +90,14 @@ public class WireFeedInput {
}
}
private final boolean validate;
private boolean xmlHealerOn;
private final Locale locale;
/**
* Returns the list of supported input feed types.
* <p>
*
*
* @see WireFeed for details on the format of these strings.
* <p>
* @return a list of String elements with the supported input feed types.
*
*
*/
public static List<String> getSupportedFeedTypes() {
return getFeedParsers().getSupportedFeedTypes();
@ -106,7 +106,7 @@ public class WireFeedInput {
/**
* Creates a WireFeedInput instance with input validation turned off.
* <p>
*
*
*/
public WireFeedInput() {
this(false, Locale.US);
@ -115,10 +115,10 @@ public class WireFeedInput {
/**
* Creates a WireFeedInput instance.
* <p>
*
*
* @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation
* does not happen)
*
*
*/
public WireFeedInput(final boolean validate, final Locale locale) {
this.validate = false; // TODO FIX THIS THINGY
@ -137,9 +137,9 @@ public class WireFeedInput {
* <p>
* By default is TRUE.
* <p>
*
*
* @param heals TRUE enables stream healing, FALSE disables it.
*
*
*/
public void setXmlHealerOn(final boolean heals) {
xmlHealerOn = heals;
@ -156,9 +156,9 @@ public class WireFeedInput {
* <p>
* By default is TRUE.
* <p>
*
*
* @return TRUE if healing is enabled, FALSE if not.
*
*
*/
public boolean getXmlHealerOn() {
return xmlHealerOn;
@ -169,7 +169,7 @@ public class WireFeedInput {
* <p>
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
* <p>
*
*
* @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.
@ -177,7 +177,7 @@ public class WireFeedInput {
* @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(final File file) throws FileNotFoundException, IOException, IllegalArgumentException, FeedException {
WireFeed feed;
@ -195,13 +195,13 @@ public class WireFeedInput {
* <p>
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
* <p>
*
*
* @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 FeedException if the feed could not be parsed
*
*
*/
public WireFeed build(Reader reader) throws IllegalArgumentException, FeedException {
final SAXBuilder saxBuilder = createSAXBuilder();
@ -225,13 +225,13 @@ public class WireFeedInput {
* <p>
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
* <p>
*
*
* @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 FeedException if the feed could not be parsed
*
*
*/
public WireFeed build(final InputSource is) throws IllegalArgumentException, FeedException {
final SAXBuilder saxBuilder = createSAXBuilder();
@ -252,13 +252,13 @@ public class WireFeedInput {
* <p>
* NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
* <p>
*
*
* @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 FeedException if the feed could not be parsed
*
*
*/
public WireFeed build(final org.w3c.dom.Document document) throws IllegalArgumentException, FeedException {
final DOMBuilder domBuilder = new DOMBuilder();
@ -277,13 +277,13 @@ public class WireFeedInput {
* <p>
* NOTE: All other build methods delegate to this method.
* <p>
*
*
* @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 FeedException if the feed could not be parsed
*
*
*/
public WireFeed build(final Document document) throws IllegalArgumentException, FeedException {
final WireFeedParser parser = getFeedParsers().getParserFor(document);
@ -295,7 +295,7 @@ public class WireFeedInput {
/**
* Creates and sets up a org.jdom2.input.SAXBuilder for parsing.
*
*
* @return a new org.jdom2.input.SAXBuilder object
*/
protected SAXBuilder createSAXBuilder() {
@ -357,4 +357,5 @@ public class WireFeedInput {
saxBuilder.setExpandEntities(false);
return saxBuilder;
}
}

View file

@ -17,6 +17,7 @@
package com.sun.syndication.io.impl;
import java.io.StringReader;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@ -26,6 +27,7 @@ import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.atom.Content;
import com.sun.syndication.feed.atom.Entry;
@ -44,6 +46,7 @@ import com.sun.syndication.io.FeedException;
*/
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);
@ -102,9 +105,9 @@ public class Atom03Generator extends BaseWireFeedGenerator {
}
protected void addEntries(final Feed feed, final Element parent) throws FeedException {
final List<Entry> items = feed.getEntries();
for (int i = 0; i < items.size(); i++) {
addEntry(items.get(i), parent);
final List<Entry> entries = feed.getEntries();
for (final Entry entry : entries) {
addEntry(entry, parent);
}
checkEntriesConstraints(parent);
}
@ -118,129 +121,151 @@ public class Atom03Generator extends BaseWireFeedGenerator {
}
protected void populateFeedHeader(final Feed feed, final Element eFeed) throws FeedException {
if (feed.getTitleEx() != null) {
final Content titleEx = feed.getTitleEx();
if (titleEx != null) {
final Element titleElement = new Element("title", getFeedNamespace());
fillContentElement(titleElement, feed.getTitleEx());
fillContentElement(titleElement, titleEx);
eFeed.addContent(titleElement);
}
List<Link> links = feed.getAlternateLinks();
for (int i = 0; i < links.size(); i++) {
eFeed.addContent(generateLinkElement(links.get(i)));
for (final Link link : links) {
eFeed.addContent(generateLinkElement(link));
}
links = feed.getOtherLinks();
for (int i = 0; i < links.size(); i++) {
eFeed.addContent(generateLinkElement(links.get(i)));
for (final Link link : links) {
eFeed.addContent(generateLinkElement(link));
}
if (feed.getAuthors() != null && !feed.getAuthors().isEmpty()) {
final List<SyndPerson> authors = feed.getAuthors();
if (Lists.isNotEmpty(authors)) {
final Element authorElement = new Element("author", getFeedNamespace());
fillPersonElement(authorElement, feed.getAuthors().get(0));
fillPersonElement(authorElement, authors.get(0));
eFeed.addContent(authorElement);
}
final List<SyndPerson> contributors = feed.getContributors();
for (int i = 0; i < contributors.size(); i++) {
for (final SyndPerson contributor : contributors) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
fillPersonElement(contributorElement, contributors.get(i));
fillPersonElement(contributorElement, contributor);
eFeed.addContent(contributorElement);
}
if (feed.getTagline() != null) {
final Content tagline = feed.getTagline();
if (tagline != null) {
final Element taglineElement = new Element("tagline", getFeedNamespace());
fillContentElement(taglineElement, feed.getTagline());
fillContentElement(taglineElement, tagline);
eFeed.addContent(taglineElement);
}
if (feed.getId() != null) {
eFeed.addContent(generateSimpleElement("id", feed.getId()));
final String id = feed.getId();
if (id != null) {
eFeed.addContent(generateSimpleElement("id", id));
}
if (feed.getGenerator() != null) {
eFeed.addContent(generateGeneratorElement(feed.getGenerator()));
final Generator generator = feed.getGenerator();
if (generator != null) {
eFeed.addContent(generateGeneratorElement(generator));
}
if (feed.getCopyright() != null) {
eFeed.addContent(generateSimpleElement("copyright", feed.getCopyright()));
final String copyright = feed.getCopyright();
if (copyright != null) {
eFeed.addContent(generateSimpleElement("copyright", copyright));
}
if (feed.getInfo() != null) {
final Content info = feed.getInfo();
if (info != null) {
final Element infoElement = new Element("info", getFeedNamespace());
fillContentElement(infoElement, feed.getInfo());
fillContentElement(infoElement, info);
eFeed.addContent(infoElement);
}
if (feed.getModified() != null) {
final Date modified = feed.getModified();
if (modified != null) {
final Element modifiedElement = new Element("modified", getFeedNamespace());
modifiedElement.addContent(DateParser.formatW3CDateTime(feed.getModified(), Locale.US));
modifiedElement.addContent(DateParser.formatW3CDateTime(modified, Locale.US));
eFeed.addContent(modifiedElement);
}
}
protected void populateEntry(final Entry entry, final Element eEntry) throws FeedException {
if (entry.getTitleEx() != null) {
final Content titleEx = entry.getTitleEx();
if (titleEx != null) {
final Element titleElement = new Element("title", getFeedNamespace());
fillContentElement(titleElement, entry.getTitleEx());
fillContentElement(titleElement, titleEx);
eEntry.addContent(titleElement);
}
List<Link> links = entry.getAlternateLinks();
for (int i = 0; i < links.size(); i++) {
eEntry.addContent(generateLinkElement(links.get(i)));
final List<Link> alternateLinks = entry.getAlternateLinks();
for (final Link link : alternateLinks) {
eEntry.addContent(generateLinkElement(link));
}
links = entry.getOtherLinks();
for (int i = 0; i < links.size(); i++) {
eEntry.addContent(generateLinkElement(links.get(i)));
final List<Link> otherLinks = entry.getOtherLinks();
for (final Link link : otherLinks) {
eEntry.addContent(generateLinkElement(link));
}
if (entry.getAuthors() != null && !entry.getAuthors().isEmpty()) {
final List<SyndPerson> authors = entry.getAuthors();
if (Lists.isNotEmpty(authors)) {
final Element authorElement = new Element("author", getFeedNamespace());
fillPersonElement(authorElement, entry.getAuthors().get(0));
fillPersonElement(authorElement, authors.get(0));
eEntry.addContent(authorElement);
}
final List<SyndPerson> contributors = entry.getContributors();
for (int i = 0; i < contributors.size(); i++) {
for (final SyndPerson contributor : contributors) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
fillPersonElement(contributorElement, contributors.get(i));
fillPersonElement(contributorElement, contributor);
eEntry.addContent(contributorElement);
}
if (entry.getId() != null) {
eEntry.addContent(generateSimpleElement("id", entry.getId()));
final String id = entry.getId();
if (id != null) {
eEntry.addContent(generateSimpleElement("id", id));
}
if (entry.getModified() != null) {
final Date modified = entry.getModified();
if (modified != null) {
final Element modifiedElement = new Element("modified", getFeedNamespace());
modifiedElement.addContent(DateParser.formatW3CDateTime(entry.getModified(), Locale.US));
modifiedElement.addContent(DateParser.formatW3CDateTime(modified, Locale.US));
eEntry.addContent(modifiedElement);
}
if (entry.getIssued() != null) {
final Date issued = entry.getIssued();
if (issued != null) {
final Element issuedElement = new Element("issued", getFeedNamespace());
issuedElement.addContent(DateParser.formatW3CDateTime(entry.getIssued(), Locale.US));
issuedElement.addContent(DateParser.formatW3CDateTime(issued, Locale.US));
eEntry.addContent(issuedElement);
}
if (entry.getCreated() != null) {
final Date created = entry.getCreated();
if (created != null) {
final Element createdElement = new Element("created", getFeedNamespace());
createdElement.addContent(DateParser.formatW3CDateTime(entry.getCreated(), Locale.US));
createdElement.addContent(DateParser.formatW3CDateTime(created, Locale.US));
eEntry.addContent(createdElement);
}
if (entry.getSummary() != null) {
final Content summary = entry.getSummary();
if (summary != null) {
final Element summaryElement = new Element("summary", getFeedNamespace());
fillContentElement(summaryElement, entry.getSummary());
fillContentElement(summaryElement, summary);
eEntry.addContent(summaryElement);
}
final List<Content> contents = entry.getContents();
for (int i = 0; i < contents.size(); i++) {
for (final Content content : contents) {
final Element contentElement = new Element("content", getFeedNamespace());
fillContentElement(contentElement, contents.get(i));
fillContentElement(contentElement, content);
eEntry.addContent(contentElement);
}
generateForeignMarkup(eEntry, entry.getForeignMarkup());
}
protected void checkFeedHeaderConstraints(final Element eFeed) throws FeedException {
@ -253,75 +278,98 @@ public class Atom03Generator extends BaseWireFeedGenerator {
}
protected Element generateLinkElement(final Link link) {
final Element linkElement = new Element("link", getFeedNamespace());
if (link.getRel() != null) {
final Attribute relAttribute = new Attribute("rel", link.getRel().toString());
final String rel = link.getRel();
if (rel != null) {
final Attribute relAttribute = new Attribute("rel", rel.toString());
linkElement.setAttribute(relAttribute);
}
if (link.getType() != null) {
final Attribute typeAttribute = new Attribute("type", link.getType());
final String type = link.getType();
if (type != null) {
final Attribute typeAttribute = new Attribute("type", type);
linkElement.setAttribute(typeAttribute);
}
if (link.getHref() != null) {
final Attribute hrefAttribute = new Attribute("href", link.getHref());
final String href = link.getHref();
if (href != null) {
final Attribute hrefAttribute = new Attribute("href", href);
linkElement.setAttribute(hrefAttribute);
}
return linkElement;
}
protected void fillPersonElement(final Element element, final SyndPerson person) {
if (person.getName() != null) {
element.addContent(generateSimpleElement("name", person.getName()));
}
if (person.getUri() != null) {
element.addContent(generateSimpleElement("url", person.getUri()));
final String name = person.getName();
if (name != null) {
element.addContent(generateSimpleElement("name", name));
}
if (person.getEmail() != null) {
element.addContent(generateSimpleElement("email", person.getEmail()));
final String uri = person.getUri();
if (uri != null) {
element.addContent(generateSimpleElement("url", uri));
}
final String email = person.getEmail();
if (email != null) {
element.addContent(generateSimpleElement("email", email));
}
}
protected Element generateTagLineElement(final Content tagline) {
final Element taglineElement = new Element("tagline", getFeedNamespace());
if (tagline.getType() != null) {
final Attribute typeAttribute = new Attribute("type", tagline.getType());
final String type = tagline.getType();
if (type != null) {
final Attribute typeAttribute = new Attribute("type", type);
taglineElement.setAttribute(typeAttribute);
}
if (tagline.getValue() != null) {
taglineElement.addContent(tagline.getValue());
final String value = tagline.getValue();
if (value != null) {
taglineElement.addContent(value);
}
return taglineElement;
}
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException {
if (content.getType() != null) {
final Attribute typeAttribute = new Attribute("type", content.getType());
final String type = content.getType();
if (type != null) {
final Attribute typeAttribute = new Attribute("type", type);
contentElement.setAttribute(typeAttribute);
}
final String mode = content.getMode();
if (mode != null) {
final Attribute modeAttribute = new Attribute("mode", content.getMode().toString());
final Attribute modeAttribute = new Attribute("mode", mode.toString());
contentElement.setAttribute(modeAttribute);
}
if (content.getValue() != null) {
final String value = content.getValue();
if (value != null) {
if (mode == null || mode.equals(Content.ESCAPED)) {
contentElement.addContent(content.getValue());
contentElement.addContent(value);
} else if (mode.equals(Content.BASE64)) {
contentElement.addContent(Base64.encode(content.getValue()));
contentElement.addContent(Base64.encode(value));
} else if (mode.equals(Content.XML)) {
final StringBuffer tmpDocString = new StringBuffer("<tmpdoc>");
tmpDocString.append(content.getValue());
tmpDocString.append(value);
tmpDocString.append("</tmpdoc>");
final StringReader tmpDocReader = new StringReader(tmpDocString.toString());
Document tmpDoc;
@ -336,24 +384,29 @@ public class Atom03Generator extends BaseWireFeedGenerator {
final List<org.jdom2.Content> children = tmpDoc.getRootElement().removeContent();
contentElement.addContent(children);
}
}
}
protected Element generateGeneratorElement(final Generator generator) {
final Element generatorElement = new Element("generator", getFeedNamespace());
if (generator.getUrl() != null) {
final Attribute urlAttribute = new Attribute("url", generator.getUrl());
final String url = generator.getUrl();
if (url != null) {
final Attribute urlAttribute = new Attribute("url", url);
generatorElement.setAttribute(urlAttribute);
}
if (generator.getVersion() != null) {
final Attribute versionAttribute = new Attribute("version", generator.getVersion());
final String version = generator.getVersion();
if (version != null) {
final Attribute versionAttribute = new Attribute("version", version);
generatorElement.setAttribute(versionAttribute);
}
if (generator.getValue() != null) {
generatorElement.addContent(generator.getValue());
final String value = generator.getValue();
if (value != null) {
generatorElement.addContent(value);
}
return generatorElement;

View file

@ -25,6 +25,7 @@ import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.output.XMLOutputter;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.atom.Content;
import com.sun.syndication.feed.atom.Entry;
@ -35,9 +36,8 @@ import com.sun.syndication.feed.atom.Person;
import com.sun.syndication.feed.synd.SyndPerson;
import com.sun.syndication.io.FeedException;
/**
*/
public class Atom03Parser extends BaseWireFeedParser {
private static final String ATOM_03_URI = "http://purl.org/atom/ns#";
private static final Namespace ATOM_03_NS = Namespace.getNamespace(ATOM_03_URI);
@ -62,125 +62,137 @@ public class Atom03Parser extends BaseWireFeedParser {
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException {
if (validate) {
validateFeed(document);
}
final Element rssRoot = document.getRootElement();
return parseFeed(rssRoot, locale);
}
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
// with validation turned on.
// otherwise will have to check the document elements by hand.
// TODO 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 with validation
// turned on. otherwise will have to check the document elements by hand.
}
protected WireFeed parseFeed(final Element eFeed, final Locale locale) {
final Feed feed = new Feed(getType());
feed.setStyleSheet(getStyleSheet(eFeed.getDocument()));
final String type = getType();
final Document document = eFeed.getDocument();
final String styleSheet = getStyleSheet(document);
Element e = eFeed.getChild("title", getAtomNamespace());
if (e != null) {
feed.setTitleEx(parseContent(e));
final Feed feed = new Feed(type);
feed.setStyleSheet(styleSheet);
final Element title = eFeed.getChild("title", getAtomNamespace());
if (title != null) {
feed.setTitleEx(parseContent(title));
}
List<Element> eList = eFeed.getChildren("link", getAtomNamespace());
feed.setAlternateLinks(parseAlternateLinks(eList));
feed.setOtherLinks(parseOtherLinks(eList));
final List<Element> links = eFeed.getChildren("link", getAtomNamespace());
feed.setAlternateLinks(parseAlternateLinks(links));
feed.setOtherLinks(parseOtherLinks(links));
e = eFeed.getChild("author", getAtomNamespace());
if (e != null) {
final Element author = eFeed.getChild("author", getAtomNamespace());
if (author != null) {
final List<SyndPerson> authors = new ArrayList<SyndPerson>();
authors.add(parsePerson(e));
authors.add(parsePerson(author));
feed.setAuthors(authors);
}
eList = eFeed.getChildren("contributor", getAtomNamespace());
if (!eList.isEmpty()) {
feed.setContributors(parsePersons(eList));
final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace());
if (!contributors.isEmpty()) {
feed.setContributors(parsePersons(contributors));
}
e = eFeed.getChild("tagline", getAtomNamespace());
if (e != null) {
feed.setTagline(parseContent(e));
final Element tagline = eFeed.getChild("tagline", getAtomNamespace());
if (tagline != null) {
feed.setTagline(parseContent(tagline));
}
e = eFeed.getChild("id", getAtomNamespace());
if (e != null) {
feed.setId(e.getText());
final Element id = eFeed.getChild("id", getAtomNamespace());
if (id != null) {
feed.setId(id.getText());
}
e = eFeed.getChild("generator", getAtomNamespace());
if (e != null) {
final Element generator = eFeed.getChild("generator", getAtomNamespace());
if (generator != null) {
final Generator gen = new Generator();
gen.setValue(e.getText());
String att = getAttributeValue(e, "url");
gen.setValue(generator.getText());
String att = getAttributeValue(generator, "url");
if (att != null) {
gen.setUrl(att);
}
att = getAttributeValue(e, "version");
att = getAttributeValue(generator, "version");
if (att != null) {
gen.setVersion(att);
}
feed.setGenerator(gen);
}
e = eFeed.getChild("copyright", getAtomNamespace());
if (e != null) {
feed.setCopyright(e.getText());
final Element copyright = eFeed.getChild("copyright", getAtomNamespace());
if (copyright != null) {
feed.setCopyright(copyright.getText());
}
e = eFeed.getChild("info", getAtomNamespace());
if (e != null) {
feed.setInfo(parseContent(e));
final Element info = eFeed.getChild("info", getAtomNamespace());
if (info != null) {
feed.setInfo(parseContent(info));
}
e = eFeed.getChild("modified", getAtomNamespace());
if (e != null) {
feed.setModified(DateParser.parseDate(e.getText(), locale));
final Element modified = eFeed.getChild("modified", getAtomNamespace());
if (modified != null) {
feed.setModified(DateParser.parseDate(modified.getText(), locale));
}
feed.setModules(parseFeedModules(eFeed, locale));
eList = eFeed.getChildren("entry", getAtomNamespace());
if (!eList.isEmpty()) {
feed.setEntries(parseEntries(eList, locale));
final List<Element> entries = eFeed.getChildren("entry", getAtomNamespace());
if (!entries.isEmpty()) {
feed.setEntries(parseEntries(entries, locale));
}
final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
if (!foreignMarkup.isEmpty()) {
feed.setForeignMarkup(foreignMarkup);
}
return feed;
}
private Link parseLink(final Element eLink) {
final Link link = new Link();
String att = getAttributeValue(eLink, "rel");
if (att != null) {
link.setRel(att);
final String rel = getAttributeValue(eLink, "rel");
if (rel != null) {
link.setRel(rel);
}
att = getAttributeValue(eLink, "type");
if (att != null) {
link.setType(att);
final String type = getAttributeValue(eLink, "type");
if (type != null) {
link.setType(type);
}
att = getAttributeValue(eLink, "href");
if (att != null) {
link.setHref(att);
final String href = getAttributeValue(eLink, "href");
if (href != null) {
link.setHref(href);
}
return link;
}
// List(Elements) -> List(Link)
private List<Link> parseLinks(final List<Element> eLinks, final boolean alternate) {
final List<Link> links = new ArrayList<Link>();
for (int i = 0; i < eLinks.size(); i++) {
final Element eLink = eLinks.get(i);
for (final Element eLink : eLinks) {
final String rel = getAttributeValue(eLink, "rel");
if (alternate) {
if ("alternate".equals(rel)) {
@ -192,11 +204,9 @@ public class Atom03Parser extends BaseWireFeedParser {
}
}
}
if (!links.isEmpty()) {
return links;
} else {
return null;
}
return Lists.emptyToNull(links);
}
// List(Elements) -> List(Link)
@ -210,51 +220,67 @@ public class Atom03Parser extends BaseWireFeedParser {
}
private Person parsePerson(final Element ePerson) {
final Person person = new Person();
Element e = ePerson.getChild("name", getAtomNamespace());
if (e != null) {
person.setName(e.getText());
final Element name = ePerson.getChild("name", getAtomNamespace());
if (name != null) {
person.setName(name.getText());
}
e = ePerson.getChild("url", getAtomNamespace());
if (e != null) {
person.setUrl(e.getText());
final Element url = ePerson.getChild("url", getAtomNamespace());
if (url != null) {
person.setUrl(url.getText());
}
e = ePerson.getChild("email", getAtomNamespace());
if (e != null) {
person.setEmail(e.getText());
final Element email = ePerson.getChild("email", getAtomNamespace());
if (email != null) {
person.setEmail(email.getText());
}
return person;
}
// List(Elements) -> List(Persons)
private List<SyndPerson> parsePersons(final List<Element> ePersons) {
final List<SyndPerson> persons = new ArrayList<SyndPerson>();
for (int i = 0; i < ePersons.size(); i++) {
persons.add(parsePerson(ePersons.get(i)));
}
if (!persons.isEmpty()) {
return persons;
} else {
return null;
for (final Element person : ePersons) {
persons.add(parsePerson(person));
}
return Lists.emptyToNull(persons);
}
private Content parseContent(final Element e) {
String value = null;
String type = getAttributeValue(e, "type");
if (type == null) {
type = "text/plain";
}
String mode = getAttributeValue(e, "mode");
if (mode == null) {
mode = Content.XML; // default to xml content
}
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)) {
final XMLOutputter outputter = new XMLOutputter();
final List<org.jdom2.Content> contents = e.getContent();
for (final org.jdom2.Content content : contents) {
@ -267,6 +293,7 @@ public class Atom03Parser extends BaseWireFeedParser {
}
value = outputter.outputString(contents);
}
final Content content = new Content();
@ -278,71 +305,71 @@ public class Atom03Parser extends BaseWireFeedParser {
// List(Elements) -> List(Entries)
private List<Entry> parseEntries(final List<Element> eEntries, final Locale locale) {
final List<Entry> entries = new ArrayList<Entry>();
for (int i = 0; i < eEntries.size(); i++) {
entries.add(parseEntry(eEntries.get(i), locale));
}
if (!entries.isEmpty()) {
return entries;
} else {
return null;
for (final Element entry : eEntries) {
entries.add(parseEntry(entry, locale));
}
return Lists.emptyToNull(entries);
}
private Entry parseEntry(final Element eEntry, final Locale locale) {
final Entry entry = new Entry();
Element e = eEntry.getChild("title", getAtomNamespace());
if (e != null) {
entry.setTitleEx(parseContent(e));
final Element title = eEntry.getChild("title", getAtomNamespace());
if (title != null) {
entry.setTitleEx(parseContent(title));
}
List<Element> eList = eEntry.getChildren("link", getAtomNamespace());
entry.setAlternateLinks(parseAlternateLinks(eList));
entry.setOtherLinks(parseOtherLinks(eList));
final List<Element> links = eEntry.getChildren("link", getAtomNamespace());
entry.setAlternateLinks(parseAlternateLinks(links));
entry.setOtherLinks(parseOtherLinks(links));
e = eEntry.getChild("author", getAtomNamespace());
if (e != null) {
final Element author = eEntry.getChild("author", getAtomNamespace());
if (author != null) {
final List<SyndPerson> authors = new ArrayList<SyndPerson>();
authors.add(parsePerson(e));
authors.add(parsePerson(author));
entry.setAuthors(authors);
}
eList = eEntry.getChildren("contributor", getAtomNamespace());
if (!eList.isEmpty()) {
entry.setContributors(parsePersons(eList));
final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace());
if (!contributors.isEmpty()) {
entry.setContributors(parsePersons(contributors));
}
e = eEntry.getChild("id", getAtomNamespace());
if (e != null) {
entry.setId(e.getText());
final Element id = eEntry.getChild("id", getAtomNamespace());
if (id != null) {
entry.setId(id.getText());
}
e = eEntry.getChild("modified", getAtomNamespace());
if (e != null) {
entry.setModified(DateParser.parseDate(e.getText(), locale));
final Element modified = eEntry.getChild("modified", getAtomNamespace());
if (modified != null) {
entry.setModified(DateParser.parseDate(modified.getText(), locale));
}
e = eEntry.getChild("issued", getAtomNamespace());
if (e != null) {
entry.setIssued(DateParser.parseDate(e.getText(), locale));
final Element issued = eEntry.getChild("issued", getAtomNamespace());
if (issued != null) {
entry.setIssued(DateParser.parseDate(issued.getText(), locale));
}
e = eEntry.getChild("created", getAtomNamespace());
if (e != null) {
entry.setCreated(DateParser.parseDate(e.getText(), locale));
final Element created = eEntry.getChild("created", getAtomNamespace());
if (created != null) {
entry.setCreated(DateParser.parseDate(created.getText(), locale));
}
e = eEntry.getChild("summary", getAtomNamespace());
if (e != null) {
entry.setSummary(parseContent(e));
final Element summary = eEntry.getChild("summary", getAtomNamespace());
if (summary != null) {
entry.setSummary(parseContent(summary));
}
eList = eEntry.getChildren("content", getAtomNamespace());
if (!eList.isEmpty()) {
final List<Element> contents = eEntry.getChildren("content", getAtomNamespace());
if (!contents.isEmpty()) {
final List<Content> content = new ArrayList<Content>();
for (int i = 0; i < eList.size(); i++) {
content.add(parseContent(eList.get(i)));
for (final Element eContent : contents) {
content.add(parseContent(eContent));
}
entry.setContents(content);
}
@ -353,7 +380,9 @@ public class Atom03Parser extends BaseWireFeedParser {
if (!foreignMarkup.isEmpty()) {
entry.setForeignMarkup(foreignMarkup);
}
return entry;
}
}

View file

@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@ -30,6 +31,7 @@ import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.XMLOutputter;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.atom.Category;
import com.sun.syndication.feed.atom.Content;
@ -49,8 +51,8 @@ import com.sun.syndication.io.WireFeedOutput;
* @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);
@ -87,15 +89,23 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
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);
if (feed.getXmlBase() != null) {
root.setAttribute("base", feed.getXmlBase(), Namespace.XML_NAMESPACE);
final String xmlBase = feed.getXmlBase();
if (xmlBase != null) {
root.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE);
}
generateModuleNamespaceDefs(root);
return root;
}
protected void populateFeed(final Feed feed, final Element parent) throws FeedException {
@ -113,41 +123,49 @@ public class Atom10Generator extends BaseWireFeedGenerator {
protected void addEntries(final Feed feed, final Element parent) throws FeedException {
final List<Entry> items = feed.getEntries();
for (int i = 0; i < items.size(); i++) {
addEntry(items.get(i), parent);
for (final Entry entry : items) {
addEntry(entry, parent);
}
checkEntriesConstraints(parent);
}
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);
final String xmlBase = entry.getXmlBase();
if (xmlBase != null) {
eEntry.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE);
}
populateEntry(entry, eEntry);
generateForeignMarkup(eEntry, entry.getForeignMarkup());
checkEntryConstraints(eEntry);
generateItemModules(entry.getModules(), eEntry);
parent.addContent(eEntry);
}
protected void populateFeedHeader(final Feed feed, final Element eFeed) throws FeedException {
if (feed.getTitleEx() != null) {
final Content titleEx = feed.getTitleEx();
if (titleEx != null) {
final Element titleElement = new Element("title", getFeedNamespace());
fillContentElement(titleElement, feed.getTitleEx());
fillContentElement(titleElement, titleEx);
eFeed.addContent(titleElement);
}
List<Link> links = feed.getAlternateLinks();
if (links != null) {
for (int i = 0; i < links.size(); i++) {
eFeed.addContent(generateLinkElement(links.get(i)));
final List<Link> alternateLinks = feed.getAlternateLinks();
if (alternateLinks != null) {
for (final Link link : alternateLinks) {
eFeed.addContent(generateLinkElement(link));
}
}
links = feed.getOtherLinks();
if (links != null) {
for (int j = 0; j < links.size(); j++) {
eFeed.addContent(generateLinkElement(links.get(j)));
final List<Link> otherLinks = feed.getOtherLinks();
if (otherLinks != null) {
for (final Link link : otherLinks) {
eFeed.addContent(generateLinkElement(link));
}
}
@ -159,133 +177,153 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
final List<SyndPerson> authors = feed.getAuthors();
if (authors != null && !authors.isEmpty()) {
for (int i = 0; i < authors.size(); i++) {
if (Lists.isNotEmpty(authors)) {
for (final SyndPerson author : authors) {
final Element authorElement = new Element("author", getFeedNamespace());
fillPersonElement(authorElement, feed.getAuthors().get(i));
fillPersonElement(authorElement, author);
eFeed.addContent(authorElement);
}
}
final List<SyndPerson> contributors = feed.getContributors();
if (contributors != null && !contributors.isEmpty()) {
for (int i = 0; i < contributors.size(); i++) {
if (Lists.isNotEmpty(contributors)) {
for (final SyndPerson contributor : contributors) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
fillPersonElement(contributorElement, contributors.get(i));
fillPersonElement(contributorElement, contributor);
eFeed.addContent(contributorElement);
}
}
if (feed.getSubtitle() != null) {
final Content subtitle = feed.getSubtitle();
if (subtitle != null) {
final Element subtitleElement = new Element("subtitle", getFeedNamespace());
fillContentElement(subtitleElement, feed.getSubtitle());
fillContentElement(subtitleElement, subtitle);
eFeed.addContent(subtitleElement);
}
if (feed.getId() != null) {
eFeed.addContent(generateSimpleElement("id", feed.getId()));
final String id = feed.getId();
if (id != null) {
eFeed.addContent(generateSimpleElement("id", id));
}
if (feed.getGenerator() != null) {
eFeed.addContent(generateGeneratorElement(feed.getGenerator()));
final Generator generator = feed.getGenerator();
if (generator != null) {
eFeed.addContent(generateGeneratorElement(generator));
}
if (feed.getRights() != null) {
eFeed.addContent(generateSimpleElement("rights", feed.getRights()));
final String rights = feed.getRights();
if (rights != null) {
eFeed.addContent(generateSimpleElement("rights", rights));
}
if (feed.getIcon() != null) {
eFeed.addContent(generateSimpleElement("icon", feed.getIcon()));
final String icon = feed.getIcon();
if (icon != null) {
eFeed.addContent(generateSimpleElement("icon", icon));
}
if (feed.getLogo() != null) {
eFeed.addContent(generateSimpleElement("logo", feed.getLogo()));
final String logo = feed.getLogo();
if (logo != null) {
eFeed.addContent(generateSimpleElement("logo", logo));
}
if (feed.getUpdated() != null) {
final Date updated = feed.getUpdated();
if (updated != null) {
final Element updatedElement = new Element("updated", getFeedNamespace());
updatedElement.addContent(DateParser.formatW3CDateTime(feed.getUpdated(), Locale.US));
updatedElement.addContent(DateParser.formatW3CDateTime(updated, Locale.US));
eFeed.addContent(updatedElement);
}
}
protected void populateEntry(final Entry entry, final Element eEntry) throws FeedException {
if (entry.getTitleEx() != null) {
final Content titleEx = entry.getTitleEx();
if (titleEx != null) {
final Element titleElement = new Element("title", getFeedNamespace());
fillContentElement(titleElement, entry.getTitleEx());
fillContentElement(titleElement, titleEx);
eEntry.addContent(titleElement);
}
List<Link> links = entry.getAlternateLinks();
if (links != null) {
for (int i = 0; i < links.size(); i++) {
eEntry.addContent(generateLinkElement(links.get(i)));
final List<Link> alternateLinks = entry.getAlternateLinks();
if (alternateLinks != null) {
for (final Link link : alternateLinks) {
eEntry.addContent(generateLinkElement(link));
}
}
links = entry.getOtherLinks();
if (links != null) {
for (int i = 0; i < links.size(); i++) {
eEntry.addContent(generateLinkElement(links.get(i)));
final List<Link> otherLinks = entry.getOtherLinks();
if (otherLinks != null) {
for (final Link link : otherLinks) {
eEntry.addContent(generateLinkElement(link));
}
}
final List<Category> cats = entry.getCategories();
if (cats != null) {
for (int i = 0; i < cats.size(); i++) {
eEntry.addContent(generateCategoryElement(cats.get(i)));
for (final Category category : cats) {
eEntry.addContent(generateCategoryElement(category));
}
}
final List<SyndPerson> authors = entry.getAuthors();
if (authors != null && !authors.isEmpty()) {
for (int i = 0; i < authors.size(); i++) {
if (Lists.isNotEmpty(authors)) {
for (final SyndPerson author : authors) {
final Element authorElement = new Element("author", getFeedNamespace());
fillPersonElement(authorElement, entry.getAuthors().get(i));
fillPersonElement(authorElement, author);
eEntry.addContent(authorElement);
}
}
final List<SyndPerson> contributors = entry.getContributors();
if (contributors != null && !contributors.isEmpty()) {
for (int i = 0; i < contributors.size(); i++) {
if (Lists.isNotEmpty(contributors)) {
for (final SyndPerson contributor : contributors) {
final Element contributorElement = new Element("contributor", getFeedNamespace());
fillPersonElement(contributorElement, contributors.get(i));
fillPersonElement(contributorElement, contributor);
eEntry.addContent(contributorElement);
}
}
if (entry.getId() != null) {
eEntry.addContent(generateSimpleElement("id", entry.getId()));
final String id = entry.getId();
if (id != null) {
eEntry.addContent(generateSimpleElement("id", id));
}
if (entry.getUpdated() != null) {
final Date updated = entry.getUpdated();
if (updated != null) {
final Element updatedElement = new Element("updated", getFeedNamespace());
updatedElement.addContent(DateParser.formatW3CDateTime(entry.getUpdated(), Locale.US));
updatedElement.addContent(DateParser.formatW3CDateTime(updated, Locale.US));
eEntry.addContent(updatedElement);
}
if (entry.getPublished() != null) {
final Date published = entry.getPublished();
if (published != null) {
final Element publishedElement = new Element("published", getFeedNamespace());
publishedElement.addContent(DateParser.formatW3CDateTime(entry.getPublished(), Locale.US));
publishedElement.addContent(DateParser.formatW3CDateTime(published, Locale.US));
eEntry.addContent(publishedElement);
}
if (entry.getContents() != null && !entry.getContents().isEmpty()) {
final List<Content> contents = entry.getContents();
if (Lists.isNotEmpty(contents)) {
final Element contentElement = new Element("content", getFeedNamespace());
final Content content = entry.getContents().get(0);
final Content content = contents.get(0);
fillContentElement(contentElement, content);
eEntry.addContent(contentElement);
}
if (entry.getSummary() != null) {
final Content summary = entry.getSummary();
if (summary != null) {
final Element summaryElement = new Element("summary", getFeedNamespace());
fillContentElement(summaryElement, entry.getSummary());
fillContentElement(summaryElement, summary);
eEntry.addContent(summaryElement);
}
if (entry.getSource() != null) {
final Feed source = entry.getSource();
if (source != null) {
final Element sourceElement = new Element("source", getFeedNamespace());
populateFeedHeader(entry.getSource(), sourceElement);
populateFeedHeader(source, sourceElement);
eEntry.addContent(sourceElement);
}
}
protected void checkFeedHeaderConstraints(final Element eFeed) throws FeedException {
@ -298,90 +336,122 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
protected Element generateCategoryElement(final Category cat) {
final Element catElement = new Element("category", getFeedNamespace());
if (cat.getTerm() != null) {
final Attribute termAttribute = new Attribute("term", cat.getTerm());
final Namespace namespace = getFeedNamespace();
final Element catElement = new Element("category", namespace);
final String term = cat.getTerm();
if (term != null) {
final Attribute termAttribute = new Attribute("term", term);
catElement.setAttribute(termAttribute);
}
if (cat.getLabel() != null) {
final Attribute labelAttribute = new Attribute("label", cat.getLabel());
final String label = cat.getLabel();
if (label != null) {
final Attribute labelAttribute = new Attribute("label", label);
catElement.setAttribute(labelAttribute);
}
if (cat.getScheme() != null) {
final Attribute schemeAttribute = new Attribute("scheme", cat.getScheme());
final String scheme = cat.getScheme();
if (scheme != null) {
final Attribute schemeAttribute = new Attribute("scheme", scheme);
catElement.setAttribute(schemeAttribute);
}
return catElement;
}
protected Element generateLinkElement(final Link link) {
final Element linkElement = new Element("link", getFeedNamespace());
if (link.getRel() != null) {
final Attribute relAttribute = new Attribute("rel", link.getRel());
final Namespace namespace = getFeedNamespace();
final Element linkElement = new Element("link", namespace);
final String rel = link.getRel();
if (rel != null) {
final Attribute relAttribute = new Attribute("rel", rel);
linkElement.setAttribute(relAttribute);
}
if (link.getType() != null) {
final Attribute typeAttribute = new Attribute("type", link.getType());
final String type = link.getType();
if (type != null) {
final Attribute typeAttribute = new Attribute("type", type);
linkElement.setAttribute(typeAttribute);
}
if (link.getHref() != null) {
final Attribute hrefAttribute = new Attribute("href", link.getHref());
final String href = link.getHref();
if (href != null) {
final Attribute hrefAttribute = new Attribute("href", href);
linkElement.setAttribute(hrefAttribute);
}
if (link.getHreflang() != null) {
final Attribute hreflangAttribute = new Attribute("hreflang", link.getHreflang());
final String hreflang = link.getHreflang();
if (hreflang != null) {
final Attribute hreflangAttribute = new Attribute("hreflang", hreflang);
linkElement.setAttribute(hreflangAttribute);
}
if (link.getTitle() != null) {
final Attribute title = new Attribute("title", link.getTitle());
final String linkTitle = link.getTitle();
if (linkTitle != null) {
final Attribute title = new Attribute("title", linkTitle);
linkElement.setAttribute(title);
}
if (link.getLength() != 0) {
final Attribute lenght = new Attribute("length", Long.toString(link.getLength()));
linkElement.setAttribute(lenght);
}
return linkElement;
}
protected void fillPersonElement(final Element element, final SyndPerson person) {
if (person.getName() != null) {
element.addContent(generateSimpleElement("name", person.getName()));
}
if (person.getUri() != null) {
element.addContent(generateSimpleElement("uri", person.getUri()));
final String name = person.getName();
if (name != null) {
element.addContent(generateSimpleElement("name", name));
}
if (person.getEmail() != null) {
element.addContent(generateSimpleElement("email", person.getEmail()));
final String uri = person.getUri();
if (uri != null) {
element.addContent(generateSimpleElement("uri", uri));
}
final String email = person.getEmail();
if (email != null) {
element.addContent(generateSimpleElement("email", email));
}
generatePersonModules(person.getModules(), element);
}
protected Element generateTagLineElement(final Content tagline) {
final Element taglineElement = new Element("subtitle", getFeedNamespace());
if (tagline.getType() != null) {
final Attribute typeAttribute = new Attribute("type", tagline.getType());
final String type = tagline.getType();
if (type != null) {
final Attribute typeAttribute = new Attribute("type", type);
taglineElement.setAttribute(typeAttribute);
}
if (tagline.getValue() != null) {
taglineElement.addContent(tagline.getValue());
final String value = tagline.getValue();
if (value != null) {
taglineElement.addContent(value);
}
return taglineElement;
}
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException {
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
@ -396,16 +466,20 @@ public class Atom10Generator extends BaseWireFeedGenerator {
final Attribute typeAttribute = new Attribute("type", atomType);
contentElement.setAttribute(typeAttribute);
}
final String href = content.getSrc();
if (href != null) {
final Attribute srcAttribute = new Attribute("src", href);
contentElement.setAttribute(srcAttribute);
}
if (content.getValue() != null) {
final String value = content.getValue();
if (value != null) {
if (atomType != null && (atomType.equals(Content.XHTML) || atomType.indexOf("/xml") != -1 || atomType.indexOf("+xml") != -1)) {
final StringBuffer tmpDocString = new StringBuffer("<tmpdoc>");
tmpDocString.append(content.getValue());
tmpDocString.append(value);
tmpDocString.append("</tmpdoc>");
final StringReader tmpDocReader = new StringReader(tmpDocString.toString());
Document tmpDoc;
@ -417,29 +491,37 @@ public class Atom10Generator extends BaseWireFeedGenerator {
}
final List<org.jdom2.Content> children = tmpDoc.getRootElement().removeContent();
contentElement.addContent(children);
} else {
// must be type html, text or some other non-XML format
// JDOM will escape property for XML
contentElement.addContent(content.getValue());
contentElement.addContent(value);
}
}
}
protected Element generateGeneratorElement(final Generator generator) {
final Element generatorElement = new Element("generator", getFeedNamespace());
if (generator.getUrl() != null) {
final Attribute urlAttribute = new Attribute("uri", generator.getUrl());
final String url = generator.getUrl();
if (url != null) {
final Attribute urlAttribute = new Attribute("uri", url);
generatorElement.setAttribute(urlAttribute);
}
if (generator.getVersion() != null) {
final Attribute versionAttribute = new Attribute("version", generator.getVersion());
final String version2 = generator.getVersion();
if (version2 != null) {
final Attribute versionAttribute = new Attribute("version", version2);
generatorElement.setAttribute(versionAttribute);
}
if (generator.getValue() != null) {
generatorElement.addContent(generator.getValue());
final String value = generator.getValue();
if (value != null) {
generatorElement.addContent(value);
}
return generatorElement;

View file

@ -33,6 +33,7 @@ import org.jdom2.Parent;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.XMLOutputter;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.atom.Category;
import com.sun.syndication.feed.atom.Content;
@ -52,6 +53,7 @@ import com.sun.syndication.io.WireFeedOutput;
* @author Dave Johnson
*/
public class Atom10Parser extends BaseWireFeedParser {
private static final String ATOM_10_URI = "http://www.w3.org/2005/Atom";
private static final Namespace ATOM_10_NS = Namespace.getNamespace(ATOM_10_URI);
@ -94,13 +96,9 @@ public class Atom10Parser extends BaseWireFeedParser {
}
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
// with validation turned on.
// otherwise will have to check the document elements by hand.
// 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 with validation
// turned on. otherwise will have to check the document elements by hand.
}
protected WireFeed parseFeed(final Element eFeed, final Locale locale) throws FeedException {
@ -135,203 +133,225 @@ public class Atom10Parser extends BaseWireFeedParser {
}
private Feed parseFeedMetadata(final String baseURI, final Element eFeed, final Locale locale) {
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) {
final Element title = eFeed.getChild("title", getAtomNamespace());
if (title != null) {
final Content c = new Content();
c.setValue(parseTextConstructToString(e));
c.setType(getAttributeValue(e, "type"));
c.setValue(parseTextConstructToString(title));
c.setType(getAttributeValue(title, "type"));
feed.setTitleEx(c);
}
List<Element> eList = eFeed.getChildren("link", getAtomNamespace());
feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, eList));
feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, eList));
final List<Element> links = eFeed.getChildren("link", getAtomNamespace());
feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, links));
feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, links));
final List<Element> cList = eFeed.getChildren("category", getAtomNamespace());
feed.setCategories(parseCategories(baseURI, cList));
final List<Element> categories = eFeed.getChildren("category", getAtomNamespace());
feed.setCategories(parseCategories(baseURI, categories));
eList = eFeed.getChildren("author", getAtomNamespace());
if (!eList.isEmpty()) {
feed.setAuthors(parsePersons(baseURI, eList, locale));
final List<Element> authors = eFeed.getChildren("author", getAtomNamespace());
if (!authors.isEmpty()) {
feed.setAuthors(parsePersons(baseURI, authors, locale));
}
eList = eFeed.getChildren("contributor", getAtomNamespace());
if (!eList.isEmpty()) {
feed.setContributors(parsePersons(baseURI, eList, locale));
final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace());
if (!contributors.isEmpty()) {
feed.setContributors(parsePersons(baseURI, contributors, locale));
}
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);
final Element subtitle = eFeed.getChild("subtitle", getAtomNamespace());
if (subtitle != null) {
final Content content = new Content();
content.setValue(parseTextConstructToString(subtitle));
content.setType(getAttributeValue(subtitle, "type"));
feed.setSubtitle(content);
}
e = eFeed.getChild("id", getAtomNamespace());
if (e != null) {
feed.setId(e.getText());
final Element id = eFeed.getChild("id", getAtomNamespace());
if (id != null) {
feed.setId(id.getText());
}
e = eFeed.getChild("generator", getAtomNamespace());
if (e != null) {
final Element generator = eFeed.getChild("generator", getAtomNamespace());
if (generator != null) {
final Generator gen = new Generator();
gen.setValue(e.getText());
String att = getAttributeValue(e, "uri");
if (att != null) {
gen.setUrl(att);
gen.setValue(generator.getText());
final String uri = getAttributeValue(generator, "uri");
if (uri != null) {
gen.setUrl(uri);
}
att = getAttributeValue(e, "version");
if (att != null) {
gen.setVersion(att);
final String version = getAttributeValue(generator, "version");
if (version != null) {
gen.setVersion(version);
}
feed.setGenerator(gen);
}
e = eFeed.getChild("rights", getAtomNamespace());
if (e != null) {
feed.setRights(parseTextConstructToString(e));
final Element rights = eFeed.getChild("rights", getAtomNamespace());
if (rights != null) {
feed.setRights(parseTextConstructToString(rights));
}
e = eFeed.getChild("icon", getAtomNamespace());
if (e != null) {
feed.setIcon(e.getText());
final Element icon = eFeed.getChild("icon", getAtomNamespace());
if (icon != null) {
feed.setIcon(icon.getText());
}
e = eFeed.getChild("logo", getAtomNamespace());
if (e != null) {
feed.setLogo(e.getText());
final Element logo = eFeed.getChild("logo", getAtomNamespace());
if (logo != null) {
feed.setLogo(logo.getText());
}
e = eFeed.getChild("updated", getAtomNamespace());
if (e != null) {
feed.setUpdated(DateParser.parseDate(e.getText(), locale));
final Element updated = eFeed.getChild("updated", getAtomNamespace());
if (updated != null) {
feed.setUpdated(DateParser.parseDate(updated.getText(), locale));
}
return feed;
}
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) {
link.setRel(att);
final String rel = getAttributeValue(eLink, "rel");
if (rel != null) {
link.setRel(rel);
}
att = getAttributeValue(eLink, "type");
if (att != null) {
link.setType(att);
final String type = getAttributeValue(eLink, "type");
if (type != null) {
link.setType(type);
}
att = getAttributeValue(eLink, "href");
if (att != null) {
link.setHref(att);
if (isRelativeURI(att)) {
link.setHrefResolved(resolveURI(baseURI, eLink, att));
final String href = getAttributeValue(eLink, "href");
if (href != null) {
link.setHref(href);
if (isRelativeURI(href)) {
link.setHrefResolved(resolveURI(baseURI, eLink, href));
}
}
att = getAttributeValue(eLink, "title");
if (att != null) {
link.setTitle(att);
final String title = getAttributeValue(eLink, "title");
if (title != null) {
link.setTitle(title);
}
att = getAttributeValue(eLink, "hreflang");
if (att != null) {
link.setHreflang(att);
final String hrefLang = getAttributeValue(eLink, "hreflang");
if (hrefLang != null) {
link.setHreflang(hrefLang);
}
att = getAttributeValue(eLink, "length");
if (att != null) {
final Long val = NumberParser.parseLong(att);
final String length = getAttributeValue(eLink, "length");
if (length != null) {
final Long val = NumberParser.parseLong(length);
if (val != null) {
link.setLength(val.longValue());
}
}
return link;
}
// List(Elements) -> List(Link)
private List<Link> parseAlternateLinks(final Feed feed, final Entry entry, final String baseURI, final List<Element> eLinks) {
final List<Link> links = new ArrayList<Link>();
for (int i = 0; i < eLinks.size(); i++) {
final Element eLink = eLinks.get(i);
for (final Element eLink : eLinks) {
final Link link = parseLink(feed, entry, baseURI, eLink);
if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) {
links.add(link);
}
}
if (!links.isEmpty()) {
return links;
} else {
return null;
}
return Lists.emptyToNull(links);
}
private List<Link> parseOtherLinks(final Feed feed, final Entry entry, final String baseURI, final List<Element> eLinks) {
final List<Link> links = new ArrayList<Link>();
for (int i = 0; i < eLinks.size(); i++) {
final Element eLink = eLinks.get(i);
for (final Element eLink : eLinks) {
final Link link = parseLink(feed, entry, baseURI, eLink);
if (!"alternate".equals(link.getRel())) {
links.add(link);
}
}
if (!links.isEmpty()) {
return links;
} else {
return null;
}
return Lists.emptyToNull(links);
}
private Person parsePerson(final String baseURI, final Element ePerson, final Locale locale) {
final Person person = new Person();
Element e = ePerson.getChild("name", getAtomNamespace());
if (e != null) {
person.setName(e.getText());
final Element name = ePerson.getChild("name", getAtomNamespace());
if (name != null) {
person.setName(name.getText());
}
e = ePerson.getChild("uri", getAtomNamespace());
if (e != null) {
person.setUri(e.getText());
if (isRelativeURI(e.getText())) {
person.setUriResolved(resolveURI(baseURI, ePerson, e.getText()));
final Element uri = ePerson.getChild("uri", getAtomNamespace());
if (uri != null) {
person.setUri(uri.getText());
if (isRelativeURI(uri.getText())) {
person.setUriResolved(resolveURI(baseURI, ePerson, uri.getText()));
}
}
e = ePerson.getChild("email", getAtomNamespace());
if (e != null) {
person.setEmail(e.getText());
final Element email = ePerson.getChild("email", getAtomNamespace());
if (email != null) {
person.setEmail(email.getText());
}
person.setModules(parsePersonModules(ePerson, locale));
return person;
}
// List(Elements) -> List(Persons)
private List<SyndPerson> parsePersons(final String baseURI, final List<Element> ePersons, final Locale locale) {
final List<SyndPerson> persons = new ArrayList<SyndPerson>();
for (int i = 0; i < ePersons.size(); i++) {
persons.add(parsePerson(baseURI, ePersons.get(i), locale));
}
if (!persons.isEmpty()) {
return persons;
} else {
return null;
for (final Element ePerson : ePersons) {
persons.add(parsePerson(baseURI, ePerson, locale));
}
return Lists.emptyToNull(persons);
}
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(final Element e) {
String value = null;
String type = getAttributeValue(e, "type");
if (type == null) {
type = Content.TEXT;
}
String value = null;
if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) {
// XHTML content needs special handling
final XMLOutputter outputter = new XMLOutputter();
@ -349,23 +369,25 @@ public class Atom10Parser extends BaseWireFeedParser {
// Everything else comes in verbatim
value = e.getText();
}
return value;
}
// List(Elements) -> List(Entries)
protected List<Entry> parseEntries(final Feed feed, final String baseURI, final List<Element> eEntries, final Locale locale) {
final List<Entry> entries = new ArrayList<Entry>();
for (int i = 0; i < eEntries.size(); i++) {
entries.add(this.parseEntry(feed, eEntries.get(i), baseURI, locale));
}
if (!entries.isEmpty()) {
return entries;
} else {
return null;
for (final Element entry : eEntries) {
entries.add(this.parseEntry(feed, entry, baseURI, locale));
}
return Lists.emptyToNull(entries);
}
protected Entry parseEntry(final Feed feed, final Element eEntry, final String baseURI, final Locale locale) {
final Entry entry = new Entry();
final String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE);
@ -373,67 +395,67 @@ public class Atom10Parser extends BaseWireFeedParser {
entry.setXmlBase(xmlBase);
}
Element e = eEntry.getChild("title", getAtomNamespace());
if (e != null) {
final Element title = eEntry.getChild("title", getAtomNamespace());
if (title != null) {
final Content c = new Content();
c.setValue(parseTextConstructToString(e));
c.setType(getAttributeValue(e, "type"));
c.setValue(parseTextConstructToString(title));
c.setType(getAttributeValue(title, "type"));
entry.setTitleEx(c);
}
List<Element> eList = eEntry.getChildren("link", getAtomNamespace());
entry.setAlternateLinks(parseAlternateLinks(feed, entry, baseURI, eList));
entry.setOtherLinks(parseOtherLinks(feed, entry, baseURI, eList));
final List<Element> links = eEntry.getChildren("link", getAtomNamespace());
entry.setAlternateLinks(parseAlternateLinks(feed, entry, baseURI, links));
entry.setOtherLinks(parseOtherLinks(feed, entry, baseURI, links));
eList = eEntry.getChildren("author", getAtomNamespace());
if (!eList.isEmpty()) {
entry.setAuthors(parsePersons(baseURI, eList, locale));
final List<Element> authors = eEntry.getChildren("author", getAtomNamespace());
if (!authors.isEmpty()) {
entry.setAuthors(parsePersons(baseURI, authors, locale));
}
eList = eEntry.getChildren("contributor", getAtomNamespace());
if (!eList.isEmpty()) {
entry.setContributors(parsePersons(baseURI, eList, locale));
final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace());
if (!contributors.isEmpty()) {
entry.setContributors(parsePersons(baseURI, contributors, locale));
}
e = eEntry.getChild("id", getAtomNamespace());
if (e != null) {
entry.setId(e.getText());
final Element id = eEntry.getChild("id", getAtomNamespace());
if (id != null) {
entry.setId(id.getText());
}
e = eEntry.getChild("updated", getAtomNamespace());
if (e != null) {
entry.setUpdated(DateParser.parseDate(e.getText(), locale));
final Element updated = eEntry.getChild("updated", getAtomNamespace());
if (updated != null) {
entry.setUpdated(DateParser.parseDate(updated.getText(), locale));
}
e = eEntry.getChild("published", getAtomNamespace());
if (e != null) {
entry.setPublished(DateParser.parseDate(e.getText(), locale));
final Element published = eEntry.getChild("published", getAtomNamespace());
if (published != null) {
entry.setPublished(DateParser.parseDate(published.getText(), locale));
}
e = eEntry.getChild("summary", getAtomNamespace());
if (e != null) {
entry.setSummary(parseContent(e));
final Element summary = eEntry.getChild("summary", getAtomNamespace());
if (summary != null) {
entry.setSummary(parseContent(summary));
}
e = eEntry.getChild("content", getAtomNamespace());
if (e != null) {
final Element content = eEntry.getChild("content", getAtomNamespace());
if (content != null) {
final List<Content> contents = new ArrayList<Content>();
contents.add(parseContent(e));
contents.add(parseContent(content));
entry.setContents(contents);
}
e = eEntry.getChild("rights", getAtomNamespace());
if (e != null) {
entry.setRights(e.getText());
final Element rights = eEntry.getChild("rights", getAtomNamespace());
if (rights != null) {
entry.setRights(rights.getText());
}
final List<Element> cList = eEntry.getChildren("category", getAtomNamespace());
entry.setCategories(parseCategories(baseURI, cList));
final List<Element> categories = eEntry.getChildren("category", getAtomNamespace());
entry.setCategories(parseCategories(baseURI, categories));
// TODO: SHOULD handle Atom entry source element
e = eEntry.getChild("source", getAtomNamespace());
if (e != null) {
entry.setSource(parseFeedMetadata(baseURI, e, locale));
final Element source = eEntry.getChild("source", getAtomNamespace());
if (source != null) {
entry.setSource(parseFeedMetadata(baseURI, source, locale));
}
entry.setModules(parseItemModules(eEntry, locale));
@ -442,39 +464,43 @@ public class Atom10Parser extends BaseWireFeedParser {
if (!foreignMarkup.isEmpty()) {
entry.setForeignMarkup(foreignMarkup);
}
return entry;
}
private List<Category> parseCategories(final String baseURI, final List<Element> eCategories) {
final List<Category> cats = new ArrayList<Category>();
for (int i = 0; i < eCategories.size(); i++) {
final Element eCategory = eCategories.get(i);
for (final Element eCategory : eCategories) {
cats.add(parseCategory(baseURI, eCategory));
}
if (!cats.isEmpty()) {
return cats;
} else {
return null;
}
return Lists.emptyToNull(cats);
}
private Category parseCategory(final String baseURI, final Element eCategory) {
final Category category = new Category();
String att = getAttributeValue(eCategory, "term");
if (att != null) {
category.setTerm(att);
final String term = getAttributeValue(eCategory, "term");
if (term != null) {
category.setTerm(term);
}
att = getAttributeValue(eCategory, "scheme");
if (att != null) {
category.setScheme(att);
if (isRelativeURI(att)) {
category.setSchemeResolved(resolveURI(baseURI, eCategory, att));
final String scheme = getAttributeValue(eCategory, "scheme");
if (scheme != null) {
category.setScheme(scheme);
if (isRelativeURI(scheme)) {
category.setSchemeResolved(resolveURI(baseURI, eCategory, scheme));
}
}
att = getAttributeValue(eCategory, "label");
if (att != null) {
category.setLabel(att);
final String label = getAttributeValue(eCategory, "label");
if (label != null) {
category.setLabel(label);
}
return category;
}
@ -506,10 +532,13 @@ public class Atom10Parser extends BaseWireFeedParser {
* @param url URL to be resolved
*/
public static String resolveURI(final String baseURI, final Parent parent, String url) {
if (!resolveURIs) {
return url;
}
if (isRelativeURI(url)) {
if (".".equals(url) || "./".equals(url)) {
url = "";
}
@ -560,7 +589,9 @@ public class Atom10Parser extends BaseWireFeedParser {
return formURI(baseURI, url);
}
}
return url;
}
/**
@ -658,7 +689,8 @@ public class Atom10Parser extends BaseWireFeedParser {
* Parse entry from reader.
*/
public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException,
FeedException {
FeedException {
// Parse entry into JDOM tree
final SAXBuilder builder = new SAXBuilder();
final Document entryDoc = builder.build(rd);
@ -681,4 +713,5 @@ public class Atom10Parser extends BaseWireFeedParser {
final Feed parsedFeed = (Feed) input.build(feedDoc);
return parsedFeed.getEntries().get(0);
}
}

View file

@ -122,25 +122,28 @@ public abstract class BaseWireFeedGenerator implements WireFeedGenerator {
// ConcurrentModificationException
// below
for (int i = 0; i < additionalNamespaces.size(); i++) {
final Namespace ns = additionalNamespaces.get(i);
for (final Namespace ns : additionalNamespaces) {
final String prefix = ns.getPrefix();
if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) {
root.removeNamespaceDeclaration(ns);
}
}
}
private static void collectUsedPrefixes(final Element el, final Set<String> collector) {
final String prefix = el.getNamespacePrefix();
if (prefix != null && prefix.length() > 0 && !collector.contains(prefix)) {
collector.add(prefix);
}
final List<Element> kids = el.getChildren();
for (int i = 0; i < kids.size(); i++) {
collectUsedPrefixes(kids.get(i), collector); // recursion
// - worth it
for (final Element kid : kids) {
// recursion- worth it
collectUsedPrefixes(kid, collector);
}
}
}

View file

@ -36,9 +36,9 @@ import com.sun.syndication.io.ModuleGenerator;
/**
* Feed Generator for DublinCore Module.
* <p/>
*
*
* @author Elaine Chien
*
*
*/
public class DCModuleGenerator implements ModuleGenerator {
@ -83,7 +83,7 @@ public class DCModuleGenerator implements ModuleGenerator {
* 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).
* <p/>
*
*
* @return a set with all the URIs this module generator uses.
*/
@Override
@ -94,97 +94,137 @@ public class DCModuleGenerator implements ModuleGenerator {
/**
* Populate an element tree with elements for a module.
* <p>
*
*
* @param module the module to populate from.
* @param element the root element to attach child elements to.
*/
@Override
public final void generate(final Module module, final Element element) {
final DCModule dcModule = (DCModule) module;
if (dcModule.getTitle() != null) {
final String title = dcModule.getTitle();
if (title != null) {
element.addContent(generateSimpleElementList("title", dcModule.getTitles()));
}
if (dcModule.getCreator() != null) {
final String creator = dcModule.getCreator();
if (creator != null) {
element.addContent(generateSimpleElementList("creator", dcModule.getCreators()));
}
final List<DCSubject> subjects = dcModule.getSubjects();
for (int i = 0; i < subjects.size(); i++) {
element.addContent(generateSubjectElement(subjects.get(i)));
for (final DCSubject dcSubject : subjects) {
element.addContent(generateSubjectElement(dcSubject));
}
if (dcModule.getDescription() != null) {
final String description = dcModule.getDescription();
if (description != null) {
element.addContent(generateSimpleElementList("description", dcModule.getDescriptions()));
}
if (dcModule.getPublisher() != null) {
final String publisher = dcModule.getPublisher();
if (publisher != null) {
element.addContent(generateSimpleElementList("publisher", dcModule.getPublishers()));
}
if (dcModule.getContributors() != null) {
element.addContent(generateSimpleElementList("contributor", dcModule.getContributors()));
final List<String> contributors = dcModule.getContributors();
if (contributors != null) {
element.addContent(generateSimpleElementList("contributor", contributors));
}
if (dcModule.getDate() != null) {
final Date dcDate = dcModule.getDate();
if (dcDate != null) {
for (final Date date : dcModule.getDates()) {
element.addContent(generateSimpleElement("date", DateParser.formatW3CDateTime(date, Locale.US)));
}
}
if (dcModule.getType() != null) {
final String type = dcModule.getType();
if (type != null) {
element.addContent(generateSimpleElementList("type", dcModule.getTypes()));
}
if (dcModule.getFormat() != null) {
final String format = dcModule.getFormat();
if (format != null) {
element.addContent(generateSimpleElementList("format", dcModule.getFormats()));
}
if (dcModule.getIdentifier() != null) {
final String identifier = dcModule.getIdentifier();
if (identifier != null) {
element.addContent(generateSimpleElementList("identifier", dcModule.getIdentifiers()));
}
if (dcModule.getSource() != null) {
final String source = dcModule.getSource();
if (source != null) {
element.addContent(generateSimpleElementList("source", dcModule.getSources()));
}
if (dcModule.getLanguage() != null) {
final String language = dcModule.getLanguage();
if (language != null) {
element.addContent(generateSimpleElementList("language", dcModule.getLanguages()));
}
if (dcModule.getRelation() != null) {
final String relation = dcModule.getRelation();
if (relation != null) {
element.addContent(generateSimpleElementList("relation", dcModule.getRelations()));
}
if (dcModule.getCoverage() != null) {
final String coverage = dcModule.getCoverage();
if (coverage != null) {
element.addContent(generateSimpleElementList("coverage", dcModule.getCoverages()));
}
if (dcModule.getRights() != null) {
final String rights = dcModule.getRights();
if (rights != null) {
element.addContent(generateSimpleElementList("rights", dcModule.getRightsList()));
}
}
/**
* Utility method to generate an element for a subject.
* <p>
*
*
* @param subject the subject to generate an element for.
* @return the element for the subject.
*/
protected final Element generateSubjectElement(final DCSubject subject) {
final Element subjectElement = new Element("subject", getDCNamespace());
if (subject.getTaxonomyUri() != null) {
final Element descriptionElement = new Element("Description", getRDFNamespace());
final String taxonomyUri = subject.getTaxonomyUri();
final String value = subject.getValue();
if (taxonomyUri != null) {
final Attribute resourceAttribute = new Attribute("resource", taxonomyUri, getRDFNamespace());
final Element topicElement = new Element("topic", getTaxonomyNamespace());
final Attribute resourceAttribute = new Attribute("resource", subject.getTaxonomyUri(), getRDFNamespace());
topicElement.setAttribute(resourceAttribute);
final Element descriptionElement = new Element("Description", getRDFNamespace());
descriptionElement.addContent(topicElement);
if (subject.getValue() != null) {
if (value != null) {
final Element valueElement = new Element("value", getRDFNamespace());
valueElement.addContent(subject.getValue());
valueElement.addContent(value);
descriptionElement.addContent(valueElement);
}
subjectElement.addContent(descriptionElement);
} else {
subjectElement.addContent(subject.getValue());
subjectElement.addContent(value);
}
return subjectElement;
}
/**
* Utility method to generate a single element containing a string.
* <p>
*
*
* @param name the name of the elment to generate.
* @param value the value of the text in the element.
* @return the element generated.
@ -192,24 +232,22 @@ public class DCModuleGenerator implements ModuleGenerator {
protected final Element generateSimpleElement(final String name, final String value) {
final Element element = new Element(name, getDCNamespace());
element.addContent(value);
return element;
}
/**
* Utility method to generate a list of simple elements.
* <p>
*
*
* @param name the name of the element list to generate.
* @param value the list of values for the elements.
* @param values the list of values for the elements.
* @return a list of Elements created.
*/
protected final List<Element> generateSimpleElementList(final String name, final List<String> value) {
protected final List<Element> generateSimpleElementList(final String name, final List<String> values) {
final List<Element> elements = new ArrayList<Element>();
for (final String string : value) {
elements.add(generateSimpleElement(name, string));
for (final String value : values) {
elements.add(generateSimpleElement(name, value));
}
return elements;
}
}

View file

@ -64,139 +64,163 @@ public class DCModuleParser implements ModuleParser {
/**
* Parse an element tree and return the module found in it.
* <p>
*
*
* @param dcRoot the root element containing the module elements.
* @param locale for date/time parsing
* @return the module parsed from the element tree, <i>null</i> if none.
*/
@Override
public Module parse(final Element dcRoot, final Locale locale) {
boolean foundSomething = false;
final DCModule dcm = new DCModuleImpl();
List<Element> eList = dcRoot.getChildren("title", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> titles = dcRoot.getChildren("title", getDCNamespace());
if (!titles.isEmpty()) {
foundSomething = true;
dcm.setTitles(parseElementList(eList));
dcm.setTitles(parseElementList(titles));
}
eList = dcRoot.getChildren("creator", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> creators = dcRoot.getChildren("creator", getDCNamespace());
if (!creators.isEmpty()) {
foundSomething = true;
dcm.setCreators(parseElementList(eList));
dcm.setCreators(parseElementList(creators));
}
eList = dcRoot.getChildren("subject", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> subjects = dcRoot.getChildren("subject", getDCNamespace());
if (!subjects.isEmpty()) {
foundSomething = true;
dcm.setSubjects(parseSubjects(eList));
dcm.setSubjects(parseSubjects(subjects));
}
eList = dcRoot.getChildren("description", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> descriptions = dcRoot.getChildren("description", getDCNamespace());
if (!descriptions.isEmpty()) {
foundSomething = true;
dcm.setDescriptions(parseElementList(eList));
dcm.setDescriptions(parseElementList(descriptions));
}
eList = dcRoot.getChildren("publisher", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> publishers = dcRoot.getChildren("publisher", getDCNamespace());
if (!publishers.isEmpty()) {
foundSomething = true;
dcm.setPublishers(parseElementList(eList));
dcm.setPublishers(parseElementList(publishers));
}
eList = dcRoot.getChildren("contributor", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> contributors = dcRoot.getChildren("contributor", getDCNamespace());
if (!contributors.isEmpty()) {
foundSomething = true;
dcm.setContributors(parseElementList(eList));
dcm.setContributors(parseElementList(contributors));
}
eList = dcRoot.getChildren("date", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> dates = dcRoot.getChildren("date", getDCNamespace());
if (!dates.isEmpty()) {
foundSomething = true;
dcm.setDates(parseElementListDate(eList, locale));
dcm.setDates(parseElementListDate(dates, locale));
}
eList = dcRoot.getChildren("type", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> types = dcRoot.getChildren("type", getDCNamespace());
if (!types.isEmpty()) {
foundSomething = true;
dcm.setTypes(parseElementList(eList));
dcm.setTypes(parseElementList(types));
}
eList = dcRoot.getChildren("format", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> formats = dcRoot.getChildren("format", getDCNamespace());
if (!formats.isEmpty()) {
foundSomething = true;
dcm.setFormats(parseElementList(eList));
dcm.setFormats(parseElementList(formats));
}
eList = dcRoot.getChildren("identifier", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> identifiers = dcRoot.getChildren("identifier", getDCNamespace());
if (!identifiers.isEmpty()) {
foundSomething = true;
dcm.setIdentifiers(parseElementList(eList));
dcm.setIdentifiers(parseElementList(identifiers));
}
eList = dcRoot.getChildren("source", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> sources = dcRoot.getChildren("source", getDCNamespace());
if (!sources.isEmpty()) {
foundSomething = true;
dcm.setSources(parseElementList(eList));
dcm.setSources(parseElementList(sources));
}
eList = dcRoot.getChildren("language", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> languages = dcRoot.getChildren("language", getDCNamespace());
if (!languages.isEmpty()) {
foundSomething = true;
dcm.setLanguages(parseElementList(eList));
dcm.setLanguages(parseElementList(languages));
}
eList = dcRoot.getChildren("relation", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> relations = dcRoot.getChildren("relation", getDCNamespace());
if (!relations.isEmpty()) {
foundSomething = true;
dcm.setRelations(parseElementList(eList));
dcm.setRelations(parseElementList(relations));
}
eList = dcRoot.getChildren("coverage", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> coverages = dcRoot.getChildren("coverage", getDCNamespace());
if (!coverages.isEmpty()) {
foundSomething = true;
dcm.setCoverages(parseElementList(eList));
dcm.setCoverages(parseElementList(coverages));
}
eList = dcRoot.getChildren("rights", getDCNamespace());
if (!eList.isEmpty()) {
final List<Element> rights = dcRoot.getChildren("rights", getDCNamespace());
if (!rights.isEmpty()) {
foundSomething = true;
dcm.setRightsList(parseElementList(eList));
dcm.setRightsList(parseElementList(rights));
}
if (foundSomething) {
return dcm;
} else {
return null;
}
}
/**
* Utility method to parse a taxonomy from an element.
* <p>
*
*
* @param desc the taxonomy description element.
* @return the string contained in the resource of the element.
*/
protected final String getTaxonomy(final Element desc) {
String d = null;
final Element taxo = desc.getChild("topic", getTaxonomyNamespace());
if (taxo != null) {
final Attribute a = taxo.getAttribute("resource", getRDFNamespace());
if (a != null) {
d = a.getValue();
String taxonomy = null;
final Element topic = desc.getChild("topic", getTaxonomyNamespace());
if (topic != null) {
final Attribute resource = topic.getAttribute("resource", getRDFNamespace());
if (resource != null) {
taxonomy = resource.getValue();
}
}
return d;
return taxonomy;
}
/**
* Utility method to parse a list of subjects out of a list of elements.
* <p>
*
*
* @param eList the element list to parse.
* @return a list of subjects parsed from the elements.
*/
protected final List<DCSubject> parseSubjects(final List<Element> eList) {
final List<DCSubject> subjects = new ArrayList<DCSubject>();
for (final Element element : eList) {
final Element eSubject = element;
final Element eDesc = eSubject.getChild("Description", getRDFNamespace());
if (eDesc != null) {
final String taxonomy = getTaxonomy(eDesc);
final List<Element> eValues = eDesc.getChildren("value", getRDFNamespace());
for (final Element element2 : eValues) {
final Element eValue = element2;
for (final Element eSubject : eList) {
final Element description = eSubject.getChild("Description", getRDFNamespace());
if (description != null) {
final String taxonomy = getTaxonomy(description);
final List<Element> values = description.getChildren("value", getRDFNamespace());
for (final Element value : values) {
final DCSubject subject = new DCSubjectImpl();
subject.setTaxonomyUri(taxonomy);
subject.setValue(eValue.getText());
subject.setValue(value.getText());
subjects.add(subject);
}
} else {
final DCSubject subject = new DCSubjectImpl();
subject.setValue(eSubject.getText());
@ -210,34 +234,31 @@ public class DCModuleParser implements ModuleParser {
/**
* Utility method to parse a list of strings out of a list of elements.
* <p>
*
* @param eList the list of elements to parse.
*
* @param elements the list of elements to parse.
* @return the list of strings
*/
protected final List<String> parseElementList(final List<Element> eList) {
protected final List<String> parseElementList(final List<Element> elements) {
final List<String> values = new ArrayList<String>();
for (final Element element : eList) {
final Element e = element;
values.add(e.getText());
for (final Element element : elements) {
values.add(element.getText());
}
return values;
}
/**
* Utility method to parse a list of dates out of a list of elements.
* <p>
*
* @param eList the list of elements to parse.
*
* @param elements the list of elements to parse.
* @return the list of dates.
*/
protected final List<Date> parseElementListDate(final List<Element> eList, final Locale locale) {
protected final List<Date> parseElementListDate(final List<Element> elements, final Locale locale) {
final List<Date> values = new ArrayList<Date>();
for (final Element element : eList) {
final Element e = element;
values.add(DateParser.parseDate(e.getText(), locale));
for (final Element element : elements) {
values.add(DateParser.parseDate(element.getText(), locale));
}
return values;
}
}

View file

@ -31,44 +31,34 @@ import java.util.TimeZone;
* It uses the JDK java.text.SimpleDateFormat class attemtping the parse using a mask for each one
* of the possible formats.
* <p/>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class DateParser {
private static String[] ADDITIONAL_MASKS;
static {
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
// 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
// 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" };
"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
@ -77,14 +67,18 @@ public class DateParser {
*/
@SuppressWarnings("unused")
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" };
"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" };
static {
ADDITIONAL_MASKS = PropertiesLoader.getPropertiesLoader().getTokenizedProperty("datetime.extra.masks", "|");
}
/**
* Private constructor to avoid DateParser instances creation.
@ -97,12 +91,12 @@ public class DateParser {
* <p/>
* It uses the masks in order until one of them succedes or all fail.
* <p/>
*
*
* @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
* <b>null</b> if it was not possible to parse the the string with any of the masks.
*
*
*/
private static Date parseUsingMask(final String[] masks, String sDate, final Locale locale) {
if (sDate != null) {
@ -145,11 +139,11 @@ public class DateParser {
* <p/>
* Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.
* <p/>
*
*
* @param sDate string to parse for a date.
* @return the Date represented by the given RFC822 string. It returns <b>null</b> if it was not
* possible to parse the given string into a Date.
*
*
*/
public static Date parseRFC822(String sDate, final Locale locale) {
final int utIndex = sDate.indexOf(" UT");
@ -175,16 +169,15 @@ public class DateParser {
* <p/>
* Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.
* <p/>
*
*
* @param sDate string to parse for a date.
* @return the Date represented by the given W3C date-time string. It returns <b>null</b> if it
* was not possible to parse the given string into a Date.
*
*
*/
public static Date parseW3CDateTime(String sDate, final Locale locale) {
// if sDate has time on it, it injects 'GTM' before de TZ displacement
// to
// allow the SimpleDateFormat parser to parse it properly
// if sDate has time on it, it injects 'GTM' before de TZ displacement to allow the
// SimpleDateFormat parser to parse it properly
final int tIndex = sDate.indexOf("T");
if (tIndex > -1) {
if (sDate.endsWith("Z")) {
@ -212,21 +205,21 @@ public class DateParser {
/**
* Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.
* <p>
*
*
* @param sDate string to parse for a date.
* @return the Date represented by the given W3C date-time string. It returns <b>null</b> if it
* was not possible to parse the given string into a Date.
*
*
* */
public static Date parseDate(final String sDate, final Locale locale) {
Date d = parseW3CDateTime(sDate, locale);
if (d == null) {
d = parseRFC822(sDate, locale);
if (d == null && ADDITIONAL_MASKS.length > 0) {
d = parseUsingMask(ADDITIONAL_MASKS, sDate, locale);
Date date = parseW3CDateTime(sDate, locale);
if (date == null) {
date = parseRFC822(sDate, locale);
if (date == null && ADDITIONAL_MASKS.length > 0) {
date = parseUsingMask(ADDITIONAL_MASKS, sDate, locale);
}
}
return d;
return date;
}
/**
@ -234,11 +227,11 @@ public class DateParser {
* <p/>
* Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.
* <p/>
*
*
* @param date Date to parse
* @return the RFC822 represented by the given Date It returns <b>null</b> if it was not
* possible to parse the date.
*
*
*/
public static String formatRFC822(final Date date, final Locale locale) {
final SimpleDateFormat dateFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", locale);
@ -251,11 +244,11 @@ public class DateParser {
* <p/>
* Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.
* <p/>
*
*
* @param date Date to parse
* @return the W3C Date Time represented by the given Date It returns <b>null</b> if it was not
* possible to parse the date.
*
*
*/
public static String formatW3CDateTime(final Date date, final Locale locale) {
final SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", locale);

View file

@ -34,22 +34,22 @@ import com.sun.syndication.io.WireFeedParser;
* Parsers for a specific type must extend this class and register in the parser list. (Right now
* registration is hardcoded in the WireFeedParser constructor).
* <p>
*
*
* @author Alejandro Abdelnur
*
*
*/
public class FeedParsers extends PluginManager<WireFeedParser> {
/**
* WireFeedParser.classes= [className] ...
*
*
*/
public static final String FEED_PARSERS_KEY = "WireFeedParser.classes";
/**
* Creates a parser instance.
* <p>
*
*
*/
public FeedParsers() {
super(FEED_PARSERS_KEY);
@ -62,22 +62,20 @@ public class FeedParsers extends PluginManager<WireFeedParser> {
/**
* Finds the real parser type for the given document feed.
* <p>
*
*
* @param document document feed to find the parser for.
* @return the parser for the given document or <b>null</b> if there is no parser for that
* document.
*
*
*/
public WireFeedParser getParserFor(final Document document) {
final List<WireFeedParser> parsers = getPlugins();
WireFeedParser parser = null;
for (int i = 0; parser == null && i < parsers.size(); i++) {
parser = parsers.get(i);
if (!parser.isMyType(document)) {
parser = null;
for (final WireFeedParser parser : parsers) {
if (parser.isMyType(document)) {
return parser;
}
}
return parser;
return null;
}
@Override

View file

@ -27,9 +27,8 @@ import org.jdom2.Namespace;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.ModuleGenerator;
/**
*/
public class ModuleGenerators extends PluginManager<ModuleGenerator> {
private Set<Namespace> allNamespaces;
public ModuleGenerators(final String propertyKey, final BaseWireFeedGenerator parentGenerator) {
@ -51,8 +50,7 @@ public class ModuleGenerators extends PluginManager<ModuleGenerator> {
public void generateModules(final List<Module> modules, final Element element) {
final Map<String, ModuleGenerator> generators = getPluginMap();
for (int i = 0; i < modules.size(); i++) {
final Module module = modules.get(i);
for (final Module module : modules) {
final String namespaceUri = module.getUri();
final ModuleGenerator generator = generators.get(namespaceUri);
if (generator != null) {
@ -65,11 +63,12 @@ public class ModuleGenerators extends PluginManager<ModuleGenerator> {
if (allNamespaces == null) {
allNamespaces = new HashSet<Namespace>();
final List<String> mUris = getModuleNamespaces();
for (int i = 0; i < mUris.size(); i++) {
final ModuleGenerator mGen = getGenerator(mUris.get(i));
for (final String mUri : mUris) {
final ModuleGenerator mGen = getGenerator(mUri);
allNamespaces.addAll(mGen.getNamespaces());
}
}
return allNamespaces;
}
}

View file

@ -16,13 +16,13 @@
*/
package com.sun.syndication.io.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.jdom2.Element;
import org.jdom2.Namespace;
import com.rometools.utils.Lists;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.ModuleParser;
import com.sun.syndication.io.WireFeedParser;
@ -30,6 +30,7 @@ import com.sun.syndication.io.WireFeedParser;
/**
*/
public class ModuleParsers extends PluginManager<ModuleParser> {
public ModuleParsers(final String propertyKey, final WireFeedParser parentParser) {
super(propertyKey, parentParser, null);
}
@ -46,16 +47,13 @@ public class ModuleParsers extends PluginManager<ModuleParser> {
public List<Module> parseModules(final Element root, final Locale locale) {
final List<ModuleParser> parsers = getPlugins();
List<Module> modules = null;
for (int i = 0; i < parsers.size(); i++) {
final ModuleParser parser = parsers.get(i);
for (final ModuleParser parser : parsers) {
final String namespaceUri = parser.getNamespaceUri();
final Namespace namespace = Namespace.getNamespace(namespaceUri);
if (hasElementsFrom(root, namespace)) {
final Module module = parser.parse(root, locale);
if (module != null) {
if (modules == null) {
modules = new ArrayList<Module>();
}
modules = Lists.createWhenNull(modules);
modules.add(module);
}
}
@ -65,15 +63,14 @@ public class ModuleParsers extends PluginManager<ModuleParser> {
private boolean hasElementsFrom(final Element root, final Namespace namespace) {
boolean hasElements = false;
// boolean hasElements = namespace.equals(root.getNamespace());
if (!hasElements) {
final List<Element> children = root.getChildren();
for (int i = 0; !hasElements && i < children.size(); i++) {
final Element child = children.get(i);
hasElements = namespace.equals(child.getNamespace());
for (final Element child : root.getChildren()) {
final Namespace childNamespace = child.getNamespace();
if (namespace.equals(childNamespace)) {
hasElements = true;
break;
}
}
return hasElements;
}
}

View file

@ -37,16 +37,17 @@ import com.sun.syndication.io.WireFeedParser;
*
*/
public abstract class PluginManager<T> {
private final String[] propertyValues;
private Map<String, T> pluginsMap;
private List<T> pluginsList;
private final List<String> keys;
private final WireFeedParser parentParser;
private final WireFeedGenerator parentGenerator;
private Map<String, T> pluginsMap;
private List<T> pluginsList;
/**
* Creates a PluginManager
* <p>
*
* @param propertyKey property key defining the plugins classes
*
@ -86,25 +87,32 @@ public abstract class PluginManager<T> {
// PRIVATE - LOADER PART
private void loadPlugins() {
final List<T> finalPluginsList = new ArrayList<T>();
pluginsList = new ArrayList<T>();
pluginsMap = new HashMap<String, T>();
String className = null;
try {
final Class<T>[] classes = getClasses();
for (final Class<T> classe : classes) {
className = classe.getName();
final T plugin = classe.newInstance();
for (final Class<T> clazz : classes) {
className = clazz.getName();
final T plugin = clazz.newInstance();
if (plugin instanceof DelegatingModuleParser) {
((DelegatingModuleParser) plugin).setFeedParser(parentParser);
}
if (plugin instanceof DelegatingModuleGenerator) {
((DelegatingModuleGenerator) plugin).setFeedGenerator(parentGenerator);
}
pluginsMap.put(getKey(plugin), plugin);
// to preserve the order of definition in the rome.properties files
pluginsList.add(plugin);
}
final Collection<T> plugins = pluginsMap.values();
@ -143,9 +151,13 @@ public abstract class PluginManager<T> {
*/
@SuppressWarnings("unchecked")
private Class<T>[] getClasses() throws ClassNotFoundException {
final ClassLoader classLoader = ConfigurableClassLoader.INSTANCE.getClassLoader();
final List<Class<T>> classes = new ArrayList<Class<T>>();
final boolean useLoadClass = Boolean.valueOf(System.getProperty("rome.pluginmanager.useloadclass", "false")).booleanValue();
for (final String propertyValue : propertyValues) {
final Class<T> mClass;
if (useLoadClass) {
@ -155,6 +167,7 @@ public abstract class PluginManager<T> {
}
classes.add(mClass);
}
final Class<T>[] array = new Class[classes.size()];
classes.toArray(array);
return array;

View file

@ -17,7 +17,6 @@
package com.sun.syndication.io.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@ -56,44 +55,40 @@ public class RSS090Parser extends BaseWireFeedParser {
@Override
public boolean isMyType(final Document document) {
boolean ok = false;
final Element rssRoot = document.getRootElement();
final Namespace defaultNS = rssRoot.getNamespace();
final List<Namespace> additionalNSs = rssRoot.getAdditionalNamespaces();
ok = defaultNS != null && defaultNS.equals(getRDFNamespace());
if (ok) {
if (additionalNSs == null) {
ok = false;
} else {
ok = false;
for (int i = 0; !ok && i < additionalNSs.size(); i++) {
ok = getRSSNamespace().equals(additionalNSs.get(i));
boolean myType = false;
if (defaultNS != null && defaultNS.equals(getRDFNamespace()) && additionalNSs != null) {
for (final Namespace namespace : additionalNSs) {
if (getRSSNamespace().equals(namespace)) {
myType = true;
break;
}
}
}
return ok;
return myType;
}
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException {
if (validate) {
validateFeed(document);
}
final Element rssRoot = document.getRootElement();
return parseChannel(rssRoot, locale);
}
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 inject our own schema for the feed (they
// don't exist out there)
// to the document, produce an ouput and attempt to parse it again with
// validation turned on.
// otherwise will have to check the document elements by hand.
// TODO here we have to validate the Feed against a schema or whatever not sure how to do it
// one posibility would be to inject our own schema for the feed (they don't exist out
// there) to the document, produce an ouput and attempt to parse it again with validation
// turned on. otherwise will have to check the document elements by hand.
}
/**
@ -147,41 +142,46 @@ public class RSS090Parser extends BaseWireFeedParser {
* @return the parsed Channel bean.
*/
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
final Channel channel = new Channel(getType());
channel.setStyleSheet(getStyleSheet(rssRoot.getDocument()));
Element e = eChannel.getChild("title", getRSSNamespace());
if (e != null) {
channel.setTitle(e.getText());
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
final Element title = eChannel.getChild("title", getRSSNamespace());
if (title != null) {
channel.setTitle(title.getText());
}
e = eChannel.getChild("link", getRSSNamespace());
if (e != null) {
channel.setLink(e.getText());
final Element link = eChannel.getChild("link", getRSSNamespace());
if (link != null) {
channel.setLink(link.getText());
}
e = eChannel.getChild("description", getRSSNamespace());
if (e != null) {
channel.setDescription(e.getText());
final Element description = eChannel.getChild("description", getRSSNamespace());
if (description != null) {
channel.setDescription(description.getText());
}
channel.setImage(parseImage(rssRoot));
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
// channel modules from the root RSS element.
// 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.
final List<Module> allFeedModules = new ArrayList<Module>();
final List<Module> rootModules = parseFeedModules(rssRoot, locale);
final List<Module> channelModules = parseFeedModules(eChannel, locale);
if (rootModules != null) {
allFeedModules.addAll(rootModules);
}
if (channelModules != null) {
allFeedModules.addAll(channelModules);
}
channel.setModules(allFeedModules);
channel.setItems(parseItems(rssRoot, locale));
@ -189,7 +189,9 @@ public class RSS090Parser extends BaseWireFeedParser {
if (!foreignMarkup.isEmpty()) {
channel.setForeignMarkup(foreignMarkup);
}
return channel;
}
/**
@ -232,25 +234,33 @@ public class RSS090Parser extends BaseWireFeedParser {
* @return the parsed image bean.
*/
protected Image parseImage(final Element rssRoot) {
Image image = null;
final Element eImage = getImage(rssRoot);
if (eImage != null) {
image = new Image();
Element e = eImage.getChild("title", getRSSNamespace());
if (e != null) {
image.setTitle(e.getText());
final Element title = eImage.getChild("title", getRSSNamespace());
if (title != null) {
image.setTitle(title.getText());
}
e = eImage.getChild("url", getRSSNamespace());
if (e != null) {
image.setUrl(e.getText());
final Element url = eImage.getChild("url", getRSSNamespace());
if (url != null) {
image.setUrl(url.getText());
}
e = eImage.getChild("link", getRSSNamespace());
if (e != null) {
image.setLink(e.getText());
final Element link = eImage.getChild("link", getRSSNamespace());
if (link != null) {
image.setLink(link.getText());
}
}
return image;
}
/**
@ -265,12 +275,9 @@ public class RSS090Parser extends BaseWireFeedParser {
* @return a list with all the parsed RSSItem beans.
*/
protected List<Item> parseItems(final Element rssRoot, final Locale locale) {
final Collection<Element> eItems = getItems(rssRoot);
final List<Item> items = new ArrayList<Item>();
for (final Element element : eItems) {
final Element eItem = element;
items.add(parseItem(rssRoot, eItem, locale));
for (final Element item : getItems(rssRoot)) {
items.add(parseItem(rssRoot, item, locale));
}
return items;
}
@ -286,29 +293,32 @@ public class RSS090Parser extends BaseWireFeedParser {
* @return the parsed RSSItem bean.
*/
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
final Item item = new Item();
Element e = eItem.getChild("title", getRSSNamespace());
if (e != null) {
item.setTitle(e.getText());
final Element title = eItem.getChild("title", getRSSNamespace());
if (title != null) {
item.setTitle(title.getText());
}
e = eItem.getChild("link", getRSSNamespace());
if (e != null) {
item.setLink(e.getText());
item.setUri(e.getText());
final Element link = eItem.getChild("link", getRSSNamespace());
if (link != null) {
item.setLink(link.getText());
item.setUri(link.getText());
}
item.setModules(parseItemModules(eItem, locale));
final List<Element> 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
// 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<Element> iterator = foreignMarkup.iterator();
while (iterator.hasNext()) {
final Element element = iterator.next();
if (getContentNamespace().equals(element.getNamespace()) && element.getName().equals("encoded")) {
final Namespace eNamespace = element.getNamespace();
final String eName = element.getName();
if (getContentNamespace().equals(eNamespace) && eName.equals("encoded")) {
iterator.remove();
}
}
@ -330,28 +340,38 @@ public class RSS090Parser extends BaseWireFeedParser {
* @return the parsed RSSTextInput bean.
*/
protected TextInput parseTextInput(final Element rssRoot) {
TextInput textInput = null;
final Element eTextInput = getTextInput(rssRoot);
if (eTextInput != null) {
textInput = new TextInput();
Element e = eTextInput.getChild("title", getRSSNamespace());
if (e != null) {
textInput.setTitle(e.getText());
final Element title = eTextInput.getChild("title", getRSSNamespace());
if (title != null) {
textInput.setTitle(title.getText());
}
e = eTextInput.getChild("description", getRSSNamespace());
if (e != null) {
textInput.setDescription(e.getText());
final Element description = eTextInput.getChild("description", getRSSNamespace());
if (description != null) {
textInput.setDescription(description.getText());
}
e = eTextInput.getChild("name", getRSSNamespace());
if (e != null) {
textInput.setName(e.getText());
final Element name = eTextInput.getChild("name", getRSSNamespace());
if (name != null) {
textInput.setName(name.getText());
}
e = eTextInput.getChild("link", getRSSNamespace());
if (e != null) {
textInput.setLink(e.getText());
final Element link = eTextInput.getChild("link", getRSSNamespace());
if (link != null) {
textInput.setLink(link.getText());
}
}
return textInput;
}
}

View file

@ -21,8 +21,6 @@ import org.jdom2.DocType;
import org.jdom2.Document;
import org.jdom2.Element;
/**
*/
public class RSS091NetscapeParser extends RSS091UserlandParser {
public RSS091NetscapeParser() {
@ -39,27 +37,15 @@ public class RSS091NetscapeParser extends RSS091UserlandParser {
@Override
public boolean isMyType(final Document document) {
boolean ok = false;
final Element rssRoot = document.getRootElement();
ok = rssRoot.getName().equals("rss");
if (ok) {
ok = false;
final Attribute version = rssRoot.getAttribute("version");
if (version != null) {
ok = version.getValue().equals(getRSSVersion());
if (ok) {
ok = false;
final DocType docType = document.getDocType();
if (docType != null) {
ok = ELEMENT_NAME.equals(docType.getElementName());
ok = ok && PUBLIC_ID.equals(docType.getPublicID());
ok = ok && SYSTEM_ID.equals(docType.getSystemID());
}
}
}
}
return ok;
final Element rssRoot = document.getRootElement();
final String name = rssRoot.getName();
final Attribute version = rssRoot.getAttribute("version");
final DocType docType = document.getDocType();
return name.equals(ELEMENT_NAME) && version != null && version.getValue().equals(getRSSVersion()) && docType != null
&& ELEMENT_NAME.equals(docType.getElementName()) && PUBLIC_ID.equals(docType.getPublicID()) && SYSTEM_ID.equals(docType.getSystemID());
}
@Override

View file

@ -26,6 +26,7 @@ import org.jdom2.Element;
import org.jdom2.Namespace;
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;
@ -34,11 +35,12 @@ import com.sun.syndication.io.FeedException;
/**
* Feed Generator for RSS 0.91
* <p/>
*
*
* @author Elaine Chien
*
*
*/
public class RSS091UserlandGenerator extends RSS090Generator {
private final String version;
public RSS091UserlandGenerator() {
@ -68,6 +70,7 @@ public class RSS091UserlandGenerator extends RSS090Generator {
@Override
protected void addChannel(final Channel channel, final Element parent) throws FeedException {
super.addChannel(channel, parent);
final Element eChannel = parent.getChild("channel", getFeedNamespace());
@ -75,15 +78,16 @@ public class RSS091UserlandGenerator extends RSS090Generator {
addImage(channel, eChannel);
addTextInput(channel, eChannel);
addItems(channel, eChannel);
}
@Override
protected void checkChannelConstraints(final Element eChannel) throws FeedException {
checkNotNullAndLength(eChannel, "title", 1, 100);
checkNotNullAndLength(eChannel, "description", 1, 500);
checkNotNullAndLength(eChannel, "link", 1, 500);
checkNotNullAndLength(eChannel, "language", 2, 5);
checkLength(eChannel, "rating", 20, 500);
checkLength(eChannel, "copyright", 1, 100);
checkLength(eChannel, "pubDate", 1, 100);
@ -95,10 +99,10 @@ public class RSS091UserlandGenerator extends RSS090Generator {
final Element skipHours = eChannel.getChild("skipHours");
if (skipHours != null) {
final List<Element> hours = skipHours.getChildren();
for (int i = 0; i < hours.size(); i++) {
final Element hour = hours.get(i);
final List<Element> hours = skipHours.getChildren();
for (final Element hour : hours) {
final int value = Integer.parseInt(hour.getText().trim());
if (isHourFormat24()) {
@ -110,15 +114,17 @@ public class RSS091UserlandGenerator extends RSS090Generator {
throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23");
}
}
}
}
}
@Override
protected void checkImageConstraints(final Element eImage) throws FeedException {
checkNotNullAndLength(eImage, "title", 1, 100);
checkNotNullAndLength(eImage, "url", 1, 500);
checkLength(eImage, "link", 1, 500);
checkLength(eImage, "width", 1, 3);
checkLength(eImage, "width", 1, 3);
@ -129,7 +135,6 @@ public class RSS091UserlandGenerator extends RSS090Generator {
protected void checkItemConstraints(final Element eItem) throws FeedException {
checkNotNullAndLength(eItem, "title", 1, 100);
checkNotNullAndLength(eItem, "link", 1, 500);
checkLength(eItem, "description", 1, 500);
}
@ -153,93 +158,80 @@ public class RSS091UserlandGenerator extends RSS090Generator {
root.setAttribute(version);
root.addNamespaceDeclaration(getContentNamespace());
generateModuleNamespaceDefs(root);
return root;
}
protected Element generateSkipDaysElement(final List<String> days) {
final Element skipDaysElement = new Element("skipDays");
for (int i = 0; i < days.size(); i++) {
skipDaysElement.addContent(generateSimpleElement("day", days.get(i).toString()));
for (final String day : days) {
skipDaysElement.addContent(generateSimpleElement("day", day.toString()));
}
return skipDaysElement;
}
protected Element generateSkipHoursElement(final List<Integer> hours) {
final Element skipHoursElement = new Element("skipHours", getFeedNamespace());
for (int i = 0; i < hours.size(); i++) {
skipHoursElement.addContent(generateSimpleElement("hour", hours.get(i).toString()));
for (final Integer hour : hours) {
skipHoursElement.addContent(generateSimpleElement("hour", hour.toString()));
}
return skipHoursElement;
}
@Override
protected void populateChannel(final Channel channel, final Element eChannel) {
super.populateChannel(channel, eChannel);
final String language = channel.getLanguage();
if (language != null) {
eChannel.addContent(generateSimpleElement("language", language));
}
final String rating = channel.getRating();
if (rating != null) {
eChannel.addContent(generateSimpleElement("rating", rating));
}
final String copyright = channel.getCopyright();
if (copyright != null) {
eChannel.addContent(generateSimpleElement("copyright", copyright));
}
final Date pubDate = channel.getPubDate();
if (pubDate != null) {
eChannel.addContent(generateSimpleElement("pubDate", DateParser.formatRFC822(pubDate, Locale.US)));
}
final Date lastBuildDate = channel.getLastBuildDate();
if (lastBuildDate != null) {
eChannel.addContent(generateSimpleElement("lastBuildDate", DateParser.formatRFC822(lastBuildDate, Locale.US)));
}
final String docs = channel.getDocs();
if (docs != null) {
eChannel.addContent(generateSimpleElement("docs", docs));
}
final String managingEditor = channel.getManagingEditor();
if (managingEditor != null) {
eChannel.addContent(generateSimpleElement("managingEditor", managingEditor));
}
final String webMaster = channel.getWebMaster();
if (webMaster != null) {
eChannel.addContent(generateSimpleElement("webMaster", webMaster));
}
final List<Integer> skipHours = channel.getSkipHours();
if (skipHours != null && !skipHours.isEmpty()) {
eChannel.addContent(generateSkipHoursElement(skipHours));
}
final List<String> skipDays = channel.getSkipDays();
if (skipDays != null && !skipDays.isEmpty()) {
eChannel.addContent(generateSkipDaysElement(skipDays));
}
}
@Override
@ -249,41 +241,44 @@ public class RSS091UserlandGenerator extends RSS090Generator {
@Override
protected void populateImage(final Image image, final Element eImage) {
super.populateImage(image, eImage);
final Integer width = image.getWidth();
if (width != null) {
eImage.addContent(generateSimpleElement("width", String.valueOf(width)));
}
final Integer height = image.getHeight();
if (height != null) {
eImage.addContent(generateSimpleElement("height", String.valueOf(height)));
}
final String description = image.getDescription();
if (description != null) {
eImage.addContent(generateSimpleElement("description", description));
}
}
@Override
protected void populateItem(final Item item, final Element eItem, final int index) {
super.populateItem(item, eItem, index);
final Description description = item.getDescription();
if (description != null) {
eItem.addContent(generateSimpleElement("description", description.getValue()));
}
if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) {
final Element elem = new Element("encoded", getContentNamespace());
elem.addContent(item.getContent().getValue());
final Namespace contentNamespace = getContentNamespace();
final Content content = item.getContent();
if (item.getModule(contentNamespace.getURI()) == null && content != null) {
final Element elem = new Element("encoded", contentNamespace);
elem.addContent(content.getValue());
eItem.addContent(elem);
}
}
}

View file

@ -47,17 +47,9 @@ public class RSS091UserlandParser extends RSS090Parser {
@Override
public boolean isMyType(final Document document) {
boolean ok;
final Element rssRoot = document.getRootElement();
ok = rssRoot.getName().equals("rss");
if (ok) {
ok = false;
final Attribute version = rssRoot.getAttribute("version");
if (version != null) {
ok = version.getValue().equals(getRSSVersion());
}
}
return ok;
final Attribute version = rssRoot.getAttribute("version");
return rssRoot.getName().equals("rss") && version != null && version.getValue().equals(getRSSVersion());
}
protected String getRSSVersion() {
@ -82,73 +74,82 @@ public class RSS091UserlandParser extends RSS090Parser {
* It first invokes super.parseChannel and then parses and injects the following properties if
* present: language, pubDate, rating and copyright.
* <p/>
*
*
* @param rssRoot the root element of the RSS document to parse.
* @return the parsed Channel bean.
*/
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
final Channel channel = (Channel) super.parseChannel(rssRoot, locale);
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
Element e = eChannel.getChild("language", getRSSNamespace());
if (e != null) {
channel.setLanguage(e.getText());
final Element language = eChannel.getChild("language", getRSSNamespace());
if (language != null) {
channel.setLanguage(language.getText());
}
e = eChannel.getChild("rating", getRSSNamespace());
if (e != null) {
channel.setRating(e.getText());
final Element atinge = eChannel.getChild("rating", getRSSNamespace());
if (atinge != null) {
channel.setRating(atinge.getText());
}
e = eChannel.getChild("copyright", getRSSNamespace());
if (e != null) {
channel.setCopyright(e.getText());
final Element copyright = eChannel.getChild("copyright", getRSSNamespace());
if (copyright != null) {
channel.setCopyright(copyright.getText());
}
e = eChannel.getChild("pubDate", getRSSNamespace());
if (e != null) {
channel.setPubDate(DateParser.parseDate(e.getText(), locale));
final Element pubDate = eChannel.getChild("pubDate", getRSSNamespace());
if (pubDate != null) {
channel.setPubDate(DateParser.parseDate(pubDate.getText(), locale));
}
e = eChannel.getChild("lastBuildDate", getRSSNamespace());
if (e != null) {
channel.setLastBuildDate(DateParser.parseDate(e.getText(), locale));
final Element lastBuildDate = eChannel.getChild("lastBuildDate", getRSSNamespace());
if (lastBuildDate != null) {
channel.setLastBuildDate(DateParser.parseDate(lastBuildDate.getText(), locale));
}
e = eChannel.getChild("docs", getRSSNamespace());
if (e != null) {
channel.setDocs(e.getText());
final Element docs = eChannel.getChild("docs", getRSSNamespace());
if (docs != null) {
channel.setDocs(docs.getText());
}
e = eChannel.getChild("generator", getRSSNamespace());
if (e != null) {
channel.setGenerator(e.getText());
final Element generator = eChannel.getChild("generator", getRSSNamespace());
if (generator != null) {
channel.setGenerator(generator.getText());
}
e = eChannel.getChild("managingEditor", getRSSNamespace());
if (e != null) {
channel.setManagingEditor(e.getText());
final Element managingEditor = eChannel.getChild("managingEditor", getRSSNamespace());
if (managingEditor != null) {
channel.setManagingEditor(managingEditor.getText());
}
e = eChannel.getChild("webMaster", getRSSNamespace());
if (e != null) {
channel.setWebMaster(e.getText());
final Element webMaster = eChannel.getChild("webMaster", getRSSNamespace());
if (webMaster != null) {
channel.setWebMaster(webMaster.getText());
}
e = eChannel.getChild("skipHours");
if (e != null) {
final Element eSkipHours = eChannel.getChild("skipHours");
if (eSkipHours != null) {
final List<Integer> skipHours = new ArrayList<Integer>();
final List<Element> eHours = e.getChildren("hour", getRSSNamespace());
for (int i = 0; i < eHours.size(); i++) {
final Element eHour = eHours.get(i);
final List<Element> eHours = eSkipHours.getChildren("hour", getRSSNamespace());
for (final Element eHour : eHours) {
skipHours.add(new Integer(eHour.getText().trim()));
}
channel.setSkipHours(skipHours);
}
e = eChannel.getChild("skipDays");
if (e != null) {
final Element eSkipDays = eChannel.getChild("skipDays");
if (eSkipDays != null) {
final List<String> skipDays = new ArrayList<String>();
final List<Element> eDays = e.getChildren("day", getRSSNamespace());
for (int i = 0; i < eDays.size(); i++) {
final Element eDay = eDays.get(i);
final List<Element> eDays = eSkipDays.getChildren("day", getRSSNamespace());
for (final Element eDay : eDays) {
skipDays.add(eDay.getText().trim());
}
channel.setSkipDays(skipDays);
}
return channel;
}
@ -158,35 +159,43 @@ public class RSS091UserlandParser extends RSS090Parser {
* It first invokes super.parseImage and then parses and injects the following properties if
* present: url, link, width, height and description.
* <p/>
*
*
* @param rssRoot the root element of the RSS document to parse for image information.
* @return the parsed RSSImage bean.
*/
@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());
final Element width = eImage.getChild("width", getRSSNamespace());
if (width != null) {
final Integer val = NumberParser.parseInt(width.getText());
if (val != null) {
image.setWidth(val.intValue());
image.setWidth(val);
}
}
e = eImage.getChild("height", getRSSNamespace());
if (e != null) {
final Integer val = NumberParser.parseInt(e.getText());
final Element height = eImage.getChild("height", getRSSNamespace());
if (height != null) {
final Integer val = NumberParser.parseInt(height.getText());
if (val != null) {
image.setHeight(val.intValue());
image.setHeight(val);
}
}
e = eImage.getChild("description", getRSSNamespace());
if (e != null) {
image.setDescription(e.getText());
final Element description = eImage.getChild("description", getRSSNamespace());
if (description != null) {
image.setDescription(description.getText());
}
}
return image;
}
/**
@ -194,13 +203,15 @@ public class RSS091UserlandParser extends RSS090Parser {
*/
@Override
protected List<Element> getItems(final Element rssRoot) {
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
final List<Element> emptyList = Collections.emptyList();
if (eChannel != null) {
return eChannel.getChildren("item", getRSSNamespace());
} else {
return emptyList;
return Collections.emptyList();
}
}
/**
@ -208,12 +219,15 @@ public class RSS091UserlandParser extends RSS090Parser {
*/
@Override
protected Element getImage(final Element rssRoot) {
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
if (eChannel != null) {
return eChannel.getChild("image", getRSSNamespace());
} else {
return null;
}
}
/**
@ -228,13 +242,16 @@ public class RSS091UserlandParser extends RSS090Parser {
*/
@Override
protected Element getTextInput(final Element rssRoot) {
final String elementName = getTextInputLabel();
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
if (eChannel != null) {
return eChannel.getChild(elementName, getRSSNamespace());
} else {
return null;
}
}
/**
@ -243,26 +260,31 @@ public class RSS091UserlandParser extends RSS090Parser {
* It first invokes super.parseItem and then parses and injects the description property if
* present.
* <p/>
*
*
* @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.
*/
@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
final Item item = super.parseItem(rssRoot, eItem, locale);
final Element e = eItem.getChild("description", getRSSNamespace());
if (e != null) {
item.setDescription(parseItemDescription(rssRoot, e));
final Element description = eItem.getChild("description", getRSSNamespace());
if (description != null) {
item.setDescription(parseItemDescription(rssRoot, description));
}
final Element ce = eItem.getChild("encoded", getContentNamespace());
if (ce != null) {
final Element encoded = eItem.getChild("encoded", getContentNamespace());
if (encoded != null) {
final Content content = new Content();
content.setType(Content.HTML);
content.setValue(ce.getText());
content.setValue(encoded.getText());
item.setContent(content);
}
return item;
}
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) {

View file

@ -31,12 +31,10 @@ import com.sun.syndication.io.FeedException;
/**
* Feed Generator for RSS 0.92
* <p/>
*
*
* @author Elaine Chien
*
*
*/
public class RSS092Generator extends RSS091UserlandGenerator {
public RSS092Generator() {
@ -49,37 +47,47 @@ public class RSS092Generator extends RSS091UserlandGenerator {
@Override
protected void populateChannel(final Channel channel, final Element eChannel) {
super.populateChannel(channel, eChannel);
final Cloud cloud = channel.getCloud();
if (cloud != null) {
eChannel.addContent(generateCloud(cloud));
}
}
protected Element generateCloud(final Cloud cloud) {
final Element eCloud = new Element("cloud", getFeedNamespace());
if (cloud.getDomain() != null) {
eCloud.setAttribute(new Attribute("domain", cloud.getDomain()));
final String domain = cloud.getDomain();
if (domain != null) {
eCloud.setAttribute(new Attribute("domain", domain));
}
if (cloud.getPort() != 0) {
eCloud.setAttribute(new Attribute("port", String.valueOf(cloud.getPort())));
final int port = cloud.getPort();
if (port != 0) {
eCloud.setAttribute(new Attribute("port", String.valueOf(port)));
}
if (cloud.getPath() != null) {
eCloud.setAttribute(new Attribute("path", cloud.getPath()));
final String path = cloud.getPath();
if (path != null) {
eCloud.setAttribute(new Attribute("path", path));
}
if (cloud.getRegisterProcedure() != null) {
eCloud.setAttribute(new Attribute("registerProcedure", cloud.getRegisterProcedure()));
final String registerProcedure = cloud.getRegisterProcedure();
if (registerProcedure != null) {
eCloud.setAttribute(new Attribute("registerProcedure", registerProcedure));
}
if (cloud.getProtocol() != null) {
eCloud.setAttribute(new Attribute("protocol", cloud.getProtocol()));
final String protocol = cloud.getProtocol();
if (protocol != null) {
eCloud.setAttribute(new Attribute("protocol", protocol));
}
return eCloud;
}
// Another one to thanks DW for
@ -93,6 +101,7 @@ public class RSS092Generator extends RSS091UserlandGenerator {
@Override
protected void populateItem(final Item item, final Element eItem, final int index) {
super.populateItem(item, eItem, index);
final Source source = item.getSource();
@ -106,40 +115,59 @@ public class RSS092Generator extends RSS091UserlandGenerator {
}
final List<Category> categories = item.getCategories();
for (int i = 0; i < categories.size(); i++) {
eItem.addContent(generateCategoryElement(categories.get(i)));
for (final Category category : categories) {
eItem.addContent(generateCategoryElement(category));
}
}
protected Element generateSourceElement(final Source source) {
final Element sourceElement = new Element("source", getFeedNamespace());
if (source.getUrl() != null) {
sourceElement.setAttribute(new Attribute("url", source.getUrl()));
final String url = source.getUrl();
if (url != null) {
sourceElement.setAttribute(new Attribute("url", url));
}
sourceElement.addContent(source.getValue());
return sourceElement;
}
protected Element generateEnclosure(final Enclosure enclosure) {
final Element enclosureElement = new Element("enclosure", getFeedNamespace());
if (enclosure.getUrl() != null) {
enclosureElement.setAttribute("url", enclosure.getUrl());
final String url = enclosure.getUrl();
if (url != null) {
enclosureElement.setAttribute("url", url);
}
if (enclosure.getLength() != 0) {
enclosureElement.setAttribute("length", String.valueOf(enclosure.getLength()));
final long length = enclosure.getLength();
if (length != 0) {
enclosureElement.setAttribute("length", String.valueOf(length));
}
if (enclosure.getType() != null) {
enclosureElement.setAttribute("type", enclosure.getType());
final String type = enclosure.getType();
if (type != null) {
enclosureElement.setAttribute("type", type);
}
return enclosureElement;
}
protected Element generateCategoryElement(final Category category) {
final Element categoryElement = new Element("category", getFeedNamespace());
if (category.getDomain() != null) {
categoryElement.setAttribute("domain", category.getDomain());
final String domain = category.getDomain();
if (domain != null) {
categoryElement.setAttribute("domain", domain);
}
categoryElement.addContent(category.getValue());
return categoryElement;
}

View file

@ -56,41 +56,47 @@ public class RSS092Parser extends RSS091UserlandParser {
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
final Channel channel = (Channel) super.parseChannel(rssRoot, locale);
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);
final String domain = eCloud.getAttributeValue("domain");
if (domain != null) {
cloud.setDomain(domain);
}
att = eCloud.getAttributeValue("port");// getRSSNamespace()); DONT
// KNOW WHY DOESN'T WORK
if (att != null) {
cloud.setPort(Integer.parseInt(att.trim()));
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String port = eCloud.getAttributeValue("port");
if (port != null) {
cloud.setPort(Integer.parseInt(port.trim()));
}
att = eCloud.getAttributeValue("path");// getRSSNamespace()); DONT
// KNOW WHY DOESN'T WORK
if (att != null) {
cloud.setPath(att);
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String path = eCloud.getAttributeValue("path");
if (path != null) {
cloud.setPath(path);
}
att = eCloud.getAttributeValue("registerProcedure");// getRSSNamespace());
// DONT KNOW WHY
// DOESN'T WORK
if (att != null) {
cloud.setRegisterProcedure(att);
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String registerProcedure = eCloud.getAttributeValue("registerProcedure");
if (registerProcedure != null) {
cloud.setRegisterProcedure(registerProcedure);
}
att = eCloud.getAttributeValue("protocol");// getRSSNamespace());
// DONT KNOW WHY DOESN'T
// WORK
if (att != null) {
cloud.setProtocol(att);
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String protocol = eCloud.getAttributeValue("protocol");
if (protocol != null) {
cloud.setProtocol(protocol);
}
channel.setCloud(cloud);
}
return channel;
}
@ -99,76 +105,83 @@ public class RSS092Parser extends RSS091UserlandParser {
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
final Item item = super.parseItem(rssRoot, eItem, locale);
Element e = eItem.getChild("source", getRSSNamespace());
if (e != null) {
final Element eSource = eItem.getChild("source", getRSSNamespace());
if (eSource != null) {
final Source source = new Source();
final String url = e.getAttributeValue("url");// getRSSNamespace());
// DONT
// KNOW WHY DOESN'T WORK
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String url = eSource.getAttributeValue("url");
source.setUrl(url);
source.setValue(e.getText());
source.setValue(eSource.getText());
item.setSource(source);
}
// 0.92 allows one enclosure occurrence, 0.93 multiple
// just saving to write some code.
final List<Element> eEnclosures = eItem.getChildren("enclosure");// getRSSNamespace());
// DONT KNOW
// WHY
// DOESN'T
// WORK
// 0.92 allows one enclosure occurrence, 0.93 multiple just saving to write some code.
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final List<Element> eEnclosures = eItem.getChildren("enclosure");
if (!eEnclosures.isEmpty()) {
final List<Enclosure> enclosures = new ArrayList<Enclosure>();
for (int i = 0; i < eEnclosures.size(); i++) {
e = eEnclosures.get(i);
for (final Element eEnclosure : eEnclosures) {
final Enclosure enclosure = new Enclosure();
String att = e.getAttributeValue("url");// getRSSNamespace());
// DONT KNOW WHY DOESN'T
// WORK
if (att != null) {
enclosure.setUrl(att);
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String url = eEnclosure.getAttributeValue("url");
if (url != null) {
enclosure.setUrl(url);
}
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) {
enclosure.setType(att);
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String length = eEnclosure.getAttributeValue("length");
enclosure.setLength(NumberParser.parseLong(length, 0L));
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String type = eEnclosure.getAttributeValue("type");
if (type != null) {
enclosure.setType(type);
}
enclosures.add(enclosure);
}
item.setEnclosures(enclosures);
}
final List<Element> eCats = eItem.getChildren("category");// getRSSNamespace());
// DONT KNOW WHY
// DOESN'T WORK
item.setCategories(parseCategories(eCats));
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final List<Element> categories = eItem.getChildren("category");
item.setCategories(parseCategories(categories));
return item;
}
protected List<Category> parseCategories(final List<Element> eCats) {
List<Category> cats = null;
if (!eCats.isEmpty()) {
cats = new ArrayList<Category>();
for (int i = 0; i < eCats.size(); i++) {
for (final Element eCat : eCats) {
final Category cat = new Category();
final Element e = eCats.get(i);
final String att = e.getAttributeValue("domain");// getRSSNamespace());
// DONT KNOW WHY
// DOESN'T WORK
if (att != null) {
cat.setDomain(att);
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String domain = eCat.getAttributeValue("domain");
if (domain != null) {
cat.setDomain(domain);
}
cat.setValue(e.getText());
cat.setValue(eCat.getText());
cats.add(cat);
}
}
return cats;
}
@Override

View file

@ -41,23 +41,29 @@ public class RSS093Parser extends RSS092Parser {
@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
final Item item = super.parseItem(rssRoot, eItem, locale);
Element e = eItem.getChild("pubDate", getRSSNamespace());
if (e != null) {
item.setPubDate(DateParser.parseDate(e.getText(), locale));
final Element pubDate = eItem.getChild("pubDate", getRSSNamespace());
if (pubDate != null) {
item.setPubDate(DateParser.parseDate(pubDate.getText(), locale));
}
e = eItem.getChild("expirationDate", getRSSNamespace());
if (e != null) {
item.setExpirationDate(DateParser.parseDate(e.getText(), locale));
final Element expirationDate = eItem.getChild("expirationDate", getRSSNamespace());
if (expirationDate != null) {
item.setExpirationDate(DateParser.parseDate(expirationDate.getText(), locale));
}
e = eItem.getChild("description", getRSSNamespace());
if (e != null) {
final String type = e.getAttributeValue("type");
final Element description = eItem.getChild("description", getRSSNamespace());
if (description != null) {
final String type = description.getAttributeValue("type");
if (type != null) {
item.getDescription().setType(type);
}
}
return item;
}
}

View file

@ -26,8 +26,6 @@ import com.sun.syndication.feed.rss.Channel;
import com.sun.syndication.feed.rss.Guid;
import com.sun.syndication.feed.rss.Item;
/**
*/
public class RSS094Parser extends RSS093Parser {
public RSS094Parser() {
@ -45,22 +43,19 @@ public class RSS094Parser extends RSS093Parser {
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
final Channel channel = (Channel) super.parseChannel(rssRoot, locale);
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
final List<Element> eCats = eChannel.getChildren("category", getRSSNamespace());
channel.setCategories(parseCategories(eCats));
final List<Element> categories = eChannel.getChildren("category", getRSSNamespace());
channel.setCategories(parseCategories(categories));
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
}
final Element ttl = eChannel.getChild("ttl", getRSSNamespace());
if (ttl != null && ttl.getText() != null) {
final Integer ttlValue = NumberParser.parseInt(ttl.getText());
if (ttlValue != null) {
channel.setTtl(ttlValue.intValue());
channel.setTtl(ttlValue);
}
}
@ -69,33 +64,40 @@ public class RSS094Parser extends RSS093Parser {
@Override
public Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
final Item item = super.parseItem(rssRoot, eItem, locale);
item.setExpirationDate(null);
Element e = eItem.getChild("author", getRSSNamespace());
if (e != null) {
item.setAuthor(e.getText());
final Element author = eItem.getChild("author", getRSSNamespace());
if (author != null) {
item.setAuthor(author.getText());
}
e = eItem.getChild("guid", getRSSNamespace());
if (e != null) {
final Element eGuid = eItem.getChild("guid", getRSSNamespace());
if (eGuid != null) {
final Guid guid = new Guid();
final String att = e.getAttributeValue("isPermaLink");// getRSSNamespace());
// DONT KNOW WHY
// DOESN'T WORK
// getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
final String att = eGuid.getAttributeValue("isPermaLink");
if (att != null) {
guid.setPermaLink(att.equalsIgnoreCase("true"));
}
guid.setValue(e.getText());
guid.setValue(eGuid.getText());
item.setGuid(guid);
}
e = eItem.getChild("comments", getRSSNamespace());
if (e != null) {
item.setComments(e.getText());
final Element comments = eItem.getChild("comments", getRSSNamespace());
if (comments != null) {
item.setComments(comments.getText());
}
return item;
}
}

View file

@ -29,9 +29,9 @@ import com.sun.syndication.io.FeedException;
/**
* Feed Generator for RSS 1.0
* <p/>
*
*
* @author Elaine Chien
*
*
*/
public class RSS10Generator extends RSS090Generator {
@ -54,22 +54,25 @@ public class RSS10Generator extends RSS090Generator {
@Override
protected void populateChannel(final Channel channel, final Element eChannel) {
super.populateChannel(channel, eChannel);
if (channel.getUri() != null) {
eChannel.setAttribute("about", channel.getUri(), getRDFNamespace());
final String channelUri = channel.getUri();
if (channelUri != null) {
eChannel.setAttribute("about", channelUri, getRDFNamespace());
}
final List<Item> items = channel.getItems();
if (!items.isEmpty()) {
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());
for (final Item item : items) {
final Element lis = new Element("li", getRDFNamespace());
final String uri = item.getUri();
if (uri != null) {
eLi.setAttribute("resource", uri, getRDFNamespace());
lis.setAttribute("resource", uri, getRDFNamespace());
}
eSeq.addContent(eLi);
eSeq.addContent(lis);
}
eItems.addContent(eSeq);
eChannel.addContent(eItems);
@ -78,10 +81,11 @@ public class RSS10Generator extends RSS090Generator {
@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) {
@ -92,11 +96,13 @@ public class RSS10Generator extends RSS090Generator {
if (description != null) {
eItem.addContent(generateSimpleElement("description", description.getValue()));
}
if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) {
final Element elem = new Element("encoded", getContentNamespace());
elem.addContent(item.getContent().getValue());
eItem.addContent(elem);
}
}
@Override

View file

@ -49,33 +49,21 @@ public class RSS10Parser extends RSS090Parser {
* It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") namespace being defined in
* the root element and for the RSS 1.0 ("http://purl.org/rss/1.0/") namespace in the channel
* element.
*
*
* @param document document to check if it can be parsed with this parser implementation.
* @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
*/
@Override
public boolean isMyType(final Document document) {
boolean ok = false;
final Element rssRoot = document.getRootElement();
final Namespace defaultNS = rssRoot.getNamespace();
ok = defaultNS != null && defaultNS.equals(getRDFNamespace());
if (ok) {
// now also test if the channel element exists with the right
// namespace
final Element channel = rssRoot.getChild("channel", getRSSNamespace());
if (channel == null) {
ok = false;
}
}
return ok;
return defaultNS != null && defaultNS.equals(getRDFNamespace()) && rssRoot.getChild("channel", getRSSNamespace()) != null;
}
/**
* Returns the namespace used by RSS elements in document of the RSS 1.0
* <P>
*
*
* @return returns "http://purl.org/rss/1.0/".
*/
@Override
@ -89,29 +77,32 @@ public class RSS10Parser extends RSS090Parser {
* It first invokes super.parseItem and then parses and injects the description property if
* present.
* <p/>
*
*
* @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.
*/
@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {
final Item item = super.parseItem(rssRoot, eItem, locale);
final Element e = eItem.getChild("description", getRSSNamespace());
if (e != null) {
item.setDescription(parseItemDescription(rssRoot, e));
final Element description = eItem.getChild("description", getRSSNamespace());
if (description != null) {
item.setDescription(parseItemDescription(rssRoot, description));
}
final Element ce = eItem.getChild("encoded", getContentNamespace());
if (ce != null) {
final Element encoded = eItem.getChild("encoded", getContentNamespace());
if (encoded != null) {
final Content content = new Content();
content.setType(Content.HTML);
content.setValue(ce.getText());
content.setValue(encoded.getText());
item.setContent(content);
}
final String uri = eItem.getAttributeValue("about", getRDFNamespace());
if (uri != null) {
item.setUri(uri);
final String about = eItem.getAttributeValue("about", getRDFNamespace());
if (about != null) {
item.setUri(about);
}
return item;
@ -119,6 +110,7 @@ public class RSS10Parser extends RSS090Parser {
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
final Channel channel = (Channel) super.parseChannel(rssRoot, locale);
final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

View file

@ -28,11 +28,10 @@ import com.sun.syndication.feed.rss.Item;
/**
* Feed Generator for RSS 2.0
* <p/>
*
*
* @author Elaine Chien
*
*
*/
public class RSS20Generator extends RSS094Generator {
public RSS20Generator() {
@ -45,6 +44,7 @@ public class RSS20Generator extends RSS094Generator {
@Override
protected void populateChannel(final Channel channel, final Element eChannel) {
super.populateChannel(channel, eChannel);
final String generator = channel.getGenerator();
@ -58,19 +58,20 @@ public class RSS20Generator extends RSS094Generator {
}
final List<Category> categories = channel.getCategories();
for (int i = 0; i < categories.size(); i++) {
eChannel.addContent(generateCategoryElement(categories.get(i)));
for (final Category category : categories) {
eChannel.addContent(generateCategoryElement(category));
}
}
@Override
public void populateItem(final Item item, final Element eItem, final int index) {
super.populateItem(item, eItem, index);
final Element eDescription = eItem.getChild("description", getFeedNamespace());
if (eDescription != null) {
eDescription.removeAttribute("type");
final Element description = eItem.getChild("description", getFeedNamespace());
if (description != null) {
description.removeAttribute("type");
}
final String author = item.getAuthor();

View file

@ -22,8 +22,6 @@ import org.jdom2.Element;
import com.sun.syndication.feed.rss.Description;
/**
*/
public class RSS20Parser extends RSS094Parser {
public RSS20Parser() {
@ -52,19 +50,11 @@ public class RSS20Parser extends RSS094Parser {
@Override
public boolean isMyType(final Document document) {
boolean ok;
final Element rssRoot = document.getRootElement();
ok = rssRoot.getName().equals("rss");
if (ok) {
ok = false;
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());
}
}
return ok;
final Attribute version = rssRoot.getAttribute("version");
// 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.
return rssRoot.getName().equals("rss") && version != null && version.getValue().startsWith(getRSSVersion());
}
}

View file

@ -26,16 +26,17 @@ 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
*
*
*/
public class RSS20wNSParser extends RSS20Parser {
private static String RSS20_URI = "http://backend.userland.com/rss2";
public RSS20wNSParser() {
@ -50,11 +51,7 @@ public class RSS20wNSParser extends RSS20Parser {
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;
return defaultNS != null && defaultNS.equals(getRSSNamespace()) && super.isMyType(document);
}
@Override
@ -65,7 +62,7 @@ public class RSS20wNSParser extends RSS20Parser {
/**
* After we parse the feed we put "rss_2.0" in it (so converters and generators work) this
* parser is a phantom.
*
*
*/
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

View file

@ -17,6 +17,7 @@
package com.sun.syndication.io.impl;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
@ -31,11 +32,10 @@ import com.sun.syndication.io.ModuleGenerator;
/**
* Feed Generator for SY ModuleImpl
* <p/>
*
*
* @author Elaine Chien
*
*
*/
public class SyModuleGenerator implements ModuleGenerator {
private static final String SY_URI = "http://purl.org/rss/1.0/modules/syndication/";
@ -60,7 +60,7 @@ public class SyModuleGenerator implements ModuleGenerator {
* 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).
* <p/>
*
*
* @return a set with all the URIs (JDOM Namespace elements) this module generator uses.
*/
@Override
@ -73,9 +73,10 @@ public class SyModuleGenerator implements ModuleGenerator {
final SyModule syModule = (SyModule) module;
if (syModule.getUpdatePeriod() != null) {
final String updatePeriod = syModule.getUpdatePeriod();
if (updatePeriod != null) {
final Element updatePeriodElement = new Element("updatePeriod", SY_NS);
updatePeriodElement.addContent(syModule.getUpdatePeriod());
updatePeriodElement.addContent(updatePeriod);
element.addContent(updatePeriodElement);
}
@ -83,10 +84,13 @@ public class SyModuleGenerator implements ModuleGenerator {
updateFrequencyElement.addContent(String.valueOf(syModule.getUpdateFrequency()));
element.addContent(updateFrequencyElement);
if (syModule.getUpdateBase() != null) {
final Date updateBase = syModule.getUpdateBase();
if (updateBase != null) {
final Element updateBaseElement = new Element("updateBase", SY_NS);
updateBaseElement.addContent(DateParser.formatW3CDateTime(syModule.getUpdateBase(), Locale.US));
updateBaseElement.addContent(DateParser.formatW3CDateTime(updateBase, Locale.US));
element.addContent(updateBaseElement);
}
}
}

View file

@ -26,9 +26,8 @@ import com.sun.syndication.feed.module.SyModule;
import com.sun.syndication.feed.module.SyModuleImpl;
import com.sun.syndication.io.ModuleParser;
/**
*/
public class SyModuleParser implements ModuleParser {
@Override
public String getNamespaceUri() {
return SyModule.URI;
@ -40,29 +39,35 @@ public class SyModuleParser implements ModuleParser {
@Override
public Module parse(final Element syndRoot, final Locale locale) {
boolean foundSomething = false;
final SyModule sm = new SyModuleImpl();
Element e = syndRoot.getChild("updatePeriod", getDCNamespace());
if (e != null) {
final Element updatePeriod = syndRoot.getChild("updatePeriod", getDCNamespace());
if (updatePeriod != null) {
foundSomething = true;
sm.setUpdatePeriod(e.getText());
sm.setUpdatePeriod(updatePeriod.getText());
}
e = syndRoot.getChild("updateFrequency", getDCNamespace());
if (e != null) {
final Element updateFrequency = syndRoot.getChild("updateFrequency", getDCNamespace());
if (updateFrequency != null) {
foundSomething = true;
sm.setUpdateFrequency(Integer.parseInt(e.getText().trim()));
sm.setUpdateFrequency(Integer.parseInt(updateFrequency.getText().trim()));
}
e = syndRoot.getChild("updateBase", getDCNamespace());
if (e != null) {
final Element updateBase = syndRoot.getChild("updateBase", getDCNamespace());
if (updateBase != null) {
foundSomething = true;
sm.setUpdateBase(DateParser.parseDate(e.getText(), locale));
sm.setUpdateBase(DateParser.parseDate(updateBase.getText(), locale));
}
if (foundSomething) {
return sm;
} else {
return null;
}
}
}