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:com.connexta.arbitro.ctx.RequestCtxFactory.java

/**
 *  Returns instance of <code>AbstractRequestCtx</code> based one the XACML version.
 *
 * @param root  the node to parse for the <code>AbstractRequestCtx</code>
 * @return <code>AbstractRequestCtx</code> object
 * @throws ParsingException  if the DOM node is invalid
 *///ww  w .jav  a  2s  .co  m
public AbstractRequestCtx getRequestCtx(Node root) throws ParsingException {

    String requestCtxNs = root.getNamespaceURI();

    if (requestCtxNs != null) {
        if (XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER.equals(requestCtxNs.trim())) {
            return RequestCtx.getInstance(root);
        } else if (XACMLConstants.REQUEST_CONTEXT_1_0_IDENTIFIER.equals(requestCtxNs.trim())
                || XACMLConstants.REQUEST_CONTEXT_2_0_IDENTIFIER.equals(requestCtxNs.trim())) {
            return com.connexta.arbitro.ctx.xacml2.RequestCtx.getInstance(root);
        } else {
            throw new ParsingException("Invalid namespace in XACML request");
        }
    } else {
        log.warn("No Namespace defined in XACML request and Assume as XACML 3.0");
        return RequestCtx.getInstance(root);
    }
}

From source file:com.connexta.arbitro.ctx.RequestCtxFactory.java

/**
 *  Returns instance of <code>AbstractRequestCtx</code> based one the XACML version.
 *
 * @param request  the String to parse for the <code>AbstractRequestCtx</code>
 * @return <code>AbstractRequestCtx</code> object
 * @throws ParsingException  if the request is invalid
 *//*from w  w  w .  j  a v  a 2s.c  o  m*/
public AbstractRequestCtx getRequestCtx(String request) throws ParsingException {

    Node root = getXacmlRequest(request);
    String requestCtxNs = root.getNamespaceURI();

    if (requestCtxNs != null) {
        if (XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER.equals(requestCtxNs.trim())) {
            return RequestCtx.getInstance(root);
        } else if (XACMLConstants.REQUEST_CONTEXT_1_0_IDENTIFIER.equals(requestCtxNs.trim())
                || XACMLConstants.REQUEST_CONTEXT_2_0_IDENTIFIER.equals(requestCtxNs.trim())) {
            return com.connexta.arbitro.ctx.xacml2.RequestCtx.getInstance(root);
        } else {
            throw new ParsingException("Invalid namespace in XACML request");
        }
    } else {
        log.warn("No Namespace defined in XACML request and Assume as XACML 3.0");
        return RequestCtx.getInstance(root);
    }
}

From source file:nl.b3p.kaartenbalie.service.requesthandler.WMSRequestHandler.java

private static void prefixElements(Document source, Document destination, String spAbbr) {
    Element root_source = source.getDocumentElement();
    NodeList nodelist_source = root_source.getChildNodes();
    int size_source = nodelist_source.getLength();

    for (int i = 0; i < size_source; i++) {
        Node node_source = nodelist_source.item(i);

        if (node_source instanceof Element) {
            Element element_source = (Element) node_source;
            String tagName = element_source.getTagName();

            if (!tagName.equalsIgnoreCase("ServiceException")) {
                Node importedNode = destination.importNode(element_source, true);
                Node newNode = destination.renameNode(importedNode, importedNode.getNamespaceURI(),
                        OGCCommunication.attachSp(spAbbr, tagName));

                Element root_destination = destination.getDocumentElement();
                root_destination.appendChild(newNode);
            }/*from   ww  w  .  j  a  va  2 s  .  co  m*/
        }
    }
}

From source file:com.connexta.arbitro.ctx.RequestCtxFactory.java

/**
 *  Returns instance of <code>AbstractRequestCtx</code> based one the XACML version.
 *
 * Creates a new <code>RequestCtx</code> by parsing XML from an input stream. Note that this a
 * convenience method, and it will not do schema validation by default. You should be parsing
 * the data yourself, and then providing the root node to the other <code>getInstance</code>
 * method. If you use this convenience method, you probably want to turn on validation by
 * setting the context schema file (see the programmer guide for more information on this).
 *
 * @param input input a stream providing the XML data
 * @return <code>AbstractRequestCtx</code> object
 * @throws ParsingException  if the DOM node is invalid
 *///  ww w  .j  a v  a  2s. c  o  m
public AbstractRequestCtx getRequestCtx(InputStream input) throws ParsingException {

    Node root = InputParser.parseInput(input, "Request");
    String requestCtxNs = root.getNamespaceURI();

    if (requestCtxNs != null) {
        if (XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER.equals(requestCtxNs.trim())) {
            return RequestCtx.getInstance(root);
        } else if (XACMLConstants.REQUEST_CONTEXT_1_0_IDENTIFIER.equals(requestCtxNs.trim())
                || XACMLConstants.REQUEST_CONTEXT_2_0_IDENTIFIER.equals(requestCtxNs.trim())) {
            return com.connexta.arbitro.ctx.xacml2.RequestCtx.getInstance(root);
        } else {
            throw new ParsingException("Invalid namespace in XACML request");
        }
    } else {
        log.warn("No Namespace defined in XACML request and Assume as XACML 3.0");
        return RequestCtx.getInstance(root);
    }
}

From source file:org.echocat.jemoni.carbon.spring.Jmx2CarbonBridgeDefinitionParser.java

@Override
protected void doParse(@Nonnull Element element, @Nonnull BeanDefinitionBuilder bean) {
    final String jmxRegistryRef = element.getAttribute(JMX_REGISTRY_REF_ATTRIBUTE);
    final String mBeanServerRef = element.getAttribute(MBEAN_SERVER_REF_ATTRIBUTE);
    if (hasText(jmxRegistryRef)) {
        if (hasText(mBeanServerRef)) {
            throw new IllegalArgumentException("The " + JMX_REGISTRY_REF_ATTRIBUTE + " and "
                    + MBEAN_SERVER_REF_ATTRIBUTE + " attributes could not be used at the same time.");
        }/* w w  w  .  j  a  v  a  2 s.co m*/
        bean.addConstructorArgReference(jmxRegistryRef);
    } else if (hasText(mBeanServerRef)) {
        bean.addConstructorArgReference(mBeanServerRef);
    }
    bean.addConstructorArgReference(element.getAttribute(WRITER_REF_ATTRIBUTE));

    final String classLoaderRef = element.getAttribute(CLASS_LOADER_REF_ATTRIBUTE);
    if (hasText(classLoaderRef)) {
        bean.addPropertyReference("classLoader", classLoaderRef);
    }

    final String pathPrefix = element.getAttribute(PATH_PREFIX_ATTRIBUTE);
    if (hasText(pathPrefix)) {
        bean.addPropertyValue("pathPrefix", pathPrefix);
    }

    Configuration configuration = null;
    final NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        final Node child = children.item(i);
        if (CONFIGURATION_ELEMENT.equals(child.getLocalName())
                && SCHEMA_NAMESPACE.equals(child.getNamespaceURI())) {
            configuration = unmarshall(child);
        }
    }

    final String rulesRef = element.getAttribute(CONFIGURATION_REF_ATTRIBUTE);
    if (hasText(rulesRef)) {
        if (configuration != null) {
            throw new IllegalArgumentException("The " + CONFIGURATION_ELEMENT + " element and "
                    + CONFIGURATION_REF_ATTRIBUTE + " attribute could not be used at the same time.");
        }
        bean.addPropertyReference("configuration", rulesRef);
    } else {
        bean.addPropertyValue("configuration", configuration);
    }
}

From source file:net.bpelunit.test.unit.TestSOAPEncoder.java

@Test
public void testEncodeRPCLiteResponseUnwrapped() throws Exception {
    Element literal = TestUtil.readLiteralData(PATH_TO_FILES + "rpclit1.xmlfrag");
    SOAPOperationCallIdentifier operation = TestUtil.getCall(PATH_TO_FILES, PARTNER_WSDL, PARTNER_OPERATION,
            SOAPOperationDirectionIdentifier.OUTPUT);
    ISOAPEncoder encoder = new RPCLiteralEncoder();
    SOAPMessage message = encoder.construct(operation, literal, BPELUnitConstants.SOAP_FAULT_CODE_CLIENT,
            BPELUnitConstants.SOAP_FAULT_DESCRIPTION);

    final Node firstChild = message.getSOAPBody().getFirstChild();
    assertEquals(XMLConstants.NULL_NS_URI, firstChild.getNamespaceURI());
    assertEquals(operation.getName() + "Response", firstChild.getLocalName());
}

From source file:org.brekka.phalanx.webservices.SoapExceptionResolver.java

private void resolveDetail(final MessageContext messageContext, final Throwable ex, final SoapFault soapFault) {
    SoapMessage request = (SoapMessage) messageContext.getRequest();
    DOMSource payloadSource = (DOMSource) request.getPayloadSource();
    Node node = payloadSource.getNode();
    String localName = node.getLocalName();
    String namespace = node.getNamespaceURI();
    String faultName = StringUtils.removeEnd(localName, "Request") + "Fault";
    QName faultQName = new QName(namespace, faultName);

    SchemaType schemaType = XmlBeans.getContextTypeLoader().findDocumentType(faultQName);
    if (schemaType != null) {
        try {// w  w  w  . jav  a 2  s . c om
            XmlObject faultDocument = prepareFaultDetail(messageContext, faultName, schemaType, ex);
            if (faultDocument != null) {
                // Add detailed
                StringWriter writer = new StringWriter();
                faultDocument.save(writer, SAVE_OPTIONS);
                Transformer transformer = transformerFactory.newTransformer();

                SoapFaultDetail faultDetail = soapFault.addFaultDetail();
                Result result = faultDetail.getResult();
                transformer.transform(new StreamSource(new StringReader(writer.toString())), result);
            }
        } catch (Exception e) {
            if (log.isWarnEnabled()) {
                log.warn(format("Failed to create custom fault message of type '%s'", schemaType), e);
            }
        }
    }
}

From source file:org.cleverbus.core.common.exception.AbstractSoapExceptionFilter.java

/**
 * Gets the exception name./*from w  w  w. ja v  a2  s. co m*/
 *
 * @param detailNode the fault detail node
 * @return exception fully qualified name
 */
protected QName getExceptionName(Node detailNode) {
    Node exNode = getFirstElm(detailNode);

    return new QName(exNode.getNamespaceURI(), exNode.getLocalName());
}

From source file:org.cleverbus.core.common.ws.HeaderAndPayloadValidatingInterceptor.java

/**
 * Checks if input request should be ignored from header checking.
 *
 * @param messageContext the msg context
 * @return {@code true} when input request should be ignored, otherwise {@code false}
 */// www.j  ava  2s  . c  o m
private boolean ignoreRequest(MessageContext messageContext) {
    Node reqNode = ((DOMSource) messageContext.getRequest().getPayloadSource()).getNode();
    QName reqName = new QName(reqNode.getNamespaceURI(), reqNode.getLocalName());
    return ignoreRequests.contains(reqName);
}

From source file:Main.java

/**
 * Checks if two Nodes are equal<br>
 * <p/>/*  w w w.  j  a  va2 s. c om*/
 * Compares Nodes just by their Name, Type, Value and Namespace generically
 */

public static boolean nodesEqual(Node node1, Node node2, boolean ignoreWhitespace)

{

    if ((node1 == null) || (node2 == null))

        return false;

    /*   
            
    if (node1.getNodeType() == node2.getNodeType() &&
            
       (areNullorEqual(node1.getNodeValue(), node2.getNodeValue(), ignoreWhitespace, false)) &&
            
       (areNullorEqual(node1.getLocalName(), node2.getLocalName(), ignoreWhitespace, false)) &&
            
       (areNullorEqual(node1.getNamespaceURI(), node2.getNamespaceURI(), ignoreWhitespace, false)) &&
            
       (areNullorEqual(node1.getNodeName(), node2.getNodeName(), ignoreWhitespace, false)))
            
        return true;
            
     */

    if (areNonNullAndEqual(node1.getNamespaceURI(), node2.getNamespaceURI()))

    {

        if (node1.getNodeType() == node2.getNodeType() &&

                (areNullorEqual(node1.getNodeValue(), node2.getNodeValue(), ignoreWhitespace, false)) &&

                (areNullorEqual(node1.getLocalName(), node2.getLocalName(), ignoreWhitespace, false)))

            return true;

    } else if ((node1.getNamespaceURI() == null) && (node2.getNamespaceURI() == null))

    {

        //System.out.println("===> Both Namespace URIs are null");

        if ((node1.getNodeType() == node2.getNodeType()) &&

                (areNullorEqual(node1.getNodeValue(), node2.getNodeValue(), ignoreWhitespace, false)) &&

                (areNullorEqual(node1.getNodeName(), node2.getNodeName(), ignoreWhitespace, false)))

            return true;

    }

    return false;

}