Example usage for org.w3c.dom NamedNodeMap item

List of usage examples for org.w3c.dom NamedNodeMap item

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap item.

Prototype

public Node item(int index);

Source Link

Document

Returns the indexth item in the map.

Usage

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private void copyNode(Node sourceNode, Node destinationNode) {
    Document destinationDoc = destinationNode.getOwnerDocument();

    switch (sourceNode.getNodeType()) {
    case Node.TEXT_NODE:
        Text text = destinationDoc.createTextNode(sourceNode.getNodeValue());
        destinationNode.appendChild(text);
        break;//  w ww.j  a v  a2 s .  co  m
    case Node.ELEMENT_NODE:
        Element element = destinationDoc.createElement(sourceNode.getNodeName());
        destinationNode.appendChild(element);

        element.setTextContent(sourceNode.getNodeValue());

        // Copy attributes
        NamedNodeMap attributes = sourceNode.getAttributes();
        int nbAttributes = attributes.getLength();

        for (int i = 0; i < nbAttributes; i++) {
            Node attribute = attributes.item(i);
            element.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
        }

        // Copy children nodes
        NodeList children = sourceNode.getChildNodes();
        int nbChildren = children.getLength();
        for (int i = 0; i < nbChildren; i++) {
            Node child = children.item(i);
            copyNode(child, element);
        }
    }
}

From source file:com.connexta.arbitro.ctx.xacml3.XACML3EvaluationCtx.java

private Set<String> getChildXPaths(Node root, String xPath) {

    Set<String> xPaths = new HashSet<String>();
    NamespaceContext namespaceContext = null;

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();

    if (namespaceContext == null) {

        //see if the request root is in a namespace
        String namespace = null;//ww w  .j ava  2s.  c o m
        if (root != null) {
            namespace = root.getNamespaceURI();
        }
        // name spaces are used, so we need to lookup the correct
        // prefix to use in the search string
        NamedNodeMap namedNodeMap = root.getAttributes();

        Map<String, String> nsMap = new HashMap<String, String>();
        if (namedNodeMap != null) {
            for (int i = 0; i < namedNodeMap.getLength(); i++) {
                Node n = namedNodeMap.item(i);
                // we found the matching namespace, so get the prefix
                // and then break out
                String prefix = DOMHelper.getLocalName(n);
                String nodeValue = n.getNodeValue();
                nsMap.put(prefix, nodeValue);
            }
        }

        // if there is not any namespace is defined for content element, default XACML request
        //  name space would be there.
        if (XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER.equals(namespace)
                || XACMLConstants.REQUEST_CONTEXT_2_0_IDENTIFIER.equals(namespace)
                || XACMLConstants.REQUEST_CONTEXT_1_0_IDENTIFIER.equals(namespace)) {
            nsMap.put("xacml", namespace);
        }

        namespaceContext = new DefaultNamespaceContext(nsMap);
    }

    xpath.setNamespaceContext(namespaceContext);

    try {
        XPathExpression expression = xpath.compile(xPath);
        NodeList matches = (NodeList) expression.evaluate(root, XPathConstants.NODESET);
        if (matches != null && matches.getLength() > 0) {

            for (int i = 0; i < matches.getLength(); i++) {
                String text = null;
                Node node = matches.item(i);
                short nodeType = node.getNodeType();

                // see if this is straight text, or a node with data under
                // it and then get the values accordingly
                if ((nodeType == Node.CDATA_SECTION_NODE) || (nodeType == Node.COMMENT_NODE)
                        || (nodeType == Node.TEXT_NODE) || (nodeType == Node.ATTRIBUTE_NODE)) {
                    // there is no child to this node
                    text = node.getNodeValue();
                } else {

                    // the data is in a child node
                    text = "/" + DOMHelper.getLocalName(node);
                }
                String newXPath = '(' + xPath + ")[" + (i + 1) + ']';
                xPaths.add(newXPath);
            }
        }
    } catch (Exception e) {
        // TODO
    }

    return xPaths;
}

From source file:DOMProcessor.java

/** Converts the given DOM node into XML. Recursively converts
  * any child nodes. This version allows the XML version, encoding and stand-alone
  * status to be set.//from  www  . j  a va  2s  .c  o m
  * @param node DOM Node to display.
  * @param version XML version, or null if default ('1.0') is to be used.
  * @param encoding XML encoding, or null if encoding is not to be specified.
  * @param standalone XML stand-alone status or null if not to be specified.
  */
private void outputNodeAsXML(Node node, String version, String encoding, Boolean standalone) {
    // Store node name, type and value.
    String name = node.getNodeName(), value = makeFriendly(node.getNodeValue());
    int type = node.getNodeType();

    // Ignore empty nodes (e.g. blank lines etc.)
    if ((value != null) && (value.trim().equals(""))) {
        return;
    }

    switch (type) {
    case Node.DOCUMENT_NODE: // Start of document.
    {
        if (version == null) {
            out.print("<?xml version=\"1.0\" ");
        } else {
            out.print("<?xml version=\"" + version + "\" ");
        }

        if (encoding != null) {
            out.print("encoding=\"" + encoding + "\" ");
        }

        if (standalone != null) {
            if (standalone.booleanValue()) {
                out.print("standalone=\"yes\" ");
            } else {
                out.print("standalone=\"no\" ");
            }
        }

        out.println("?>");

        // Output the document's child nodes.
        NodeList children = node.getChildNodes();

        for (int i = 0; i < children.getLength(); i++) {
            outputNodeAsXML(children.item(i));
        }
        break;
    }

    case Node.ELEMENT_NODE: // Document element with attributes.
    {
        // Output opening element tag.
        indent++;
        indent();
        out.print("<" + name);

        // Output any attributes the element might have.
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            out.print(" " + attribute.getNodeName() + "=\"" + attribute.getNodeValue() + "\"");
        }
        out.print(">");

        // Output any child nodes that exist.                    
        NodeList children = node.getChildNodes();

        for (int i = 0; i < children.getLength(); i++) {
            outputNodeAsXML(children.item(i));
        }

        break;
    }

    case Node.CDATA_SECTION_NODE: // Display text.
    case Node.TEXT_NODE: {
        out.print(value);
        break;
    }

    case Node.COMMENT_NODE: // Comment node.
    {
        indent++;
        indent();
        out.print("<!--" + value + "-->");
        indent--;
        break;
    }

    case Node.ENTITY_REFERENCE_NODE: // Entity reference nodes.
    {
        indent++;
        indent();
        out.print("&" + name + ";");
        indent--;
        break;
    }

    case Node.PROCESSING_INSTRUCTION_NODE: // Processing instruction.
    {
        indent++;
        indent();
        out.print("<?" + name);
        if ((value != null) && (value.length() > 0)) {
            out.print(" " + value);
        }
        out.println("?>");
        indent--;
        break;
    }
    }

    // Finally output closing tags for each element.
    if (type == Node.ELEMENT_NODE) {
        out.print("</" + node.getNodeName() + ">");
        indent--;
        if (node.getNextSibling() == null) {
            indent(); // Only throw new line if this is the last sibling.
        }
    }
}

From source file:com.krawler.workflow.bizservice.WorkflowServiceImpl.java

@Override
public String reloadWorkflow(String processid) throws ServiceException {
    String result = "{\"success\":false}";
    try {//from  ww  w.  ja v  a2 s  . co m
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

        String path = ConfigReader.getinstance().get("workflowpath") + processid;

        File fdir = new File(path);
        File file = new File(fdir + System.getProperty("file.separator") + "bpmn.xml");
        Document doc = docBuilder.parse(file);
        int s;
        int a;
        String name = "";
        ObjectInfo obj = new ObjectInfo();
        ArrayList taskContainer = new ArrayList();

        String nodeName = "";
        NodeList nodeList = doc.getElementsByTagName("Pool");
        for (s = 1; s < nodeList.getLength(); s++) {
            Node node = nodeList.item(s);
            ObjectInfo processObj = new ObjectInfo();
            processObj.type = "process";
            getNodeInfo(node, processObj);
            NodeList childrenList = node.getChildNodes();
            for (int cnt = 0; cnt < childrenList.getLength(); cnt++) {
                node = childrenList.item(cnt);
                nodeName = node.getNodeName();
                if (nodeName.compareToIgnoreCase("Lanes") == 0) {
                    NodeList laneList = node.getChildNodes();
                    for (int laneCount = 0; laneCount < laneList.getLength(); laneCount++) {
                        node = laneList.item(laneCount);
                        nodeName = node.getNodeName();
                        if (nodeName.compareToIgnoreCase("Lane") == 0) {
                            ObjectInfo laneObj = new ObjectInfo();
                            laneObj.type = "lane";
                            getNodeInfo(node, laneObj);
                            NodeList laneChildren = node.getChildNodes();
                            for (int laneChildrencnt = 0; laneChildrencnt < laneChildren
                                    .getLength(); laneChildrencnt++) {
                                node = laneChildren.item(laneChildrencnt);
                                nodeName = node.getNodeName();
                                if (nodeName.compareToIgnoreCase("NodeGraphicsInfos") == 0) {
                                    getGraphicsNodeInfo(getActivityNode(node, 1), laneObj);
                                }
                            }
                            taskContainer.add(laneObj);
                        }
                    }
                } else {
                    if (nodeName.compareToIgnoreCase("NodeGraphicsInfos") == 0) {
                        getGraphicsNodeInfo(getActivityNode(node, 1), processObj);
                    }
                }

            }
            taskContainer.add(processObj);
        }

        nodeList = doc.getElementsByTagName("Activities");

        for (s = 0; s < nodeList.getLength(); s++) {
            name = "";
            Node node = nodeList.item(s);
            NodeList childrenList = node.getChildNodes();
            for (int cnt = 0; cnt < childrenList.getLength(); cnt++) {
                node = childrenList.item(cnt);
                Node activityNode = getActivityNode(node, 0);
                if (activityNode.getNodeType() == Node.ELEMENT_NODE) {
                    obj = new ObjectInfo();
                    obj.type = "activity";
                    getNodeInfo(activityNode, obj);
                    Node graphicsInfoNode = getActivityNode(activityNode, 1);
                    getGraphicsNodeInfo(graphicsInfoNode, obj);
                    taskContainer.add(obj);
                }
            }
        }

        JSONObject jtemp = new com.krawler.utils.json.base.JSONObject();
        for (int j = 0; j < taskContainer.size(); j++) {
            obj = (ObjectInfo) taskContainer.get(j);
            JSONObject jobj = new com.krawler.utils.json.base.JSONObject();
            jobj.put("Id", obj.objId);
            jobj.put("name", obj.name);
            jobj.put("xpos", obj.xpos);
            jobj.put("ypos", obj.ypos);
            jobj.put("height", obj.height);
            jobj.put("width", obj.width);
            jobj.put("parent", obj.parentId);
            jobj.put("refId", obj.refId);
            jobj.put("hasStart", obj.hasStart);
            jobj.put("hasEnd", obj.hasEnd);
            jobj.put("startRefId", obj.startRefId);
            jobj.put("endRefId", obj.endRefId);
            jobj.put("derivationRule", obj.derivationRule);
            jobj.put("domEl", obj.domEl);
            if (obj.type.compareToIgnoreCase("activity") == 0) {
                jtemp.append("data", jobj);
            } else if (obj.type.compareToIgnoreCase("process") == 0) {
                jtemp.append("processes", jobj);
            } else if (obj.type.compareToIgnoreCase("lane") == 0) {
                jtemp.append("lanes", jobj);
            }
        }

        NodeList transitionList = doc.getElementsByTagName("Transitions");
        for (int i = 0; i < transitionList.getLength(); i++) {
            Node node = transitionList.item(i);
            NodeList childrenList = node.getChildNodes();

            for (int cnt = 0; cnt < childrenList.getLength(); cnt++) {
                node = childrenList.item(cnt);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    JSONObject jobj = new com.krawler.utils.json.base.JSONObject();
                    NamedNodeMap attr = node.getAttributes();
                    for (int b = 0; b < attr.getLength(); b++) {
                        Node attribute = attr.item(b);
                        name = attribute.getNodeName();
                        if (name.compareToIgnoreCase("From") == 0) {
                            jobj.put("fromId", attribute.getNodeValue());
                        } else if (name.compareToIgnoreCase("To") == 0) {
                            jobj.put("toId", attribute.getNodeValue());
                        }
                    }
                    jtemp.append("Lines", jobj);
                }
            }
        }

        return jtemp.toString();
    } catch (ParserConfigurationException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    } catch (SAXException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    } catch (IOException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    } catch (JSONException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    }
}

From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java

private String getAttribute(Node node, String attributeName) throws Exception {
    try {/*from  w w  w .  j  av  a2s  . c  o m*/
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attributeNode = attributes.item(i);
            if (attributeNode.getNodeName().equals(attributeName)) {
                return attributeNode.getNodeValue();
            }
        }
        return null;
    } catch (Exception e) {
        log.error(e);
        log.error(e.getStackTrace());
        throw (e);
    }
}

From source file:com.krawler.workflow.bizservice.WorkflowServiceImpl.java

public String importWorkflow(String processid) throws ServiceException {
    String result = "{\"success\":false}";
    try {// ww  w  .ja v  a 2s .  com

        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

        String path = ConfigReader.getinstance().get("workflowpath") + processid;

        File fdir = new File(path);
        File file = new File(fdir + System.getProperty("file.separator") + "bpmn.xml");
        Document doc = docBuilder.parse(file);
        int s;
        int a;
        String name = "";
        ObjectInfo obj = new ObjectInfo();

        HashMap<String, ObjectInfo> activityHm = new HashMap<String, ObjectInfo>();
        NodeList nodeList = doc.getElementsByTagName("Activity");

        for (s = 0; s < nodeList.getLength(); s++) {
            name = "";
            Node node = nodeList.item(s);

            if (node.getNodeType() == Node.ELEMENT_NODE) {
                obj = new ObjectInfo();
                obj.type = getNodeType(node);
                getNodeInfo(node, obj);
                if (obj.type.equals("activity")) {
                    Node graphicsInfoNode = getActivityNode(node, 1);
                    getGraphicsNodeInfo(graphicsInfoNode, obj);
                }
                activityHm.put(obj.objId, obj);
            }

        }

        NodeList transitionList = doc.getElementsByTagName("Transitions");
        String fromId = "";
        String toId = "";
        ObjectInfo fromObj;
        ObjectInfo toObj;
        ObjectInfo tempObj;
        JSONObject jobj;
        JSONObject jtemp = new com.krawler.utils.json.base.JSONObject();
        HashMap<String, String> fromConditionHm = new HashMap<String, String>();
        MultiMap toConditionHm = new MultiHashMap();
        for (int i = 0; i < transitionList.getLength(); i++) {
            Node node = transitionList.item(i);
            NodeList childrenList = node.getChildNodes();
            for (int cnt = 0; cnt < childrenList.getLength(); cnt++) {
                node = childrenList.item(cnt);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    NamedNodeMap attr = node.getAttributes();
                    for (int b = 0; b < attr.getLength(); b++) {
                        Node attribute = attr.item(b);
                        name = attribute.getNodeName();
                        if (name.compareToIgnoreCase("From") == 0) {
                            fromId = attribute.getNodeValue();
                        } else if (name.compareToIgnoreCase("To") == 0) {
                            toId = attribute.getNodeValue();
                        }
                    }
                    fromObj = activityHm.get(fromId);
                    toObj = activityHm.get(toId);
                    if (fromObj.type.equals("start")) {
                        tempObj = new ObjectInfo();
                        tempObj = activityHm.get(toId);
                        tempObj.hasStart = "true";
                        activityHm.put(toId, tempObj);
                        continue;
                    }
                    if (toObj.type.equals("end")) {
                        tempObj = new ObjectInfo();
                        tempObj = activityHm.get(fromId);
                        tempObj.hasEnd = "true";
                        activityHm.put(fromId, tempObj);
                        continue;
                    }
                    if (fromObj.type.equals("activity") && toObj.type.equals("activity")) {
                        jobj = new com.krawler.utils.json.base.JSONObject();
                        jobj.put("fromId", "flowPanel" + fromId);
                        jobj.put("toId", "flowPanel" + toId);
                        jtemp.append("Lines", jobj);
                        tempObj = new ObjectInfo();
                        tempObj = activityHm.get(fromId);
                        tempObj.derivationRule = "sequence";
                        activityHm.put(fromId, tempObj);
                        continue;
                    }
                    if (fromObj.type.equals("activity") && toObj.type.equals("condition")) {
                        fromConditionHm.put(toId, fromId);
                        tempObj = new ObjectInfo();
                        tempObj = activityHm.get(fromId);
                        tempObj.derivationRule = "evaluation";
                        activityHm.put(fromId, tempObj);
                        continue;
                    }
                    if (fromObj.type.equals("condition") && toObj.type.equals("activity")) {
                        toConditionHm.put(fromId, toId);
                        continue;
                    }
                }
            }
        }

        Set keys = activityHm.keySet();
        Iterator ite = keys.iterator();
        while (ite.hasNext()) {
            String key = (String) ite.next();
            obj = new ObjectInfo();
            obj = activityHm.get(key);
            if (obj.type.equals("activity")) {
                jobj = new com.krawler.utils.json.base.JSONObject();
                jobj.put("Id", "flowPanel" + obj.objId);
                jobj.put("name", obj.name);
                jobj.put("xpos", obj.xpos);
                jobj.put("ypos", obj.ypos);
                jobj.put("height", obj.height);
                jobj.put("width", obj.width);
                jobj.put("parent", obj.parentId);
                jobj.put("refId", obj.refId);
                jobj.put("hasStart", obj.hasStart);
                jobj.put("hasEnd", obj.hasEnd);
                jobj.put("startRefId", obj.startRefId);
                jobj.put("endRefId", obj.endRefId);
                jobj.put("derivationRule", obj.derivationRule);
                jobj.put("domEl", obj.domEl);
                jtemp.append("data", jobj);
            }
        }

        keys = fromConditionHm.keySet();
        ite = keys.iterator();
        Iterator ite1 = null;
        String key = "";
        while (ite.hasNext()) {
            key = (String) ite.next();
            fromId = fromConditionHm.get(key);
            List toList = (List) toConditionHm.get(key);
            ite1 = toList.iterator();
            while (ite1.hasNext()) {
                toId = (String) ite1.next();
                jobj = new com.krawler.utils.json.base.JSONObject();
                jobj.put("fromId", "flowPanel" + fromId);
                jobj.put("toId", "flowPanel" + toId);
                jtemp.append("Lines", jobj);
            }
        }
        return jtemp.toString();
    } catch (ParserConfigurationException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    } catch (SAXException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    } catch (IOException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    } catch (JSONException ex) {
        logger.warn(ex.getMessage(), ex);
        result = "{\"success\":false}";
        throw ServiceException.FAILURE("workflow.reloadWorkflow", ex);
    }
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private SOAPElement addSoapElement(Context context, SOAPEnvelope se, SOAPElement soapParent, Node node)
        throws Exception {
    String prefix = node.getPrefix();
    String namespace = node.getNamespaceURI();
    String nodeName = node.getNodeName();
    String localName = node.getLocalName();
    String value = node.getNodeValue();

    boolean includeResponseElement = true;
    if (context.sequenceName != null) {
        includeResponseElement = ((Sequence) context.requestedObject).isIncludeResponseElement();
    }//ww  w .  ja  va  2s  . c om

    SOAPElement soapElement = null;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;

        boolean toAdd = true;
        if (!includeResponseElement && "response".equalsIgnoreCase(localName)) {
            toAdd = false;
        }
        if ("http://schemas.xmlsoap.org/soap/envelope/".equals(element.getParentNode().getNamespaceURI())
                || "http://schemas.xmlsoap.org/soap/envelope/".equals(namespace)
                || nodeName.toLowerCase().endsWith(":envelope") || nodeName.toLowerCase().endsWith(":body")
        //element.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 ||
        //nodeName.toUpperCase().indexOf("NS0:") != -1
        ) {
            toAdd = false;
        }

        if (toAdd) {
            if (prefix == null || prefix.equals("")) {
                soapElement = soapParent.addChildElement(nodeName);
            } else {
                soapElement = soapParent.addChildElement(se.createName(localName, prefix, namespace));
            }
        } else {
            soapElement = soapParent;
        }

        if (soapElement != null) {
            if (soapParent.equals(se.getBody()) && !soapParent.equals(soapElement)) {
                if (XsdForm.qualified == context.project.getSchemaElementForm()) {
                    if (soapElement.getAttribute("xmlns") == null) {
                        soapElement.addAttribute(se.createName("xmlns"), context.project.getTargetNamespace());
                    }
                }
            }

            if (element.hasAttributes()) {
                String attrType = element.getAttribute("type");
                if (("attachment").equals(attrType)) {
                    if (context.requestedObject instanceof AbstractHttpTransaction) {
                        AttachmentDetails attachment = AttachmentManager.getAttachment(element);
                        if (attachment != null) {
                            byte[] raw = attachment.getData();
                            if (raw != null)
                                soapElement.addTextNode(Base64.encodeBase64String(raw));
                        }

                        /* DON'T WORK YET *\
                        AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), element.getAttribute("content-type"));
                        ap.setContentId(key);
                        ap.setContentLocation(element.getAttribute("url"));
                        responseMessage.addAttachmentPart(ap);
                        \* DON'T WORK YET */
                    }
                }

                if (!includeResponseElement && "response".equalsIgnoreCase(localName)) {
                    // do not add attributes
                } else {
                    NamedNodeMap attributes = element.getAttributes();
                    int len = attributes.getLength();
                    for (int i = 0; i < len; i++) {
                        Node item = attributes.item(i);
                        addSoapElement(context, se, soapElement, item);
                    }
                }
            }

            if (element.hasChildNodes()) {
                NodeList childNodes = element.getChildNodes();
                int len = childNodes.getLength();
                for (int i = 0; i < len; i++) {
                    Node item = childNodes.item(i);
                    switch (item.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        addSoapElement(context, se, soapElement, item);
                        break;
                    case Node.CDATA_SECTION_NODE:
                    case Node.TEXT_NODE:
                        String text = item.getNodeValue();
                        text = (text == null) ? "" : text;
                        soapElement.addTextNode(text);
                        break;
                    default:
                        break;
                    }
                }
            }
        }
    } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
        if (prefix == null || prefix.equals("")) {
            soapElement = soapParent.addAttribute(se.createName(nodeName), value);
        } else {
            soapElement = soapParent.addAttribute(se.createName(localName, prefix, namespace), value);
        }
    }
    return soapElement;
}

From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java

public static final List<Element> createEntityFromBusinessObject(final BusinessEntity businessEntity)
        throws Exception {

    /* Create list of elements */
    final List<Element> elementList = new ArrayList<Element>();

    if (businessEntity != null) {
        final Node node = businessEntity.getDomNode();
        if (node.hasChildNodes()) {
            final NodeList nodeList = node.getChildNodes();
            for (int i = 0; i < nodeList.getLength(); i++) {

                /* To avoid : 'DOM Level 3 Not implemented' error */
                final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                final Document document = builder.newDocument();
                final Element element = (Element) document.importNode(nodeList.item(i), true);

                if (element.getNodeName() != null && element.getNodeName().contains(":")) {
                    final String nodeName = element.getNodeName().split(":")[1];

                    /* Check for attributes */
                    final NamedNodeMap attributes = element.getAttributes();

                    if (attributes != null && attributes.getLength() != 0) {

                        /* Create new map for attributes */
                        final Map<String, String> attributeMap = new HashMap<String, String>();

                        for (int j = 0; j < attributes.getLength(); j++) {
                            final Attr attr = (Attr) attributes.item(j);

                            /* Set node name and value in map */
                            attributeMap.put(attr.getNodeName(), attr.getNodeValue());
                        }/*w w w  . j a  va  2  s. c o m*/

                        /* Create node with attributes */
                        elementList.add(MSCRMMessageFormatUtils.createMessageElement(nodeName,
                                element.getTextContent(), attributeMap));
                    } else {

                        /* Create node without attributes */
                        elementList.add(MSCRMMessageFormatUtils.createMessageElement(nodeName,
                                element.getTextContent()));
                    }
                }
            }
        }
        return elementList;
    } else {
        return null;
    }
}

From source file:com.twinsoft.convertigo.beans.core.Sequence.java

private static Node cloneNodeWithUserData(Node node, boolean recurse) {
    if (node != null) {
        Object node_output = node.getUserData(Step.NODE_USERDATA_OUTPUT);

        Node clonedNode = node.cloneNode(false);
        clonedNode.setUserData(Step.NODE_USERDATA_OUTPUT, node_output, null);

        if (node.getNodeType() == Node.ELEMENT_NODE) {
            // attributes
            NamedNodeMap attributeMap = clonedNode.getAttributes();
            for (int i = 0; i < attributeMap.getLength(); i++) {
                Node clonedAttribute = attributeMap.item(i);
                String attr_name = clonedAttribute.getNodeName();
                Object attr_output = ((Element) node).getAttributeNode(attr_name)
                        .getUserData(Step.NODE_USERDATA_OUTPUT);
                clonedAttribute.setUserData(Step.NODE_USERDATA_OUTPUT, attr_output, null);
            }//w  ww.j a v a2  s.c o  m

            // recurse on element child nodes only
            if (recurse && node.hasChildNodes()) {
                NodeList list = node.getChildNodes();
                for (int i = 0; i < list.getLength(); i++) {
                    Node clonedChild = cloneNodeWithUserData(list.item(i), recurse);
                    if (clonedChild != null) {
                        clonedNode.appendChild(clonedChild);
                    }
                }
            }
        }

        return clonedNode;
    }
    return null;
}

From source file:org.mumod.android.provider.StatusNet.java

private String getTagValueWithMultiItem(Element eElement) {
    String returnVal = "";
    Node eNode;//from  w  w w  .j ava 2  s . c om
    int NumOFItem = eElement.getElementsByTagName("link").getLength();
    for (int y = 0; y < NumOFItem; y++) {
        eNode = eElement.getElementsByTagName("link").item(y);
        NamedNodeMap attributes = eNode.getAttributes();
        for (int g = 0; g < attributes.getLength(); g++) {
            Attr attribute = (Attr) attributes.item(g);
            if (attribute.getNodeName().equals("rel") && attribute.getNodeValue().equals("alternate")) {
                try {
                    if (eNode.getAttributes().getNamedItem("type").getNodeValue()
                            .equals("application/atom+xml"))
                        returnVal = eNode.getAttributes().getNamedItem("href").getNodeValue();
                } catch (Exception e) {
                    if (MustardApplication.DEBUG)
                        e.printStackTrace();
                }
            }
        }
    }
    return returnVal;
}