Class ClauseParser

java.lang.Object
org.apache.juneau.commons.beanquery.ClauseParser

public final class ClauseParser extends Object
The clause grammar shared by the one search string and the one opts string (design §5.3).

A string is a list of key=value clauses:

  • Top-level commas (outside parentheses) separate clauses. A comma inside parentheses is protected (so an $in(OPEN,CLOSED) value survives intact).
  • The first unescaped = in a clause separates the key from the value; the value keeps any further = characters verbatim.
  • Backslash escapes decode to literals: \, → comma, \= → equals, \\ → backslash, \$ → dollar. Any other backslash is left as-is.

For search, the key is a column name and the value is a raw $-expression handed to SearchExpressionParser. For opts, the key is an option name and the value is a plain string. A session decodes these strings when the query runs; the BeanQuery bean itself never parses them.

Since:
10.0.0
  • Method Details

    • parse

      public static Map<String,String> parse(String s)
      Parses a search-or-opts string into an ordered key→value map.

      Keys are stripped of surrounding whitespace; values are decoded but otherwise kept verbatim. A blank input, or a null input, yields an empty map. A later clause with a duplicate key overwrites an earlier one.

      Parameters:
      s - The raw string (a search or opts value). Can be null.
      Returns:
      A new, mutable, insertion-ordered map (never null).
    • escape

      public static String escape(String s)
      Escapes a single key or value so it can be spliced into a clause string without changing its meaning.

      Backslash, comma, and equals become \\, \,, and \= respectively. A leading $ additionally becomes \$, so an escaped column name can never be mistaken for a $or(/$and(/$not( search-grammar group prefix (design §4). Note that a raw $-expression value must not be escaped — its commas live inside parentheses and its structure is the $-language's own, not this grammar's.

      Parameters:
      s - The raw key or value. Can be null.
      Returns:
      The escaped text, or null if s is null.