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

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

Introduction

In this page you can find the example usage for org.apache.commons.text 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:com.softwareaggov.messaging.simplesoapjms.client.web.SendSoapJmsCall.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    out.write("<h1>" + req.getContextPath() + " - Sending SOAP Call</h1>");
    try {//from  w  ww .j  a v  a 2s  .c o m
        String callType = req.getParameter("calltype");
        SoapClientLocal soapJmsService = null;
        if (null != callType) {
            if ("oneway".equals(callType.toLowerCase()))
                soapJmsService = soapJmsClientOneWayService;
            else if ("twoway".equals(callType.toLowerCase()))
                soapJmsService = soapJmsClientTwoWayService;
            else
                throw new IllegalArgumentException("call type [" + callType + "] not supported.");
        } else {
            throw new IllegalArgumentException("call type [null] not supported.");
        }

        if (null == soapJmsService)
            throw new IllegalArgumentException(
                    "soapJmsService is null...should not be...check code or configs");

        String response = soapJmsService.callWS();

        String responseToDisplay = "";
        if (null != response) {
            if (response.toLowerCase().startsWith("<?xml")) {
                responseToDisplay = StringEscapeUtils.escapeXml10(response);
            } else {
                responseToDisplay = response;
            }
        } else {
            responseToDisplay = "null";
        }

        out.write("<p><b>messages sent successfully</b></p>");
        out.write(String.format("<div><p>Response:</p><p>%s</p></div>", responseToDisplay));

        out.close();
    } catch (Throwable exc) {
        log.error("Error Occurred", exc);
        throw new ServletException(exc);
    }
}

From source file:de.micromata.genome.logging.LogAttribute.java

public String getEscapedValue() {
    return StringEscapeUtils.escapeXml10(value);
}

From source file:com.nridge.core.base.io.xml.IOXML.java

/**
 * Writes an XML node (name/value) while ensuring the characters are properly
 * escaped.//from  ww w .j a  v a  2 s.c  om
 *
 * @param aPW Print writer output stream.
 * @param anIndentAmount Count of spaces to indent.
 * @param aName Node name.
 * @param aValue Node value.
 * @throws IOException I/O related exception.
 */
public static void writeNodeNameValue(PrintWriter aPW, int anIndentAmount, String aName, String aValue)
        throws IOException {
    if (StringUtils.isNotEmpty(aValue)) {
        indentLine(aPW, anIndentAmount);
        aPW.printf("<%s>%s</%s>%n", aName, StringEscapeUtils.escapeXml10(aValue), aName);
    }
}

From source file:com.nridge.core.base.io.xml.DataFieldXML.java

public void saveValue(PrintWriter aPW, DataField aDataField, int anIndentAmount) throws IOException {
    if (aDataField.isRangeAssigned()) {
        String singleValue;/*www  . jav a  2  s  .c  om*/
        mRangeXML.saveNode(aPW, anIndentAmount + 1);
        mRangeXML.saveAttr(aPW, aDataField.getRange());
        mRangeXML.saveValue(aPW, aDataField.getRange());
        if (aDataField.isMultiValue()) {
            String mvDelimiter = aDataField.getFeature(Field.FEATURE_MV_DELIMITER);
            if (StringUtils.isNotEmpty(mvDelimiter))
                singleValue = aDataField.collapse(mvDelimiter.charAt(0));
            else
                singleValue = aDataField.collapse();
        } else
            singleValue = aDataField.getValue();

        IOXML.writeNodeNameValue(aPW, anIndentAmount + 1, "Value", singleValue);
        IOXML.indentLine(aPW, anIndentAmount);
        aPW.printf("</%s>%n", IO.XML_FIELD_NODE_NAME);
    } else {
        if (aDataField.isMultiValue()) {
            String mvDelimiter = aDataField.getFeature(Field.FEATURE_MV_DELIMITER);
            if (StringUtils.isNotEmpty(mvDelimiter))
                aPW.printf(">%s</%s>%n",
                        StringEscapeUtils.escapeXml10(aDataField.collapse(mvDelimiter.charAt(0))),
                        IO.XML_FIELD_NODE_NAME);
            else
                aPW.printf(">%s</%s>%n", StringEscapeUtils.escapeXml10(aDataField.collapse()),
                        IO.XML_FIELD_NODE_NAME);
        } else {
            if (aDataField.isFeatureTrue(Field.FEATURE_IS_CONTENT))
                aPW.printf(">%s</%s>%n", XMLUtl.escapeElemStrValue(aDataField.getValue()),
                        IO.XML_FIELD_NODE_NAME);
            else
                aPW.printf(">%s</%s>%n", StringEscapeUtils.escapeXml10(aDataField.getValue()),
                        IO.XML_FIELD_NODE_NAME);
        }
    }
}

From source file:fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor.java

public String encodeURI(URI u) {
    return StringEscapeUtils.escapeXml10(u.toASCIIString());
}

From source file:com.nridge.core.base.io.xml.DataTableXML.java

/**
 * Saves the previous assigned bag/table (e.g. via constructor or set method)
 * to the print writer stream wrapped in a tag name specified in the parameter.
 *
 * @param aPW            PrintWriter stream instance.
 * @param aTagName       Tag name./*from   ww  w.ja  v a2s .c  o  m*/
 * @param anIndentAmount Indentation count.
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void save(PrintWriter aPW, String aTagName, int anIndentAmount) throws IOException {
    String cellValue;
    DataField dataField;
    int columnCount, rowCount;

    rowCount = mDataTable.rowCount();
    columnCount = mDataTable.columnCount();
    String tagName = StringUtils.remove(aTagName, StrUtl.CHAR_SPACE);
    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("<%s", tagName);
    IOXML.writeAttrNameValue(aPW, "type", IO.extractType(mDataTable.getClass().getName()));
    IOXML.writeAttrNameValue(aPW, "name", mDataTable.getName());
    IOXML.writeAttrNameValue(aPW, "dimensions", String.format("%d cols x %d rows", columnCount, rowCount));
    IOXML.writeAttrNameValue(aPW, "version", IO.DATATABLE_XML_FORMAT_VERSION);
    for (Map.Entry<String, String> featureEntry : mDataTable.getFeatures().entrySet())
        IOXML.writeAttrNameValue(aPW, featureEntry.getKey(), featureEntry.getValue());
    aPW.printf(">%n");

    if ((mContextTotal != 0) || (mContextLimit != 0)) {
        IOXML.indentLine(aPW, anIndentAmount + 2);
        aPW.printf("<Context");
        IOXML.writeAttrNameValue(aPW, "start", mContextStart);
        IOXML.writeAttrNameValue(aPW, "limit", mContextLimit);
        IOXML.writeAttrNameValue(aPW, "total", mContextTotal);
        aPW.printf("/>%n");
    }
    DataBag dataBag = new DataBag(mDataTable.getColumnBag());
    if (mSaveFieldsWithoutValues)
        dataBag.setAssignedFlagAll(true);
    DataBagXML dataBagXML = new DataBagXML(dataBag);
    dataBagXML.save(aPW, "Columns", anIndentAmount + 2);
    if (rowCount > 0) {
        IOXML.indentLine(aPW, anIndentAmount + 2);
        aPW.printf("<Rows");
        IOXML.writeAttrNameValue(aPW, "count", rowCount);
        aPW.printf(">%n");
        for (int row = 0; row < rowCount; row++) {
            IOXML.indentLine(aPW, anIndentAmount + 3);
            aPW.printf("<Row>%n");
            IOXML.indentLine(aPW, anIndentAmount + 4);
            for (int col = 0; col < columnCount; col++) {
                dataField = mDataTable.getFieldByRowCol(row, col);
                cellValue = dataField.collapse();
                if (StringUtils.isEmpty(cellValue))
                    aPW.printf("<C/>");
                else
                    aPW.printf("<C>%s</C>", StringEscapeUtils.escapeXml10(cellValue));
            }
            aPW.printf("%n");
            IOXML.indentLine(aPW, anIndentAmount + 3);
            aPW.printf("</Row>%n");
        }
        IOXML.indentLine(aPW, anIndentAmount + 2);
        aPW.printf("</Rows>%n");
    }
    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("</%s>%n", tagName);
}

From source file:com.nridge.core.base.io.xml.DocumentXML.java

/**
 * Saves the previous assigned document (e.g. via constructor or set method)
 * to the print writer stream wrapped in a tag name specified in the parameter.
 *
 * @param aPW            PrintWriter stream instance.
 * @param aParentTag     Parent tag name.
 * @param aDocument      Document instance.
 * @param anIndentAmount Indentation count.
 *
 * @throws java.io.IOException I/O related exception.
 *///from   w ww. j a v  a 2s.c o  m
public void save(PrintWriter aPW, String aParentTag, Document aDocument, int anIndentAmount)
        throws IOException {
    RelationshipXML relationshipXML;
    String docType = StringUtils.remove(aDocument.getType(), StrUtl.CHAR_SPACE);
    String parentTag = StringUtils.remove(aParentTag, StrUtl.CHAR_SPACE);

    IOXML.indentLine(aPW, anIndentAmount);
    if (StringUtils.isNotEmpty(aParentTag))
        aPW.printf("<%s-%s", parentTag, docType);
    else
        aPW.printf("<%s", docType);
    if (!mIsSimple) {
        IOXML.writeAttrNameValue(aPW, "type", aDocument.getType());
        IOXML.writeAttrNameValue(aPW, "name", aDocument.getName());
        IOXML.writeAttrNameValue(aPW, "title", aDocument.getTitle());
        IOXML.writeAttrNameValue(aPW, "schemaVersion", aDocument.getSchemaVersion());
    }
    for (Map.Entry<String, String> featureEntry : aDocument.getFeatures().entrySet())
        IOXML.writeAttrNameValue(aPW, featureEntry.getKey(), featureEntry.getValue());
    aPW.printf(">%n");
    DataTableXML dataTableXML = new DataTableXML(aDocument.getTable());
    dataTableXML.setSaveFieldsWithoutValues(mSaveFieldsWithoutValues);
    dataTableXML.save(aPW, IO.XML_TABLE_NODE_NAME, anIndentAmount + 1);
    if (aDocument.relationshipCount() > 0) {
        ArrayList<Relationship> docRelationships = aDocument.getRelationships();
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("<%s>%n", IO.XML_RELATED_NODE_NAME);
        for (Relationship relationship : docRelationships) {
            relationshipXML = new RelationshipXML(relationship);
            relationshipXML.setSaveFieldsWithoutValues(mSaveFieldsWithoutValues);
            relationshipXML.save(aPW, IO.XML_RELATIONSHIP_NODE_NAME, anIndentAmount + 2);
        }
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("</%s>%n", IO.XML_RELATED_NODE_NAME);
    }
    HashMap<String, String> docACL = aDocument.getACL();
    if (docACL.size() > 0) {
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("<%s>%n", IO.XML_ACL_NODE_NAME);
        for (Map.Entry<String, String> aclEntry : docACL.entrySet()) {
            IOXML.indentLine(aPW, anIndentAmount + 2);
            aPW.printf("<%s", IO.XML_ACE_NODE_NAME);
            IOXML.writeAttrNameValue(aPW, "name", aclEntry.getKey());
            aPW.printf(">%s</%s>%n", StringEscapeUtils.escapeXml10(aclEntry.getValue()), IO.XML_ACE_NODE_NAME);
        }
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("</%s>%n", IO.XML_ACL_NODE_NAME);
    }
    IOXML.indentLine(aPW, anIndentAmount);
    if (StringUtils.isNotEmpty(aParentTag))
        aPW.printf("</%s-%s>%n", parentTag, docType);
    else
        aPW.printf("</%s>%n", docType);
}

From source file:org.codelibs.fess.api.gsa.GsaApiManager.java

protected String escapeXml(final Object obj) {
    final StringBuilder buf = new StringBuilder(255);
    if (obj instanceof List<?>) {
        buf.append("<list>");
        for (final Object child : (List<?>) obj) {
            buf.append("<item>").append(escapeXml(child)).append("</item>");
        }/*from  w w w. ja  v  a 2  s.c  om*/
        buf.append("</list>");
    } else if (obj instanceof Map<?, ?>) {
        buf.append("<data>");
        for (final Map.Entry<?, ?> entry : ((Map<?, ?>) obj).entrySet()) {

            buf.append("<name>").append(escapeXml(entry.getKey())).append("</name><value>")
                    .append(escapeXml(entry.getValue())).append("</value>");
        }
        buf.append("</data>");
    } else if (obj instanceof Date) {
        final SimpleDateFormat sdf = new SimpleDateFormat(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
        buf.append(StringEscapeUtils.escapeXml10(sdf.format(obj)));
    } else if (obj != null) {
        buf.append(StringEscapeUtils.escapeXml10(obj.toString()));
    }
    return buf.toString();
}

From source file:org.tightblog.rendering.requests.WeblogSearchRequest.java

private void parseSearchRequestInfo() {
    if (StringUtils.isNotBlank(extraPathInfo)) {
        this.searchPhrase = StringEscapeUtils.escapeXml10(getRequestParameter("q"));
        this.category = Utilities.decode(getRequestParameter("cat"));
    }/*w  w  w .  j  a va  2 s . c o  m*/
}