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

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

Introduction

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

Prototype

public static final String unescapeXml(final String input) 

Source Link

Document

Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the five basic XML entities (gt, lt, quot, amp, apos).

Usage

From source file:org.jvoicexml.profile.vxml21.tagstrategy.AbstractTagStrategy.java

/**
 * {@inheritDoc}//from   ww w.  ja  v  a  2s  .  c  o  m
 */
public void evalAttributes(final VoiceXmlInterpreterContext context) throws SemanticError {
    final Collection<String> evalAttributes = getEvalAttributes();
    if (evalAttributes == null) {
        return;
    }

    final DataModel model = context.getDataModel();
    for (String name : evalAttributes) {
        final Object expr = attributes.get(name);
        if (expr != null) {
            final String exprstring = expr.toString();
            final String cleanedExprstring = StringEscapeUtils.unescapeXml(exprstring);
            final Object value = model.evaluateExpression(cleanedExprstring, Object.class);
            attributes.put(name, value);
        }
    }
}

From source file:org.jvoicexml.profile.vxml21.tagstrategy.IfStrategy.java

/**
 * Checks the condition of the given node.
 *
 * @param context//  ww  w .  j  a  va  2  s .  c o m
 *            The current VoiceXML interpreter context
 * @param node
 *            The node with a cond.
 * @return <code>true</code> if the cond expression evaluates to true.
 *
 * @exception SemanticError
 *                Error evaluating the cond expression.
 */
private boolean checkCondition(final VoiceXmlInterpreterContext context, final VoiceXmlNode node)
        throws SemanticError {
    final String cond = node.getAttribute(If.ATTRIBUTE_COND);
    if (cond == null) {
        // This holds only for the else cases.
        return true;
    }

    final DataModel model = context.getDataModel();
    final String unescapedCond = StringEscapeUtils.unescapeXml(cond);
    return model.evaluateExpression(unescapedCond, Boolean.class);
}

From source file:org.jvoicexml.profile.vxml21.tagstrategy.LogStrategy.java

/**
 * {@inheritDoc}/*from  www. j  av  a2s.  c  o  m*/
 *
 * Logs the containing text as a message.
 */
public void execute(final VoiceXmlInterpreterContext context, final VoiceXmlInterpreter interpreter,
        final FormInterpretationAlgorithm fia, final FormItem item, final VoiceXmlNode node)
        throws JVoiceXMLEvent {
    final NodeList list = node.getChildNodes();
    final StringBuilder outputText = new StringBuilder();

    // get and write the label attribute
    final String label = (String) getAttribute(Log.ATTRIBUTE_LABEL);
    if (label != null) {
        outputText.append(label);
        outputText.append(": ");
    }

    final String expr = (String) getAttribute(Log.ATTRIBUTE_EXPR);
    if (expr != null) {
        outputText.append(expr);
    }

    // process children
    final DataModel model = context.getDataModel();
    for (int i = 0; i < list.getLength(); i++) {
        final VoiceXmlNode current = (VoiceXmlNode) list.item(i);
        if (current instanceof Text) {
            // text node handling
            final Text text = (Text) current;
            final String msg = text.getNodeValue();
            if (msg == null) {
                LOGGER.warn("ignoring empty log node");
            } else {
                outputText.append(msg.trim());
            }
        }

        if (current instanceof Value) {
            // value node handling
            final Value value = (Value) current;
            String currentExpr = value.getExpr();
            if (currentExpr != null) {
                final String unescapedCurrentExpr = StringEscapeUtils.unescapeXml(currentExpr);
                if (!currentExpr.endsWith(";")) {
                    currentExpr += ";";
                }
                final Object eval = model.evaluateExpression(unescapedCurrentExpr, Object.class);
                final String evalReadable = model.toString(eval);
                outputText.append(evalReadable);
            }
        }
    }

    // write the eventual tag-value to the class-logger,
    // priority Level.INFO
    if (outputText.length() > 0) {
        LOGGER.info(outputText.toString());
    }
}

From source file:org.jvoicexml.profile.vxml21.tagstrategy.ScriptStrategy.java

/**
 * Processes an internal script./*from w w w. j  a  va2s. c o m*/
 * 
 * @param script
 *            the script to evaluate
 * @param model
 *            the employed data model
 * @throws SemanticError
 *             Error evaluating the script.
 */
private void processInternalScript(final String script, final DataModel model) throws SemanticError {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("evaluating internal script: " + script);
    }
    final String cleanedScript = StringEscapeUtils.unescapeXml(script);
    model.evaluateExpression(cleanedScript, Object.class);
}

From source file:org.jvoicexml.profile.vxml21.tagstrategy.ValueStrategy.java

/**
 * Retrieves the TTS output of this tag.
 *
 * @return Output of this tag, <code>null</code> if there is no text to
 *         output./*from ww w. j  ava2 s .  c  o  m*/
 *
 * @exception SemanticError
 *                Error evaluating an expression.
 */
private String getOutput() throws SemanticError {
    final Object result = getAttribute(Value.ATTRIBUTE_EXPR);
    if (result == null) {
        LOGGER.warn("ignoring empty value result");

        return null;
    }

    final String text = result.toString();
    final String cleaned = text.trim();
    if (cleaned.length() == 0) {
        LOGGER.warn("ignoring empty value node");

        return null;
    }

    return StringEscapeUtils.unescapeXml(cleaned);
}

From source file:org.kie.server.services.jbpm.ui.form.InMemoryFormProvider.java

protected String filterXML(String document, String lang, String deploymentId, Map inputs, Map outputs) {
    try {/* ww w . j  a va 2 s.  co m*/
        if (inputs == null) {
            inputs = Collections.emptyMap();
        }
        if (outputs == null) {
            outputs = Collections.emptyMap();
        }

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();

        Document doc = builder.parse(new ByteArrayInputStream(document.getBytes()));
        NodeList nodes = doc.getElementsByTagName(NODE_FORM);
        Node nodeForm = nodes.item(0);
        NodeList childNodes = nodeForm.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if (node.getNodeName().equals(NODE_FIELD)) {

                String fieldType = node.getAttributes().getNamedItem(ATTR_TYPE).getNodeValue();
                if (SUB_FORM_TYPE.equals(fieldType)) {

                    String defaultSubForm = findPropertyValue(node, "defaultSubform");
                    if (defaultSubForm != null) {

                        String subFormContent = formManagerService.getFormByKey(deploymentId, defaultSubForm);

                        if (subFormContent != null) {
                            // read once to find out input binding name
                            Document tmpSubForm = builder
                                    .parse(new ByteArrayInputStream(subFormContent.getBytes()));

                            Node firstFieldNode = tmpSubForm.getElementsByTagName(NODE_FIELD).item(0);
                            // inputs - current node
                            String currentNodeInputBinding = findPropertyValue(node, "inputBinding");
                            currentNodeInputBinding = currentNodeInputBinding.replaceAll("/", ".");

                            // outputs current node
                            String currentNodeOutputBinding = findPropertyValue(node, "outputBinding");
                            currentNodeOutputBinding = currentNodeOutputBinding.replaceAll("/", ".");

                            // inputs sub form
                            String inputBindingSubForm = findPropertyValue(firstFieldNode, "inputBinding");
                            inputBindingSubForm = inputBindingSubForm.split("/")[0];

                            // outputs sub form
                            String outputBindingSubForm = findPropertyValue(firstFieldNode, "outputBinding");
                            outputBindingSubForm = outputBindingSubForm.split("/")[0];

                            Map<String, Object> subFormInputs = new HashMap<String, Object>(inputs);
                            try {
                                subFormInputs.put(inputBindingSubForm,
                                        MVELSafeHelper.getEvaluator().eval(currentNodeInputBinding, inputs));
                            } catch (Exception e) {

                            }

                            Map<String, Object> subFormOutputs = new HashMap<String, Object>(outputs);
                            try {
                                subFormOutputs.put(outputBindingSubForm,
                                        MVELSafeHelper.getEvaluator().eval(currentNodeOutputBinding, outputs));
                            } catch (Exception e) {

                            }

                            // run the transformation
                            String filtered = filterXML(subFormContent, lang, deploymentId, subFormInputs,
                                    subFormOutputs);

                            Document docSubForm = builder.parse(new ByteArrayInputStream(filtered.getBytes()));
                            NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                            Node nodeFormSubForm = nodesSubForm.item(0);

                            Node imported = doc.importNode(nodeFormSubForm, true);

                            node.getParentNode().replaceChild(imported, node);
                        }
                    }
                } else if (MULTI_SUB_FORM_TYPE.equals(fieldType)) {

                    String defaultSubForm = findPropertyValue(node, "defaultSubform");
                    if (defaultSubForm != null) {

                        String subFormContent = formManagerService.getFormByKey(deploymentId, defaultSubForm);
                        if (subFormContent != null) {

                            String inputBinding = findPropertyValue(node, "inputBinding");
                            inputBinding = inputBinding.replaceAll("/", ".");

                            String outputBinding = findPropertyValue(node, "outputBinding");
                            outputBinding = outputBinding.replaceAll("/", ".");

                            Collection<Object> list = new ArrayList<Object>();
                            Collection<Object> listOut = new ArrayList<Object>();
                            Map<String, Object> subFormInputs = new HashMap<String, Object>(inputs);
                            Map<String, Object> subFormOutputs = new HashMap<String, Object>(outputs);
                            try {
                                list = (Collection<Object>) MVELSafeHelper.getEvaluator().eval(inputBinding,
                                        inputs);
                            } catch (Exception e) {
                                // no elements found add simple object to generate single line
                                list.add(new Object());
                            }
                            try {
                                listOut = (Collection<Object>) MVELSafeHelper.getEvaluator().eval(outputBinding,
                                        outputs);
                            } catch (Exception e) {
                                // no elements found add simple object to generate single line
                                list.add(new Object());
                            }

                            // read once to find out input binding name
                            Document tmpSubForm = builder
                                    .parse(new ByteArrayInputStream(subFormContent.getBytes()));

                            Node firstFieldNode = tmpSubForm.getElementsByTagName(NODE_FIELD).item(0);

                            String inputBindingSubForm = findPropertyValue(firstFieldNode, "inputBinding");
                            inputBindingSubForm = inputBindingSubForm.split("/")[0];

                            String outputBindingSubForm = findPropertyValue(firstFieldNode, "outputBinding");
                            outputBindingSubForm = outputBindingSubForm.split("/")[0];
                            // inputs
                            for (Object element : list) {
                                subFormInputs.put(inputBindingSubForm, element);

                                String filtered = filterXML(subFormContent, lang, deploymentId, subFormInputs,
                                        subFormOutputs);

                                Document docSubForm = builder
                                        .parse(new ByteArrayInputStream(filtered.getBytes()));
                                NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                                Node nodeFormSubForm = nodesSubForm.item(0);

                                Node imported = doc.importNode(nodeFormSubForm, true);

                                node.getParentNode().appendChild(imported);
                            }
                            // outputs
                            for (Object element : listOut) {
                                subFormOutputs.put(outputBindingSubForm, element);

                                String filtered = filterXML(subFormContent, lang, deploymentId,
                                        Collections.emptyMap(), subFormOutputs);

                                Document docSubForm = builder
                                        .parse(new ByteArrayInputStream(filtered.getBytes()));
                                NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                                Node nodeFormSubForm = nodesSubForm.item(0);

                                Node imported = doc.importNode(nodeFormSubForm, true);

                                node.getParentNode().appendChild(imported);
                            }

                            node.getParentNode().removeChild(node);
                        }

                    }

                } else {

                    NodeList fieldPropsNodes = node.getChildNodes();
                    for (int j = 0; j < fieldPropsNodes.getLength(); j++) {
                        Node nodeFieldProp = fieldPropsNodes.item(j);
                        if (nodeFieldProp.getNodeName().equals(NODE_PROPERTY)) {
                            String propName = nodeFieldProp.getAttributes().getNamedItem(ATTR_NAME)
                                    .getNodeValue();
                            String value = StringEscapeUtils.unescapeXml(
                                    nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());
                            if (inputs != null && propName != null && value != null
                                    && "inputBinding".equals(propName)) {
                                if (!value.isEmpty()) {
                                    value = value.replaceAll("/", ".");
                                    try {
                                        Object actualValue = MVELSafeHelper.getEvaluator().eval(value, inputs);

                                        nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE)
                                                .setNodeValue(String.valueOf(actualValue));
                                    } catch (Exception e) {
                                        // no elements found add simple object to generate single line

                                    }
                                }
                            } else if (outputs != null && propName != null && value != null
                                    && "outputBinding".equals(propName)) {
                                if (!value.isEmpty()) {
                                    value = value.replaceAll("/", ".");
                                    try {
                                        Object actualValue = MVELSafeHelper.getEvaluator().eval(value, outputs);

                                        nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE)
                                                .setNodeValue(String.valueOf(actualValue));
                                    } catch (Exception e) {
                                        // no elements found add simple object to generate single line

                                    }
                                }
                            } else if (propName != null && value != null
                                    && ATTR_LANG_NAMES.contains(propName)) {
                                filterProperty(nodeFieldProp, lang, value);
                            }
                        }
                    }
                }
            }
        }

        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);
        document = writer.toString();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return document;
}

From source file:org.kie.server.services.jbpm.ui.form.InMemoryFormProvider.java

protected String findPropertyValue(Node node, String propertyName) {
    NodeList fieldPropsNodes = node.getChildNodes();
    for (int j = 0; j < fieldPropsNodes.getLength(); j++) {
        Node nodeFieldProp = fieldPropsNodes.item(j);
        if (nodeFieldProp.getNodeName().equals(NODE_PROPERTY)) {
            String propName = nodeFieldProp.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
            String value = StringEscapeUtils
                    .unescapeXml(nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());
            if (propertyName.equals(propName)) {
                return value;
            }//w  w w  . j  a  v a  2  s.c om
        }
    }

    return null;
}

From source file:org.kie.server.services.jbpm.ui.form.RemoteFormModellerFormProvider.java

protected String filterXML(String document, String lang, String deploymentId, Map inputs, Map outputs) {
    try {//  w  w  w.ja v a  2 s.c  om
        if (inputs == null) {
            inputs = Collections.emptyMap();
        }
        if (outputs == null) {
            outputs = Collections.emptyMap();
        }

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();

        Document doc = builder.parse(new ByteArrayInputStream(document.getBytes()));
        NodeList nodes = doc.getElementsByTagName(NODE_FORM);
        Node nodeForm = nodes.item(0);
        NodeList childNodes = nodeForm.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if (node.getNodeName().equals(NODE_FIELD)) {

                String fieldType = node.getAttributes().getNamedItem(ATTR_TYPE).getNodeValue();
                if (SUB_FORM_TYPE.equals(fieldType)) {

                    String defaultSubForm = findPropertyValue(node, "defaultSubform");
                    if (defaultSubForm != null) {

                        String subFormContent = formManagerService.getFormByKey(deploymentId, defaultSubForm);

                        if (subFormContent != null) {
                            // read once to find out input binding name
                            Document tmpSubForm = builder
                                    .parse(new ByteArrayInputStream(subFormContent.getBytes()));

                            Node firstFieldNode = tmpSubForm.getElementsByTagName(NODE_FIELD).item(0);
                            // inputs - current node
                            String currentNodeInputBinding = findPropertyValue(node, "inputBinding");
                            currentNodeInputBinding = currentNodeInputBinding.replaceAll("/", ".");

                            // outputs current node
                            String currentNodeOutputBinding = findPropertyValue(node, "outputBinding");
                            currentNodeOutputBinding = currentNodeOutputBinding.replaceAll("/", ".");

                            // inputs sub form
                            String inputBindingSubForm = findPropertyValue(firstFieldNode, "inputBinding");
                            inputBindingSubForm = inputBindingSubForm.split("/")[0];

                            // outputs sub form
                            String outputBindingSubForm = findPropertyValue(firstFieldNode, "outputBinding");
                            outputBindingSubForm = outputBindingSubForm.split("/")[0];

                            Map<String, Object> subFormInputs = new HashMap<String, Object>(inputs);
                            try {
                                subFormInputs.put(inputBindingSubForm,
                                        MVELSafeHelper.getEvaluator().eval(currentNodeInputBinding, inputs));
                            } catch (Exception e) {

                            }

                            Map<String, Object> subFormOutputs = new HashMap<String, Object>(outputs);
                            try {
                                subFormOutputs.put(outputBindingSubForm,
                                        MVELSafeHelper.getEvaluator().eval(currentNodeOutputBinding, outputs));
                            } catch (Exception e) {

                            }

                            // run the transformation
                            String filtered = filterXML(subFormContent, lang, deploymentId, subFormInputs,
                                    subFormOutputs);

                            Document docSubForm = builder.parse(new ByteArrayInputStream(filtered.getBytes()));
                            NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                            Node nodeFormSubForm = nodesSubForm.item(0);

                            Node imported = doc.importNode(nodeFormSubForm, true);

                            node.getParentNode().appendChild(imported);
                        }
                    }
                } else if (MULTI_SUB_FORM_TYPE.equals(fieldType)) {

                    String defaultSubForm = findPropertyValue(node, "defaultSubform");
                    if (defaultSubForm != null) {

                        String subFormContent = formManagerService.getFormByKey(deploymentId, defaultSubForm);
                        if (subFormContent != null) {

                            String inputBinding = findPropertyValue(node, "inputBinding");
                            inputBinding = inputBinding.replaceAll("/", ".");

                            String outputBinding = findPropertyValue(node, "outputBinding");
                            outputBinding = outputBinding.replaceAll("/", ".");

                            Collection<Object> list = new ArrayList<Object>();
                            Collection<Object> listOut = new ArrayList<Object>();
                            Map<String, Object> subFormInputs = new HashMap<String, Object>(inputs);
                            Map<String, Object> subFormOutputs = new HashMap<String, Object>(outputs);
                            try {
                                list = (Collection<Object>) MVELSafeHelper.getEvaluator().eval(inputBinding,
                                        inputs);
                            } catch (Exception e) {
                                // no elements found add simple object to generate single line
                                list.add(new Object());
                            }
                            try {
                                listOut = (Collection<Object>) MVELSafeHelper.getEvaluator().eval(outputBinding,
                                        outputs);
                            } catch (Exception e) {
                                // no elements found add simple object to generate single line
                                list.add(new Object());
                            }

                            // read once to find out input binding name
                            Document tmpSubForm = builder
                                    .parse(new ByteArrayInputStream(subFormContent.getBytes()));

                            Node firstFieldNode = tmpSubForm.getElementsByTagName(NODE_FIELD).item(0);

                            String inputBindingSubForm = findPropertyValue(firstFieldNode, "inputBinding");
                            inputBindingSubForm = inputBindingSubForm.split("/")[0];

                            String outputBindingSubForm = findPropertyValue(firstFieldNode, "outputBinding");
                            outputBindingSubForm = outputBindingSubForm.split("/")[0];

                            Node nodeFormSubForm = null;

                            // inputs
                            for (Object element : list) {
                                subFormInputs.put(inputBindingSubForm, element);

                                String filtered = filterXML(subFormContent, lang, deploymentId, subFormInputs,
                                        subFormOutputs);

                                Document docSubForm = builder
                                        .parse(new ByteArrayInputStream(filtered.getBytes()));
                                NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                                nodeFormSubForm = nodesSubForm.item(0);
                            }
                            // outputs
                            for (Object element : listOut) {
                                subFormOutputs.put(outputBindingSubForm, element);

                                String filtered = filterXML(subFormContent, lang, deploymentId,
                                        Collections.emptyMap(), subFormOutputs);

                                Document docSubForm = builder
                                        .parse(new ByteArrayInputStream(filtered.getBytes()));
                                NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                                nodeFormSubForm = nodesSubForm.item(0);
                            }

                            // Adding nestedForm after filtering inputs & outputs
                            Node imported = doc.importNode(nodeFormSubForm, true);
                            node.getParentNode().appendChild(imported);
                        }
                    }
                }

                NodeList fieldPropsNodes = node.getChildNodes();
                for (int j = 0; j < fieldPropsNodes.getLength(); j++) {
                    Node nodeFieldProp = fieldPropsNodes.item(j);
                    if (nodeFieldProp.getNodeName().equals(NODE_PROPERTY)) {
                        String propName = nodeFieldProp.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
                        String value = StringEscapeUtils.unescapeXml(
                                nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());
                        if (inputs != null && propName != null && value != null
                                && "inputBinding".equals(propName)) {
                            setPropertyNodeValue(nodeFieldProp, value, inputs);
                        } else if (outputs != null && propName != null && value != null
                                && "outputBinding".equals(propName)) {
                            setPropertyNodeValue(nodeFieldProp, value, outputs);
                        } else if (propName != null && ATTR_LANG_NAMES.contains(propName)
                                && !StringUtils.isEmpty(value)) {
                            filterProperty(nodeFieldProp, lang, value);
                        }
                    }
                }
            }
        }

        document = asString(doc);
    } catch (Exception ex) {
        logger.error("Error when filtering form", ex);
    }
    return document;
}

From source file:org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl.java

public Form deserializeForm(Node nodeForm) throws Exception {
    if (!nodeForm.getNodeName().equals(NODE_FORM)) {
        return null;
    }/*from ww  w  .  ja v a2  s . co  m*/

    Form form = new Form();
    form.setId(Long.valueOf(
            StringEscapeUtils.unescapeXml(nodeForm.getAttributes().getNamedItem(ATTR_ID).getNodeValue())));

    Set<Field> fields = new TreeSet<>();
    NodeList childNodes = nodeForm.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeName().equals(NODE_PROPERTY)) {
            String propName = node.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
            String value = StringEscapeUtils
                    .unescapeXml(node.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());

            if ("subject".equals(propName)) {
                form.setSubject(value);
            } else if ("name".equals(propName)) {
                form.setName(value);
            } else if ("displayMode".equals(propName)) {
                form.setDisplayMode(value);
            } else if ("labelMode".equals(propName)) {
                form.setLabelMode(value);
            } else if ("showMode".equals(propName)) {
                form.setShowMode(value);
            } else if ("status".equals(propName)) {
                form.setStatus(Long.valueOf(value));
            } else if ("formTemplate".equals(propName)) {
                form.setFormTemplate(value);
            } else if ("migrationStep".equals(propName)) {
                form.setMigrationStep(Integer.decode(value));
            }
        } else if (node.getNodeName().equals(NODE_FIELD)) {
            Field field = deserializeField(node);
            field.setForm(form);
            fields.add(field);
        } else if (node.getNodeName().equals(NODE_DATA_HOLDER)) {
            String holderId = getNodeAttributeValue(node, ATTR_ID);
            String holderInputId = getNodeAttributeValue(node, ATTR_INPUT_ID);
            String holderOutId = getNodeAttributeValue(node, ATTR_OUT_ID);
            String holderType = getNodeAttributeValue(node, ATTR_TYPE);
            String holderValue = getNodeAttributeValue(node, ATTR_VALUE);
            String holderRenderColor = getNodeAttributeValue(node, ATTR_NAME);
            String holderSupportedType = getNodeAttributeValue(node, ATTR_SUPPORTED_TYPE);

            DataHolder dataHolder = new DataHolder(holderId, holderInputId, holderOutId, holderType,
                    holderValue, holderRenderColor, holderSupportedType);

            form.setDataHolder(dataHolder);
        }
    }
    if (fields != null) {
        form.setFormFields(fields);
    }
    return form;
}

From source file:org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl.java

public Field deserializeField(Node nodeField) throws Exception {
    if (!nodeField.getNodeName().equals(NODE_FIELD)) {
        return null;
    }/*  w w w.  j  a  v a  2s .  c o m*/

    Field field = new Field();
    field.setId(Long.valueOf(nodeField.getAttributes().getNamedItem(ATTR_ID).getNodeValue()));
    field.setFieldName(nodeField.getAttributes().getNamedItem(ATTR_NAME).getNodeValue());
    field.setPosition(Integer.parseInt(nodeField.getAttributes().getNamedItem(ATTR_POSITION).getNodeValue()));
    field.setFieldType(
            fieldTypeManager.getTypeByCode(nodeField.getAttributes().getNamedItem(ATTR_TYPE).getNodeValue()));

    Node bag = nodeField.getAttributes().getNamedItem(ATTR_BAG_TYPE);

    if (bag != null) {
        field.setBag(bag.getNodeValue());
    }

    NodeList fieldPropsNodes = nodeField.getChildNodes();
    for (int j = 0; j < fieldPropsNodes.getLength(); j++) {
        Node nodeFieldProp = fieldPropsNodes.item(j);
        if (nodeFieldProp.getNodeName().equals(NODE_PROPERTY)) {
            String propName = nodeFieldProp.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
            String value = StringEscapeUtils
                    .unescapeXml(nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());
            if (propName != null && value != null) {
                if ("fieldRequired".equals(propName)) {
                    field.setFieldRequired(Boolean.valueOf(value));
                } else if ("groupWithPrevious".equals(propName)) {
                    field.setGroupWithPrevious(Boolean.valueOf(value));
                } else if ("height".equals(propName)) {
                    field.setHeight(value);
                } else if ("labelCSSClass".equals(propName)) {
                    field.setLabelCSSClass(value);
                } else if ("labelCSSStyle".equals(propName)) {
                    field.setLabelCSSStyle(value);
                } else if ("label".equals(propName)) {
                    field.setLabel(deserializeI18nEntrySet(value));
                } else if ("errorMessage".equals(propName)) {
                    field.setErrorMessage(deserializeI18nEntrySet(value));
                } else if ("title".equals(propName)) {
                    field.setTitle(deserializeI18nEntrySet(value));
                } else if ("readonly".equals(propName)) {
                    field.setReadonly(Boolean.valueOf(value));
                } else if ("size".equals(propName)) {
                    if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) {
                        field.setSize(Long.valueOf(value));
                    }
                } else if ("formula".equals(propName)) {
                    field.setFormula(value);
                } else if ("rangeFormula".equals(propName)) {
                    field.setRangeFormula(value);
                } else if ("pattern".equals(propName)) {
                    field.setPattern(value);
                } else if ("maxlength".equals(propName)) {
                    if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) {
                        field.setMaxlength(Long.valueOf(value));
                    }
                } else if ("styleclass".equals(propName)) {
                    field.setStyleclass(value);
                } else if ("cssStyle".equals(propName)) {
                    field.setCssStyle(value);
                } else if ("tabindex".equals(propName)) {
                    if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value)) {
                        field.setTabindex(Long.valueOf(value));
                    }
                } else if ("accesskey".equals(propName)) {
                    field.setAccesskey(value);
                } else if ("isHTML".equals(propName)) {
                    field.setIsHTML(Boolean.valueOf(value));
                } else if ("htmlContent".equals(propName)) {
                    field.setHtmlContent(deserializeI18nEntrySet(value));
                } else if ("hideContent".equals(propName)) {
                    field.setHideContent(Boolean.valueOf(value));
                } else if ("defaultValueFormula".equals(propName)) {
                    field.setDefaultValueFormula(value);
                } else if ("defaultSubform".equals(propName)) {
                    field.setDefaultSubform(value);
                } else if ("previewSubform".equals(propName)) {
                    field.setPreviewSubform(value);
                } else if ("tableSubform".equals(propName)) {
                    field.setTableSubform(value);
                } else if ("newItemText".equals(propName)) {
                    field.setNewItemText(deserializeI18nEntrySet(value));
                } else if ("addItemText".equals(propName)) {
                    field.setAddItemText(deserializeI18nEntrySet(value));
                } else if ("cancelItemText".equals(propName)) {
                    field.setCancelItemText(deserializeI18nEntrySet(value));
                } else if ("deleteItems".equals(propName)) {
                    field.setDeleteItems(Boolean.valueOf(value));
                } else if ("updateItems".equals(propName)) {
                    field.setUpdateItems(Boolean.valueOf(value));
                } else if ("visualizeItems".equals(propName)) {
                    field.setVisualizeItem(Boolean.valueOf(value));
                } else if ("hideCreateItem".equals(propName)) {
                    field.setHideCreateItem(Boolean.valueOf(value));
                } else if ("expanded".equals(propName)) {
                    field.setExpanded(Boolean.valueOf(value));
                } else if ("enableTableEnterData".equals(propName)) {
                    field.setEnableTableEnterData(Boolean.valueOf(value));
                } else if ("inputBinding".equals(propName)) {
                    field.setInputBinding(value);
                } else if ("outputBinding".equals(propName)) {
                    field.setOutputBinding(value);
                } else if ("customFieldType".equals(propName)) {
                    field.setCustomFieldType(value);
                } else if ("param1".equals(propName)) {
                    field.setParam1(value);
                } else if ("param2".equals(propName)) {
                    field.setParam2(value);
                } else if ("param3".equals(propName)) {
                    field.setParam3(value);
                } else if ("param4".equals(propName)) {
                    field.setParam4(value);
                } else if ("param5".equals(propName)) {
                    field.setParam5(value);
                } else if ("fieldClass".equals(propName)) {
                    field.getFieldType().setFieldClass(value);
                } else if ("onChangeScript".equals(propName)) {
                    field.setOnChangeScript(value);
                } else if ("movedToForm".equals(propName) && value != null) {
                    field.setMovedToForm(value);
                } else if ("sourceLink".equals(propName) && value != null) {
                    field.setSourceLink(value);
                }
            }
        }
    }

    return field;
}