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.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java

private void createHTMLscope(StringBuilder html, Space space, AnalyticsQuery query) {
    html.append(//w  w  w  . j a  v a  2  s  . c o  m
            "<fieldset><legend>Query scope: <i>this is the list of objects you can combine to build expressions in the query</i></legend>");
    html.append("<table>");
    html.append("<tr><td></td><td>You can Drag & Drop expression into input fields</td></tr>");
    html.append("<tr><td>GroupBy:</td><td>");
    for (Axis axis : space.A(true)) {// only print the visible scope
        try {
            IDomain image = axis.getDefinitionSafe().getImageDomain();
            if (!image.isInstanceOf(IDomain.OBJECT)) {
                DimensionIndex index = axis.getIndex();
                html.append("<span draggable='true' style='" + axis_style + "'");
                ExpressionAST expr = axis.getDefinitionSafe();
                html.append("title='" + getExpressionValueType(expr).toString() + ": ");
                if (axis.getDescription() != null) {
                    html.append(axis.getDescription());
                }
                if (index.getErrorMessage() != null) {
                    html.append("\nError:" + index.getErrorMessage());
                }
                html.append("'");
                html.append(" ondragstart='drag(event,\"" + index.getDimensionName() + "\")'>");
                if (index.getErrorMessage() == null) {
                    html.append("&nbsp;" + index.getDimensionName() + "&nbsp;");
                } else {
                    html.append("&nbsp;<del>" + index.getDimensionName() + "</del>&nbsp;");
                }
                html.append("</span>");
            }
        } catch (Exception e) {
            // ignore
        }
    }
    html.append("</td></tr>");
    html.append("<tr><td>Metrics:</td><td>");
    for (Measure m : space.M()) {
        if (m.getMetric() != null && !m.getMetric().isDynamic()) {
            html.append("<span draggable='true'  style='" + metric_style + "'");
            ExpressionAST expr = m.getDefinitionSafe();
            html.append("title='" + getExpressionValueType(expr).toString() + ": ");
            if (m.getDescription() != null) {
                html.append(m.getDescription());
            }
            html.append("'");
            html.append(" ondragstart='drag(event,\"" + m.getName() + "\")'");
            html.append(">&nbsp;" + m.getName() + "&nbsp;</span>");
        }
    }
    html.append("</td></tr></table>");
    URI scopeLink = getPublicBaseUriBuilder().path("/analytics/{reference}/scope")
            .queryParam("style", Style.HTML).queryParam("access_token", userContext.getToken().getOid())
            .build(query.getBBID());
    html.append(
            "<a href=\"" + StringEscapeUtils.escapeHtml4(scopeLink.toASCIIString()) + "\">View the scope</a>");
    html.append("</fieldset>");
}

From source file:com.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java

/**
 * @param space/*from  ww w .  j  a v  a  2  s  .  c  o  m*/
 * @param suggestions
 * @param values 
 * @param types 
 * @param expression 
 * @return
 */
private Response createHTMLPageScope(Space space, ExpressionSuggestion suggestions, String BBID, String value,
        ObjectType[] types, ValueType[] values) {
    String title = getPageTitle(space);
    StringBuilder html = createHTMLHeader("Scope: " + title);
    createHTMLtitle(html, title, BBID, getParentLink(space));
    if (value != null && value.length() > 0 && suggestions.getValidateMessage() != null
            && suggestions.getValidateMessage().length() > 0) {
        createHTMLproblems(html, Collections
                .singletonList(new Problem(Severity.WARNING, value, suggestions.getValidateMessage())));
    }
    html.append("<form>");
    html.append("<p>Expression:<input type='text' name='value' size=100 value='" + getFieldValue(value)
            + "' placeholder='type expression to validate it or to filter the suggestion list'></p>");
    html.append("<fieldset><legend>Filter by expression type</legend>");
    html.append(
            "<input type='checkbox' name='types' value='" + ObjectType.DIMENSION + "'>" + ObjectType.DIMENSION);
    html.append("<input type='checkbox' name='types' value='" + ObjectType.COLUMN + "'>" + ObjectType.COLUMN);
    html.append(
            "<input type='checkbox' name='types' value='" + ObjectType.RELATION + "'>" + ObjectType.RELATION);
    html.append("<input type='checkbox' name='types' value='" + ObjectType.METRIC + "'>" + ObjectType.METRIC);
    html.append(
            "<input type='checkbox' name='types' value='" + ObjectType.FUNCTION + "'>" + ObjectType.FUNCTION);
    html.append("</fieldset>");
    html.append("<fieldset><legend>Filter by expression value</legend>");
    html.append("<input type='checkbox' name='values' value='" + ValueType.DATE + "'>" + ValueType.DATE);
    html.append("<input type='checkbox' name='values' value='" + ValueType.STRING + "'>" + ValueType.STRING);
    html.append(
            "<input type='checkbox' name='values' value='" + ValueType.CONDITION + "'>" + ValueType.CONDITION);
    html.append("<input type='checkbox' name='values' value='" + ValueType.NUMERIC + "'>" + ValueType.NUMERIC);
    html.append(
            "<input type='checkbox' name='values' value='" + ValueType.AGGREGATE + "'>" + ValueType.AGGREGATE);
    html.append("</fieldset>");
    html.append("<input type=\"hidden\" name=\"style\" value=\"HTML\">"
            + "<input type=\"hidden\" name=\"access_token\" value=\""
            + space.getUniverse().getContext().getToken().getOid() + "\">"
            + "<input type=\"submit\" value=\"Refresh\">");
    html.append("</form>");
    html.append(
            "<p><i> This is the list of all available expressions and function in this scope. Relation expression can be composed in order to navigate the data model.</i></p>");
    html.append("<table>");
    for (ExpressionSuggestionItem item : suggestions.getSuggestions()) {
        html.append("<tr><td>");
        html.append(item.getObjectType() + "</td><td>");
        html.append(item.getValueType() + "</td><td>");
        String style = other_style;
        if (item.getObjectType() == ObjectType.DIMENSION)
            style = axis_style;
        if (item.getObjectType() == ObjectType.METRIC)
            style = metric_style;
        if (item.getObjectType() == ObjectType.FUNCTION)
            style = func_style;
        html.append("<span style='" + style + "'>&nbsp;" + item.getDisplay() + "&nbsp;</span>");
        if (item.getSuggestion() != null) {
            URI link = getPublicBaseUriBuilder().path("/analytics/{reference}/scope")
                    .queryParam("value", value + item.getSuggestion()).queryParam("style", Style.HTML)
                    .queryParam("access_token", userContext.getToken().getOid()).build(BBID);
            html.append(
                    "&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(link.toASCIIString()) + "\">+</a>]");
        }
        if (item.getExpression() != null && item.getExpression() instanceof AxisExpression) {
            AxisExpression ref = (AxisExpression) item.getExpression();
            Axis axis = ref.getAxis();
            if (axis.getDimensionType() == Type.CATEGORICAL) {
                URI link = getPublicBaseUriBuilder().path("/analytics/{reference}/facets/{facetId}")
                        .queryParam("style", Style.HTML)
                        .queryParam("access_token", userContext.getToken().getOid())
                        .build(BBID, item.getSuggestion());
                html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(link.toASCIIString())
                        + "\">Indexed</a>]");
            } else if (axis.getDimensionType() == Type.CONTINUOUS) {
                URI link = getPublicBaseUriBuilder().path("/analytics/{reference}/facets/{facetId}")
                        .queryParam("style", Style.HTML)
                        .queryParam("access_token", userContext.getToken().getOid())
                        .build(BBID, item.getSuggestion());
                html.append("&nbsp;[<a href=\"" + StringEscapeUtils.escapeHtml4(link.toASCIIString())
                        + "\">Period</a>]");
            }
        }
        if (item.getDescription() != null && item.getDescription().length() > 0) {
            html.append("<br><i>" + item.getDescription() + "</i>");
        }
        html.append("</td></tr>");
    }
    html.append("</table>");
    createHTMLAPIpanel(html, "scopeAnalysis");
    html.append("</body></html>");
    return Response.ok(html.toString(), "text/html").build();
}

From source file:com.squid.kraken.v4.api.core.analytics.AnalyticsServiceBaseImpl.java

private void createHTMLAPIpanel(StringBuilder html, String method) {
    html.append("<fieldset><legend>API reference</legend>");
    // compute the raw URI
    UriBuilder builder = getPublicBaseUriBuilder().path(uriInfo.getPath());
    MultivaluedMap<String, String> parameters = uriInfo.getQueryParameters();
    parameters.remove(ACCESS_TOKEN_PARAM);
    parameters.remove(STYLE_PARAM);//from w  w  w  .j  ava 2  s .c  o  m
    parameters.remove(ENVELOPE_PARAM);
    for (Entry<String, List<String>> parameter : parameters.entrySet()) {
        for (String value : parameter.getValue()) {
            builder.queryParam(parameter.getKey(), value);
        }
    }
    html.append(
            "<p>Request URL: <i>this URL will require authentication</i></p><div style='display:block;'><pre style='background-color: #fcf6db;border: 1px solid #e5e0c6; width:1024px; max-height: 400px;overflow-y: auto;'>"
                    + StringEscapeUtils.escapeHtml4(builder.build().toString()) + "</pre></div>");
    String curlURL = "\"" + (StringEscapeUtils.escapeHtml4(builder.build().toString()).replace("'", "'"))
            + "\"";
    html.append(
            "<p>CURL: <i>the command is authorized with the current token</i></p><div style='display:block;'><pre style='background-color: #fcf6db;border: 1px solid #e5e0c6; width:1024px; max-height: 400px;overflow-y: auto;'>curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer "
                    + userContext.getToken().getOid() + "' " + curlURL + "</pre></div>");
    createHTMLswaggerLink(html, method);
    html.append("</fieldset>");
    html.append(
            "<div class=\"footer\"><p>Powered by <a href=\"http://openbouquet.io/\">Open Bouquet</a> <i style='color:white;'>the Analytics Rest API</i></p></div>\n");
}

From source file:com.crushpaper.Servlet.java

/** Helper method. Adds the HTML for a source to a list. */
private void addSourceHtml(Entry source, StringBuilder result, SourceEmbedContext embedContext, String prefix,
        int resultNumber, String rootId) throws IOException {
    final String url = source.getSourceUrl();

    final StringBuilder header = new StringBuilder();
    final StringBuilder footer = new StringBuilder();
    if (embedContext == SourceEmbedContext.InQuotation || embedContext == SourceEmbedContext.InQuotations) {
        header.append("<div class=\"listItemFooter\">");
        footer.append("</div>");
    } else if (embedContext == SourceEmbedContext.InSources) {
        startItemListItem(result, rootId, source.getId());
        header.append("<table class=\"magic nopadding\"><tr><td class=\"resultNumber\">");
        header.append(getItemMetaDataJsonHtml(source.getType(), source.getId()).toString());
        header.append(resultNumber + ".</td>");
        header.append(//from   w w w . j  a v  a2  s. c  o  m
                "<td><input type=\"checkbox\" class=\"justDrag aloneCheckbox\" onclick=\"checkboxOnClick(event); return true;\"></td>");
        header.append("<td class=\"listItem\">");
        footer.append("</td></tr></table>");
        finishItemListItem(footer);
    } else {
        header.append("<div>");
        footer.append("</div>");
    }

    result.append(header);
    if (prefix != null) {
        result.append(prefix);
    }

    if (embedContext == SourceEmbedContext.InQuotation || embedContext == SourceEmbedContext.InQuotation) {
        result.append(servletText.fragmentFrom());
        result.append(" ");
    }

    String domain = null;
    try {
        if (url != null) {
            final URI uri = new URI(url);
            domain = uri.getHost();
        }
    } catch (final URISyntaxException e) {
    }

    if (embedContext == SourceEmbedContext.InSources) {
        result.append("<div class=\"sourceHeader\">");
    }

    result.append("<div class=\"sourceTitle\">");

    if (domain != null && embedContext != SourceEmbedContext.InSources) {
        result.append("<a onclick=\"newTab(event); return false;\" target=\"_blank\" title=\""
                + servletText.showExternalSourceLinkTooltip() + "\" href=\"");
        result.append(StringEscapeUtils.escapeHtml4(url));
        result.append("\">");
    }

    String title = source.getSourceTitle();
    if (title == null || title.isEmpty()) {
        title = servletText.fragmentBlankTitle();
    }

    if (embedContext == SourceEmbedContext.InSource) {
        title = servletText.fragmentVisitExternalSource();
    }

    result.append(StringEscapeUtils.escapeHtml4(title));

    if (domain != null && embedContext != SourceEmbedContext.InSources) {
        result.append("</a>");
    }

    result.append("</div>");

    result.append(" ");

    if (domain != null) {
        result.append("<span class=\"domain\">");
        if (embedContext != SourceEmbedContext.InSource) {
            result.append("(");
        }

        result.append(domain);

        if (embedContext != SourceEmbedContext.InSource) {
            result.append(")");
        }

        result.append("</span>");
    }

    if (embedContext == SourceEmbedContext.InQuotation || embedContext == SourceEmbedContext.InQuotations
            || embedContext == SourceEmbedContext.InSources) {
        result.append(" <a onclick=\"newPaneForLink(event, 'Source', '" + source.getId()
                + "'); return false;\" class=\"sourceMore\" title=\"" + servletText.moreFromThisSourceTooltip()
                + "\" href=\"/source/");
        result.append(source.getId());
        result.append("\">");
        result.append(servletText.buttonMoreQuotations());
        result.append("</a>");
    }

    if (embedContext == SourceEmbedContext.InSources) {
        result.append("</div>");
    }

    if (embedContext == SourceEmbedContext.InSource || embedContext == SourceEmbedContext.InSources) {
        result.append("<div class=\""
                + (embedContext == SourceEmbedContext.InSource ? "sourceFooter" : "listItemFooter") + "\">");
        result.append(servletText.fragmentLastModified() + " <span>");
        result.append(formatDateAndTime(source.getModTime()) + "<span class=\"rawDateTime\">"
                + source.getModTime() + "</span></span></div>");
    }

    result.append(footer);
}

From source file:com.crushpaper.Servlet.java

/** Helper method. Adds the HTML for a source to a list. */
private void addSourceHtmlToExport(Entry source, StringBuilder result) throws IOException {
    final String url = source.getSourceUrl();

    result.append("<div class=\"source\">\n");

    result.append("<div class=\"sourceTitle\">");
    String title = source.getSourceTitle();
    if (title == null || title.isEmpty()) {
        title = servletText.fragmentBlankTitle();
    }/*from  ww  w  .j av a 2  s . c  om*/

    result.append(StringEscapeUtils.escapeHtml4(title));

    result.append("</div>\n");

    if (url != null && !url.isEmpty()) {
        result.append("<a target=\"_blank\" href=\"");
        result.append(StringEscapeUtils.escapeHtml4(url));
        result.append("\">");
        result.append(StringEscapeUtils.escapeHtml4(url));
        result.append("</a>\n");
    }

    result.append("</div>\n");
}

From source file:com.crushpaper.Servlet.java

/** Export the notebook in HTML format. */
private void getNotebookHtmlForExport(final StringBuilder result, Entry entry, Entry root,
        boolean asNestedLists, boolean includeQuotations, boolean includeReferencesSection) throws IOException {
    String title = StringEscapeUtils.escapeHtml4(entry.getNoteOrTitle());

    result.append("<!doctype html><html>\n");
    result.append("<head>\n");
    result.append("<title>");
    result.append(title);//w w w .j a  va  2s . com
    result.append("</title>\n");
    result.append("<style type=\"text/css\">"
            + "p.quotation { font-family:Georgia, serif; background:#FDFFAA; padding:4px 8px 4px 8px; border-left:1px solid #dedede; }\n"
            + "</style>");
    result.append("</head>\n");
    result.append("<body>\n");
    result.append("<h1>");
    result.append(title);
    result.append("</h1>\n");

    SourcesHashList sources = new SourcesHashList();

    addEntryHtmlToExport(root, result, sources, asNestedLists, includeQuotations, includeReferencesSection,
            true);

    if (includeReferencesSection) {
        List<Entry> sourcesList = sources.getSources();
        if (!sourcesList.isEmpty()) {
            result.append("<h2>References</h2>\n<ol>\n");
            int i = 0;
            for (Entry source : sourcesList) {
                result.append("<li>\n");
                result.append("<a name=\"reference" + (++i) + "\">\n");
                addSourceHtmlToExport(source, result);
                result.append("</a>\n</li>\n");
            }

            result.append("</ol>\n");
        }
    }

    result.append("</body>\n</html>\n");
}

From source file:net.sourceforge.pmd.renderers.HTMLRenderer.java

private void glomRuleViolations(Writer writer, Iterator<RuleViolation> violations) throws IOException {

    StringBuilder buf = new StringBuilder(500);

    while (violations.hasNext()) {
        RuleViolation rv = violations.next();
        buf.setLength(0);/*from w ww  .  ja  v  a 2s. co m*/
        buf.append("<tr");
        if (colorize) {
            buf.append(" bgcolor=\"lightgrey\"");
        }
        colorize = !colorize;
        buf.append("> " + PMD.EOL);
        buf.append("<td align=\"center\">" + violationCount + "</td>" + PMD.EOL);
        buf.append("<td width=\"*%\">"
                + maybeWrap(StringEscapeUtils.escapeHtml4(rv.getFilename()),
                        linePrefix == null ? "" : linePrefix + Integer.toString(rv.getBeginLine()))
                + "</td>" + PMD.EOL);
        buf.append(
                "<td align=\"center\" width=\"5%\">" + Integer.toString(rv.getBeginLine()) + "</td>" + PMD.EOL);

        String d = StringEscapeUtils.escapeHtml4(rv.getDescription());

        String infoUrl = rv.getRule().getExternalInfoUrl();
        if (StringUtils.isNotBlank(infoUrl)) {
            d = "<a href=\"" + infoUrl + "\">" + d + "</a>";
        }
        buf.append("<td width=\"*\">" + d + "</td>" + PMD.EOL);
        buf.append("</tr>" + PMD.EOL);
        writer.write(buf.toString());
        violationCount++;
    }
}

From source file:net.vpc.common.jsf.FacesUtils.java

public static SelectItem createSelectItem(String value, String label, String styleClass, String style,
        String desc, boolean disabled) {
    StringBuilder sb = new StringBuilder();
    if (style != null && style.length() > 0) {
        sb.append(" style='").append(style).append('\'');
    }//from  w  w w  . j  a  v  a 2s  .  c o  m
    if (styleClass != null && styleClass.length() > 0) {
        sb.append(" class='").append(styleClass).append('\'');
    }
    if (sb.length() > 0) {
        sb.insert(0, "<span ");
        sb.append(">");
        sb.append(StringEscapeUtils.escapeHtml4(label));
        sb.append("</span>");
        return new SelectItem(value, sb.toString(), desc, disabled, false);
    } else {
        return new SelectItem(value, label, desc, disabled, true);
    }
}

From source file:ninja.diagnostics.DiagnosticErrorRenderer.java

private String escape(String value) {
    return StringEscapeUtils.escapeHtml4(value);
}

From source file:nl.knaw.huc.di.tag.model.graph.DotFactory.java

private String escape(final String label) {
    return StringEscapeUtils.escapeHtml4(label).replaceAll("\n", "\\\\n")
    //        .replace(" ", "_")
    ;/*from w w  w .j  a  va 2s .c o m*/
}