import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import net.jaekl.cfb.db.CfbSchema;
+import net.jaekl.cfb.db.driver.DbDriver;
+import net.jaekl.cfb.db.driver.PostgresqlDriver;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
-import net.jaekl.cfb.db.CfbSchema;
-import net.jaekl.cfb.db.driver.DbDriver;
-import net.jaekl.cfb.db.driver.PostgresqlDriver;
-
public class CFB {
DbDriver m_driver;
CfbSchema m_schema;
+ CfbBundle m_bundle;
+ Locale m_locale;
// Command-line parameters
String m_dbName; // db name
String m_user; // db user
String m_pass; // db password
- CFB() {
+ CFB(Locale locale) {
m_driver = new PostgresqlDriver();
m_schema = new CfbSchema(m_driver);
+ m_locale = locale;
+ m_bundle = CfbBundle.getInst(m_locale);
m_dbName = "CFB";
m_host = "localhost";
help.printHelp(pw, 80, getClass().getName(), "", opt, 0, 0, "", true);
}
+ String trans(String key) {
+ return m_bundle.get(key);
+ }
+
void doMain(PrintWriter pw, String[] args) throws SQLException {
if ( ! parseArgs(pw, args) ) {
return;
try (Connection con = m_driver.connect(m_host, m_port, m_dbName, m_user, m_pass)) {
if (null == con) {
- // TODO: string table
- pw.println("FATAL: Cannot connect to db.");
+ String cannotConnectFormat = trans(CfbBundle.CANNOT_CONNECT);
+ String cannotConnect = MessageFormat.format(cannotConnectFormat, m_host, m_port, m_dbName, m_user);
+ pw.println(cannotConnect);
return;
}
m_schema.ensureDbInitialized(con);
}
public static void main(String[] args) {
- CFB cfb = new CFB();
+ CFB cfb = new CFB(Locale.getDefault());
try (PrintWriter pw = new PrintWriter(System.out)){
cfb.doMain(pw, args);