Package org.geotools.filter.text.cql2
Class CQL
- Object
-
- CQL
-
public class CQL extends Object
Utility class to parse CQL predicates and expressions to GeoAPIFilter
s andExpression
s, respectively.CQL is an acronym for Contextual Query Language, a query predicate language whose syntax is similar to a SQL WHERE clause, defined as OGC Common Query Language in clause 6.2.2 of the OGC Catalog Service for Web, version 2.0.1 implementation specification.
This class provides three methods,
toFilter(String)
,toExpression(String)
andtoFilterList(String)
; and an overloaded version of each one for the user to provide aFilterFactory
implementation to use.Usage
Here are some usage examples. Refer to the BNF of grammar to see what exactly you can do.Filter f = CQL.toFilter("ATTR1 < 10 AND ATTR2 < 2 OR ATTR3 > 10"); Filter f = CQL.toFilter("NAME = 'New York' "); Filter f = CQL.toFilter("NAME LIKE 'New%' "); Filter f = CQL.toFilter("NAME IS NULL"); Filter f = CQL.toFilter("DATE BEFORE 2006-11-30T01:30:00Z"); Filter f = CQL.toFilter("NAME DOES-NOT-EXIST"); Filter f = CQL.toFilter("QUANTITY BETWEEN 10 AND 20"); Filter f = CQL.toFilter("CROSSES(SHAPE, LINESTRING(1 2, 10 15))"); Filter f = CQL.toFilter("BBOX(SHAPE, 10,20,30,40)"); Expression e = CQL.toExpression("NAME"); Expression e = CQL.toExpression("QUANTITY * 2"); Expression e = CQL.toExpression("strConcat(NAME, 'suffix')"); List filters = CQL.toFilterList("NAME IS NULL;BBOX(SHAPE, 10,20,30,40);INCLUDE");
- Since:
- 2.5
- Author:
- Mauricio Pazos (Axios Engineering), Gabriel Roldan (Axios Engineering)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
main(String[] args)
Command line expression tester used to try out filters and expressions.static String
toCQL(List<Filter> filterList)
static String
toCQL(Expression expression)
Generates the expression text associated to theExpression
object.static String
toCQL(Filter filter)
Generates the cql predicate associated to theFilter
object.static Expression
toExpression(String cqlExpression)
Parses the input string in OGC CQL format into an Expression, using the systems defaultFilterFactory
implementation.static Expression
toExpression(String cqlExpression, FilterFactory filterFactory)
Parses the input string in OGC CQL format into anExpression
, using the providedFilterFactory
.static Filter
toFilter(String cqlPredicate)
Parses the input string in OGC CQL format into a Filter, using the systems default FilterFactory implementation.static Filter
toFilter(String cqlPredicate, FilterFactory filterFactory)
Parses the input string in OGC CQL format into a Filter, using the provided FilterFactory.static List<Filter>
toFilterList(String cqlFilterList)
Parses the input string, which has to be a list of OGC CQL predicates separated by;
into aList
ofFilter
s, using the provided FilterFactory.static List<Filter>
toFilterList(String cqlSequencePredicate, FilterFactory filterFactory)
Parses the input string which has to be a list of OGC CQL predicates separated by ";
" into aList
ofFilter
s, using the provided FilterFactory.
-
-
-
Method Detail
-
toFilter
public static Filter toFilter(String cqlPredicate) throws CQLException
Parses the input string in OGC CQL format into a Filter, using the systems default FilterFactory implementation.- Parameters:
cqlPredicate
- a string containing a query predicate in OGC CQL format.- Returns:
- a
Filter
equivalent to the constraint specified incqlPredicate
. - Throws:
CQLException
-
toFilter
public static Filter toFilter(String cqlPredicate, FilterFactory filterFactory) throws CQLException
Parses the input string in OGC CQL format into a Filter, using the provided FilterFactory.- Parameters:
cqlPredicate
- a string containing a query predicate in OGC CQL format.filterFactory
- theFilterFactory
to use for the creation of the Filter. If it is null the method finds the default implementation.- Returns:
- a
Filter
equivalent to the constraint specified inPredicate
. - Throws:
CQLException
-
toExpression
public static Expression toExpression(String cqlExpression) throws CQLException
Parses the input string in OGC CQL format into an Expression, using the systems defaultFilterFactory
implementation.- Parameters:
cqlExpression
- a string containing an OGC CQL expression.- Returns:
- a
Expression
equivalent to the one specified incqlExpression
. - Throws:
CQLException
-
toExpression
public static Expression toExpression(String cqlExpression, FilterFactory filterFactory) throws CQLException
Parses the input string in OGC CQL format into anExpression
, using the providedFilterFactory
.- Parameters:
cqlExpression
- a string containing a OGC CQL expression.filterFactory
- theFilterFactory
to use for the creation of the Expression. If it is null the method finds the default implementation.- Returns:
- a
Filter
equivalent to the constraint specified incqlExpression
. - Throws:
CQLException
-
toFilterList
public static List<Filter> toFilterList(String cqlFilterList) throws CQLException
Parses the input string, which has to be a list of OGC CQL predicates separated by;
into aList
ofFilter
s, using the provided FilterFactory.- Parameters:
cqlFilterList
- a list of OGC CQL predicates separated by ";
"- Returns:
- a
List
ofFilter
, one for each input CQL statement - Throws:
CQLException
-
toCQL
public static String toCQL(List<Filter> filterList)
- Returns:
- ecql predicates separated by ";"
-
toCQL
public static String toCQL(Filter filter)
Generates the cql predicate associated to theFilter
object.- Returns:
- cql predicate
-
toCQL
public static String toCQL(Expression expression)
Generates the expression text associated to theExpression
object.- Returns:
- expression as text
-
toFilterList
public static List<Filter> toFilterList(String cqlSequencePredicate, FilterFactory filterFactory) throws CQLException
Parses the input string which has to be a list of OGC CQL predicates separated by ";
" into aList
ofFilter
s, using the provided FilterFactory.- Parameters:
cqlSequencePredicate
- a list of OGC CQL predicates separated by ";
"filterFactory
- theFilterFactory
to use for the creation of the Expression. If it is null the method finds the default implementation.- Returns:
- a List of
Filter
, one for each input CQL statement - Throws:
CQLException
-
main
public static final void main(String[] args)
Command line expression tester used to try out filters and expressions.
-
-