wam         02/03/20 07:40:17

  Modified:    src/share/org/apache/slide/search SearchQueryResult.java
                        SearchImpl.java Search.java
               src/webdav/server/org/apache/slide/webdav/method
                        SearchMethod.java
               src/share/org/apache/slide/search/basic BasicQuery.java
  Log:
  code cleanup
  enable UNPROCESSABLE_ENTITY
  
  Revision  Changes    Path
  1.5       +1 -0      
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SearchQueryResult.java    19 Mar 2002 17:27:52 -0000      1.4
  +++ SearchQueryResult.java    20 Mar 2002 15:40:16 -0000      1.5
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java,v 1.5 
2002/03/20 15:40:16 wam Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/03/20 15:40:16 $
    *
    * ====================================================================
    *
  @@ -77,7 +77,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
    *
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class SearchQueryResult extends HashSet {
       
  @@ -85,6 +85,7 @@
       public final static int STATUS_BAD_QUERY      = 1;
       public final static int STATUS_INVALID_SCOPE  = 2;
       public final static int STATUS_PARTIAL_RESULT = 3;
  +    public final static int STATUS_UNPROCESSABLE_ENTITY = 4;
       
       private int status;
       private String description;
  
  
  
  1.7       +94 -71    jakarta-slide/src/share/org/apache/slide/search/SearchImpl.java
  
  Index: SearchImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SearchImpl.java   14 Feb 2002 17:05:03 -0000      1.6
  +++ SearchImpl.java   20 Mar 2002 15:40:16 -0000      1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchImpl.java,v 1.6 
2002/02/14 17:05:03 wam Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/02/14 17:05:03 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchImpl.java,v 1.7 
2002/03/20 15:40:16 wam Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/03/20 15:40:16 $
    *
    * ====================================================================
    *
  @@ -87,7 +87,7 @@
    * Search helper.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public final class SearchImpl implements Search {
       
  @@ -95,19 +95,19 @@
       
       
       /**
  -      * Constructor.
  -      *
  -      * @param namespace Namespace
  -      * @param namespaceConfig Namespace configuration
  -      */
  +     * Constructor.
  +     *
  +     * @param namespace Namespace
  +     * @param namespaceConfig Namespace configuration
  +     */
       public SearchImpl(Namespace namespace,
  -                                       NamespaceConfig namespaceConfig,
  -                                       Structure structureHelper,
  -                                       Content contentHelper) {
  -             this.namespace = namespace;
  -             this.namespaceConfig = namespaceConfig;
  -             this.structureHelper = structureHelper;
  -             this.contentHelper = contentHelper;
  +                      NamespaceConfig namespaceConfig,
  +                      Structure structureHelper,
  +                      Content contentHelper) {
  +        this.namespace = namespace;
  +        this.namespaceConfig = namespaceConfig;
  +        this.structureHelper = structureHelper;
  +        this.contentHelper = contentHelper;
       }
       
       
  @@ -115,42 +115,42 @@
       
       // TODO: must be configurable in domain.xml (Namespace.java)
       private static final SearchLanguage [] SEARCH_LANGUAGES = {
  -             new BasicSearchLanguage ()
  +        new BasicSearchLanguage ()
       };
       
       
       private static final Map GRAMMAR_BY_URI = new HashMap ();
       static {
  -             for (int i = 0; i < SEARCH_LANGUAGES.length; i++)
  -                     GRAMMAR_BY_URI.put (SEARCH_LANGUAGES [i].getGrammarUri(),
  -                                                             SEARCH_LANGUAGES [i]);
  +        for (int i = 0; i < SEARCH_LANGUAGES.length; i++)
  +            GRAMMAR_BY_URI.put (SEARCH_LANGUAGES [i].getGrammarUri(),
  +                                SEARCH_LANGUAGES [i]);
       }
       
       /**
  -      * Log channel for logger
  -      */
  +     * Log channel for logger
  +     */
       private final static String LOG_CHANNEL = SearchImpl.class.getName();
       
       
       /**
  -      * Namespace.
  -      */
  +     * Namespace.
  +     */
       private Namespace namespace;
       
       /**
  -      * Structure.
  -      */
  +     * Structure.
  +     */
       private Structure structureHelper;
       
       
       /**
  -      * Namespace configuration.
  -      */
  +     * Namespace configuration.
  +     */
       private NamespaceConfig namespaceConfig;
       
       /**
  -      * Namespace configuration.
  -      */
  +     * Namespace configuration.
  +     */
       private Content contentHelper;
       
       
  @@ -158,56 +158,79 @@
       
       
       /**
  -      * Search.
  -      *
  -      * @param token Credentials token
  -      * @param object Object on which permission is granted
  -      * @exception ServiceAccessException DataSource access error
  -      */
  +     * Search.
  +     *
  +     * @param token Credentials token
  +     * @param object Object on which permission is granted
  +     * @exception ServiceAccessException DataSource access error
  +     */
       public SearchQueryResult search (SlideToken token, SearchQuery query)
  -             throws ServiceAccessException {
  -             return query.execute ();
  +        throws ServiceAccessException {
  +        return query.execute ();
       }
       
       
       /**
  -      * Return the allowed query languages.
  -      */
  +     * Return the allowed query languages.
  +     */
       public SearchLanguage[] getSupportedLanguages () {
  -             return SEARCH_LANGUAGES;
  +        return SEARCH_LANGUAGES;
       }
       
       
  +    /**
  +     * Retrieve a SearchLanguage identified by the grammar uri (namespace)
  +     *
  +     * @param    grammarUri          identifier for the SearchLanguage
  +     *
  +     * @return   the SearchLanguage
  +     *
  +     * @throws   BadQueryException
  +     *
  +     */
       public SearchLanguage getLanguage (String grammarUri)
  -             throws BadQueryException
  +        throws BadQueryException
       {
  -             SearchLanguage result =(SearchLanguage) GRAMMAR_BY_URI.get 
(grammarUri);
  -             if (result == null)
  -                     throw new BadQueryException ("grammar not found: " + 
grammarUri);
  -             
  -             return result;
  -    }
  -     
  -     
  -    
  -    
  -     public SearchQuery getSearchQuery (String grammarUri,
  -                                                                        Element 
queryElement,
  -                                                                        SlideToken 
token,
  -                                                                        int 
maxDepth)
  -             throws BadQueryException
  -     {
  -             SearchQuery result = null;
  -             // create search token
  -             SearchToken searchToken =
  -                     SearchToken.createSearchToken (token, contentHelper, 
structureHelper, maxDepth);
  -             
  -             SearchLanguage language = getLanguage (grammarUri);
  -             result = language.parseQuery (queryElement, searchToken);
  -             
  -             
  -             return result;
  -     }
  -     
  -     
  +        SearchLanguage result =(SearchLanguage) GRAMMAR_BY_URI.get (grammarUri);
  +        if (result == null)
  +            throw new BadQueryException ("grammar not found: " + grammarUri);
  +        
  +        return result;
  +    }
  +    
  +    
  +    
  +    
  +    /**
  +     * Creates a SearchQuery.
  +     *
  +     * @param    grammarUri          identifier for the SearchLanguage
  +     * @param    queryElement        the element containing the query
  +     * @param    token               the SlideToken
  +     * @param    maxDepth            may be 0, 1 or INFINIT
  +     *
  +     * @return   the SearchQuery
  +     *
  +     * @throws   BadQueryException
  +     *
  +     */
  +    public SearchQuery createSearchQuery (String grammarUri,
  +                                       Element queryElement,
  +                                       SlideToken token,
  +                                       int maxDepth)
  +        throws BadQueryException
  +    {
  +        SearchQuery result = null;
  +        // create search token
  +        SearchToken searchToken =
  +            SearchToken.createSearchToken (token, contentHelper, structureHelper, 
maxDepth);
  +        
  +        SearchLanguage language = getLanguage (grammarUri);
  +        result = language.parseQuery (queryElement, searchToken);
  +        
  +        
  +        return result;
  +    }
  +    
  +    
   }
  
  
  
  1.6       +12 -12    jakarta-slide/src/share/org/apache/slide/search/Search.java
  
  Index: Search.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/Search.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Search.java       14 Feb 2002 17:05:03 -0000      1.5
  +++ Search.java       20 Mar 2002 15:40:16 -0000      1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/Search.java,v 
1.5 2002/02/14 17:05:03 wam Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/02/14 17:05:03 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/Search.java,v 
1.6 2002/03/20 15:40:16 wam Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/03/20 15:40:16 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    * Search helper.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public interface Search {
       
  @@ -114,12 +114,12 @@
        *
        */
       SearchLanguage getLanguage (String grammarUri)
  -             throws BadQueryException;
  -     
  -     
  -     SearchQuery getSearchQuery (String grammarUri,
  -                                                             Element 
searchRequestElement,
  -                                                             SlideToken token,
  -                                                             int maxDepth)
  -             throws BadQueryException;
  +        throws BadQueryException;
  +    
  +    
  +    SearchQuery createSearchQuery (String grammarUri,
  +                                Element searchRequestElement,
  +                                SlideToken token,
  +                                int maxDepth)
  +        throws BadQueryException;
   }
  
  
  
  1.10      +263 -242  
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SearchMethod.java 19 Mar 2002 17:27:53 -0000      1.9
  +++ SearchMethod.java 20 Mar 2002 15:40:17 -0000      1.10
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/SearchMethod.java,v
 1.10 2002/03/20 15:40:17 wam Exp $
  + * $Revision: 1.10 $
  + * $Date: 2002/03/20 15:40:17 $
    *
    * ====================================================================
    *
  @@ -156,304 +156,325 @@
                   // SearchLanguage language = searchHelper.getLanguage 
(grammarNamespace);
                   int maxDepth = getConfig().getDepthLimit();
                   
  -                searchQuery = searchHelper.getSearchQuery
  +                searchQuery = searchHelper.createSearchQuery
                       (grammarNamespace, queryElement, slideToken, maxDepth);
                   
                   requestedProperties = searchQuery.requestedProperties ();
               }
               catch (SAXException e) {
                   resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +                resp.setContentType (TEXT_XML);
                   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);
  -                }
  +                resp.setStatus(WebdavStatus.SC_UNPROCESSABLE_ENTITY);
  +                resp.setContentType (TEXT_XML);
  +                createErrorResult (SearchQueryResult.STATUS_UNPROCESSABLE_ENTITY,
  +                                   e.getMessage());
  +                throw new WebdavException(WebdavStatus.SC_UNPROCESSABLE_ENTITY);
               }
  -            else {
  +            catch (BadQueryException e) {
                   resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -                createErrorResult (SearchQueryResult.STATUS_BAD_QUERY, "SEARCH not 
implemented on this server");
                   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;
           
  -        /**
  -         * 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.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());
  +                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) {
               
  -            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
  -            }
  +            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);
  +        }
  +    }
  +    
  +    /**
  +     * Method sendResult
  +     *
  +     * @param    responseDoc         a  Document
  +     *
  +     * @throws   JDOMException
  +     * @throws   IOException
  +     *
  +     */
  +    private void  sendResult (org.jdom.Document responseDoc)
  +        throws org.jdom.JDOMException, IOException
  +    {
  +        XMLOutputter xmlWriter = new XMLOutputter ();
  +        xmlWriter.output (responseDoc, resp.getWriter());
  +    }
  +    
  +    /**
  +     * 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) {}
  +    }
  +    
  +    /**
  +     * 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;
           
           /**
  -         * Method getSearchRequestElement
  +         * constructs a WebdavResult
            *
  -         * @return   an Element
  +         * @param    queryResult         the result of the query
  +         * @param    retriever           the retriever to get the properties
            *
  -         * @throws   WebdavException
  +         * @throws   JDOMException
  +         * @throws   SlideException
            *
  -         * @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);
  -            }
  +        WebdavResult (SearchQueryResult queryResult, PropertyRetriever retriever)
  +            throws org.jdom.JDOMException, SlideException
  +        {
  +            this.queryResult = queryResult;
  +            this.retriever = retriever;
  +            init();
           }
           
           /**
  -         * Method sendResult
  -         *
  -         * @param    responseDoc         a  Document
  +         * Method getWebdavStatus
            *
  -         * @throws   JDOMException
  -         * @throws   IOException
  +         * @return   an int
            *
            */
  -        private void  sendResult (org.jdom.Document responseDoc)
  -            throws org.jdom.JDOMException, IOException
  -        {
  -            XMLOutputter xmlWriter = new XMLOutputter ();
  -            xmlWriter.output (responseDoc, resp.getWriter());
  +        int getWebdavStatus () {
  +            return webdavStatus;
           }
           
           /**
  -         * Method createErrorResult
  +         * Method getWebdabResultDocument
            *
  -         * @param    queryStatus         an int
  -         * @param    message             a  String
  +         * @return   a Document
            *
            */
  -        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) {}
  +        org.jdom.Document getWebdabResultDocument () {
  +            return responseDoc;
           }
           
           /**
  -         * 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
  +         * Method init
  +         *
  +         * @throws   JDOMException
  +         * @throws   SlideException
  +         *
            */
  -        class WebdavResult {
  -            
  -            private SearchQueryResult queryResult;
  -            private org.jdom.Document responseDoc;
  -            private PropertyRetriever retriever;
  +        private void init () throws org.jdom.JDOMException, SlideException {
               
  -            /** the status of the response */
  -            private int webdavStatus = WebdavStatus.SC_MULTI_STATUS;
  +            String href = null;
  +            int errorStatus = webdavStatus;
               
  -            /**
  -             * 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;
  +            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());
  +                }
               }
               
  -            /**
  -             * 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());
  -                    }
  +            int status = queryResult.getStatus();
  +            if (status != SearchQueryResult.STATUS_OK) {
  +                
  +                String webdavStatusText = null;
  +                
  +                switch (status) {
  +                    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_NOT_FOUND;
  +                        href = queryResult.getHref();
  +                        break;
  +                        
  +                    case SearchQueryResult.STATUS_PARTIAL_RESULT:
  +                        errorStatus = WebdavStatus.SC_INSUFFICIENT_STORAGE;
  +                        href = req.getContextPath();
  +                        break;
  +                        
  +                    case SearchQueryResult.STATUS_UNPROCESSABLE_ENTITY:
  +                        errorStatus = WebdavStatus.SC_UNPROCESSABLE_ENTITY;
  +                        href = req.getContextPath();
  +                        break;
  +                        
  +                    default:
  +                        throw new WebdavException
  +                            (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                        
                   }
  +                org.jdom.Element responseElement =
  +                    new org.jdom.Element (WebdavConstants.E_RESPONSE, namespace);
                   
  -                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 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));
  +                responseElement.addContent (hrefElement);
  +                responseElement.addContent (statusElement);
  +                
  +                String description = queryResult.getDescription();
  +                if (description != null) {
                       org.jdom.Element responseDescriptionElement =
  -                        new org.jdom.Element 
(WebdavConstants.E_RESPONSEDESCRIPTION, namespace);
  -                    
  -                    responseDescriptionElement.addContent 
(queryResult.getDescription());
  +                        new org.jdom.Element (WebdavConstants.E_RESPONSEDESCRIPTION,
  +                                              namespace);
                       
  -                    responseElement.addContent (hrefElement);
  -                    responseElement.addContent (statusElement);
  +                    responseDescriptionElement.addContent (description);
                       responseElement.addContent (responseDescriptionElement);
  -                    rootElement.addContent (responseElement);
                   }
  +                
  +                if (status == SearchQueryResult.STATUS_INVALID_SCOPE) {
  +                    responseElement.addContent (
  +                        new org.jdom.Element ("scopeerror",
  +                                              namespace));
  +                }
  +                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);
  -            }
  +        }
  +        
  +        /**
  +         * Method getStatusText
  +         *
  +         * @param    status              an int
  +         *
  +         * @return   a String
  +         *
  +         */
  +        private String getStatusText (int status) {
  +            return  "HTTP/1.1 " + status + " "
  +                + WebdavStatus.getStatusText (status);
           }
       }
  +}
  
  
  
  1.4       +7 -1      
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicQuery.java   19 Mar 2002 17:27:53 -0000      1.3
  +++ BasicQuery.java   20 Mar 2002 15:40:17 -0000      1.4
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v 1.4 
2002/03/20 15:40:17 wam Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/03/20 15:40:17 $
    *
    * ====================================================================
    *
  @@ -92,7 +92,7 @@
    * BasicSearchExpressions.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class BasicQuery extends SearchQuery {
       
  @@ -216,9 +216,15 @@
               }
           }
           
  -        catch (BadQueryException e) { // is this only INVALID_SCOPE?
  +        catch (InvalidScopeException e) {
               result = new SearchQueryResult ();
               result.setStatus (SearchQueryResult.STATUS_INVALID_SCOPE);
  +            result.setHref (scope.getHref());
  +        }
  +        
  +        catch (BadQueryException e) { // is this only INVALID_SCOPE?
  +            result = new SearchQueryResult ();
  +            result.setStatus (SearchQueryResult.STATUS_BAD_QUERY);
               result.setDescription (e.getMessage());
               result.setHref (scope.getHref());
           }
  
  
  

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

Reply via email to