Package org.apache.webdav.lib.methods

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


            super.endElement(uri, name, raw);
        }
    }

    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();
View Full Code Here

            super.endElement(uri, name, raw);
        }
    }

    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

           // setAllowedMethods. Haven't looked to see how important doing that is.
           
           // Existence is determined separately (see existsTest).
           
           
           final OptionsMethod optionsMethod = new OptionsMethod(pathEncoded);
            configureMethod(optionsMethod);
            try
            {
                optionsMethod.setFollowRedirects(true);
                final int status = fileSystem.getClient().executeMethod(optionsMethod);
                if (status < 200 || status > 299)
                {
                    if (status == 401 || status == 403)
                    {
                        setAllowedMethods(null);

                        // permission denied on this object, but we might get some informations from the parent
                        processParentDavResource();
                        return;
                    }
                    else
                    {
                        injectType(FileType.IMAGINARY);
                    }
                    return;
                }
                // handle the (maybe) redirected url
                redirectionResolved = true;
                System.out.println(optionsMethod.getURI().getPath());
//                resource.getHttpURL().setEscapedPath(optionsMethod.getURI().getPath());
                resource.getHttpURL().setEscapedPath(optionsMethod.getURI().getEscapedPath());

                setAllowedMethods(optionsMethod.getAllowedMethods());
               
                boolean exists = existsTest(pathEncoded);
                if (!exists)
                {
                    injectType(FileType.IMAGINARY);
                    return;
                }
               
                try
                {
                    resource.setProperties(WebdavResource.DEFAULT, 1);
                }
                catch (IOException e)
                {
                  e.printStackTrace();
                 
                    throw new FileSystemException(e);
                }
            }
            finally
            {
              optionsMethod.releaseConnection();
            }
        }

        ResourceTypeProperty resourceType = resource.getResourceType();
        if (resourceType == null) {
View Full Code Here

        if (redirectionResolved)
        {
            return;
        }

        final OptionsMethod optionsMethod = new OptionsMethod(getName().getPath());
        configureMethod(optionsMethod);
        try
        {
            optionsMethod.setFollowRedirects(true);
            final int status = fileSystem.getClient().executeMethod(optionsMethod);
            if (status >= 200 && status <= 299)
            {
                setAllowedMethods(optionsMethod.getAllowedMethods());
                resource.getHttpURL().setEscapedPath(optionsMethod.getPath());
                redirectionResolved = true;
            }
        }
        finally
        {
            optionsMethod.releaseConnection();
        }
    }
View Full Code Here

        if (allowedMethods != null)
        {
            return;
        }

        final OptionsMethod optionsMethod = new OptionsMethod(getName().getPath());
        configureMethod(optionsMethod);
        try
        {
            optionsMethod.setFollowRedirects(true);
            final int status = fileSystem.getClient().executeMethod(optionsMethod);
            if (status < 200 || status > 299)
            {
                if (status == 401 || status == 403)
                {
                    setAllowedMethods(null);
                    return;
                }
            }

            setAllowedMethods(optionsMethod.getAllowedMethods());
        }
        finally
        {
            optionsMethod.releaseConnection();
        }

        return;
    }
View Full Code Here

     */
    public boolean optionsMethod(String path)
        throws HttpException, IOException {

        setClient();
        OptionsMethod method;
        if (path.trim().equals("*"))
            method = new OptionsMethod("*");
        else
            method = new OptionsMethod(URIUtil.encodePath(path));
        int statusCode = client.executeMethod(method);

        setStatusCode(statusCode);

        if  (statusCode >= 200 && statusCode < 300) {
            // check if the specific method is possbile
            allowedMethods = method.getAllowedMethods();
            // check WebDAV capabilities.
            davCapabilities = method.getDavCapabilities();
            return true;
        }

        return false;
    }
View Full Code Here

    public Enumeration optionsMethod(HttpURL httpURL)
        throws HttpException, IOException {

        HttpClient client = getSessionInstance(httpURL, true);

        OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath());
        client.executeMethod(method);

        Vector options = new Vector();
        int statusCode = method.getStatusLine().getStatusCode();
        if (statusCode >= 200 && statusCode < 300) {
            // check if the specific method is possbile
            Enumeration allowedMethods = method.getAllowedMethods();
            while (allowedMethods.hasMoreElements()) {
                options.addElement(allowedMethods.nextElement());
            }
            // check WebDAV capabilities.
            Enumeration davCapabilities = method.getDavCapabilities();
            while (davCapabilities.hasMoreElements()) {
                options.addElement(davCapabilities.nextElement());
            }
            Enumeration responses = method.getResponses();
            if (responses.hasMoreElements()) {
                ResponseEntity response =
                    (ResponseEntity) responses.nextElement();
                Enumeration workspaces = response.getWorkspaces();
                String sResult="";
View Full Code Here

    public Enumeration optionsMethod(HttpURL httpURL, int type)
        throws HttpException, IOException {

        HttpClient client = getSessionInstance(httpURL, true);

        OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath(),
                                                 type);
        client.executeMethod(method);

        Vector options = new Vector();
        int statusCode = method.getStatusLine().getStatusCode();
        if  (statusCode >= 200 && statusCode < 300) {
            Enumeration responses = method.getResponses();
            if (responses.hasMoreElements()) {
                ResponseEntity response =
                    (ResponseEntity) responses.nextElement();
                // String sResult="";
                if (type == OPTIONS_WORKSPACE){
View Full Code Here

    public Enumeration optionsMethod(String path, int type)
        throws HttpException, IOException {

        setClient();

        OptionsMethod method = new OptionsMethod(URIUtil.encodePath(path),
                                                 type);
        client.executeMethod(method);

        Vector options = new Vector();
        int statusCode = method.getStatusLine().getStatusCode();
        if  (statusCode >= 200 && statusCode < 300) {
            Enumeration responses = method.getResponses();
            if (responses.hasMoreElements()) {
                ResponseEntity response =
                    (ResponseEntity) responses.nextElement();
                // String sResult="";
                if (type == OPTIONS_WORKSPACE){
View Full Code Here

TOP

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

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.