View Javadoc
1 /*** 2 Copyright (C) 2002-2003 Together 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 18 */ 19 20 package org.webdocwf.util.i18njdbc; 21 22 import java.sql.*; 23 import java.util.Properties; 24 import java.util.StringTokenizer; 25 import java.io.File; 26 27 /*** 28 * This class implements the Driver interface for the I18nJdbc driver. 29 * 30 * @author Zoran Milakovic 31 * @author Zeljko Kovacevic 32 */ 33 34 public class I18nDriver implements Driver 35 { 36 37 //PARAMETER NAMES 38 39 40 //ZK added properties for i18nJdbc driver 41 public static final String CHARSET = "charset"; 42 public static final String NAMECOLUMN = "nameColumn"; 43 public static final String VALUECOLUMN = "valueColumn"; 44 public static final String CREATE="create"; 45 public static final String FILE_EXTENSION = "fileExtension"; 46 //DEFAULT VALUES 47 48 //ZK added this 49 public static final String DEFAULT_CHARSET = "UTF-8"; 50 public static final String DEFAULT_NAMECOLUMN = "name"; 51 public static final String DEFAULT_VALUECOLUMN = "value"; 52 public static final boolean DEFAULT_CREATE = false; 53 public static final String DEFAULT_EXTENSION = ".properties"; 54 //data types 55 56 public static final String VARCHAR_TYPE = "VARCHAR"; 57 public static String FILE_NAME_EXT = "extension"; 58 private final static String URL_PREFIX = "jdbc:webdocwf:i18n:"; 59 private Properties info = null; 60 61 /* If set to true, driver will log into i18ndriver.log file, in working directory */ 62 private static boolean ENABLE_LOG = false; 63 64 /* If set to true, driver will show stack traces and other debug info */ 65 public static boolean DEBUG = false; 66 67 /*** 68 *Gets the propertyInfo attribute of the I18nJdbc object 69 * 70 * @param url Description of Parameter 71 * @param info Description of Parameter 72 * @return The propertyInfo value 73 * @exception SQLException Description of Exception 74 * @since 75 */ 76 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) 77 throws SQLException 78 { 79 return new DriverPropertyInfo[0]; 80 } 81 82 83 /*** 84 *Gets the majorVersion attribute of the I18nJdbc object 85 * 86 * @return The majorVersion value 87 * @since 88 */ 89 public int getMajorVersion() 90 { 91 return 1; 92 } 93 94 95 /*** 96 *Gets the minorVersion attribute of the I18nJdbc object 97 * 98 * @return The minorVersion value 99 * @since 100 */ 101 public int getMinorVersion() 102 { 103 return 0; 104 } 105 106 107 /*** 108 *Description of the Method 109 * 110 * @param url Description of Parameter 111 * @param info Description of Parameter 112 * @return Description of the Returned Value 113 * @exception SQLException Description of Exception 114 * @since 115 */ 116 public Connection connect(String url, Properties info) throws SQLException 117 { 118 DriverManager.println("i18nJdbc - I18nDriver:connect() - url=" + url); 119 // check for correct url 120 if (!url.startsWith(URL_PREFIX)) 121 { 122 return null; 123 } 124 // get filepath from url 125 String filePath = url.substring(URL_PREFIX.length()); 126 String filePathAll = filePath; 127 StringTokenizer st = new StringTokenizer( filePath , ";" ); 128 129 //System.out.println("filePathAll="+filePathAll); 130 131 filePath = st.nextToken(); 132 if (!filePath.endsWith(File.separator)) 133 { 134 filePath += File.separator; 135 } 136 DriverManager.println("i18nJdbc - i18nDriver:connect() - filePath=" + filePath); 137 return new I18nConnection(filePathAll, info); 138 } 139 140 141 /*** 142 * Description of the Method 143 * 144 * @param url Description of Parameter 145 * @return Description of the Returned Value 146 * @exception SQLException Description of Exception 147 * @since 148 */ 149 public boolean acceptsURL(String url) throws SQLException 150 { 151 DriverManager.println("I18nJdbc - I18nDriver:accept() - url=" + url); 152 return url.startsWith(URL_PREFIX); 153 } 154 155 156 /*** 157 *Description of the Method 158 * 159 * @return Description of the Returned Value 160 * @since 161 */ 162 public boolean jdbcCompliant() 163 { 164 return false; 165 } 166 // This static block inits the driver when the class is loaded by the JVM. 167 static 168 { 169 try 170 { 171 java.sql.DriverManager.registerDriver(new I18nDriver()); 172 } 173 catch (SQLException e) 174 { 175 throw new RuntimeException( 176 "FATAL ERROR: Could not initialise i18n driver ! Message was: " 177 + e.getMessage()); 178 } 179 } 180 181 public static void log( String message) { 182 if ( I18nDriver.ENABLE_LOG ) { 183 try { 184 File file = new File("i18ndriver.log"); 185 if (!file.exists()) 186 file.createNewFile(); 187 java.io.RandomAccessFile fileLogr = new java.io.RandomAccessFile(file, 188 "rw"); 189 fileLogr.seek(fileLogr.length()); 190 fileLogr.writeBytes("I18nJdbc, "+message + "\r\n"); 191 fileLogr.close(); 192 } 193 catch (Exception ex) { 194 ex.printStackTrace(); 195 } 196 } 197 } 198 199 } 200

This page was automatically generated by Maven