Example usage for org.w3c.dom NamedNodeMap getLength

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

Introduction

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

Prototype

public int getLength();

Source Link

Document

The number of nodes in this map.

Usage

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

/**
 * /*from  w  w  w  .  j  a  va2s. c o  m*/
 * @param account
 * @param accountId
 * @param cADbject
 * @return
 * @throws Exception
 */
public static final Task createCRMObjectTypeTask(final ScribeObject cADbject,
        final String crmFieldIntraSeparator) throws Exception {

    /* Create xml beans object */
    final Task task = Task.Factory.newInstance();

    /* Create new cursor */
    XmlCursor cursor = null;
    try {
        cursor = task.newCursor();
        cursor.toFirstContentToken();
        final Node node = cursor.getDomNode();

        /* Get main namespace URl */
        if (node != null) {
            final String nsURL = node.getNamespaceURI();

            /* Iterate on the Element list and create SOAP object */
            for (final Element element : cADbject.getXmlContent()) {

                if (logger.isDebugEnabled()) {
                    logger.debug("----Inside createCRMObject_Task: adding node : " + element.getNodeName()
                            + " with value : " + element.getTextContent());
                }

                /* Get crm field */
                final String crmField = element.getNodeName();

                String crmFieldName = null;

                /* If field contains the type information */
                if (crmField != null && crmField.contains(crmFieldIntraSeparator)) {

                    /* Split the field and get name */
                    crmFieldName = crmField.split(crmFieldIntraSeparator)[0];
                } else {
                    crmFieldName = crmField;
                }

                /* Add all new nodes */
                cursor.beginElement(new QName(nsURL, crmFieldName));

                /* Set node attributes */
                if (element.getAttributes() != null) {

                    /* Get attribute map */
                    final NamedNodeMap namedNodeMap = element.getAttributes();

                    /* Interate over map */
                    for (int i = 0; i < namedNodeMap.getLength(); i++) {

                        /* Get respective item */
                        final Node namedNode = namedNodeMap.item(i);

                        if (logger.isDebugEnabled()) {
                            logger.debug("----Inside createCRMObject_Task: adding attribute name : "
                                    + namedNode.getNodeName() + " with value : " + namedNode.getNodeValue());
                        }

                        /* Set node attribute */
                        cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue());
                    }
                }

                /* Set node value */
                cursor.insertChars(element.getTextContent());

                /* Jump to next token */
                cursor.toNextToken();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.dispose();
        }
    }
    return task;
}

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

/**
 * /*  w w w.  ja va2  s .com*/
 * @param account
 * @param accountId
 * @param cADbject
 * @return
 * @throws Exception
 */
public static final Contact createCRMObjectTypeContact(final ScribeObject cADbject,
        final String crmFieldIntraSeparator) throws Exception {

    /* Create xml beans object */
    final Contact contact = Contact.Factory.newInstance();

    /* Create new cursor */
    XmlCursor cursor = null;
    try {
        cursor = contact.newCursor();
        cursor.toFirstContentToken();
        final Node node = cursor.getDomNode();

        /* Get main namespace URl */
        if (node != null) {
            final String nsURL = node.getNamespaceURI();

            /* Iterate on the Element list and create SOAP object */
            for (final Element element : cADbject.getXmlContent()) {

                if (logger.isDebugEnabled()) {
                    logger.debug("----Inside createCRMObject_Contact: adding node : " + element.getNodeName()
                            + " with value : " + element.getTextContent());
                }

                /* Get crm field */
                final String crmField = element.getNodeName();

                String crmFieldName = null;

                /* If field contains the type information */
                if (crmField != null && crmField.contains(crmFieldIntraSeparator)) {

                    /* Split the field and get name */
                    crmFieldName = crmField.split(crmFieldIntraSeparator)[0];
                } else {
                    crmFieldName = crmField;
                }

                /* Add all new nodes */
                cursor.beginElement(new QName(nsURL, crmFieldName));

                /* Set node attributes */
                if (element.getAttributes() != null) {

                    /* Get attribute map */
                    final NamedNodeMap namedNodeMap = element.getAttributes();

                    /* Interate over map */
                    for (int i = 0; i < namedNodeMap.getLength(); i++) {

                        /* Get respective item */
                        final Node namedNode = namedNodeMap.item(i);

                        if (logger.isDebugEnabled()) {
                            logger.debug("----Inside createCRMObject_Contact: adding attribute name : "
                                    + namedNode.getNodeName() + " with value: " + namedNode.getNodeValue());
                        }

                        /* Set node attribute */
                        cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue());
                    }
                }

                /* Set node value */
                cursor.insertChars(element.getTextContent());

                /* Jump to next token */
                cursor.toNextToken();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.dispose();
        }
    }
    return contact;
}

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

/**
 * /*from  w  w  w .  j  a v  a 2  s  . c  o  m*/
 * @param account
 * @param accountId
 * @param cADbject
 * @return
 * @throws Exception
 */
public static final Lead createCRMObjectTypeLead(final ScribeObject cADbject,
        final String crmFieldIntraSeparator) throws Exception {

    /* Create xml beans object */
    final Lead lead = Lead.Factory.newInstance();

    /* Create new cursor */
    XmlCursor cursor = null;
    try {
        cursor = lead.newCursor();
        cursor.toFirstContentToken();
        final Node node = cursor.getDomNode();

        /* Get main namespace URl */
        if (node != null) {

            final String nsURL = node.getNamespaceURI();

            /* Iterate on the Element list and create SOAP object */
            for (final Element element : cADbject.getXmlContent()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("----Inside createCRMObject_Lead: adding node : " + element.getNodeName()
                            + " with value : " + element.getTextContent());
                }

                /* Get crm field */
                final String crmField = element.getNodeName();

                String crmFieldName = null;

                /* If field contains the type information */
                if (crmField != null && crmField.contains(crmFieldIntraSeparator)) {

                    /* Split the field and get name */
                    crmFieldName = crmField.split(crmFieldIntraSeparator)[0];
                } else {
                    crmFieldName = crmField;
                }

                /* Add all new nodes */
                cursor.beginElement(new QName(nsURL, crmFieldName));

                /* Set node attributes */
                if (element.getAttributes() != null) {

                    /* Get attribute map */
                    final NamedNodeMap namedNodeMap = element.getAttributes();

                    /* Interate over map */
                    for (int i = 0; i < namedNodeMap.getLength(); i++) {

                        /* Get respective item */
                        final Node namedNode = namedNodeMap.item(i);

                        if (logger.isDebugEnabled()) {
                            logger.debug("----Inside createCRMObject_Lead: adding attribute name : "
                                    + namedNode.getNodeName() + " with value: " + namedNode.getNodeValue());
                        }

                        /* Set node attribute */
                        cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue());
                    }
                }

                /* Set node value */
                cursor.insertChars(element.getTextContent());

                /* Jump to next token */
                cursor.toNextToken();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.dispose();
        }
    }
    return lead;
}

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

/**
 * //from ww  w  .  jav  a 2 s.c  om
 * @param account
 * @param accountId
 * @param cADbject
 * @return
 * @throws Exception
 */
public static final Account createCRMObjectTypeAccount(final ScribeObject cADbject,
        final String crmFieldIntraSeparator) throws Exception {

    /* Create xml beans object */
    final Account account = Account.Factory.newInstance();

    /* Create new cursor */
    XmlCursor cursor = null;
    try {
        cursor = account.newCursor();
        cursor.toFirstContentToken();
        final Node node = cursor.getDomNode();

        /* Get main namespace URl */
        if (node != null) {
            final String nsURL = node.getNamespaceURI();

            /* Iterate on the Element list and create SOAP object */
            for (final Element element : cADbject.getXmlContent()) {

                if (logger.isDebugEnabled()) {
                    logger.debug("----Inside createCRMObject_Account: adding node: " + element.getNodeName()
                            + " with value : " + element.getTextContent());
                }

                /* Get crm field */
                final String crmField = element.getNodeName();

                String crmFieldName = null;

                /* If field contains the type information */
                if (crmField != null && crmField.contains(crmFieldIntraSeparator)) {

                    /* Split the field and get name */
                    crmFieldName = crmField.split(crmFieldIntraSeparator)[0];

                } else {
                    crmFieldName = crmField;
                }

                /* Add all new nodes */
                cursor.beginElement(new QName(nsURL, crmFieldName));

                /* Set node attributes */
                if (element.getAttributes() != null) {

                    /* Get attribute map */
                    final NamedNodeMap namedNodeMap = element.getAttributes();

                    /* Interate over map */
                    for (int i = 0; i < namedNodeMap.getLength(); i++) {

                        /* Get respective item */
                        final Node namedNode = namedNodeMap.item(i);

                        if (logger.isDebugEnabled()) {
                            logger.debug("----Inside createCRMObject_Account: adding attribute name : "
                                    + namedNode.getNodeName() + " with value : " + namedNode.getNodeValue());
                        }

                        /* Set node attribute */
                        cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue());
                    }
                }

                /* Set node value */
                cursor.insertChars(element.getTextContent());

                /* Jump to next token */
                cursor.toNextToken();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.dispose();
        }
    }
    return account;
}

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

/**
 * //from   w  w w .  j  a  v a  2s .  c  om
 * @param account
 * @param accountId
 * @param cADbject
 * @return
 * @throws Exception
 */
public static final Opportunity createCRMObjectTypeOpportunity(final ScribeObject cADbject,
        final String crmFieldIntraSeparator) throws Exception {

    /* Create xml beans object */
    final Opportunity opportunity = Opportunity.Factory.newInstance();

    /* Create new cursor */
    XmlCursor cursor = null;
    try {
        cursor = opportunity.newCursor();
        cursor.toFirstContentToken();
        final Node node = cursor.getDomNode();

        /* Get main namespace URl */
        if (node != null) {

            final String nsURL = node.getNamespaceURI();

            /* Iterate on the Element list and create SOAP object */
            for (final Element element : cADbject.getXmlContent()) {

                if (logger.isDebugEnabled()) {
                    logger.debug("----Inside createCRMObject_Opportunity: adding node : "
                            + element.getNodeName() + " with value : " + element.getTextContent());
                }

                /* Get crm field */
                final String crmField = element.getNodeName();

                String crmFieldName = null;

                /* If field contains the type information */
                if (crmField != null && crmField.contains(crmFieldIntraSeparator)) {

                    /* Split the field and get name */
                    crmFieldName = crmField.split(crmFieldIntraSeparator)[0];
                } else {
                    crmFieldName = crmField;
                }

                /* Add all new nodes */
                cursor.beginElement(new QName(nsURL, crmFieldName));

                /* Set node attributes */
                if (element.getAttributes() != null) {

                    /* Get attribute map */
                    final NamedNodeMap namedNodeMap = element.getAttributes();

                    /* Interate over map */
                    for (int i = 0; i < namedNodeMap.getLength(); i++) {

                        /* Get respective item */
                        final Node namedNode = namedNodeMap.item(i);

                        if (logger.isDebugEnabled()) {
                            logger.debug("----Inside createCRMObject_Opportunity: adding attribute name : "
                                    + namedNode.getNodeName() + " with value: " + namedNode.getNodeValue());
                        }

                        /* Set node attribute */
                        cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue());
                    }
                }

                /* Set node value */
                cursor.insertChars(element.getTextContent());

                /* Jump to next token */
                cursor.toNextToken();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.dispose();
        }
    }
    return opportunity;
}

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

/**
 * //from   www  . j  a  v a 2 s .co  m
 * @param account
 * @param accountId
 * @param cADbject
 * @return
 * @throws Exception
 */
public static final Incident createCRMObjectTypeIncident(final ScribeObject cADbject,
        final String crmFieldIntraSeparator) throws Exception {

    /* Create xml beans object */
    /* In MS CRM 'Incident' is actually a 'Case' */
    final Incident caseObject = Incident.Factory.newInstance();

    /* Create new cursor */
    XmlCursor cursor = null;
    try {
        cursor = caseObject.newCursor();
        cursor.toFirstContentToken();
        final Node node = cursor.getDomNode();

        /* Get main namespace URl */
        if (node != null) {
            final String nsURL = node.getNamespaceURI();

            /* Iterate on the Element list and create SOAP object */
            for (final Element element : cADbject.getXmlContent()) {

                if (logger.isDebugEnabled()) {
                    logger.debug("----Inside createCRMObject_Incident: adding node : " + element.getNodeName()
                            + " with value : " + element.getTextContent());
                }

                /* Get crm field */
                final String crmField = element.getNodeName();

                String crmFieldName = null;

                /* If field contains the type information */
                if (crmField != null && crmField.contains(crmFieldIntraSeparator)) {

                    /* Split the field and get name */
                    crmFieldName = crmField.split(crmFieldIntraSeparator)[0];
                } else {
                    crmFieldName = crmField;
                }

                /* Add all new nodes */
                cursor.beginElement(new QName(nsURL, crmFieldName));

                /* Set node attributes */
                if (element.getAttributes() != null) {

                    /* Get attribute map */
                    final NamedNodeMap namedNodeMap = element.getAttributes();

                    /* Interate over map */
                    for (int i = 0; i < namedNodeMap.getLength(); i++) {

                        /* Get respective item */
                        final Node namedNode = namedNodeMap.item(i);

                        if (logger.isDebugEnabled()) {
                            logger.debug("----Inside createCRMObject_Incident: adding attribute name : "
                                    + namedNode.getNodeName() + " with value: " + namedNode.getNodeValue());
                        }

                        /* Set node attribute */
                        cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue());
                    }
                }

                /* Set node value */
                cursor.insertChars(element.getTextContent());

                /* Jump to next token */
                cursor.toNextToken();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.dispose();
        }
    }
    return caseObject;
}

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

private void getNodeInfo(Node node, ObjectInfo obj) {
    int a;/*from w  w  w. ja  v a  2  s  .com*/
    String name = "";
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        NamedNodeMap attributes = node.getAttributes();
        for (a = 0; a < attributes.getLength(); a++) {
            Node attribute = attributes.item(a);
            name = attribute.getNodeName();
            if (name.compareToIgnoreCase("Id") == 0) {
                obj.objId = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("Name") == 0) {
                obj.name = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("Parent") == 0) {
                obj.parentId = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("ParentPool") == 0) {
                obj.domEl = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("refId") == 0) {
                obj.refId = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("hasStart") == 0) {
                obj.hasStart = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("hasEnd") == 0) {
                obj.hasEnd = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("startRefId") == 0) {
                obj.startRefId = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("endRefId") == 0) {
                obj.endRefId = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("derivationRule") == 0) {
                obj.derivationRule = attribute.getNodeValue();
            } else if (name.compareToIgnoreCase("domEl") == 0) {
                obj.domEl = attribute.getNodeValue();
            }

        }
    }
}

From source file:DOMProcessor.java

/** Searches the given node for a given attribute and returns the value associated with it.
  * This version does not recurse to children of the given node.
  * @param attributeName Attribute to search for.
  * @param node Node from which to start search.
  * @return Value associated with the attribute, or null if not found.  
  *//*from   w  w w  .j a v a 2 s  .  c  o  m*/
public String getNodeAttribute(String attributeName, Node node) {
    // Only consider document or element nodes.
    if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getNodeType() != Node.ELEMENT_NODE)) {
        return null;
    }

    // Search attributes associated with the node.
    NamedNodeMap attributes = node.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        if (attribute.getNodeName().equalsIgnoreCase(attributeName)) {
            return attribute.getNodeValue();
        }
    }

    // If we get this far, the attribute has not been found.
    return null;
}

From source file:DOMProcessor.java

/** Searches for a given attribute in the given node and updates list
  * of attribute values. Recursively searches for sub-nodes of the given one.
  * @param element Element to search for.
  * @param node Node to start search from.
  *//*from  w w w.  j a  v  a2  s .  c  o m*/
private void searchAttributes(String element, Node node) {
    // Only consider document or element nodes.
    if ((node.getNodeType() != Node.DOCUMENT_NODE) && (node.getNodeType() != Node.ELEMENT_NODE)) {
        return;
    }

    // Search attributes associated with current node.
    NamedNodeMap attributes = node.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        if (attribute.getNodeName().equalsIgnoreCase(element)) {
            //matches.add(attribute.getNodeValue());
            matches.add(attribute);
        }
    }

    // Search child nodes.
    NodeList children = node.getChildNodes();

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

From source file:DOMProcessor.java

/** Renames the given element with the given new name.
  * @param existingElement Element to rename.
  * @param newName New name to give element.
  *//*from ww w  . j av a  2 s . c om*/
public void renameElement(Node existingElement, String newName) {
    // Create an element with the new name
    Node newElement = dom.createElement(newName);

    // Copy the attributes to the new element
    NamedNodeMap attrs = existingElement.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr2 = (Attr) dom.importNode(attrs.item(i), true);
        newElement.getAttributes().setNamedItem(attr2);
    }

    // Move all the children
    while (existingElement.hasChildNodes()) {
        newElement.appendChild(existingElement.getFirstChild());
    }

    // Replace the old node with the new node
    existingElement.getParentNode().replaceChild(newElement, existingElement);
}