List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4
public static final String escapeHtml4(final String input)
Escapes the characters in a String using HTML entities.
For example:
"bread" & "butter"
"bread" & "butter"
.
From source file:com.lucas.analytics.controller.ml.SearchController.java
public static Search getSearch(String query) throws IOException { ObjectMapper mapper = new ObjectMapper(); String noWhitespace = query.replace(" ", "+"); String targetUrl = baseUrl + "?q=" + StringEscapeUtils.escapeHtml4(noWhitespace) + "&limit=10"; System.out.println("targetUrl: " + targetUrl); return mapper.readValue(Request.Get(targetUrl).execute().returnContent().asString(), Search.class); }
From source file:de.vanita5.twittnuker.util.HtmlEscapeHelper.java
public static String escape(final String string) { if (string == null) return null; return StringEscapeUtils.escapeHtml4(string); }
From source file:com.denimgroup.threadfix.util.ValidationUtils.java
public static boolean containsHTML(String input) { return input != null && !input.equals(StringEscapeUtils.escapeHtml4(input)); }
From source file:de.akra.idocit.java.utils.StringUtils.java
/** * Escapes the special characters in the given string with HTML entities. Tabs and * line breaks are replaced with their corresponding HTML entities as well. * //from w w w .jav a 2 s.c om * @param unescapedText * [SOURCE] The text to escape * * @return [OBJECT] The escaped text */ public static String escapeHtml(final String unescapedText) { final String escapedText = StringEscapeUtils.escapeHtml4(unescapedText); final StringBuilder tmpText = new StringBuilder(); for (int i = 0; i < escapedText.length(); ++i) { switch (escapedText.charAt(i)) { case '\t': tmpText.append(XML_TAG_TAB); break; case '\r': tmpText.append(XML_TAG_BR); // if CR and LF are together, replace it only once // Changes due to Issue #2 if ((escapedText.length() > i + 1) && escapedText.charAt(i + 1) == '\n') // End changes due to Issue #2 { i++; } break; case '\n': tmpText.append(XML_TAG_BR); // if CR and LF are together, replace it only once // Changes due to Issue #2 if ((escapedText.length() > i + 1) && escapedText.charAt(i + 1) == '\r') // End changes due to Issue #2 { i++; } break; default: tmpText.append(escapedText.charAt(i)); break; } } return tmpText.toString(); }
From source file:com.vmware.identity.openidconnect.common.State.java
private static boolean htmlFriendly(String value) { return Objects.equals(value, StringEscapeUtils.escapeHtml4(value)); }
From source file:mobisocial.musubi.ui.util.FeedHTML.java
public static void writeHeader(FileOutputStream fo, FeedManager feedManager, MFeed feed) { PrintWriter w = new PrintWriter(fo); w.print("<html>"); w.print("<head>"); w.print("<title>"); w.print(StringEscapeUtils.escapeHtml4(UiUtil.getFeedNameFromMembersList(feedManager, feed))); w.print("</title>"); w.print("</head>"); w.print("<body>"); w.print("<h1>"); w.print(StringEscapeUtils.escapeHtml4(UiUtil.getFeedNameFromMembersList(feedManager, feed))); w.print("</h1>"); w.flush();// w w w .ja v a 2 s . c o m }
From source file:net.longfalcon.taglib.TextFunctions.java
public static String escapeHtml(String s) { return StringEscapeUtils.escapeHtml4(s); }
From source file:com.orange.wro.taglib.tag.HtmlIncludeTag.java
@Override protected String quote(String str) { return StringEscapeUtils.escapeHtml4(str); }
From source file:de.wbuecke.codec.HtmlInput.java
@Override public String encode(String plaintext) { return StringEscapeUtils.escapeHtml4(plaintext); }
From source file:jease.site.Discussions.java
/** * Adds a comment with given values to given Discussion. Visible flag * indicates if added comment should be visible or not. * // www . j av a 2 s .com * Returns null on success, otherwise an error message. */ public static String addComment(Discussion discussion, String author, String subject, String comment, boolean visible) { if (StringUtils.isBlank(subject) || StringUtils.isBlank(author) || StringUtils.isBlank(comment)) { return I18N.get("All_fields_are_required"); } if (subject.length() > MAX_SUBJECT_LENGTH || author.length() > MAX_AUTHOR_LENGTH || comment.length() > MAX_COMMENT_LENGTH) { return I18N.get("Input_is_too_long"); } // Escape all user input subject = StringEscapeUtils.escapeHtml4(subject); author = StringEscapeUtils.escapeHtml4(author); comment = StringEscapeUtils.escapeHtml4(comment); // Save comment to database. discussion.addComment(subject, author, comment, visible); Nodes.save(discussion); // Send email for review to editor in charge. String recipient = discussion.getEditor().getEmail(); if (StringUtils.isNotBlank(recipient)) { Mails.dispatch(recipient, recipient, String.format("%s (%s)", subject, author), comment); } return null; }