strip html from entry titles (closes #329)

This commit is contained in:
Athou
2013-06-24 10:18:07 +02:00
parent a8407a4a62
commit 268fb26220
2 changed files with 14 additions and 10 deletions

View File

@@ -40,7 +40,7 @@ import com.steadystate.css.parser.CSSOMParser;
public class FeedUtils {
protected static Logger log = LoggerFactory.getLogger(FeedUtils.class);
private static final List<String> ALLOWED_IFRAME_CSS_RULES = Arrays.asList(
"height", "width", "border");
private static final char[] DISALLOWED_IFRAME_CSS_RULE_CHARACTERS = new char[] {
@@ -105,7 +105,8 @@ public class FeedUtils {
return encoding;
}
public static String handleContent(String content, String baseUri) {
public static String handleContent(String content, String baseUri,
boolean keepTextOnly) {
if (StringUtils.isNotBlank(content)) {
baseUri = StringUtils.trimToEmpty(baseUri);
Whitelist whitelist = new Whitelist();
@@ -158,8 +159,12 @@ public class FeedUtils {
clean.outputSettings(new OutputSettings().escapeMode(
EscapeMode.base).prettyPrint(false));
content = clean.body().html();
Element body = clean.body();
if (keepTextOnly) {
content = body.text();
} else {
content = body.html();
}
}
return content;
}
@@ -375,8 +380,8 @@ public class FeedUtils {
for (Element element : elements) {
String href = element.attr("src");
if (href != null) {
String proxy = removeTrailingSlash(publicUrl) + "/rest/server/proxy?u="
+ imageProxyEncoder(href);
String proxy = removeTrailingSlash(publicUrl)
+ "/rest/server/proxy?u=" + imageProxyEncoder(href);
element.attr("src", proxy);
}
}

View File

@@ -43,11 +43,10 @@ public class FeedUpdateService {
FeedEntry update = null;
if (existing == null) {
FeedEntryContent content = entry.getContent();
content.setTitle(FeedUtils.truncate(
FeedUtils.handleContent(content.getTitle(), feed.getLink()),
2048));
content.setTitle(FeedUtils.truncate(FeedUtils.handleContent(
content.getTitle(), feed.getLink(), true), 2048));
content.setContent(FeedUtils.handleContent(content.getContent(),
feed.getLink()));
feed.getLink(), false));
entry.setInserted(Calendar.getInstance().getTime());
entry.getFeeds().add(feed);