Package net.sf.saxon

Class Query

java.lang.Object
net.sf.saxon.Query
Direct Known Subclasses:
JDOM2Query, Query

public class Query extends Object
This Query class provides a command-line interface to the Saxon XQuery processor.

The XQuery syntax supported conforms to the W3C XQuery 1.0 drafts.

  • Field Details Link icon

    • config Link icon

      protected Configuration config
    • showTime Link icon

      protected boolean showTime
    • repeat Link icon

      protected int repeat
    • sourceXmlFileName Link icon

      protected String sourceXmlFileName
    • sourceJsonFileName Link icon

      protected String sourceJsonFileName
    • queryFileName Link icon

      protected String queryFileName
    • useURLs Link icon

      protected boolean useURLs
    • outputFileName Link icon

      protected String outputFileName
    • moduleURIResolverClass Link icon

      protected String moduleURIResolverClass
    • explaining Link icon

      protected boolean explaining
    • wrap Link icon

      protected boolean wrap
    • projection Link icon

      protected boolean projection
    • streaming Link icon

      protected boolean streaming
    • updating Link icon

      protected boolean updating
    • writeback Link icon

      protected boolean writeback
    • backup Link icon

      protected boolean backup
    • explainOutputFileName Link icon

      protected String explainOutputFileName
    • languageVersion Link icon

      protected String languageVersion
    • nsOption Link icon

      protected String nsOption
  • Constructor Details Link icon

    • Query Link icon

      public Query()
  • Method Details Link icon

    • getConfiguration Link icon

      protected Configuration getConfiguration()
      Get the configuration in use
      Returns:
      the configuration
    • main Link icon

      public static void main(String[] args)
      Main program, can be used directly from the command line.

      The format is:

      java net.sf.saxon.Query [options] query-file >output-file

      followed by any number of parameters in the form {keyword=value}... which can be referenced from within the query.

      This program executes the query in query-file.

      Parameters:
      args - List of arguments supplied on operating system command line
    • doQuery Link icon

      public void doQuery(String[] args)
      Support method for main program. This support method can also be invoked from subclasses that support the same command line interface
      Parameters:
      args - the command-line arguments
    • doQuery Link icon

      public void doQuery(String[] args, String command)
      Support method for main program. This support method can also be invoked from subclasses that support the same command line interface
      Parameters:
      args - the command-line arguments
      command - not used, retained for backwards compatibility
    • initializeConfiguration Link icon

      protected void initializeConfiguration(Configuration config)
      Customisation hook called immediately after the Configuration object is instantiated. The intended purpose of this hook is to allow a subclass to supply an OEM license key programmatically, but it can also be used for other initialization of the Configuration. This method is called before analyzing the command line options, so configuration settings made at this stage may be overridden when the command line options are processed. However, if a configuration file is used, the settings defined in the configuration file will have been applied.
      Parameters:
      config - the Configuration object
    • applyLocalOptions Link icon

      protected void applyLocalOptions(CommandLineOptions options, Configuration config)
      Customisation hook: apply options defined locally in a subclass
      Parameters:
      options - the CommandLineOptions
      config - the Saxon Configuration
    • processSourceFile Link icon

      protected Source processSourceFile(String sourceFileName, boolean useURLs) throws TransformerException
      Throws:
      TransformerException
    • compileQuery Link icon

      protected XQueryExecutable compileQuery(XQueryCompiler compiler, String queryFileName, boolean useURLs) throws SaxonApiException, IOException
      Compile the query
      Parameters:
      compiler - the XQuery compiler
      queryFileName - the filename holding the query (or "-" for the standard input, or the actual query text enclosed in curly braces
      useURLs - true if the filename is in the form of a URI
      Returns:
      the compiled query
      Throws:
      SaxonApiException - if query compilation fails
      IOException - if the query cannot be read
    • explain Link icon

      protected void explain(XQueryExpression exp) throws FileNotFoundException, XPathException
      Explain the results of query compilation
      Parameters:
      exp - the compiled expression
      Throws:
      FileNotFoundException - if the destination for the explanation doesn't exist
      XPathException - if other failures occur
    • processSource Link icon

      protected void processSource(Source sourceInput, XQueryExecutable exp, XQueryEvaluator evaluator) throws SaxonApiException
      Process the supplied XML source file
      Parameters:
      sourceInput - the supplied source
      exp - the compiled XQuery expression
      evaluator - the dynamic query context
      Throws:
      SaxonApiException - if processing fails
    • runQuery Link icon

      protected void runQuery(XQueryExecutable exp, XQueryEvaluator evaluator, Source input, Destination destination) throws SaxonApiException
      Run the query
      Parameters:
      exp - the compiled query expression
      evaluator - the dynamic query context
      input - the supplied XML source if any
      destination - the destination for serialized results
      Throws:
      SaxonApiException - if the query fails
    • runUpdate Link icon

      protected void runUpdate(XQueryExecutable exp, XQueryEvaluator evaluator, Serializer serializer) throws SaxonApiException
      Run an updating query
      Parameters:
      exp - the compiled query expression
      evaluator - the query evaluator
      serializer - the destination for serialized results
      Throws:
      SaxonApiException - if the query fails
    • quit Link icon

      protected void quit(String message, int code)
      Exit with a message
      Parameters:
      message - The message to be output
      code - The result code to be returned to the operating system shell
    • badUsage Link icon

      protected void badUsage(String message)
      Report incorrect usage of the command line, with a list of the options and arguments that are available
      Parameters:
      message - The error message
    • createFileIfNecessary Link icon

      public static void createFileIfNecessary(File file) throws IOException
      Utility method to create a file if it does not already exist, including creation of any necessary directories named in the file path
      Parameters:
      file - the file that is required to exist
      Throws:
      IOException - if file creation fails