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 wa...@apache.org on 2002/03/22 15:32:38 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/search CompareHint.java RequestedResource.java RequestedResourceImpl.java SearchQueryResult.java

wam         02/03/22 06:32:37

  Modified:    src/share/org/apache/slide/search/basic BasicExpression.java
                        BasicQuery.java CompareExpression.java
                        Literals.java MergeExpression.java
               src/share/org/apache/slide/search RequestedResource.java
                        RequestedResourceImpl.java SearchQueryResult.java
  Added:       src/share/org/apache/slide/search/basic
                        IsCollectionExpression.java
                        IsDefinedExpression.java NotExpression.java
                        OrderBy.java
               src/share/org/apache/slide/search CompareHint.java
  Log:
  implement orderby, is-collection, isdefined
  
  Revision  Changes    Path
  1.3       +34 -25    jakarta-slide/src/share/org/apache/slide/search/basic/BasicExpression.java
  
  Index: BasicExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicExpression.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BasicExpression.java	8 Mar 2002 12:07:19 -0000	1.2
  +++ BasicExpression.java	22 Mar 2002 14:32:37 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicExpression.java,v 1.2 2002/03/08 12:07:19 wam Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/03/08 12:07:19 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicExpression.java,v 1.3 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -81,7 +81,7 @@
    *
    *
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public abstract class BasicExpression {
       
  @@ -107,7 +107,7 @@
       protected BasicExpression (Element e) {
           this.expressionElement = e;
       }
  -    
  +   
       /**
        * Factory method to create the concrete expression.
        *
  @@ -127,28 +127,37 @@
               result = new EmptyExpression ();
           }
           else {
  -        String name = e.getName();
  -        
  -        if (name.equals (Literals.AND))
  -            result = new AndExpression (e);
  -            
  -        else if (name.equals (Literals.OR))
  -            result = new OrExpression (e);
  -            
  -        else if (name.equals (Literals.GT))
  -            result = new GTExpression (e);
  +            String name = e.getName();
               
  -       else if (name.equals (Literals.LT))
  -            result = new LTExpression (e);
  -            
  -        else if (name.equals (Literals.EQ))
  -            result = new EQExpression (e);
  -            
  -        else
  -            throw new InvalidQueryException
  -                ("operator " + name + " is an unprocessable entity");
  +            if (name.equals (Literals.AND))
  +                result = new AndExpression (e);
  +                
  +            else if (name.equals (Literals.OR))
  +                result = new OrExpression (e);
  +                
  +            else if (name.equals (Literals.GT))
  +                result = new GTExpression (e);
  +                
  +            else if (name.equals (Literals.LT))
  +                result = new LTExpression (e);
  +                
  +            else if (name.equals (Literals.EQ))
  +                result = new EQExpression (e);
  +                
  +            else if (name.equals (Literals.ISCOLLECTION))
  +                result = new IsCollectionExpression (e);
  +                
  +            else if (name.equals (Literals.ISDEFINED))
  +                result = new IsDefinedExpression (e);
  +                
  +            else if (name.equals (Literals.NOT))
  +                result = new NotExpression (e);
  +                
  +            else
  +                throw new InvalidQueryException
  +                    ("operator " + name + " is an unprocessable entity");
           }
  -        
  +
           return result;
           
       }
  
  
  
  1.5       +25 -25    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasicQuery.java	20 Mar 2002 15:40:17 -0000	1.4
  +++ BasicQuery.java	22 Mar 2002 14:32:37 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v 1.5 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -88,15 +88,15 @@
    * A BasicSearchQuery represents the query and is able to deliver a
    * SearchQueryResult using the execute method. It may serve as a base class for
    * store specific implementations. It hosts the information about the SELECT,
  - * FROM, WHERE, ORDERBY and LIMIT. It also hold a tree of
  + * FROM, WHERE, ORDERBY and LIMIT. It also holds a tree of
    * BasicSearchExpressions.
    *
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class BasicQuery extends SearchQuery {
       
  -    // this should somehow be replaced
  +    /** all resources within the scope */
       private RequestedResourcesPool requestedResources;
       
       /** the element describing this query */
  @@ -114,16 +114,16 @@
       /** <LIMIT> */
       private int limit;
       
  +    /** ORDER BY */
  +    private OrderBy orderBy;
  +    
       /** indicates, if a limit is defined */
       private boolean limitDefined = false;
       
       /** the top level expression in the <WHERE> clause */
       private BasicExpression rootExpression;
       
  -    
  -    
  -    // TODO: <ORDERBY>
  -    
  +   
       /**
        * Constructs a query from the queryString. queryString is an XML
        * document according to the DASL basicsearch specfication.
  @@ -147,11 +147,6 @@
           }
       }
       
  -    //    BasicQuery (String queryString) throws BadQueryException {
  -    //      this (queryString, Integer.MAX_VALUE);
  -    //    }
  -    
  -    
       /**
        * Constructs a query from queryElement. queryElement is a DOM
        * element <searchrequest> according to the DASL basicsearch
  @@ -207,8 +202,13 @@
               rootExpression.resolve (pool);
               
               if (rootExpression.isResolved ()) {
  -                result = new SearchQueryResult (rootExpression.getResultSet());
  -                
  +                if (orderBy != null) {
  +                    result = new SearchQueryResult (rootExpression.getResultSet(),
  +                                                   orderBy.getComparator());
  +                }
  +                else {
  +                    result = new SearchQueryResult (rootExpression.getResultSet());
  +                }
                   if (requestedResources.partialResult()) {
                       result.setStatus(SearchQueryResult.STATUS_PARTIAL_RESULT);
                       result.setDescription ("The server truncated the result set");
  @@ -235,9 +235,9 @@
       
       
       /**
  -     * Method getScope
  +     * QueryScope accessor
        *
  -     * @return   a Scope
  +     * @return   the Scope
        *
        */
       QueryScope getScope () {
  @@ -275,12 +275,11 @@
       int getLimit () {
           return limit;
       }
  -    
  -    
  +        
       /**
  -     * builds the internal structure out of the JDOM tree
  +     * builds the internal structure from the JDOM tree
        *
  -     * @param    root                an Element
  +     * @param    basicSearchElement                an Element
        *
        * @throws   BadQueryException
        */
  @@ -326,9 +325,10 @@
           
           scope = new BasicQueryScope (fromElement);
           
  -        // TODO orderby...
  +        if (orderByElement != null)
  +            orderBy = new OrderBy (orderByElement);
           
  -        // <where> is not manatory
  +        // <where> is not mandatory
           if (whereElement != null) {
               List expressionList = whereElement.getChildren();
               
  
  
  
  1.3       +54 -15    jakarta-slide/src/share/org/apache/slide/search/basic/CompareExpression.java
  
  Index: CompareExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/CompareExpression.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CompareExpression.java	14 Feb 2002 17:05:02 -0000	1.2
  +++ CompareExpression.java	22 Mar 2002 14:32:37 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/CompareExpression.java,v 1.2 2002/02/14 17:05:02 wam Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/14 17:05:02 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/CompareExpression.java,v 1.3 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -73,22 +73,27 @@
   
   import org.apache.slide.search.InvalidQueryException;
   
  -
   /**
  - * Abstract base class for compare expressions (GT, EQ, ...).
  + * Abstract base class for compare expressions (GT, EQ, is-collection ...).
    *
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public abstract class CompareExpression extends BasicExpression {
       
       /** the property name <prop> */
       protected String property;
  -
  +    
       /** the property's value <literal> */
       protected String literal;
       
       /**
  +     * dummy constructor, called by is-collection (as no prop / literal
  +     * is passed).
  +     */
  +    CompareExpression () {}
  +    
  +    /**
        * Creates a compare expression according to Element e
        *
        * @param e jdom element, that describes the expression
  @@ -96,18 +101,54 @@
        */
       CompareExpression (Element e) throws InvalidQueryException {
           super (e);
  -        List propList =
  -            e.getChild (Literals.PROP, e.getNamespace()).getChildren();
  +        property = getPropName(e);
  +        literal  = getLiteral (e);
  +    }
  +    
  +    /**
  +     * extracs the value of <literal> of an expression
  +     *
  +     * @param    e                   an Expression
  +     *
  +     * @return   the literal as string
  +     *
  +     * @throws   InvalidQueryException if no <literal> found in e
  +     *
  +     */
  +    private String  getLiteral(Element e) throws InvalidQueryException {
  +        Element lit = e.getChild (Literals.LITERAL, e.getNamespace());
  +        if (lit == null)
  +            throw new InvalidQueryException
  +                ("No literal element supplied");
  +        
  +        return lit.getText ();
  +    }
  +    
  +    /**
  +     * extracts the property name of this expression
  +     *
  +     * @param    e                   an Expression
  +     *
  +     * @return   the property name as string
  +     *
  +     * @throws   InvalidQueryException if no or more than one
  +     *           property was supplied
  +     *
  +     */
  +    protected String getPropName(Element e) throws InvalidQueryException {
  +        Element propListElement = e.getChild (Literals.PROP, e.getNamespace());
  +        if (propListElement == null)
  +            throw new InvalidQueryException
  +                ("No property element supplied");
  +        
  +        List propList = propListElement.getChildren();
           
           if (propList.size() != 1)
               throw new InvalidQueryException
                   ("Expected exactly 1 prop element, found " + propList.size());
           
           
  -        property = ((Element)propList.get(0)).getName();
  -        
  -        Element lit = e.getChild (Literals.LITERAL, e.getNamespace());
  -        literal = lit.getText ();
  +        return ((Element)propList.get(0)).getName();
       }
       
       /**
  @@ -144,7 +185,6 @@
        */
       protected abstract boolean compare (RequestedResource item);
       
  -
       /**
        * String representation for debugging purposes.
        *
  @@ -153,6 +193,5 @@
       protected String toString (String op) {
           return "(" +property + " " + op + " " + literal + ")";
       }
  -    
   }
   
  
  
  
  1.3       +31 -23    jakarta-slide/src/share/org/apache/slide/search/basic/Literals.java
  
  Index: Literals.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/Literals.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Literals.java	14 Feb 2002 17:05:02 -0000	1.2
  +++ Literals.java	22 Mar 2002 14:32:37 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/Literals.java,v 1.2 2002/02/14 17:05:02 wam Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/14 17:05:02 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/Literals.java,v 1.3 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -67,30 +67,38 @@
    * static container for some literals.
    *
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class Literals {
   
   
  -    public static final String ALLPROP     = "allprop";
  -    public static final String AND         = "and";
  -    public static final String BASICSEARCH = "basicsearch";
  -    public static final String DEPTH       = "depth";
  -    public static final String EQ          = "eq";
  -    public static final String FROM        = "from";
  -    public static final String GT          = "gt";
  -    public static final String HREF        = "href";
  -    public static final String INFINITY    = "infinity";
  -    public static final String LIMIT       = "limit";
  -    public static final String LITERAL     = "literal";
  -    public static final String LT          = "lt";
  -    public static final String OR          = "or";
  -    public static final String ORDERBY     = "orderby";
  -    public static final String PROP        = "prop";
  -    public static final String RESULTSET   = "resultset";
  -    public static final String SCOPE       = "scope";
  -    public static final String SELECT      = "select";
  -    public static final String WHERE       = "where";
  +    public static final String ALLPROP       = "allprop";
  +    public static final String AND           = "and";
  +    public static final String ASCENDING     = "ascending";
  +    public static final String BASICSEARCH   = "basicsearch";
  +    public static final String CASESENSITIVE = "casesensitive";
  +    public static final String DEPTH         = "depth";
  +    public static final String DESCENDING    = "descending";
  +    public static final String EQ            = "eq";
  +    public static final String FROM          = "from";
  +    public static final String GT            = "gt";
  +    public static final String HREF          = "href";
  +    public static final String INFINITY      = "infinity";
  +    public static final String ISCOLLECTION  = "is-collection";
  +    public static final String ISDEFINED     = "isdefined";
  +    public static final String LIMIT         = "limit";
  +    public static final String LITERAL       = "literal";
  +    public static final String LT            = "lt";
  +    public static final String NOT           = "not";
  +    public static final String OR            = "or";
  +    public static final String ORDER         = "order";
  +    public static final String ORDERBY       = "orderby";
  +    public static final String PROP          = "prop";
  +    public static final String RESOURCETYPE  = "resourcetype";
  +    public static final String RESULTSET     = "resultset";
  +    public static final String SCOPE         = "scope";
  +    public static final String SELECT        = "select";
  +    public static final String WHERE         = "where";
   
       // this one must be slidewide known, move it to appropriate class somewhen
       // (is that true after the new DASL?)
  
  
  
  1.3       +5 -6      jakarta-slide/src/share/org/apache/slide/search/basic/MergeExpression.java
  
  Index: MergeExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/MergeExpression.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MergeExpression.java	14 Feb 2002 17:05:02 -0000	1.2
  +++ MergeExpression.java	22 Mar 2002 14:32:37 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/MergeExpression.java,v 1.2 2002/02/14 17:05:02 wam Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/14 17:05:02 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/MergeExpression.java,v 1.3 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -76,7 +76,7 @@
    * Abstract base class for merge expressions (AND, OR).
    *
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public abstract class MergeExpression extends BasicExpression {
       
  @@ -155,8 +155,7 @@
        * the concrete merge class.
        *
        * @param    s1                  a  Set
  -     * @param    s2                  a  Set
  -     *
  +      *
        */
       protected abstract void merge (Set s);
       
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/search/basic/IsCollectionExpression.java
  
  Index: IsCollectionExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/IsCollectionExpression.java,v 1.1 2002/03/22 14:32:37 wam Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/22 14:32:37 $
   *
   * ====================================================================
   *
   * 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.slide.search.basic;
  import org.apache.slide.search.*;
  
  import org.jdom.Element;
  import org.apache.slide.search.InvalidQueryException;
  import java.util.Set;
  
  /**
   * Represents an EQUALS expression.
   *
   * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
   * @version $Revision: 1.1 $
   */
  public class IsCollectionExpression extends CompareExpression {
      
      /**
       * Creates an EQ expression according to Element e
       *
       * @param e jdom element, that describes the expression
       *
       */
      protected IsCollectionExpression (Element e) throws InvalidQueryException {
          this.expressionElement = e;
          property = Literals.RESOURCETYPE;
          literal = "<collection/>";
      }
         
      /**
       * Checks item for equality against <prop><literal> of this expression.
       *
       * @param    item                a  BasicDataItem
       *
       * @return   a boolean
       *
       */
      protected boolean compare (RequestedResource item) {
          return item.equals (property, literal) == Literals.TRUE;
      }
      
  
      /**
       * For debugging purpose.
       *
       * @return   This expression as string
       *
       */
      public String toString () {
          return (Literals.ISCOLLECTION);
      }
  }
  
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/search/basic/IsDefinedExpression.java
  
  Index: IsDefinedExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/IsDefinedExpression.java,v 1.1 2002/03/22 14:32:37 wam Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/22 14:32:37 $
   *
   * ====================================================================
   *
   * 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.slide.search.basic;
  import org.apache.slide.search.*;
  
  import org.jdom.Element;
  import org.apache.slide.search.InvalidQueryException;
  import java.util.Set;
  
  /**
   * Represents an EQUALS expression.
   *
   * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
   * @version $Revision: 1.1 $
   */
  public class IsDefinedExpression extends CompareExpression {
      
      /**
       * Creates an EQ expression according to Element e
       *
       * @param e jdom element, that describes the expression
       *
       */
      protected IsDefinedExpression (Element e) throws InvalidQueryException {
          this.expressionElement = e;
          property = getPropName (e);
          literal = "";
      }
      
      /**
       * Checks item for equality against <prop><literal> of this expression.
       *
       * @param    item                a  BasicDataItem
       *
       * @return   a boolean
       *
       */
      protected boolean compare (RequestedResource item) {
          return item.isDefined (property);
      }
      
      
      /**
       * For debugging purpose.
       *
       * @return   This expression as string
       *
       */
      public String toString () {
          return super.toString (Literals.EQ);
      }
  }
  
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/search/basic/NotExpression.java
  
  Index: NotExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/NotExpression.java,v 1.1 2002/03/22 14:32:37 wam Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/22 14:32:37 $
   *
   * ====================================================================
   *
   * 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]
   *
   */
  
  /**
   * Represents a NOT expression.
   *
   * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
   * @version $Revision: 1.1 $
   */
  
  package org.apache.slide.search.basic;
  
  import org.jdom.Element;
  import org.apache.slide.search.InvalidQueryException;
  import java.util.Set;
  import java.util.Iterator;
  
  public class NotExpression extends BasicExpression {
      
      /** the one nested expression */
      protected BasicExpression nestedExpression;
      
      /**
       * Creates a NOT expression according to Element e
       *
       * @param e jdom element, that describes the expression
       *
       */
      protected NotExpression (Element e) throws InvalidQueryException {
          super (e);
          Iterator it = e.getChildren().iterator();
          
          if (it.hasNext()) {
              nestedExpression =
                  BasicExpression.createExpression ((Element) it.next());
          }
          if (nestedExpression == null || it.hasNext()) {
              throw new InvalidQueryException
                  ("not expression must contain exactly one nested expression");
          }
      }
      
      /**
       * resolves the nested expression and creates a result set for this
       * expression
       *
       * @param    pool                a  Set
       *
       */
      protected void resolve (Set pool) {
          if (isResolved)
              return;
          
          nestedExpression.resolve (pool);
          if (nestedExpression.isResolved) {
              resultSet.addAll (pool);
              resultSet.removeAll (nestedExpression.getResultSet());
              isResolved = true;
          }
          else
              isResolved = false;
      }
      
      /**
       * For debugging purpose.
       *
       * @return   This expression as string
       *
       */
      public String toString () {
          return " not " + nestedExpression.toString();
      }
  }
  
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/search/basic/OrderBy.java
  
  Index: OrderBy.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/OrderBy.java,v 1.1 2002/03/22 14:32:37 wam Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/22 14:32:37 $
   *
   * ====================================================================
   *
   * 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.slide.search.basic;
  
  import org.jdom.Element;
  import org.jdom.Attribute;
  import org.jdom.Namespace;
  
  import org.apache.slide.search.InvalidQueryException;
  import org.apache.slide.search.RequestedResource;
  import org.apache.slide.search.CompareHint;
  
  import java.util.Comparator;
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Iterator;
  
  public class OrderBy {
      
      Comparator theComparator = new _Comparator ();
      List orderByElements = new ArrayList ();
      
      OrderBy (Element orderByElement) throws InvalidQueryException {
          Namespace nameSpace = orderByElement.getNamespace ();
          Iterator it =
              orderByElement.getChildren (Literals.ORDER, nameSpace).iterator();
          
          while (it.hasNext()) {
              Element order = (Element) it.next();
              String propName = getPropName (order);
              boolean isAscending = isAscending (order);
              boolean isCaseSensitive = isCaseSensitive (order);
              
              orderByElements.add
                  (new CompareHint (propName, isAscending, isCaseSensitive));
          }
      }
      
      public Comparator getComparator () {
          return theComparator;
      }
      
      
      private boolean isCaseSensitive (Element order) {
          boolean result = true;
          Attribute caseSens =
              order.getAttribute (Literals.CASESENSITIVE, order.getNamespace());
          
          if (caseSens != null) {
              try {
                  result = caseSens.getBooleanValue();
              }
              catch (org.jdom.DataConversionException e) {
                  e.printStackTrace();
              }
          }
          return result;
      }
      
      
      
      private boolean isAscending (Element order) throws InvalidQueryException {
          Element asc = order.getChild (Literals.ASCENDING, order.getNamespace());
          Element desc = order.getChild (Literals.DESCENDING, order.getNamespace());
          boolean result = true;
          
          if (asc != null && desc != null)
              throw new InvalidQueryException ("either ascending or descending may be supplied");
          
          if (desc != null)
              result = false;
          
          return result;
      }
      
      private String getPropName (Element order) throws InvalidQueryException {
          
          Element prop = order.getChild (Literals.PROP, order.getNamespace ());
          
          List propList =
              order.getChild (Literals.PROP, order.getNamespace()).getChildren();
          
          if (propList.size() != 1)
              throw new InvalidQueryException
                  ("Expected exactly 1 prop element, found " + propList.size());
          
          return ((Element)propList.get(0)).getName();
      }
      
      
      class _Comparator implements Comparator  {
          
          public int compare(Object o1, Object o2) {
              RequestedResource r1 = (RequestedResource)o1;
              RequestedResource r2 = (RequestedResource)o2;
          
              int result = 0;
              
              Iterator it = orderByElements.iterator();
              while (it.hasNext() && result == 0) {
                  CompareHint obe = (CompareHint)it.next();
                  result = r1.compareTo (r2, obe);
              }
              return result;
          }
      }
  }
  
  
  
  
  1.2       +88 -62    jakarta-slide/src/share/org/apache/slide/search/RequestedResource.java
  
  Index: RequestedResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/RequestedResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestedResource.java	14 Feb 2002 17:02:46 -0000	1.1
  +++ RequestedResource.java	22 Mar 2002 14:32:37 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/RequestedResource.java,v 1.1 2002/02/14 17:02:46 wam Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/14 17:02:46 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/RequestedResource.java,v 1.2 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -85,87 +85,113 @@
    * TODO: Namespace awareness!!
    *
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public interface RequestedResource {
       
  -	
  +    
       /**
  -	 * href accessor
  -	 *
  -	 * @return   the href of this item
  -	 */
  +     * href accessor
  +     *
  +     * @return   the href of this item
  +     */
       public String getHref ();
       
       /**
  -	 * Checks, if a property, represented by its name and value (as String),
  -	 * is greater than the matching property within this item.
  -	 *
  -	 * @param    propName the name of the property to check
  -	 * @param    literal  the value as String to check again
  -	 *
  -	 * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  -	 *
  -	 */
  +     * Checks, if a property, represented by its name and value (as String),
  +     * is greater than the matching property within this item.
  +     *
  +     * @param    propName the name of the property to check
  +     * @param    literal  the value as String to check again
  +     *
  +     * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  +     *
  +     */
       public int greaterThan (String propName, String literal);
       
       /**
  -	 * Checks, if a property, represented by its name and value (as String),
  -	 * is lower than the matching property within this item.
  -	 *
  -	 * @param    propName the name of the property to check
  -	 * @param    literal  the value as String to check again
  -	 *
  -	 * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  -	 *
  -	 */
  +     * Checks, if a property, represented by its name and value (as String),
  +     * is lower than the matching property within this item.
  +     *
  +     * @param    propName the name of the property to check
  +     * @param    literal  the value as String to check again
  +     *
  +     * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  +     *
  +     */
       public int lowerThan (String propName, String literal);
       
       /**
  -	 * Checks, if a property, represented by its name and value (as String),
  -	 * is greater or equal than the matching property within this item.
  -	 *
  -	 * @param    propName the name of the property to check
  -	 * @param    literal  the value as String to check again
  -	 *
  -	 * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  -	 *
  -	 */
  +     * Checks, if a property, represented by its name and value (as String),
  +     * is greater or equal than the matching property within this item.
  +     *
  +     * @param    propName the name of the property to check
  +     * @param    literal  the value as String to check again
  +     *
  +     * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  +     *
  +     */
       public int greaterThanEquals (String propName, String literal);
  -	
  +    
       /**
  -	 * Checks, if a property, represented by its name and value (as String),
  -	 * is lower or equal than the matching property within this item.
  -	 *
  -	 * @param    propName the name of the property to check
  -	 * @param    literal  the value as String to check again
  -	 *
  -	 * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  -	 *
  -	 */
  +     * Checks, if a property, represented by its name and value (as String),
  +     * is lower or equal than the matching property within this item.
  +     *
  +     * @param    propName the name of the property to check
  +     * @param    literal  the value as String to check again
  +     *
  +     * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  +     *
  +     */
       public int lowerThanEquals (String propName, String literal);
       
       /**
  -	 * Checks, if a property, represented by its name and value (as String),
  -	 * is EQUAL the matching property within this item.
  -	 *
  -	 * @param    propName the name of the property to check
  -	 * @param    literal  the value as String to check again
  -	 *
  -	 * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  -	 *
  -	 */
  +     * Checks, if a property, represented by its name and value (as String),
  +     * is EQUAL the matching property within this item.
  +     *
  +     * @param    propName the name of the property to check
  +     * @param    literal  the value as String to check again
  +     *
  +     * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  +     *
  +     */
       public int equals (String propName, String literal);
       
       /**
  -	 * Method getThisValue
  -	 *
  -	 * @param    propName            the property name
  -	 *
  -	 * @return   the value of the property within this item
  -	 */
  +     * Retrieves the value for the given property of this Resource
  +     *
  +     * @param    propName            the property name
  +     *
  +     * @return   the value of the property within this item
  +     */
       public Object getThisValue (String propName);
  -	
  +    
  +    
  +    /**
  +     * Compares this resource to another resource according to the given
  +     * compareHints. This is used by ordering. A value < 0 is retuned, if this
  +     * resource is to be placed before the other resource, not necessarily if
  +     * is lower than the other resource (depending on isAscending() in hints).
  +     *
  +     * @param    otherResource       the other resource to compare to
  +     * @param    hint                hints to do the compare (propName, isAscending...)
  +     *
  +     * @return   an int indicating the sort order.
  +     *
  +     *
  +     */
  +    public int compareTo (RequestedResource otherResource, CompareHint hint);
  +    
  +    /**
  +     * Method isDefined
  +     *
  +     * @param    propName            a  String
  +     *
  +     * @return   true if propName is defined in this resource.
  +     *
  +     */
  +    public boolean isDefined (String propName);
  +    
   }
   
   
  
  
  
  1.2       +318 -273  jakarta-slide/src/share/org/apache/slide/search/RequestedResourceImpl.java
  
  Index: RequestedResourceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/RequestedResourceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestedResourceImpl.java	14 Feb 2002 17:02:46 -0000	1.1
  +++ RequestedResourceImpl.java	22 Mar 2002 14:32:37 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/RequestedResourceImpl.java,v 1.1 2002/02/14 17:02:46 wam Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/14 17:02:46 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/RequestedResourceImpl.java,v 1.2 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -83,294 +83,339 @@
    * equals, ...
    *
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class RequestedResourceImpl implements RequestedResource {
  -	
  -	// TODO: properties with namespace...
  -	
  -	
  -	/** The ObjectNode of this resource */
  -	private ObjectNode objectNode;
  -	
  -	/** the latest revision of this resource */
  -	private NodeRevisionDescriptor revisionDescriptor;
  -	
  -	
  -	private static final int EQ =  1;
  -	private static final int GT =  2;
  -	private static final int LT =  3;
  -	private static final int GTE = 4;
  -	private static final int LTE = 5;
  -	
  -	// private boolean isCollection;
  -	
  -	/**
  -	 * Constructs a RequestedResource.
  -	 *
  -	 * @param objectNode    the ObjectNode for this resource
  -	 * @param slideToken    the slideToken for this request
  -	 * @param contentHelper you won't believe, the ContentHelper
  -	 *
  -	 * @throws BadQueryException
  -	 */
  -	public RequestedResourceImpl (ObjectNode objectNode,
  -								  SlideToken slideToken,
  -								  Content contentHelper)
  -		throws SlideException
  -	{
  -		this.objectNode = objectNode;
  -		NodeRevisionDescriptors revisionDescriptors;
  -		
  -		try {
  -			revisionDescriptors =
  -				contentHelper.retrieve (slideToken, objectNode.getUri());
  -			
  -			try {
  -				revisionDescriptor =
  -					contentHelper.retrieve (slideToken, revisionDescriptors);
  -			}
  -			catch (org.apache.slide.content.RevisionDescriptorNotFoundException e) {
  -				// The object doesn't have any revision, we create a dummy
  -				// NodeRevisionDescriptor object
  -				// isCollection = true;
  -				revisionDescriptor = new NodeRevisionDescriptor(0);
  -				
  -				String resourceName = objectNode.getUri();
  -				int lastSlash = resourceName.lastIndexOf('/');
  -				if (lastSlash != -1)
  -					resourceName = resourceName.substring(lastSlash + 1);
  -				
  -				revisionDescriptor.setName (resourceName);
  -			}
  -			
  -		}
  -		catch (Exception e) {
  -			e.printStackTrace();
  -			throw new SlideException (e.getMessage()); // TODO: clean exception handling
  -		}
  -	}
  -	protected RequestedResourceImpl () {}
  -	
  -    /**
  -	 * Checks, if a property, represented by its name and value (as String),
  -	 * is greater than the matching property within this item.
  -	 *
  -	 * @param    propName the name of the property to check
  -	 * @param    literal  the value as String to check again
  -	 *
  -	 * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  -	 *
  -	 */
  +    
  +    // TODO: properties with namespace...
  +    
  +    
  +    /** The ObjectNode of this resource */
  +    private ObjectNode objectNode;
  +    
  +    /** the latest revision of this resource */
  +    private NodeRevisionDescriptor revisionDescriptor;
  +    
  +    
  +    private static final int EQ =  1;
  +    private static final int GT =  2;
  +    private static final int LT =  3;
  +    private static final int GTE = 4;
  +    private static final int LTE = 5;
  +    
  +    // private boolean isCollection;
  +    
  +    /**
  +     * Constructs a RequestedResource.
  +     *
  +     * @param objectNode    the ObjectNode for this resource
  +     * @param slideToken    the slideToken for this request
  +     * @param contentHelper you won't believe, the ContentHelper
  +     *
  +     * @throws BadQueryException
  +     */
  +    public RequestedResourceImpl (ObjectNode objectNode,
  +                                  SlideToken slideToken,
  +                                  Content contentHelper)
  +        throws SlideException
  +    {
  +        this.objectNode = objectNode;
  +        NodeRevisionDescriptors revisionDescriptors;
  +        
  +        try {
  +            revisionDescriptors =
  +                contentHelper.retrieve (slideToken, objectNode.getUri());
  +            
  +            try {
  +                revisionDescriptor =
  +                    contentHelper.retrieve (slideToken, revisionDescriptors);
  +            }
  +            catch (org.apache.slide.content.RevisionDescriptorNotFoundException e) {
  +                // The object doesn't have any revision, we create a dummy
  +                // NodeRevisionDescriptor object
  +                // isCollection = true;
  +                revisionDescriptor = new NodeRevisionDescriptor(0);
  +                
  +                String resourceName = objectNode.getUri();
  +                int lastSlash = resourceName.lastIndexOf('/');
  +                if (lastSlash != -1)
  +                    resourceName = resourceName.substring(lastSlash + 1);
  +                
  +                revisionDescriptor.setName (resourceName);
  +            }
  +        }
  +        catch (Exception e) {
  +            e.printStackTrace();
  +            throw new SlideException (e.getMessage()); // TODO: clean exception handling
  +        }
  +    }
  +    protected RequestedResourceImpl () {}
  +    
  +    /**
  +     * Checks, if a property, represented by its name and value (as String),
  +     * is greater than the matching property within this item.
  +     *
  +     * @param    propName the name of the property to check
  +     * @param    literal  the value as String to check again
  +     *
  +     * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  +     *
  +     */
       public int greaterThan (String propName, String literal) {
  -		return compare (propName, literal, GT);
  +        return compare (propName, literal, GT);
       }
       
       public int greaterThanEquals (String propName, String literal) {
  -		return compare (propName, literal, GTE);
  +        return compare (propName, literal, GTE);
       }
  -	
  -	public int lowerThan (String propName, String literal) {
  -		return compare (propName, literal, LT);
  +    
  +    public int lowerThan (String propName, String literal) {
  +        return compare (propName, literal, LT);
       }
       
  -	public int lowerThanEquals (String propName, String literal) {
  -		return compare (propName, literal, LTE);
  +    public int lowerThanEquals (String propName, String literal) {
  +        return compare (propName, literal, LTE);
       }
       
  -	
  -	
  +    
  +    
       /**
  -	 * Checks, if a property, represented by its name and value (as String),
  -	 * is EQUAL the matching property within this item.
  -	 *
  -	 * @param    propName the name of the property to check
  -	 * @param    literal  the value as String to check again
  -	 *
  -	 * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  -	 *
  -	 */
  +     * Checks, if a property, represented by its name and value (as String),
  +     * is EQUAL the matching property within this item.
  +     *
  +     * @param    propName the name of the property to check
  +     * @param    literal  the value as String to check again
  +     *
  +     * @return   Literals.TRUE, Literals.FALSE or Literals.UNKNOWN
  +     *
  +     */
       public int equals (String propName, String literal) {
  -		return compare (propName, literal, EQ);
  +        return compare (propName, literal, EQ);
  +    }
  +    
  +    /**
  +     * href accessor
  +     *
  +     * @return   the href of this item
  +     */
  +    public String getHref() {
  +        return objectNode.getUri();
  +    }
  +    
  +    
  +    /**
  +     * Method getThisValue
  +     *
  +     * @param    propName            the property name
  +     *
  +     * @return   the value of the property within this item
  +     */
  +    public Object getThisValue (String propName) {
  +        Object result = null;
  +        // special handling for properties as contenlength, contenttype, ...
  +        
  +        // all other properties...
  +        NodeProperty np = revisionDescriptor.getProperty (propName);
  +        result = (np == null) ? null : np.getValue();
  +        
  +        return result;
  +    }
  +    
  +    // brauchen wir die???
  +    /**
  +     * Method isCollection
  +     *
  +     * @param    revisionDescriptor  a  NodeRevisionDescriptor
  +     *
  +     * @return   a boolean
  +     *
  +     */
  +    public boolean isCollection (NodeRevisionDescriptor revisionDescriptor) {
  +        boolean result = false;
  +        
  +        if (revisionDescriptor == null)
  +            return true;
  +        
  +        NodeProperty property = revisionDescriptor.getProperty("resourcetype");
  +        
  +        if ((property != null)
  +            && (property.getValue().equals("<collection/>"))) {
  +            result = true;
  +        }
  +        
  +        return result;
  +    }
  +    
  +    
  +    /**
  +     * compares two RequestedResources according to OrderByHint. NULL values are
  +     * always considered as lessThan. (see [DASL] 5.6)
  +     *
  +     * @param    otherResource       a  RequestedResource
  +     * @param    hint                an OrderByHint
  +     *
  +     * @return   an int
  +     *
  +     */
  +    public int compareTo (RequestedResource otherResource, CompareHint hint) {
  +        int result = 0;
  +        
  +        Comparable otherValue = (Comparable) otherResource.getThisValue (hint.getProperty());
  +        Comparable thisValue = (Comparable) getThisValue (hint.getProperty());
  +        
  +        if (thisValue != null && otherValue != null)
  +            result = thisValue.compareTo(otherValue);
  +            
  +        else if (thisValue == null && otherValue != null)
  +            result = -1;
  +            
  +        else if (thisValue != null && otherValue == null)
  +            result = 1;
  +            
  +        else
  +            result = 0;
  +        
  +        if (hint.isAscending() == false)
  +            result = result * -1;
  +        
  +        // todo: take casesensitive into account
  +        
  +        return result;
  +    }
  +    
  +    /**
  +     * Method isDefined
  +     *
  +     * @param    propName            a  String
  +     *
  +     * @return   true if propName is defined in this resource.
  +     *
  +     */
  +    public boolean isDefined (String propName) {
  +        return getThisValue (propName) == null ? false : true;
       }
  -	
  -	/**
  -	 * href accessor
  -	 *
  -	 * @return   the href of this item
  -	 */
  -	public String getHref()	{
  -		return objectNode.getUri();
  -	}
  -	
  -	
  -    /**
  -	 * Method getThisValue
  -	 *
  -	 * @param    propName            the property name
  -	 *
  -	 * @return   the value of the property within this item
  -	 */
  -	public Object getThisValue (String propName) {
  -		Object result = null;
  -		// special handling for properties as contenlength, contenttype, ...
  -		
  -		// all other properties...
  -		NodeProperty np = revisionDescriptor.getProperty (propName);
  -		result = (np == null) ? null : np.getValue();
  -		
  -		return result;
  -	}
  -	
  -	// brauchen wir die???
  -	/**
  -	 * Method isCollection
  -	 *
  -	 * @param    revisionDescriptor  a  NodeRevisionDescriptor
  -	 *
  -	 * @return   a boolean
  -	 *
  -	 */
  -	public boolean isCollection (NodeRevisionDescriptor revisionDescriptor) {
  -		boolean result = false;
  -		
  -		if (revisionDescriptor == null)
  -			return true;
  -		
  -		NodeProperty property = revisionDescriptor.getProperty("resourcetype");
  -		
  -		if ((property != null)
  -			&& (property.getValue().equals("<collection/>"))) {
  -			result = true;
  -		}
  -		
  -		return result;
  -    }
  -	
  -	/**
  -	 * Compares the value of this resources property (propname) to the
  -	 * propname / literal pair. Returns an integer greater, equal or less than
  -	 * 0 according java.lang.Comparable
  -	 *
  -	 * @param    propName            a  String
  -	 * @param    literal             a  String
  -	 *
  -	 * @return   an int
  -	 *
  -	 * @throws   NumberFormatException
  -	 * @throws   UnknownException
  -	 *
  -	 */
  +    
  +    
  +    /**
  +     * Compares the value of this resources property (propname) to the
  +     * propname / literal pair. Returns an integer greater, equal or less than
  +     * 0 according java.lang.Comparable
  +     *
  +     * @param    propName            a  String
  +     * @param    literal             a  String
  +     *
  +     * @return   an int
  +     *
  +     * @throws   NumberFormatException
  +     * @throws   UnknownException
  +     *
  +     */
       private int compareTo (String propName, String literal)
  -		throws NumberFormatException, UnknownException
  +        throws NumberFormatException, UnknownException
       {
  -		int result = 0;
  -		
  -		Object thisValue = getThisValue (propName);
  -		if (thisValue == null)
  -			throw new UnknownException ();
  -		
  -		Object otherValue = null;
  -		
  -		otherValue = getOtherValue (thisValue, literal);
  -		result = ((Comparable)thisValue).compareTo((Comparable)otherValue);
  -		return result;
  -    }
  -    
  -	/**
  -	 * Method getOtherValue
  -	 *
  -	 * @param    thisValue           an Object
  -	 * @param    literal             a  String
  -	 *
  -	 * @return   an Object
  -	 *
  -	 * @throws   NumberFormatException
  -	 */
  +        int result = 0;
  +        
  +        Object thisValue = getThisValue (propName);
  +        if (thisValue == null)
  +            throw new UnknownException ();
  +        
  +        Object otherValue = null;
  +        
  +        otherValue = getOtherValue (thisValue, literal);
  +        result = ((Comparable)thisValue).compareTo((Comparable)otherValue);
  +        return result;
  +    }
  +    
  +    /**
  +     * Method getOtherValue
  +     *
  +     * @param    thisValue           an Object
  +     * @param    literal             a  String
  +     *
  +     * @return   an Object
  +     *
  +     * @throws   NumberFormatException
  +     */
       private Object getOtherValue (Object thisValue, String literal)
  -		throws NumberFormatException
  +        throws NumberFormatException
       {
  -		Object otherValue = null;
  -		if (thisValue instanceof Boolean)
  -			otherValue = new Boolean (literal);
  -			
  -		else if (thisValue instanceof Date) {
  -			otherValue = new Date (); // TODO: dateTime.iso8601tz
  -			// otherValue = new Date (literal); // TODO: dateTime.iso8601tz
  -		}
  -			
  -		else if (thisValue instanceof Float)
  -			otherValue = new Float (literal);
  -			
  -		else if (thisValue instanceof Integer)
  -			otherValue = new Integer (literal);
  -			
  -		else if (thisValue instanceof Long)
  -			otherValue = new Long (literal);
  -			
  -		else
  -			otherValue = literal;
  -		return otherValue;
  -    }
  -	
  -	private int compare (String propName, String literal, int op) {
  -		int result = Literals.FALSE;
  -		
  -		Object thisValue = getThisValue (propName);
  -		if (thisValue == null)
  -			return Literals.UNKNOWN;
  -		
  -		Object otherValue = null;
  -		
  -		try {
  -			otherValue = getOtherValue (thisValue, literal);
  -			
  -			switch (op)
  -			{
  -				case EQ:
  -					if (compareTo (propName, literal) == 0)
  -						result = Literals.TRUE;
  -					break;
  -					
  -				case GT:
  -					if (compareTo (propName, literal) > 0)
  -						result = Literals.TRUE;
  -					break;
  -					
  -				case LT:
  -					if (compareTo (propName, literal) < 0)
  -						result = Literals.TRUE;
  -					break;
  -					
  -				case GTE:
  -					if (compareTo (propName, literal) >= 0)
  -						result = Literals.TRUE;
  -					break;
  -					
  -				case LTE:
  -					if (compareTo (propName, literal) <= 0)
  -						result = Literals.TRUE;
  -					break;
  -				default:
  -					break;
  -			}
  -			
  -		}
  -		catch (NumberFormatException e) {
  -			result = Literals.UNKNOWN;
  -		}
  -		catch (UnknownException e) {
  -			result = Literals.UNKNOWN;
  -		}
  -		
  -		
  -		return result;
  -    }
  -	
  -	
  -	/**
  -	 * Dummy Exception to indicate UNKNOWN state
  -	 */
  +        Object otherValue = null;
  +        if (thisValue instanceof Boolean)
  +            otherValue = new Boolean (literal);
  +            
  +        else if (thisValue instanceof Date) {
  +            otherValue = new Date (); // TODO: dateTime.iso8601tz
  +            // otherValue = new Date (literal); // TODO: dateTime.iso8601tz
  +        }
  +            
  +        else if (thisValue instanceof Float)
  +            otherValue = new Float (literal);
  +            
  +        else if (thisValue instanceof Integer)
  +            otherValue = new Integer (literal);
  +            
  +        else if (thisValue instanceof Long)
  +            otherValue = new Long (literal);
  +            
  +        else
  +            otherValue = literal;
  +        return otherValue;
  +    }
  +    
  +    private int compare (String propName, String literal, int op) {
  +        int result = Literals.FALSE;
  +        
  +        Object thisValue = getThisValue (propName);
  +        if (thisValue == null)
  +            return Literals.UNKNOWN;
  +        
  +        Object otherValue = null;
  +        
  +        try {
  +            otherValue = getOtherValue (thisValue, literal);
  +            
  +            switch (op)
  +            {
  +                case EQ:
  +                    if (compareTo (propName, literal) == 0)
  +                        result = Literals.TRUE;
  +                    break;
  +                    
  +                case GT:
  +                    if (compareTo (propName, literal) > 0)
  +                        result = Literals.TRUE;
  +                    break;
  +                    
  +                case LT:
  +                    if (compareTo (propName, literal) < 0)
  +                        result = Literals.TRUE;
  +                    break;
  +                    
  +                case GTE:
  +                    if (compareTo (propName, literal) >= 0)
  +                        result = Literals.TRUE;
  +                    break;
  +                    
  +                case LTE:
  +                    if (compareTo (propName, literal) <= 0)
  +                        result = Literals.TRUE;
  +                    break;
  +                default:
  +                    break;
  +            }
  +        }
  +        catch (NumberFormatException e) {
  +            result = Literals.UNKNOWN;
  +        }
  +        catch (UnknownException e) {
  +            result = Literals.UNKNOWN;
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Dummy Exception to indicate UNKNOWN state
  +     */
       private class UnknownException extends Exception {
       }
   }
  
  
  
  1.6       +52 -11    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SearchQueryResult.java	20 Mar 2002 15:40:16 -0000	1.5
  +++ SearchQueryResult.java	22 Mar 2002 14:32:37 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java,v 1.6 2002/03/22 14:32:37 wam Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/03/22 14:32:37 $
    *
    * ====================================================================
    *
  @@ -65,21 +65,26 @@
   
   import java.util.Set;
   import java.util.HashSet;
  +import java.util.TreeSet;
  +import java.util.Iterator;
  +import java.util.Comparator;
   import org.apache.slide.common.*;
   import org.apache.slide.structure.*;
   import org.apache.slide.authenticate.CredentialsToken;
   import org.apache.slide.util.Configuration;
   
   /**
  - * A Hashset containing the result items of a query. May also contain a status
  - * and a response description (For example: 507 partial result)
  + * Aggregates a set containing the result items of a query. This set is either
  + * a HashSet (if no ordering was requested) or a TreeSet (if orderby was
  + * specified) May also contain a status and a response description
  + * (For example: 507 partial result)
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author <a href="mailto:martin.wallmer@softweareag.com">Martin Wallmer</a>
    *
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
  -public class SearchQueryResult extends HashSet {
  +public class SearchQueryResult {
       
       public final static int STATUS_OK             = 0;
       public final static int STATUS_BAD_QUERY      = 1;
  @@ -91,6 +96,7 @@
       private String description;
       private String href;
       
  +    private Set result;
       /**
        * Method setStatus
        *
  @@ -130,7 +136,7 @@
       public String getDescription() {
           return description;
       }
  -
  +    
       /**
        * Method setHref
        *
  @@ -150,13 +156,48 @@
           return href;
       }
       
  +    /**
  +     * Constructs an empty unorderred SearchQueryResult
  +     *
  +     */
  +    public SearchQueryResult () {
  +        result = new HashSet ();
  +    }
  +    
  +    /**
  +     * Constructs an unordered SearchQueryResult
  +     *
  +     * @param result    the set containing the result items
  +     */
       public SearchQueryResult (Set result) {
  -        super (result);
  +        this (result, null);
  +    }
  +    
  +    /**
  +     * Constructs an ordered SearchQueryResult
  +     *
  +     * @param result    the set containing the result items
  +     * @param comparator for ordering
  +     */
  +    public SearchQueryResult (Set result, Comparator comparator) {
  +        if (comparator == null)
  +            this.result = result;
  +        else {
  +            this.result = new TreeSet (comparator);
  +            this.result.addAll (result);
  +        }
           status = STATUS_OK;
           description = "";
       }
       
  -    public SearchQueryResult () {
  -        super ();
  +    /**
  +     * Method iterator
  +     *
  +     * @return   iterator for iteraing the result
  +     *
  +     */
  +    public Iterator iterator () {
  +        return result.iterator();
       }
  +    
   }
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/search/CompareHint.java
  
  Index: CompareHint.java
  ===================================================================
  /**
   * OrderByHint.java
   *
   * @author Created by Omnicore CodeGuide
   */
  
  package org.apache.slide.search;
  
  public class CompareHint {
      
      private String property;
      private boolean ascending;
      private boolean caseSensitive;
      
      public String getProperty () {
          return property;
      }
      
      public boolean isAscending () {
          return ascending;
      }
      
      public boolean isCaseSensitive () {
          return caseSensitive;
      }
      
      public CompareHint (String property, boolean ascending, boolean caseSensitive) {
          this.property = property;
          this.ascending = ascending;
          this.caseSensitive = caseSensitive;
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>