java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIOptions.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 03 Jul 2014 00:18:35 +0200
changeset 54 3d5cc308e268
child 55 c703fb7f088f
permissions -rw-r--r--
CLIOptions, CLIParser – basics
franta-hg@54
     1
/**
franta-hg@54
     2
 * Alt2XML
franta-hg@54
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@54
     4
 *
franta-hg@54
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@54
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@54
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@54
     8
 * (at your option) any later version.
franta-hg@54
     9
 *
franta-hg@54
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@54
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@54
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@54
    13
 * GNU General Public License for more details.
franta-hg@54
    14
 *
franta-hg@54
    15
 * You should have received a copy of the GNU General Public License
franta-hg@54
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@54
    17
 */
franta-hg@54
    18
package cz.frantovo.alt2xml.cli;
franta-hg@54
    19
franta-hg@54
    20
import java.io.File;
franta-hg@54
    21
import java.io.InputStream;
franta-hg@54
    22
import java.io.OutputStream;
franta-hg@54
    23
import java.util.ArrayList;
franta-hg@54
    24
import java.util.List;
franta-hg@54
    25
import java.util.Properties;
franta-hg@54
    26
franta-hg@54
    27
/**
franta-hg@54
    28
 * Holds options from command line, validates them, combines with configuration and provides derived
franta-hg@54
    29
 * objects.
franta-hg@54
    30
 *
franta-hg@54
    31
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@54
    32
 */
franta-hg@54
    33
public class CLIOptions {
franta-hg@54
    34
franta-hg@54
    35
	private File inputFile;
franta-hg@54
    36
	private InputStream inputStream;
franta-hg@54
    37
	private String inputUrl;
franta-hg@54
    38
franta-hg@54
    39
	private String systemId;
franta-hg@54
    40
	private final Properties readerProperties = new Properties();
franta-hg@54
    41
franta-hg@54
    42
	private OutputStream outputStream;
franta-hg@54
    43
	private String action;
franta-hg@54
    44
	private final Properties actionProperties = new Properties();
franta-hg@54
    45
	private final List<String> actionData = new ArrayList<>();
franta-hg@54
    46
franta-hg@54
    47
	public void validate() throws InvalidOptionsException {
franta-hg@54
    48
		InvalidOptionsException e = new InvalidOptionsException();
franta-hg@54
    49
franta-hg@54
    50
		/**
franta-hg@54
    51
		 * TODO: validace
franta-hg@54
    52
		 */
franta-hg@54
    53
		if (e.hasProblems()) {
franta-hg@54
    54
			throw e;
franta-hg@54
    55
		}
franta-hg@54
    56
	}
franta-hg@54
    57
franta-hg@54
    58
	public void setInputFile(File inputFile) {
franta-hg@54
    59
		this.inputFile = inputFile;
franta-hg@54
    60
	}
franta-hg@54
    61
franta-hg@54
    62
	public void setInputStream(InputStream inputStream) {
franta-hg@54
    63
		this.inputStream = inputStream;
franta-hg@54
    64
	}
franta-hg@54
    65
franta-hg@54
    66
	public void setInputUrl(String inputUrl) {
franta-hg@54
    67
		this.inputUrl = inputUrl;
franta-hg@54
    68
	}
franta-hg@54
    69
franta-hg@54
    70
	public void setSystemId(String systemId) {
franta-hg@54
    71
		this.systemId = systemId;
franta-hg@54
    72
	}
franta-hg@54
    73
 
franta-hg@54
    74
	public void setOutputStream(OutputStream outputStream) {
franta-hg@54
    75
		this.outputStream = outputStream;
franta-hg@54
    76
	}
franta-hg@54
    77
	
franta-hg@54
    78
	public void setAction(String action) {
franta-hg@54
    79
		this.action = action;
franta-hg@54
    80
	}
franta-hg@54
    81
franta-hg@54
    82
	public void addReaderProperty(String name, String value) {
franta-hg@54
    83
		readerProperties.put(name, value);
franta-hg@54
    84
	}
franta-hg@54
    85
franta-hg@54
    86
	public void addActionProperty(String name, String value) {
franta-hg@54
    87
		actionProperties.put(name, value);
franta-hg@54
    88
	}
franta-hg@54
    89
franta-hg@54
    90
	public void addActionData(String value) {
franta-hg@54
    91
		actionData.add(value);
franta-hg@54
    92
	}
franta-hg@54
    93
franta-hg@54
    94
}