Class SelectorExpression

java.lang.Object
com.iizix.prop.SelectorExpression
Direct Known Subclasses:
EditorSelectorExpression

public class SelectorExpression extends Object
The Selector Expression Parser.
Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • SelectorExpression

      public SelectorExpression(String expression)
      Creates the Expression String.

      There are four special sub expressions that are specified within brackets:

      • { dev: "device" } device or OS selection,
      • { lang: "language" } language selection,
      • { sel: "selectorReference" } used to get the result of another selector (circular references not allowed),
      • { wc: environmentVariable: "Wild*Card?String" } matches an environment variable,
      • { regexp: environmentVariable: "RegularExpressionWithinQuotes" } matches an environment variable in a Regular Expression,
      • { java: "javaClassName" } executes a Java class implementing the interface ISelectorExpression.
      Parameters:
      expression - The expression.
  • Method Details

    • isValidWordCharacter

      public boolean isValidWordCharacter(int ch)
      Checks for valid character in a word.

      The word has the same syntax validity as Atom names, i.e. the characters :/\{}"'?*^,; are not allowed, but augmented with white space characters - \t \r \n and space.

      Parameters:
      ch - The character to test.
      Returns:
      true for valid character, false otherwise.
    • parse

      public boolean parse()
      Parses the expression.
      Returns:
      true for success, false if errors are present.
    • getErrorPosition

      public int getErrorPosition()
      Gets the error position.
      Returns:
      The error position or -1 for no error.
    • getError

      public String getError()
      Gets the error.
      Returns:
      The error, or null for no error.
    • getExpression

      public String getExpression()
      Outputs the expression reformatted.

      If an error is present, the original expression is returned.

      Returns:
      The expression reformatted as a string.
    • getClassRefactoredExpression

      public String getClassRefactoredExpression(String oldClassName, String newClassName)
      Outputs the expression reformatted used for class refactoring.

      If an error is present, the original expression is returned.

      Parameters:
      oldClassName - The old class name.
      newClassName - The new class name.
      Returns:
      The expression reformatted as a string.
    • getSelectorRefactoredExpression

      public String getSelectorRefactoredExpression(String oldSelectorName, String newSelectorName)
      Outputs the expression reformatted used for Selector refactoring.

      If an error is present, the original expression is returned.

      Parameters:
      oldSelectorName - The old Selector name.
      newSelectorName - The new Selector name.
      Returns:
      The expression reformatted as a string.
    • getReferences

      public SelectorExpression.Reference[] getReferences()
      Gets the selector and class references in the expression.
    • getReferences

      public void getReferences(HashSet<String> selectors, HashSet<String> classes)
      Gets the selector and class references in the expression.
    • isSelected

      public boolean isSelected(Selector selector, EnvProps envProps)
      Called to resolve the SelectorExpression by custom Java code.
      Parameters:
      envProps - The client environment properties to verify for environment.
      Returns:
      true if the Selector is selected to be used, false otherwise.
    • eval

      protected boolean eval(Selector selector, EnvProps envProps, int[] index, boolean isDesigner)
      Evaluates an expression at specified index.
      Parameters:
      selector - The selector.
      envProps - The client environment properties to verify for environment.
      index - The index in [0] processed.
      isDesigner - If true, Java classes always return true and are not called.
      Returns:
      Result from expression evaluation.
    • main

      public static void main(String[] args)
      Command line.