TabularFormatter: basics v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 22 Dec 2013 21:02:37 +0100
branchv_0
changeset 32 5e412dbd9362
parent 31 ef2fdb55e8ec
child 33 04db6ccd6c48
TabularFormatter: basics
java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
--- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java	Sun Dec 22 20:51:32 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java	Sun Dec 22 21:02:37 2013 +0100
@@ -20,6 +20,7 @@
 import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
 import static info.globalcode.sql.dk.Functions.findByName;
 import info.globalcode.sql.dk.formatting.SilentFormatter;
+import info.globalcode.sql.dk.formatting.TabularFormatter;
 import info.globalcode.sql.dk.formatting.XmlFormatter;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -37,6 +38,10 @@
 
 	private List<DatabaseDefinition> databases = new ArrayList<>();
 	private List<FormatterDefinition> formatters = new ArrayList<>();
+	/**
+	 * is used if no formatter is specified on CLI nor in user configuration
+	 */
+	public static final String DEFAULT_FORMATTER = TabularFormatter.NAME;
 	private String defaultFormatter;
 	/**
 	 * Default list of formatters. Is used if particular name is not found in user configuration.
@@ -47,6 +52,7 @@
 		Collection<FormatterDefinition> l = new ArrayList<>();
 		l.add(new FormatterDefinition(SilentFormatter.NAME, SilentFormatter.class.getName()));
 		l.add(new FormatterDefinition(XmlFormatter.NAME, XmlFormatter.class.getName()));
+		l.add(new FormatterDefinition(TabularFormatter.NAME, TabularFormatter.class.getName()));
 		buildInFormatters = Collections.unmodifiableCollection(l);
 	}
 
@@ -72,9 +78,23 @@
 		this.formatters = formatters;
 	}
 
+	/**
+	 * @param name name of desired formatter. Looking for this name in user configuration, then in
+	 * buil-in formatters. If null, default from configuration or (if not configured) built-in
+	 * default is used.
+	 * @return formatter definition or null if none for this name is found
+	 */
 	public FormatterDefinition getFormatter(String name) {
-		FormatterDefinition fd = findByName(formatters, name);
-		return fd == null ? findByName(buildInFormatters, name) : fd;
+		if (name == null) {
+			if (defaultFormatter == null) {
+				return getFormatter(DEFAULT_FORMATTER);
+			} else {
+				return getFormatter(defaultFormatter);
+			}
+		} else {
+			FormatterDefinition fd = findByName(formatters, name);
+			return fd == null ? findByName(buildInFormatters, name) : fd;
+		}
 	}
 
 	/**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Sun Dec 22 21:02:37 2013 +0100
@@ -0,0 +1,31 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk.formatting;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class TabularFormatter extends AbstractFormatter {
+
+	public static final String NAME = "tabular";
+
+	public TabularFormatter(FormatterContext formatterContext) {
+		super(formatterContext);
+	}
+}