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

View file

@ -50,6 +50,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -109,7 +110,7 @@ public class GoogleBaseParser implements ModuleParser {
}
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final HashMap tag2pd = new HashMap();
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.Iterator;
import java.util.List;
import java.util.Locale;
import org.jdom2.Element;
import org.jdom2.Namespace;
@ -68,7 +69,7 @@ public class ModuleParserRSS1 implements ModuleParser {
}
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final CreativeCommonsImpl module = new CreativeCommonsImpl();
{
// Parsing Channel level.

View file

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

View file

@ -45,6 +45,7 @@ package org.rometools.feed.module.content.io;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.jdom2.Attribute;
import org.jdom2.Element;
@ -72,7 +73,7 @@ public class ContentModuleParser implements com.sun.syndication.io.ModuleParser
}
@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;
final ContentModule cm = new ContentModuleImpl();
final List encodeds = element.getChildren("encoded", CONTENT_NS);

View file

@ -16,6 +16,8 @@
*/
package org.rometools.feed.module.feedburner.io;
import java.util.Locale;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.rometools.feed.module.feedburner.FeedBurner;
@ -40,7 +42,7 @@ public class FeedBurnerModuleParser implements ModuleParser {
}
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final FeedBurnerImpl fbi = new FeedBurnerImpl();
boolean returnObj = false;
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.List;
import java.util.Locale;
import org.jdom2.Element;
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)
*/
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseGML(element);
return geoRssModule;
}

View file

@ -16,6 +16,8 @@
*/
package org.rometools.feed.module.georss;
import java.util.Locale;
import org.jdom2.Element;
import org.rometools.feed.module.georss.geometries.Envelope;
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)
*/
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseSimple(element);
return geoRssModule;
}

View file

@ -16,6 +16,8 @@
*/
package org.rometools.feed.module.georss;
import java.util.Locale;
import org.jdom2.Element;
import org.rometools.feed.module.georss.geometries.Point;
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)
*/
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseW3C(element);
return geoRssModule;
}

View file

@ -44,6 +44,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.logging.Logger;
@ -81,7 +82,7 @@ public class ITunesParser implements ModuleParser {
}
@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;
if (element.getName().equals("channel")) {

View file

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

View file

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

View file

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

View file

@ -46,6 +46,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
import org.jdom2.Element;
@ -76,7 +77,7 @@ public class Parser implements ModuleParser {
}
@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")) {
return new PhotocastModuleImpl();
} 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;
import java.util.Locale;
import java.util.StringTokenizer;
import org.jdom2.Element;
@ -71,7 +72,7 @@ public class SlashModuleParser implements ModuleParser {
}
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final SlashImpl si = new SlashImpl();
Element tag = element.getChild("hit_parade", SlashModuleParser.NS);
if (tag != null) {

View file

@ -21,6 +21,7 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.jdom2.Element;
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.
*/
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final SleEntryImpl sle = new SleEntryImpl();
ArrayList values = new ArrayList();
final List groups = element.getChildren("group", ModuleParser.TEMP);
ArrayList<EntryValue> values = new ArrayList<EntryValue>();
final List<Element> groups = element.getChildren("group", ModuleParser.TEMP);
for (int i = 0; groups != null && i < groups.size(); i++) {
final Element group = (Element) groups.get(i);
for (final Element group : groups) {
final StringValue value = new StringValue();
value.setElement(group.getAttributeValue("element"));
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()]));
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());
for (int i = 0; sorts != null && i < sorts.size(); i++) {
final Element sort = (Element) sorts.get(i);
for (final Element sort : sorts) {
final String dataType = sort.getAttributeValue("data-type");
// System.out.println("Doing datatype "+dataType +" :: "+sorts.size());
if (dataType == null || dataType.equals(Sort.TEXT_TYPE)) {
@ -118,8 +117,10 @@ public class ItemParser implements com.sun.syndication.io.ModuleParser {
Date dateValue = null;
try {
dateValue = DateParser.parseRFC822(sort.getAttributeValue("value"));
dateValue = dateValue == null ? DateParser.parseW3CDateTime(sort.getAttributeValue("value")) : dateValue;
dateValue = DateParser.parseRFC822(sort.getAttributeValue("value"), locale);
if (dateValue == null) {
dateValue = DateParser.parseW3CDateTime(sort.getAttributeValue("value"), locale);
}
} catch (final Exception e) {
; // ignore parse exceptions
}

View file

@ -19,6 +19,7 @@ package org.rometools.feed.module.sle.io;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.jdom2.Element;
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.
*/
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
if (element.getChild("treatAs", NS) == null) {
return null;
}
@ -70,11 +71,8 @@ public class ModuleParser implements com.sun.syndication.io.ModuleParser {
sle.setTreatAs(element.getChildText("treatAs", NS));
final Element listInfo = element.getChild("listinfo", NS);
final List groups = listInfo.getChildren("group", NS);
ArrayList values = new ArrayList();
for (int i = 0; groups != null && i < groups.size(); i++) {
final Element ge = (Element) groups.get(i);
ArrayList<Object> values = new ArrayList<Object>();
for (final Element ge : listInfo.getChildren("group", NS)) {
final Namespace ns = ge.getAttribute("ns") == null ? element.getNamespace() : Namespace.getNamespace(ge.getAttributeValue("ns"));
final String elementName = ge.getAttributeValue("element");
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()]));
values = values.size() == 0 ? values : new ArrayList();
values = values.size() == 0 ? values : new ArrayList<Object>();
final List sorts = listInfo.getChildren("sort", NS);
for (int i = 0; sorts != null && i < sorts.size(); i++) {
final Element se = (Element) sorts.get(i);
for (final Element se : listInfo.getChildren("sort", NS)) {
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 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++) {
final Element e = (Element) elements.get(i);
final Element e = elements.get(i);
final Group[] groups = sle.getGroupFields();
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>
*/
public class DateValue implements EntryValue {
private static final long serialVersionUID = 8864338943592633517L;
private Date value;
private final ObjectBean obj = new ObjectBean(DateValue.class, this);
private String element;
@ -87,7 +88,7 @@ public class DateValue implements EntryValue {
* @return
*/
@Override
public Comparable getValue() {
public Comparable<Date> getValue() {
return value;
}

View file

@ -46,7 +46,7 @@ public interface EntryValue extends Serializable, Cloneable {
*
* @return Returns the value of the element.
*/
public Comparable getValue();
public Comparable<?> getValue();
/**
* 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>
*/
public class Group implements Serializable, Cloneable {
private static final long serialVersionUID = -7054101150858658108L;
private Namespace namespace = Namespace.XML_NAMESPACE;
private final ObjectBean obj = new ObjectBean(Group.class, this);
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>
*/
public class NumberValue implements EntryValue {
private static final long serialVersionUID = 8043418996659222922L;
private BigDecimal value;
private final ObjectBean obj = new ObjectBean(NumberValue.class, this);
private String element;
@ -62,7 +63,7 @@ public class NumberValue implements EntryValue {
}
@Override
public Comparable getValue() {
public Comparable<BigDecimal> getValue() {
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>
*/
public class Sort implements Serializable, Cloneable {
private static final long serialVersionUID = -5839582908829350351L;
/**
* 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>
*/
public class StringValue implements EntryValue {
private static final long serialVersionUID = -8384073300710802173L;
private final ObjectBean obj = new ObjectBean(StringValue.class, this);
private String element;
private String label;
@ -60,7 +61,7 @@ public class StringValue implements EntryValue {
}
@Override
public Comparable getValue() {
public Comparable<String> getValue() {
return value;
}

View file

@ -3,9 +3,11 @@ package org.rometools.feed.module.sse;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.rometools.feed.module.sse.modules.Conflict;
import org.rometools.feed.module.sse.modules.Conflicts;
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.
*/
@Override
public Set getNamespaces() {
public Set<Namespace> getNamespaces() {
return SSEModule.NAMESPACES;
}
@ -119,10 +121,10 @@ public class SSE091Generator implements DelegatingModuleGenerator {
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) {
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 Conflict conflict = (Conflict) confictIter.next();
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) {
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 Update update = (Update) updateIter.next();
final Update update = updateIter.next();
generateAttribute(updateElement, Update.BY_ATTRIBUTE, update.getBy());
generateAttribute(updateElement, Update.WHEN_ATTRIBUTE, update.getWhen());
historyElement.addContent(updateElement);
@ -175,7 +177,7 @@ public class SSE091Generator implements DelegatingModuleGenerator {
private String toString(final Object o) {
if (o != null) {
if (o instanceof Date) {
return DateParser.formatRFC822((Date) o);
return DateParser.formatRFC822((Date) o, Locale.US);
} else {
return o.toString();
}

View file

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

View file

@ -1,6 +1,7 @@
package org.rometools.feed.module.sse.modules;
import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/**
* <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.
*/
public class Conflicts extends SSEModule {
private static final long serialVersionUID = 2722893639295169689L;
public static final String NAME = "conflicts";
@Override
public void copyFrom(final CopyFrom obj) {
public void copyFrom(final CopyFrom<? extends Module> obj) {
// nothing to copy, just a place-holder
}
}

View file

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

View file

@ -3,6 +3,7 @@ package org.rometools.feed.module.sse.modules;
import java.util.Date;
import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/**
* <pre>
@ -18,6 +19,8 @@ import com.sun.syndication.feed.CopyFrom;
* .
*/
public class Related extends SSEModule {
private static final long serialVersionUID = -2982701526362850770L;
public static final String NAME = "related";
/**
@ -48,7 +51,7 @@ public class Related extends SSEModule {
public static final String UNTIL_ATTRIBUTE = "until";
@Override
public void copyFrom(final CopyFrom obj) {
public void copyFrom(final CopyFrom<? extends Module> obj) {
final Related related = (Related) obj;
related.link = link;
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.
*/
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";
// a default prefix to use for sse tags
public static final String PREFIX = "sx";
public static final Namespace SSE_NS = Namespace.getNamespace(PREFIX, SSE_SCHEMA_URI);
public static final Set NAMESPACES;
public static final Set<Namespace> NAMESPACES;
static {
final Set nss = new HashSet();
final Set<Namespace> nss = new HashSet<Namespace>();
nss.add(SSEModule.SSE_NS);
NAMESPACES = Collections.unmodifiableSet(nss);
}
@ -33,7 +35,7 @@ public abstract class SSEModule implements Module {
}
@Override
public Class getInterface() {
public Class<? extends Module> getInterface() {
return getClass();
}
@ -54,5 +56,5 @@ public abstract class SSEModule implements Module {
}
@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 com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/**
* <pre>
@ -24,6 +25,8 @@ import com.sun.syndication.feed.CopyFrom;
* .
*/
public class Sharing extends SSEModule {
private static final long serialVersionUID = 8626705992778126861L;
public static final String NAME = "sharing";
public static final String UNTIL_ATTRIBUTE = "until";
@ -49,7 +52,7 @@ public class Sharing extends SSEModule {
private Related related;
@Override
public void copyFrom(final CopyFrom obj) {
public void copyFrom(final CopyFrom<? extends Module> obj) {
final Sharing sharing = (Sharing) obj;
ordered = sharing.ordered;
since = sharing.since == null ? null : (Date) sharing.since.clone();

View file

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

View file

@ -3,6 +3,7 @@ package org.rometools.feed.module.sse.modules;
import java.util.Date;
import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
/**
* <pre>
@ -18,6 +19,7 @@ import com.sun.syndication.feed.CopyFrom;
* .
*/
public class Update extends SSEModule {
private static final long serialVersionUID = 4806771926023433667L;
public static final String NAME = "update";
public static final String BY_ATTRIBUTE = "by";
public static final String WHEN_ATTRIBUTE = "when";
@ -26,7 +28,7 @@ public class Update extends SSEModule {
private String by;
@Override
public void copyFrom(final CopyFrom other) {
public void copyFrom(final CopyFrom<? extends Module> other) {
final Update otherUpdate = (Update) other;
otherUpdate.when = when == null ? null : (Date) when.clone();
// 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 com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.module.Module;
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>
*/
public class YWeatherModuleImpl extends ModuleImpl implements YWeatherEntryModule, YWeatherFeedModule {
private static final long serialVersionUID = -4753704339578661020L;
private Location location;
private Astronomy astronomy;
private Atmosphere atmosphere;
@ -66,12 +68,12 @@ public class YWeatherModuleImpl extends ModuleImpl implements YWeatherEntryModul
}
@Override
public Class getInterface() {
public Class<? extends Module> getInterface() {
return CopyFromInterface.class;
}
@Override
public void copyFrom(final CopyFrom o) {
public void copyFrom(final CopyFrom<? extends Module> o) {
final YWeatherModuleImpl from = (YWeatherModuleImpl) o;
setAstronomy(from.getAstronomy() != null ? (Astronomy) from.getAstronomy().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.util.HashSet;
import java.util.Set;
import org.jdom2.Element;
import org.jdom2.Namespace;
@ -203,10 +204,9 @@ public class WeatherModuleGenerator implements ModuleGenerator {
}
@Override
public java.util.Set getNamespaces() {
final HashSet set = new HashSet();
public Set<Namespace> getNamespaces() {
final Set<Namespace> set = new HashSet<Namespace>();
set.add(WeatherModuleGenerator.NS);
return set;
}

View file

@ -42,6 +42,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
import org.jdom2.Element;
@ -83,7 +84,7 @@ public class WeatherModuleParser implements ModuleParser {
}
@Override
public Module parse(final Element element) {
public Module parse(final Element element, final Locale locale) {
final YWeatherModuleImpl module = new YWeatherModuleImpl();
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) {
final Forecast[] f = new Forecast[forecasts.size()];
int i = 0;
for (final Iterator it = forecasts.iterator(); it.hasNext(); i++) {
final Element forecast = (Element) it.next();
for (final Iterator<Element> it = forecasts.iterator(); it.hasNext(); i++) {
final Element forecast = it.next();
try {
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.Iterator;
import java.util.List;
import java.util.Locale;
import junit.framework.Test;
import junit.framework.TestSuite;
@ -153,8 +154,8 @@ public class SSEParserTest extends AbstractTestCase {
// this test is brittle, but its comprehensive
if ("until".equals(a1Name) || "since".equals(a1Name) || "when".equals(a1Name)) {
av1 = DateParser.parseRFC822((String) av1);
av2 = DateParser.parseRFC822((String) av2);
av1 = DateParser.parseRFC822((String) av1, Locale.US);
av2 = DateParser.parseRFC822((String) av2, Locale.US);
}
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();
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);
}