Example usage for org.apache.commons.lang3 StringEscapeUtils escapeXml10

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeXml10

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeXml10.

Prototype

public static String escapeXml10(final String input) 

Source Link

Document

Escapes the characters in a String using XML entities.

For example: "bread" & "butter" => "bread" & "butter" .

Usage

From source file:jodtemplate.template.JODTemplateObjectWrapper.java

@Override
public TemplateModel wrap(final Object obj) throws TemplateModelException {
    if (obj instanceof String) {
        return super.wrap(StringEscapeUtils.escapeXml10((String) obj));
    }/*ww w  .ja  va2s.c om*/
    return super.wrap(obj);
}

From source file:com.igormaznitsa.jcp.expression.functions.FunctionSTR2XML.java

@Override
@Nonnull/*from w w  w  . j  av a2  s. c o m*/
public Value executeStr(@Nonnull final PreprocessorContext context, @Nonnull final Value value) {
    final String escaped = StringEscapeUtils.escapeXml10(value.asString());
    return Value.valueOf(escaped);
}

From source file:com.cloud.hypervisor.ovm3.objects.XmlTestResultTest.java

public String escapeOrNot(String s) {
    if (s.startsWith("<")) {
        return StringEscapeUtils.escapeXml10(s);
    }/*ww  w. j av  a 2  s.  co m*/
    return s;
}

From source file:io.wcm.devops.conga.generator.plugins.handlebars.escaping.XmlEscapingStrategy.java

@Override
public String escape(CharSequence value) {
    return value == null ? null : StringEscapeUtils.escapeXml10(value.toString());
}

From source file:be.ceau.solrtalk.model.Field.java

public void setValue(String value) {
    this.value = StringEscapeUtils.escapeXml10(value);
}

From source file:com.revencoft.sample.utils.Encodes.java

/**
 * Xml ?.
 */
public static String escapeXml(String xml) {
    return StringEscapeUtils.escapeXml10(xml);
}

From source file:be.ceau.solrtalk.model.Doc.java

@XmlTransient
public void setId(int hash) {
    addField(new Field(Attribute.ID, StringEscapeUtils.escapeXml10(String.valueOf(hash))));
}

From source file:de.mpg.escidoc.services.cone.util.RdfHelper.java

/**
 * Formats an List&lt;Pair&gt; into an RDF list.
 * //  w  ww  .  ja v a  2  s  .  co m
 * @param pairs A list of key-value pairs
 * 
 * @return The RDF
 */
public static String formatList(List<? extends Describable> pairs, Model model) {

    StringWriter result = new StringWriter();

    result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    result.append("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
            + "xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");

    if (model.getRdfAboutTag() != null && model.getRdfAboutTag().getNamespaceURI() != null
            && !model.getRdfAboutTag().getNamespaceURI().equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))

    {
        result.append(" xmlns:" + model.getRdfAboutTag().getPrefix() + "=\""
                + model.getRdfAboutTag().getNamespaceURI() + "\"");
    }

    result.append(">\n");
    if (pairs != null) {

        for (Describable pair : pairs) {
            if (pair instanceof Pair) {
                String key = ((Pair) pair).getKey();
                try {
                    result.append("\t<rdf:Description rdf:about=\""
                            + PropertyReader.getProperty("escidoc.cone.service.url") + key.replace("\"", "\\\"")
                            + "\">\n");
                    if (((Pair) pair).getValue() instanceof LocalizedString) {
                        if (((LocalizedString) ((Pair) pair).getValue()).getLanguage() != null) {
                            result.append("\t\t<dc:title xml:lang=\""
                                    + ((LocalizedString) ((Pair) pair).getValue()).getLanguage() + "\">"
                                    + StringEscapeUtils.escapeXml10(
                                            ((LocalizedString) ((Pair) pair).getValue()).getValue())
                                    + "</dc:title>\n");
                        } else {
                            result.append("\t\t<dc:title>"
                                    + StringEscapeUtils.escapeXml10(
                                            ((LocalizedString) ((Pair) pair).getValue()).getValue())
                                    + "</dc:title>\n");
                        }
                    } else {
                        result.append("\t\t<dc:title>"
                                + StringEscapeUtils.escapeXml10(((Pair) pair).getValue().toString())
                                + "</dc:title>\n");
                    }
                    result.append("\t</rdf:Description>\n");
                } catch (Exception exception) {
                    throw new RuntimeException(exception);
                }
            } else if (pair instanceof TreeFragment) {
                result.append(((TreeFragment) pair).toRdf(model));
            }
        }
    }

    result.append("</rdf:RDF>\n");

    return result.toString();
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.exporters.XmlExporter.java

@Override
public void export(final File file) throws IOException {
    final StringBuilder buffer = new StringBuilder(256000);

    buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    buffer.append("<jhexed>\n");

    buffer.append("\t<docOptions>\n");
    buffer.append("\t\t<columns>").append(this.docOptions.getColumns()).append("</columns>\n");
    buffer.append("\t\t<rows>").append(this.docOptions.getRows()).append("</rows>\n");
    buffer.append("\t\t<commentary>").append(StringEscapeUtils.escapeXml10(this.docOptions.getCommentary()))
            .append("</commentary>\n");
    buffer.append("\t\t<hexBorderWidth>").append(this.docOptions.getLineWidth()).append("</hexBorderWidth>\n");
    buffer.append("\t\t<hexBorderColor>").append(Utils.color2html(this.docOptions.getColor(), false))
            .append("</hexBorderColor>\n");
    buffer.append("\t\t<hexOrientation>").append(
            this.docOptions.getHexOrientation() == HexEngine.ORIENTATION_VERTICAL ? "vertical" : "horizontal")
            .append("</hexOrientation>\n");
    buffer.append("\t</docOptions>\n");
    if (exportData.isBackgroundImageExport() && this.docOptions.getImage() != null) {
        buffer.append("\t<backImage>")
                .append(Utils.byteArray2String(this.docOptions.getImage().getImageData(), true, true))
                .append("</backImage>\n");
    }//ww  w . j av a2s. co m
    buffer.append("\t<layers>\n");
    for (final LayerExportRecord f : exportData.getLayers()) {
        if (Thread.currentThread().isInterrupted()) {
            return;
        }
        if (f.isAllowed()) {
            buffer.append("\t\t<layer name=\"")
                    .append(StringEscapeUtils.escapeXml10(f.getLayer().getLayerName()))
                    .append("\" commentary=\"")
                    .append(StringEscapeUtils.escapeXml10(f.getLayer().getComments())).append("\">\n");
            buffer.append("\t\t\t<values>\n");
            for (int i = 1; i < f.getLayer().getHexValuesNumber(); i++) {
                final HexFieldValue vl = f.getLayer().getHexValueForIndex(i);
                buffer.append("\t\t\t\t<value index=\"").append(i).append("\" name=\"")
                        .append(StringEscapeUtils.escapeXml10(vl.getName())).append("\" commentary=\"")
                        .append(StringEscapeUtils.escapeXml10(vl.getComment())).append("\">\n");
                if (vl instanceof HexColorValue) {
                    final Color clr = ((HexColorValue) vl).getColor();
                    buffer.append("\t\t\t\t\t<color color=\"").append(Utils.color2html(clr, true))
                            .append("\"/>\n");
                } else if (vl instanceof HexSVGImageValue) {
                    buffer.append("\t\t\t\t\t<svg>").append(Utils
                            .byteArray2String(((HexSVGImageValue) vl).getImage().getImageData(), true, true))
                            .append("</svg>\n");
                }
                buffer.append("\t\t\t\t</value>\n");
            }
            buffer.append("\t\t\t</values>\n");
            buffer.append("\t\t\t<array>").append(Utils.byteArray2String(f.getLayer().getArray(), true, true))
                    .append("</array>\n");
            buffer.append("\t\t</layer>\n");
        }
    }
    buffer.append("\t</layers>\n");
    if (this.exportData.isCellCommentariesExport()) {
        buffer.append("\t<cellComments>\n");
        final Iterator<Entry<HexPosition, String>> cellComment = this.cellComments.iterator();
        while (cellComment.hasNext()) {
            if (Thread.currentThread().isInterrupted()) {
                return;
            }
            final Entry<HexPosition, String> entry = cellComment.next();
            final HexPosition hexPos = entry.getKey();
            final String escapedComment = StringEscapeUtils.escapeXml11(entry.getValue());
            buffer.append("\t\t<cellComment col=\"").append(hexPos.getColumn()).append("\" row=\"")
                    .append(hexPos.getRow()).append("\" text=\"").append(escapedComment).append("\"/>\n");
        }
        buffer.append("\t</cellComments>\n");
    }
    buffer.append("</jhexed>\n");
    if (!Thread.currentThread().isInterrupted()) {
        FileUtils.write(file, buffer.toString());
    }
}

From source file:be.ceau.solrtalk.model.Doc.java

@XmlTransient
public void setMimeType(String contenttype) {
    addField(new Field(Attribute.MIMETYPE, StringEscapeUtils.escapeXml10(contenttype)));
}