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:org.exist.dom.ElementImpl.java

/**
 * Returns a list of all attribute nodes in attrs that are already present
 * in the current element./*  ww w .  ja  v  a2s.  c  o  m*/
 *
 * @param attrs
 * @return The attributes list
 * @throws DOMException
 */
private NodeList findDupAttributes(NodeList attrs) throws DOMException {
    NodeListImpl dupList = null;
    final NamedNodeMap map = getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        final Node attr = attrs.item(i);
        //Workaround: Xerces sometimes returns null for getLocalName() !!!!
        String localName = attr.getLocalName();
        if (localName == null) {
            localName = attr.getNodeName();
        }
        final Node duplicate = map.getNamedItemNS(attr.getNamespaceURI(), localName);
        if (duplicate != null) {
            if (dupList == null) {
                dupList = new NodeListImpl();
            }
            dupList.add(duplicate);
        }
    }
    return dupList;
}

From source file:org.exist.http.SOAPServer.java

public void doPost(DBBroker broker, HttpServletRequest request, HttpServletResponse response, String path)
        throws BadRequestException, PermissionDeniedException, NotFoundException, IOException {
    /*//from ww w  .java 2  s  .co  m
     * Example incoming SOAP Request
     * 
       <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
     <SOAP-ENV:Header/>
     <SOAP-ENV:Body>
         <echo xmlns="http://localhost:8080/exist/servlet/db/echo.xqws">
             <arg1>adam</arg1>
         </echo>
     </SOAP-ENV:Body>
       </SOAP-ENV:Envelope>
     */

    // 1) Read the incoming SOAP request
    final InputStream is = request.getInputStream();
    final byte[] buf = new byte[request.getContentLength()];
    int bytes = 0;
    int offset = 0;
    final int max = 4096;
    while ((bytes = is.read(buf, offset, max)) != -1) {
        offset += bytes;
    }

    // 2) Create an XML Document from the SOAP Request
    Document soapRequest = null;
    try {
        soapRequest = BuildXMLDocument(buf);
    } catch (final Exception e) {
        LOG.debug(e.getMessage());
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writeResponse(response, formatXPathException(null, path, new XPathException(
                "Unable to construct an XML document from the SOAP Request, probably an invalid request: "
                        + e.getMessage(),
                e)), "text/html", ENCODING);
        return;
    }

    try {
        final StringWriter out = new StringWriter();
        broker.getSerializer().serialize((ElementImpl) soapRequest.getDocumentElement(), out);
        //System.out.println(out.toString());

    } catch (final SAXException e) {
        LOG.error("Error during serialization.", e);
    }

    // 3) Validate the SOAP Request 
    //TODO: validate the SOAP Request

    // 4) Extract the function call from the SOAP Request
    final NodeList nlBody = soapRequest.getDocumentElement().getElementsByTagNameNS(Namespaces.SOAP_ENVELOPE,
            "Body");
    if (nlBody == null) {
        LOG.error("Style Parameter wrapped not supported yet");
    }

    final Node nSOAPBody = nlBody.item(0); // DW: can return NULL ! case: style ParameterWrapped
    final NodeList nlBodyChildren = nSOAPBody.getChildNodes();
    Node nSOAPFunction = null;
    for (int i = 0; i < nlBodyChildren.getLength(); i++) {
        Node bodyChild = nlBodyChildren.item(i);
        if (bodyChild.getNodeType() == Node.ELEMENT_NODE) {
            nSOAPFunction = bodyChild;
            break;
        }
    }

    // Check the namespace for the function in the SOAP document is the same as the request path?
    final String funcNamespace = nSOAPFunction.getNamespaceURI();

    if (funcNamespace != null) {
        if (!funcNamespace.equals(request.getRequestURL().toString())) {
            //function in SOAP request has an invalid namespace
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            writeResponse(response, "SOAP Function call has invalid namespace, got: " + funcNamespace
                    + " but expected: " + request.getRequestURL().toString(), "text/html", ENCODING);
            return;
        }
    } else {
        //function in SOAP request has no namespace
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writeResponse(response,
                "SOAP Function call has no namespace, expected: " + request.getRequestURL().toString(),
                "text/html", ENCODING);
        return;
    }

    // 4.5) Detemine encoding style
    final String encodingStyle = ((org.w3c.dom.Element) nSOAPFunction).getAttributeNS(Namespaces.SOAP_ENVELOPE,
            "encodingStyle");
    boolean isRpcEncoded = (encodingStyle != null
            && "http://schemas.xmlsoap.org/soap/encoding/".equals(encodingStyle));

    // As this detection is a "quirk" which is not always available, let's use a better one...
    if (!isRpcEncoded) {
        final NodeList nlSOAPFunction = nSOAPFunction.getChildNodes();
        for (int i = 0; i < nlSOAPFunction.getLength(); i++) {
            final Node functionChild = nlSOAPFunction.item(i);
            if (functionChild.getNodeType() == Node.ELEMENT_NODE) {
                if (((org.w3c.dom.Element) functionChild).hasAttributeNS(Namespaces.SCHEMA_INSTANCE_NS,
                        "type")) {
                    isRpcEncoded = true;
                    break;
                }
            }
        }
    }

    // 5) Execute the XQWS function indicated by the SOAP request  
    try {
        //Get the internal description for the function requested by SOAP (should be in the cache)
        final XQWSDescription description = getXQWSDescription(broker, path, request);

        //Create an XQuery to call the XQWS function
        final CompiledXQuery xqCallXQWS = XQueryExecuteXQWSFunction(broker, nSOAPFunction, description, request,
                response);

        //xqCallXQWS
        final XQuery xqueryService = broker.getXQueryService();
        final Sequence xqwsResult = xqueryService.execute(xqCallXQWS, null);

        // 6) Create a SOAP Response describing the Result
        String funcName = nSOAPFunction.getLocalName();
        if (funcName == null) {
            funcName = nSOAPFunction.getNodeName();
        }
        final byte[] result = description.getSOAPResponse(funcName, xqwsResult, request, isRpcEncoded);

        // 7) Send the SOAP Response to the http servlet response
        response.setContentType(MimeType.XML_LEGACY_TYPE.getName());
        final ServletOutputStream os = response.getOutputStream();
        final BufferedOutputStream bos = new BufferedOutputStream(os);
        bos.write(result);
        bos.close();
        os.close();
    } catch (final XPathException xpe) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writeResponse(response, formatXPathException(null, path, xpe), "text/html", ENCODING);
    } catch (final SAXException saxe) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writeResponse(response,
                formatXPathException(null, path, new XPathException(
                        "SAX exception while transforming node: " + saxe.getMessage(), saxe)),
                "text/html", ENCODING);
    } catch (final TransformerConfigurationException tce) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writeResponse(response,
                formatXPathException(null, path,
                        new XPathException("SAX exception while transforming node: " + tce.getMessage(), tce)),
                "text/html", ENCODING);
    }
}

From source file:org.exist.http.urlrewrite.XQueryURLRewrite.java

@Override
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws IOException, ServletException {
    if (rewriteConfig == null) {
        configure();/*from   w  w  w . ja v  a2 s .  c  o  m*/
        rewriteConfig = new RewriteConfig(this);
    }

    final long start = System.currentTimeMillis();
    final HttpServletRequest request = servletRequest;
    final HttpServletResponse response = servletResponse;

    if (LOG.isTraceEnabled()) {
        LOG.trace(request.getRequestURI());
    }
    final Descriptor descriptor = Descriptor.getDescriptorSingleton();
    if (descriptor != null && descriptor.requestsFiltered()) {
        final String attr = (String) request.getAttribute("XQueryURLRewrite.forwarded");
        if (attr == null) {
            //                request = new HttpServletRequestWrapper(request, /*formEncoding*/ "utf-8" );
            //logs the request if specified in the descriptor
            descriptor.doLogRequestInReplayLog(request);

            request.setAttribute("XQueryURLRewrite.forwarded", "true");
        }
    }

    Subject user = defaultUser;

    Subject requestUser = HttpAccount.getUserFromServletRequest(request);
    if (requestUser != null) {
        user = requestUser;
    } else {
        // Secondly try basic authentication
        final String auth = request.getHeader("Authorization");
        if (auth != null) {
            requestUser = authenticator.authenticate(request, response);
            if (requestUser != null) {
                user = requestUser;
            }
        }
    }

    try {
        configure();
        //checkCache(user);

        final RequestWrapper modifiedRequest = new RequestWrapper(request);
        final URLRewrite staticRewrite = rewriteConfig.lookup(modifiedRequest);
        if (staticRewrite != null && !staticRewrite.isControllerForward()) {
            modifiedRequest.setPaths(staticRewrite.resolve(modifiedRequest), staticRewrite.getPrefix());

            if (LOG.isTraceEnabled()) {
                LOG.trace("Forwarding to target: " + staticRewrite.getTarget());
            }
            staticRewrite.doRewrite(modifiedRequest, response);
        } else {

            if (LOG.isTraceEnabled()) {
                LOG.trace("Processing request URI: " + request.getRequestURI());
            }
            if (staticRewrite != null) {
                // fix the request URI
                staticRewrite.updateRequest(modifiedRequest);
            }

            // check if the request URI is already in the url cache
            ModelAndView modelView = getFromCache(request.getHeader("Host") + request.getRequestURI(), user);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Checked cache for URI: " + modifiedRequest.getRequestURI() + " original: "
                        + request.getRequestURI());
            }
            // no: create a new model and view configuration
            if (modelView == null) {
                modelView = new ModelAndView();
                // Execute the query
                Sequence result = Sequence.EMPTY_SEQUENCE;
                DBBroker broker = null;
                try {
                    broker = pool.get(user);
                    modifiedRequest.setAttribute(RQ_ATTR_REQUEST_URI, request.getRequestURI());

                    final Properties outputProperties = new Properties();

                    outputProperties.setProperty(OutputKeys.INDENT, "yes");
                    outputProperties.setProperty(OutputKeys.ENCODING, "UTF-8");
                    outputProperties.setProperty(OutputKeys.MEDIA_TYPE, MimeType.XML_TYPE.getName());

                    result = runQuery(broker, modifiedRequest, response, modelView, staticRewrite,
                            outputProperties);

                    logResult(broker, result);

                    if (response.isCommitted()) {
                        return;
                    }

                    // process the query result
                    if (result.getItemCount() == 1) {
                        final Item resource = result.itemAt(0);
                        if (!Type.subTypeOf(resource.getType(), Type.NODE)) {
                            throw new ServletException(
                                    "XQueryURLRewrite: urlrewrite query should return an element!");
                        }
                        Node node = ((NodeValue) resource).getNode();
                        if (node.getNodeType() == Node.DOCUMENT_NODE) {
                            node = ((Document) node).getDocumentElement();
                        }
                        if (node.getNodeType() != Node.ELEMENT_NODE) {
                            //throw new ServletException("Redirect XQuery should return an XML element!");
                            response(broker, response, outputProperties, result);
                            return;
                        }
                        Element elem = (Element) node;
                        if (!(Namespaces.EXIST_NS.equals(elem.getNamespaceURI()))) {
                            response(broker, response, outputProperties, result);
                            return;
                            //                            throw new ServletException("Redirect XQuery should return an element in namespace " + Namespaces.EXIST_NS);
                        }

                        if (Namespaces.EXIST_NS.equals(elem.getNamespaceURI())
                                && "dispatch".equals(elem.getLocalName())) {
                            node = elem.getFirstChild();
                            while (node != null) {
                                if (node.getNodeType() == Node.ELEMENT_NODE
                                        && Namespaces.EXIST_NS.equals(node.getNamespaceURI())) {
                                    final Element action = (Element) node;
                                    if ("view".equals(action.getLocalName())) {
                                        parseViews(modifiedRequest, action, modelView);
                                    } else if ("error-handler".equals(action.getLocalName())) {
                                        parseErrorHandlers(modifiedRequest, action, modelView);
                                    } else if ("cache-control".equals(action.getLocalName())) {
                                        final String option = action.getAttribute("cache");
                                        modelView.setUseCache("yes".equals(option));
                                    } else {
                                        final URLRewrite urw = parseAction(modifiedRequest, action);
                                        if (urw != null) {
                                            modelView.setModel(urw);
                                        }
                                    }
                                }
                                node = node.getNextSibling();
                            }
                            if (modelView.getModel() == null) {
                                modelView.setModel(new PassThrough(config, elem, modifiedRequest));
                            }
                        } else if (Namespaces.EXIST_NS.equals(elem.getNamespaceURI())
                                && "ignore".equals(elem.getLocalName())) {
                            modelView.setModel(new PassThrough(config, elem, modifiedRequest));
                            final NodeList nl = elem.getElementsByTagNameNS(Namespaces.EXIST_NS,
                                    "cache-control");
                            if (nl.getLength() > 0) {
                                elem = (Element) nl.item(0);
                                final String option = elem.getAttribute("cache");
                                modelView.setUseCache("yes".equals(option));
                            }
                        } else {
                            response(broker, response, outputProperties, result);
                            return;
                        }
                    } else if (result.getItemCount() > 1) {
                        response(broker, response, outputProperties, result);
                        return;
                    }

                    if (modelView.useCache()) {
                        LOG.debug("Caching request to " + request.getRequestURI());
                        urlCache.put(modifiedRequest.getHeader("Host") + request.getRequestURI(), modelView);
                    }

                } finally {
                    pool.release(broker);
                }

                // store the original request URI to org.exist.forward.request-uri
                modifiedRequest.setAttribute(RQ_ATTR_REQUEST_URI, request.getRequestURI());
                modifiedRequest.setAttribute(RQ_ATTR_SERVLET_PATH, request.getServletPath());

            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("URLRewrite took " + (System.currentTimeMillis() - start) + "ms.");
            }
            final HttpServletResponse wrappedResponse = new CachingResponseWrapper(response,
                    modelView.hasViews() || modelView.hasErrorHandlers());
            if (modelView.getModel() == null) {
                modelView.setModel(new PassThrough(config, modifiedRequest));
            }

            if (staticRewrite != null) {
                if (modelView.getModel().doResolve()) {
                    staticRewrite.rewriteRequest(modifiedRequest);
                } else {
                    modelView.getModel().setAbsolutePath(modifiedRequest);
                }
            }
            modifiedRequest.allowCaching(!modelView.hasViews());
            doRewrite(modelView.getModel(), modifiedRequest, wrappedResponse);

            int status = ((CachingResponseWrapper) wrappedResponse).getStatus();
            if (status == HttpServletResponse.SC_NOT_MODIFIED) {
                response.flushBuffer();
            } else if (status < 400) {
                if (modelView.hasViews()) {
                    applyViews(modelView, modelView.views, response, modifiedRequest, wrappedResponse);
                } else {
                    ((CachingResponseWrapper) wrappedResponse).flush();
                }
            } else {
                // HTTP response code indicates an error
                if (modelView.hasErrorHandlers()) {
                    final byte[] data = ((CachingResponseWrapper) wrappedResponse).getData();
                    if (data != null) {
                        modifiedRequest.setAttribute(RQ_ATTR_ERROR, new String(data, UTF_8));
                    }
                    applyViews(modelView, modelView.errorHandlers, response, modifiedRequest, wrappedResponse);
                } else {
                    flushError(response, wrappedResponse);
                }
            }
        }
        //            Sequence result;
        //            if ((result = (Sequence) request.getAttribute(RQ_ATTR_RESULT)) != null) {
        //                writeResults(response, broker, result);
        //            }
    } catch (final Throwable e) {
        LOG.error("Error while processing " + servletRequest.getRequestURI() + ": " + e.getMessage(), e);
        throw new ServletException("An error occurred while processing request to "
                + servletRequest.getRequestURI() + ": " + e.getMessage(), e);

    }
}

From source file:org.exist.http.urlrewrite.XQueryURLRewrite.java

private void parseViews(HttpServletRequest request, Element view, ModelAndView modelView)
        throws ServletException {
    Node node = view.getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE && Namespaces.EXIST_NS.equals(node.getNamespaceURI())) {
            final URLRewrite urw = parseAction(request, (Element) node);
            if (urw != null) {
                modelView.addView(urw);/* w w  w.j ava2s  .  com*/
            }
        }
        node = node.getNextSibling();
    }
}

From source file:org.exist.http.urlrewrite.XQueryURLRewrite.java

private void parseErrorHandlers(HttpServletRequest request, Element view, ModelAndView modelView)
        throws ServletException {
    Node node = view.getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE && Namespaces.EXIST_NS.equals(node.getNamespaceURI())) {
            final URLRewrite urw = parseAction(request, (Element) node);
            if (urw != null) {
                modelView.addErrorHandler(urw);
            }//  w  w w. j  ava 2  s  . c om
        }
        node = node.getNextSibling();
    }
}

From source file:org.exist.xquery.modules.httpclient.POSTFunction.java

public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    Sequence response = null;/*from ww w .j  a  v  a  2s. c o  m*/

    // must be a URL
    if (args[0].isEmpty()) {
        return (Sequence.EMPTY_SEQUENCE);
    }

    //get the url
    String url = args[0].itemAt(0).getStringValue();

    //get the payload

    Item payload = args[1].itemAt(0);

    //get the persist state
    boolean persistState = args[2].effectiveBooleanValue();

    PostMethod post = new PostMethod(url);

    if (isCalledAs("post")) {
        RequestEntity entity = null;

        if (Type.subTypeOf(payload.getType(), Type.NODE)) {

            //serialize the node to SAX
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OutputStreamWriter osw = null;

            try {
                osw = new OutputStreamWriter(baos, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw (new XPathException(this, e.getMessage()));
            }

            SAXSerializer sax = new SAXSerializer(osw, new Properties());

            try {
                payload.toSAX(context.getBroker(), sax, new Properties());
                osw.flush();
                osw.close();
            } catch (Exception e) {
                throw (new XPathException(this, e.getMessage()));
            }

            byte[] reqPayload = baos.toByteArray();
            entity = new ByteArrayRequestEntity(reqPayload, "application/xml; charset=utf-8");
        } else {

            try {
                entity = new StringRequestEntity(payload.getStringValue(), "text/text; charset=utf-8", "UTF-8");
            } catch (UnsupportedEncodingException uee) {
                uee.printStackTrace();
            }
        }

        post.setRequestEntity(entity);
    } else if (isCalledAs("post-form")) {
        Node nPayload = ((NodeValue) payload).getNode();

        if ((nPayload instanceof Element) && nPayload.getNamespaceURI().equals(HTTPClientModule.NAMESPACE_URI)
                && nPayload.getLocalName().equals("fields")) {
            Part[] parts = parseFields((Element) nPayload);
            post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
        } else {
            throw (new XPathException(this, "fields must be provided"));
        }

    } else {
        return (Sequence.EMPTY_SEQUENCE);
    }

    //setup POST Request Headers
    if (!args[3].isEmpty()) {
        setHeaders(post, ((NodeValue) args[3].itemAt(0)).getNode());
    }

    try {

        //execute the request
        response = doRequest(context, post, persistState, null, null);

    } catch (IOException ioe) {
        throw (new XPathException(this, ioe.getMessage(), ioe));
    } finally {
        post.releaseConnection();
    }

    return (response);
}

From source file:org.geowebcache.config.XMLConfiguration.java

private static Node checkAndTransform(Document doc) throws ConfigurationException {
    Node rootNode = doc.getDocumentElement();

    // debugPrint(rootNode);

    if (!rootNode.getNodeName().equals("gwcConfiguration")) {
        log.info("The configuration file is of the pre 1.0 type, trying to convert.");
        rootNode = applyTransform(rootNode, "geowebcache_pre10.xsl").getFirstChild();
    }//w  w w  .  j av  a 2  s. c  o m

    // debugPrint(rootNode);

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.0.0")) {
        log.info("Updating configuration from 1.0.0 to 1.0.1");
        rootNode = applyTransform(rootNode, "geowebcache_100.xsl").getFirstChild();
    }

    // debugPrint(rootNode);

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.0.1")) {
        log.info("Updating configuration from 1.0.1 to 1.0.2");
        rootNode = applyTransform(rootNode, "geowebcache_101.xsl").getFirstChild();
    }

    // debugPrint(rootNode);

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.0.2")) {
        log.info("Updating configuration from 1.0.2 to 1.1.0");
        rootNode = applyTransform(rootNode, "geowebcache_102.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.1.0")) {
        log.info("Updating configuration from 1.1.0 to 1.1.3");
        rootNode = applyTransform(rootNode, "geowebcache_110.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.1.3")) {
        log.info("Updating configuration from 1.1.3 to 1.1.4");
        rootNode = applyTransform(rootNode, "geowebcache_113.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.1.4")) {
        log.info("Updating configuration from 1.1.4 to 1.1.5");
        rootNode = applyTransform(rootNode, "geowebcache_114.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.1.5")) {
        log.info("Updating configuration from 1.1.5 to 1.2.0");
        rootNode = applyTransform(rootNode, "geowebcache_115.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.2.0")) {
        log.info("Updating configuration from 1.2.0 to 1.2.1");
        rootNode = applyTransform(rootNode, "geowebcache_120.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.2.1")) {
        log.info("Updating configuration from 1.2.1 to 1.2.2");
        rootNode = applyTransform(rootNode, "geowebcache_121.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.2.2")) {
        log.info("Updating configuration from 1.2.2 to 1.2.4");
        rootNode = applyTransform(rootNode, "geowebcache_122.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.2.4")) {
        log.info("Updating configuration from 1.2.4 to 1.2.5");
        rootNode = applyTransform(rootNode, "geowebcache_124.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.2.5")) {
        log.info("Updating configuration from 1.2.5 to 1.2.6");
        rootNode = applyTransform(rootNode, "geowebcache_125.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.2.6")) {
        log.info("Updating configuration from 1.2.6 to 1.5.0");
        rootNode = applyTransform(rootNode, "geowebcache_126.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.5.0")) {
        log.info("Updating configuration from 1.5.0 to 1.5.1");
        rootNode = applyTransform(rootNode, "geowebcache_150.xsl").getFirstChild();
    }

    if (rootNode.getNamespaceURI().equals("http://geowebcache.org/schema/1.5.1")) {
        log.info("Updating configuration from 1.5.1 to 1.6.0");
        rootNode = applyTransform(rootNode, "geowebcache_151.xsl").getFirstChild();
    }

    // Check again after transform
    if (!rootNode.getNodeName().equals("gwcConfiguration")) {
        log.error("Unable to parse file, expected gwcConfiguration at root after transform.");
        throw new ConfigurationException("Unable to parse after transform.");
    } else {
        // Parsing the schema file
        try {
            validate(rootNode);
            log.info("Configuration file validated fine.");
        } catch (SAXException e) {
            String msg = "*** GWC configuration validation error: " + e.getMessage();
            char[] c = new char[4 + msg.length()];
            Arrays.fill(c, '*');
            String warndecoration = new String(c).substring(0, 80);
            log.warn(warndecoration);
            log.warn(msg);
            log.warn(
                    "*** Will try to use configuration anyway. Please check the order of declared elements against the schema.");
            log.warn(warndecoration);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    return rootNode;
}

From source file:org.gluu.saml.Response.java

public Map<String, List<String>> getAttributes() throws XPathExpressionException {
    Map<String, List<String>> result = new HashMap<String, List<String>>();
    XPath xPath = XPathFactory.newInstance().newXPath();

    xPath.setNamespaceContext(NAMESPACES);
    XPathExpression query = xPath
            .compile("/samlp:Response/saml:Assertion/saml:AttributeStatement/saml:Attribute");
    NodeList nodes = (NodeList) query.evaluate(xmlDoc, XPathConstants.NODESET);
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);

        Node nameNode = node.getAttributes().getNamedItem("Name");
        if (nameNode == null) {
            continue;
        }// w ww .j a  v a  2s . c om

        String attributeName = nameNode.getNodeValue();
        List<String> attributeValues = new ArrayList<String>();

        NodeList nameChildNodes = node.getChildNodes();
        for (int j = 0; j < nameChildNodes.getLength(); j++) {
            Node nameChildNode = nameChildNodes.item(j);

            if (nameChildNode.getNamespaceURI().equalsIgnoreCase("urn:oasis:names:tc:SAML:2.0:assertion")
                    && nameChildNode.getLocalName().equals("AttributeValue")) {
                NodeList valueChildNodes = nameChildNode.getChildNodes();
                for (int k = 0; k < valueChildNodes.getLength(); k++) {
                    Node valueChildNode = valueChildNodes.item(k);
                    attributeValues.add(valueChildNode.getNodeValue());
                }
            }
        }

        result.put(attributeName, attributeValues);
    }

    return result;
}

From source file:org.jasig.portal.plugin.deployer.AbstractExtractingEarDeployer.java

private String getNodeName(Node node) {
    if (node.getNamespaceURI() == null) {
        return node.getNodeName();
    }/*from   www  .  ja v a 2s.  c  om*/

    return node.getLocalName();
}

From source file:org.jbpm.bpel.integration.soap.SoapUtil.java

public static void copyNamespaces(SOAPElement target, Element source) throws SOAPException {
    // easy way out: no attributes
    if (!source.hasAttributes())
        return;/*from  w  w  w .ja v  a 2  s.c om*/
    // traverse attributes to discover namespace declarations
    NamedNodeMap attributes = source.getAttributes();
    for (int i = 0, n = attributes.getLength(); i < n; i++) {
        Node attribute = attributes.item(i);
        // is attribute a namespace declaration?
        if (!BpelConstants.NS_XMLNS.equals(attribute.getNamespaceURI()))
            continue;
        // namespace declaration format xmlns:prefix="namespaceURI" |
        // xmlns="defaultNamespaceURI"
        String namespaceURI = attribute.getNodeValue();
        String prefix = attribute.getLocalName();
        // non-default namespace declaration?
        if (!"xmlns".equals(prefix)) {
            // BPEL-195: prevent addition matching visible declaration at target
            if (namespaceURI.equals(target.getNamespaceURI(prefix)))
                continue;
            target.addNamespaceDeclaration(prefix, namespaceURI);
            if (traceEnabled)
                log.trace("added namespace declaration: " + prefix + "->" + namespaceURI);
        }
        // non-empty default namespace declaration
        else if (namespaceURI.length() > 0) {
            prefix = XmlUtil.generatePrefix(DEFAULT_NAMESPACE_PREFIX, source);
            target.addNamespaceDeclaration(prefix, namespaceURI);
            if (traceEnabled)
                log.trace("reassigned default namespace declaration: " + prefix + "->" + namespaceURI);
        }
    }
}