forked from Archives/Athou_commafeed
strip html from entry titles (closes #329)
This commit is contained in:
@@ -40,7 +40,7 @@ import com.steadystate.css.parser.CSSOMParser;
|
|||||||
public class FeedUtils {
|
public class FeedUtils {
|
||||||
|
|
||||||
protected static Logger log = LoggerFactory.getLogger(FeedUtils.class);
|
protected static Logger log = LoggerFactory.getLogger(FeedUtils.class);
|
||||||
|
|
||||||
private static final List<String> ALLOWED_IFRAME_CSS_RULES = Arrays.asList(
|
private static final List<String> ALLOWED_IFRAME_CSS_RULES = Arrays.asList(
|
||||||
"height", "width", "border");
|
"height", "width", "border");
|
||||||
private static final char[] DISALLOWED_IFRAME_CSS_RULE_CHARACTERS = new char[] {
|
private static final char[] DISALLOWED_IFRAME_CSS_RULE_CHARACTERS = new char[] {
|
||||||
@@ -105,7 +105,8 @@ public class FeedUtils {
|
|||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String handleContent(String content, String baseUri) {
|
public static String handleContent(String content, String baseUri,
|
||||||
|
boolean keepTextOnly) {
|
||||||
if (StringUtils.isNotBlank(content)) {
|
if (StringUtils.isNotBlank(content)) {
|
||||||
baseUri = StringUtils.trimToEmpty(baseUri);
|
baseUri = StringUtils.trimToEmpty(baseUri);
|
||||||
Whitelist whitelist = new Whitelist();
|
Whitelist whitelist = new Whitelist();
|
||||||
@@ -158,8 +159,12 @@ public class FeedUtils {
|
|||||||
|
|
||||||
clean.outputSettings(new OutputSettings().escapeMode(
|
clean.outputSettings(new OutputSettings().escapeMode(
|
||||||
EscapeMode.base).prettyPrint(false));
|
EscapeMode.base).prettyPrint(false));
|
||||||
content = clean.body().html();
|
Element body = clean.body();
|
||||||
|
if (keepTextOnly) {
|
||||||
|
content = body.text();
|
||||||
|
} else {
|
||||||
|
content = body.html();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
@@ -375,8 +380,8 @@ public class FeedUtils {
|
|||||||
for (Element element : elements) {
|
for (Element element : elements) {
|
||||||
String href = element.attr("src");
|
String href = element.attr("src");
|
||||||
if (href != null) {
|
if (href != null) {
|
||||||
String proxy = removeTrailingSlash(publicUrl) + "/rest/server/proxy?u="
|
String proxy = removeTrailingSlash(publicUrl)
|
||||||
+ imageProxyEncoder(href);
|
+ "/rest/server/proxy?u=" + imageProxyEncoder(href);
|
||||||
element.attr("src", proxy);
|
element.attr("src", proxy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,10 @@ public class FeedUpdateService {
|
|||||||
FeedEntry update = null;
|
FeedEntry update = null;
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
FeedEntryContent content = entry.getContent();
|
FeedEntryContent content = entry.getContent();
|
||||||
content.setTitle(FeedUtils.truncate(
|
content.setTitle(FeedUtils.truncate(FeedUtils.handleContent(
|
||||||
FeedUtils.handleContent(content.getTitle(), feed.getLink()),
|
content.getTitle(), feed.getLink(), true), 2048));
|
||||||
2048));
|
|
||||||
content.setContent(FeedUtils.handleContent(content.getContent(),
|
content.setContent(FeedUtils.handleContent(content.getContent(),
|
||||||
feed.getLink()));
|
feed.getLink(), false));
|
||||||
|
|
||||||
entry.setInserted(Calendar.getInstance().getTime());
|
entry.setInserted(Calendar.getInstance().getTime());
|
||||||
entry.getFeeds().add(feed);
|
entry.getFeeds().add(feed);
|
||||||
|
|||||||
Reference in New Issue
Block a user