java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
branchv_0
changeset 17 d8ab8aece6f2
parent 16 5b8fcd35d4d6
child 18 7900bb1666f6
equal deleted inserted replaced
16:5b8fcd35d4d6 17:d8ab8aece6f2
    15  * You should have received a copy of the GNU General Public License
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    17  */
    17  */
    18 package info.globalcode.sql.dk;
    18 package info.globalcode.sql.dk;
    19 
    19 
       
    20 import java.io.BufferedReader;
       
    21 import java.io.InputStreamReader;
    20 import java.io.PrintStream;
    22 import java.io.PrintStream;
    21 import java.util.EnumSet;
    23 import java.util.EnumSet;
       
    24 import java.util.logging.Level;
       
    25 import java.util.logging.Logger;
    22 
    26 
    23 /**
    27 /**
    24  * Displays info like help, version etc.
    28  * Displays info like help, version etc.
    25  *
    29  *
    26  * @author Ing. František Kučera (frantovo.cz)
    30  * @author Ing. František Kučera (frantovo.cz)
    27  */
    31  */
    28 public class InfoLister {
    32 public class InfoLister {
    29 
    33 
    30 	public void showInfo(CLIOptions options, PrintStream out) {
    34 	private static final Logger log = Logger.getLogger(InfoLister.class.getName());
       
    35 	private PrintStream out;
       
    36 
       
    37 	public InfoLister(PrintStream out) {
       
    38 		this.out = out;
       
    39 	}
       
    40 
       
    41 	public void showInfo(CLIOptions options) {
    31 		EnumSet<CLIOptions.INFO_TYPE> infoTypes = options.getShowInfo();
    42 		EnumSet<CLIOptions.INFO_TYPE> infoTypes = options.getShowInfo();
    32 		for (CLIOptions.INFO_TYPE infoType : infoTypes) {
    43 		for (CLIOptions.INFO_TYPE infoType : infoTypes) {
    33 			switch (infoType) {
    44 			switch (infoType) {
    34 				/**
    45 				/**
    35 				 * TODO: implement show info
    46 				 * TODO: implement show info
    36 				 */
    47 				 */
    37 				case FORMATTERS:
    48 				case FORMATTERS:
    38 					out.println("TODO: list available formatters");
    49 					println("TODO: list available formatters");
    39 					break;
    50 					break;
    40 				case HELP:
    51 				case HELP:
    41 					out.println("TODO: show some help");
    52 					println("TODO: show some help");
    42 					break;
    53 					break;
    43 				case LICENSE:
    54 				case LICENSE:
    44 					out.println("TODO: show license");
    55 					printLicense();
    45 					break;
    56 					break;
    46 				case TYPES:
    57 				case TYPES:
    47 					out.println("TODO: list supported types");
    58 					println("TODO: list supported types");
    48 					break;
    59 					break;
    49 				case VERSION:
    60 				case VERSION:
    50 					out.println("TODO: show version");
    61 					println("TODO: show version");
    51 					break;
    62 					break;
    52 				case DATABASES:
    63 				case DATABASES:
    53 					out.println("TODO: list databases");
    64 					println("TODO: list databases");
    54 					break;
    65 					break;
    55 				case CONNECTION:
    66 				case CONNECTION:
    56 					out.println("TODO: test database connection: " + options.getDatabaseNameToTest());
    67 					println("TODO: test database connection: " + options.getDatabaseNameToTest());
    57 					break;
    68 					break;
    58 				default:
    69 				default:
    59 					throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType);
    70 					throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType);
    60 			}
    71 			}
    61 		}
    72 		}
    62 	}
    73 	}
       
    74 
       
    75 	private void printLicense() {
       
    76 		try (BufferedReader license = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("info/globalcode/sql/dk/license.txt")))) {
       
    77 			while (true) {
       
    78 				String line = license.readLine();
       
    79 				if (line == null) {
       
    80 					break;
       
    81 				} else {
       
    82 					println(line);
       
    83 				}
       
    84 			}
       
    85 		} catch (Exception e) {
       
    86 			log.log(Level.SEVERE, "Unable to print license. See our website for license information.", e);
       
    87 		}
       
    88 	}
       
    89 
       
    90 	private void println(String line) {
       
    91 		out.println(line);
       
    92 	}
    63 }
    93 }