1 23 24 package org.apache.slide.util; 25 26 import java.io.File ; 27 import java.io.FileInputStream ; 28 import java.io.IOException ; 29 import java.io.InputStream ; 30 import java.util.Properties ; 31 32 import org.apache.slide.common.Domain; 33 import org.apache.slide.store.Store; 34 35 52 public abstract class Configuration { 53 54 55 57 58 61 public static class Property { 62 63 64 66 67 73 public static final String DomainInitFilename = 74 "org.apache.slide.domain"; 75 76 77 83 public static final String IntegratedSecurity = 84 "org.apache.slide.security"; 85 86 87 93 public static final String IntegratedLocking = "org.apache.slide.lock"; 94 95 96 102 public static final String VersionControl = "org.apache.slide.versioncontrol"; 103 104 105 111 public static final String Search = "org.apache.slide.search"; 112 113 114 120 public static final String Binding = "org.apache.slide.binding"; 121 122 123 129 public static final String Events = "org.apache.slide.events"; 130 131 137 public static final String UrlEncoding = "org.apache.slide.urlEncoding"; 138 139 140 146 public static final String PrincipalIdentifiedLocks = "org.apache.slide.principalIdentifiedLocks"; 147 148 149 155 public static final String Debug = "org.apache.slide.debug"; 156 157 158 164 public static final String FileName = "slide.properties"; 165 166 167 static final String ResourceName = 168 "/org/apache/slide/slide.properties"; 169 170 } 171 172 173 175 176 179 private static Properties _default; 180 181 182 185 private static boolean _debug; 186 187 188 191 private static boolean _security; 192 193 194 197 private static boolean _locking; 198 199 200 203 private static boolean _versioncontrol; 204 205 206 209 private static boolean _search; 210 211 212 215 private static boolean _binding; 216 217 220 private static boolean _events; 221 222 225 private static String _urlEncoding; 226 227 228 231 private static boolean _principalIdentifiedLocks; 232 233 234 236 237 240 public static boolean debug() { 241 return _debug; 242 } 243 244 245 248 public static boolean useIntegratedSecurity() { 249 return _security; 250 } 251 252 253 256 public static boolean useIntegratedLocking() { 257 return _locking; 258 } 259 260 261 264 public static boolean useVersionControl() { 265 return _versioncontrol; 266 } 267 268 269 272 public static boolean useSearch () { 273 return _search; 274 } 275 276 public static boolean useBinding (Store store) { 278 return _binding && store.useBinding(); 279 } 280 281 285 public static boolean useGlobalBinding () { 286 return _binding; 287 } 288 289 292 public static boolean fireEvents() { 293 return _events; 294 } 295 296 297 300 public static String urlEncoding() { 301 return _urlEncoding; 302 } 303 304 307 public static boolean usePrincipalIdentifiedLocks() { 308 return _principalIdentifiedLocks; 309 } 310 311 312 314 315 static { 316 getDefault(); 317 } 318 319 320 322 323 330 public static synchronized Properties getDefault() { 331 if (_default == null) { 332 load(); 333 } 334 return _default; 335 } 336 337 338 340 341 348 protected static void load() { 349 350 File file; 351 InputStream is; 352 353 _default = new Properties (); 355 try { 356 _default.load(Configuration.class.getResourceAsStream 357 (Property.ResourceName)); 358 } catch (Exception except) { 359 } 364 365 file = new File (System.getProperty("java.home"), "lib"); 368 file = new File (file, Property.FileName); 369 if (file.exists()) { 370 _default = new Properties (_default); 371 try { 372 _default.load(new FileInputStream (file)); 373 Domain.info("Configuration found in java.home"); 374 } catch (IOException except) { 375 } 377 } 378 379 try { 382 is = Configuration.class.getResourceAsStream("/" 383 + Property.FileName); 384 if ( is != null ) { 385 _default = new Properties (_default); 386 _default.load(is); 387 Domain.info("Configuration found in classpath"); 388 } 389 } catch (Exception except) { 390 } 392 393 String prop; 394 395 prop = _default.getProperty(Property.Debug, "false"); 396 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 397 _debug = true; 398 } 399 400 prop = _default.getProperty(Property.IntegratedSecurity, "true"); 401 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 402 _security = true; 403 } else { 404 _security = false; 405 } 406 407 prop = _default.getProperty(Property.IntegratedLocking, "true"); 408 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 409 _locking = true; 410 } else { 411 _locking = false; 412 } 413 414 prop = _default.getProperty(Property.VersionControl, "true"); 415 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 416 _versioncontrol = true; 417 } else { 418 _versioncontrol = false; 419 } 420 421 prop = _default.getProperty(Property.Search, "true"); 422 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 423 _search = true; 424 } else { 425 _search = false; 426 } 427 428 prop = _default.getProperty(Property.Binding, "true"); 429 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 430 _binding = true; 431 } else { 432 _binding = false; 433 } 434 435 prop = _default.getProperty(Property.Events, "false"); 436 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 437 _events = true; 438 } else { 439 _events = false; 440 } 441 442 prop = _default.getProperty(Property.PrincipalIdentifiedLocks, "false"); 443 if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { 444 _principalIdentifiedLocks = true; 445 } else { 446 _principalIdentifiedLocks = false; 447 } 448 449 String defaultEncoding = new java.io.InputStreamReader (System.in).getEncoding(); 450 _urlEncoding = _default.getProperty(Property.UrlEncoding, defaultEncoding); 451 452 } 453 454 } 455
| Popular Tags
|