wam         02/03/19 09:27:53

  Modified:    src/share/org/apache/slide/search SearchQueryResult.java
               src/webdav/server/org/apache/slide/webdav/method
                        SearchMethod.java
               src/share/org/apache/slide/search/basic BasicQuery.java
  Log:
  enhanced errorhandling
  
  Revision  Changes    Path
  1.4       +84 -8     
jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java
  
  Index: SearchQueryResult.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SearchQueryResult.java    14 Feb 2002 17:05:03 -0000      1.3
  +++ SearchQueryResult.java    19 Mar 2002 17:27:52 -0000      1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java,v 1.3 
2002/02/14 17:05:03 wam Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/02/14 17:05:03 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java,v 1.4 
2002/03/19 17:27:52 wam Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/03/19 17:27:52 $
    *
    * ====================================================================
    *
  @@ -71,15 +71,91 @@
   import org.apache.slide.util.Configuration;
   
   /**
  - * Search query result.
  + * A Hashset containing the result items of a query. May also contain a status
  + * and a response description (For example: 507 partial result)
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.3 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
  + *
  + * @version $Revision: 1.4 $
    */
   public class SearchQueryResult extends HashSet {
       
  -     public SearchQueryResult (Set result) {
  -             super (result);
  -     }
  +    public final static int STATUS_OK             = 0;
  +    public final static int STATUS_BAD_QUERY      = 1;
  +    public final static int STATUS_INVALID_SCOPE  = 2;
  +    public final static int STATUS_PARTIAL_RESULT = 3;
  +    
  +    private int status;
  +    private String description;
  +    private String href;
  +    
  +    /**
  +     * Method setStatus
  +     *
  +     * @param    status              an int
  +     *
  +     */
  +    public void setStatus(int status) {
  +        this.status = status;
  +    }
  +    
  +    /**
  +     * Method getStatus
  +     *
  +     * @return   an int
  +     *
  +     */
  +    public int getStatus() {
  +        return status;
  +    }
  +    
  +    /**
  +     * Method setDescription
  +     *
  +     * @param    description         a  String
  +     *
  +     */
  +    public void setDescription(String description) {
  +        this.description = description;
  +    }
  +    
  +    /**
  +     * Method getDescription
  +     *
  +     * @return   a String
  +     *
  +     */
  +    public String getDescription() {
  +        return description;
  +    }
  +
  +    /**
  +     * Method setHref
  +     *
  +     * @param    href                a  String
  +     *
  +     */
  +    public void setHref (String href) {
  +        this.href = href;
  +    }
  +    /**
  +     * Method getHref
  +     *
  +     * @return   a String
  +     *
  +     */
  +    public String getHref () {
  +        return href;
  +    }
  +    
  +    public SearchQueryResult (Set result) {
  +        super (result);
  +        status = STATUS_OK;
  +        description = "";
  +    }
       
  +    public SearchQueryResult () {
  +        super ();
  +    }
   }
  
  
  
  1.9       +303 -140  
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/SearchMethod.java
  
  Index: SearchMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/SearchMethod.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SearchMethod.java 13 Mar 2002 09:29:11 -0000      1.8
  +++ SearchMethod.java 19 Mar 2002 17:27:53 -0000      1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/SearchMethod.java,v
 1.8 2002/03/13 09:29:11 juergen Exp $
  - * $Revision: 1.8 $
  - * $Date: 2002/03/13 09:29:11 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/SearchMethod.java,v
 1.9 2002/03/19 17:27:53 wam Exp $
  + * $Revision: 1.9 $
  + * $Date: 2002/03/19 17:27:53 $
    *
    * ====================================================================
    *
  @@ -125,6 +125,7 @@
       private Search searchHelper  = null;
       
       private RequestedProperties requestedProperties = null;
  +    private PropertyRetriever retriever;
       
       // ----------------------------------------------------------- Constructors
       
  @@ -133,9 +134,11 @@
                            HttpServletResponse resp, WebdavServletConfig config) {
           super(token, req, resp, config);
           searchHelper = token.getSearchHelper();
  +        retriever = new PropertyRetrieverImpl
  +            (token, slideToken);
  +        
       }
       
  -    
       /**
        * Method parseRequest
        *
  @@ -144,153 +147,313 @@
        */
       protected void parseRequest() throws WebdavException {
           
  -        Element queryElement = getQueryElement();
  -        String grammarNamespace = queryElement.getNamespaceURI();
           if (Configuration.useSearch ()) {
  -        try {
  -            // SearchLanguage language = searchHelper.getLanguage 
(grammarNamespace);
  -            int maxDepth = getConfig().getDepthLimit();
  -            
  -            searchQuery = searchHelper.getSearchQuery
  -                (grammarNamespace, queryElement, slideToken, maxDepth);
  -            
  -            requestedProperties = searchQuery.requestedProperties ();
  -        }
  -        catch (InvalidQueryException e) {
  -            resp.setStatus(WebdavStatus.SC_UNPROCESSABLE_ENTITY);
  -            throw new WebdavException(WebdavStatus.SC_UNPROCESSABLE_ENTITY);
  -        }
  -        catch (BadQueryException e) {
  -            resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  -        }
  -        }
  -        else {
  -            resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            try {
  +                Element queryElement = getQueryElement();
  +                String grammarNamespace = queryElement.getNamespaceURI();
  +                
  +                
  +                // SearchLanguage language = searchHelper.getLanguage 
(grammarNamespace);
  +                int maxDepth = getConfig().getDepthLimit();
  +                
  +                searchQuery = searchHelper.getSearchQuery
  +                    (grammarNamespace, queryElement, slideToken, maxDepth);
  +                
  +                requestedProperties = searchQuery.requestedProperties ();
  +            }
  +            catch (SAXException e) {
  +                resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +                createErrorResult (SearchQueryResult.STATUS_BAD_QUERY,
  +                                   e.getMessage());
  +                throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            }
  +            catch (InvalidQueryException e) {
  +                    resp.setStatus(WebdavStatus.SC_UNPROCESSABLE_ENTITY);
  +                    throw new WebdavException(WebdavStatus.SC_UNPROCESSABLE_ENTITY);
  +                }
  +                catch (BadQueryException e) {
  +                    resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +                    throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +                }
  +            }
  +            else {
  +                resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +                createErrorResult (SearchQueryResult.STATUS_BAD_QUERY, "SEARCH not 
implemented on this server");
  +                throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +            }
           }
           
  -    }
  -    
  -    
  -    /**
  -     * Method executeRequest
  -     *
  -     * @throws   WebdavException
  -     *
  -     * @version  12/28/2001
  -     */
  -    protected void executeRequest() throws WebdavException {
           
  -        SearchQueryResult result = null;
  -        try {
  -            result = searchHelper.search (slideToken, searchQuery);
  -            sendResult (result);
  +        /**
  +         * Method executeRequest
  +         *
  +         * @throws   WebdavException
  +         *
  +         * @version  12/28/2001
  +         */
  +        protected void executeRequest() throws WebdavException {
  +            
  +            SearchQueryResult result = null;
  +            
  +            try {
  +                resp.setContentType (ReportMethod.TEXT_XML + "; charset=" +
  +                                         ReportMethod.ENCODING);
  +                
  +                result = searchHelper.search (slideToken, searchQuery);
  +                WebdavResult webdavResult = new WebdavResult (result, retriever);
  +                org.jdom.Document responseDoc = 
webdavResult.getWebdabResultDocument();
  +                sendResult (responseDoc);
  +                resp.setStatus (webdavResult.getWebdavStatus());
  +            }
  +            
  +            catch (StructureException e) {
  +                try {
  +                    resp.sendError
  +                        (WebdavStatus.SC_NOT_FOUND,
  +                         WebdavStatus.getStatusText(WebdavStatus.SC_NOT_FOUND));
  +                } catch(IOException ex) {
  +                    ex.printStackTrace();
  +                }
  +                throw new WebdavException(WebdavStatus.SC_NOT_FOUND);
  +            } catch (Exception e) {
  +                
  +                resp.setStatus(getErrorCode(e));  // no special handling needed
  +                throw new WebdavException(WebdavStatus.SC_ACCEPTED, false); // 
abort the TA
  +            }
           }
           
  -        catch (StructureException e) {
  -            try {
  -                resp.sendError
  -                    (WebdavStatus.SC_NOT_FOUND,
  -                     WebdavStatus.getStatusText(WebdavStatus.SC_NOT_FOUND));
  -            } catch(IOException ex) {
  -                ex.printStackTrace();
  -            }
  -            throw new WebdavException(WebdavStatus.SC_NOT_FOUND);
  -        } catch (Exception e) {
  -            resp.setStatus(getErrorCode(e));  // no special handling needed
  -            throw new WebdavException(WebdavStatus.SC_ACCEPTED, false); // abort 
the TA
  +        /**
  +         * Method getSearchRequestElement
  +         *
  +         * @return   an Element
  +         *
  +         * @throws   WebdavException
  +         *
  +         * @version  12/28/2001
  +         */
  +        private Element getQueryElement() throws WebdavException, SAXException {
  +            Element queryElement = null;
  +            try
  +            {
  +                Document document = parseRequestContent();
  +                Element rootElement = document.getDocumentElement();
  +                NodeList nl = rootElement.getChildNodes();
  +                for (int i = 0; i < nl.getLength(); i++) {
  +                    if (nl.item (i) instanceof Element)
  +                        queryElement = (Element)nl.item(i);
  +                }
  +                return queryElement;
  +                
  +                
  +            } catch (ParserConfigurationException e) {
  +                System.err.println(e.getMessage());
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +            } catch (IOException e) {
  +                System.err.println(e.getMessage());
  +                e.printStackTrace();
  +                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                throw new WebdavException
  +                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +            }
           }
  -        resp.setStatus (WebdavStatus.SC_MULTI_STATUS);
  -    }
  -    
  -    /**
  -     * Method getSearchRequestElement
  -     *
  -     * @return   an Element
  -     *
  -     * @throws   WebdavException
  -     *
  -     * @version  12/28/2001
  -     */
  -    private Element getQueryElement() throws WebdavException {
  -        Element queryElement = null;
  -        try
  +        
  +        /**
  +         * Method sendResult
  +         *
  +         * @param    responseDoc         a  Document
  +         *
  +         * @throws   JDOMException
  +         * @throws   IOException
  +         *
  +         */
  +        private void  sendResult (org.jdom.Document responseDoc)
  +            throws org.jdom.JDOMException, IOException
           {
  -            Document document = parseRequestContent();
  -            Element rootElement = document.getDocumentElement();
  -            NodeList nl = rootElement.getChildNodes();
  -            for (int i = 0; i < nl.getLength(); i++) {
  -                if (nl.item (i) instanceof Element)
  -                    queryElement = (Element)nl.item(i);
  -            }
  -            return queryElement;
  -            
  -        } catch (SAXException e) {
  -            resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  -        } catch (ParserConfigurationException e) {
  -            System.err.println(e.getMessage());
  -            resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  -            throw new WebdavException
  -                (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  -        } catch (IOException e) {
  -            System.err.println(e.getMessage());
  -            e.printStackTrace();
  -            resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  -            throw new WebdavException
  -                (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +            XMLOutputter xmlWriter = new XMLOutputter ();
  +            xmlWriter.output (responseDoc, resp.getWriter());
           }
  -    }
  -    
  -    private void sendResult (SearchQueryResult result) throws
  -        SlideException, org.jdom.JDOMException, IOException
  -    {
           
  -        resp.setContentType (ReportMethod.TEXT_XML + "; charset=" +
  -                                 ReportMethod.ENCODING);
  -        
  -        
  -        org.jdom.Namespace namespace = org.jdom.Namespace.getNamespace ("D", 
"DAV:");
  -        org.jdom.Element element =
  -            new org.jdom.Element (WebdavConstants.E_MULTISTATUS, namespace);
  -        
  -        org.jdom.Document responseDoc = new org.jdom.Document (element);
  -        
  -        resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
  -        
  -        PropertyRetriever retriever = new PropertyRetrieverImpl
  -            (token, slideToken);
  -        
  -        Iterator it = result.iterator();
  -        String serverURL = "http://"; + req.getServerName()+ ":" + 
req.getServerPort();
  -        while (it.hasNext()) {
  -            
  -            org.jdom.Element responseElement =
  -                new org.jdom.Element (WebdavConstants.E_RESPONSE, namespace);
  -            
  -            element.addContent (responseElement);
  -            org.jdom.Element hrefElement =
  -                new org.jdom.Element (WebdavConstants.E_HREF, namespace);
  -            
  -            RequestedResource resource = (RequestedResource)it.next();
  -            String uri = resource.getHref();
  -            hrefElement.addContent(uri);
  -            responseElement.addContent (hrefElement);
  -            List propstatList= retriever.getPropertiesOfObject (requestedProperties,
  -                                                 uri,
  -                                                 req.getContextPath(),
  -                                                 serverURL,
  -                                                                true);
  -            Iterator iterator = propstatList.iterator();
  -            while (iterator.hasNext()) {
  -                responseElement.addContent((org.jdom.Element)iterator.next());
  +        /**
  +         * Method createErrorResult
  +         *
  +         * @param    queryStatus         an int
  +         * @param    message             a  String
  +         *
  +         */
  +        private void createErrorResult (int queryStatus, String message) {
  +            SearchQueryResult result = new SearchQueryResult ();
  +            result.setStatus (queryStatus);
  +            result.setDescription (message);
  +            result.setHref (req.getContextPath());
  +            
  +            try {
  +                WebdavResult webdavResult = new WebdavResult (result, retriever);
  +                org.jdom.Document responseDoc = 
webdavResult.getWebdabResultDocument();
  +                sendResult (responseDoc);
               }
  +            catch (Exception e) {}
           }
           
  -        XMLOutputter xmlWriter = new XMLOutputter ();
  -        xmlWriter.output (responseDoc, resp.getWriter());
  +        /**
  +         * Represents the webdav result for a SEARCH. It encapsulates the response
  +         * body, and the status of the response. It contains a list of response
  +         * elements with propstat elements and optional a response element with
  +         * an error status and a responsedescription
  +         */
  +        class WebdavResult {
  +            
  +            private SearchQueryResult queryResult;
  +            private org.jdom.Document responseDoc;
  +            private PropertyRetriever retriever;
  +            
  +            /** the status of the response */
  +            private int webdavStatus = WebdavStatus.SC_MULTI_STATUS;
  +            
  +            /**
  +             * constructs a WebdavResult
  +             *
  +             * @param    queryResult         the result of the query
  +             * @param    retriever           the retriever to get the properties
  +             *
  +             * @throws   JDOMException
  +             * @throws   SlideException
  +             *
  +             */
  +            WebdavResult (SearchQueryResult queryResult, PropertyRetriever 
retriever)
  +                throws org.jdom.JDOMException, SlideException
  +            {
  +                this.queryResult = queryResult;
  +                this.retriever = retriever;
  +                init();
  +            }
  +            
  +            /**
  +             * Method getWebdavStatus
  +             *
  +             * @return   an int
  +             *
  +             */
  +            int getWebdavStatus () {
  +                return webdavStatus;
  +            }
  +            
  +            /**
  +             * Method getWebdabResultDocument
  +             *
  +             * @return   a Document
  +             *
  +             */
  +            org.jdom.Document getWebdabResultDocument () {
  +                return responseDoc;
  +            }
  +            
  +            /**
  +             * Method init
  +             *
  +             * @throws   JDOMException
  +             * @throws   SlideException
  +             *
  +             */
  +            private void init () throws org.jdom.JDOMException, SlideException {
  +                
  +                String href = null;
  +                int errorStatus = webdavStatus;
  +                
  +                org.jdom.Namespace namespace = org.jdom.Namespace.getNamespace 
("D", "DAV:");
  +                org.jdom.Element rootElement =
  +                    new org.jdom.Element (WebdavConstants.E_MULTISTATUS, namespace);
  +                
  +                responseDoc = new org.jdom.Document (rootElement);
  +                
  +                Iterator it = queryResult.iterator();
  +                String serverURL = "http://"; + req.getServerName()+ ":" + 
req.getServerPort();
  +                while (it.hasNext()) {
  +                    
  +                    org.jdom.Element responseElement =
  +                        new org.jdom.Element (WebdavConstants.E_RESPONSE, 
namespace);
  +                    
  +                    rootElement.addContent (responseElement);
  +                    org.jdom.Element hrefElement =
  +                        new org.jdom.Element (WebdavConstants.E_HREF, namespace);
  +                    
  +                    RequestedResource resource = (RequestedResource)it.next();
  +                    String uri = resource.getHref();
  +                    hrefElement.addContent(uri);
  +                    responseElement.addContent (hrefElement);
  +                    List propstatList= retriever.getPropertiesOfObject 
(requestedProperties,
  +                                                                        uri,
  +                                                                        
req.getContextPath(),
  +                                                                        serverURL,
  +                                                                        true);
  +                    Iterator iterator = propstatList.iterator();
  +                    while (iterator.hasNext()) {
  +                        
responseElement.addContent((org.jdom.Element)iterator.next());
  +                    }
  +                }
  +                
  +                if (queryResult.getStatus() != SearchQueryResult.STATUS_OK) {
  +                    
  +                    String webdavStatusText = null;
  +                    
  +                    switch (queryResult.getStatus()) {
  +                        case SearchQueryResult.STATUS_BAD_QUERY:
  +                            webdavStatus = WebdavStatus.SC_BAD_REQUEST;
  +                            errorStatus = WebdavStatus.SC_BAD_REQUEST;
  +                            href = queryResult.getHref();
  +                            break;
  +                            
  +                        case SearchQueryResult.STATUS_INVALID_SCOPE:
  +                            webdavStatus = WebdavStatus.SC_BAD_REQUEST;
  +                            errorStatus = WebdavStatus.SC_BAD_REQUEST;
  +                            href = queryResult.getHref();
  +                            break;
  +                            
  +                        case SearchQueryResult.STATUS_PARTIAL_RESULT:
  +                            errorStatus = WebdavStatus.SC_INSUFFICIENT_STORAGE;
  +                            href = req.getContextPath();
  +                            break;
  +                            
  +                        default:
  +                            break;
  +                    }
  +                    org.jdom.Element responseElement =
  +                        new org.jdom.Element (WebdavConstants.E_RESPONSE, 
namespace);
  +                    
  +                    org.jdom.Element hrefElement =
  +                        new org.jdom.Element (WebdavConstants.E_HREF, namespace);
  +                    
  +                    hrefElement.addContent (href);
  +                    
  +                    org.jdom.Element statusElement =
  +                        new org.jdom.Element (WebdavConstants.E_STATUS, namespace);
  +                    
  +                    statusElement.addContent (getStatusText (errorStatus));
  +                    
  +                    org.jdom.Element responseDescriptionElement =
  +                        new org.jdom.Element 
(WebdavConstants.E_RESPONSEDESCRIPTION, namespace);
  +                    
  +                    responseDescriptionElement.addContent 
(queryResult.getDescription());
  +                    
  +                    responseElement.addContent (hrefElement);
  +                    responseElement.addContent (statusElement);
  +                    responseElement.addContent (responseDescriptionElement);
  +                    rootElement.addContent (responseElement);
  +                }
  +            }
  +            
  +            /**
  +             * Method getStatusText
  +             *
  +             * @param    status              an int
  +             *
  +             * @return   a String
  +             *
  +             */
  +            private String getStatusText (int status) {
  +                return  "HTTP/1.1 " + status + " "
  +                    + WebdavStatus.getStatusText (status);
  +            }
  +        }
       }
  -    
  -}
  -
  
  
  
  1.3       +48 -32    
jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java
  
  Index: BasicQuery.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BasicQuery.java   8 Mar 2002 09:51:50 -0000       1.2
  +++ BasicQuery.java   19 Mar 2002 17:27:53 -0000      1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v 1.2 
2002/03/08 09:51:50 wam Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/03/08 09:51:50 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v 1.3 
2002/03/19 17:27:53 wam Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/03/19 17:27:53 $
    *
    * ====================================================================
    *
  @@ -92,7 +92,7 @@
    * BasicSearchExpressions.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class BasicQuery extends SearchQuery {
       
  @@ -120,7 +120,7 @@
       /** the top level expression in the <WHERE> clause */
       private BasicExpression rootExpression;
       
  -        
  +    
       
       // TODO: <ORDERBY>
       
  @@ -147,9 +147,9 @@
           }
       }
       
  -//    BasicQuery (String queryString) throws BadQueryException {
  -//      this (queryString, Integer.MAX_VALUE);
  -//    }
  +    //    BasicQuery (String queryString) throws BadQueryException {
  +    //      this (queryString, Integer.MAX_VALUE);
  +    //    }
       
       
       /**
  @@ -162,15 +162,15 @@
        * @throws BadQueryException
        */
       BasicQuery (org.w3c.dom.Element basicSearchElementDOM, SearchToken token) 
throws BadQueryException {
  -
  +        
           this.searchToken = token;
  -
  +        
           org.jdom.Element basicSearchElementJDom =
               new DOMBuilder ().build (basicSearchElementDOM);
  -
  +        
           parseQueryElement (basicSearchElementJDom);
       }
  -        
  +    
       
       /**
        * Constructs a query from queryElement. queryElement is a DOM
  @@ -185,7 +185,7 @@
           this.searchToken = token;
           parseQueryElement (basicSearchElementJDOM);
       }
  -        
  +    
       
       /**
        * Executes a request. A store specific implementation should overwrite
  @@ -203,23 +203,28 @@
               requestedResources =
                   new RequestedResourcesPoolImpl (searchToken, scope);
               
  -            Set pool = requestedResources.getPool (); // !!!!
  -            // from where we get our root pool?
  -            // Set rootPool = propertyResolver.getPool();
  -            
  -            //
  +            Set pool = requestedResources.getPool ();
               rootExpression.resolve (pool);
  +            
               if (rootExpression.isResolved ()) {
                   result = new SearchQueryResult (rootExpression.getResultSet());
                   
  +                if (requestedResources.partialResult()) {
  +                    result.setStatus(SearchQueryResult.STATUS_PARTIAL_RESULT);
  +                    result.setDescription ("The server truncated the result set");
  +                }
               }
           }
           
  -        catch (BadQueryException e) { // TODO: correct exception handling!
  -            e.printStackTrace();
  +        catch (BadQueryException e) { // is this only INVALID_SCOPE?
  +            result = new SearchQueryResult ();
  +            result.setStatus (SearchQueryResult.STATUS_INVALID_SCOPE);
  +            result.setDescription (e.getMessage());
  +            result.setHref (scope.getHref());
  +        }
  +        finally  {
  +            return result;
           }
  -        
  -        return result;
       }
       
       
  @@ -304,18 +309,28 @@
           Element limitElement = basicSearchElement.getChild
               (Literals.LIMIT, namespace);
           
  +        Element propElement = selectElement.getChild (Literals.PROP, namespace);
  +        if (propElement == null)
  +            propElement = selectElement.getChild (Literals.ALLPROP, namespace);
  +        
  +        if (propElement == null)
  +            throw new BadQueryException ("required element <prop> or <allprop> not 
supplied");
  +        
  +        requestedProperties = new RequestedPropertiesImpl (propElement);
           
           scope = new BasicQueryScope (fromElement);
  -        requestedProperties = new RequestedPropertiesImpl
  -            (selectElement.getChild (Literals.PROP, namespace));
           
           // TODO orderby...
           
  -        // if no where clause is supplied, use a dummy expression
  -        List expressionList = whereElement.getChildren();
  -        
  -        rootExpression = BasicExpression.createExpression
  -            ((Element) expressionList.get (0));
  +        // <where> is not manatory
  +        if (whereElement != null) {
  +            List expressionList = whereElement.getChildren();
  +            
  +            rootExpression = BasicExpression.createExpression
  +                ((Element) expressionList.get (0));
  +        }
  +        else
  +            rootExpression = BasicExpression.createExpression (null);
           
           if (limitElement != null) {
               limit = new Integer (limitElement.getTextTrim()).intValue();
  @@ -332,10 +347,11 @@
        */
       public String toString () {
           
  -        return
  -            "SELECT [" + requestedProperties + "] FROM [" + scope
  -            + "] WHERE [" + rootExpression + "]";
  +        String result =
  +            "SELECT [" + requestedProperties + "] FROM [" + scope + "] "
  +            + "WHERE [" + rootExpression + "]";
           
  +        return result;
       }
       
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to