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

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

Introduction

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

Prototype

public static CharEscaper xmlContentEscaper() 

Source Link

Document

Returns a CharEscaper instance that escapes special characters in a string so it can safely be included in an XML document in element content.

Usage

From source file:com.google.transconsole.common.messages.TextFragment.java

/**
 * @param format The format in which this fragment will be written.
 *
 * @return the string with proper XML escaping done on the content
 *//*from  www  . j a v a  2 s.  c  o  m*/
public String toXml(BundleFormat format) {
    return CharEscapers.xmlContentEscaper().escape(getPresentation());
}

From source file:com.google.transconsole.common.messages.Message.java

private void appendSource(StringBuilder sb) {
    for (String source : properties.getSources()) {
        sb.append("<source>");
        sb.append(CharEscapers.xmlContentEscaper().escape(source));
        sb.append("</source>");
    }// w w  w  .  j a  v a  2s.  c  o  m
}

From source file:com.google.transconsole.common.messages.Placeholder.java

/**
 * Returns an XML fragment representing the placeholder in the XMB format.
 *
 * If the placeholder was constructed with only its presentation, a
 * placeholder in the XTB format is returned instead.
 *
 * The format is described in/*from w  ww.j a  va 2  s .c o m*/
 *
 * /home/build/nonconf/google3/i18n/messagebundle.dtd.
 * /home/build/nonconf/google3/i18n/translationbundle.dtd.
 *
 * @return xml fragment
 */
public String toXml(BundleFormat format) {
    StringBuilder sb = new StringBuilder();

    sb.append("<ph name=\"");
    sb.append(CharEscapers.xmlEscaper().escape(presentation));
    sb.append("\"");
    if (format.equals(BundleFormat.XMB)) {
        sb.append(">");
        if (example != null) {
            sb.append("<ex>");
            sb.append(CharEscapers.xmlContentEscaper().escape(example));
            sb.append("</ex>");
        }
        if (original != null) {
            sb.append(CharEscapers.xmlContentEscaper().escape(original));
        }
        sb.append("</ph>");
    } else {
        sb.append("/>");
    }

    return sb.toString();
}