Class QueryFormatter


  • public class QueryFormatter
    extends Object
    Formatter for JCR queries in order to make them easier to read. Formatting is done on a best-effort basis. Warning: Care was taken to not add newlines inside string literals and so on, but there is still no guarantee that the formatted query is semantically equal to the original one. It is NOT recommended to run queries that are returned by these methods.
    • Constructor Detail

      • QueryFormatter

        public QueryFormatter()
    • Method Detail

      • isXPath

        public static boolean isXPath​(String query,
                                      String language)
        Detect whether the query is an XPath query.
        Parameters:
        query - the query
        language - the language, if known, or null
        Returns:
        true if xpath
      • format

        public static String format​(@NotNull
                                    @NotNull String query,
                                    String language)
        Format the query into a more human-readable way, by adding newlines before keywords such as "where", "and", and "or".
        Parameters:
        query - the query (may not be null)
        language - the query language, or null if unknown
        Returns:
        the formatted query