# HG changeset patch
# User František Kučera <franta-hg@frantovo.cz>
# Date 1410032475 -7200
# Node ID c96459e0269017bc0749a35bcad96eb4eca564f4
# Parent  46c7cc4863c163ffd817c7f16eac2193dc4e6039
CLI: supprt combination of --input-file and --system-id (to choose proper input module for given SystemId but actually read stream from the file)

diff -r 46c7cc4863c1 -r c96459e02690 java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIOptions.java
--- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIOptions.java	Sat Sep 06 21:24:53 2014 +0200
+++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLIOptions.java	Sat Sep 06 21:41:15 2014 +0200
@@ -18,11 +18,16 @@
 package cz.frantovo.alt2xml.cli;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
 import org.xml.sax.InputSource;
 
 /**
@@ -33,6 +38,8 @@
  */
 public class CLIOptions {
 
+	private static final Logger log = Logger.getLogger(CLIOptions.class.getName());
+
 	private File inputFile;
 	private InputStream inputStream;
 
@@ -74,18 +81,29 @@
 	public InputSource getInputSource() {
 		InputSource is = new InputSource();
 
+		if (systemId != null) {
+			is.setSystemId(systemId);
+		}
+
 		if (inputFile != null) {
-			is.setSystemId(inputFile.toURI().toASCIIString());
+			if (systemId == null) {
+				is.setSystemId(inputFile.toURI().toASCIIString());
+			} else {
+				try {
+					is.setByteStream(new FileInputStream(inputFile));
+				} catch (FileNotFoundException e) {
+					LogRecord message = new LogRecord(Level.WARNING, "Unable to open file „{0}“ → fallback to SystemId „{1}“");
+					message.setParameters(new Object[]{inputFile, systemId});
+					message.setThrown(e);
+					log.log(message);
+				}
+			}
 		}
 
 		if (inputStream != null) {
 			is.setByteStream(inputStream);
 		}
 
-		if (systemId != null) {
-			is.setSystemId(systemId);
-		}
-
 		return is;
 	}