Fixed bug in the feedparser and improved performance of date parsing
This commit is contained in:
parent
b7f9d066b9
commit
f54593e2c1
|
@ -28,7 +28,9 @@ public class SyndHandler extends DefaultHandler {
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName,
|
public void startElement(String uri, String localName, String qName,
|
||||||
Attributes attributes) throws SAXException {
|
Attributes attributes) throws SAXException {
|
||||||
|
if (localName.equals("image") || qName.equals("image")) {
|
||||||
|
Log.d(TAG, "Found image");
|
||||||
|
}
|
||||||
Namespace handler = getHandlingNamespace(uri);
|
Namespace handler = getHandlingNamespace(uri);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
SyndElement element = handler.handleElementStart(localName, state,
|
SyndElement element = handler.handleElementStart(localName, state,
|
||||||
|
@ -81,7 +83,7 @@ public class SyndHandler extends DefaultHandler {
|
||||||
|
|
||||||
private Namespace getHandlingNamespace(String uri) {
|
private Namespace getHandlingNamespace(String uri) {
|
||||||
Namespace handler = state.namespaces.get(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();
|
handler = state.defaultNamespaces.peek();
|
||||||
}
|
}
|
||||||
return handler;
|
return handler;
|
||||||
|
|
|
@ -20,14 +20,30 @@ public class SyndDateUtils {
|
||||||
/** RFC 3339 date format for localtime dates with offset. */
|
/** RFC 3339 date format for localtime dates with offset. */
|
||||||
public static final String RFC3339LOCAL = "yyyy-MM-dd'T'HH:mm:ssZ";
|
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) {
|
public static Date parseRFC822Date(final String date) {
|
||||||
Date result = null;
|
Date result = null;
|
||||||
SimpleDateFormat format = new SimpleDateFormat(RFC822DAY, Locale.US);
|
SimpleDateFormat format = RFC822Formatter.get();
|
||||||
try {
|
try {
|
||||||
result = format.parse(date);
|
result = format.parse(date);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
format = new SimpleDateFormat(RFC822, Locale.US);
|
format.applyPattern(RFC822);
|
||||||
try {
|
try {
|
||||||
result = format.parse(date);
|
result = format.parse(date);
|
||||||
} catch (ParseException e1) {
|
} catch (ParseException e1) {
|
||||||
|
@ -40,16 +56,15 @@ public class SyndDateUtils {
|
||||||
|
|
||||||
public static Date parseRFC3339Date(final String date) {
|
public static Date parseRFC3339Date(final String date) {
|
||||||
Date result = null;
|
Date result = null;
|
||||||
SimpleDateFormat format = null;
|
SimpleDateFormat format = RFC3339Formatter.get();
|
||||||
if (date.endsWith("Z")) {
|
if (date.endsWith("Z")) {
|
||||||
format = new SimpleDateFormat(RFC3339UTC, Locale.US);
|
|
||||||
try {
|
try {
|
||||||
result = format.parse(date);
|
result = format.parse(date);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
format = new SimpleDateFormat(RFC3339LOCAL, Locale.US);
|
format.applyPattern(RFC3339LOCAL);
|
||||||
// remove last colon
|
// remove last colon
|
||||||
StringBuffer buf = new StringBuffer(date.length() - 1);
|
StringBuffer buf = new StringBuffer(date.length() - 1);
|
||||||
int colonIdx = date.lastIndexOf(':');
|
int colonIdx = date.lastIndexOf(':');
|
||||||
|
|
Loading…
Reference in New Issue