diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-06-23 23:19:28 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-06-23 23:19:28 +0200 |
commit | dc32fb843d1408e2ca4a986caeb05dfa24a0f981 (patch) | |
tree | 8d2ec392a88464704e9d5cf7d66d0c67a86eb64f | |
parent | cdc8adab8d59f229eb93365ebbdf3a6f1673c689 (diff) | |
download | AntennaPod-dc32fb843d1408e2ca4a986caeb05dfa24a0f981.zip |
encoded content is now properly rendered
4 files changed, 31 insertions, 52 deletions
diff --git a/src/de/podfetcher/activity/ItemviewActivity.java b/src/de/podfetcher/activity/ItemviewActivity.java index 7d6565f38..3844ee8e0 100644 --- a/src/de/podfetcher/activity/ItemviewActivity.java +++ b/src/de/podfetcher/activity/ItemviewActivity.java @@ -1,5 +1,7 @@ package de.podfetcher.activity; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.text.DateFormat; import android.content.Intent; @@ -83,34 +85,35 @@ public class ItemviewActivity extends SherlockActivity { .getTime(), System.currentTimeMillis(), DateFormat.MEDIUM, DateFormat.SHORT)); txtvTitle.setText(item.getTitle()); - webvDescription.loadData(item.getContentEncoded(), "text/html", null); - } - -/* TODO implement - final DownloadObserver downloadObserver = new DownloadObserver(this) { - @Override - protected void onProgressUpdate( - DownloadStatus... values) { - + String url = ""; + try { + url = URLEncoder.encode(item.getContentEncoded(), "utf-8") + .replaceAll("\\+", " "); + } catch (UnsupportedEncodingException e) { + url = "Page could not be loaded"; + e.printStackTrace(); } - @Override - protected void onPostExecute(Boolean result) { - boolean r = getStatusList()[0].isSuccessful(); - if (r) { - //setDownloadedState(); - } else { - //setNotDownloadedState(); - } - } - }; - */ + webvDescription.loadData(url, "text/html", "utf-8"); + + } + + /* + * TODO implement final DownloadObserver downloadObserver = new + * DownloadObserver(this) { + * + * @Override protected void onProgressUpdate( DownloadStatus... values) { + * + * } + * + * @Override protected void onPostExecute(Boolean result) { boolean r = + * getStatusList()[0].isSuccessful(); if (r) { //setDownloadedState(); } + * else { //setNotDownloadedState(); } } }; + */ @Override public boolean onCreateOptionsMenu(Menu menu) { return FeedItemMenuHandler.onCreateMenu(new MenuInflater(this), menu); } - - @Override public boolean onOptionsItemSelected(MenuItem menuItem) { @@ -118,7 +121,7 @@ public class ItemviewActivity extends SherlockActivity { invalidateOptionsMenu(); return true; } - + @Override public boolean onPrepareOptionsMenu(Menu menu) { return FeedItemMenuHandler.onPrepareMenu(menu, item); diff --git a/src/de/podfetcher/syndication/namespace/atom/AtomText.java b/src/de/podfetcher/syndication/namespace/atom/AtomText.java index a80b48412..3669fc758 100644 --- a/src/de/podfetcher/syndication/namespace/atom/AtomText.java +++ b/src/de/podfetcher/syndication/namespace/atom/AtomText.java @@ -1,8 +1,9 @@ package de.podfetcher.syndication.namespace.atom; +import org.apache.commons.lang3.StringEscapeUtils; + import de.podfetcher.syndication.namespace.Namespace; import de.podfetcher.syndication.namespace.SyndElement; -import de.podfetcher.syndication.util.HtmlUnescaper; /** Represents Atom Element which contains text (content, title, summary). */ public class AtomText extends SyndElement { @@ -21,7 +22,7 @@ public class AtomText extends SyndElement { /** Processes the content according to the type and returns it. */ public String getProcessedContent() { if (type.equals(TYPE_HTML)) { - return HtmlUnescaper.unescape(content); + return StringEscapeUtils.unescapeHtml4(content); } else if (type.equals(TYPE_XHTML)) { return content; } else { // Handle as text by default diff --git a/src/de/podfetcher/syndication/namespace/content/NSContent.java b/src/de/podfetcher/syndication/namespace/content/NSContent.java index 8f5187518..d9f3501c9 100644 --- a/src/de/podfetcher/syndication/namespace/content/NSContent.java +++ b/src/de/podfetcher/syndication/namespace/content/NSContent.java @@ -6,6 +6,7 @@ import de.podfetcher.syndication.handler.HandlerState; import de.podfetcher.syndication.namespace.Namespace; import de.podfetcher.syndication.namespace.SyndElement; import de.podfetcher.syndication.namespace.rss20.NSRSS20; +import org.apache.commons.lang3.StringEscapeUtils; public class NSContent extends Namespace { public static final String NSTAG = "content"; @@ -43,7 +44,7 @@ public class NSContent extends Namespace { @Override public void handleElementEnd(String localName, HandlerState state) { if (localName.equals(ENCODED)) { - state.getCurrentItem().setContentEncoded(encoded.toString()); + state.getCurrentItem().setContentEncoded(StringEscapeUtils.unescapeHtml4(encoded.toString())); encoded = null; } } diff --git a/src/de/podfetcher/syndication/util/HtmlUnescaper.java b/src/de/podfetcher/syndication/util/HtmlUnescaper.java deleted file mode 100644 index 703f17ec3..000000000 --- a/src/de/podfetcher/syndication/util/HtmlUnescaper.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.podfetcher.syndication.util; - -import java.util.HashMap; - -/** Unescapes HTML */ -public class HtmlUnescaper { - private static HashMap<String, String> symbols; - - static { - symbols = new HashMap<String, String>(); - symbols.put(" ", " "); - symbols.put(""", "\""); - symbols.put("&", "&"); - symbols.put("<", "<"); - symbols.put(">", ">"); - - } - - public static String unescape(final String source) { - String result = source; - for (String key : symbols.keySet()) { - result = result.replaceAll(key, symbols.get(key)); - } - return result; - } -} |