All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.sis.console.FormattedOutputCommand Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.sis.console;

import java.util.Locale;
import java.util.EnumSet;
import java.io.Console;
import java.io.IOException;
import java.util.function.Predicate;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.JAXBException;
import org.opengis.metadata.Metadata;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.util.FactoryException;
import org.apache.sis.io.wkt.WKTFormat;
import org.apache.sis.io.wkt.Convention;
import org.apache.sis.io.wkt.Colors;
import org.apache.sis.metadata.MetadataStandard;
import org.apache.sis.metadata.ValueExistencePolicy;
import org.apache.sis.referencing.CRS;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.DataStores;
import org.apache.sis.storage.DataStoreProvider;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.base.CodeType;
import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.Version;
import org.apache.sis.util.collection.TableColumn;
import org.apache.sis.util.collection.TreeTable;
import org.apache.sis.util.collection.TreeTableFormat;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.measure.Range;
import org.apache.sis.setup.OptionKey;
import org.apache.sis.xml.MarshallerPool;
import org.apache.sis.xml.XML;


/**
 * Base class of commands that provided formatted output.
 * The output format is controlled by {@link OutputFormat} enumeration.
 *
 * @author  Martin Desruisseaux (Geomatys)
 */
abstract class FormattedOutputCommand extends CommandRunner {
    /**
     * The output format.
     */
    private final OutputFormat outputFormat;

    /**
     * The WKT convention, or {@code null} if it does not apply.
     * This is slightly redundant to {@link #version}, but specific to the WKT format.
     */
    Convention convention;

    /**
     * Desired version of output format, or {@code null} if unspecified.
     * The format can be specified after the format name, for example {@code "gpx-1.1"}.
     */
    private Version version;

    /**
     * The provider of {@link DataStore} instances capable to write data in the {@link #outputFormat},
     * or {@code null} if none.
     */
    private final DataStoreProvider provider;

    /**
     * Sets to {@code true} by {@link #readMetadataOrCRS()} if the users provided an unexpected number of file arguments.
     * In such case, the {@link #run()} should terminate with exit code {@link Command#INVALID_ARGUMENT_EXIT_CODE}.
     */
    boolean hasUnexpectedFileCount;

    /**
     * Creates a new sub-command with the given command-line arguments.
     * This constructor is for {@code MetadataCommand} subclasses.
     *
     * @param  commandIndex      index of the {@code arguments} element containing the sub-command name, or -1 if none.
     * @param  arguments         the command-line arguments provided by the user.
     * @param  validOptions      the command-line options allowed by this sub-command.
     * @param  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.
     */
    FormattedOutputCommand(final int commandIndex, final String[] arguments, final EnumSet




© 2015 - 2024 Weber Informatics LLC | Privacy Policy