encoded content is now properly rendered

This commit is contained in:
daniel oeh 2012-06-23 23:19:28 +02:00
parent cdc8adab8d
commit dc32fb843d
4 changed files with 31 additions and 52 deletions

View File

@ -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);
String url = "";
try {
url = URLEncoder.encode(item.getContentEncoded(), "utf-8")
.replaceAll("\\+", " ");
} catch (UnsupportedEncodingException e) {
url = "Page could not be loaded";
e.printStackTrace();
}
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();
}
}
};
*/
/*
* 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);

View File

@ -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

View File

@ -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;
}
}

View File

@ -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("&nbsp", " ");
symbols.put("&quot", "\"");
symbols.put("&amp", "&");
symbols.put("&lt", "<");
symbols.put("&gt", ">");
}
public static String unescape(final String source) {
String result = source;
for (String key : symbols.keySet()) {
result = result.replaceAll(key, symbols.get(key));
}
return result;
}
}