You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by "Shawn C. Dodd" <sd...@agea.com> on 2001/05/06 18:03:25 UTC
Changes to SearchMethod
Remy,
Here is the update to SearchMethod I promised you. There's no new
functionality; I just cleaned up the interface. If you'd prefer patches in
diff format, I'd be happy to accomodate you.
Changes:
- Removed everything relating to depth support and type support, as these
are not needed for SEARCH requests. This is *not* a backwards-compatible
change; it will break existing consumers of the interface.
- Added JavaDoc comment blocks for all public methods.
One question. Now that I've removed all properties and constants, should I
also remove the associated comments? (E.g., "// -----------------
Constants".)
Sincerely,
Shawn
--- cut here ---
/*
* $Header:
/home/cvspublic/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/me
thods/PropFindMethod.java,v 1.24 2001/04/13 08:04:38 remm Exp $
* $Revision: 1.24 $
* $Date: 2001/04/13 08:04:38 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.webdav.lib.methods;
import java.io.InputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.util.WebdavStatus;
import org.apache.util.XMLPrinter;
import org.apache.webdav.lib.Header;
import org.apache.webdav.lib.Property;
import org.apache.webdav.lib.State;
import org.apache.webdav.lib.WebdavException;
import org.apache.webdav.lib.properties.GetLastModifiedProperty;
import org.apache.webdav.lib.properties.ResourceTypeProperty;
/**
* Implements the WebDAV SEARCH Method, used for executing queries on the
WebDAV server.
*
* <P> The SEARCH method initiates a server-side search. The body of the
* request defines the query. The server responds with a text/xml entity
* matching the WebDAV PROPFIND response.
*
* <P> According to <a
href="http://www.webdav.org/dasl/protocol/draft-dasl-protocol-00.html">
* the DASL draft</a> a typical request looks like this:
*
* <PRE>
* SEARCH /folder/ HTTP/1.1
* Host: www.foo.bar
* Content-type: text/xml; charset="utf-8"
* Content-Length: xxxx
*
* <?xml version="1.0"?>
* <D:searchrequest xmlns:D = "DAV:" >
* <D:basicsearch>
* <D:select>
* <D:prop><D:getcontentlength/></D:prop>
* </D:select>
* <D:from>
* <D:scope>
* <D:href>/folder/</D:href>
* <D:depth>infinity</D:depth>
* </D:scope>
* </D:from>
* </D:basicsearch>
* </D:searchrequest>
* </PRE>
*
* <P> However, other query grammars may be used. A typical request
using
* the <a
href="http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/exchsv
2k/_exch2k_sql_web_storage_system_sql.htm">
* SQL-based grammar</a> implemented in Microsoft's Web Storage System
* (currently shipping with Exchange 2000 and SharePoint Portal Server)
looks
* like this:
*
* <PRE>
* SEARCH /folder/ HTTP/1.1
* Host: www.foo.bar
* Content-type: text/xml; charset="utf-8"
* Content-Length: xxxx
*
* <?xml version="1.0"?>
* <D:searchrequest xmlns:D = "DAV:" >
* <D:sql>
* SELECT "DAV:contentclass", "DAV:displayname"
* FROM "/folder/"
* WHERE "DAV:ishidden" = false
* AND "DAV:isfolder" = false
* </D:sql>
* </D:searchrequest>
* </PRE>
*
* @author <a href="mailto:sdodd@agea.com">Shawn C. Dodd</a>
*/
public class SearchMethod extends XMLResponseMethodBase
{
// --------------------------------------------------------------
Constants
// -----------------------------------------------------------
Constructors
/**
* Create a SearchMethod unassociated with any resource path or query
body.
*/
public SearchMethod() {
name = "SEARCH";
}
/**
* Create a SearchMethod associated with the given WebDAV resource path.
*
* @param path Relative path to the WebDAV resource (presumably a
collection).
*/
public SearchMethod(String path) {
super(path);
name = "SEARCH";
}
/**
* Create a SearchMethod using the given XML request body.
*
* @param path Relative path to the WebDAV resource (presumably a
collection).
* @param query Complete request body in XML including a search query in
your favorite grammar.
*/
public SearchMethod(String path, String query) {
this(path);
setQuery(query);
}
// ----------------------------------------------------- Instance
Variables
/**
* The namespace abbreviation that prefixes DAV tags
*/
protected String prefix = null;
// -------------------------------------------------------------
Properties
// --------------------------------------------------- WebdavMethod
Methods
public void recycle() {
super.recycle();
prefix = null;
}
/**
* Generate additional headers needed by the request.
*
* @param host the host
* @param state State token
*/
public void generateHeaders(String host, State state) {
super.generateHeaders(host, state);
super.setHeader("Content-Type", "text/xml; charset=utf-8");
}
/**
* Return a text representation of the query associated with this method
* instance. Currently, this is simply the query text previously passed
* to setQuery() or the constructor.
*
* @return String query
*/
public String generateQuery()
if (query == null || query.trim().length() < 1) {
// TODO Must support some mechanism for delegating the
// generation of the query to a pluggable query grammar
// support class or package. Right now, executing this
// method object without first explicitly setting the
// query is an error.
return "";
} else {
return query;
}
}
/**
* Returns an enumeration of URL paths each representing a property in
the
* reply returned from the search.
*
* <br>If the search returned multiple result properties, then there
will
* be multiple URLs. The URLs are picked out of the
* <code><D:href></code> elements of the response.
*
* @return an enumeration of URL paths as Strings
*/
public Enumeration getAllResponseURLs() {
checkUsed();
return getResponseHashtable().keys();
}
/**
* Returns an enumeration of <code>Property</code> objects, or an empty
* enumeration if none exist.
*/
public Enumeration getResponseProperties(String urlPath) {
checkUsed();
Response response = (Response) getResponseHashtable().get(urlPath);
if (response != null) {
return response.getProperties();
} else {
return (new Vector()).elements();
}
}
}