adapted new module api with locale (rometools/rome-modules#22)

This commit is contained in:
Martin Kurz 2013-10-13 16:33:42 +02:00
parent 8055c61580
commit fc6ee1cba7
7 changed files with 18 additions and 11 deletions

View file

@ -18,6 +18,7 @@ package org.rometools.propono.atom.client;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpMethodBase;
@ -68,7 +69,7 @@ public class ClientAtomService extends AtomService {
if (method.getStatusCode() != 200) { if (method.getStatusCode() != 200) {
throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode()); throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode());
} }
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(method.getResponseBodyAsStream()), uri); final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(method.getResponseBodyAsStream()), uri, Locale.US);
if (!romeEntry.isMediaEntry()) { if (!romeEntry.isMediaEntry()) {
return new ClientEntry(this, null, romeEntry, false); return new ClientEntry(this, null, romeEntry, false);
} else { } else {

View file

@ -20,6 +20,7 @@ import java.io.InputStreamReader;
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.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpMethodBase;
@ -103,7 +104,7 @@ public class ClientCollection extends Collection {
if (method.getStatusCode() != 200) { if (method.getStatusCode() != 200) {
throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode()); throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode());
} }
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(method.getResponseBodyAsStream()), uri); final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(method.getResponseBodyAsStream()), uri, Locale.US);
if (!romeEntry.isMediaEntry()) { if (!romeEntry.isMediaEntry()) {
return new ClientEntry(service, this, romeEntry, false); return new ClientEntry(service, this, romeEntry, false);
} else { } else {

View file

@ -21,6 +21,7 @@ import java.io.InputStreamReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.Header;
@ -209,7 +210,7 @@ public class ClientEntry extends Entry {
if (code != 200 && code != 201) { if (code != 200 && code != 201) {
throw new ProponoException("ERROR HTTP status=" + code + " : " + Utilities.streamToString(is)); throw new ProponoException("ERROR HTTP status=" + code + " : " + Utilities.streamToString(is));
} }
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), getCollection().getHrefResolved()); final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), getCollection().getHrefResolved(), Locale.US);
BeanUtils.copyProperties(this, romeEntry); BeanUtils.copyProperties(this, romeEntry);
} catch (final Exception e) { } catch (final Exception e) {

View file

@ -23,6 +23,7 @@ import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.Header;
@ -254,7 +255,7 @@ public class ClientMediaEntry extends ClientEntry {
} }
final InputStream is = method.getResponseBodyAsStream(); final InputStream is = method.getResponseBodyAsStream();
if (method.getStatusCode() == 200 || method.getStatusCode() == 201) { if (method.getStatusCode() == 200 || method.getStatusCode() == 201) {
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), col.getHrefResolved()); final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), col.getHrefResolved(), Locale.US);
BeanUtils.copyProperties(this, romeEntry); BeanUtils.copyProperties(this, romeEntry);
} else { } else {

View file

@ -19,6 +19,8 @@
*/ */
package org.rometools.propono.atom.common.rome; package org.rometools.propono.atom.common.rome;
import java.util.Locale;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.Namespace; import org.jdom2.Namespace;
@ -44,8 +46,7 @@ public class AppModuleParser implements ModuleParser {
/** Parse JDOM element into module */ /** Parse JDOM element into module */
@Override @Override
public Module parse(final Element elem) { public Module parse(final Element elem, final Locale locale) {
final boolean foundSomething = false;
final AppModule m = new AppModuleImpl(); final AppModule m = new AppModuleImpl();
final Element control = elem.getChild("control", getContentNamespace()); final Element control = elem.getChild("control", getContentNamespace());
if (control != null) { if (control != null) {
@ -62,7 +63,7 @@ public class AppModuleParser implements ModuleParser {
final Element edited = elem.getChild("edited", getContentNamespace()); final Element edited = elem.getChild("edited", getContentNamespace());
if (edited != null) { if (edited != null) {
try { try {
m.setEdited(DateParser.parseW3CDateTime(edited.getTextTrim())); m.setEdited(DateParser.parseW3CDateTime(edited.getTextTrim(), locale));
} catch (final Exception ignored) { } catch (final Exception ignored) {
} }
} }

View file

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Writer; import java.io.Writer;
import java.util.Collections; import java.util.Collections;
import java.util.Locale;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -174,7 +175,7 @@ public class AtomServlet extends HttpServlet {
if (req.getContentType().startsWith("application/atom+xml")) { if (req.getContentType().startsWith("application/atom+xml")) {
// parse incoming entry // parse incoming entry
final Entry entry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(req.getInputStream(), "UTF-8")), null); final Entry entry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(req.getInputStream(), "UTF-8")), null, Locale.US);
// call handler to post it // call handler to post it
final Entry newEntry = handler.postEntry(areq, entry); final Entry newEntry = handler.postEntry(areq, entry);
@ -277,7 +278,7 @@ public class AtomServlet extends HttpServlet {
if (handler.isEntryURI(areq)) { if (handler.isEntryURI(areq)) {
// parse incoming entry // parse incoming entry
final Entry unsavedEntry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(req.getInputStream(), "UTF-8")), null); final Entry unsavedEntry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(req.getInputStream(), "UTF-8")), null, Locale.US);
// call handler to put entry // call handler to put entry
handler.putEntry(areq, unsavedEntry); handler.putEntry(areq, unsavedEntry);

View file

@ -30,6 +30,7 @@ import java.util.Collections;
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.StringTokenizer; import java.util.StringTokenizer;
import javax.activation.FileTypeMap; import javax.activation.FileTypeMap;
@ -509,7 +510,7 @@ public class FileBasedCollection extends Collection {
private Entry loadAtomResourceEntry(final InputStream in, final File file) { private Entry loadAtomResourceEntry(final InputStream in, final File file) {
try { try {
final Entry entry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in)), null); final Entry entry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in)), null, Locale.US);
updateMediaEntryAppLinks(entry, file.getName(), true); updateMediaEntryAppLinks(entry, file.getName(), true);
return entry; return entry;
@ -615,7 +616,7 @@ public class FileBasedCollection extends Collection {
*/ */
private Entry loadAtomEntry(final InputStream in) { private Entry loadAtomEntry(final InputStream in) {
try { try {
return Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in, "UTF-8")), null); return Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in, "UTF-8")), null, Locale.US);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;