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();
53 if (e.hasProblems()) {
58 public void setInputFile(File inputFile) {
59 this.inputFile = inputFile;
62 public void setInputStream(InputStream inputStream) {
63 this.inputStream = inputStream;
66 public void setSystemId(String systemId) {
67 this.systemId = systemId;
70 public InputSource getInputSource() {
71 InputSource is = new InputSource();
73 if (inputFile != null) {
74 is.setSystemId(inputFile.toURI().toASCIIString());
77 if (inputStream != null) {
78 is.setByteStream(inputStream);
81 if (systemId != null) {
82 is.setSystemId(systemId);
88 public void setOutputStream(OutputStream outputStream) {
89 this.outputStream = outputStream;
92 public OutputStream getOutputStream() {
96 public void setAction(String action) {
100 public String getAction() {
104 public void addReaderProperty(String name, String value) {
105 readerProperties.put(name, value);
108 public void addActionProperty(String name, String value) {
109 actionProperties.put(name, value);
112 public void addActionData(String value) {
113 actionData.add(value);