Package org.apache.webdav.lib.methods

Examples of org.apache.webdav.lib.methods.SearchMethod


    protected void performSearchMethod(String query) throws SAXException {
        try {
            DOMStreamer propertyStreamer = new DOMStreamer(this.xmlConsumer);
            OptionsMethod optionsMethod = new OptionsMethod(this.targetUrl);
            SearchMethod searchMethod = new SearchMethod(this.targetUrl, query);
            HttpURL url = new HttpURL(this.targetUrl);
            HttpState state = new HttpState();
            state.setCredentials(null, new UsernamePasswordCredentials(
                    url.getUser(),
                    url.getPassword()));                      
            HttpConnection conn = new HttpConnection(url.getHost(), url.getPort());
            WebdavResource resource = new WebdavResource(new HttpURL(this.targetUrl));
            if(!resource.exists()) {
                throw new SAXException("The WebDAV resource don't exist");
            }
            optionsMethod.execute(state, conn);
            if(!optionsMethod.isAllowed("SEARCH")) {
                throw new SAXException("The server don't support the SEARCH method");
            }
            searchMethod.execute(state, conn);
            Enumeration enumeration = searchMethod.getAllResponseURLs();
            this.contentHandler.startElement(
                DASL_QUERY_NS,
                RESULT_ROOT_TAG,
                PREFIX + ":" + RESULT_ROOT_TAG,
                new AttributesImpl());
            while (enumeration.hasMoreElements()) {
                String path = (String) enumeration.nextElement();
                Enumeration properties = searchMethod.getResponseProperties(path);
                AttributesImpl attr = new AttributesImpl();
                attr.addAttribute(DASL_QUERY_NS, PATH_NODE_NAME, PREFIX + ":" + PATH_NODE_NAME, "CDATA",path);

                this.contentHandler.startElement(DASL_QUERY_NS,
                    RESOURCE_NODE_NAME,
View Full Code Here


        dispatcher.fireVetoableEvent(information, credentials);
    }

    public Value[] search(String query, Credentials credentials) throws IOException {
        String url = domain+"/";
        SearchMethod searchMethod = new SearchMethod(url, query);
        searchMethod.setDoAuthentication(true);
        HttpState httpState = new HttpState();
        httpState.setCredentials(null, host, credentials);
        int state = searchMethod.execute(httpState, new HttpConnection(host, port, protocol));
        if ( state != HttpStatus.SC_MULTI_STATUS ) {
            throw new IOException("Received status code "+state+" when doing SEARCH with query="+query);
        }
        List values = new ArrayList();
        for ( Enumeration e = searchMethod.getAllResponseURLs(); e.hasMoreElements(); ) {
            Map searchResults = new HashMap();
            String uri = (String)e.nextElement();
            for ( Enumeration pe = searchMethod.getResponseProperties(uri); pe.hasMoreElements(); ) {
              Property property = (Property)pe.nextElement();
        searchResults.put(property.getLocalName(), property.getPropertyAsString());
          }
      if ( uri.indexOf(domain) != -) {
        uri = uri.substring(uri.indexOf(domain)+domain.length());
View Full Code Here

        }
    }

    protected void performSearchMethod(String query) throws SAXException {
      OptionsMethod optionsMethod = null;
      SearchMethod searchMethod = null;
        try {
            DOMStreamer propertyStreamer = new DOMStreamer(this.xmlConsumer);
            optionsMethod = new OptionsMethod(this.targetUrl);
            searchMethod = new SearchMethod(this.targetUrl, query);
            HttpURL url = new HttpURL(this.targetUrl);
            HttpState state = new HttpState();
            state.setCredentials(null, new UsernamePasswordCredentials(
                    url.getUser(),
                    url.getPassword()));
            HttpConnection conn = new HttpConnection(url.getHost(), url.getPort());
           
            // eventcaching stuff
            SourceValidity extraValidity = makeWebdavEventValidity(url);
            if(extraValidity!=null && m_validity!=null)
              m_validity.add(extraValidity);
            // end eventcaching stuff
           
            WebdavResource resource = new WebdavResource(new HttpURL(this.targetUrl));
            if(!resource.exists()) {
                throw new SAXException("The WebDAV resource don't exist");
            }
            optionsMethod.execute(state, conn);
            if(!optionsMethod.isAllowed("SEARCH")) {
                throw new SAXException("The server doesn't support the SEARCH method");
            }
            int httpstatus = searchMethod.execute(state, conn);
           
           
            this.contentHandler.startElement(DASL_QUERY_NS,
                                             RESULT_ROOT_TAG,
                                             PREFIX + ":" + RESULT_ROOT_TAG,
                                             XMLUtils.EMPTY_ATTRIBUTES);
           
            // something might have gone wrong, report it
            // 207 = multistatus webdav response
            if(httpstatus != 207) {
             
              this.contentHandler.startElement(DASL_QUERY_NS,
                        ERROR_ROOT_TAG,
                        PREFIX + ":" + ERROR_ROOT_TAG,
                        XMLUtils.EMPTY_ATTRIBUTES);
             
              // dump whatever the server said
              propertyStreamer.stream(searchMethod.getResponseDocument());
             
              this.contentHandler.endElement(DASL_QUERY_NS,
                  ERROR_ROOT_TAG,
                        PREFIX + ":" + ERROR_ROOT_TAG);
             
            } else {
              // show results
             
              Enumeration enumeration = searchMethod.getAllResponseURLs();
             
              while (enumeration.hasMoreElements()) {
                  String path = (String) enumeration.nextElement();
                  Enumeration properties = searchMethod.getResponseProperties(path);
                  AttributesImpl attr = new AttributesImpl();
                  attr.addAttribute(DASL_QUERY_NS, PATH_NODE_NAME, PREFIX + ":" + PATH_NODE_NAME, "CDATA",path);
 
                  this.contentHandler.startElement(DASL_QUERY_NS,
                      RESOURCE_NODE_NAME,
                      PREFIX + ":" + RESOURCE_NODE_NAME,
                      attr);
                  while(properties.hasMoreElements()) {
                      BaseProperty metadata = (BaseProperty) properties.nextElement();
                      Element propertyElement = metadata.getElement();
                      propertyStreamer.stream(propertyElement);
                  }
 
                  this.contentHandler.endElement(DASL_QUERY_NS,
                      RESOURCE_NODE_NAME,
                      PREFIX + ":" + RESOURCE_NODE_NAME);
              }
            }
           
            this.contentHandler.endElement(DASL_QUERY_NS,
                                           RESULT_ROOT_TAG,
                                           PREFIX + ":" + RESULT_ROOT_TAG);
        } catch (SAXException e) {
            throw new SAXException("Unable to fetch the query data:", e);
        } catch (HttpException e1) {
            this.getLogger().error("Unable to contact Webdav server", e1);
            throw new SAXException("Unable to connect with server: ", e1);
        } catch (IOException e2) {
            throw new SAXException("Unable to connect with server: ", e2);
        } catch (NullPointerException e) {
            throw new SAXException("Unable to fetch the query data:", e);
        } catch (Exception e) {
            throw new SAXException("Generic Error:", e);
        } finally {
          // cleanup
          if(searchMethod!=null)
            searchMethod.releaseConnection();
          if(optionsMethod!=null)
            optionsMethod.releaseConnection();
        }
    }
View Full Code Here

    protected void performSearchMethod(String query) throws SAXException {
        try {
            DOMStreamer propertyStreamer = new DOMStreamer(this.xmlConsumer);
            OptionsMethod optionsMethod = new OptionsMethod(this.targetUrl);
            SearchMethod searchMethod = new SearchMethod(this.targetUrl, query);
            HttpURL url = new HttpURL(this.targetUrl);
            HttpState state = new HttpState();
            state.setCredentials(null, new UsernamePasswordCredentials(
                    url.getUser(),
                    url.getPassword()));
            HttpConnection conn = new HttpConnection(url.getHost(), url.getPort());
            WebdavResource resource = new WebdavResource(new HttpURL(this.targetUrl));
            if(!resource.exists()) {
                throw new SAXException("The WebDAV resource don't exist");
            }
            optionsMethod.execute(state, conn);
            if(!optionsMethod.isAllowed("SEARCH")) {
                throw new SAXException("The server don't support the SEARCH method");
            }
            searchMethod.execute(state, conn);

            Enumeration enumeration = searchMethod.getAllResponseURLs();
            this.contentHandler.startElement(DASL_QUERY_NS,
                                             RESULT_ROOT_TAG,
                                             PREFIX + ":" + RESULT_ROOT_TAG,
                                             XMLUtils.EMPTY_ATTRIBUTES);
            while (enumeration.hasMoreElements()) {
                String path = (String) enumeration.nextElement();
                Enumeration properties = searchMethod.getResponseProperties(path);
                AttributesImpl attr = new AttributesImpl();
                attr.addAttribute(DASL_QUERY_NS, PATH_NODE_NAME, PREFIX + ":" + PATH_NODE_NAME, "CDATA",path);

                this.contentHandler.startElement(DASL_QUERY_NS,
                    RESOURCE_NODE_NAME,
View Full Code Here

        }
    }

    protected void performSearchMethod(String query) throws SAXException {
      OptionsMethod optionsMethod = null;
      SearchMethod searchMethod = null;
        try {
            DOMStreamer propertyStreamer = new DOMStreamer(this.xmlConsumer);
            optionsMethod = new OptionsMethod(this.targetUrl);
            searchMethod = new SearchMethod(this.targetUrl, query);
            HttpURL url = new HttpURL(this.targetUrl);
            HttpState state = new HttpState();
            state.setCredentials(null, new UsernamePasswordCredentials(
                    url.getUser(),
                    url.getPassword()));
            HttpConnection conn = new HttpConnection(url.getHost(), url.getPort());
           
            // eventcaching stuff
            SourceValidity extraValidity = makeWebdavEventValidity(url);
            if(extraValidity!=null && m_validity!=null)
              m_validity.add(extraValidity);
            // end eventcaching stuff
           
            WebdavResource resource = new WebdavResource(new HttpURL(this.targetUrl));
            if(!resource.exists()) {
                throw new SAXException("The WebDAV resource don't exist");
            }
            optionsMethod.execute(state, conn);
            if(!optionsMethod.isAllowed("SEARCH")) {
                throw new SAXException("The server doesn't support the SEARCH method");
            }
            int httpstatus = searchMethod.execute(state, conn);
           
           
            this.contentHandler.startElement(DASL_QUERY_NS,
                                             RESULT_ROOT_TAG,
                                             PREFIX + ":" + RESULT_ROOT_TAG,
                                             XMLUtils.EMPTY_ATTRIBUTES);
           
            // something might have gone wrong, report it
            // 207 = multistatus webdav response
            if(httpstatus != 207) {
             
              this.contentHandler.startElement(DASL_QUERY_NS,
                        ERROR_ROOT_TAG,
                        PREFIX + ":" + ERROR_ROOT_TAG,
                        XMLUtils.EMPTY_ATTRIBUTES);
             
              // dump whatever the server said
              propertyStreamer.stream(searchMethod.getResponseDocument());
             
              this.contentHandler.endElement(DASL_QUERY_NS,
                  ERROR_ROOT_TAG,
                        PREFIX + ":" + ERROR_ROOT_TAG);
             
            } else {
              // show results
             
              Enumeration enumeration = searchMethod.getAllResponseURLs();
             
              while (enumeration.hasMoreElements()) {
                  String path = (String) enumeration.nextElement();
                  Enumeration properties = searchMethod.getResponseProperties(path);
                  AttributesImpl attr = new AttributesImpl();
                  attr.addAttribute(DASL_QUERY_NS, PATH_NODE_NAME, PREFIX + ":" + PATH_NODE_NAME, "CDATA",path);
 
                  this.contentHandler.startElement(DASL_QUERY_NS,
                      RESOURCE_NODE_NAME,
                      PREFIX + ":" + RESOURCE_NODE_NAME,
                      attr);
                  while(properties.hasMoreElements()) {
                      BaseProperty metadata = (BaseProperty) properties.nextElement();
                      Element propertyElement = metadata.getElement();
                      propertyStreamer.stream(propertyElement);
                  }
 
                  this.contentHandler.endElement(DASL_QUERY_NS,
                      RESOURCE_NODE_NAME,
                      PREFIX + ":" + RESOURCE_NODE_NAME);
              }
            }
           
            this.contentHandler.endElement(DASL_QUERY_NS,
                                           RESULT_ROOT_TAG,
                                           PREFIX + ":" + RESULT_ROOT_TAG);
        } catch (SAXException e) {
            throw new SAXException("Unable to fetch the query data:", e);
        } catch (HttpException e1) {
            this.getLogger().error("Unable to contact Webdav server", e1);
            throw new SAXException("Unable to connect with server: ", e1);
        } catch (IOException e2) {
            throw new SAXException("Unable to connect with server: ", e2);
        } catch (NullPointerException e) {
            throw new SAXException("Unable to fetch the query data:", e);
        } catch (Exception e) {
            throw new SAXException("Generic Error:", e);
        } finally {
          // cleanup
          if(searchMethod!=null)
            searchMethod.releaseConnection();
          if(optionsMethod!=null)
            optionsMethod.releaseConnection();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.webdav.lib.methods.SearchMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.