Fixed bug in the feedparser and improved performance of date parsing

This commit is contained in:
daniel oeh 2012-06-23 21:47:37 +02:00
parent b7f9d066b9
commit f54593e2c1
2 changed files with 24 additions and 7 deletions

View File

@ -28,7 +28,9 @@ public class SyndHandler extends DefaultHandler {
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (localName.equals("image") || qName.equals("image")) {
Log.d(TAG, "Found image");
}
Namespace handler = getHandlingNamespace(uri);
if (handler != null) {
SyndElement element = handler.handleElementStart(localName, state,
@ -81,7 +83,7 @@ public class SyndHandler extends DefaultHandler {
private Namespace getHandlingNamespace(String uri) {
Namespace handler = state.namespaces.get(uri);
if (handler == null && !state.defaultNamespaces.empty()) {
if (handler == null && uri.equals(DEFAULT_PREFIX) &&!state.defaultNamespaces.empty()) {
handler = state.defaultNamespaces.peek();
}
return handler;

View File

@ -19,15 +19,31 @@ public class SyndDateUtils {
/** RFC 3339 date format for localtime dates with offset. */
public static final String RFC3339LOCAL = "yyyy-MM-dd'T'HH:mm:ssZ";
private static ThreadLocal<SimpleDateFormat> RFC822Formatter = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat(RFC822DAY, Locale.US);
}
};
private static ThreadLocal<SimpleDateFormat> RFC3339Formatter = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat(RFC3339UTC, Locale.US);
}
};
public static Date parseRFC822Date(final String date) {
Date result = null;
SimpleDateFormat format = new SimpleDateFormat(RFC822DAY, Locale.US);
SimpleDateFormat format = RFC822Formatter.get();
try {
result = format.parse(date);
} catch (ParseException e) {
e.printStackTrace();
format = new SimpleDateFormat(RFC822, Locale.US);
format.applyPattern(RFC822);
try {
result = format.parse(date);
} catch (ParseException e1) {
@ -40,16 +56,15 @@ public class SyndDateUtils {
public static Date parseRFC3339Date(final String date) {
Date result = null;
SimpleDateFormat format = null;
SimpleDateFormat format = RFC3339Formatter.get();
if (date.endsWith("Z")) {
format = new SimpleDateFormat(RFC3339UTC, Locale.US);
try {
result = format.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
} else {
format = new SimpleDateFormat(RFC3339LOCAL, Locale.US);
format.applyPattern(RFC3339LOCAL);
// remove last colon
StringBuffer buf = new StringBuffer(date.length() - 1);
int colonIdx = date.lastIndexOf(':');