Example usage for org.apache.commons.lang StringEscapeUtils escapeHtml

List of usage examples for org.apache.commons.lang StringEscapeUtils escapeHtml

Introduction

In this page you can find the example usage for org.apache.commons.lang StringEscapeUtils escapeHtml.

Prototype

public static String escapeHtml(String input) 

Source Link

Usage

From source file:MainClass.java

public static void main(String[] args) {
    String strHTMLInput = "<P>MyName<P>";
    String strEscapeHTML = StringEscapeUtils.escapeHtml(strHTMLInput);
    String strUnEscapeHTML = StringEscapeUtils.unescapeHtml(strEscapeHTML);
    System.out.println("Escaped HTML >>> " + strEscapeHTML);
    System.out.println("UnEscaped HTML >>> " + strUnEscapeHTML);
}

From source file:StringEscapeUtilsTrial.java

public static void main(String[] args) {
    String strHTMLInput = "<p>MyName<p>";
    String strEscapeHTML = StringEscapeUtils.escapeHtml(strHTMLInput);
    String strUnEscapeHTML = StringEscapeUtils.unescapeHtml(strEscapeHTML);
    System.out.println("Escaped HTML >>> " + strEscapeHTML);
    System.out.println("UnEscaped HTML >>> " + strUnEscapeHTML);
}

From source file:StringUtilsEscapeExampleV1.java

public static void main(String args[]) {
    String unescapedJava = "Are you for real?";
    System.err.println(StringEscapeUtils.escapeJava(unescapedJava));

    String unescapedJavaScript = "What's in a name?";
    System.err.println(StringEscapeUtils.escapeJavaScript(unescapedJavaScript));

    String unescapedSql = "Mc'Williams";
    System.err.println(StringEscapeUtils.escapeSql(unescapedSql));

    String unescapedXML = "<data>";
    System.err.println(StringEscapeUtils.escapeXml(unescapedXML));

    String unescapedHTML = "<data>";
    System.err.println(StringEscapeUtils.escapeHtml(unescapedHTML));

}

From source file:at.tuwien.ifs.somtoolbox.doc.RunnablesReferenceCreator.java

public static void main(String[] args) {
    ArrayList<Class<? extends SOMToolboxApp>> runnables = SubClassFinder.findSubclassesOf(SOMToolboxApp.class,
            true);// www .  ja v  a  2  s  .c  o m
    Collections.sort(runnables, SOMToolboxApp.TYPE_GROUPED_COMPARATOR);

    StringBuilder sbIndex = new StringBuilder(runnables.size() * 50);
    StringBuilder sbDetails = new StringBuilder(runnables.size() * 200);

    sbIndex.append("\n<table border=\"0\">\n");

    Type lastType = null;

    for (Class<? extends SOMToolboxApp> c : runnables) {
        try {
            // Ignore abstract classes and interfaces
            if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) {
                continue;
            }

            Type type = Type.getType(c);
            if (type != lastType) {
                sbIndex.append("  <tr> <td colspan=\"2\"> <h5> " + type + " Applications </h5> </td> </tr>\n");
                sbDetails.append("<h2> " + type + " Applications </h2>\n");
                lastType = type;
            }
            String descr = "N/A";
            try {
                descr = (String) c.getDeclaredField("DESCRIPTION").get(null);
            } catch (Exception e) {
            }
            String longDescr = "descr";
            try {
                longDescr = (String) c.getDeclaredField("LONG_DESCRIPTION").get(null);
            } catch (Exception e) {
            }

            sbIndex.append("  <tr>\n");
            sbIndex.append("    <td> <a href=\"#").append(c.getSimpleName()).append("\">")
                    .append(c.getSimpleName()).append("</a> </td>\n");
            sbIndex.append("    <td> ").append(descr).append(" </td>\n");
            sbIndex.append("  </tr>\n");

            sbDetails.append("<h3 id=\"").append(c.getSimpleName()).append("\">").append(c.getSimpleName())
                    .append("</h3>\n");
            sbDetails.append("<p>").append(longDescr).append("</p>\n");

            try {
                Parameter[] options = (Parameter[]) c.getField("OPTIONS").get(null);
                JSAP jsap = AbstractOptionFactory.registerOptions(options);
                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                PrintStream ps = new PrintStream(os);
                AbstractOptionFactory.printHelp(jsap, c.getName(), ps);
                sbDetails.append("<pre>").append(StringEscapeUtils.escapeHtml(os.toString())).append("</pre>");
            } catch (Exception e1) { // we didn't find the options => let the class be invoked ...
            }

        } catch (SecurityException e) {
            // Should not happen - no Security
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }
    sbIndex.append("</table>\n\n");
    System.out.println(sbIndex);
    System.out.println(sbDetails);
}

From source file:cc.aileron.commons.util.HtmlUtils.java

/**
 * @param value//from   ww  w. j a va  2 s  .  c  o m
 * @return value
 */
public static String escape(final String value) {
    return StringEscapeUtils.escapeHtml(value);
}

From source file:com.liferay.cucumber.util.HtmlUtil.java

public static String escape(String text) {
    return StringEscapeUtils.escapeHtml(text);
}

From source file:com.bluexml.side.requirements.generator.services.StringEscapeUtilsService.java

public static String escapeHtml(EObject node, String label) {
    return StringEscapeUtils.escapeHtml(label.replaceAll("\n", "<br/>").replaceAll("\r", ""));
}

From source file:lu.lippmann.cdb.common.gui.dataset.InstanceFormatter.java

public static String htmlFormat(final Instance inst, final boolean withHTMLHeader) {
    final StringBuilder sb = new StringBuilder();
    if (withHTMLHeader)
        sb.append("<html><body>");
    for (int i = 0; i < inst.numAttributes(); i++) {
        sb.append(StringEscapeUtils.escapeHtml(inst.attribute(i).name())).append(" = ");
        sb.append("<b>");
        if (inst.attribute(i).isNominal() || inst.attribute(i).isString()) {
            sb.append(StringEscapeUtils.escapeHtml(inst.stringValue(i)));
        } else if (inst.attribute(i).isDate()) {
            final Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis((long) inst.value(i));
            sb.append(FormatterUtil.DATE_FORMAT.format(cal.getTime()));
        } else if (inst.attribute(i).isNumeric()) {
            sb.append(inst.value(i));//from   w  w w.jav  a2 s . co m
        }
        sb.append("</b>");
        sb.append("<br/>");
    }
    if (withHTMLHeader)
        sb.append("</body></html>");
    return sb.toString();
}

From source file:net.geoprism.util.EscapeUtil.java

public static String escapeHTMLAttribute(String value) {
    if (value != null) {
        String encoded = StringEscapeUtils.escapeHtml(value);
        encoded = encoded.replaceAll("'", "&#x27;");
        encoded = encoded.replaceAll("/", "&#x2F;");

        return encoded;
    }/*from  w w  w .j  a v a2s.c o  m*/

    return "";
}

From source file:com.haulmont.bali.util.HtmlUtils.java

/**
 * Converts string with content to html string.
 *
 * @param text to be converted//from  w  ww  .ja v a 2 s. c  o m
 * @return Converted string.
 */
public static String convertToHtml(String text) {
    String html = StringEscapeUtils.escapeHtml(text);
    html = StringUtils.replace(html, "\n", "<br/>");
    html = StringUtils.replace(html, " ", "&nbsp;");
    html = StringUtils.replace(html, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
    return html;
}