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.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java

protected void applySequenceFlowProperties(SequenceFlow sequenceFlow, Map<String, String> properties) {
    // sequence flow name is options
    if (properties.get("name") != null && !"".equals(properties.get("name"))) {
        sequenceFlow/*from   w  w w .ja v a 2s.  c  o  m*/
                .setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
        // add unescaped and untouched name value as extension eleent as well
        Utils.setMetaDataExtensionValue(sequenceFlow, "elementname",
                wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
    }
    if (properties.get("bgcolor") != null && properties.get("bgcolor").length() > 0) {
        if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
            List<String> colorsList = new ArrayList<String>();
            colorsList.add("bgcolor:" + properties.get("bgcolor"));
            _elementColors.put(sequenceFlow.getId(), colorsList);
        } else {
            _elementColors.get(sequenceFlow.getId()).add("bgcolor:" + properties.get("bgcolor"));
        }
    }
    if (properties.get("bordercolor") != null && properties.get("bordercolor").length() > 0) {
        if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
            List<String> colorsList = new ArrayList<String>();
            colorsList.add("bordercolor:" + properties.get("bordercolor"));
            _elementColors.put(sequenceFlow.getId(), colorsList);
        } else {
            _elementColors.get(sequenceFlow.getId()).add("bordercolor:" + properties.get("bordercolor"));
        }
    }
    if (properties.get("fontsize") != null && properties.get("fontsize").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata
                .demandFeature("http://www.jboss.org/drools", "fontsize", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute,
                properties.get("fontsize"));
        sequenceFlow.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("fontcolor") != null && properties.get("fontcolor").length() > 0) {
        if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
            List<String> colorsList = new ArrayList<String>();
            colorsList.add("fontcolor:" + properties.get("fontcolor"));
            _elementColors.put(sequenceFlow.getId(), colorsList);
        } else {
            _elementColors.get(sequenceFlow.getId()).add("fontcolor:" + properties.get("fontcolor"));
        }
    }

    // Custom extended auto connection property for Stunner.
    String sourceConnAutoPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.SOURCE;
    String sourceConnAutoRaw = properties.get(sourceConnAutoPropertyName);
    if (null != sourceConnAutoRaw && Boolean.TRUE.equals(Boolean.parseBoolean(sourceConnAutoRaw))) {
        Utils.setMetaDataExtensionValue(sequenceFlow, sourceConnAutoPropertyName, Boolean.toString(true));
    }
    String targetConnAutoPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.TARGET;
    String targetConnAutoRaw = properties.get(targetConnAutoPropertyName);
    if (null != targetConnAutoRaw && Boolean.TRUE.equals(Boolean.parseBoolean(targetConnAutoRaw))) {
        Utils.setMetaDataExtensionValue(sequenceFlow, targetConnAutoPropertyName, Boolean.toString(true));
    }

    if (properties.get("isselectable") != null && properties.get("isselectable").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata
                .demandFeature("http://www.jboss.org/drools", "selectable", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute,
                properties.get("isselectable"));
        sequenceFlow.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) {
        Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing();
        audit.getDocumentation().add(createDocumentation(properties.get("auditing")));
        sequenceFlow.setAuditing(audit);
    }
    applySequenceFlowCondition(sequenceFlow, properties);
    if (properties.get("priority") != null && !"".equals(properties.get("priority"))) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl priorityElement = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools",
                "priority", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(priorityElement,
                properties.get("priority"));
        sequenceFlow.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) {
        Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring();
        monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring")));
        sequenceFlow.setMonitoring(monitoring);
    }
    sequenceFlow.setIsImmediate(Boolean.parseBoolean(properties.get("isimmediate")));
    // simulation properties
    if (properties.get("probability") != null && properties.get("probability").length() > 0) {
        ControlParameters controlParams = BpsimFactory.eINSTANCE.createControlParameters();
        Parameter probParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType probParamValueParam = BpsimFactory.eINSTANCE.createFloatingParameterType();
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        probParamValueParam
                .setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("probability")))));
        probParam.getParameterValue().add(probParamValueParam);
        controlParams.setProbability(probParam);
        if (_simulationElementParameters.containsKey(sequenceFlow.getId())) {
            _simulationElementParameters.get(sequenceFlow.getId()).add(controlParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(controlParams);
            _simulationElementParameters.put(sequenceFlow.getId(), values);
        }
    }
}

From source file:org.kuali.coeus.common.impl.custom.attr.CustomAttributeServiceImpl.java

@Override
public void setCustomAttributeKeyValue(String documentNumber,
        Map<String, CustomAttributeDocument> customAttributeDocuments, String attributeName, String networkId) {
    WorkflowDocument workflowDocument = WorkflowDocumentFactory.loadDocument(networkId, documentNumber);

    // Not sure to delete all the content, but there is no other options
    workflowDocument.clearAttributeContent();
    WorkflowAttributeDefinition customDataDef = WorkflowAttributeDefinition.Builder.create(attributeName)
            .build();//from  w w w.j ava 2s . com
    WorkflowAttributeDefinition.Builder refToUpdate = WorkflowAttributeDefinition.Builder.create(customDataDef);

    if (customAttributeDocuments != null) {
        for (Map.Entry<String, CustomAttributeDocument> customAttributeDocumentEntry : customAttributeDocuments
                .entrySet()) {
            CustomAttributeDocument customAttributeDocument = customAttributeDocumentEntry.getValue();
            if (StringUtils.isNotBlank(customAttributeDocument.getCustomAttribute().getValue())) {
                refToUpdate.addPropertyDefinition(customAttributeDocument.getCustomAttribute().getName(),
                        StringEscapeUtils.escapeXml(customAttributeDocument.getCustomAttribute().getValue()));
            }
        }
    }
    workflowDocument.addAttributeDefinition(refToUpdate.build());
    workflowDocument.saveDocumentData();
}

From source file:org.lobid.lodmill.OaiDcEncoder.java

@Override
public void literal(final String name, final String value) {
    writer.write("<" + name + ">\n\t");
    writer.write(StringEscapeUtils.escapeXml(value));
    writer.write("\n</" + name + ">\n");
}

From source file:org.lobid.lodmill.XmlEntitySplitter.java

private void appendValuesToEntity(final String qName, final Attributes attributes) {
    this.builder.append("<" + qName);
    if (attributes.getLength() > 0) {
        for (int i = 0; i < attributes.getLength(); i++) {
            builder.append(" " + attributes.getQName(i) + "=\""
                    + StringEscapeUtils.escapeXml(attributes.getValue(i)) + "\"");
        }/*from w  ww  .j  av  a  2s. co m*/
    }
    builder.append(">");
}

From source file:org.lobid.lodmill.XmlEntitySplitter.java

@Override
public void characters(final char[] chars, final int start, final int length) throws SAXException {
    builder.append(StringEscapeUtils.escapeXml(new String(chars, start, length)));
}

From source file:org.mayocat.shop.front.views.WebViewMessageBodyWriter.java

private void writeDeveloperError(WebView webView, Exception e, OutputStream entityStream) {
    try {// w w w  .ja v a  2 s.  c om
        // Note:
        // This could be seen as a "server error", but we don't set the Status header to 500 because we want to be
        // able to distinguish between actual server errors (internal Mayocat Shop server error) and theme
        // developers errors (which this is).
        // This is comes at play when setting up monitoring with alerts on a number of 5xx response above a
        // certain threshold.

        // Re-serialize the context as json with indentation for better debugging
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        Map<String, Object> context = webView.data();
        String jsonContext = mapper.writeValueAsString(context);
        Template error = new Template("developerError",
                Resources.toString(Resources.getResource("templates/developerError.html"), Charsets.UTF_8));
        Map<String, Object> errorContext = Maps.newHashMap();
        errorContext.put("error", StringEscapeUtils.escapeXml(cleanErrorMessageForDisplay(e.getMessage())));
        errorContext.put("stackTrace", StringEscapeUtils.escapeXml(ExceptionUtils.getStackTrace(e)));
        errorContext.put("context", StringEscapeUtils.escapeXml(jsonContext).trim());
        errorContext.put("rawContext", jsonContext);
        errorContext.put("template", webView.template().toString());

        engine.get().register(error);
        String rendered = engine.get().render(error.getId(), mapper.writeValueAsString(errorContext));
        entityStream.write(rendered.getBytes());
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }
}

From source file:org.meresco.triplestore.HttpHandler.java

public String sparqlForm(QueryParameters httpArguments) {
    String query;//from  w ww.ja  v a 2s. c o m
    if (httpArguments.containsKey("query")) {
        query = httpArguments.singleValue("query");
    } else {
        query = "";
        for (Namespace namespace : this.tripleStore.getNamespaces()) {
            query += "PREFIX " + namespace.getPrefix() + ": <" + namespace.getName() + ">\n";
        }
        query += "\nSELECT ?subject ?predicate ?object\n";
        query += "WHERE { ?subject ?predicate ?object }\n";
        query += "LIMIT 50";
    }
    return "<html><head><title>Meresco Triplestore Sparql Form</title></head>\n"
            + "<body><form action=\"/query\">\n" + "<textarea cols=\"100\" rows=\"20\" name=\"query\">"
            + StringEscapeUtils.escapeXml(query) + "</textarea><br/>\n"
            + "<input type=\"hidden\" name=\"outputContentType\" value=\"application/json\"/>\n"
            + "Format: <select name=\"mimeType\">\n"
            + "<option value=\"application/sparql-results+json\">json</option>\n"
            + "<option value=\"application/xml\">xml</option>\n" + "</select><br />\n"
            + "<input type=\"submit\">\n" + "</form>\n</body></html>";
}

From source file:org.meresco.triplestore.TransactionItem.java

public String toString() {
    return "<transaction_item>" + "<action>" + this.action + "</action>" + "<identifier>"
            + StringEscapeUtils.escapeXml(this.identifier) + "</identifier>" + "<filedata>"
            + Base64.encodeBase64String(this.filedata.getBytes()) + "</filedata>" + "</transaction_item>\n";
}

From source file:org.mfcrawler.model.export.gexf.ExportPagesGexf.java

/**
 * Writes a gexf node from a page//from  w w  w. j a  va  2 s .  c om
 * @param fileWriter the file write
 * @param site the page (the node)
 * @exception
 */
private static void writeGexfNode(FileWriter fileWriter, Page page) throws IOException {
    String linkName = StringEscapeUtils.escapeXml(page.getLink().getUrl());
    String titleName = StringEscapeUtils.escapeXml(page.getTitle());
    fileWriter.write("<node id=\"");
    fileWriter.write(linkName);
    fileWriter.write("\" label=\"");
    fileWriter.write(titleName);
    fileWriter.write("\" start=\"");
    fileWriter.write(ConversionUtils.toFormattedDate(page.getCrawlTime(), DATETIME_FORMAT));

    fileWriter.write("\"> <attvalues> <attvalue for=\"score\" value=\"");
    fileWriter.write(ConversionUtils.toString(page.getScore()));
    fileWriter.write("\"/> <attvalue for=\"innerDeep\" value=\"");
    fileWriter.write(ConversionUtils.toString(page.getInnerDeep()));
    fileWriter.write("\"/> <attvalue for=\"outerDeep\" value=\"");
    fileWriter.write(ConversionUtils.toString(page.getOuterDeep()));
    fileWriter.write("\"/> </attvalues> </node> \n");
}

From source file:org.mfcrawler.model.export.gexf.ExportPagesGexf.java

/**
 * Writes a gexf edge from a source link (correct page) and a target link
 * @param fileWriter the file write/*  ww w  . jav  a2 s.c om*/
 * @param edgeId the edge id
 * @param sourceLink the source link, the source of the edge
 * @param targetLink the outgoing link, the target of the edge
 * @exception
 */
private static void writeGexfEdge(FileWriter fileWriter, int edgeId, Link sourceLink, Link targetLink)
        throws IOException {
    fileWriter.write("<edge id=\"");
    fileWriter.write(ConversionUtils.toString(edgeId));
    fileWriter.write("\" source=\"");
    fileWriter.write(StringEscapeUtils.escapeXml(sourceLink.getUrl()));
    fileWriter.write("\" target=\"");
    fileWriter.write(StringEscapeUtils.escapeXml(targetLink.getUrl()));
    fileWriter.write("\" type=\"directed\" /> \n");
}