CLI → CLIStarter
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 17 Jun 2014 18:19:01 +0200
changeset 536bcb20e856fe
parent 52 e539cae27747
child 54 3d5cc308e268
CLI → CLIStarter
java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java
java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIStarter.java
     1.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java	Mon Jun 16 22:35:44 2014 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,78 +0,0 @@
     1.4 -/**
     1.5 - * Alt2XML
     1.6 - * Copyright © 2014 František Kučera (frantovo.cz)
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, either version 3 of the License, or
    1.11 - * (at your option) any later version.
    1.12 - *
    1.13 - * This program is distributed in the hope that it will be useful,
    1.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.16 - * GNU General Public License for more details.
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License
    1.19 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.20 - */
    1.21 -package cz.frantovo.alt2xml.cli;
    1.22 -
    1.23 -import cz.frantovo.alt2xml.out.Action;
    1.24 -import cz.frantovo.alt2xml.out.ActionContext;
    1.25 -import cz.frantovo.alt2xml.out.ActionFactory;
    1.26 -import java.io.File;
    1.27 -import java.io.OutputStream;
    1.28 -import java.util.Arrays;
    1.29 -import java.util.HashMap;
    1.30 -import java.util.Map;
    1.31 -import java.util.ServiceLoader;
    1.32 -import java.util.logging.Level;
    1.33 -import java.util.logging.Logger;
    1.34 -import javax.xml.parsers.SAXParser;
    1.35 -import javax.xml.parsers.SAXParserFactory;
    1.36 -import org.xml.sax.InputSource;
    1.37 -
    1.38 -/**
    1.39 - *
    1.40 - * @author Ing. František Kučera (frantovo.cz)
    1.41 - */
    1.42 -public class CLI {
    1.43 -
    1.44 -	private static final Logger log = Logger.getLogger(CLI.class.getName());
    1.45 -
    1.46 -	public static void main(String[] args) {
    1.47 -
    1.48 -		try {
    1.49 -			File inputFile = new File(args[0]);
    1.50 -			String actionCode = args[1];
    1.51 -			OutputStream outputStream = System.out;
    1.52 -
    1.53 -			Map<String, ActionFactory> actionFactories = new HashMap<>();
    1.54 -
    1.55 -			for (ActionFactory f : ServiceLoader.load(ActionFactory.class)) {
    1.56 -				String code = f.getActionCode();
    1.57 -				actionFactories.put(code, f);
    1.58 -				log.log(Level.CONFIG, "Discovered output module: {0} = {1}", new Object[]{code, f.getClass().getName()});
    1.59 -			}
    1.60 -
    1.61 -			ActionFactory actionFactory = actionFactories.get(actionCode);
    1.62 -
    1.63 -			if (actionFactory == null) {
    1.64 -				log.log(Level.SEVERE, "No such output action with code: {0}", actionCode);
    1.65 -			} else {
    1.66 -
    1.67 -				ActionContext actionContext = new ActionContext(outputStream);
    1.68 -				Action action = actionFactory.getAction(actionContext);
    1.69 -
    1.70 -				SAXParserFactory t = SAXParserFactory.newInstance();
    1.71 -				SAXParser p = t.newSAXParser();
    1.72 -
    1.73 -				action.run(p, new InputSource(inputFile.toURI().toASCIIString()));
    1.74 -			}
    1.75 -
    1.76 -		} catch (Exception e) {
    1.77 -			log.log(Level.SEVERE, "Error during processing: " + Arrays.toString(args), e);
    1.78 -		}
    1.79 -
    1.80 -	}
    1.81 -}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIStarter.java	Tue Jun 17 18:19:01 2014 +0200
     2.3 @@ -0,0 +1,78 @@
     2.4 +/**
     2.5 + * Alt2XML
     2.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21 +package cz.frantovo.alt2xml.cli;
    2.22 +
    2.23 +import cz.frantovo.alt2xml.out.Action;
    2.24 +import cz.frantovo.alt2xml.out.ActionContext;
    2.25 +import cz.frantovo.alt2xml.out.ActionFactory;
    2.26 +import java.io.File;
    2.27 +import java.io.OutputStream;
    2.28 +import java.util.Arrays;
    2.29 +import java.util.HashMap;
    2.30 +import java.util.Map;
    2.31 +import java.util.ServiceLoader;
    2.32 +import java.util.logging.Level;
    2.33 +import java.util.logging.Logger;
    2.34 +import javax.xml.parsers.SAXParser;
    2.35 +import javax.xml.parsers.SAXParserFactory;
    2.36 +import org.xml.sax.InputSource;
    2.37 +
    2.38 +/**
    2.39 + *
    2.40 + * @author Ing. František Kučera (frantovo.cz)
    2.41 + */
    2.42 +public class CLIStarter {
    2.43 +
    2.44 +	private static final Logger log = Logger.getLogger(CLIStarter.class.getName());
    2.45 +
    2.46 +	public static void main(String[] args) {
    2.47 +
    2.48 +		try {
    2.49 +			File inputFile = new File(args[0]);
    2.50 +			String actionCode = args[1];
    2.51 +			OutputStream outputStream = System.out;
    2.52 +
    2.53 +			Map<String, ActionFactory> actionFactories = new HashMap<>();
    2.54 +
    2.55 +			for (ActionFactory f : ServiceLoader.load(ActionFactory.class)) {
    2.56 +				String code = f.getActionCode();
    2.57 +				actionFactories.put(code, f);
    2.58 +				log.log(Level.CONFIG, "Discovered output module: {0} = {1}", new Object[]{code, f.getClass().getName()});
    2.59 +			}
    2.60 +
    2.61 +			ActionFactory actionFactory = actionFactories.get(actionCode);
    2.62 +
    2.63 +			if (actionFactory == null) {
    2.64 +				log.log(Level.SEVERE, "No such output action with code: {0}", actionCode);
    2.65 +			} else {
    2.66 +
    2.67 +				ActionContext actionContext = new ActionContext(outputStream);
    2.68 +				Action action = actionFactory.getAction(actionContext);
    2.69 +
    2.70 +				SAXParserFactory t = SAXParserFactory.newInstance();
    2.71 +				SAXParser p = t.newSAXParser();
    2.72 +
    2.73 +				action.run(p, new InputSource(inputFile.toURI().toASCIIString()));
    2.74 +			}
    2.75 +
    2.76 +		} catch (Exception e) {
    2.77 +			log.log(Level.SEVERE, "Error during processing: " + Arrays.toString(args), e);
    2.78 +		}
    2.79 +
    2.80 +	}
    2.81 +}