1 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 33 34 public class I18nDriver implements Driver 35 { 36 37 39 40 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 48 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 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 62 private static boolean ENABLE_LOG = false; 63 64 65 public static boolean DEBUG = false; 66 67 76 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) 77 throws SQLException 78 { 79 return new DriverPropertyInfo[0]; 80 } 81 82 83 89 public int getMajorVersion() 90 { 91 return 1; 92 } 93 94 95 101 public int getMinorVersion() 102 { 103 return 0; 104 } 105 106 107 116 public Connection connect(String url, Properties info) throws SQLException 117 { 118 DriverManager.println("i18nJdbc - I18nDriver:connect() - url=" + url); 119 if (!url.startsWith(URL_PREFIX)) 121 { 122 return null; 123 } 124 String filePath = url.substring(URL_PREFIX.length()); 126 String filePathAll = filePath; 127 StringTokenizer st = new StringTokenizer ( filePath , ";" ); 128 129 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 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 162 public boolean jdbcCompliant() 163 { 164 return false; 165 } 166 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 201 | Popular Tags |