diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-06-24 17:08:16 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-06-24 17:08:16 +0200 |
commit | e3115f1ae4f89b75fecf3c5e3763b4b38cc09899 (patch) | |
tree | d18d7116b204c98b4d67581407f2c6e9d0f03501 /src/de/podfetcher/syndication/handler | |
parent | e128e6fd6e91064163b7c857609a73c4b5413fa6 (diff) | |
download | AntennaPod-e3115f1ae4f89b75fecf3c5e3763b4b38cc09899.zip |
Switched to StringBuffer-method for getting characters in Feedparser
Diffstat (limited to 'src/de/podfetcher/syndication/handler')
-rw-r--r-- | src/de/podfetcher/syndication/handler/HandlerState.java | 8 | ||||
-rw-r--r-- | src/de/podfetcher/syndication/handler/SyndHandler.java | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/de/podfetcher/syndication/handler/HandlerState.java b/src/de/podfetcher/syndication/handler/HandlerState.java index a95cae6f0..4488fd8fa 100644 --- a/src/de/podfetcher/syndication/handler/HandlerState.java +++ b/src/de/podfetcher/syndication/handler/HandlerState.java @@ -11,6 +11,7 @@ import de.podfetcher.feed.FeedItem; /** Contains all relevant information to describe the current state of a SyndHandler.*/ public class HandlerState { + /** Feed that the Handler is currently processing. */ protected Feed feed; protected FeedItem currentItem; @@ -18,6 +19,8 @@ public class HandlerState { /** Namespaces that have been defined so far. */ protected HashMap<String, Namespace> namespaces; protected Stack<Namespace> defaultNamespaces; + /** Buffer for saving characters. */ + protected StringBuffer contentBuf; public HandlerState(Feed feed) { this.feed = feed; @@ -55,6 +58,11 @@ public class HandlerState { return second; } + public StringBuffer getContentBuf() { + return contentBuf; + } + + diff --git a/src/de/podfetcher/syndication/handler/SyndHandler.java b/src/de/podfetcher/syndication/handler/SyndHandler.java index 795e3a24a..3cecabd64 100644 --- a/src/de/podfetcher/syndication/handler/SyndHandler.java +++ b/src/de/podfetcher/syndication/handler/SyndHandler.java @@ -20,6 +20,7 @@ public class SyndHandler extends DefaultHandler { private static final String DEFAULT_PREFIX = ""; protected HandlerState state; + public SyndHandler(Feed feed, TypeGetter.Type type) { state = new HandlerState(feed); if (type == TypeGetter.Type.RSS20) { @@ -30,6 +31,7 @@ public class SyndHandler extends DefaultHandler { @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + state.contentBuf = new StringBuffer(); Namespace handler = getHandlingNamespace(uri); if (handler != null) { SyndElement element = handler.handleElementStart(localName, state, @@ -43,6 +45,12 @@ public class SyndHandler extends DefaultHandler { public void characters(char[] ch, int start, int length) throws SAXException { if (!state.tagstack.empty()) { + if (state.getTagstack().size() >= 2) { + if (state.contentBuf != null) { + String content = new String(ch, start, length); + state.contentBuf.append(content); + } + } SyndElement top = state.tagstack.peek(); if (top.getNamespace() != null) { top.getNamespace().handleCharacters(state, ch, start, length); @@ -59,6 +67,7 @@ public class SyndHandler extends DefaultHandler { state.tagstack.pop(); } + state.contentBuf = null; } |