Package org.apache.sis.console
Class FormattedOutputCommand
java.lang.Object
org.apache.sis.console.CommandRunner
org.apache.sis.console.FormattedOutputCommand
- Direct Known Subclasses:
CRSCommand
,IdentifierCommand
,MetadataCommand
,TransformCommand
Base class of commands that provided formatted output.
The output format is controlled by
OutputFormat
enumeration.- Since:
- 0.8
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Convention
The WKT convention, ornull
if it does not apply.(package private) boolean
Sets totrue
byreadMetadataOrCRS()
if the users provided an unexpected number of file arguments.private final OutputFormat
The output format.private final DataStoreProvider
private Version
Desired version of output format, ornull
if unspecified.Fields inherited from class org.apache.sis.console.CommandRunner
colors, commandName, debug, encoding, err, files, instance, locale, options, out, outputBuffer, TEST, timezone
-
Constructor Summary
ConstructorsConstructorDescriptionFormattedOutputCommand
(int commandIndex, String[] arguments, EnumSet<Option> validOptions, OutputFormat... supportedFormats) Creates a new sub-command with the given command-line arguments. -
Method Summary
Modifier and TypeMethodDescription(package private) final void
Formats the given metadata or CRS object to the standard output stream.(package private) Predicate<TreeTable.Node>
Returns the filter for simplifying the tree table to be formatted, ornull
if none.private boolean
Returnstrue
ifCommandRunner.out
is sending its output to the console.(package private) final Object
If the given argument seems to be an authority code ("URN", "EPSG", "CRS", "AUTO", etc.), delegates toCRS.forCode(String)
.Methods inherited from class org.apache.sis.console.CommandRunner
canNotOpen, error, hasContradictoryOptions, hasUnexpectedFileCount, help, run, useStandardInput
-
Field Details
-
outputFormat
The output format. -
convention
Convention conventionThe WKT convention, ornull
if it does not apply. This is slightly redundant toversion
, but specific to the WKT format. -
version
Desired version of output format, ornull
if unspecified. The format can be specified after the format name, for example"gpx-1.1"
. -
provider
-
hasUnexpectedFileCount
boolean hasUnexpectedFileCountSets totrue
byreadMetadataOrCRS()
if the users provided an unexpected number of file arguments. In such case, theCommandRunner.run()
should terminate with exit codeCommand.INVALID_ARGUMENT_EXIT_CODE
.
-
-
Constructor Details
-
FormattedOutputCommand
FormattedOutputCommand(int commandIndex, String[] arguments, EnumSet<Option> validOptions, OutputFormat... supportedFormats) throws InvalidOptionException Creates a new sub-command with the given command-line arguments. This constructor is forMetadataCommand
subclasses.- Parameters:
commandIndex
- index of thearguments
element containing the sub-command name, or -1 if none.arguments
- the command-line arguments provided by the user.validOptions
- the command-line options allowed by this sub-command.supportedFormats
- the output formats to accept. The first format is the default one.- Throws:
InvalidOptionException
- if an illegal option has been provided, or the option has an illegal value.
-
-
Method Details
-
readMetadataOrCRS
If the given argument seems to be an authority code ("URN", "EPSG", "CRS", "AUTO", etc.), delegates toCRS.forCode(String)
. Otherwise reads the metadata using a datastore. The input format is detected automatically (this is notoutputFormat
).- Returns:
- a
Metadata
orCoordinateReferenceSystem
instance, ornull
if none. - Throws:
DataStoreException
- if an error occurred while reading the file.org.opengis.util.FactoryException
- if an error occurred while looking for a CRS identifier.
-
format
Formats the given metadata or CRS object to the standard output stream. The format is determined byoutputFormat
and (in WKT case only)convention
.- Throws:
DataStoreException
- if an error occurred while producing output using a data store.JAXBException
- if an error occurred while producing the XML output using JAXB.IOException
- should never happen since we are appending to a print writer.
-
getNodeFilter
Predicate<TreeTable.Node> getNodeFilter()Returns the filter for simplifying the tree table to be formatted, ornull
if none. This is used only for the tree in text format (not for XML output). -
isConsole
private boolean isConsole()Returnstrue
ifCommandRunner.out
is sending its output to the console. If not, then we are probably writing to a file or the user specified his own encoding. In such case, we will send the XML output to anOutputStream
instead of to aWriter
and let the marshaller apply the encoding itself.
-