adapted locale changes from rometools/rome-moudles#22

This commit is contained in:
Martin Kurz 2013-10-13 16:28:35 +02:00
parent 0baa10d58d
commit 63ac66e5b8
4 changed files with 23 additions and 18 deletions

View file

@ -20,6 +20,7 @@ package com.sun.syndication.io.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
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;
@ -106,13 +107,13 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
boolean hasHead = false; boolean hasHead = false;
if (opml.getCreated() != null) { if (opml.getCreated() != null) {
hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated())); hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US));
} }
hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState()));
if (opml.getModified() != null) { if (opml.getModified() != null) {
hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified())); hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US));
} }
hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail());

View file

@ -19,6 +19,7 @@ package com.sun.syndication.io.impl;
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 OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
* @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
*/ */
@Override @Override
public WireFeed parse(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException {
final Opml opml = new Opml(); final Opml opml = new Opml();
opml.setFeedType("opml_1.0"); opml.setFeedType("opml_1.0");
@ -92,11 +93,11 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
opml.setTitle(head.getChildText("title")); opml.setTitle(head.getChildText("title"));
if (head.getChildText("dateCreated") != null) { if (head.getChildText("dateCreated") != null) {
opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"))); opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US));
} }
if (head.getChildText("dateModified") != null) { if (head.getChildText("dateModified") != null) {
opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"))); opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US));
} }
opml.setOwnerName(head.getChildTextTrim("ownerName")); opml.setOwnerName(head.getChildTextTrim("ownerName"));
@ -160,13 +161,13 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
} }
} }
opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate)); opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
opml.setModules(parseFeedModules(root)); opml.setModules(parseFeedModules(root, locale));
return opml; return opml;
} }
protected Outline parseOutline(final Element e, final boolean validate) throws FeedException { protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException {
if (!e.getName().equals("outline")) { if (!e.getName().equals("outline")) {
throw new RuntimeException("Not an outline element."); throw new RuntimeException("Not an outline element.");
} }
@ -211,17 +212,17 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
} }
final List children = e.getChildren("outline"); final List children = e.getChildren("outline");
outline.setModules(parseItemModules(e)); outline.setModules(parseItemModules(e, locale));
outline.setChildren(parseOutlines(children, validate)); outline.setChildren(parseOutlines(children, validate, locale));
return outline; return outline;
} }
protected List parseOutlines(final List elements, final boolean validate) throws FeedException { protected List parseOutlines(final List elements, final boolean validate, final Locale locale) throws FeedException {
final ArrayList results = new ArrayList(); final ArrayList results = new ArrayList();
for (int i = 0; i < elements.size(); i++) { for (int i = 0; i < elements.size(); i++) {
results.add(parseOutline((Element) elements.get(i), validate)); results.add(parseOutline((Element) elements.get(i), validate, locale));
} }
return results; return results;

View file

@ -8,6 +8,8 @@
*/ */
package com.sun.syndication.io.impl; package com.sun.syndication.io.impl;
import java.util.Locale;
import org.jdom2.Document; import org.jdom2.Document;
import org.jdom2.Element; import org.jdom2.Element;
@ -76,7 +78,7 @@ public class OPML20Generator extends OPML10Generator {
retValue = super.generateOutline(outline); retValue = super.generateOutline(outline);
if (outline.getCreated() != null) { if (outline.getCreated() != null) {
retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated())); retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated(), Locale.US));
} }
return retValue; return retValue;

View file

@ -18,6 +18,7 @@
package com.sun.syndication.io.impl; package com.sun.syndication.io.impl;
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;
@ -71,9 +72,9 @@ public class OPML20Parser extends OPML10Parser {
* @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM). * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
*/ */
@Override @Override
public WireFeed parse(final Document document, final boolean validate) throws IllegalArgumentException, FeedException { public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException {
Opml opml; Opml opml;
opml = (Opml) super.parse(document, validate); opml = (Opml) super.parse(document, validate, locale);
final Element head = document.getRootElement().getChild("head"); final Element head = document.getRootElement().getChild("head");
@ -92,13 +93,13 @@ public class OPML20Parser extends OPML10Parser {
} }
@Override @Override
protected Outline parseOutline(final Element e, final boolean validate) throws FeedException { protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException {
Outline retValue; Outline retValue;
retValue = super.parseOutline(e, validate); retValue = super.parseOutline(e, validate, locale);
if (e.getAttributeValue("created") != null) { if (e.getAttributeValue("created") != null) {
retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"))); retValue.setCreated(DateParser.parseRFC822(e.getAttributeValue("created"), locale));
} }
final List atts = retValue.getAttributes(); final List atts = retValue.getAttributes();