use of org.xwiki.rendering.converter.ConversionException in project xwiki-platform by xwiki.
the class FeedPlugin method saveEntry.
private void saveEntry(String feedname, String feedurl, SyndEntry entry, XWikiDocument doc, BaseObject obj, boolean fullContent, XWikiContext context) throws XWikiException {
obj.setStringValue("feedname", feedname);
obj.setStringValue("title", entry.getTitle());
// set document title to the feed title
String title;
try {
// Strips HTML tags that the feed can output, since they are not supported in document titles.
// (For example Google Blog search adds a <b> tag around matched keyword in title)
// If some day wiki syntax is supported in document titles, we might want to convert to wiki syntax instead.
title = this.stripHtmlTags(entry.getTitle());
} catch (ConversionException e) {
LOGGER.warn("Failed to strip HTML tags from entry title : " + e.getMessage());
// Nevermind, we will use the original title
title = entry.getTitle();
}
doc.setTitle(title);
obj.setIntValue("flag", 0);
@SuppressWarnings("unchecked") List<SyndCategory> categList = entry.getCategories();
StringBuffer categs = new StringBuffer("");
if (categList != null) {
for (SyndCategory categ : categList) {
if (categs.length() != 0) {
categs.append(", ");
}
categs.append(categ.getName());
}
}
obj.setStringValue("category", categs.toString());
StringBuffer contents = new StringBuffer("");
String description = (entry.getDescription() == null) ? null : entry.getDescription().getValue();
@SuppressWarnings("unchecked") List<SyndContent> contentList = entry.getContents();
if (contentList != null && contentList.size() > 0) {
for (SyndContent content : contentList) {
if (contents.length() != 0) {
contents.append("\n");
}
contents.append(content.getValue());
}
}
// If we find more data in the description we will use that one instead of the content field
if ((description != null) && (description.length() > contents.length())) {
obj.setLargeStringValue("content", description);
} else {
obj.setLargeStringValue("content", contents.toString());
}
Date edate = entry.getPublishedDate();
if (edate == null) {
edate = new Date();
}
obj.setDateValue("date", edate);
obj.setStringValue("url", entry.getLink());
obj.setStringValue("author", entry.getAuthor());
obj.setStringValue("feedurl", feedurl);
// TODO: need to get entry xml or serialization
// obj.setLargeStringValue("xml", entry.toString());
obj.setLargeStringValue("xml", "");
if (fullContent) {
String url = entry.getLink();
if ((url != null) && (!url.trim().equals(""))) {
try {
String sfullContent = context.getWiki().getURLContent(url, context);
obj.setLargeStringValue("fullContent", (sfullContent.length() > 65000) ? sfullContent.substring(0, 65000) : sfullContent);
} catch (Exception e) {
obj.setLargeStringValue("fullContent", "Exception while reading fullContent: " + e.getMessage());
}
} else {
obj.setLargeStringValue("fullContent", "No url");
}
}
}
Aggregations