Class FormattedOutputCommand

java.lang.Object
org.apache.sis.console.CommandRunner
org.apache.sis.console.FormattedOutputCommand
Direct Known Subclasses:
CRSCommand, IdentifierCommand, MetadataCommand, TransformCommand

abstract class FormattedOutputCommand extends CommandRunner
Base class of commands that provided formatted output. The output format is controlled by OutputFormat enumeration.
Since:
0.8
Version:
1.0
  • Field Details

    • outputFormat

      private final OutputFormat outputFormat
      The output format.
    • convention

      Convention convention
      The WKT convention, or null if it does not apply. This is slightly redundant to version, but specific to the WKT format.
    • version

      private Version version
      Desired version of output format, or null if unspecified. The format can be specified after the format name, for example "gpx-1.1".
    • provider

      private final DataStoreProvider provider
      The provider of DataStore instances capable to write data in the outputFormat, or null if none.
    • hasUnexpectedFileCount

      boolean hasUnexpectedFileCount
      Sets to true by readMetadataOrCRS() if the users provided an unexpected number of file arguments. In such case, the CommandRunner.run() should terminate with exit code Command.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 for MetadataCommand subclasses.
      Parameters:
      commandIndex - index of the arguments 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

      final Object readMetadataOrCRS() throws DataStoreException, org.opengis.util.FactoryException
      If the given argument seems to be an authority code ("URN", "EPSG", "CRS", "AUTO", etc.), delegates to CRS.forCode(String). Otherwise reads the metadata using a datastore. The input format is detected automatically (this is not outputFormat).
      Returns:
      a Metadata or CoordinateReferenceSystem instance, or null 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

      final void format(Object object) throws DataStoreException, JAXBException, IOException
      Formats the given metadata or CRS object to the standard output stream. The format is determined by outputFormat 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, or null if none. This is used only for the tree in text format (not for XML output).
    • isConsole

      private boolean isConsole()
      Returns true if CommandRunner.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 an OutputStream instead of to a Writer and let the marshaller apply the encoding itself.