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) ConventionThe WKT convention, ornullif it does not apply.(package private) booleanSets totruebyreadMetadataOrCRS()if the users provided an unexpected number of file arguments.private final OutputFormatThe output format.private final DataStoreProviderprivate VersionDesired version of output format, ornullif 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 voidFormats 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, ornullif none.private booleanReturnstrueifCommandRunner.outis sending its output to the console.(package private) final ObjectIf 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, ornullif it does not apply. This is slightly redundant toversion, but specific to the WKT format. -
version
Desired version of output format, ornullif unspecified. The format can be specified after the format name, for example"gpx-1.1". -
provider
-
hasUnexpectedFileCount
boolean hasUnexpectedFileCountSets totruebyreadMetadataOrCRS()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 forMetadataCommandsubclasses.- Parameters:
commandIndex- index of theargumentselement 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
MetadataorCoordinateReferenceSysteminstance, ornullif 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 byoutputFormatand (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, ornullif none. This is used only for the tree in text format (not for XML output). -
isConsole
private boolean isConsole()ReturnstrueifCommandRunner.outis 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 anOutputStreaminstead of to aWriterand let the marshaller apply the encoding itself.
-