diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-06-23 21:47:37 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-06-23 21:47:37 +0200 |
commit | f54593e2c177c68a0fa3b4f8188eed1448641435 (patch) | |
tree | 37f8057c380e4c1942888890e094ea94664ebe1d /src/de/podfetcher | |
parent | b7f9d066b91fc5efe7e471ae080e885be649e1df (diff) | |
download | AntennaPod-f54593e2c177c68a0fa3b4f8188eed1448641435.zip |
Fixed bug in the feedparser and improved performance of date parsing
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r-- | src/de/podfetcher/syndication/handler/SyndHandler.java | 6 | ||||
-rw-r--r-- | src/de/podfetcher/syndication/util/SyndDateUtils.java | 25 |
2 files changed, 24 insertions, 7 deletions
diff --git a/src/de/podfetcher/syndication/handler/SyndHandler.java b/src/de/podfetcher/syndication/handler/SyndHandler.java index 5f61c9750..36dcd74c6 100644 --- a/src/de/podfetcher/syndication/handler/SyndHandler.java +++ b/src/de/podfetcher/syndication/handler/SyndHandler.java @@ -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; diff --git a/src/de/podfetcher/syndication/util/SyndDateUtils.java b/src/de/podfetcher/syndication/util/SyndDateUtils.java index 5059c4776..2559aaa77 100644 --- a/src/de/podfetcher/syndication/util/SyndDateUtils.java +++ b/src/de/podfetcher/syndication/util/SyndDateUtils.java @@ -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(':'); |