3 * Copyright © 2014 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package cz.frantovo.alt2xml.cli;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Properties;
26 import org.xml.sax.InputSource;
29 * Holds options from command line, validates them, combines with configuration and provides derived
32 * @author Ing. František Kučera (frantovo.cz)
34 public class CLIOptions {
36 private File inputFile;
37 private InputStream inputStream;
39 private String systemId;
40 private final Properties readerProperties = new Properties();
42 private OutputStream outputStream;
43 private String action;
44 private final Properties actionProperties = new Properties();
45 private final List<String> actionData = new ArrayList<>();
47 public void validate() throws InvalidOptionsException {
48 InvalidOptionsException e = new InvalidOptionsException();
50 if (inputFile == null && systemId == null) {
51 e.addProblem(new InvalidOptionsException.OptionProblem("Please specify also systemId when reading from a stream (like STDIN) instead of from a file."));
57 if (e.hasProblems()) {
62 public void setInputFile(File inputFile) {
63 this.inputFile = inputFile;
66 public void setInputStream(InputStream inputStream) {
67 this.inputStream = inputStream;
70 public void setSystemId(String systemId) {
71 this.systemId = systemId;
74 public InputSource getInputSource() {
75 InputSource is = new InputSource();
77 if (inputFile != null) {
78 is.setSystemId(inputFile.toURI().toASCIIString());
81 if (inputStream != null) {
82 is.setByteStream(inputStream);
85 if (systemId != null) {
86 is.setSystemId(systemId);
92 public void setOutputStream(OutputStream outputStream) {
93 this.outputStream = outputStream;
96 public OutputStream getOutputStream() {
100 public void setAction(String action) {
101 this.action = action;
104 public String getAction() {
108 public void addReaderProperty(String name, String value) {
109 readerProperties.put(name, value);
112 public Properties getReaderProperties() {
113 return readerProperties;
116 public void addActionProperty(String name, String value) {
117 actionProperties.put(name, value);
120 public Properties getActionProperties() {
121 return actionProperties;
124 public void addActionData(String value) {
125 actionData.add(value);
128 public List<String> getActionData() {