juergen 02/01/28 03:24:41
Added: src/share/org/apache/slide/search/basic AndExpression.java
BasicDataItem.java BasicSearchExpression.java
BasicSearchLanguage.java BasicSearchQuery.java
CompareExpression.java EQExpression.java
GetAllProperties.java GTExpression.java
Literals.java MergeExpression.java Scope.java
SelectedProperty.java SelectedPropertyList.java
Log:
package basicsearch renamed to basic (Martin)
Revision Changes Path
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/AndExpression.java
Index: AndExpression.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/AndExpression.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.apache.slide.search.InvalidQueryException;
import java.util.Iterator;
/**
* Represents an AND expression.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class AndExpression extends MergeExpression {
/**
* Creates an AND expression according to Element e
*
* @param e jdom element, that describes the expression
*
*/
protected AndExpression (Element e) throws InvalidQueryException {
super (e);
}
// ToDo: implement merge method
// something like void merge (Set s1, Set s2);
protected void merge(java.util.Set s1, java.util.Set s2) {
}
/**
* String representation for debugging purposes.
*
* @return this expression as String
*/
public String toString () {
return super.toString (Literals.AND);
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/BasicDataItem.java
Index: BasicDataItem.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicDataItem.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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 java.util.Map;
import java.util.HashMap;
import java.util.Date;
import org.apache.slide.content.NodeProperty;
/**
* Represents one item of a searcheable set. Consists of an href, which is
* a unique identifier, and a set of NodeProperty objects. A BasicDataItem may
* be compared against a property represented by property name and value
* (as String). These compare methods (equals(), greaterThan(), ...) use three
* valued logic (TRUE, FALSE, UNKNOWN). UNKNOWN is returned when this item does
* not know the property to compare against or when the value of that property
* may not be converted to the datatype of this items matching property (for
* example comparing a Float against the string "foo").
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class BasicDataItem {
/** href of this result item */
private String href;
/** Holds node properties keyed by their name */
private Map properties = new HashMap();
// should contain something reflecting the status (errormessage,succes,...)
/**
* Constructs a ResultItem with href. Use addProperty to add properties.
*
* @param href the URI of this item
*
*/
BasicDataItem (String href) {
this.href = href;
}
/**
* href accessor
*
* @return the href of this item
*/
String getHref () {
return href;
}
/**
* Method addProperty
*
* @param prop nodeProperty to add
*/
void addProperty (NodeProperty prop) {
properties.put (prop.getName (), prop);
}
/**
* retrieve a property.
*
* @param propName the name of the property
*
* @return the node property
*/
NodeProperty getNodeProperty (String propName) {
return (NodeProperty) properties.get (propName);
}
/**
* 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
*
*/
int greaterThan (String propName, String literal) {
int result = Literals.FALSE;
try
{
if (compareTo(propName, literal) > 0)
result = Literals.TRUE;
else
result = Literals.FALSE;
}
catch (NumberFormatException e) {
result = Literals.UNKNOWN;
}
catch (UnknownException e) {
result = Literals.UNKNOWN;
}
return result;
}
/**
* 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
*
*/
int equals (String propName, String literal) {
int result = Literals.FALSE;
Object thisValue = getThisValue (propName);
if (thisValue == null)
return Literals.UNKNOWN;
Object otherValue = null;
try {
otherValue = getOtherValue (thisValue, literal);
if (thisValue.equals (otherValue))
result = Literals.TRUE;
else
result = Literals.FALSE;
}
catch (NumberFormatException e) {
result = Literals.UNKNOWN;
}
return result;
}
/**
* Method compareTo
*
* @param propName a String
* @param literal a String
*
* @return an int
*
* @throws NumberFormatException
*
* @version 1/21/2002
*/
private int compareTo (String propName, String literal)
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 getThisValue
*
* @param propName a String
*
* @return an Object
*/
Object getThisValue (String propName) {
NodeProperty np = getNodeProperty (propName);
return np == null ? null : np.getValue();
}
/**
* Method getOtherValue
*
* @param thisValue an Object
* @param literal a String
*
* @return an Object
*
* @throws NumberFormatException
*/
private Object getOtherValue (Object thisValue, String literal)
throws NumberFormatException
{
Object otherValue = null;
if (thisValue instanceof Boolean)
otherValue = new Boolean (literal);
else if (thisValue instanceof Date)
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
otherValue = literal;
return otherValue;
}
/**
* Method hashCode
*
* @return an int
*/
public int hashCode() {
return href.hashCode();
}
/**
* Dummy Exception to indicate UNKNOWN state
*/
class UnknownException extends Exception {
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchExpression.java
Index: BasicSearchExpression.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchExpression.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.apache.slide.search.InvalidQueryException;
import java.util.Set;
import java.util.HashSet;
/**
* A BasicSearchExpression represents exactly one operator (AND, GT, ...).
* It may have the state resolved or unresolved. If it is unresolved, it
* contains the BasicSearchExpressions, on which the operation is to
* be executed. If it is resolved, it contains a Set of BasicDataItems,
* that represents the result set of this BasicSearchExpression. The state
* transition from unresolved to resolved may only happen, when all subsequent
* BasicSearchExpressions have the state resolved.
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public abstract class BasicSearchExpression {
/** the JDOM element representing this expression. */
protected Element expressionElement;
/** indicate, if this expression is resolved */
protected boolean isResolved;
/** the resultset of this expression, if it has the state resolved */
protected Set resultSet = new HashSet ();
/**
* prevent from being instantiated from outside, use factory method
*/
private BasicSearchExpression () {}
/**
* constructor. Only called by the conrecte expressions
*
* @param e the jdom element representing this expression.
*/
protected BasicSearchExpression (Element e) {
this.expressionElement = e;
}
/**
* Factory method to create the concrete expression.
*
* @param e the jdom element representing the expression
*
* @return a BasicSearchExpression
*
* @throws InvalidQueryException
*/
static public BasicSearchExpression createExpression
(Element e) throws InvalidQueryException
{
String name = e.getName();
BasicSearchExpression result = null;
if (name.equals (Literals.AND))
result = new AndExpression (e);
else if (name.equals (Literals.GT))
result = new GTExpression (e);
else if (name.equals (Literals.EQ))
result = new EQExpression (e);
else
throw new InvalidQueryException
("operator " + name + " is an unprocessable entity");
return result;
}
/**
* retrieves the result set.
*
* @return a Set
*
* @throws IllegalStateException if the expression is not yet resolved
*/
Set getResultSet () {
if (!isResolved)
throw new IllegalStateException ("Expression not yet resolved");
return resultSet;
}
/**
* Method isResolved
*
* @return true if expression is resolved
*/
boolean isResolved () {
return isResolved;
}
/**
* Resolve this expression.
*
* @param pool out of this Set of BasicDataItems the result set
* is created
*/
protected abstract void resolve (Set pool);
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchLanguage.java
Index: BasicSearchLanguage.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchLanguage.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.SearchLanguage;
import org.apache.slide.search.SearchQuery;
import org.apache.slide.search.BadQueryException;
import org.w3c.dom.Element;
/**
* Represent the BasicSearchLanguage for Slide
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class BasicSearchLanguage extends SearchLanguage {
static final String GRAMMAR_NAME =
"basicsearch";
static final String GRAMMAR_NAMESPACE =
"DAV:";
public BasicSearchLanguage () {}
/**
* Method getName
*
* @return the name of this query language
*/
public String getName() {
return GRAMMAR_NAME;
}
/**
* Retrieves the URI of this language
*
* @return the namspace of this language
*/
public String getGrammarUri() {
return GRAMMAR_NAMESPACE;
}
/**
* Creates a SearchQuery out of this queryString
*
* @param queryString an XML String describing this query
*
* @return the SearchQuery
*
* @throws InvalidQueryException
*/
public SearchQuery parseQuery (String queryString)
throws BadQueryException
{
return new BasicSearchQuery (queryString);
}
/**
* Creates a SearchQuery out of this queryElement
*
* @param queryElement an XML Element describing this query
*
* @return the SearchQuery
*
* @throws InvalidQueryException
*/
public SearchQuery parseQuery (Element queryElement)
throws BadQueryException
{
return new BasicSearchQuery (queryElement);
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchQuery.java
Index: BasicSearchQuery.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchQuery.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.SearchQuery;
import org.apache.slide.search.SearchException;
import org.apache.slide.search.BadQueryException;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.search.SearchQueryResult;
import org.jdom.input.DOMBuilder;
import org.jdom.input.SAXBuilder;
import org.jdom.Namespace;
import org.jdom.Element;
import org.jdom.Document;
import org.xml.sax.InputSource;
import java.io.StringReader;
import java.util.List;
import java.util.Set;
/**
* 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
* BasicSearchExpressions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class BasicSearchQuery extends SearchQuery {
// this should somehow be replaced
private GetAllProperties propertyResolver;
/** the element describing this query */
private Element queryElement;
/** the namespace for this query */
private Namespace namespace;
/** the scope of this query, <FROM> */
private Scope scope;
/** List of selected properties, <SELECT> */
private SelectedPropertyList selectedProperties;
/** <LIMIT> */
private int limit;
/** indicates, if a limit is defined */
private boolean limitDefined = false;
/** the top level expression in the <WHERE> clause */
private BasicSearchExpression rootExpression;
// TODO: <ORDERBY>
/**
* Constructs a query from the queryString. queryString is an XML
* document according to the DASL basicsearch specfication.
*
* @parameter queryString the search query
*
* @throws BadQueryException
*/
BasicSearchQuery (String queryString) throws BadQueryException {
try
{
Document doc =
new SAXBuilder ().build (new StringReader (queryString));
Element root = doc.getRootElement();
parseQueryElement (root);
}
catch (org.jdom.JDOMException e) {
e.printStackTrace();
throw new BadQueryException (e.getMessage());
}
}
/**
* Constructs a query from queryElement. queryElement is a DOM
* element <searchrequest> according to the DASL basicsearch
* specfication.
*
* @parameter queryString the search query
*
* @throws BadQueryException
*/
BasicSearchQuery (org.w3c.dom.Element queryElement) throws BadQueryException {
Element root = new DOMBuilder ().build (queryElement);
parseQueryElement (root);
}
/**
* Executes a request. A store specific implementation should overwrite
* this to optimize the execution.
*
* @return a SearchQueryResult
*
* @throws ServiceAccessException
*
*/
public SearchQueryResult execute() throws ServiceAccessException {
// from where we get our root pool?
Set rootPool = propertyResolver.getAllProperties();
rootExpression.resolve (rootPool);
return new SearchQueryResult () ;
}
/**
* Method getScope
*
* @return a Scope
*
*/
Scope getScope () {
return scope;
}
/**
* Method getSelectedProperties
*
* @return a SelectedPropertyList
*/
SelectedPropertyList getSelectedProperties () {
return selectedProperties;
}
BasicSearchExpression getExpression () {
return rootExpression;
}
/**
* Method isLimitDefined
*
* @return true if <limit> was specified
*/
boolean isLimitDefined () {
return limitDefined;
}
/**
* Method getLimit
*
* @return the value of <limit>
*/
int getLimit () {
return limit;
}
/**
* builds the internal structure out of the JDOM tree
*
* @param root an Element
*
* @throws BadQueryException
*/
private void parseQueryElement (Element root)
throws BadQueryException
{
namespace = root.getNamespace();
this.queryElement = root.getChild (Literals.BASICSEARCH, namespace);
Element selectElement = queryElement.getChild
(Literals.SELECT, namespace);
Element fromElement = queryElement.getChild
(Literals.FROM, namespace);
Element whereElement = queryElement.getChild
(Literals.WHERE, namespace);
Element orderByElement = queryElement.getChild
(Literals.ORDERBY, namespace);
Element limitElement = queryElement.getChild
(Literals.LIMIT, namespace);
scope = new Scope (fromElement);
selectedProperties = new SelectedPropertyList
(selectElement.getChild (Literals.PROP, namespace));
// TODO orderby...
List expressionList = whereElement.getChildren();
rootExpression = BasicSearchExpression.createExpression
((Element) expressionList.get (0));
if (limitElement != null) {
limit = new Integer (limitElement.getTextTrim()).intValue();
limitDefined = true;
}
}
/**
* For debugging purpose.
*
* @return this query in string representation
*
*/
public String toString () {
return
"SELECT [" + selectedProperties + "] FROM [" + scope
+ "] WHERE [" + rootExpression + "]";
}
// for testing
public void setPropertyResolver (GetAllProperties propertyResolver) {
this.propertyResolver = propertyResolver;
}
public GetAllProperties getPropertyResolver() {
return propertyResolver;
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/CompareExpression.java
Index: CompareExpression.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/CompareExpression.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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 java.util.Iterator;
import java.util.Set;
import java.util.List;
import java.util.ArrayList;
import org.jdom.Namespace;
import org.jdom.Element;
import org.apache.slide.search.InvalidQueryException;
/**
* Abstract base class for compare expressions (GT, EQ, ...).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public abstract class CompareExpression extends BasicSearchExpression {
/** the property name <prop> */
protected String property;
/** the property's value <literal> */
protected String literal;
/**
* Creates a compare expression according to Element e
*
* @param e jdom element, that describes the expression
*
*/
CompareExpression (Element e) throws InvalidQueryException {
super (e);
List propList =
e.getChild (Literals.PROP, e.getNamespace()).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 ();
}
/**
* Resolves this expression. All elements in the pool are compared
* against property / literal.
*
* @param pool a Set
*
*/
protected void resolve (Set pool) {
if (isResolved)
return;
Iterator it = pool.iterator();
while (it.hasNext()) {
BasicDataItem item =
(BasicDataItem)it.next();
if (compare (item))
resultSet.add (item);
}
isResolved = true;
}
/**
* The concrete CompareExpression must overwrite this.
*
* @param item one BasicDataItem out of pool
*
* @return a boolean
*
*/
protected abstract boolean compare (BasicDataItem item);
/**
* String representation for debugging purposes.
*
* @return this expression as String
*/
protected String toString (String op) {
return "(" +property + " " + op + " " + literal + ")";
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/EQExpression.java
Index: EQExpression.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/EQExpression.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.apache.slide.search.InvalidQueryException;
import java.util.Set;
/**
* Represents an EQUALS expression.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class EQExpression extends CompareExpression {
/**
* Creates an EQ expression according to Element e
*
* @param e jdom element, that describes the expression
*
*/
protected EQExpression (Element e) throws InvalidQueryException {
super (e);
}
/**
* Checks item for equality against <prop><literal> of this expression.
*
* @param item a BasicDataItem
*
* @return a boolean
*
*/
protected boolean compare (BasicDataItem item) {
return item.equals (property, literal) == Literals.TRUE;
}
/**
* 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/GetAllProperties.java
Index: GetAllProperties.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/GetAllProperties.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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 java.util.Set;
import org.apache.slide.search.SearchQueryResult;
/**
* this should somehow provide the global pool of items, out of which the
* SEARCH builds its result set. Matter of change...
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public interface GetAllProperties {
SearchQueryResult getAllProperties ();
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/GTExpression.java
Index: GTExpression.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/GTExpression.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.apache.slide.search.InvalidQueryException;
import java.util.Iterator;
import java.util.Set;
/**
* Represents an GREATER_THAN expression.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class GTExpression extends CompareExpression {
/**
* Creates a GT expression according to Element e
*
* @param e jdom element, that describes the expression
*
*/
protected GTExpression (Element e) throws InvalidQueryException {
super (e);
}
/**
* Checks if item is greater than <prop><literal> of this expression.
*
* @param item a BasicDataItem
*
* @return a boolean
*
*/
protected boolean compare (BasicDataItem item) {
return item.greaterThan (property, literal) == Literals.TRUE;
}
/**
* For debugging purpose.
*
* @return This expression as string
*
*/
public String toString () {
return super.toString (Literals.GT);
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/Literals.java
Index: Literals.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/Literals.java,v 1.1
2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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;
/**
* static container for some literals.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class Literals {
static final int DEPTH_UNDEFINED = -1;
static final int DEPTH_0 = 0;
static final int DEPTH_1 = 1;
static final int DEPTH_INFINITY = 2;
static final String ALLPROP = "allprop";
static final String AND = "and";
static final String BASICSEARCH = "basicsearch";
static final String DEPTH = "depth";
static final String EQ = "eq";
static final String FROM = "from";
static final String GT = "gt";
static final String HREF = "href";
static final String INFINITY = "infinity";
static final String LIMIT = "limit";
static final String LITERAL = "literal";
static final String ORDERBY = "orderby";
static final String PROP = "prop";
static final String RESULTSET = "resultset";
static final String SCOPE = "scope";
static final String SELECT = "select";
static final String WHERE = "where";
// this one must be slidewide known, move it to appropriate class somewhen
static final String DT_NAMESPACE
= "urn:uuid:C2F41010-65B3-11d1-A29F-00AA00C14882/";
static final int TRUE = 1;
static final int FALSE = 0;
static final int UNKNOWN = -1;
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/MergeExpression.java
Index: MergeExpression.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/MergeExpression.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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 java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import org.jdom.Element;
import org.apache.slide.search.InvalidQueryException;
/**
* Abstract base class for merge expressions (AND, OR).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public abstract class MergeExpression extends BasicSearchExpression {
/** all nested expressions */
protected List nestedExpressions = new ArrayList ();
/**
* Creates a merge expression according to Element e
*
* @param e jdom element, that describes the expression
*
*/
MergeExpression (Element e) throws InvalidQueryException {
super (e);
Iterator it = e.getChildren().iterator();
while (it.hasNext()) {
Element el = (Element) it.next();
nestedExpressions.add (BasicSearchExpression.createExpression (el));
}
}
/**
* Resolves this expression. If all nested expressions may be resolved,
* their result sets are merged according to the merge method of the
* concrete expression
*
* @param pool the pool out of which the nested expressions build
* their result sets
*/
protected void resolve (Set pool) {
if (isResolved)
return;
// TODO: get all nested elements and call the merge method
// of the concrete MergeExpression (AndExpression, OrExpression)
// Iterator it = nestedExpressions.iterator();
// while (it.hasNext()) {
// BasicSearchExpression exp = (BasicSearchExpression)it.next();
// exp.resolve (pool);
// }
//
}
/**
* Two intermediate result sets are merged according the rules of
* the concrete merge class.
*
* @param s1 a Set
* @param s2 a Set
*
*/
protected abstract void merge (Set s1, Set s2);
/**
* String representation for debugging purposes.
*
* @return this expression as String
*/
protected String toString (String op) {
StringBuffer sb = new StringBuffer();
Iterator it = nestedExpressions.iterator();
while (it.hasNext()) {
sb.append (((BasicSearchExpression) it.next()).toString());
if (it.hasNext())
sb.append (" ").append (op).append (" ");
}
return sb.toString();
}
}
1.1 jakarta-slide/src/share/org/apache/slide/search/basic/Scope.java
Index: Scope.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/Scope.java,v 1.1
2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.content.NodeProperty;
import org.apache.slide.search.BadQueryException;
import org.jdom.Element;
import org.jdom.Namespace;
/**
* Holds the scope information supplied with the <FROM> element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class Scope {
/** String representing the URI */
private String href;
/**
* the depth of this query. May be DEPTH_UNDEFINED (-1), DEPTH_0 = (),
* DEPTH_1 (1) or DEPTH_INFINITY (2)
*/
private int depth;
/**
* Constructs a scope
*
* @param propertyName the name of the property
*/
public Scope (String href) {
this.href = href;
}
/**
* Constructs a scope
*
* @param propertyName the name of the property
*/
public Scope (String href, int depth) {
this.href = href;
this.depth = depth;
}
/**
* Constructs a scope from e FROM element
*
* @param propertyName the name of the property
*/
public Scope (Element fromElement) throws BadQueryException {
Namespace namespace = fromElement.getNamespace();
String name = fromElement.getName ();
if (! (namespace.getURI().equals (NodeProperty.DEFAULT_NAMESPACE)
&& name.equals (Literals.FROM)))
throw new BadQueryException ("expected DAV:from");
Element scope = fromElement.getChild (Literals.SCOPE, namespace);
href = scope.getChildTextTrim (Literals.HREF, namespace);
Element depth = scope.getChild (Literals.DEPTH, namespace);
if (depth != null) {
String d = depth.getTextTrim();
if (d.equals ("0"))
this.depth = Literals.DEPTH_0;
else if (d.equals ("1"))
this.depth = Literals.DEPTH_1;
else if (d.equals (Literals.INFINITY))
this.depth = Literals.DEPTH_INFINITY;
else
this.depth = Literals.DEPTH_UNDEFINED;
}
else
this.depth = Literals.DEPTH_UNDEFINED;
}
/**
* href accessor
*
* @return a String
*
*/
public String getHref() {
return href;
}
/**
* depth accessor
*
* @return an int
*
*/
public int getDepth() {
return depth;
}
/**
* checks, if another Object is equal to this SelectedProperty
*
* @param o an Object
*
* @return true if equal
*/
public boolean equals (Object o) {
if (! (o instanceof Scope))
return false;
Scope other = (Scope)o;
if (!href.equals (other.getHref()))
return false;
if (! (depth == other.getDepth()))
return false;
return true;
}
/**
* Debugging purpose
*
* @return String representation of this SelectedProperty
*/
public String toString () {
return href + ", depth = " + depth;
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/SelectedProperty.java
Index: SelectedProperty.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/SelectedProperty.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.content.NodeProperty;
/**
* Holds one property as part of the SELECT element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class SelectedProperty {
private String namespace;
private String propertyName;
/**
* Constructs a SelectedProperty using the default namespace as defined
* in NodeProperty
*
* @param propertyName the name of the property
*/
public SelectedProperty (String propertyName) {
this.propertyName = propertyName;
this.namespace = NodeProperty.DEFAULT_NAMESPACE;
}
/**
* Constructs a SelectedProperty:
*
* @param propertyName the name of the property
* @param namespace the namespace of the property
*/
public SelectedProperty (String propertyName, String namespace) {
this.propertyName = propertyName;
this.namespace = namespace;
}
/**
* Method getPropertyName
*
* @return the property's name
*/
public String getPropertyName() {
return propertyName;
}
/**
* Method getNamespace
*
* @return the property's namespace
*/
public String getNamespace() {
return namespace;
}
/**
* checks, if another Object is equal to this SelectedProperty
*
* @param o an Object
*
* @return true if equal
*/
public boolean equals (Object o) {
if (! (o instanceof SelectedProperty))
return false;
SelectedProperty other = (SelectedProperty)o;
if (!namespace.equals (other.getNamespace()))
return false;
if (!propertyName.equals (other.getPropertyName()))
return false;
return true;
}
/**
* debugging purpose
*
* @return String representation of this SelectedProperty
*/
public String toString () {
return namespace + propertyName;
}
}
1.1
jakarta-slide/src/share/org/apache/slide/search/basic/SelectedPropertyList.java
Index: SelectedPropertyList.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/SelectedPropertyList.java,v
1.1 2002/01/28 11:24:36 juergen Exp $
* $Revision: 1.1 $
* $Date: 2002/01/28 11:24:36 $
*
* ====================================================================
*
* 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 [EMAIL PROTECTED]
*
* 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.BadQueryException;
import org.apache.slide.content.NodeProperty;
import org.jdom.Element;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
/**
* Holds one property as part of the SELECT element.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Wallmer</a>
* @version $Revision: 1.1 $
*/
public class SelectedPropertyList {
private boolean isAllProp = false;
private List selectedPropertyList = new ArrayList ();
/**
* Default constructor
*/
public SelectedPropertyList () {}
/**
* Constructs a List of SelectedProperty from a DAV:prop element
* in NodeProperty
*
* @param propertyName the name of the property
*/
public SelectedPropertyList (Element propElement)
throws BadQueryException
{
String uri = propElement.getNamespace().getURI();
String name = propElement.getName ();
if (! (uri.equals (NodeProperty.DEFAULT_NAMESPACE)
&& name.equals ("prop")))
throw new BadQueryException ("expected DAV:prop");
Iterator it = propElement.getChildren().iterator();
while (it.hasNext()) {
Element prop = (Element)it.next();
uri = prop.getNamespace().getURI();
name = prop.getName ();
addSelectedProperty (new SelectedProperty (name, uri));
}
}
/**
* Constructs a List of SelectedProperty from a DAV:prop element
* in NodeProperty
*
* @param propertyName the name of the property
*/
public SelectedPropertyList (boolean isAllProp) {
super ();
this.isAllProp = isAllProp;
}
/**
* Method addSelectedProperty
*
* @param prop a SelectedProperty
*/
public void addSelectedProperty (SelectedProperty prop) {
if (isAllProp == true)
throw new IllegalStateException ();
selectedPropertyList.add (prop);
}
/**
* Returns an iterator for all selected properties
*
* @return an Iterator
*/
public Iterator iterator () {
if (isAllProp == true)
throw new IllegalStateException ();
return selectedPropertyList.iterator();
}
/**
* Method equals
*
* @param o an Object
*
* @return true if equal
*/
public boolean equals (Object o) {
if (! (o instanceof SelectedPropertyList))
return false;
SelectedPropertyList p = (SelectedPropertyList) o;
SelectedProperty sThis, sOther;
Iterator it = p.iterator();
int size = selectedPropertyList.size();
for (int i = 0; i < size; i++) {
if (!it.hasNext())
return false;
sThis = (SelectedProperty) selectedPropertyList.get (i);
sOther = (SelectedProperty) it.next();
if (!sThis.equals(sOther))
return false;
}
if (it.hasNext())
return false;
return true;
}
/**
* Method toString
*
* @return string representation
*/
public String toString () {
Iterator it = iterator();
StringBuffer sb = new StringBuffer();
while (it.hasNext()) {
sb.append (((SelectedProperty)it.next()).toString());
if (it.hasNext())
sb.append (", ");
}
return sb.toString();
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>