Example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4.

Prototype

public static final String escapeHtml4(final String input) 

Source Link

Document

Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter"

becomes:

"bread" & "butter".

Usage

From source file:com.day.cq.wcm.foundation.forms.LayoutHelper.java

/**
 * Print the left column, title and required. This method creates a wrapper
 * div with the class form_leftcol, inside the divs are two divs, the first
 * one containing the label with the class form_leftcollabel. The second
 * inner div contains a star if the field is required, the div has the class
 * form_leftcolmark./*  w w w  .  ja va  2s  .c  o m*/
 * <p/>
 * The <code>title</code> is encoded using
 * {@link StringEscapeUtils#escapeHtml4(String)} before it is written to
 * the {@link Writer}.
 *
 * @param fieldId  The id of the field (not the name) - This can be null if
 *                 title is null.
 * @param title    The title of the field (or null)
 * @param required Flag indicating if this field is required.
 * @param hideLabel Option to completely hide the label (removes form_leftcollabel and form_leftcolmark 
 * divs content)
 * @param out      The writer.
 * @throws IOException If writing fails.
 * @since 5.4
 */
public static void printTitle(String fieldId, String title, boolean required, boolean hideLabel, Writer out)
        throws IOException {
    out.write("<div class=\"form_leftcol\"");
    if (hideLabel) {
        out.write(" style=\"display: none;\"");
    }
    if (title != null && title.length() > 0) {
        title = StringEscapeUtils.escapeHtml4(title);
    } else {
        title = "&nbsp;";
    }
    out.write(">");
    out.write("<div class=\"form_leftcollabel\">");
    if (fieldId != null) {
        fieldId = StringEscapeUtils.escapeHtml4(fieldId);
        out.write("<label for=\"" + fieldId + "\">" + title + "</label>");
    } else {
        out.write("<span>" + title + "</span>");
    }
    out.write("</div>");
    out.write("<div class=\"form_leftcolmark\">");
    if (!hideLabel) {
        if (required) {
            out.write(" *");
        } else {
            out.write("&nbsp;");
        }
    }
    out.write("</div>");
    out.write("</div>\n");
}

From source file:com.thoughtworks.go.domain.DefaultCommentRenderer.java

private String dynamicLink(Matcher matcher) {
    String linkWithRealId = StringEscapeUtils.escapeHtml4(link.replace("${ID}", id(matcher)));
    return String.format("<a href=\"%s\" target=\"story_tracker\">%s</a>", linkWithRealId, textOnLink(matcher));
}

From source file:com.olabini.jescov.generators.LineInfo.java

public String getCode() {
    return StringEscapeUtils.escapeHtml4(this.code);
}

From source file:com.primeleaf.krystal.web.view.console.SearchView.java

private void printSearchResults() throws Exception {
    printBreadCrumbs();/*from w  w  w. j  a va2s  .  c o m*/
    if (request.getAttribute(HTTPConstants.REQUEST_ERROR) != null) {
        printError((String) request.getAttribute(HTTPConstants.REQUEST_ERROR));
    }

    String searchText = request.getAttribute("SEARCHTEXT").toString();
    searchText = StringEscapeUtils.escapeHtml4(searchText);

    out.println("<div id=\"searchresults\">");

    out.println("<div class=\"panel panel-default\">");
    out.println("<div class=\"panel-heading\"><h4><i class=\"fa fa-lg fa-search\"></i> Search Results : "
            + searchText + " </h4></div>");
    out.println("</div>");

    printDocumentClasses();
    printDocuments();
    printDocumentNotes();

    out.println("<div class=\"well well-sm\">");
    out.println("Total time taken to retreive results : " + request.getAttribute("EXECUTIONTIME") + " seconds");
    out.println("</div>");

    out.println("</div>");

    String[] searchWords = searchText.split("\\s+");
    String classNames[] = { "highlight", "btn-danger", "btn-success", "btn-warning", "btn-default" };
    int i = 0;
    for (String searchWord : searchWords) {
        String className = classNames[i % 5];
        i++;
        out.println("<script>$(\"#searchresults \").highlight(\"" + StringEscapeUtils.escapeHtml4(searchWord)
                + "\",  { element: 'span', className: '" + className + "' });</script>");
    }
}

From source file:com.qwazr.webapps.exception.WebappException.java

private void sendQuietlyHTML(HttpServletResponse response) throws IOException {
    PrintWriter printWriter = response.getWriter();
    String message = StringEscapeUtils.escapeHtml4(error.message);
    response.setStatus(error.status);// w  w w.j a v  a2  s .com
    response.setContentType("text/html");
    printWriter.print("<html><head><title>");
    printWriter.print(error.title.title);
    printWriter.println("</title></head>");
    printWriter.print("<body><h3>");
    printWriter.print(error.title.title);
    printWriter.println("</h3>");
    printWriter.print("<pre>");
    printWriter.print(message);
    printWriter.println("</pre></body></html>");
}

From source file:net.java.sip.communicator.impl.gui.main.chat.replacers.KeywordReplacer.java

/**
 * Replace operation. Searches for the keyword in the provided piece of
 * content and replaces it with the piece of content surrounded by &lt;b&gt;
 * tags./*from  ww  w.  j  a va  2s . c o m*/
 *
 * @param target the destination to write the result to
 * @param piece the piece of content to process
 */
@Override
public void replace(final StringBuilder target, final String piece) {
    if (this.keyword == null || this.keyword.isEmpty()) {
        target.append(StringEscapeUtils.escapeHtml4(piece));
        return;
    }

    final Matcher m = Pattern
            .compile("(^|\\W)(" + Pattern.quote(keyword) + ")(\\W|$)", Pattern.CASE_INSENSITIVE).matcher(piece);
    int prevEnd = 0;
    while (m.find()) {
        target.append(StringEscapeUtils.escapeHtml4(
                piece.substring(prevEnd, m.start() + m.group(INDEX_OPTIONAL_PREFIX_GROUP).length())));
        prevEnd = m.end() - m.group(INDEX_OPTIONAL_SUFFIX_GROUP).length();
        final String keywordMatch = m.group(INDEX_KEYWORD_MATCH_GROUP).trim();
        target.append("<b>");
        target.append(StringEscapeUtils.escapeHtml4(keywordMatch));
        target.append("</b>");
    }
    target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd)));
}

From source file:com.day.cq.wcm.foundation.Sitemap.java

public void draw(Writer w) throws IOException {
    PrintWriter out = new PrintWriter(w);

    int previousLevel = -1;

    for (Link aLink : links) {
        if (aLink.getLevel() > previousLevel)
            out.print("<div class=\"linkcontainer\">");
        else if (aLink.getLevel() < previousLevel) {
            for (int i = aLink.getLevel(); i < previousLevel; i++)
                out.print("</div>");
        }//from   w w w .  j a va  2s.  c  om

        out.printf("<div class=\"link\"><a href=\"%s.html\">%s</a></div>",
                StringEscapeUtils.escapeHtml4(aLink.getPath()), aLink.getTitle());

        previousLevel = aLink.getLevel();
    }

    for (int i = -1; i < previousLevel; i++)
        out.print("</div>");
}

From source file:com.thruzero.common.web.model.container.builder.xml.XmlRssFeedPanelBuilder.java

@Override
public AbstractPanel build() throws Exception {
    int maxEntries = getPanelNode().getAttributeTransformer("size").getIntValue(5);
    int refreshRateInHours = getPanelNode().getAttributeTransformer("refreshRate").getIntValue(24);
    int quoteTooltipsCount = getPanelNode().getAttributeTransformer("quoteTooltipsCount").getIntValue(-1);
    String titleIcon = getPanelNode().getAttributeTransformer("titleIcon").getStringValue();
    boolean includeImage = getPanelNode().getAttributeTransformer("includeImage").getBooleanValue(false);
    String feedUrl = getPanelNode().getText();

    PerformanceLoggerHelper performanceLoggerHelper = new PerformanceLoggerHelper();
    RssFeedService service = ServiceLocator.locate(RssFeedService.class);
    RssFeed rssFeed = service.readRssFeed(maxEntries, feedUrl, refreshRateInHours, includeImage);
    performanceLoggerHelper.debug("readRssFeed [" + StringEscapeUtils.escapeHtml4(feedUrl) + "]");

    RssFeedPanel result = new RssFeedPanel(getPanelId(), getPanelTitle(), getPanelTitleLink(),
            getCollapseDirection(), isUseWhiteChevron(), getPanelHeaderStyleClass(), getToolbar(), rssFeed,
            quoteTooltipsCount, titleIcon);

    return result;
}

From source file:com.davis.bluefolder.EndpointException.java

/**
 * Since we always want to return the JSON representation of an instance of {@link
 * JsonApiResponse}, then we don't want to use this method since it's designed to just return a
 * string message./*from  w  w w.  j a v a2s. c  o  m*/
 *
 * @param message the message
 * @param status  the status
 */
@Deprecated
public EndpointException(String message, Status status) {
    super(Response.status(status).entity(StringEscapeUtils.escapeHtml4(message))
            .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).build());
}

From source file:com.silverware.ipdswizzler.EvernoteExporter.java

/**
 * Print a single memo.//from  www.ja v  a2 s  .co  m
 * 
 * @param printWriter
 * @param memo
 * @param index
 */
private void printMemo(PrintWriter printWriter, Memo memo, int index) {
    printWriter.println("<note>");

    String title = memo.getTitle();
    String content = memo.getContent();
    String[] tags = memo.getTags();

    if (title != null) {
        printWriter.printf("<title>%s</title>\n", StringEscapeUtils.escapeHtml4(title), index);
    }

    printWriter.print(
            "<content><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note>");

    if (content != null) {
        printContentAsHtml(printWriter, content);
    }

    printWriter.println("</en-note>]]></content>");

    if (tags != null) {
        for (int tagIndex = 0; tagIndex < tags.length; tagIndex++) {
            printWriter.printf("<tag>%s</tag>\n", StringEscapeUtils.escapeHtml4(tags[tagIndex]));
        }
    }

    printWriter.println("</note>");
}