java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIStarter.java
changeset 99 fadfde5b3e55
parent 64 e2c691eedf4d
child 111 e4900596abdb
     1.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIStarter.java	Wed Sep 17 19:13:47 2014 +0200
     1.2 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIStarter.java	Wed Sep 17 21:00:32 2014 +0200
     1.3 @@ -23,6 +23,8 @@
     1.4  import cz.frantovo.alt2xml.out.OutputActionException;
     1.5  import java.util.HashMap;
     1.6  import java.util.Map;
     1.7 +import java.util.Map.Entry;
     1.8 +import java.util.Properties;
     1.9  import java.util.ServiceLoader;
    1.10  import java.util.logging.Level;
    1.11  import java.util.logging.LogRecord;
    1.12 @@ -31,6 +33,8 @@
    1.13  import javax.xml.parsers.SAXParser;
    1.14  import javax.xml.parsers.SAXParserFactory;
    1.15  import org.xml.sax.SAXException;
    1.16 +import org.xml.sax.SAXNotRecognizedException;
    1.17 +import org.xml.sax.SAXNotSupportedException;
    1.18  
    1.19  /**
    1.20   *
    1.21 @@ -58,7 +62,7 @@
    1.22  		try {
    1.23  			CLIParser cliParser = new CLIParser();
    1.24  			CLIOptions cliOptions = cliParser.parseOptions(args);
    1.25 -			
    1.26 +
    1.27  			cliOptions.validate();
    1.28  
    1.29  			Map<String, ActionFactory> actionFactories = new HashMap<>();
    1.30 @@ -79,14 +83,17 @@
    1.31  			} else {
    1.32  
    1.33  				ActionContext actionContext = new ActionContext(cliOptions.getOutputStream());
    1.34 -				
    1.35 +
    1.36  				actionContext.setActionProperties(cliOptions.getActionProperties());
    1.37  				actionContext.setActionData(cliOptions.getActionData());
    1.38 -				
    1.39 +
    1.40  				Action action = actionFactory.getAction(actionContext);
    1.41  
    1.42  				SAXParserFactory t = SAXParserFactory.newInstance();
    1.43 +				parametrizeParserFactory(t, cliOptions.getReaderFeatures());
    1.44 +				
    1.45  				SAXParser p = t.newSAXParser();
    1.46 +				paramtrizeParser(p, cliOptions.getReaderProperties());
    1.47  
    1.48  				action.run(p, cliOptions.getInputSource());
    1.49  			}
    1.50 @@ -115,4 +122,16 @@
    1.51  
    1.52  		System.exit(exitCode);
    1.53  	}
    1.54 +
    1.55 +	private static void parametrizeParserFactory(SAXParserFactory factory, Map<String, Boolean> features) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
    1.56 +		for (Entry<String, Boolean> feature : features.entrySet()) {
    1.57 +			factory.setFeature(feature.getKey(), feature.getValue());
    1.58 +		}
    1.59 +	}
    1.60 +
    1.61 +	private static void paramtrizeParser(SAXParser parser, Properties readerProperties) throws SAXNotRecognizedException, SAXNotSupportedException {
    1.62 +		for (String name : readerProperties.stringPropertyNames()) {
    1.63 +			parser.setProperty(name, readerProperties.getProperty(name));
    1.64 +		}
    1.65 +	}
    1.66  }