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.github.naoghuman.cm.model.glossary.GlossaryModel.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeLong(this.getId());
    out.writeLong(this.getGenerationTime());
    out.writeObject(StringEscapeUtils.escapeHtml4(this.getTitle()));
    out.writeObject(StringEscapeUtils.escapeHtml4(this.getDescription()));
    out.writeObject(StringEscapeUtils.escapeHtml4(this.getNotes()));
}

From source file:com.griddynamics.deming.ecommerce.api.endpoint.catalog.CatalogManagerEndpoint.java

private void escape(ImportCategoryWrapper categoryWrapper) {
    categoryWrapper.name = StringEscapeUtils.escapeHtml4(categoryWrapper.name);
    categoryWrapper.description = StringEscapeUtils.escapeHtml4(categoryWrapper.description);

    if (CollectionUtils.isNotEmpty(categoryWrapper.products)) {
        for (ImportProductWrapper product : categoryWrapper.products) {
            product.name = StringEscapeUtils.escapeHtml4(product.name);
            product.description = StringEscapeUtils.escapeHtml4(product.description);
        }/* ww w.  j  av  a  2s.  co m*/
    }

    if (CollectionUtils.isNotEmpty(categoryWrapper.subcategories)) {
        for (ImportCategoryWrapper subcategoryWrapper : categoryWrapper.subcategories) {
            escape(subcategoryWrapper);
        }
    }
}

From source file:com.mgmtp.jfunk.core.reporting.EmailReporter.java

private String replacePlaceholderToken(final String template, final String token, final String value,
        final boolean escapeHtml) {
    return template.replace("${" + token + "}", escapeHtml ? StringEscapeUtils.escapeHtml4(value) : value);
}

From source file:de.decoit.visa.topology.NetworkComponent.java

@Override
public JSONObject toJSON() throws JSONException {
    JSONObject rv = new JSONObject();

    rv.put("id", id);
    rv.put("identifier", localName);
    rv.put("name", StringEscapeUtils.escapeHtml4(name));
    rv.put("config", config.toJSON());

    if (this instanceof NCSwitch) {
        rv.put("isSwitch", true);
    } else {/*from   w  ww. j a  v a2 s  .c o  m*/
        rv.put("isSwitch", false);
    }

    rv.put("isGroup", false);

    return rv;
}

From source file:com.uwyn.jhighlight.renderer.XhtmlRenderer.java

/**
 * Returns the XHTML header that preceedes the highlighted source code.
 * <p>It will integrate the CSS class definitions and use the source's
 * name to indicate in XHTML which file has been highlighted.
 *
 * @param name The name of the source file.
 * @return The constructed XHTML header.
 * @since 1.0//  w  w w.  j a va  2 s .co  m
 */
protected String getXhtmlHeader(String name) {
    name = org.apache.commons.lang3.StringUtils.defaultString(name);

    return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
            + "                      \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
            + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n" + "<head>\n"
            + "    <meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />\n"
            + "    <meta name=\"generator\" content=\"JHighlight v" + VersionUtils.getVersion() + " ("
            + VersionUtils.URL + ")\" />\n" + "    <title>" + StringEscapeUtils.escapeHtml4(name) + "</title>\n"
            + "    <link rel=\"Help\" href=\"" + VersionUtils.URL + "\" />\n"
            + "    <style type=\"text/css\">\n" + getCssClassDefinitions() + "    </style>\n" + "</head>\n"
            + "<body>\n" + "<h1>" + StringEscapeUtils.escapeHtml4(name) + "</h1>" + "<code>";
}

From source file:com.github.naoghuman.cm.model.category.CategoryModel.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeLong(this.getId());
    out.writeLong(this.getMatrixId());
    out.writeLong(this.getGenerationTime());
    out.writeObject(StringEscapeUtils.escapeHtml4(this.getTitle()));
    out.writeObject(StringEscapeUtils.escapeHtml4(this.getDescription()));
}

From source file:fr.in2p3.maven.plugin.DependencyXmlMojo.java

private static void addAttribute(PrintStream out, String name, String value) {
    if (value != null) {
        if (value.contains("\"")) {
            value = value.replaceAll("\"", "'");
        }//from   w w  w .ja v  a  2 s. com
        out.print(" " + name + "=\"" + StringEscapeUtils.escapeHtml4(value) + "\"");
    }
}

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

@Test
public void shouldSupportUTF8() throws Exception {
    String link = "http://mingle05/projects/cce/cards/${ID}";
    String regex = "#(\\d+)";
    trackingTool = new DefaultCommentRenderer(link, regex);

    String result = trackingTool.render("The story #111 is fixed by . #122 is also related to this");
    assertThat(result,//from w w w  . j av  a2 s  .c o  m
            is("The story " + dynamicLink("111") + " is fixed by " + StringEscapeUtils.escapeHtml4("")
                    + ". " + dynamicLink("122") + " is also related to this"));
}

From source file:com.esri.gpt.catalog.arcgis.metadata.AGSInterrogator.java

/**
 * Loops through JSON/HTML REST responses from an ArcGIS services tree in order to 
 * determine the SOAP endpoint for ArcGIS Server services catalog
 * @param baseUrl the current base URL associated with a REST endpoint of the services tree
 * @return the SOAP endpoint to the ArcGIS Server services catalog (can be null)
 *//*w ww . ja  va 2  s. co m*/
private String determineSoapUrl(String baseUrl) {

    // submit the json request
    String restUrl = this.target.getRestUrl();
    JSONObject jsoParent = null;
    try {
        this.httpClient.setUrl(baseUrl + "?f=json");
        String json = this.httpClient.readResponseAsCharacters();
        jsoParent = new JSONObject(json);
    } catch (JSONException e) {
        LOGGER.finest("Invalid JSON response: " + e.toString());
        return null;
    } catch (IOException ioe) {
        LOGGER.finest("Cannot scrape HTML response: " + ioe.toString());
    }
    if (jsoParent == null)
        return null;

    // loop through the services
    try {
        JSONArray jsoServices = jsoParent.getJSONArray("services");
        if (jsoServices != null) {
            for (int i = 0; i < jsoServices.length(); i++) {
                JSONObject service = jsoServices.getJSONObject(i);
                if (service != null) {
                    String name = Val.chkStr(service.getString("name"));
                    String type = Val.chkStr(service.getString("type"));

                    // for some reason, service names within a folder are partial paths
                    // e.g baseurl = http://server.arcgisonline.com/ArcGIS/rest/services/Elevation 
                    // name = Elevation/ESRI_Elevation_World
                    if (name.lastIndexOf("/") != -1) {
                        //if (this.baseUrl.lastIndexOf("/") != -1) {
                        //  String folder = this.baseUrl.substring(this.baseUrl.lastIndexOf("/")+1);
                        //  if (name.startsWith(folder+"/")) {
                        //   name = name.substring(name.lastIndexOf("/")+1);
                        // }
                        //}
                    }

                    // scrape the service HTML page for a SOAP URL
                    if ((name.length() > 0) && (type.length() > 0)) {
                        String soapEndpoint = "";
                        boolean considerReverseProxy = false;
                        try {
                            String relative = "/" + name + "/" + type;
                            String currentUrl = restUrl + relative + "?f=html";
                            this.httpClient.setUrl(currentUrl);
                            String html = httpClient.readResponseAsCharacters();
                            soapEndpoint = Val.chkStr(this.scapeHtmlForSoapEndpoint(html));
                            if (soapEndpoint.length() > 0) {
                                int idx = soapEndpoint.toLowerCase().indexOf(relative.toLowerCase());
                                if (idx != -1) {
                                    soapEndpoint = soapEndpoint.substring(0, idx);
                                }
                            }
                        } catch (IOException ioe) {
                            String msg = "Cannot scrape ArcGIS service html response::";
                            msg += "\n restUrl=" + StringEscapeUtils.escapeHtml4(Val.stripControls(restUrl))
                                    + "\n htmlUrl=" + StringEscapeUtils
                                            .escapeHtml4(Val.stripControls(this.httpClient.getUrl()));
                            LOGGER.finer(msg + "\n" + ioe.toString());
                        }

                        // validate the soap endpoint
                        try {
                            if (soapEndpoint.length() > 0) {
                                considerReverseProxy = true;
                                String validated = this.pingCatalogWsdl(soapEndpoint);
                                return validated;
                            }
                        } catch (IOException ioe) {
                            String msg = "Unable to ping ArcGIS services catalog soap url:";
                            msg += "\n restUrl=" + StringEscapeUtils.escapeHtml4(Val.stripControls(restUrl))
                                    + "\n soapUrl="
                                    + StringEscapeUtils.escapeHtml4(Val.stripControls(soapEndpoint));
                            LOGGER.finer(msg + "\n" + ioe.toString());
                        }

                        // try again considering a revese proxy for the soap endpoint
                        try {
                            if (considerReverseProxy) {
                                soapEndpoint = Val.chkStr(guessReverseProxyUrl(soapEndpoint));
                                if (soapEndpoint.length() > 0) {
                                    String validated = this.pingCatalogWsdl(soapEndpoint);
                                    return validated;
                                }
                            }
                        } catch (IOException ioe) {
                            String msg = "Unable to ping ArcGIS services catalog soap url (try reverse proxy):";
                            msg += "\n restUrl=" + StringEscapeUtils.escapeHtml4(Val.stripControls(restUrl))
                                    + "\n soapUrl="
                                    + StringEscapeUtils.escapeHtml4(Val.stripControls(soapEndpoint));
                            LOGGER.finer(msg + "\n" + ioe.toString());
                        }

                    }
                }
            }
        }
    } catch (JSONException e) {
        LOGGER.finest("No ArcGIS services: " + StringEscapeUtils.escapeHtml4(Val.stripControls(baseUrl)) + " - "
                + e.toString());
    }

    // loop through the folders
    try {
        JSONArray jsoFolders = jsoParent.getJSONArray("folders");
        if (jsoFolders != null) {
            for (int i = 0; i < jsoFolders.length(); i++) {
                String name = Val.chkStr(jsoFolders.getString(i));
                if (name.length() > 0) {
                    String currentUrl = restUrl + "/" + name;
                    String soapEndpoint = this.determineSoapUrl(currentUrl);
                    if ((soapEndpoint != null) && (soapEndpoint.length() > 0)) {
                        return soapEndpoint;
                    }
                }
            }
        }
    } catch (JSONException e) {
        LOGGER.finest("No ArcGIS folders: " + StringEscapeUtils.escapeHtml4(Val.stripControls(baseUrl)) + " - "
                + e.toString());
    }

    return null;
}

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

@Test
public void shouldEscapeTheWholeCommentIfNoneIsMatched() {
    trackingTool = new DefaultCommentRenderer("", "");
    String toRender = "some <string>";
    String result = trackingTool.render(toRender);
    assertThat(result, is(StringEscapeUtils.escapeHtml4(toRender)));
}