Example usage for org.w3c.dom Element getElementsByTagNameNS

List of usage examples for org.w3c.dom Element getElementsByTagNameNS

Introduction

In this page you can find the example usage for org.w3c.dom Element getElementsByTagNameNS.

Prototype

public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Returns a NodeList of all the descendant Elements with a given local name and namespace URI in document order.

Usage

From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java

/**
 * Get the Extensible elements form wsdl4jExtensibleElements
 * <code>Vector</code> if any and copy them to <code>Component</code>
 * <p/> Note - SOAP body extensible element will be processed differently
 *
 * @param wsdl4jExtensibleElements//from   w  w  w.  ja va  2  s . c o m
 * @param description                   where is the ext element (port , portype , biding)
 * @param wsdl4jDefinition
 * @param originOfExtensibilityElements -
 *                                      this will indicate the place this extensibility element came
 *                                      from.
 */
private void copyExtensibleElements(List wsdl4jExtensibleElements, Definition wsdl4jDefinition,
        AxisDescription description, String originOfExtensibilityElements) throws AxisFault {

    ExtensibilityElement wsdl4jExtensibilityElement;

    for (Iterator iterator = wsdl4jExtensibleElements.iterator(); iterator.hasNext();) {

        wsdl4jExtensibilityElement = (ExtensibilityElement) iterator.next();

        if (wsdl4jExtensibilityElement instanceof UnknownExtensibilityElement) {

            UnknownExtensibilityElement unknown = (UnknownExtensibilityElement) (wsdl4jExtensibilityElement);
            QName type = unknown.getElementType();

            // <wsp:Policy>
            if (WSDLConstants.WSDL11Constants.POLICY.equals(type)) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: PolicyElement found " + unknown);
                }
                Policy policy = (Policy) PolicyUtil.getPolicyComponent(unknown.getElement());
                description.getPolicySubject().attachPolicy(policy);

                //                    int attachmentScope =
                //                            getPolicyAttachmentPoint(description, originOfExtensibilityElements);
                //                    if (attachmentScope > -1) {
                //                        description.getPolicyInclude().addPolicyElement(
                //                                attachmentScope, policy);
                //                    }
                // <wsp:PolicyReference>
            } else if (WSDLConstants.WSDL11Constants.POLICY_REFERENCE.equals(type)) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: PolicyReference found " + unknown);
                }
                PolicyReference policyReference = (PolicyReference) PolicyUtil
                        .getPolicyComponent(unknown.getElement());
                description.getPolicySubject().attachPolicyReference(policyReference);

                //                    int attachmentScope =
                //                            getPolicyAttachmentPoint(description, originOfExtensibilityElements);
                //                    if (attachmentScope > -1) {
                //                        description.getPolicyInclude().addPolicyRefElement(
                //                                attachmentScope, policyReference);
                //                    }
            } else if (AddressingConstants.Final.WSAW_USING_ADDRESSING.equals(type)
                    || AddressingConstants.Submission.WSAW_USING_ADDRESSING.equals(unknown.getElementType())) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: wsaw:UsingAddressing found " + unknown);
                }
                // FIXME We need to set this the appropriate Axis Description AxisEndpoint or
                // AxisBinding .
                if (originOfExtensibilityElements.equals(PORT)
                        || originOfExtensibilityElements.equals(BINDING)) {
                    if (Boolean.TRUE.equals(unknown.getRequired())) {
                        AddressingHelper.setAddressingRequirementParemeterValue(axisService,
                                AddressingConstants.ADDRESSING_REQUIRED);
                    } else {
                        AddressingHelper.setAddressingRequirementParemeterValue(axisService,
                                AddressingConstants.ADDRESSING_OPTIONAL);
                    }
                }

            } else if (wsdl4jExtensibilityElement.getElementType() != null
                    && wsdl4jExtensibilityElement.getElementType().getNamespaceURI()
                            .equals(org.apache.axis2.namespace.Constants.FORMAT_BINDING)) {
                Element typeMapping = unknown.getElement();

                NodeList typeMaps = typeMapping
                        .getElementsByTagNameNS(org.apache.axis2.namespace.Constants.FORMAT_BINDING, "typeMap");
                int count = typeMaps.getLength();
                HashMap typeMapper = new HashMap();
                for (int index = 0; index < count; index++) {
                    Node node = typeMaps.item(index);
                    NamedNodeMap attributes = node.getAttributes();
                    Node typeName = attributes.getNamedItem("typeName");

                    if (typeName != null) {
                        String prefix = getPrefix(typeName.getNodeValue());

                        if (prefix != null) {
                            String ns = (String) wsdl4jDefinition.getNamespaces().get(prefix);
                            if (ns != null) {
                                Node formatType = attributes.getNamedItem("formatType");
                                typeMapper.put(new QName(ns, getTypeName(typeName.getNodeValue())),
                                        formatType.getNodeValue());
                            }

                        }
                    }
                }
            } else if (wsdl4jExtensibilityElement.getElementType() != null && wsdl4jExtensibilityElement
                    .getElementType().getNamespaceURI().equals(org.apache.axis2.namespace.Constants.JAVA_NS)) {
                Element unknowJavaElement = unknown.getElement();
                if (unknowJavaElement.getLocalName().equals("address")) {
                    NamedNodeMap nameAttributes = unknowJavaElement.getAttributes();
                    Node node = nameAttributes.getNamedItem("className");
                    Parameter serviceClass = new Parameter();
                    serviceClass.setName("className");
                    serviceClass.setValue(node.getNodeValue());
                    axisService.addParameter(serviceClass);
                    Parameter transportName = new Parameter();
                    transportName.setName("TRANSPORT_NAME");
                    transportName.setValue("java");
                    axisService.addParameter(transportName);
                }
            } else {
                // Ignore this element - it is a totally unknown element
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: Unknown Extensibility Element found " + unknown);
                }
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Address) {
            SOAP12Address soapAddress = (SOAP12Address) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI());
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAPAddress) {
            SOAPAddress soapAddress = (SOAPAddress) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI());
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPAddress) {
            HTTPAddress httpAddress = (HTTPAddress) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, httpAddress.getLocationURI());
            }

        } else if (wsdl4jExtensibilityElement instanceof Schema) {
            Schema schema = (Schema) wsdl4jExtensibilityElement;
            // just add this schema - no need to worry about the imported
            // ones
            axisService.addSchema(getXMLSchema(schema.getElement(), schema.getDocumentBaseURI()));

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Operation) {
            SOAP12Operation soapOperation = (SOAP12Operation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;

            String style = soapOperation.getStyle();
            if (style != null) {
                axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

            String soapActionURI = soapOperation.getSoapActionURI();

            if (this.isCodegen && ((soapActionURI == null) || (soapActionURI.equals("")))) {
                soapActionURI = axisBindingOperation.getAxisOperation().getInputAction();
            }

            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
                log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: "
                        + soapActionURI);

            if (soapActionURI != null && !soapActionURI.equals("")) {
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapActionURI);
                axisBindingOperation.getAxisOperation().setSoapAction(soapActionURI);
                if (!isServerSide) {
                    axisBindingOperation.getAxisOperation().setOutputAction(soapActionURI);
                }

                axisService.mapActionToOperation(soapActionURI, axisBindingOperation.getAxisOperation());
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAPOperation) {
            SOAPOperation soapOperation = (SOAPOperation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;

            String style = soapOperation.getStyle();
            if (style != null) {
                axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

            String soapAction = soapOperation.getSoapActionURI();
            if (this.isCodegen && ((soapAction == null) || (soapAction.equals("")))) {
                soapAction = axisBindingOperation.getAxisOperation().getInputAction();
            }

            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
                log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: "
                        + soapAction);

            if (soapAction != null) {
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapAction);
                axisBindingOperation.getAxisOperation().setSoapAction(soapAction);
                if (!isServerSide) {
                    axisBindingOperation.getAxisOperation().setOutputAction(soapAction);
                }

                axisService.mapActionToOperation(soapAction, axisBindingOperation.getAxisOperation());
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPOperation) {
            HTTPOperation httpOperation = (HTTPOperation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;

            String httpLocation = httpOperation.getLocationURI();
            if (httpLocation != null) {
                // change the template to make it same as WSDL 2 template
                httpLocation = httpLocation.replaceAll("\\(", "{");
                httpLocation = httpLocation.replaceAll("\\)", "}");
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation);

            }
            axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION,
                    HTTPConstants.MEDIA_TYPE_TEXT_XML);

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Header) {

            SOAP12Header soapHeader = (SOAP12Header) wsdl4jExtensibilityElement;
            SOAPHeaderMessage headerMessage = new SOAPHeaderMessage();

            headerMessage.setNamespaceURI(soapHeader.getNamespaceURI());
            headerMessage.setUse(soapHeader.getUse());

            Boolean required = soapHeader.getRequired();

            if (required != null) {
                headerMessage.setRequired(required.booleanValue());
            }

            if (wsdl4jDefinition != null) {
                // find the relevant schema part from the messages
                Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage());

                if (msg == null) {
                    msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet());
                }

                if (msg == null) {
                    // TODO i18n this
                    throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL ");
                }
                Part msgPart = msg.getPart(soapHeader.getPart());

                if (msgPart == null) {
                    // TODO i18n this
                    throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL ");
                }
                // see basic profile 4.4.2 Bindings and Faults header, fault and headerfaults
                // can only have elements
                headerMessage.setElement(msgPart.getElementName());
            }

            headerMessage.setMessage(soapHeader.getMessage());
            headerMessage.setPart(soapHeader.getPart());

            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders == null) {
                    soapHeaders = new ArrayList();
                    bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders);
                }
                soapHeaders.add(headerMessage);
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAPHeader) {

            SOAPHeader soapHeader = (SOAPHeader) wsdl4jExtensibilityElement;
            SOAPHeaderMessage headerMessage = new SOAPHeaderMessage();
            headerMessage.setNamespaceURI(soapHeader.getNamespaceURI());
            headerMessage.setUse(soapHeader.getUse());
            Boolean required = soapHeader.getRequired();
            if (null != required) {
                headerMessage.setRequired(required.booleanValue());
            }
            if (null != wsdl4jDefinition) {
                // find the relevant schema part from the messages
                Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage());

                if (msg == null) {
                    msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet());
                }

                if (msg == null) {
                    // todo i18n this
                    throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL ");
                }
                Part msgPart = msg.getPart(soapHeader.getPart());
                if (msgPart == null) {
                    // todo i18n this
                    throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL ");
                }
                headerMessage.setElement(msgPart.getElementName());
            }
            headerMessage.setMessage(soapHeader.getMessage());

            headerMessage.setPart(soapHeader.getPart());

            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders == null) {
                    soapHeaders = new ArrayList();
                    bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders);
                }
                soapHeaders.add(headerMessage);
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAPBinding) {

            SOAPBinding soapBinding = (SOAPBinding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;

            axisBinding.setType(soapBinding.getTransportURI());

            axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

            String style = soapBinding.getStyle();
            if (style != null) {
                axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

        } else if (wsdl4jExtensibilityElement instanceof SOAP12Binding) {

            SOAP12Binding soapBinding = (SOAP12Binding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;

            axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
                    SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

            String style = soapBinding.getStyle();
            if (style != null) {
                axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }

            String transportURI = soapBinding.getTransportURI();
            axisBinding.setType(transportURI);

        } else if (wsdl4jExtensibilityElement instanceof HTTPBinding) {
            HTTPBinding httpBinding = (HTTPBinding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;
            // set the binding style same as the wsd2 to process smoothly
            axisBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
            axisBinding.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, httpBinding.getVerb());
        } else if (wsdl4jExtensibilityElement instanceof MIMEContent) {
            if (description instanceof AxisBindingMessage) {
                MIMEContent mimeContent = (MIMEContent) wsdl4jExtensibilityElement;
                String messageSerialization = mimeContent.getType();
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(),
                        originOfExtensibilityElements, messageSerialization);
            }
        } else if (wsdl4jExtensibilityElement instanceof MIMEMimeXml) {
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(),
                        originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_TEXT_XML);
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPUrlEncoded) {
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(),
                        originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_X_WWW_FORM);
            }
        }
    }
}

From source file:org.apache.cxf.ws.security.sts.provider.operation.IssueDelegate.java

private X509Certificate getCertificateFromRequest(Object requestObject) throws CertificateException {
    UseKeyType useKeyType = extractType(requestObject, UseKeyType.class);
    byte[] x509 = null;
    if (null != useKeyType) {
        KeyInfoType keyInfoType = extractType(useKeyType.getAny(), KeyInfoType.class);
        if (null != keyInfoType) {
            for (Object keyInfoContent : keyInfoType.getContent()) {
                X509DataType x509DataType = extractType(keyInfoContent, X509DataType.class);
                if (null != x509DataType) {
                    for (Object x509Object : x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName()) {
                        x509 = extractType(x509Object, byte[].class);
                        if (null != x509) {
                            break;
                        }//from  w ww . ja  va 2  s .c o m
                    }
                }
            }
        } else {
            Element elementNSImpl = (Element) useKeyType.getAny();
            NodeList x509CertData = elementNSImpl.getElementsByTagNameNS(Constants.SignatureSpecNS,
                    Constants._TAG_X509CERTIFICATE);
            if (x509CertData != null && x509CertData.getLength() > 0) {
                x509 = Base64.decodeBase64(x509CertData.item(0).getTextContent().getBytes());
            }
        }
        if (x509 != null) {
            CertificateFactory cf = CertificateFactory.getInstance(X_509);
            Certificate certificate = cf.generateCertificate(new ByteArrayInputStream(x509));
            X509Certificate x509Cert = (X509Certificate) certificate;
            return x509Cert;
        }

    }
    return null;
}

From source file:org.apache.geode.management.internal.configuration.utils.XmlUtilsJUnitTest.java

/**
 * Test method for {@link XmlUtils#querySingleElement(Node, String, XPathContext)}.
 *///from   w ww  . j a  v  a  2s . co m
@Test
public void testQuerySingleElement() throws Exception {
    final Document doc = XmlUtils.createDocumentFromReader(new InputStreamReader(
            getClass().getResourceAsStream("XmlUtilsJUnitTest.testQuerySingleElement.xml")));
    final Element root = doc.getDocumentElement();
    final String cacheNamespace = "http://geode.apache.org/schema/cache";
    final XPathContext cacheXPathContext = new XPathContext("cache", cacheNamespace);

    // There are mulitple region elements, this should get the first one.
    final NodeList n1 = XmlUtils.query(root, "//cache:region[1]", cacheXPathContext);
    final Node e1 = XmlUtils.querySingleElement(root, "//cache:region", cacheXPathContext);
    assertNotNull(e1);
    assertSame(root.getElementsByTagNameNS(cacheNamespace, "region").item(0), e1);
    assertSame(n1.item(0), e1);

    // This should get the second region with name "r2".
    final NodeList n2 = XmlUtils.query(root, "//cache:region[2]", cacheXPathContext);
    final Node e2 = XmlUtils.querySingleElement(root, "//cache:region[@name='r2']", cacheXPathContext);
    assertNotNull(e2);
    assertSame(root.getElementsByTagNameNS(cacheNamespace, "region").item(1), e2);
    assertSame(n2.item(0), e2);

    // This should get none since there is no r3.
    final Node e3 = XmlUtils.querySingleElement(root, "//cache:region[@name='r3']", cacheXPathContext);
    assertNull(e3);

    // Query attributes (not Elements)
    final String q4 = "//cache:region/@name";
    final NodeList n4 = XmlUtils.query(root, q4, cacheXPathContext);
    assertEquals(2, n4.getLength());
    assertEquals(Node.ATTRIBUTE_NODE, n4.item(0).getNodeType());
    // This should get none since path is to an attribute.
    try {
        XmlUtils.querySingleElement(root, q4, cacheXPathContext);
        fail("Expected XPathExpressionException");
    } catch (XPathExpressionException expected) {
        // ignore
    }
}

From source file:org.apache.juddi.v3.client.cryptor.DigSigUtil.java

private boolean verifySignature(Element element, PublicKey validatingKey,
        AtomicReference<String> OutReadableErrorMessage) {
    if (OutReadableErrorMessage == null) {
        OutReadableErrorMessage = new AtomicReference<String>();
    }//from w  w  w.j  a  v  a 2 s .co m
    XMLSignatureFactory fac = initXMLSigFactory();
    NodeList nl = element.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    if (nl.getLength() == 0) {
        throw new RuntimeException("Cannot find Signature element");
    }
    DOMValidateContext valContext = new DOMValidateContext(validatingKey, nl.item(0));
    try {
        valContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
        XMLSignature signature = fac.unmarshalXMLSignature(valContext);
        boolean coreValidity = signature.validate(valContext);
        // Check core validation status.
        if (coreValidity == false) {
            logger.warn("Signature failed core validation");
            boolean sv = signature.getSignatureValue().validate(valContext);
            logger.debug("signature validation status: " + sv);
            OutReadableErrorMessage
                    .set("signature validation failed: " + sv + "." + OutReadableErrorMessage.get());
            // Check the validation status of each Reference.
            @SuppressWarnings("unchecked")
            Iterator<Reference> i = signature.getSignedInfo().getReferences().iterator();
            //System.out.println("---------------------------------------------");
            for (int j = 0; i.hasNext(); j++) {
                Reference ref = (Reference) i.next();
                boolean refValid = ref.validate(valContext);
                logger.debug(j);
                logger.debug("ref[" + j + "] validity status: " + refValid);
                if (!refValid) {
                    OutReadableErrorMessage
                            .set("signature reference " + j + " invalid. " + OutReadableErrorMessage.get());
                }
                logger.debug("Ref type: " + ref.getType() + ", URI: " + ref.getURI());
                for (Object xform : ref.getTransforms()) {
                    logger.debug("Transform: " + xform);
                }
                String calcDigValStr = digestToString(ref.getCalculatedDigestValue());
                String expectedDigValStr = digestToString(ref.getDigestValue());
                logger.warn("    Calc Digest: " + calcDigValStr);
                logger.warn("Expected Digest: " + expectedDigValStr);
                if (!calcDigValStr.equalsIgnoreCase(expectedDigValStr)) {
                    OutReadableErrorMessage.set(
                            "digest mismatch for signature ref " + j + "." + OutReadableErrorMessage.get());
                }
            }
        } else {
            logger.info("Signature passed core validation");
        }
        return coreValidity;
    } catch (Exception e) {
        OutReadableErrorMessage
                .set("signature validation failed: " + e.getMessage() + OutReadableErrorMessage.get());
        logger.fatal(e);
        return false;
    }
}

From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java

public static NodeList getNodes(Element element, String[] nameSpaces, String localName) {
    NodeList nodeListResult = null;
    for (String namespace : nameSpaces) {
        if ((nodeListResult = element.getElementsByTagNameNS(namespace, localName)) != null
                && nodeListResult.getLength() > 0) {
            return nodeListResult;
        }/*from w ww . j a va  2  s  .co  m*/
    }
    return null;
}

From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java

public static NodeList getNodes(Element element, String nameSpace, String localName) {
    return element.getElementsByTagNameNS(nameSpace, localName);
}

From source file:org.apache.rave.portal.service.impl.DefaultOmdlService.java

private void parseOmdlFile(Document xml, OmdlInputAdapter omdlInputAdapter) throws BadOmdlXmlFormatException {
    Element rootEl = xml.getDocumentElement();
    String rootNodename = rootEl.getNodeName();
    String namespace = rootEl.getNamespaceURI();
    if (rootNodename != WORKSPACE) {
        throw new BadOmdlXmlFormatException("Root node must be <" + WORKSPACE + ">");
    }//from  ww  w  . j  a v a2 s . co m
    // TODO - which is it - spec examples show both?
    if (namespace != NAMESPACE && namespace != NAMESPACE + "/") {
        throw new BadOmdlXmlFormatException("Default xml namespace must be " + NAMESPACE);
    }
    //child <identifier> - omit
    //child <goal> - omit
    //child <status> - omit
    //child <description> - omit
    //child <creator> - omit
    //child <date> - omit

    // Try to get the page name (title in omdl)
    String title = null;
    NodeList nodeList = rootEl.getElementsByTagNameNS(namespace, TITLE);
    if (nodeList.getLength() > 0) {
        Node node = rootEl.getElementsByTagNameNS(namespace, TITLE).item(0);
        if (node.getTextContent() != null) {
            title = node.getTextContent();
        }
    }
    // store this if found, although at present it will be overwritten by the users page name
    omdlInputAdapter.setName(title);

    String layoutCode = null;
    // Try to get the layoutCode
    nodeList = rootEl.getElementsByTagNameNS(namespace, LAYOUT);
    if (nodeList.getLength() > 0) {
        Node node = rootEl.getElementsByTagNameNS(namespace, LAYOUT).item(0);
        if (node.getTextContent() != null) {
            layoutCode = node.getTextContent();
        }
    }
    // Next try to find all the <app> elements (widgets)
    nodeList = rootEl.getElementsByTagNameNS(namespace, APP);
    if (nodeList != null && nodeList.getLength() > 0) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Element appElement = (Element) nodeList.item(i);
            String id = appElement.getAttribute(ID_ATTRIBUTE);
            if (id != null) {
                String position = null;
                String hrefLink = null;
                String hrefType = null;
                Node positionNode = appElement.getElementsByTagNameNS(namespace, POSITION).item(0);
                if (positionNode != null) {
                    Element positionElement = (Element) positionNode;
                    position = positionElement.getTextContent();
                }
                Node linkNode = appElement.getElementsByTagNameNS(namespace, LINK).item(0);
                if (linkNode != null) {
                    Element linkElement = (Element) linkNode;
                    hrefLink = linkElement.getAttribute(HREF);
                    hrefType = linkElement.getAttribute(TYPE_ATTRIBUTE);
                }
                omdlInputAdapter.addToAppMap(new OmdlWidgetReference(id, hrefLink, hrefType), position);
            }
        }
    }
    // store the string found in the xml file
    omdlInputAdapter.setLayoutCode(layoutCode);
    // update this string into a RAVE layout
    omdlInputAdapter.setLayoutCode(OmdlModelUtils.getRaveLayoutForImport(omdlInputAdapter));
}

From source file:org.apache.servicemix.jbi.deployer.utils.ManagementSupport.java

private static Element getChildElement(Element element, String name) {
    NodeList l = element.getElementsByTagNameNS(HTTP_JAVA_SUN_COM_XML_NS_JBI_MANAGEMENT_MESSAGE, name);
    return (Element) l.item(0);
}

From source file:org.apache.servicemix.jbi.runtime.impl.AbstractComponentContext.java

/**
 * Resolve a standard EPR understood by ServiceMix container.
 * Currently, the supported syntax is the WSA one, the address uri
 * being parsed with the following possiblities:
 *    jbi:endpoint:service-namespace/service-name/endpoint
 *    jbi:endpoint:service-namespace:service-name:endpoint
 *
 * The full EPR will look like:/*from  ww  w  .ja  v a  2s.c o  m*/
 *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
 *     <wsa:Address>jbi:endpoint:http://foo.bar.com/service/endpoint</wsa:Address>
 *   </epr>
 *
 * BCs should also be able to resolve such EPR but using their own URI parsing,
 * for example:
 *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
 *     <wsa:Address>http://foo.bar.com/myService?http.soap=true</wsa:Address>
 *   </epr>
 *
 * or
 *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
 *     <wsa:Address>jms://activemq/queue/FOO.BAR?persistent=true</wsa:Address>
 *   </epr>
 *
 * Note that the separator should be same as the one used in the namespace
 * depending on the namespace:
 *     http://foo.bar.com  => '/'
 *     urn:foo:bar         => ':'
 *
 * The syntax is the same as the one that can be used to specifiy a target
 * for a JBI exchange with the restriction that it only allows the
 * endpoint subprotocol to be used.
 *
 * @param epr the xml fragment to resolve
 * @return the resolved endpoint or <code>null</code>
 */
public ServiceEndpoint resolveStandardEPR(DocumentFragment epr) {
    try {
        NodeList children = epr.getChildNodes();
        for (int i = 0; i < children.getLength(); ++i) {
            Node n = children.item(i);
            if (n.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            Element elem = (Element) n;
            String[] namespaces = new String[] { WSAddressingConstants.WSA_NAMESPACE_200508,
                    WSAddressingConstants.WSA_NAMESPACE_200408, WSAddressingConstants.WSA_NAMESPACE_200403,
                    WSAddressingConstants.WSA_NAMESPACE_200303 };
            NodeList nl = null;
            for (String ns : namespaces) {
                NodeList tnl = elem.getElementsByTagNameNS(ns, WSAddressingConstants.EL_ADDRESS);
                if (tnl.getLength() == 1) {
                    nl = tnl;
                    break;
                }
            }
            if (nl != null) {
                Element address = (Element) nl.item(0);
                String uri = DOMUtil.getElementText(address);
                if (uri != null) {
                    uri = uri.trim();
                    if (uri.startsWith("endpoint:")) {
                        uri = uri.substring("endpoint:".length());
                        String[] parts = URIResolver.split3(uri);
                        return getEndpoint(new QName(parts[0], parts[1]), parts[2]);
                    } else if (uri.startsWith("service:")) {
                        uri = uri.substring("service:".length());
                        String[] parts = URIResolver.split2(uri);
                        return getEndpoint(new QName(parts[0], parts[1]), parts[1]);
                    }
                }
                // TODO should we support interface: and operation: here?
            }
        }
    } catch (Exception e) {
        LOG.debug("Unable to resolve EPR: " + e);
    }
    return null;
}

From source file:org.apache.webdav.lib.methods.LockMethod.java

/**
 * Parse response./*  w ww . ja v  a  2 s  .c  o  m*/
 *
 * @param input Input stream
 */
public void parseResponse(InputStream input, HttpState state, HttpConnection conn)
        throws IOException, HttpException {
    int status = getStatusLine().getStatusCode();
    if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_MULTI_STATUS) {

        parseXMLResponse(input);

        NodeList list = getResponseDocument().getDocumentElement().getElementsByTagNameNS("DAV:", "locktoken");

        if (list.getLength() == 1) {
            Element locktoken = (Element) list.item(0);
            NodeList list2 = locktoken.getElementsByTagNameNS("DAV:", "href");
            if (list2.getLength() == 1) {
                this.lockToken = DOMUtils.getTextValue(list2.item(0));
                if (state instanceof WebdavState) {
                    /* 
                     * lockMethod/unlockMethod take unescaped URIs but LockMathod.getPath()
                     * func returns an escaped URI so searching for the lock by path name in 
                     * the state object doesn't work. Convert escaped back to unescaped.
                     */
                    ((WebdavState) state).addLock(URIUtil.decode(getPath()), this.lockToken);
                }
            }
        }

        list = getResponseDocument().getDocumentElement().getElementsByTagNameNS("DAV:", "owner");

        if (list.getLength() == 1) {
            Element owner = (Element) list.item(0);

            this.owner = DOMUtils.getTextValue(owner);
        }
    }
}