java.lang.Object
org.gcube.resources.discovery.client.queries.impl.QueryBox
org.gcube.resources.discovery.client.queries.impl.QueryTemplate
All Implemented Interfaces:
Query
Direct Known Subclasses:
XQuery

public class QueryTemplate extends QueryBox implements Query
A Query that interpolates named parameters inside a template.

Templates are strings with empty XML elements, optionally with a DEFAULT attribute, e.g.:

all results that satisfy <cond1/> or <cond2 def='that'/> <extra/>

Whenever expression() is invoked, the elements in the template are replaced according to the first rule that applies among the following:

  • by the value of an equally named parameter, if one exists
  • by the value of the DEFAULT attribute, if one exists
  • by the empty string
For example, given the previous template and the single parameter cond1="this", expression() returns:

all results that satisfy this or that

  • Field Details

  • Constructor Details

    • QueryTemplate

      public QueryTemplate(String template)
      Creates an instance with a template.
      Parameters:
      template - the template
    • QueryTemplate

      public QueryTemplate(String template, Map<String,String> parameters)
      Creates an instance with a template and an initial set of parameters.
      Parameters:
      template - the template
  • Method Details

    • expression

      public String expression()
      Description copied from interface: Query
      Returns the textual expression of the query.
      Specified by:
      expression in interface Query
      Overrides:
      expression in class QueryBox
      Returns:
      the expression.
    • addParameter

      public void addParameter(String name, String value)
      Adds a parameter to the query, overwriting any value that it may already have.
      Parameters:
      name - the parameter name
      value - the parameter value
      Throws:
      IllegalStateException - if the parameter name or value are null
    • appendParameter

      public void appendParameter(String name, String value)
      Adds a parameter to the query, extending any value that it may already have.
      Parameters:
      name - the parameter name
      value - the value
      Throws:
      IllegalStateException - if the parameter name or value are null
    • parameter

      public String parameter(String name) throws IllegalStateException
      Returns the current value of a parameter.
      Parameters:
      name - the parameter name
      Returns:
      the value
      Throws:
      IllegalStateException - if the parameter does not exist
      IllegalStateException - if the parameter name is null
    • hasParameter

      public boolean hasParameter(String name)
      Returns true if the query has a given parameter.
      Parameters:
      name - the parameter name
      Returns:
      true if the query has a given parameter, false otherwise
      Throws:
      IllegalStateException - if the parameter name is null