Example usage for org.w3c.dom Node getNamespaceURI

List of usage examples for org.w3c.dom Node getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Node getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureVerifier.java

@SuppressWarnings("unchecked")
private boolean isIdOfficeObjectValid(String signatureId, XMLObject idOfficeObject) {

    SignatureProperties signatureProperties;
    if (1 != idOfficeObject.getContent().size()) {
        LOG.error("Expect SignatureProperties element in \"idPackageObject\".");
        return false;
    }//  w  w w . j  av  a2s  .  c  o m
    signatureProperties = (SignatureProperties) idOfficeObject.getContent().get(0);

    if (signatureProperties.getProperties().size() != 1) {
        LOG.error("Unexpected # of SignatureProperty's in idOfficeObject");
        return false;
    }

    // SignatureInfo
    SignatureProperty signatureInfoProperty = (SignatureProperty) signatureProperties.getProperties().get(0);
    if (!signatureInfoProperty.getId().equals("idOfficeV1Details")) {
        LOG.error("Unexpected SignatureProperty: expected id=idOfficeV1Details " + "but got: "
                + signatureInfoProperty.getId());
        return false;
    }
    if (!signatureInfoProperty.getTarget().equals("#" + signatureId)) {
        LOG.error("Unexpected SignatureProperty: expected target=#" + signatureId + " but got: "
                + signatureInfoProperty.getTarget());
        LOG.warn("Allowing this error because of a bug in Office2010");
        // work-around for existing bug in Office2011
        // return false;
    }

    // SignatureInfoV1
    if (signatureInfoProperty.getContent().size() != 1) {
        LOG.error("Unexpected content in SignatureInfoProperty.");
        return false;
    }
    DOMStructure signatureInfoV1DOM = (DOMStructure) signatureInfoProperty.getContent().get(0);
    Node signatureInfoElement = signatureInfoV1DOM.getNode();
    if (!signatureInfoElement.getNamespaceURI().equals(OOXMLSignatureFacet.OFFICE_DIGSIG_NS)) {
        LOG.error("Unexpected SignatureInfoProperty content: NS=" + signatureInfoElement.getNamespaceURI());
        return false;
    }

    // TODO: validate childs: validate all possible from 2.5.2.5
    // ([MS-OFFCRYPTO]) or just ManifestHashAlgorithm?

    return true;
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureVerifier.java

@SuppressWarnings("unchecked")
private boolean validateSignatureProperty(SignatureProperty signatureProperty, String signatureId) {

    if (!signatureProperty.getId().equals("idSignatureTime")) {
        LOG.error("Unexpected SignatureProperty: expected id=idSignatureTime " + "but got: "
                + signatureProperty.getId());
        return false;
    }/*www  .j a v a 2  s . co  m*/
    if (!signatureProperty.getTarget().equals("#" + signatureId)) {
        LOG.error("Unexpected SignatureProperty: expected target=#" + signatureId + "but got: "
                + signatureProperty.getTarget());
        return false;
    }
    List<XMLStructure> signatureTimeContent = signatureProperty.getContent();
    if (signatureTimeContent.size() != 1) {
        LOG.error("Unexpected SignatureTime content.");
        return false;
    }
    DOMStructure signatureTimeDOM = (DOMStructure) signatureTimeContent.get(0);
    Node signatureTimeElement = signatureTimeDOM.getNode();
    if (!signatureTimeElement.getNamespaceURI().equals(OOXMLSignatureFacet.OOXML_DIGSIG_NS)) {
        LOG.error("Invalid SignatureTime element: NS=" + signatureTimeElement.getNamespaceURI());
        return false;
    }
    if (!signatureTimeElement.getLocalName().equals("SignatureTime")) {
        LOG.error("Invalid SignatureTime element: Name=" + signatureTimeElement.getLocalName());
        return false;
    }
    if (signatureTimeElement.getChildNodes().getLength() != 2) {
        LOG.error("Invalid SignatureTime element: Childs=" + signatureTimeElement.getChildNodes().getLength()
                + ", expected 2 (Format+Value)");
        return false;
    }

    // format element
    Node formatElement = signatureTimeElement.getChildNodes().item(0);
    if (!formatElement.getNamespaceURI().equals(OOXMLSignatureFacet.OOXML_DIGSIG_NS)) {
        LOG.error("Invalid SignatureTime.Format element: NS=" + formatElement.getNamespaceURI());
        return false;
    }
    if (!formatElement.getLocalName().equals("Format")) {
        LOG.error("Invalid SignatureTime.Format element: Name=" + formatElement.getLocalName());
        return false;
    }

    // value element
    Node valueElement = signatureTimeElement.getChildNodes().item(1);
    if (!valueElement.getNamespaceURI().equals(OOXMLSignatureFacet.OOXML_DIGSIG_NS)) {
        LOG.error("Invalid SignatureTime.Value element: NS=" + valueElement.getNamespaceURI());
        return false;
    }
    if (!valueElement.getLocalName().equals("Value")) {
        LOG.error("Invalid SignatureTime.Value element: Name=" + valueElement.getLocalName());
        return false;
    }

    // TODO: validate value?

    return true;
}

From source file:org.lareferencia.backend.harvester.OCLCBasedHarvesterImpl.java

/**
 * @param node//from  w  w  w . ja v  a  2s.c  om
 * @param document 
 * @return 
 * @throws TransformerException
 * @throws NoSuchFieldException 
 */
private String getMetadataString(Node node, Document document)
        throws TransformerException, NoSuchFieldException {

    /**
     *  TODO: bsqueda secuencial, puede ser ineficiente pero xpath no esta implementado sobre nodos individaules
     *  en la interfaz listRecords, en necesario construir un DomHelper para Harvester, es sencillo dada la clase
     *  base BaseMetadataDOMHelper
     */

    NodeList childs = node.getChildNodes();
    Node metadataNode = null;
    for (int i = 0; i < childs.getLength(); i++)
        if (childs.item(i).getNodeName().contains(METADATA_NODE_NAME))
            metadataNode = childs.item(i);

    if (metadataNode == null)
        throw new NoSuchFieldException("No existe el nodo: " + METADATA_NODE_NAME + " en la respuesta.\n"
                + MedatadaDOMHelper.Node2XMLString(node));

    // este rename unifica los casos distintos de namespace encontrados en repositorios
    document.renameNode(metadataNode, metadataNode.getNamespaceURI(), METADATA_NODE_NAME);

    // TODO: Ver el tema del char &#56256;
    return MedatadaDOMHelper.Node2XMLString(metadataNode);
}

From source file:chat.viska.xmpp.HandshakerPipe.java

/**
 * Checks the feature list and see if any feature should negotiate next. Also
 * flags any informational {@link StreamFeature}s as negotiated. Also sets the
 * field {@code negotiatingFeature}.//from  w w  w  .  j  a  v a  2s.  c o  m
 * @param document XML sent by the server.
 * @return {@link StreamFeature} selected to negotiate.
 */
@Nullable
private Element consumeStreamFeatures(final Document document) {
    final List<Node> announcedFeatures = DomUtils.convertToList(document.getDocumentElement().getChildNodes());
    if (announcedFeatures.size() == 0) {
        return null;
    }

    for (StreamFeature informational : INFORMATIONAL_FEATURES) {
        for (Node announced : announcedFeatures) {
            if (informational.getNamespace().equals(announced.getNamespaceURI())
                    && informational.getName().equals(announced.getLocalName())) {
                if (this.negotiatedFeatures.add(informational)) {
                    this.eventStream.onNext(new FeatureNegotiatedEvent(this, informational));
                }
            }
        }
    }

    for (StreamFeature supported : FEATURES_ORDER) {
        for (Node announced : announcedFeatures) {
            if (supported.getNamespace().equals(announced.getNamespaceURI())
                    && supported.getName().equals(announced.getLocalName())) {
                this.negotiatingFeature = supported;
                return (Element) announced;
            }
        }
    }

    return null;
}

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

/**
 * /*from w w w  . j a va  2  s.  c om*/
 * @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

/**
 * //from  ww  w  .  j  av  a2 s . c  o  m
 * @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

/**
 * /*  w  ww  . j  a  v  a 2s.c o  m*/
 * @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

/**
 * /* ww 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

/**
 * /* w ww.j  av a 2 s.  c  om*/
 * @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.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java

/**
 * /*from  ww  w .  j  ava  2  s  .co m*/
 * @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;
}