Java Code Examples for org.apache.commons.lang3.StringEscapeUtils.escapeXml()

The following are Jave code examples for showing how to use escapeXml() of the org.apache.commons.lang3.StringEscapeUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: solo-spring   File: FeedProcessor.java   View Source Code Vote up 5 votes
private Entry getEntry(final boolean hasMultipleUsers, String authorName, final JSONArray articles,
		final boolean isFullContent, int i) throws org.json.JSONException, org.b3log.solo.service.ServiceException {
	final JSONObject article = articles.getJSONObject(i);
	final Entry ret = new Entry();
	final String title = StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_TITLE));
	ret.setTitle(title);
	final String summary = isFullContent ? StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_CONTENT))
			: StringEscapeUtils.escapeXml(article.optString(Article.ARTICLE_ABSTRACT));
	ret.setSummary(summary);
	final Date updated = (Date) article.get(Article.ARTICLE_UPDATE_DATE);
	ret.setUpdated(updated);
	final String link = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
	ret.setLink(link);
	ret.setId(link);
	if (hasMultipleUsers) {
		authorName = StringEscapeUtils.escapeXml(articleQueryService.getAuthor(article).getString(User.USER_NAME));
	}
	ret.setAuthor(authorName);
	final String tagsString = article.getString(Article.ARTICLE_TAGS_REF);
	final String[] tagStrings = tagsString.split(",");
	for (final String tagString : tagStrings) {
		final Category catetory = new Category();
		ret.addCatetory(catetory);
		final String tag = tagString;
		catetory.setTerm(tag);
	}

	return ret;
}
 
Example 2
Project: solo-spring   File: FeedProcessor.java   View Source Code Vote up 5 votes
private Entry getEntryForArticle(final List<JSONObject> articles, final boolean hasMultipleUsers, String authorName,
		final boolean isFullContent, int i) throws org.json.JSONException, org.b3log.solo.service.ServiceException {
	final JSONObject article = articles.get(i);
	final Entry ret = new Entry();
	final String title = StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_TITLE));
	ret.setTitle(title);
	final String summary = isFullContent ? StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_CONTENT))
			: StringEscapeUtils.escapeXml(article.optString(Article.ARTICLE_ABSTRACT));
	ret.setSummary(summary);
	final Date updated = (Date) article.get(Article.ARTICLE_UPDATE_DATE);
	ret.setUpdated(updated);
	final String link = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
	ret.setLink(link);
	ret.setId(link);
	if (hasMultipleUsers) {
		authorName = StringEscapeUtils.escapeXml(articleQueryService.getAuthor(article).getString(User.USER_NAME));
	}
	ret.setAuthor(authorName);
	final String tagsString = article.getString(Article.ARTICLE_TAGS_REF);
	final String[] tagStrings = tagsString.split(",");
	for (final String tagString : tagStrings) {
		final Category catetory = new Category();
		ret.addCatetory(catetory);
		catetory.setTerm(tagString);
	}

	return ret;
}
 
Example 3
Project: solo-spring   File: FeedProcessor.java   View Source Code Vote up 5 votes
private Item getItem(final JSONArray articles, final boolean hasMultipleUsers, String authorName,
		final boolean isFullContent, int i) throws org.json.JSONException, org.b3log.solo.service.ServiceException {
	final JSONObject article = articles.getJSONObject(i);
	final Item ret = new Item();
	final String title = StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_TITLE));
	ret.setTitle(title);
	final String description = isFullContent
			? StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_CONTENT))
			: StringEscapeUtils.escapeXml(article.optString(Article.ARTICLE_ABSTRACT));
	ret.setDescription(description);
	final Date pubDate = (Date) article.get(Article.ARTICLE_UPDATE_DATE);
	ret.setPubDate(pubDate);
	final String link = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
	ret.setLink(link);
	ret.setGUID(link);
	final String authorEmail = article.getString(Article.ARTICLE_AUTHOR_EMAIL);
	if (hasMultipleUsers) {
		authorName = StringEscapeUtils.escapeXml(articleQueryService.getAuthor(article).getString(User.USER_NAME));
	}
	ret.setAuthor(authorEmail + "(" + authorName + ")");
	final String tagsString = article.getString(Article.ARTICLE_TAGS_REF);
	final String[] tagStrings = tagsString.split(",");
	for (final String tagString : tagStrings) {
		final org.b3log.solo.model.feed.rss.Category catetory = new org.b3log.solo.model.feed.rss.Category();
		ret.addCatetory(catetory);
		final String tag = tagString;
		catetory.setTerm(tag);
	}

	return ret;
}
 
Example 4
Project: solo-spring   File: FeedProcessor.java   View Source Code Vote up 5 votes
private Item getItemForArticles(final List<JSONObject> articles, final boolean hasMultipleUsers, String authorName,
		final boolean isFullContent, int i) throws org.json.JSONException, org.b3log.solo.service.ServiceException {
	final JSONObject article = articles.get(i);
	final Item ret = new Item();
	final String title = StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_TITLE));
	ret.setTitle(title);
	final String description = isFullContent
			? StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_CONTENT))
			: StringEscapeUtils.escapeXml(article.optString(Article.ARTICLE_ABSTRACT));
	ret.setDescription(description);
	final Date pubDate = (Date) article.get(Article.ARTICLE_UPDATE_DATE);
	ret.setPubDate(pubDate);
	final String link = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
	ret.setLink(link);
	ret.setGUID(link);
	final String authorEmail = article.getString(Article.ARTICLE_AUTHOR_EMAIL);
	if (hasMultipleUsers) {
		authorName = StringEscapeUtils.escapeXml(articleQueryService.getAuthor(article).getString(User.USER_NAME));
	}
	ret.setAuthor(authorEmail + "(" + authorName + ")");
	final String tagsString = article.getString(Article.ARTICLE_TAGS_REF);
	final String[] tagStrings = tagsString.split(",");
	for (final String tagString : tagStrings) {
		final org.b3log.solo.model.feed.rss.Category catetory = new org.b3log.solo.model.feed.rss.Category();
		ret.addCatetory(catetory);
		catetory.setTerm(tagString);
	}

	return ret;
}
 
Example 5
Project: solo-spring   File: MetaWeblogAPI.java   View Source Code Vote up 5 votes
/**
 * Builds a post (post struct) with the specified post id.
 *
 * @param postId
 *            the specified post id
 * @return blog info XML
 * @throws Exception
 *             exception
 */
private String buildPost(final String postId) throws Exception {
	final StringBuilder stringBuilder = new StringBuilder();

	final JSONObject result = articleQueryService.getArticle(postId);

	if (null == result) {
		throw new Exception("Not found article[id=" + postId + "]");
	}

	final JSONObject article = result.getJSONObject(Article.ARTICLE);

	final Date createDate = (Date) article.get(Article.ARTICLE_CREATE_DATE);
	final String articleTitle = StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_TITLE));

	stringBuilder.append("<struct>");

	stringBuilder.append("<member><name>dateCreated</name>").append("<value><dateTime.iso8601>")
			.append(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(createDate))
			.append("</dateTime.iso8601></value></member>");

	stringBuilder.append("<member><name>description</name>").append("<value>")
			.append(StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_CONTENT)))
			.append("</value></member>");

	stringBuilder.append("<member><name>title</name>").append("<value>").append(articleTitle)
			.append("</value></member>");

	stringBuilder.append("<member><name>categories</name>").append("<value><array><data>");
	final JSONArray tags = article.getJSONArray(Article.ARTICLE_TAGS_REF);

	for (int i = 0; i < tags.length(); i++) {
		final String tagTitle = tags.getJSONObject(i).getString(Tag.TAG_TITLE);

		stringBuilder.append("<value>").append(tagTitle).append("</value>");
	}
	stringBuilder.append("</data></array></value></member></struct>");

	return stringBuilder.toString();
}
 
Example 6
Project: solo-spring   File: MetaWeblogAPI.java   View Source Code Vote up 5 votes
/**
 * Builds categories (array of category info structs) with the specified
 * preference.
 *
 * @return blog info XML
 * @throws Exception
 *             exception
 */
private String buildCategories() throws Exception {
	final StringBuilder stringBuilder = new StringBuilder();

	final List<JSONObject> tags = tagQueryService.getTags();

	for (final JSONObject tag : tags) {
		final String tagTitle = StringEscapeUtils.escapeXml(tag.getString(Tag.TAG_TITLE));
		final String tagId = tag.getString(Keys.OBJECT_ID);

		stringBuilder.append("<value><struct>");

		stringBuilder.append("<member><name>description</name>").append("<value>").append(tagTitle)
				.append("</value></member>");

		stringBuilder.append("<member><name>title</name>").append("<value>").append(tagTitle)
				.append("</value></member>");

		stringBuilder.append("<member><name>categoryid</name>").append("<value>").append(tagId)
				.append("</value></member>");

		stringBuilder.append("<member><name>htmlUrl</name>").append("<value>").append(Latkes.getServePath())
				.append("/tags/").append(tagTitle).append("</value></member>");

		stringBuilder.append("<member><name>rsslUrl</name>").append("<value>").append(Latkes.getServePath())
				.append("/tag-articles-rss.do?oId=").append(tagId).append("</value></member>");
		stringBuilder.append("</struct></value>");
	}

	return stringBuilder.toString();
}
 
Example 7
Project: solo-spring   File: MetaWeblogAPI.java   View Source Code Vote up 5 votes
/**
 * Builds blog info struct with the specified preference.
 *
 * @param preference
 *            the specified preference
 * @return blog info XML
 * @throws JSONException
 *             json exception
 */
private String buildBlogInfo(final JSONObject preference) throws JSONException {
	final String blogId = preference.getString(Keys.OBJECT_ID);

	final String blogTitle = StringEscapeUtils.escapeXml(preference.getString(Option.ID_C_BLOG_TITLE));

	final StringBuilder stringBuilder = new StringBuilder("<member><name>blogid</name><value>").append(blogId)
			.append("</value></member>");

	stringBuilder.append("<member><name>url</name><value>").append(Latkes.getServePath())
			.append("</value></member>");
	stringBuilder.append("<member><name>blogName</name><value>").append(blogTitle).append("</value></member>");

	return stringBuilder.toString();
}
 
Example 8
Project: solo-spring   File: MetaWeblogAPI.java   View Source Code Vote up 4 votes
/**
 * Builds recent posts (array of post structs) with the specified fetch
 * size.
 *
 * @param fetchSize
 *            the specified fetch size
 * @return blog info XML
 * @throws Exception
 *             exception
 */
private String buildRecentPosts(final int fetchSize) throws Exception {

	final StringBuilder stringBuilder = new StringBuilder();

	final List<JSONObject> recentArticles = articleQueryService.getRecentArticles(fetchSize);

	for (final JSONObject article : recentArticles) {
		final Date createDate = (Date) article.get(Article.ARTICLE_CREATE_DATE);
		final String articleTitle = StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_TITLE));

		stringBuilder.append("<value><struct>");

		stringBuilder.append("<member><name>dateCreated</name>").append("<value><dateTime.iso8601>")
				.append(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(createDate))
				.append("</dateTime.iso8601></value></member>");

		stringBuilder.append("<member><name>description</name>").append("<value>")
				.append(StringEscapeUtils.escapeXml(article.getString(Article.ARTICLE_CONTENT)))
				.append("</value></member>");

		stringBuilder.append("<member><name>title</name>").append("<value>").append(articleTitle)
				.append("</value></member>");

		stringBuilder.append("<member><name>postid</name>").append("<value>")
				.append(article.getString(Keys.OBJECT_ID)).append("</value></member>");

		stringBuilder.append("<member><name>categories</name>").append("<value><array><data>");
		final String tagTitles = article.getString(Article.ARTICLE_TAGS_REF);
		final String[] tagTitleArray = tagTitles.split(",");

		for (int i = 0; i < tagTitleArray.length; i++) {
			final String tagTitle = tagTitleArray[i];

			stringBuilder.append("<value>").append(tagTitle).append("</value>");
		}
		stringBuilder.append("</data></array></value></member>");

		stringBuilder.append("</struct></value>");
	}

	return stringBuilder.toString();
}
 
Example 9
Project: opencron   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
    return StringEscapeUtils.escapeXml(xml);
}
 
Example 10
Project: shepher   File: ReviewUtil.java   View Source Code Vote up 4 votes
public static String generateSummary(String content) {
    String summary = StringEscapeUtils.escapeXml(content);
    summary = StringUtils.substring(summary, 0, 50);
    return summary;
}