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.lyncode.jtwig.functions.internal.string.Escape.java

@Override
public Object execute(Object... arguments) throws FunctionException {
    if (arguments.length < 1 || arguments.length > 2)
        throw new FunctionException("Invalid number of arguments");

    String strategy = "html";
    if (arguments.length == 2)
        strategy = arguments[1].toString().toLowerCase();

    switch (EscapeStrategy.strategyByName(strategy.toLowerCase())) {
    case HTML:
        return StringEscapeUtils.escapeHtml4(arguments[0].toString());
    case JAVASCRIPT:
        return StringEscapeUtils.escapeEcmaScript(arguments[0].toString());
    case XML://ww  w  .j a va 2 s  . c om
        return StringEscapeUtils.escapeXml(arguments[0].toString());
    default:
        throw new FunctionException("Unknown escaping strategy");
    }

}

From source file:atd.services.BerichtenService.java

public StatusDB setBericht(String bericht, String tijd, User user, Klant klant) {
    if (!bericht.equals("") && !tijd.equals("") && user != null) {
        return berichtenDAO.setBericht(StringEscapeUtils.escapeHtml4(bericht), tijd, user, klant);
    } else {//from w  w  w.ja va  2s .  co  m
        return StatusDB.INCORRECT;
    }
}

From source file:com.silverpeas.util.EncodeHelper.java

/**
   * Convert a java string to a html string for textArea Replace ", <, >, & and \n
   *// www .  ja  v  a2 s  .co m
   * @param javastring Java string to encode
   * @return html string encoded
   */
  public static String javaStringToHtmlString(String javastring) {
      if (!isDefined(javastring)) {
          return "";
      }
      return StringEscapeUtils.escapeHtml4(javastring).replace("", "&oelig;");
  }

From source file:de.blizzy.documentr.markdown.macro.impl.AlertMacro.java

@Override
public String getHtml(IMacroContext macroContext) {
    String body = StringUtils.defaultString(macroContext.getBody());

    String type = macroContext.getParameters();
    String typeClass = StringUtils.EMPTY;
    if (StringUtils.isNotBlank(type)) {
        typeClass = " alert-" + StringEscapeUtils.escapeHtml4(type); //$NON-NLS-1$
    }//from w ww  .ja  v a 2s.c om
    return "<div class=\"alert" + typeClass + "\">" + body + "</div>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

From source file:de.blizzy.documentr.markdown.macro.impl.LabelMacro.java

@Override
public String getHtml(IMacroContext macroContext) {
    String params = macroContext.getParameters();
    String type = StringUtils.substringBefore(params, " ").trim(); //$NON-NLS-1$
    String text = StringUtils.substringAfter(params, " ").trim(); //$NON-NLS-1$
    return "<span class=\"label label-" + StringEscapeUtils.escapeHtml4(type) + "\">" + //$NON-NLS-1$ //$NON-NLS-2$
            StringEscapeUtils.escapeHtml4(text) + "</span>"; //$NON-NLS-1$
}

From source file:de.blizzy.documentr.markdown.macro.impl.PanelMacro.java

@Override
public String getHtml(IMacroContext macroContext) {
    String params = macroContext.getParameters();
    String width = StringUtils.substringBefore(params, " ").trim(); //$NON-NLS-1$
    boolean border = StringUtils.indexOf(params, " border") >= 0; //$NON-NLS-1$
    return "<div class=\"span" + StringEscapeUtils.escapeHtml4(width) + "\">" + //$NON-NLS-1$ //$NON-NLS-2$
            (border ? "<div class=\"span12 panel-border\">" : StringUtils.EMPTY) + //$NON-NLS-1$
            macroContext.getBody() + (border ? "</div>" : StringUtils.EMPTY) + //$NON-NLS-1$
            "</div>"; //$NON-NLS-1$
}

From source file:com.eryansky.common.utils.encode.EncodeUtils.java

/**
 * Html ?.
 */
public static String htmlEscape(String html) {
    return StringEscapeUtils.escapeHtml4(html);
}

From source file:com.technophobia.substeps.glossary.MarkdownSubstepsPublisher.java

private static void buildStepTagRows(final StringBuilder buf, final Collection<StepDescriptor> infos) {

    for (final StepDescriptor info : infos) {

        log.debug("info non escaped: " + info.getExpression() + "\n\tescaped:\n"
                + StringEscapeUtils.escapeHtml4(info.getExpression()));

        buf.append(String.format(TABLE_ROW_FORMAT, StringEscapeUtils.escapeHtml4(info.getExpression()),
                info.getExample().replaceAll("\n", " "),
                StringEscapeUtils.escapeHtml4(info.getDescription()).replaceAll("\n", " "))).append("\n");

    }//  ww w.j a  v a  2 s  . co m
}

From source file:de.elbe5.base.util.StringUtil.java

public static String toHtmlText(String src) {
    if (src == null) {
        return "";
    }/*from   w  w  w  . j  a v a2 s.  co  m*/
    if (src.indexOf('\n') == -1)
        return StringEscapeUtils.escapeHtml4(src);

    StringTokenizer stk = new StringTokenizer(src, "\n", true);
    if (stk.countTokens() == 0)
        return "";
    StringBuilder sb = new StringBuilder();
    String token;
    while (stk.hasMoreTokens()) {
        token = stk.nextToken();
        if (token.equals("\n"))
            sb.append("\n<br/>\n");
        else
            sb.append(StringEscapeUtils.escapeHtml4(token));
    }
    return sb.toString();
}

From source file:$.Encodes.java

/**
     * Html ?.
     */
    public static String escapeHtml(String html) {
        return StringEscapeUtils.escapeHtml4(html);
    }