Class CQL


  • public class CQL
    extends Object
    Utility class to parse CQL predicates and expressions to GeoAPI Filters and Expressions, 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) and toFilterList(String); and an overloaded version of each one for the user to provide a FilterFactory 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");
     
     
    Implementation specification 1.0
    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)
      Generates the ecql predicates associated to the List of Filters object.
      static String toCQL​(Expression expression)
      Generates the expression text associated to the Expression object.
      static String toCQL​(Filter filter)
      Generates the cql predicate associated to the Filter object.
      static Expression toExpression​(String cqlExpression)
      Parses the input string in OGC CQL format into an Expression, using the systems default FilterFactory implementation.
      static Expression toExpression​(String cqlExpression, FilterFactory filterFactory)
      Parses the input string in OGC CQL format into an Expression, using the provided FilterFactory.
      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 a List of Filters, 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 a List of Filters, using the provided FilterFactory.
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 in cqlPredicate.
        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 - the FilterFactory 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 in Predicate.
        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 default FilterFactory implementation.
        Parameters:
        cqlExpression - a string containing an OGC CQL expression.
        Returns:
        a Expression equivalent to the one specified in cqlExpression.
        Throws:
        CQLException
      • toExpression

        public static Expression toExpression​(String cqlExpression,
                                              FilterFactory filterFactory)
                                       throws CQLException
        Parses the input string in OGC CQL format into an Expression, using the provided FilterFactory.
        Parameters:
        cqlExpression - a string containing a OGC CQL expression.
        filterFactory - the FilterFactory 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 in cqlExpression .
        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 a List of Filters, using the provided FilterFactory.
        Parameters:
        cqlFilterList - a list of OGC CQL predicates separated by ";"
        Returns:
        a List of Filter, one for each input CQL statement
        Throws:
        CQLException
      • toCQL

        public static String toCQL​(List<Filter> filterList)
        Generates the ecql predicates associated to the List of Filters object.
        Returns:
        ecql predicates separated by ";"
      • toCQL

        public static String toCQL​(Filter filter)
        Generates the cql predicate associated to the Filter object.
        Returns:
        cql predicate
      • toCQL

        public static String toCQL​(Expression expression)
        Generates the expression text associated to the Expression 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 a List of Filters, using the provided FilterFactory.
        Parameters:
        cqlSequencePredicate - a list of OGC CQL predicates separated by ";"
        filterFactory - the FilterFactory 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.