1 31 32 package org.opencms.db; 33 34 import org.opencms.test.OpenCmsTestCase; 35 36 import java.io.File ; 37 import java.io.FileInputStream ; 38 import java.io.IOException ; 39 import java.io.InputStreamReader ; 40 import java.io.LineNumberReader ; 41 import java.nio.charset.Charset ; 42 import java.text.ParseException ; 43 import java.util.StringTokenizer ; 44 45 import junit.framework.Test; 46 import junit.framework.TestSuite; 47 48 77 public class TestQueryProperties extends OpenCmsTestCase { 78 79 85 public TestQueryProperties(String arg0) { 86 87 super(arg0); 88 } 89 90 96 public static Test suite() { 97 98 TestSuite suite = new TestSuite(); 99 suite.setName(TestQueryProperties.class.getName()); 100 101 suite.addTest(new TestQueryProperties("testQueryPropertiesGeneric")); 102 suite.addTest(new TestQueryProperties("testQueryPropertiesMaxdb")); 103 suite.addTest(new TestQueryProperties("testQueryPropertiesMssql")); 104 suite.addTest(new TestQueryProperties("testQueryPropertiesMysql")); 105 suite.addTest(new TestQueryProperties("testQueryPropertiesMysql3")); 106 suite.addTest(new TestQueryProperties("testQueryPropertiesOracle8")); 107 suite.addTest(new TestQueryProperties("testQueryPropertiesPostgresql")); 108 109 return suite; 110 } 111 112 122 public void testQueryPropertiesGeneric() throws IOException , ParseException { 123 124 File queries = new File ("src/org/opencms/db/generic/query.properties"); 126 parseQueryProperties(queries); 127 128 } 129 130 140 public void testQueryPropertiesMaxdb() throws IOException , ParseException { 141 142 File queries = new File ("src/org/opencms/db/maxdb/query.properties"); 144 parseQueryProperties(queries); 145 } 146 147 157 public void testQueryPropertiesMssql() throws IOException , ParseException { 158 159 File queries = new File ("src/org/opencms/db/mssql/query.properties"); 161 parseQueryProperties(queries); 162 163 } 164 165 175 public void testQueryPropertiesMysql() throws IOException , ParseException { 176 177 File queries = new File ("src/org/opencms/db/mysql/query.properties"); 179 parseQueryProperties(queries); 180 } 181 182 192 public void testQueryPropertiesMysql3() throws IOException , ParseException { 193 194 File queries = new File ("src/org/opencms/db/mysql3/query.properties"); 196 parseQueryProperties(queries); 197 } 198 199 209 public void testQueryPropertiesOracle8() throws IOException , ParseException { 210 211 File queries = new File ("src/org/opencms/db/oracle8/query.properties"); 213 parseQueryProperties(queries); 214 215 } 216 217 227 public void testQueryPropertiesPostgresql() throws IOException , ParseException { 228 229 File queries = new File ("src/org/opencms/db/postgresql/query.properties"); 231 parseQueryProperties(queries); 232 } 233 234 243 private void parseQueryProperties(File f) throws IOException , ParseException { 244 245 LineNumberReader reader = new LineNumberReader (new InputStreamReader ( 246 new FileInputStream (f), 247 Charset.forName("ISO-8859-1"))); 248 String read; 249 int len; 250 int count = 0; 251 int lastEscape = 0; 252 while ((read = reader.readLine()) != null) { 253 len = read.length(); 254 count++; 255 lastEscape = read.lastIndexOf('\\'); 256 257 if (read.trim().length() > 0) { 258 259 int firstSharp = read.indexOf('#'); 261 if (firstSharp > -1) { 262 String prefix = read.substring(0, firstSharp).trim(); 263 if (prefix.length() > 0) { 264 265 try { 267 parseKeyValue(prefix); 268 } catch (ParseException pe) { 269 270 throw new ParseException ("Bad format in file " 271 + f.getAbsolutePath() 272 + ", line " 273 + count 274 + ": " 275 + pe.getMessage(), count); 276 } 277 } else { 278 continue; 280 } 281 } else { 282 } 284 } 285 286 if (lastEscape != -1) { 288 289 if (lastEscape != len - 1) { 290 throw new ParseException ("Bad format in file " 291 + f.getAbsolutePath() 292 + ", line " 293 + count 294 + ": Line termination escape '\\' is followed by further characters.", count); 295 } 296 } 297 298 } 300 } 301 302 private void parseKeyValue(String keyValue) throws ParseException { 303 304 StringTokenizer tokenizer = new StringTokenizer (keyValue, "=: ", false); 305 if (tokenizer.countTokens() != 2) { 306 307 throw new ParseException ("Illegal key value pair " + keyValue, 0); 308 309 } 310 311 } 312 313 } 314 | Popular Tags |