Example usage for org.w3c.dom Document importNode

List of usage examples for org.w3c.dom Document importNode

Introduction

In this page you can find the example usage for org.w3c.dom Document importNode.

Prototype

public Node importNode(Node importedNode, boolean deep) throws DOMException;

Source Link

Document

Imports a node from another document to this document, without altering or removing the source node from the original document; this method creates a new copy of the source node.

Usage

From source file:org.jboss.pressgang.ccms.contentspec.builder.DocBookBuilder.java

protected Node createTopicDOMNode(final SpecTopic specTopic, final Document doc, final boolean flattenStructure,
        final String parentFileLocation) throws BuildProcessingException {
    final Document topicDoc = specTopic.getXMLDocument();

    final Node topicNode;
    if (flattenStructure) {
        // Include the topic as is, into the chapter
        topicNode = doc.importNode(topicDoc.getDocumentElement(), true);
    } else {//from w w w . j a  va  2 s  . com
        // Create the topic file and add the reference to the chapter
        final String topicFileName = createTopicXMLFile(buildData, specTopic, parentFileLocation);
        if (topicFileName != null) {

            // Remove the initial file location as we only want where it lives in the topics directory
            final String fixedParentFileLocation = buildData.getBuildOptions().getFlattenTopics() ? "topics/"
                    : parentFileLocation.replace(buildData.getBookLocaleFolder(), "");

            topicNode = XMLUtilities.createXIInclude(doc, fixedParentFileLocation + topicFileName);
        } else {
            topicNode = null;
        }
    }

    return topicNode;
}

From source file:org.jbpm.bpel.tools.WebServicesDescriptorTool.java

protected void generatePortComponent(Service service, Port port, Element jaxrpcMappingElem,
        Element descriptionElem) {
    Document webservicesDoc = descriptionElem.getOwnerDocument();
    Element portComponentElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_PORT_COMPONENT);
    descriptionElem.appendChild(portComponentElem);

    // port component name
    Element portComponentNameElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_PORT_COMPONENT_NAME);
    XmlUtil.setStringValue(portComponentNameElem, generatePortComponentName(port));
    portComponentElem.appendChild(portComponentNameElem);

    // wsdl port/*  w  ww  .  j ava2  s .c  o m*/
    Element wsdlPortElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_WSDL_PORT);
    XmlUtil.setQNameValue(wsdlPortElem,
            new QName(service.getQName().getNamespaceURI(), port.getName(), "portNS"));
    portComponentElem.appendChild(wsdlPortElem);

    // service endpoint interface
    Element seiMappingElem = findSeiMapping(port, jaxrpcMappingElem);
    Element seiElem = XmlUtil.getElement(seiMappingElem, NS_J2EE, ELEM_SERVICE_ENDPOINT_INTERFACE);
    portComponentElem.appendChild(webservicesDoc.importNode(seiElem, true));

    // service implementation bean
    Element sibElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_SERVICE_IMPL_BEAN);
    portComponentElem.appendChild(sibElem);

    // servlet link
    Element servletLinkElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_SERVLET_LINK);
    XmlUtil.setStringValue(servletLinkElem, generateServletName(port));
    sibElem.appendChild(servletLinkElem);

    // handler
    Element handlerElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_HANDLER);
    portComponentElem.appendChild(handlerElem);

    // handler name
    Element handlerNameElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_HANDLER_NAME);
    XmlUtil.setStringValue(handlerNameElem, generateHandlerName(port));
    handlerElem.appendChild(handlerNameElem);

    // handler class
    Element handlerClassElem = webservicesDoc.createElementNS(NS_J2EE, ELEM_HANDLER_CLASS);
    XmlUtil.setStringValue(handlerClassElem, SoapHandler.class.getName());
    handlerElem.appendChild(handlerClassElem);
}

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 {//  w  w w.j a  v a 2  s  .  c  o  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.RemoteFormModellerFormProvider.java

protected String filterXML(String document, String lang, String deploymentId, Map inputs, Map outputs) {
    try {//  w  ww  .ja va2 s .  c  o  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().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.server.services.jbpm.ui.form.RemoteFormModellerFormProvider.java

protected String attachSubForms(String document, String deploymentId) {
    try {//from w  ww.ja  v  a  2s  .c om
        if (!document.contains(SUB_FORM_TYPE) && !document.contains(MULTI_SUB_FORM_TYPE)) {
            return document;
        }
        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) || MULTI_SUB_FORM_TYPE.equals(fieldType)) {

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

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

                        if (subFormContent != null) {
                            Document docSubForm = builder
                                    .parse(new ByteArrayInputStream(subFormContent.getBytes()));

                            NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                            Node nodeFormSubForm = nodesSubForm.item(0);

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

                            nodeForm.appendChild(imported);
                        }
                    }
                }
            }
        }
        document = asString(doc);
    } catch (Exception ex) {
        logger.error("Error when attaching subform", ex);
    }
    return document;
}

From source file:org.kuali.rice.edl.framework.workflow.EDocLitePostProcessor.java

protected static void postEvent(String docId, Object event, String eventName) {
    try {/*from w  ww . ja v  a2 s .com*/
        Document doc = getEDLContent(docId);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Submitting doc: " + XmlJotter.jotNode(doc));
        }

        String urlstring = getURL(doc);
        if (org.apache.commons.lang.StringUtils.isEmpty(urlstring)) {
            LOG.warn("No eventNotificationURL defined in EDLContent");
            return;
        }

        Document eventDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element eventE = eventDoc.createElement("event");
        eventE.setAttribute("type", eventName);
        eventDoc.appendChild(eventE);

        Element infoE = (Element) eventDoc.importNode(propertiesToXml(event, "info"), true);
        Element docIdE = eventDoc.createElement("docId");
        docIdE.appendChild(eventDoc.createTextNode(String.valueOf(docId)));
        infoE.appendChild(docIdE);

        eventE.appendChild(infoE);
        eventE.appendChild(eventDoc.importNode(doc.getDocumentElement(), true));

        String query = "docId=" + docId;
        if (urlstring.indexOf('?') != -1) {
            urlstring += "&" + query;
        } else {
            urlstring += "?" + query;
        }

        final String _urlstring = urlstring;
        final Document _eventDoc = eventDoc;
        // a super cheesy way to enforce asynchronicity/timeout follows:
        final Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    LOG.debug("Post Event calling url: " + _urlstring);
                    submitURL(_urlstring, _eventDoc);
                    LOG.debug("Post Event done calling url: " + _urlstring);
                } catch (Exception e) {
                    LOG.error(e);
                }
            }
        });
        t.setDaemon(true);
        t.start();

        // kill the submission thread if it hasn't completed after 1 minute
        TIMER.schedule(new TimerTask() {
            public void run() {
                t.interrupt();
            }
        }, SUBMIT_URL_MILLISECONDS_WAIT);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new RuntimeException(e);
    }
}

From source file:org.kuali.rice.edl.impl.components.NoteConfigComponent.java

protected Document generateXmlInput(NoteForm form, EDLContext edlContext, Document dom) throws Exception {
    DocumentBuilder db = getDocumentBuilder(true);
    Document doc = db.newDocument();
    Element emailNodeElem = doc.createElement("emailNode");
    doc.appendChild(emailNodeElem);//from   w w  w  .j a  va2s.com
    WorkflowDocument document = (WorkflowDocument) edlContext.getRequestParser()
            .getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY);

    /* Upgrade Changes 0914 to 1011 */
    //RouteHeaderVO routeHeaderVO = document.getRouteHeader();
    JAXBContext jaxb = JAXBContext.newInstance(org.kuali.rice.kew.api.document.Document.class);
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.marshal(document.getDocument(), emailNodeElem);
    emailNodeElem.appendChild(doc.importNode(dom.getDocumentElement(), true));
    Element dConElem = XmlHelper.readXml(document.getDocumentContent().getApplicationContent())
            .getDocumentElement(); //Add document Content element for
    emailNodeElem.appendChild(doc.importNode(dConElem, true)); //access by the stylesheet when creating the email
    return doc;
}

From source file:org.kuali.rice.kew.dto.DTOConverter.java

private static Element createDocumentContentSection(Document document, Element existingAttributeElement,
        List<WorkflowAttributeDefinition> definitions, String content, String elementName,
        String documentTypeName) throws SAXException, IOException, ParserConfigurationException {
    Element contentSectionElement = existingAttributeElement;
    // if they've updated the content, we're going to re-build the content section element from scratch
    if (content != null) {
        if (!org.apache.commons.lang.StringUtils.isEmpty(content)) {
            contentSectionElement = document.createElement(elementName);
            // if they didn't merely clear the content, let's build the content section element by combining the children
            // of the incoming XML content
            Element incomingAttributeElement = XmlHelper.readXml(content).getDocumentElement();
            NodeList children = incomingAttributeElement.getChildNodes();
            for (int index = 0; index < children.getLength(); index++) {
                contentSectionElement.appendChild(document.importNode(children.item(index), true));
            }/*from w  w w .jav  a  2 s  . c o  m*/
        } else {
            contentSectionElement = null;
        }
    }
    // if they have new definitions we're going to append those to the existing content section
    if (definitions != null && !definitions.isEmpty()) {
        String errorMessage = "";
        boolean inError = false;
        if (contentSectionElement == null) {
            contentSectionElement = document.createElement(elementName);
        }
        for (WorkflowAttributeDefinition definitionVO : definitions) {
            AttributeDefinition definition = convertWorkflowAttributeDefinition(definitionVO);
            ExtensionDefinition extensionDefinition = definition.getExtensionDefinition();

            Object attribute = null;
            attribute = GlobalResourceLoader.getObject(definition.getObjectDefinition());
            if (attribute == null) {
                attribute = GlobalResourceLoader
                        .getService(QName.valueOf(definition.getExtensionDefinition().getResourceDescriptor()));
            }

            if (attribute instanceof XmlConfiguredAttribute) {
                ((XmlConfiguredAttribute) attribute)
                        .setExtensionDefinition(definition.getExtensionDefinition());
            }
            boolean propertiesAsMap = false;
            if (KewApiConstants.RULE_XML_ATTRIBUTE_TYPE.equals(extensionDefinition.getType())) {
                propertiesAsMap = true;
            }
            if (propertiesAsMap) {
                for (org.kuali.rice.kew.api.document.PropertyDefinition propertyDefinitionVO : definitionVO
                        .getPropertyDefinitions()) {
                    if (attribute instanceof GenericXMLRuleAttribute) {
                        ((GenericXMLRuleAttribute) attribute).getParamMap().put(propertyDefinitionVO.getName(),
                                propertyDefinitionVO.getValue());
                    }
                }
            }

            // validate inputs from client application if the attribute is capable
            if (attribute instanceof WorkflowAttributeXmlValidator) {
                List<? extends RemotableAttributeErrorContract> errors = ((WorkflowAttributeXmlValidator) attribute)
                        .validateClientRoutingData();
                if (!errors.isEmpty()) {
                    inError = true;
                    errorMessage += "Error validating attribute " + definitionVO.getAttributeName() + " ";
                    errorMessage += Joiner.on("; ")
                            .join(Iterables.transform(errors, Functions.toStringFunction()));
                }
            }
            // dont add to xml if attribute is in error
            if (!inError) {
                if (attribute instanceof WorkflowRuleAttribute) {
                    String attributeDocContent = ((WorkflowRuleAttribute) attribute).getDocContent();
                    if (!StringUtils.isEmpty(attributeDocContent)) {
                        XmlHelper.appendXml(contentSectionElement, attributeDocContent);
                    }
                } else if (attribute instanceof SearchableAttribute) {
                    SearchableAttribute searchableAttribute = (SearchableAttribute) attribute;
                    String searchableAttributeContent = searchableAttribute
                            .generateSearchContent(extensionDefinition, documentTypeName, definitionVO);
                    if (!StringUtils.isBlank(searchableAttributeContent)) {
                        XmlHelper.appendXml(contentSectionElement, searchableAttributeContent);
                    }
                }
            }
        }
        if (inError) {
            throw new WorkflowRuntimeException(errorMessage);
        }

    }
    if (contentSectionElement != null) {
        // always be sure and import the element into the new document, if it originated from the existing doc content
        // and
        // appended to it, it will need to be imported
        contentSectionElement = (Element) document.importNode(contentSectionElement, true);
    }
    return contentSectionElement;
}

From source file:org.kuali.rice.kew.mail.EmailNode.java

protected Document generateXmlInput(RouteContext context) throws Exception {
    DocumentBuilder db = getDocumentBuilder(true);
    Document doc = db.newDocument();
    Element emailNodeElem = doc.createElement("emailNode");
    doc.appendChild(emailNodeElem);/*from   w ww  .  j  av a2s .  co m*/
    String principalId = null; // Added to the convertRouteHeader is not ambigious.
    org.kuali.rice.kew.api.document.Document routeHeaderVO = DocumentRouteHeaderValue.to(context.getDocument());
    RouteNodeInstance routeNodeInstanceVO = org.kuali.rice.kew.engine.node.RouteNodeInstance
            .to(context.getNodeInstance());
    Document documentContent = context.getDocumentContent().getDocument();
    XStream xstream = new XStream();
    Element docElem = XmlHelper.readXml(xstream.toXML(routeHeaderVO)).getDocumentElement();
    Element nodeElem = XmlHelper.readXml(xstream.toXML(routeNodeInstanceVO)).getDocumentElement();
    emailNodeElem.appendChild(doc.importNode(docElem, true));
    emailNodeElem.appendChild(doc.importNode(nodeElem, true));
    emailNodeElem.appendChild(doc.importNode(documentContent.getDocumentElement(), true));
    Element dConElem = context.getDocumentContent().getApplicationContent();//Add document Content element for
    emailNodeElem.appendChild(doc.importNode(dConElem, true));//access by the stylesheet when creating the email
    return doc;
}

From source file:org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl.java

/**
 * This method handles converting the DocumentRouteHeaderValue into an XML representation.  The reason we can't just use
 * propertiesToXml like we have elsewhere is because the doc header has a String attached to it that has the XML document
 * content in it.  The default serialization of this will serialize this as a String so we will end up with escaped XML
 * in our output which we won't be able to process with the email stylesheet.  So we need to read the xml content from
 * the document and parse it into a DOM object so it can be appended to our output.
 *///from w w w  . j ava 2s.  c  o m
protected void addDocumentHeaderXML(Document document, DocumentRouteHeaderValue documentHeader, Node node,
        String elementName) throws Exception {
    Element element = XmlHelper.propertiesToXml(document, documentHeader, elementName);
    // now we need to "fix" the xml document content because it's going to be in there as escaped XML
    Element docContentElement = (Element) element.getElementsByTagName("docContent").item(0);
    String documentContent = docContentElement.getTextContent();

    if (!StringUtils.isBlank(documentContent) && documentContent.startsWith("<")) {
        Document documentContentXML = XmlHelper.readXml(documentContent);
        Element documentContentElement = documentContentXML.getDocumentElement();
        documentContentElement = (Element) document.importNode(documentContentElement, true);

        // remove the old, bad text content
        docContentElement.removeChild(docContentElement.getFirstChild());

        // replace with actual XML
        docContentElement.appendChild(documentContentElement);
    } else {
        // in this case it means that the XML is encrypted, unfortunately, we have no way to decrypt it since
        // the key is stored in the client application.  We will just include the doc content since none of our
        // current IU clients will be using this feature right away

        // remove the old, bad text content
        docContentElement.removeChild(docContentElement.getFirstChild());
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug(XmlJotter.jotNode(element));
    }

    node.appendChild(element);
}