Class Query
- Direct Known Subclasses:
JDOM2Query,Query
The XQuery syntax supported conforms to the W3C XQuery 1.0 drafts.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Configurationprotected booleanprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected intprotected booleanprotected Stringprotected Stringprotected booleanprotected booleanprotected booleanprotected booleanprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyLocalOptions(CommandLineOptions options, Configuration config) Customisation hook: apply options defined locally in a subclassprotected voidReport incorrect usage of the command line, with a list of the options and arguments that are availableprotected XQueryExecutablecompileQuery(XQueryCompiler compiler, String queryFileName, boolean useURLs) Compile the querystatic voidcreateFileIfNecessary(File file) Utility method to create a file if it does not already exist, including creation of any necessary directories named in the file pathvoidSupport method for main program.voidSupport method for main program.voidMain entry point for running the program from the command line via the staticmain(java.lang.String[])method.protected voidexplain(XQueryExpression exp) Explain the results of query compilationprotected ConfigurationGet the configuration in useprotected voidinitializeConfiguration(Configuration config) Customisation hook called immediately after the Configuration object is instantiated.static voidMain program, can be used directly from the command line.protected voidprocessSource(Source sourceInput, XQueryExecutable exp, XQueryEvaluator evaluator) Process the supplied XML source fileprotected SourceprocessSourceFile(String sourceFileName, boolean useURLs) protected voidExit with a message, by throwing an unchecked exception.protected voidrunQuery(XQueryExecutable exp, XQueryEvaluator evaluator, Source input, Destination destination) Run the queryprotected voidrunUpdate(XQueryExecutable exp, XQueryEvaluator evaluator, Serializer serializer) Run an updating query
-
Field Details
-
config
-
showTime
protected boolean showTime -
repeat
protected int repeat -
sourceXmlFileName
-
sourceJsonFileName
-
queryFileName
-
useURLs
protected boolean useURLs -
outputFileName
-
moduleURIResolverClass
-
explaining
protected boolean explaining -
wrap
protected boolean wrap -
streaming
protected boolean streaming -
updating
protected boolean updating -
writeback
protected boolean writeback -
backup
protected boolean backup -
explainOutputFileName
-
languageVersion
-
nsOption
-
-
Constructor Details
-
Query
public Query()
-
-
Method Details
-
getConfiguration
Get the configuration in use- Returns:
- the configuration
-
main
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
-
execute
Main entry point for running the program from the command line via the staticmain(java.lang.String[])method.This method runs the program, catches any
CommandExitExceptions, and callingSystem.exit(int)withCommandExitException.getCode().- Parameters:
args- List of arguments supplied on operating system command line- Since:
- 12.10
-
doQuery
Support method for main program. This support method can also be invoked from subclasses that support the same command line interface.In previous Saxon versions (12.9 and earlier) this method could call
System.exit(int)unless the argument"-quit:off"was passed. Now it throws aCommandExitExceptionin this case.CommandExitExceptionextendsRuntimeException, so behaviour with and without"-quit:off"is functionally identical for API clients now.- Parameters:
args- the command-line arguments
-
doQuery
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 argumentscommand- not used, retained for backwards compatibility
-
initializeConfiguration
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
Customisation hook: apply options defined locally in a subclass- Parameters:
options- the CommandLineOptionsconfig- the Saxon Configuration
-
processSourceFile
protected Source processSourceFile(String sourceFileName, boolean useURLs) throws TransformerException - Throws:
TransformerException
-
compileQuery
protected XQueryExecutable compileQuery(XQueryCompiler compiler, String queryFileName, boolean useURLs) throws SaxonApiException, IOException Compile the query- Parameters:
compiler- the XQuery compilerqueryFileName- the filename holding the query (or "-" for the standard input, or the actual query text enclosed in curly bracesuseURLs- true if the filename is in the form of a URI- Returns:
- the compiled query
- Throws:
SaxonApiException- if query compilation failsIOException- if the query cannot be read
-
explain
Explain the results of query compilation- Parameters:
exp- the compiled expression- Throws:
FileNotFoundException- if the destination for the explanation doesn't existXPathException- if other failures occur
-
processSource
protected void processSource(Source sourceInput, XQueryExecutable exp, XQueryEvaluator evaluator) throws SaxonApiException Process the supplied XML source file- Parameters:
sourceInput- the supplied sourceexp- the compiled XQuery expressionevaluator- the dynamic query context- Throws:
SaxonApiException- if processing fails
-
runQuery
protected void runQuery(XQueryExecutable exp, XQueryEvaluator evaluator, Source input, Destination destination) throws SaxonApiException Run the query- Parameters:
exp- the compiled query expressionevaluator- the dynamic query contextinput- the supplied XML source if anydestination- the destination for serialized results- Throws:
SaxonApiException- if the query fails
-
runUpdate
protected void runUpdate(XQueryExecutable exp, XQueryEvaluator evaluator, Serializer serializer) throws SaxonApiException Run an updating query- Parameters:
exp- the compiled query expressionevaluator- the query evaluatorserializer- the destination for serialized results- Throws:
SaxonApiException- if the query fails
-
quit
Exit with a message, by throwing an unchecked exception. If this method throws aCommandExitExceptionthen the catching method will callSystem.exit(int)using the value fromCommandExitException.getCode().- Parameters:
message- The message to be outputcode- The result code to be returned to the operating system shell- Throws:
CommandExitException
-
badUsage
Report incorrect usage of the command line, with a list of the options and arguments that are available- Parameters:
message- The error message
-
createFileIfNecessary
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
-