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

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

Introduction

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

Prototype

@Deprecated
public static final String escapeXml(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:org.symphonyoss.client.util.MlMessageParser.java

/**
 * Experimental - will attempt to escape all text within xml elements
 * @param xml full xml/*from  w  ww  . j  a v  a 2  s .  c  o m*/
 * @return escaped xml string
 */
public static String escapeAllXml(String xml) {
    // Match the pattern <something>text</something>
    Pattern xmlCleanerPattern = Pattern.compile("(<[^/<>]*>)([^<>]*)(</[^<>]*>)");

    StringBuilder xmlStringBuilder = new StringBuilder();

    Matcher matcher = xmlCleanerPattern.matcher(xml);
    int lastEnd = 0;
    while (matcher.find()) {
        // Include any non-matching text between this result and the previous result
        if (matcher.start() > lastEnd) {
            xmlStringBuilder.append(xml.substring(lastEnd, matcher.start()));
        }
        lastEnd = matcher.end();

        // Sanitise the characters inside the tags and append the sanitised version
        String cleanText = StringEscapeUtils.escapeXml(matcher.group(2));
        xmlStringBuilder.append(matcher.group(1)).append(cleanText).append(matcher.group(3));
    }
    // Include any leftover text after the last result
    xmlStringBuilder.append(xml.substring(lastEnd));

    return xmlStringBuilder.toString();
}

From source file:org.symphonyoss.symphony.clients.model.SymMessage.java

public void setMessageText(ApiVersion apiVersion, String text) {

    //Lets make sure we comply with XML
    text = StringEscapeUtils.escapeXml(text);

    if (apiVersion != null && !apiVersion.equals(ApiVersion.V2)) {
        setMessage(MLTypes.START_PML + text + MLTypes.END_PML);
    } else {/*from  w  w  w.j ava  2s.  c om*/
        setMessageType("MESSAGEML");
        setMessage(MLTypes.START_ML + text + MLTypes.END_ML);
    }

}

From source file:org.ut.biolab.medsavant.client.query.SearchConditionItem.java

protected String escape(String s) {
    if (s == null) {
        return "";
    } else {//from   w w  w  . j  a  v  a2s  .c  om
        return StringEscapeUtils.escapeXml(s);
    }
}

From source file:pdfreader.PDFReader.java

public void regionTextAllOnce(java.awt.event.ActionEvent evt) throws IOException, CryptographyException {

    JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML");
    jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html"));
    jfc.showSaveDialog(PDFReader.this);
    File saveFile = jfc.getSelectedFile();
    File saveFile1 = jfc.getSelectedFile();
    String outputFileName = saveFile.toString();
    String outputFileName1;/*  w  w  w .  j  a  v  a  2  s . c om*/
    outputFileName1 = saveFile1.toString().substring(0, (saveFile1.toString().length() - 5)) + ".xml";
    HtmlFileGen htmlFileGen = new HtmlFileGen(name, "C:\\blazeds\\tomcat\\webapps\\pictures\\",
            "localhost:8080/pictures/", getTheFileName(name), "");
    TaggedRegion tr;
    BufferedWriter xmlFile = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(outputFileName1), "UTF8"));
    xmlFile.write("<?xml version=\"1.0\"?><Pages>");
    int tempPageNumber = -1;
    try (BufferedWriter htmlFile = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(outputFileName), "UTF8"))) {
        for (int i = 0; i < listOfSelectedRegionInRectangle.size(); i++) {
            tr = listOfSelectedRegionInRectangle.get(i);
            if (tempPageNumber == -1)
                xmlFile.write("<Page No = \"" + tr.pageNumber + "\">");
            else if (tempPageNumber != tr.pageNumber)
                xmlFile.write("</Page><Page No = \"" + tr.pageNumber + "\">");
            //                else
            //                    xmlFile.write("<Page No = \""+tr.pageNumber+"\">");
            tempPageNumber = tr.pageNumber;
            String s = htmlFileGen.getHtmlContent(tr.pageNumber, tr.rectangle, tr.tag);
            if ("table".equals(tr.tag) || "list".equals(tr.tag)) {
                twoDRect = htmlFileGen.twoDRect;
            }
            htmlFile.write(s);
            xmlFile.write("<Region x = \"" + tr.rectangle.x + "\" y = \"" + tr.rectangle.y + "\" height = \""
                    + tr.rectangle.height + "\" width = \"" + tr.rectangle.width + "\" type = \"" + tr.tag
                    + "\">");
            xmlFile.write("<HtmlContent>" + StringEscapeUtils.escapeXml(s) + "</HtmlContent></Region>");
            //            System.out.println(s);
        }
    }
    xmlFile.write("</Page></Pages>");
    xmlFile.close();
    listOfSelectedRegionInRectangle = new ArrayList<>();
}

From source file:pl.maciejwalkowiak.plist.handler.StringHandler.java

@Override
public String handle(Object object) {
    return XMLHelper.wrap(StringEscapeUtils.escapeXml((String) object)).with("string");
}

From source file:rifServices.fileFormats.XMLUtility.java

/**
 * Write record start tag./*from  w w  w . j  av  a 2 s.c om*/
 *
 * @param recordName the record name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void writeRecordStartTag(final String recordName, final String attributeName,
        final String attributeValue) throws IOException {

    printStream.print("<");
    printStream.print(StringEscapeUtils.escapeXml(recordName));

    if ((fieldValidationUtility.isEmpty(attributeName) == false)
            && (fieldValidationUtility.isEmpty(attributeValue) == false)) {
        printStream.print(" ");
        printStream.print(attributeName);
        printStream.print("=\"");
        printStream.print(attributeValue);
        printStream.print("\"");
    }

    printStream.print(">");

    String recordComment = commentInjector.getRecordComment(recordName);

    if (recordComment != null) {
        if (commentInjector.isFirstRecordOccurrence(recordName) == true) {
            String comment = commentInjector.getRecordComment(recordName);
            commentInjector.setFirstRecordOccurrence(recordName);
            writeComment(comment);
        }
    }

    printStream.flush();
}

From source file:rifServices.fileFormats.XMLUtility.java

/**
 * Write record end tag.//  w w w  . ja  va 2 s  .co m
 *
 * @param recordName the record name
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void writeRecordEndTag(final String recordName) throws IOException {

    printStream.print("</");
    printStream.print(StringEscapeUtils.escapeXml(recordName));
    printStream.print(">");
    printStream.flush();
}

From source file:rifServices.fileFormats.XMLUtility.java

/**
 * Write field start tag./*from w  w w .j  a  v  a  2s  . c o m*/
 *
 * @param recordName the record name
 * @param fieldName the field name
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void writeFieldStartTag(final String recordName, final String fieldName) throws IOException {

    printStream.print("<");
    printStream.print(StringEscapeUtils.escapeXml(fieldName));
    printStream.print(">");

    String fieldComment = commentInjector.getFieldComment(recordName, fieldName);
    if ((fieldComment != null) && (commentInjector.isFirstFieldOccurrence(recordName, fieldName) == true)) {

        String comment = commentInjector.getFieldComment(recordName, fieldName);
        commentInjector.setFirstFieldOccurrence(recordName, fieldName);
        writeComment(comment);
    }

    printStream.flush();
}

From source file:rifServices.fileFormats.XMLUtility.java

/**
 * Write field end tag.//  w  w  w. j  a v  a 2  s .c  o m
 *
 * @param fieldName the field name
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void writeFieldEndTag(final String fieldName) throws IOException {

    printStream.print("</");
    printStream.print(StringEscapeUtils.escapeXml(fieldName));
    printStream.print(">");
    printStream.flush();
}

From source file:rifServices.fileFormats.XMLUtility.java

/**
 * Write comment./*from w ww.  j av  a  2s .  co  m*/
 *
 * @param comment the comment
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void writeComment(final String comment) throws IOException {

    printStream.print("<!-- ");
    printStream.print(StringEscapeUtils.escapeXml(comment));
    printStream.print("-->");
    printStream.flush();
}