1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java Sun Dec 22 20:51:32 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Configuration.java Sun Dec 22 21:02:37 2013 +0100
1.3 @@ -20,6 +20,7 @@
1.4 import static info.globalcode.sql.dk.Xmlns.CONFIGURATION;
1.5 import static info.globalcode.sql.dk.Functions.findByName;
1.6 import info.globalcode.sql.dk.formatting.SilentFormatter;
1.7 +import info.globalcode.sql.dk.formatting.TabularFormatter;
1.8 import info.globalcode.sql.dk.formatting.XmlFormatter;
1.9 import java.util.ArrayList;
1.10 import java.util.Collection;
1.11 @@ -37,6 +38,10 @@
1.12
1.13 private List<DatabaseDefinition> databases = new ArrayList<>();
1.14 private List<FormatterDefinition> formatters = new ArrayList<>();
1.15 + /**
1.16 + * is used if no formatter is specified on CLI nor in user configuration
1.17 + */
1.18 + public static final String DEFAULT_FORMATTER = TabularFormatter.NAME;
1.19 private String defaultFormatter;
1.20 /**
1.21 * Default list of formatters. Is used if particular name is not found in user configuration.
1.22 @@ -47,6 +52,7 @@
1.23 Collection<FormatterDefinition> l = new ArrayList<>();
1.24 l.add(new FormatterDefinition(SilentFormatter.NAME, SilentFormatter.class.getName()));
1.25 l.add(new FormatterDefinition(XmlFormatter.NAME, XmlFormatter.class.getName()));
1.26 + l.add(new FormatterDefinition(TabularFormatter.NAME, TabularFormatter.class.getName()));
1.27 buildInFormatters = Collections.unmodifiableCollection(l);
1.28 }
1.29
1.30 @@ -72,9 +78,23 @@
1.31 this.formatters = formatters;
1.32 }
1.33
1.34 + /**
1.35 + * @param name name of desired formatter. Looking for this name in user configuration, then in
1.36 + * buil-in formatters. If null, default from configuration or (if not configured) built-in
1.37 + * default is used.
1.38 + * @return formatter definition or null if none for this name is found
1.39 + */
1.40 public FormatterDefinition getFormatter(String name) {
1.41 - FormatterDefinition fd = findByName(formatters, name);
1.42 - return fd == null ? findByName(buildInFormatters, name) : fd;
1.43 + if (name == null) {
1.44 + if (defaultFormatter == null) {
1.45 + return getFormatter(DEFAULT_FORMATTER);
1.46 + } else {
1.47 + return getFormatter(defaultFormatter);
1.48 + }
1.49 + } else {
1.50 + FormatterDefinition fd = findByName(formatters, name);
1.51 + return fd == null ? findByName(buildInFormatters, name) : fd;
1.52 + }
1.53 }
1.54
1.55 /**
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java Sun Dec 22 21:02:37 2013 +0100
2.3 @@ -0,0 +1,31 @@
2.4 +/**
2.5 + * SQL-DK
2.6 + * Copyright © 2013 František Kučera (frantovo.cz)
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, either version 3 of the License, or
2.11 + * (at your option) any later version.
2.12 + *
2.13 + * This program is distributed in the hope that it will be useful,
2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.16 + * GNU General Public License for more details.
2.17 + *
2.18 + * You should have received a copy of the GNU General Public License
2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2.20 + */
2.21 +package info.globalcode.sql.dk.formatting;
2.22 +
2.23 +/**
2.24 + *
2.25 + * @author Ing. František Kučera (frantovo.cz)
2.26 + */
2.27 +public class TabularFormatter extends AbstractFormatter {
2.28 +
2.29 + public static final String NAME = "tabular";
2.30 +
2.31 + public TabularFormatter(FormatterContext formatterContext) {
2.32 + super(formatterContext);
2.33 + }
2.34 +}