java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
branchv_0
changeset 17 d8ab8aece6f2
parent 16 5b8fcd35d4d6
child 18 7900bb1666f6
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Mon Dec 16 20:01:37 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Mon Dec 16 20:20:54 2013 +0100
     1.3 @@ -17,8 +17,12 @@
     1.4   */
     1.5  package info.globalcode.sql.dk;
     1.6  
     1.7 +import java.io.BufferedReader;
     1.8 +import java.io.InputStreamReader;
     1.9  import java.io.PrintStream;
    1.10  import java.util.EnumSet;
    1.11 +import java.util.logging.Level;
    1.12 +import java.util.logging.Logger;
    1.13  
    1.14  /**
    1.15   * Displays info like help, version etc.
    1.16 @@ -27,7 +31,14 @@
    1.17   */
    1.18  public class InfoLister {
    1.19  
    1.20 -	public void showInfo(CLIOptions options, PrintStream out) {
    1.21 +	private static final Logger log = Logger.getLogger(InfoLister.class.getName());
    1.22 +	private PrintStream out;
    1.23 +
    1.24 +	public InfoLister(PrintStream out) {
    1.25 +		this.out = out;
    1.26 +	}
    1.27 +
    1.28 +	public void showInfo(CLIOptions options) {
    1.29  		EnumSet<CLIOptions.INFO_TYPE> infoTypes = options.getShowInfo();
    1.30  		for (CLIOptions.INFO_TYPE infoType : infoTypes) {
    1.31  			switch (infoType) {
    1.32 @@ -35,29 +46,48 @@
    1.33  				 * TODO: implement show info
    1.34  				 */
    1.35  				case FORMATTERS:
    1.36 -					out.println("TODO: list available formatters");
    1.37 +					println("TODO: list available formatters");
    1.38  					break;
    1.39  				case HELP:
    1.40 -					out.println("TODO: show some help");
    1.41 +					println("TODO: show some help");
    1.42  					break;
    1.43  				case LICENSE:
    1.44 -					out.println("TODO: show license");
    1.45 +					printLicense();
    1.46  					break;
    1.47  				case TYPES:
    1.48 -					out.println("TODO: list supported types");
    1.49 +					println("TODO: list supported types");
    1.50  					break;
    1.51  				case VERSION:
    1.52 -					out.println("TODO: show version");
    1.53 +					println("TODO: show version");
    1.54  					break;
    1.55  				case DATABASES:
    1.56 -					out.println("TODO: list databases");
    1.57 +					println("TODO: list databases");
    1.58  					break;
    1.59  				case CONNECTION:
    1.60 -					out.println("TODO: test database connection: " + options.getDatabaseNameToTest());
    1.61 +					println("TODO: test database connection: " + options.getDatabaseNameToTest());
    1.62  					break;
    1.63  				default:
    1.64  					throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType);
    1.65  			}
    1.66  		}
    1.67  	}
    1.68 +
    1.69 +	private void printLicense() {
    1.70 +		try (BufferedReader license = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("info/globalcode/sql/dk/license.txt")))) {
    1.71 +			while (true) {
    1.72 +				String line = license.readLine();
    1.73 +				if (line == null) {
    1.74 +					break;
    1.75 +				} else {
    1.76 +					println(line);
    1.77 +				}
    1.78 +			}
    1.79 +		} catch (Exception e) {
    1.80 +			log.log(Level.SEVERE, "Unable to print license. See our website for license information.", e);
    1.81 +		}
    1.82 +	}
    1.83 +
    1.84 +	private void println(String line) {
    1.85 +		out.println(line);
    1.86 +	}
    1.87  }