📄 i18ndriver.java
字号:
/**
Copyright (C) 2002-2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.webdocwf.util.i18njdbc;
import java.sql.*;
import java.util.Properties;
import java.util.StringTokenizer;
import java.io.File;
/**
* This class implements the Driver interface for the I18nJdbc driver.
*
* @author Zoran Milakovic
* @author Zeljko Kovacevic
*/
public class I18nDriver implements Driver
{
//PARAMETER NAMES
//ZK added properties for i18nJdbc driver
public static final String CHARSET = "charset";
public static final String NAMECOLUMN = "nameColumn";
public static final String VALUECOLUMN = "valueColumn";
public static final String CREATE="create";
public static final String FILE_EXTENSION = "fileExtension";
//DEFAULT VALUES
//ZK added this
public static final String DEFAULT_CHARSET = "UTF-8";
public static final String DEFAULT_NAMECOLUMN = "name";
public static final String DEFAULT_VALUECOLUMN = "value";
public static final boolean DEFAULT_CREATE = false;
public static final String DEFAULT_EXTENSION = ".properties";
//data types
public static final String VARCHAR_TYPE = "VARCHAR";
public static String FILE_NAME_EXT = "extension";
private final static String URL_PREFIX = "jdbc:webdocwf:i18n:";
private Properties info = null;
/* If set to true, driver will log into i18ndriver.log file, in working directory */
private static boolean ENABLE_LOG = false;
/* If set to true, driver will show stack traces and other debug info */
public static boolean DEBUG = false;
/**
*Gets the propertyInfo attribute of the I18nJdbc object
*
* @param url Description of Parameter
* @param info Description of Parameter
* @return The propertyInfo value
* @exception SQLException Description of Exception
* @since
*/
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
throws SQLException
{
return new DriverPropertyInfo[0];
}
/**
*Gets the majorVersion attribute of the I18nJdbc object
*
* @return The majorVersion value
* @since
*/
public int getMajorVersion()
{
return 1;
}
/**
*Gets the minorVersion attribute of the I18nJdbc object
*
* @return The minorVersion value
* @since
*/
public int getMinorVersion()
{
return 0;
}
/**
*Description of the Method
*
* @param url Description of Parameter
* @param info Description of Parameter
* @return Description of the Returned Value
* @exception SQLException Description of Exception
* @since
*/
public Connection connect(String url, Properties info) throws SQLException
{
DriverManager.println("i18nJdbc - I18nDriver:connect() - url=" + url);
// check for correct url
if (!url.startsWith(URL_PREFIX))
{
return null;
}
// get filepath from url
String filePath = url.substring(URL_PREFIX.length());
String filePathAll = filePath;
StringTokenizer st = new StringTokenizer( filePath , ";" );
//System.out.println("filePathAll="+filePathAll);
filePath = st.nextToken();
if (!filePath.endsWith(File.separator))
{
filePath += File.separator;
}
DriverManager.println("i18nJdbc - i18nDriver:connect() - filePath=" + filePath);
return new I18nConnection(filePathAll, info);
}
/**
* Description of the Method
*
* @param url Description of Parameter
* @return Description of the Returned Value
* @exception SQLException Description of Exception
* @since
*/
public boolean acceptsURL(String url) throws SQLException
{
DriverManager.println("I18nJdbc - I18nDriver:accept() - url=" + url);
return url.startsWith(URL_PREFIX);
}
/**
*Description of the Method
*
* @return Description of the Returned Value
* @since
*/
public boolean jdbcCompliant()
{
return false;
}
// This static block inits the driver when the class is loaded by the JVM.
static
{
try
{
java.sql.DriverManager.registerDriver(new I18nDriver());
}
catch (SQLException e)
{
throw new RuntimeException(
"FATAL ERROR: Could not initialise i18n driver ! Message was: "
+ e.getMessage());
}
}
public static void log( String message) {
if ( I18nDriver.ENABLE_LOG ) {
try {
File file = new File("i18ndriver.log");
if (!file.exists())
file.createNewFile();
java.io.RandomAccessFile fileLogr = new java.io.RandomAccessFile(file,
"rw");
fileLogr.seek(fileLogr.length());
fileLogr.writeBytes("I18nJdbc, "+message + "\r\n");
fileLogr.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -