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
     1 /**
     2  * Alt2XML
     3  * Copyright © 2014 František Kučera (frantovo.cz)
     4  *
     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.
     9  *
    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.
    14  *
    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/>.
    17  */
    18 package cz.frantovo.alt2xml.cli;
    19 
    20 import java.io.File;
    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 
    27 /**
    28  * Holds options from command line, validates them, combines with configuration and provides derived
    29  * objects.
    30  *
    31  * @author Ing. František Kučera (frantovo.cz)
    32  */
    33 public class CLIOptions {
    34 
    35 	private File inputFile;
    36 	private InputStream inputStream;
    37 	private String inputUrl;
    38 
    39 	private String systemId;
    40 	private final Properties readerProperties = new Properties();
    41 
    42 	private OutputStream outputStream;
    43 	private String action;
    44 	private final Properties actionProperties = new Properties();
    45 	private final List<String> actionData = new ArrayList<>();
    46 
    47 	public void validate() throws InvalidOptionsException {
    48 		InvalidOptionsException e = new InvalidOptionsException();
    49 
    50 		/**
    51 		 * TODO: validace
    52 		 */
    53 		if (e.hasProblems()) {
    54 			throw e;
    55 		}
    56 	}
    57 
    58 	public void setInputFile(File inputFile) {
    59 		this.inputFile = inputFile;
    60 	}
    61 
    62 	public void setInputStream(InputStream inputStream) {
    63 		this.inputStream = inputStream;
    64 	}
    65 
    66 	public void setInputUrl(String inputUrl) {
    67 		this.inputUrl = inputUrl;
    68 	}
    69 
    70 	public void setSystemId(String systemId) {
    71 		this.systemId = systemId;
    72 	}
    73  
    74 	public void setOutputStream(OutputStream outputStream) {
    75 		this.outputStream = outputStream;
    76 	}
    77 	
    78 	public void setAction(String action) {
    79 		this.action = action;
    80 	}
    81 
    82 	public void addReaderProperty(String name, String value) {
    83 		readerProperties.put(name, value);
    84 	}
    85 
    86 	public void addActionProperty(String name, String value) {
    87 		actionProperties.put(name, value);
    88 	}
    89 
    90 	public void addActionData(String value) {
    91 		actionData.add(value);
    92 	}
    93 
    94 }