Example usage for com.google.common.base CharEscapers asciiHtmlEscaper

List of usage examples for com.google.common.base CharEscapers asciiHtmlEscaper

Introduction

In this page you can find the example usage for com.google.common.base CharEscapers asciiHtmlEscaper.

Prototype

public static CharEscaper asciiHtmlEscaper() 

Source Link

Document

Returns a CharEscaper instance that escapes special characters in a string so it can safely be included in an HTML document in either element content or attribute values.

Usage

From source file:com.google.gxp.html.HtmlClosures.java

/**
 * Convert a plaintext String into a {@code HtmlClosure} that emits the
 * HTML-escaped form of the String.//  w  w  w . ja  v  a  2 s  .  c  o  m
 *
 * If you are using this in a GXP, you are doing something wrong. GXP is
 * designed to handle all escaping for you.
 */
public static HtmlClosure fromPlaintext(final String text) {
    return wrap(GxpClosures.fromString(text, CharEscapers.asciiHtmlEscaper()));
}

From source file:com.google.gxp.html.HtmlClosures.java

/**
 * Create a {@code HtmlClosure} based on a {@code Localizable}.
 *
 * The contents of the Localizable will be escaped on output.
 *///from  w  w  w. j  a  v a  2  s.  com
public static HtmlClosure fromLocalizable(final Localizable value) {
    return wrap(GxpClosures.fromLocalizable(value, CharEscapers.asciiHtmlEscaper()));
}

From source file:com.google.gxp.base.dynamic.ThrowableClosure.java

public void write(Appendable out, GxpContext gxpContext) throws IOException {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    CharEscapers.asciiHtmlEscaper().escape(out).append(sw.toString());
}

From source file:com.google.gxp.base.dynamic.FilePrinter.java

public void write(Appendable out, GxpContext gxpContext) throws IOException {
    BufferedReader br = new BufferedReader(fileReader);
    String line;//  w  w  w .  j  a  v  a 2  s  . c  o  m
    long lineNumber = 1;
    while ((line = br.readLine()) != null && lineNumber <= endLine) {
        if (startLine <= lineNumber) {
            if (lineNumber == errorLine) {
                out.append("<span class=\"error\">");
            }
            out.append(String.format("%4d: ", lineNumber));
            CharEscapers.asciiHtmlEscaper().escape(out).append(line);
            if (lineNumber == errorLine) {
                out.append("</span>");
            }
            out.append('\n');
        }
        lineNumber++;
    }
}