added locale to parsers to allow parsing of date strings in different

locales (fixes #22)
This commit is contained in:
Martin Kurz 2013-10-13 16:13:34 +02:00
parent c42306943a
commit 0a824b70a7
37 changed files with 176 additions and 123 deletions

View file

@ -26,6 +26,7 @@ import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -56,7 +57,7 @@ public class CustomTagParser implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final CustomTags module = new CustomTagsImpl(); final CustomTags module = new CustomTagsImpl();
final ArrayList tags = new ArrayList(); final ArrayList tags = new ArrayList();
final List elements = element.getChildren(); final List elements = element.getChildren();

View file

@ -50,6 +50,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -109,7 +110,7 @@ public class GoogleBaseParser implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final HashMap tag2pd = new HashMap(); final HashMap tag2pd = new HashMap();
final GoogleBaseImpl module = new GoogleBaseImpl(); final GoogleBaseImpl module = new GoogleBaseImpl();

View file

@ -43,6 +43,7 @@ package org.rometools.feed.module.cc.io;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
@ -68,7 +69,7 @@ public class ModuleParserRSS1 implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final CreativeCommonsImpl module = new CreativeCommonsImpl(); final CreativeCommonsImpl module = new CreativeCommonsImpl();
{ {
// Parsing Channel level. // Parsing Channel level.

View file

@ -43,6 +43,7 @@ package org.rometools.feed.module.cc.io;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
@ -66,7 +67,7 @@ public class ModuleParserRSS2 implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final CreativeCommonsImpl module = new CreativeCommonsImpl(); final CreativeCommonsImpl module = new CreativeCommonsImpl();
// Do channel global // Do channel global
{ {

View file

@ -45,6 +45,7 @@ package org.rometools.feed.module.content.io;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Attribute; import org.jdom2.Attribute;
import org.jdom2.Element; import org.jdom2.Element;
@ -72,7 +73,7 @@ public class ContentModuleParser implements com.sun.syndication.io.ModuleParser
} }
@Override @Override
public com.sun.syndication.feed.module.Module parse(final org.jdom2.Element element) { public com.sun.syndication.feed.module.Module parse(final Element element, final Locale locale) {
boolean foundSomething = false; boolean foundSomething = false;
final ContentModule cm = new ContentModuleImpl(); final ContentModule cm = new ContentModuleImpl();
final List encodeds = element.getChildren("encoded", CONTENT_NS); final List encodeds = element.getChildren("encoded", CONTENT_NS);

View file

@ -16,6 +16,8 @@
*/ */
package org.rometools.feed.module.feedburner.io; package org.rometools.feed.module.feedburner.io;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
import org.rometools.feed.module.feedburner.FeedBurner; import org.rometools.feed.module.feedburner.FeedBurner;
@ -40,7 +42,7 @@ public class FeedBurnerModuleParser implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final FeedBurnerImpl fbi = new FeedBurnerImpl(); final FeedBurnerImpl fbi = new FeedBurnerImpl();
boolean returnObj = false; boolean returnObj = false;
Element tag = element.getChild("awareness", FeedBurnerModuleParser.NS); Element tag = element.getChild("awareness", FeedBurnerModuleParser.NS);

View file

@ -18,6 +18,7 @@ package org.rometools.feed.module.georss;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.rometools.feed.module.georss.geometries.Envelope; import org.rometools.feed.module.georss.geometries.Envelope;
@ -56,7 +57,7 @@ public class GMLParser implements ModuleParser {
* @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element) * @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element)
*/ */
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseGML(element); final Module geoRssModule = parseGML(element);
return geoRssModule; return geoRssModule;
} }

View file

@ -16,6 +16,8 @@
*/ */
package org.rometools.feed.module.georss; package org.rometools.feed.module.georss;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.rometools.feed.module.georss.geometries.Envelope; import org.rometools.feed.module.georss.geometries.Envelope;
import org.rometools.feed.module.georss.geometries.LineString; import org.rometools.feed.module.georss.geometries.LineString;
@ -63,7 +65,7 @@ public class SimpleParser implements ModuleParser {
* @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element) * @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element)
*/ */
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseSimple(element); final Module geoRssModule = parseSimple(element);
return geoRssModule; return geoRssModule;
} }

View file

@ -16,6 +16,8 @@
*/ */
package org.rometools.feed.module.georss; package org.rometools.feed.module.georss;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.rometools.feed.module.georss.geometries.Point; import org.rometools.feed.module.georss.geometries.Point;
import org.rometools.feed.module.georss.geometries.Position; import org.rometools.feed.module.georss.geometries.Position;
@ -73,7 +75,7 @@ public class W3CGeoParser implements ModuleParser {
* @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element) * @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element)
*/ */
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseW3C(element); final Module geoRssModule = parseW3C(element);
return geoRssModule; return geoRssModule;
} }

View file

@ -44,6 +44,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -81,7 +82,7 @@ public class ITunesParser implements ModuleParser {
} }
@Override @Override
public com.sun.syndication.feed.module.Module parse(final org.jdom2.Element element) { public com.sun.syndication.feed.module.Module parse(final Element element, final Locale locale) {
AbstractITunesObject module = null; AbstractITunesObject module = null;
if (element.getName().equals("channel")) { if (element.getName().equals("channel")) {

View file

@ -24,6 +24,7 @@ package org.rometools.feed.module.mediarss.io;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -81,7 +82,7 @@ public class MediaModuleParser implements ModuleParser {
* @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element) * @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element)
*/ */
@Override @Override
public Module parse(final Element mmRoot) { public Module parse(final Element mmRoot, final Locale locale) {
MediaModuleImpl mod = null; MediaModuleImpl mod = null;
if (mmRoot.getName().equals("channel") || mmRoot.getName().equals("feed")) { if (mmRoot.getName().equals("channel") || mmRoot.getName().equals("feed")) {

View file

@ -22,6 +22,7 @@
package org.rometools.feed.module.mediarss.io; package org.rometools.feed.module.mediarss.io;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Document; import org.jdom2.Document;
import org.jdom2.Element; import org.jdom2.Element;
@ -85,8 +86,8 @@ public class RSS20YahooParser extends RSS20Parser {
* *
*/ */
@Override @Override
protected WireFeed parseChannel(final Element rssRoot) { protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
final WireFeed wFeed = super.parseChannel(rssRoot); final WireFeed wFeed = super.parseChannel(rssRoot, locale);
wFeed.setFeedType("rss_2.0"); wFeed.setFeedType("rss_2.0");
return wFeed; return wFeed;

View file

@ -20,6 +20,7 @@ import java.net.URL;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Attribute; import org.jdom2.Attribute;
import org.jdom2.Element; import org.jdom2.Element;
@ -45,7 +46,7 @@ public class OpenSearchModuleParser implements ModuleParser {
} }
@Override @Override
public Module parse(final Element dcRoot) { public Module parse(final Element dcRoot, final Locale locale) {
final URL baseURI = findBaseURI(dcRoot); final URL baseURI = findBaseURI(dcRoot);

View file

@ -46,6 +46,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jdom2.Element; import org.jdom2.Element;
@ -76,7 +77,7 @@ public class Parser implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
if (element.getName().equals("channel") || element.getName().equals("feed")) { if (element.getName().equals("channel") || element.getName().equals("feed")) {
return new PhotocastModuleImpl(); return new PhotocastModuleImpl();
} else if (element.getChild("metadata", Parser.NS) == null && element.getChild("image", Parser.NS) == null) { } else if (element.getChild("metadata", Parser.NS) == null && element.getChild("image", Parser.NS) == null) {

View file

@ -40,6 +40,7 @@
package org.rometools.feed.module.slash.io; package org.rometools.feed.module.slash.io;
import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.jdom2.Element; import org.jdom2.Element;
@ -71,7 +72,7 @@ public class SlashModuleParser implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final SlashImpl si = new SlashImpl(); final SlashImpl si = new SlashImpl();
Element tag = element.getChild("hit_parade", SlashModuleParser.NS); Element tag = element.getChild("hit_parade", SlashModuleParser.NS);
if (tag != null) { if (tag != null) {

View file

@ -21,6 +21,7 @@ import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
@ -63,13 +64,12 @@ public class ItemParser implements com.sun.syndication.io.ModuleParser {
* @return a module instance, <b>null</b> if the element did not have module information. * @return a module instance, <b>null</b> if the element did not have module information.
*/ */
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final SleEntryImpl sle = new SleEntryImpl(); final SleEntryImpl sle = new SleEntryImpl();
ArrayList values = new ArrayList(); ArrayList<EntryValue> values = new ArrayList<EntryValue>();
final List groups = element.getChildren("group", ModuleParser.TEMP); final List<Element> groups = element.getChildren("group", ModuleParser.TEMP);
for (int i = 0; groups != null && i < groups.size(); i++) { for (final Element group : groups) {
final Element group = (Element) groups.get(i);
final StringValue value = new StringValue(); final StringValue value = new StringValue();
value.setElement(group.getAttributeValue("element")); value.setElement(group.getAttributeValue("element"));
value.setLabel(group.getAttributeValue("label")); value.setLabel(group.getAttributeValue("label"));
@ -84,12 +84,11 @@ public class ItemParser implements com.sun.syndication.io.ModuleParser {
} }
sle.setGroupValues((EntryValue[]) values.toArray(new EntryValue[values.size()])); sle.setGroupValues((EntryValue[]) values.toArray(new EntryValue[values.size()]));
values = values.size() == 0 ? values : new ArrayList(); values = values.size() == 0 ? values : new ArrayList<EntryValue>();
final List sorts = new ArrayList(element.getChildren("sort", ModuleParser.TEMP)); final List<Element> sorts = new ArrayList<Element>(element.getChildren("sort", ModuleParser.TEMP));
// System.out.println("]]] sorts on element"+sorts.size()); // System.out.println("]]] sorts on element"+sorts.size());
for (int i = 0; sorts != null && i < sorts.size(); i++) { for (final Element sort : sorts) {
final Element sort = (Element) sorts.get(i);
final String dataType = sort.getAttributeValue("data-type"); final String dataType = sort.getAttributeValue("data-type");
// System.out.println("Doing datatype "+dataType +" :: "+sorts.size()); // System.out.println("Doing datatype "+dataType +" :: "+sorts.size());
if (dataType == null || dataType.equals(Sort.TEXT_TYPE)) { if (dataType == null || dataType.equals(Sort.TEXT_TYPE)) {
@ -118,8 +117,10 @@ public class ItemParser implements com.sun.syndication.io.ModuleParser {
Date dateValue = null; Date dateValue = null;
try { try {
dateValue = DateParser.parseRFC822(sort.getAttributeValue("value")); dateValue = DateParser.parseRFC822(sort.getAttributeValue("value"), locale);
dateValue = dateValue == null ? DateParser.parseW3CDateTime(sort.getAttributeValue("value")) : dateValue; if (dateValue == null) {
dateValue = DateParser.parseW3CDateTime(sort.getAttributeValue("value"), locale);
}
} catch (final Exception e) { } catch (final Exception e) {
; // ignore parse exceptions ; // ignore parse exceptions
} }

View file

@ -19,6 +19,7 @@ package org.rometools.feed.module.sle.io;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
@ -61,7 +62,7 @@ public class ModuleParser implements com.sun.syndication.io.ModuleParser {
* @return a module instance, <b>null</b> if the element did not have module information. * @return a module instance, <b>null</b> if the element did not have module information.
*/ */
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
if (element.getChild("treatAs", NS) == null) { if (element.getChild("treatAs", NS) == null) {
return null; return null;
} }
@ -70,11 +71,8 @@ public class ModuleParser implements com.sun.syndication.io.ModuleParser {
sle.setTreatAs(element.getChildText("treatAs", NS)); sle.setTreatAs(element.getChildText("treatAs", NS));
final Element listInfo = element.getChild("listinfo", NS); final Element listInfo = element.getChild("listinfo", NS);
final List groups = listInfo.getChildren("group", NS); ArrayList<Object> values = new ArrayList<Object>();
ArrayList values = new ArrayList(); for (final Element ge : listInfo.getChildren("group", NS)) {
for (int i = 0; groups != null && i < groups.size(); i++) {
final Element ge = (Element) groups.get(i);
final Namespace ns = ge.getAttribute("ns") == null ? element.getNamespace() : Namespace.getNamespace(ge.getAttributeValue("ns")); final Namespace ns = ge.getAttribute("ns") == null ? element.getNamespace() : Namespace.getNamespace(ge.getAttributeValue("ns"));
final String elementName = ge.getAttributeValue("element"); final String elementName = ge.getAttributeValue("element");
final String label = ge.getAttributeValue("label"); final String label = ge.getAttributeValue("label");
@ -82,12 +80,9 @@ public class ModuleParser implements com.sun.syndication.io.ModuleParser {
} }
sle.setGroupFields((Group[]) values.toArray(new Group[values.size()])); sle.setGroupFields((Group[]) values.toArray(new Group[values.size()]));
values = values.size() == 0 ? values : new ArrayList(); values = values.size() == 0 ? values : new ArrayList<Object>();
final List sorts = listInfo.getChildren("sort", NS); for (final Element se : listInfo.getChildren("sort", NS)) {
for (int i = 0; sorts != null && i < sorts.size(); i++) {
final Element se = (Element) sorts.get(i);
System.out.println("Parse cf:sort " + se.getAttributeValue("element") + se.getAttributeValue("data-type")); System.out.println("Parse cf:sort " + se.getAttributeValue("element") + se.getAttributeValue("data-type"));
final Namespace ns = se.getAttributeValue("ns") == null ? element.getNamespace() : Namespace.getNamespace(se.getAttributeValue("ns")); final Namespace ns = se.getAttributeValue("ns") == null ? element.getNamespace() : Namespace.getNamespace(se.getAttributeValue("ns"));
final String elementName = se.getAttributeValue("element"); final String elementName = se.getAttributeValue("element");
@ -111,9 +106,9 @@ public class ModuleParser implements com.sun.syndication.io.ModuleParser {
} }
} }
public void insertValues(final SimpleListExtension sle, final List elements) { public void insertValues(final SimpleListExtension sle, final List<Element> elements) {
for (int i = 0; elements != null && i < elements.size(); i++) { for (int i = 0; elements != null && i < elements.size(); i++) {
final Element e = (Element) elements.get(i); final Element e = elements.get(i);
final Group[] groups = sle.getGroupFields(); final Group[] groups = sle.getGroupFields();
for (final Group group2 : groups) { for (final Group group2 : groups) {

View file

@ -29,6 +29,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class DateValue implements EntryValue { public class DateValue implements EntryValue {
private static final long serialVersionUID = 8864338943592633517L;
private Date value; private Date value;
private final ObjectBean obj = new ObjectBean(DateValue.class, this); private final ObjectBean obj = new ObjectBean(DateValue.class, this);
private String element; private String element;
@ -87,7 +88,7 @@ public class DateValue implements EntryValue {
* @return * @return
*/ */
@Override @Override
public Comparable getValue() { public Comparable<Date> getValue() {
return value; return value;
} }

View file

@ -46,7 +46,7 @@ public interface EntryValue extends Serializable, Cloneable {
* *
* @return Returns the value of the element. * @return Returns the value of the element.
*/ */
public Comparable getValue(); public Comparable<?> getValue();
/** /**
* Returns the namespace of the element. * Returns the namespace of the element.

View file

@ -52,6 +52,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class Group implements Serializable, Cloneable { public class Group implements Serializable, Cloneable {
private static final long serialVersionUID = -7054101150858658108L;
private Namespace namespace = Namespace.XML_NAMESPACE; private Namespace namespace = Namespace.XML_NAMESPACE;
private final ObjectBean obj = new ObjectBean(Group.class, this); private final ObjectBean obj = new ObjectBean(Group.class, this);
private final String element; private final String element;

View file

@ -29,6 +29,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class NumberValue implements EntryValue { public class NumberValue implements EntryValue {
private static final long serialVersionUID = 8043418996659222922L;
private BigDecimal value; private BigDecimal value;
private final ObjectBean obj = new ObjectBean(NumberValue.class, this); private final ObjectBean obj = new ObjectBean(NumberValue.class, this);
private String element; private String element;
@ -62,7 +63,7 @@ public class NumberValue implements EntryValue {
} }
@Override @Override
public Comparable getValue() { public Comparable<BigDecimal> getValue() {
return value; return value;
} }

View file

@ -64,6 +64,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class Sort implements Serializable, Cloneable { public class Sort implements Serializable, Cloneable {
private static final long serialVersionUID = -5839582908829350351L;
/** /**
* dataType value for Date information. * dataType value for Date information.
*/ */

View file

@ -27,6 +27,7 @@ import com.sun.syndication.feed.impl.ObjectBean;
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class StringValue implements EntryValue { public class StringValue implements EntryValue {
private static final long serialVersionUID = -8384073300710802173L;
private final ObjectBean obj = new ObjectBean(StringValue.class, this); private final ObjectBean obj = new ObjectBean(StringValue.class, this);
private String element; private String element;
private String label; private String label;
@ -60,7 +61,7 @@ public class StringValue implements EntryValue {
} }
@Override @Override
public Comparable getValue() { public Comparable<String> getValue() {
return value; return value;
} }

View file

@ -3,9 +3,11 @@ package org.rometools.feed.module.sse;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Set; import java.util.Set;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace;
import org.rometools.feed.module.sse.modules.Conflict; import org.rometools.feed.module.sse.modules.Conflict;
import org.rometools.feed.module.sse.modules.Conflicts; import org.rometools.feed.module.sse.modules.Conflicts;
import org.rometools.feed.module.sse.modules.History; import org.rometools.feed.module.sse.modules.History;
@ -54,7 +56,7 @@ public class SSE091Generator implements DelegatingModuleGenerator {
* @return a set with all the URIs (JDOM Namespace elements) this module generator uses. * @return a set with all the URIs (JDOM Namespace elements) this module generator uses.
*/ */
@Override @Override
public Set getNamespaces() { public Set<Namespace> getNamespaces() {
return SSEModule.NAMESPACES; return SSEModule.NAMESPACES;
} }
@ -119,10 +121,10 @@ public class SSE091Generator implements DelegatingModuleGenerator {
parent.addContent(syncElement); parent.addContent(syncElement);
} }
private void generateConflicts(final Element syncElement, final List conflicts) { private void generateConflicts(final Element syncElement, final List<Conflict> conflicts) {
if (conflicts != null) { if (conflicts != null) {
final Element conflictsElement = new Element(Conflicts.NAME, SSEModule.SSE_NS); final Element conflictsElement = new Element(Conflicts.NAME, SSEModule.SSE_NS);
for (final Iterator confictIter = conflicts.iterator(); confictIter.hasNext();) { for (final Iterator<Conflict> confictIter = conflicts.iterator(); confictIter.hasNext();) {
final Element conflictElement = new Element(Conflict.NAME, SSEModule.SSE_NS); final Element conflictElement = new Element(Conflict.NAME, SSEModule.SSE_NS);
final Conflict conflict = (Conflict) confictIter.next(); final Conflict conflict = (Conflict) confictIter.next();
generateAttribute(conflictElement, Conflict.BY_ATTRIBUTE, conflict.getBy()); generateAttribute(conflictElement, Conflict.BY_ATTRIBUTE, conflict.getBy());
@ -154,11 +156,11 @@ public class SSE091Generator implements DelegatingModuleGenerator {
} }
} }
private void generateUpdates(final Element historyElement, final List updates) { private void generateUpdates(final Element historyElement, final List<Update> updates) {
if (updates != null) { if (updates != null) {
for (final Iterator updateIter = updates.iterator(); updateIter.hasNext();) { for (final Iterator<Update> updateIter = updates.iterator(); updateIter.hasNext();) {
final Element updateElement = new Element(Update.NAME, SSEModule.SSE_NS); final Element updateElement = new Element(Update.NAME, SSEModule.SSE_NS);
final Update update = (Update) updateIter.next(); final Update update = updateIter.next();
generateAttribute(updateElement, Update.BY_ATTRIBUTE, update.getBy()); generateAttribute(updateElement, Update.BY_ATTRIBUTE, update.getBy());
generateAttribute(updateElement, Update.WHEN_ATTRIBUTE, update.getWhen()); generateAttribute(updateElement, Update.WHEN_ATTRIBUTE, update.getWhen());
historyElement.addContent(updateElement); historyElement.addContent(updateElement);
@ -175,7 +177,7 @@ public class SSE091Generator implements DelegatingModuleGenerator {
private String toString(final Object o) { private String toString(final Object o) {
if (o != null) { if (o != null) {
if (o instanceof Date) { if (o instanceof Date) {
return DateParser.formatRFC822((Date) o); return DateParser.formatRFC822((Date) o, Locale.US);
} else { } else {
return o.toString(); return o.toString();
} }

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jdom2.Attribute; import org.jdom2.Attribute;
@ -52,19 +53,19 @@ public class SSE091Parser implements DelegatingModuleParser {
} }
@Override @Override
public Module parse(final org.jdom2.Element element) { public Module parse(final Element element, final Locale locale) {
SSEModule sseModule = null; SSEModule sseModule = null;
final String name = element.getName(); final String name = element.getName();
if (name.equals("rss")) { if (name.equals("rss")) {
sseModule = parseSharing(element); sseModule = parseSharing(element, locale);
} else if (name.equals("item")) { } else if (name.equals("item")) {
sseModule = parseSync(element); sseModule = parseSync(element, locale);
} }
return sseModule; return sseModule;
} }
private Sharing parseSharing(final Element element) { private Sharing parseSharing(final Element element, final Locale locale) {
final Element root = getRoot(element); final Element root = getRoot(element);
Sharing sharing = null; Sharing sharing = null;
@ -72,32 +73,32 @@ public class SSE091Parser implements DelegatingModuleParser {
if (sharingChild != null) { if (sharingChild != null) {
sharing = new Sharing(); sharing = new Sharing();
sharing.setOrdered(parseBooleanAttr(sharingChild, Sharing.ORDERED_ATTRIBUTE)); sharing.setOrdered(parseBooleanAttr(sharingChild, Sharing.ORDERED_ATTRIBUTE));
sharing.setSince(parseDateAttribute(sharingChild, Sharing.SINCE_ATTRIBUTE)); sharing.setSince(parseDateAttribute(sharingChild, Sharing.SINCE_ATTRIBUTE, locale));
sharing.setUntil(parseDateAttribute(sharingChild, Sharing.UNTIL_ATTRIBUTE)); sharing.setUntil(parseDateAttribute(sharingChild, Sharing.UNTIL_ATTRIBUTE, locale));
sharing.setWindow(parseIntegerAttribute(sharingChild, Sharing.WINDOW_ATTRIBUTE)); sharing.setWindow(parseIntegerAttribute(sharingChild, Sharing.WINDOW_ATTRIBUTE));
sharing.setVersion(parseStringAttribute(sharingChild, Sharing.VERSION_ATTRIBUTE)); sharing.setVersion(parseStringAttribute(sharingChild, Sharing.VERSION_ATTRIBUTE));
parseRelated(root, sharing); parseRelated(root, sharing, locale);
} }
return sharing; return sharing;
} }
private void parseRelated(final Element root, final Sharing sharing) { private void parseRelated(final Element root, final Sharing sharing, final Locale locale) {
Related related; Related related;
final Element relatedChild = root.getChild(Related.NAME, SSEModule.SSE_NS); final Element relatedChild = root.getChild(Related.NAME, SSEModule.SSE_NS);
if (relatedChild != null) { if (relatedChild != null) {
related = new Related(); related = new Related();
// TODO; is this an attribute? // TODO; is this an attribute?
related.setLink(parseStringAttribute(relatedChild, Related.LINK_ATTRIBUTE)); related.setLink(parseStringAttribute(relatedChild, Related.LINK_ATTRIBUTE));
related.setSince(parseDateAttribute(relatedChild, Related.SINCE_ATTRIBUTE)); related.setSince(parseDateAttribute(relatedChild, Related.SINCE_ATTRIBUTE, locale));
related.setTitle(parseStringAttribute(relatedChild, Related.TITLE_ATTRIBUTE)); related.setTitle(parseStringAttribute(relatedChild, Related.TITLE_ATTRIBUTE));
related.setType(parseIntegerAttribute(relatedChild, Related.TYPE_ATTRIBUTE)); related.setType(parseIntegerAttribute(relatedChild, Related.TYPE_ATTRIBUTE));
related.setUntil(parseDateAttribute(relatedChild, Related.UNTIL_ATTRIBUTE)); related.setUntil(parseDateAttribute(relatedChild, Related.UNTIL_ATTRIBUTE, locale));
sharing.setRelated(related); sharing.setRelated(related);
} }
} }
private Sync parseSync(final Element element) { private Sync parseSync(final Element element, final Locale locale) {
// Now I am going to get the item specific tags // Now I am going to get the item specific tags
final Element syncChild = element.getChild(Sync.NAME, SSEModule.SSE_NS); final Element syncChild = element.getChild(Sync.NAME, SSEModule.SSE_NS);
Sync sync = null; Sync sync = null;
@ -108,37 +109,37 @@ public class SSE091Parser implements DelegatingModuleParser {
sync.setVersion(parseIntegerAttribute(syncChild, Sync.VERSION_ATTRIBUTE)); sync.setVersion(parseIntegerAttribute(syncChild, Sync.VERSION_ATTRIBUTE));
sync.setDeleted(parseBooleanAttr(syncChild, Sync.DELETED_ATTRIBUTE)); sync.setDeleted(parseBooleanAttr(syncChild, Sync.DELETED_ATTRIBUTE));
sync.setConflict(parseBooleanAttr(syncChild, Sync.CONFLICT_ATTRIBUTE)); sync.setConflict(parseBooleanAttr(syncChild, Sync.CONFLICT_ATTRIBUTE));
sync.setHistory(parseHistory(syncChild)); sync.setHistory(parseHistory(syncChild, locale));
sync.setConflicts(parseConflicts(syncChild)); sync.setConflicts(parseConflicts(syncChild, locale));
} }
return sync; return sync;
} }
private List parseConflicts(final Element syncElement) { private List<Conflict> parseConflicts(final Element syncElement, final Locale locale) {
List conflicts = null; List<Conflict> conflicts = null;
final List conflictsContent = syncElement.getContent(new ContentFilter(Conflicts.NAME)); final List<Element> conflictsContent = syncElement.getContent(new ContentFilter(Conflicts.NAME));
for (final Iterator conflictsIter = conflictsContent.iterator(); conflictsIter.hasNext();) { for (final Iterator<Element> conflictsIter = conflictsContent.iterator(); conflictsIter.hasNext();) {
final Element conflictsElement = (Element) conflictsIter.next(); final Element conflictsElement = conflictsIter.next();
final List conflictContent = conflictsElement.getContent(new ContentFilter(Conflict.NAME)); final List<Element> conflictContent = conflictsElement.getContent(new ContentFilter(Conflict.NAME));
for (final Iterator conflictIter = conflictContent.iterator(); conflictIter.hasNext();) { for (final Iterator<Element> conflictIter = conflictContent.iterator(); conflictIter.hasNext();) {
final Element conflictElement = (Element) conflictIter.next(); final Element conflictElement = (Element) conflictIter.next();
final Conflict conflict = new Conflict(); final Conflict conflict = new Conflict();
conflict.setBy(parseStringAttribute(conflictElement, Conflict.BY_ATTRIBUTE)); conflict.setBy(parseStringAttribute(conflictElement, Conflict.BY_ATTRIBUTE));
conflict.setWhen(parseDateAttribute(conflictElement, Conflict.WHEN_ATTRIBUTE)); conflict.setWhen(parseDateAttribute(conflictElement, Conflict.WHEN_ATTRIBUTE, locale));
conflict.setVersion(parseIntegerAttribute(conflictElement, Conflict.VERSION_ATTRIBUTE)); conflict.setVersion(parseIntegerAttribute(conflictElement, Conflict.VERSION_ATTRIBUTE));
final List conflictItemContent = conflictElement.getContent(new ContentFilter("item")); final List<Element> conflictItemContent = conflictElement.getContent(new ContentFilter("item"));
for (final Iterator conflictItemIter = conflictItemContent.iterator(); conflictItemIter.hasNext();) { for (final Iterator<Element> conflictItemIter = conflictItemContent.iterator(); conflictItemIter.hasNext();) {
final Element conflictItemElement = (Element) conflictItemIter.next(); final Element conflictItemElement = (Element) conflictItemIter.next();
final Element root = getRoot(conflictItemElement); final Element root = getRoot(conflictItemElement);
final Item conflictItem = rssParser.parseItem(root, conflictItemElement); final Item conflictItem = rssParser.parseItem(root, conflictItemElement, locale);
conflict.setItem(conflictItem); conflict.setItem(conflictItem);
if (conflicts == null) { if (conflicts == null) {
conflicts = new ArrayList(); conflicts = new ArrayList<Conflict>();
} }
conflicts.add(conflict); conflicts.add(conflict);
} }
@ -158,21 +159,21 @@ public class SSE091Parser implements DelegatingModuleParser {
return root; return root;
} }
private History parseHistory(final Element historyElement) { private History parseHistory(final Element historyElement, final Locale locale) {
final Element historyContent = getFirstContent(historyElement, History.NAME); final Element historyContent = getFirstContent(historyElement, History.NAME);
History history = null; History history = null;
if (historyContent != null) { if (historyContent != null) {
history = new History(); history = new History();
history.setBy(parseStringAttribute(historyContent, History.BY_ATTRIBUTE)); history.setBy(parseStringAttribute(historyContent, History.BY_ATTRIBUTE));
history.setWhen(parseDateAttribute(historyContent, History.WHEN_ATTRIBUTE)); history.setWhen(parseDateAttribute(historyContent, History.WHEN_ATTRIBUTE, locale));
parseUpdates(historyContent, history); parseUpdates(historyContent, history, locale);
} }
return history; return history;
} }
private Element getFirstContent(final Element element, final String name) { private Element getFirstContent(final Element element, final String name) {
final List filterList = element.getContent(new ContentFilter(name)); final List<Element> filterList = element.getContent(new ContentFilter(name));
Element firstContent = null; Element firstContent = null;
if (filterList != null && filterList.size() > 0) { if (filterList != null && filterList.size() > 0) {
firstContent = (Element) filterList.get(0); firstContent = (Element) filterList.get(0);
@ -180,13 +181,13 @@ public class SSE091Parser implements DelegatingModuleParser {
return firstContent; return firstContent;
} }
private void parseUpdates(final Element historyChild, final History history) { private void parseUpdates(final Element historyChild, final History history, final Locale locale) {
final List updatedChildren = historyChild.getContent(new ContentFilter(Update.NAME)); final List<Element> updatedChildren = historyChild.getContent(new ContentFilter(Update.NAME));
for (final Iterator childIter = updatedChildren.iterator(); childIter.hasNext();) { for (final Iterator<Element> childIter = updatedChildren.iterator(); childIter.hasNext();) {
final Element updateChild = (Element) childIter.next(); final Element updateChild = childIter.next();
final Update update = new Update(); final Update update = new Update();
update.setBy(parseStringAttribute(updateChild, Update.BY_ATTRIBUTE)); update.setBy(parseStringAttribute(updateChild, Update.BY_ATTRIBUTE));
update.setWhen(parseDateAttribute(updateChild, Update.WHEN_ATTRIBUTE)); update.setWhen(parseDateAttribute(updateChild, Update.WHEN_ATTRIBUTE, locale));
history.addUpdate(update); history.addUpdate(update);
} }
} }
@ -222,20 +223,20 @@ public class SSE091Parser implements DelegatingModuleParser {
return attrValue; return attrValue;
} }
private Date parseDateAttribute(final Element childElement, final String attrName) { private Date parseDateAttribute(final Element childElement, final String attrName, final Locale locale) {
final Attribute dateAttribute = childElement.getAttribute(attrName); final Attribute dateAttribute = childElement.getAttribute(attrName);
final Date date = null; final Date date = null;
if (dateAttribute != null) { if (dateAttribute != null) {
// SSE spec requires the timezone to be 'GMT' // SSE spec requires the timezone to be 'GMT'
// admittedly, this is a bit heavy-handed // admittedly, this is a bit heavy-handed
final String dateAttr = dateAttribute.getValue().trim(); final String dateAttr = dateAttribute.getValue().trim();
return DateParser.parseRFC822(dateAttr); return DateParser.parseRFC822(dateAttr, locale);
} }
return date; return date;
} }
private static class ContentFilter extends AbstractFilter { private static class ContentFilter extends AbstractFilter<Element> {
private static final long serialVersionUID = 9087423853758730810L;
private final String name; private final String name;
private ContentFilter(final String name) { private ContentFilter(final String name) {
@ -243,8 +244,14 @@ public class SSE091Parser implements DelegatingModuleParser {
} }
@Override @Override
public Object filter(final Object object) { public Element filter(final Object content) {
return object instanceof Element && name.equals(((Element) object).getName()); final Element returnValue;
if (content instanceof Element && name.equals(((Element) content).getName())) {
returnValue = (Element) content;
} else {
returnValue = null;
}
return returnValue;
} }
} }

View file

@ -3,12 +3,15 @@ package org.rometools.feed.module.sse.modules;
import java.util.Date; import java.util.Date;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.rss.Item; import com.sun.syndication.feed.rss.Item;
/** /**
* <sx:conflict> element within <sx:conflicts> * <sx:conflict> element within <sx:conflicts>
*/ */
public class Conflict extends SSEModule { public class Conflict extends SSEModule {
private static final long serialVersionUID = -6923108346241653067L;
public static final String CONFLICTS_NAME = "conflicts"; public static final String CONFLICTS_NAME = "conflicts";
public static final String NAME = "conflict"; public static final String NAME = "conflict";
@ -39,7 +42,7 @@ public class Conflict extends SSEModule {
private Item conflictItem; private Item conflictItem;
@Override @Override
public void copyFrom(final CopyFrom obj) { public void copyFrom(final CopyFrom<? extends Module> obj) {
final Conflict conflict = (Conflict) obj; final Conflict conflict = (Conflict) obj;
conflict.when = when == null ? null : (Date) when.clone(); conflict.when = when == null ? null : (Date) when.clone();
conflict.by = by; conflict.by = by;

View file

@ -1,6 +1,7 @@
package org.rometools.feed.module.sse.modules; package org.rometools.feed.module.sse.modules;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/** /**
* <sx:conflicts> element within <sx:sync> * <sx:conflicts> element within <sx:sync>
@ -8,10 +9,11 @@ import com.sun.syndication.feed.CopyFrom;
* The sx:conflicts element MUST contain one or more sx:conflict sub-elements. * The sx:conflicts element MUST contain one or more sx:conflict sub-elements.
*/ */
public class Conflicts extends SSEModule { public class Conflicts extends SSEModule {
private static final long serialVersionUID = 2722893639295169689L;
public static final String NAME = "conflicts"; public static final String NAME = "conflicts";
@Override @Override
public void copyFrom(final CopyFrom obj) { public void copyFrom(final CopyFrom<? extends Module> obj) {
// nothing to copy, just a place-holder // nothing to copy, just a place-holder
} }
} }

View file

@ -5,6 +5,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/** /**
* <pre> * <pre>
@ -20,6 +21,8 @@ import com.sun.syndication.feed.CopyFrom;
* . * .
*/ */
public class History extends SSEModule { public class History extends SSEModule {
private static final long serialVersionUID = -8007994009928369002L;
// A date-time attribute. // A date-time attribute.
private Date when; private Date when;
@ -31,20 +34,20 @@ public class History extends SSEModule {
public static final String WHEN_ATTRIBUTE = "when"; public static final String WHEN_ATTRIBUTE = "when";
public static final String BY_ATTRIBUTE = "by"; public static final String BY_ATTRIBUTE = "by";
private List updates; private List<Update> updates;
public History() { public History() {
} }
@Override @Override
public void copyFrom(final CopyFrom other) { public void copyFrom(final CopyFrom<? extends Module> other) {
final History otherHistory = (History) other; final History otherHistory = (History) other;
when = otherHistory.when == null ? null : (Date) otherHistory.when.clone(); when = otherHistory.when == null ? null : (Date) otherHistory.when.clone();
// dont copy immutable // dont copy immutable
by = otherHistory.by; by = otherHistory.by;
if (otherHistory.updates != null) { if (otherHistory.updates != null) {
updates = new ArrayList(); updates = new ArrayList<Update>();
updates.addAll(otherHistory.updates); updates.addAll(otherHistory.updates);
} }
} }
@ -106,7 +109,7 @@ public class History extends SSEModule {
*/ */
public void addUpdate(final Update update) { public void addUpdate(final Update update) {
if (updates == null) { if (updates == null) {
updates = new ArrayList(); updates = new ArrayList<Update>();
} }
updates.add(update); updates.add(update);
} }
@ -116,7 +119,7 @@ public class History extends SSEModule {
* *
* @return the list of updates for this history. * @return the list of updates for this history.
*/ */
public List getUpdates() { public List<Update> getUpdates() {
return updates; return updates;
} }
} }

View file

@ -3,6 +3,7 @@ package org.rometools.feed.module.sse.modules;
import java.util.Date; import java.util.Date;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/** /**
* <pre> * <pre>
@ -18,6 +19,8 @@ import com.sun.syndication.feed.CopyFrom;
* . * .
*/ */
public class Related extends SSEModule { public class Related extends SSEModule {
private static final long serialVersionUID = -2982701526362850770L;
public static final String NAME = "related"; public static final String NAME = "related";
/** /**
@ -48,7 +51,7 @@ public class Related extends SSEModule {
public static final String UNTIL_ATTRIBUTE = "until"; public static final String UNTIL_ATTRIBUTE = "until";
@Override @Override
public void copyFrom(final CopyFrom obj) { public void copyFrom(final CopyFrom<? extends Module> obj) {
final Related related = (Related) obj; final Related related = (Related) obj;
related.link = link; related.link = link;
related.since = since == null ? null : (Date) since.clone(); related.since = since == null ? null : (Date) since.clone();

View file

@ -13,16 +13,18 @@ import com.sun.syndication.feed.module.Module;
* The base module for SSE data synchronization. Defines a namespace, uri, and basic copying operations. * The base module for SSE data synchronization. Defines a namespace, uri, and basic copying operations.
*/ */
public abstract class SSEModule implements Module { public abstract class SSEModule implements Module {
private static final long serialVersionUID = -7487775381662291314L;
public static final String SSE_SCHEMA_URI = "http://www.microsoft.com/schemas/rss/sse"; public static final String SSE_SCHEMA_URI = "http://www.microsoft.com/schemas/rss/sse";
// a default prefix to use for sse tags // a default prefix to use for sse tags
public static final String PREFIX = "sx"; public static final String PREFIX = "sx";
public static final Namespace SSE_NS = Namespace.getNamespace(PREFIX, SSE_SCHEMA_URI); public static final Namespace SSE_NS = Namespace.getNamespace(PREFIX, SSE_SCHEMA_URI);
public static final Set NAMESPACES; public static final Set<Namespace> NAMESPACES;
static { static {
final Set nss = new HashSet(); final Set<Namespace> nss = new HashSet<Namespace>();
nss.add(SSEModule.SSE_NS); nss.add(SSEModule.SSE_NS);
NAMESPACES = Collections.unmodifiableSet(nss); NAMESPACES = Collections.unmodifiableSet(nss);
} }
@ -33,7 +35,7 @@ public abstract class SSEModule implements Module {
} }
@Override @Override
public Class getInterface() { public Class<? extends Module> getInterface() {
return getClass(); return getClass();
} }
@ -54,5 +56,5 @@ public abstract class SSEModule implements Module {
} }
@Override @Override
public abstract void copyFrom(CopyFrom obj); public abstract void copyFrom(CopyFrom<? extends Module> obj);
} }

View file

@ -3,6 +3,7 @@ package org.rometools.feed.module.sse.modules;
import java.util.Date; import java.util.Date;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/** /**
* <pre> * <pre>
@ -24,6 +25,8 @@ import com.sun.syndication.feed.CopyFrom;
* . * .
*/ */
public class Sharing extends SSEModule { public class Sharing extends SSEModule {
private static final long serialVersionUID = 8626705992778126861L;
public static final String NAME = "sharing"; public static final String NAME = "sharing";
public static final String UNTIL_ATTRIBUTE = "until"; public static final String UNTIL_ATTRIBUTE = "until";
@ -49,7 +52,7 @@ public class Sharing extends SSEModule {
private Related related; private Related related;
@Override @Override
public void copyFrom(final CopyFrom obj) { public void copyFrom(final CopyFrom<? extends Module> obj) {
final Sharing sharing = (Sharing) obj; final Sharing sharing = (Sharing) obj;
ordered = sharing.ordered; ordered = sharing.ordered;
since = sharing.since == null ? null : (Date) sharing.since.clone(); since = sharing.since == null ? null : (Date) sharing.since.clone();

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/** /**
* <pre> * <pre>
@ -25,6 +26,8 @@ import com.sun.syndication.feed.CopyFrom;
* . * .
*/ */
public class Sync extends SSEModule { public class Sync extends SSEModule {
private static final long serialVersionUID = 3071686432594143174L;
public static final String NAME = "sync"; public static final String NAME = "sync";
public static final String ID_ATTRIBUTE = "id"; public static final String ID_ATTRIBUTE = "id";
@ -42,10 +45,10 @@ public class Sync extends SSEModule {
private Boolean conflict; private Boolean conflict;
private History history; private History history;
private List conflicts; private List<Conflict> conflicts;
@Override @Override
public void copyFrom(final CopyFrom obj) { public void copyFrom(final CopyFrom<? extends Module> obj) {
final Sync sync = (Sync) obj; final Sync sync = (Sync) obj;
deleted = sync.deleted; deleted = sync.deleted;
version = sync.version; version = sync.version;
@ -53,7 +56,7 @@ public class Sync extends SSEModule {
id = sync.id; id = sync.id;
history = sync.history == null ? null : (History) sync.history.clone(); history = sync.history == null ? null : (History) sync.history.clone();
if (sync.conflicts != null) { if (sync.conflicts != null) {
conflicts = new ArrayList(); conflicts = new ArrayList<Conflict>();
conflicts.addAll(sync.conflicts); conflicts.addAll(sync.conflicts);
} }
} }
@ -155,16 +158,16 @@ public class Sync extends SSEModule {
public void addConflict(final Conflict conflict) { public void addConflict(final Conflict conflict) {
if (conflicts == null) { if (conflicts == null) {
conflicts = new ArrayList(); conflicts = new ArrayList<Conflict>();
} }
conflicts.add(conflict); conflicts.add(conflict);
} }
public List getConflicts() { public List<Conflict> getConflicts() {
return conflicts; return conflicts;
} }
public void setConflicts(final List conflicts) { public void setConflicts(final List<Conflict> conflicts) {
this.conflicts = conflicts; this.conflicts = conflicts;
} }
} }

View file

@ -3,6 +3,7 @@ package org.rometools.feed.module.sse.modules;
import java.util.Date; import java.util.Date;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/** /**
* <pre> * <pre>
@ -18,6 +19,7 @@ import com.sun.syndication.feed.CopyFrom;
* . * .
*/ */
public class Update extends SSEModule { public class Update extends SSEModule {
private static final long serialVersionUID = 4806771926023433667L;
public static final String NAME = "update"; public static final String NAME = "update";
public static final String BY_ATTRIBUTE = "by"; public static final String BY_ATTRIBUTE = "by";
public static final String WHEN_ATTRIBUTE = "when"; public static final String WHEN_ATTRIBUTE = "when";
@ -26,7 +28,7 @@ public class Update extends SSEModule {
private String by; private String by;
@Override @Override
public void copyFrom(final CopyFrom other) { public void copyFrom(final CopyFrom<? extends Module> other) {
final Update otherUpdate = (Update) other; final Update otherUpdate = (Update) other;
otherUpdate.when = when == null ? null : (Date) when.clone(); otherUpdate.when = when == null ? null : (Date) when.clone();
// dont copy immutable // dont copy immutable

View file

@ -44,6 +44,7 @@ import org.rometools.feed.module.yahooweather.types.Units;
import org.rometools.feed.module.yahooweather.types.Wind; import org.rometools.feed.module.yahooweather.types.Wind;
import com.sun.syndication.feed.CopyFrom; import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.module.ModuleImpl; import com.sun.syndication.feed.module.ModuleImpl;
/** /**
@ -53,6 +54,7 @@ import com.sun.syndication.feed.module.ModuleImpl;
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class YWeatherModuleImpl extends ModuleImpl implements YWeatherEntryModule, YWeatherFeedModule { public class YWeatherModuleImpl extends ModuleImpl implements YWeatherEntryModule, YWeatherFeedModule {
private static final long serialVersionUID = -4753704339578661020L;
private Location location; private Location location;
private Astronomy astronomy; private Astronomy astronomy;
private Atmosphere atmosphere; private Atmosphere atmosphere;
@ -66,12 +68,12 @@ public class YWeatherModuleImpl extends ModuleImpl implements YWeatherEntryModul
} }
@Override @Override
public Class getInterface() { public Class<? extends Module> getInterface() {
return CopyFromInterface.class; return CopyFromInterface.class;
} }
@Override @Override
public void copyFrom(final CopyFrom o) { public void copyFrom(final CopyFrom<? extends Module> o) {
final YWeatherModuleImpl from = (YWeatherModuleImpl) o; final YWeatherModuleImpl from = (YWeatherModuleImpl) o;
setAstronomy(from.getAstronomy() != null ? (Astronomy) from.getAstronomy().clone() : null); setAstronomy(from.getAstronomy() != null ? (Astronomy) from.getAstronomy().clone() : null);
setCondition(from.getCondition() != null ? (Condition) from.getCondition().clone() : null); setCondition(from.getCondition() != null ? (Condition) from.getCondition().clone() : null);

View file

@ -39,6 +39,7 @@ package org.rometools.feed.module.yahooweather.io;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
@ -203,10 +204,9 @@ public class WeatherModuleGenerator implements ModuleGenerator {
} }
@Override @Override
public java.util.Set getNamespaces() { public Set<Namespace> getNamespaces() {
final HashSet set = new HashSet(); final Set<Namespace> set = new HashSet<Namespace>();
set.add(WeatherModuleGenerator.NS); set.add(WeatherModuleGenerator.NS);
return set; return set;
} }

View file

@ -42,6 +42,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jdom2.Element; import org.jdom2.Element;
@ -83,7 +84,7 @@ public class WeatherModuleParser implements ModuleParser {
} }
@Override @Override
public Module parse(final Element element) { public Module parse(final Element element, final Locale locale) {
final YWeatherModuleImpl module = new YWeatherModuleImpl(); final YWeatherModuleImpl module = new YWeatherModuleImpl();
final Element location = element.getChild("location", WeatherModuleParser.NS); final Element location = element.getChild("location", WeatherModuleParser.NS);
@ -152,14 +153,14 @@ public class WeatherModuleParser implements ModuleParser {
} }
} }
final List forecasts = element.getChildren("forecast", WeatherModuleParser.NS); final List<Element> forecasts = element.getChildren("forecast", WeatherModuleParser.NS);
if (forecasts != null) { if (forecasts != null) {
final Forecast[] f = new Forecast[forecasts.size()]; final Forecast[] f = new Forecast[forecasts.size()];
int i = 0; int i = 0;
for (final Iterator it = forecasts.iterator(); it.hasNext(); i++) { for (final Iterator<Element> it = forecasts.iterator(); it.hasNext(); i++) {
final Element forecast = (Element) it.next(); final Element forecast = it.next();
try { try {
f[i] = new Forecast(forecast.getAttributeValue("day"), SHORT_DATE.parse(forecast.getAttributeValue("date")), Integer.parseInt(forecast f[i] = new Forecast(forecast.getAttributeValue("day"), SHORT_DATE.parse(forecast.getAttributeValue("date")), Integer.parseInt(forecast

View file

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@ -153,8 +154,8 @@ public class SSEParserTest extends AbstractTestCase {
// this test is brittle, but its comprehensive // this test is brittle, but its comprehensive
if ("until".equals(a1Name) || "since".equals(a1Name) || "when".equals(a1Name)) { if ("until".equals(a1Name) || "since".equals(a1Name) || "when".equals(a1Name)) {
av1 = DateParser.parseRFC822((String) av1); av1 = DateParser.parseRFC822((String) av1, Locale.US);
av2 = DateParser.parseRFC822((String) av2); av2 = DateParser.parseRFC822((String) av2, Locale.US);
} }
assertTrue("unequal attributes:" + one.getName() + "." + a1.getName() + ": " + av1 + " != " + av2, av1.equals(av2)); assertTrue("unequal attributes:" + one.getName() + "." + a1.getName() + ": " + av1 + " != " + av2, av1.equals(av2));
@ -247,7 +248,7 @@ public class SSEParserTest extends AbstractTestCase {
final Date when = history.getWhen(); final Date when = history.getWhen();
assertNotNull(when); assertNotNull(when);
final Date testDate = DateParser.parseRFC822("Fri, 6 Jan 2006 19:24:09 GMT"); final Date testDate = DateParser.parseRFC822("Fri, 6 Jan 2006 19:24:09 GMT", Locale.US);
assertEquals(testDate, when); assertEquals(testDate, when);
} }