validation: test if prefix/suffix are valid regular expressions v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 26 Dec 2013 00:58:00 +0100
branchv_0
changeset 633b9ec9c23a37
parent 62 7a88ac6ba40c
child 64 fcc499518dc7
validation: test if prefix/suffix are valid regular expressions
java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java
java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
java/sql-dk/src/info/globalcode/sql/dk/InvalidOptionsException.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Thu Dec 26 00:18:03 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Thu Dec 26 00:58:00 2013 +0100
     1.3 @@ -25,6 +25,8 @@
     1.4  import java.util.Collection;
     1.5  import java.util.EnumSet;
     1.6  import java.util.List;
     1.7 +import java.util.regex.Pattern;
     1.8 +import java.util.regex.PatternSyntaxException;
     1.9  
    1.10  /**
    1.11   *
    1.12 @@ -104,6 +106,11 @@
    1.13  			e.addProblem(new InvalidOptionsException.OptionProblem("Named and numbered parameters can not be used together in one command."));
    1.14  		}
    1.15  
    1.16 +		try {
    1.17 +			Pattern.compile(namePrefix + "test" + nameSuffix);
    1.18 +		} catch (PatternSyntaxException regexException) {
    1.19 +			e.addProblem(new InvalidOptionsException.OptionProblem("Ivalid regular expression in name prefix or suffix", regexException));
    1.20 +		}
    1.21  
    1.22  		if (e.hasProblems()) {
    1.23  			throw e;
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Thu Dec 26 00:18:03 2013 +0100
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Thu Dec 26 00:58:00 2013 +0100
     2.3 @@ -29,6 +29,7 @@
     2.4  import java.io.IOException;
     2.5  import java.sql.SQLException;
     2.6  import java.util.logging.Level;
     2.7 +import java.util.logging.LogRecord;
     2.8  import java.util.logging.Logger;
     2.9  import javax.xml.bind.JAXBContext;
    2.10  import javax.xml.bind.Unmarshaller;
    2.11 @@ -49,7 +50,7 @@
    2.12  	public static void main(String[] args) {
    2.13  		log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME);
    2.14  		int exitCode = EXIT_EXPECTED_ERROR;
    2.15 -		
    2.16 +
    2.17  		if (args.length == 0) {
    2.18  			args = new String[]{CLIParser.Tokens.INFO_HELP};
    2.19  		}
    2.20 @@ -68,7 +69,10 @@
    2.21  		} catch (InvalidOptionsException e) {
    2.22  			log.log(Level.SEVERE, "Invalid CLI options", e);
    2.23  			for (InvalidOptionsException.OptionProblem p : e.getProblems()) {
    2.24 -				log.log(Level.SEVERE, "Option problem: {0}", p.getDescription());
    2.25 +				LogRecord r = new LogRecord(Level.SEVERE, "Option problem: {0}");
    2.26 +				r.setThrown(p.getException());
    2.27 +				r.setParameters(new Object[]{p.getDescription()});
    2.28 +				log.log(r);
    2.29  			}
    2.30  		} catch (ConfigurationException e) {
    2.31  			log.log(Level.SEVERE, "Configuration problem", e);
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InvalidOptionsException.java	Thu Dec 26 00:18:03 2013 +0100
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InvalidOptionsException.java	Thu Dec 26 00:58:00 2013 +0100
     3.3 @@ -44,13 +44,23 @@
     3.4  	public static class OptionProblem {
     3.5  
     3.6  		private String description;
     3.7 +		private Throwable exception;
     3.8  
     3.9  		public OptionProblem(String description) {
    3.10  			this.description = description;
    3.11  		}
    3.12  
    3.13 +		public OptionProblem(String description, Throwable exception) {
    3.14 +			this.description = description;
    3.15 +			this.exception = exception;
    3.16 +		}
    3.17 +
    3.18  		public String getDescription() {
    3.19  			return description;
    3.20  		}
    3.21 +
    3.22 +		public Throwable getException() {
    3.23 +			return exception;
    3.24 +		}
    3.25  	}
    3.26  }