/** * Loads the webapp properties based on servlet context information. * Returns a Properties object containing the settings, or null if unable * to load it. (The default file is WEB-INF/jspwiki.properties, and can * be overridden by setting PARAM_PROPERTYFILE in the server or webapp * configuration.) */ private static Properties loadWebAppProps( ServletContext context ) { String additionalPropertyFile = context.getInitParameter(PARAM_PROPERTYFILE); InputStream additionalPropertyStream = null; InputStream propertyStream = null; try { // Use the default property file. propertyStream = context.getResourceAsStream(DEFAULT_PROPERTYFILE); if( propertyStream == null ) { throw new WikiException("Default-Property file cannot be found!"+DEFAULT_PROPERTYFILE); } // Load Default Properties Properties props = new Properties( TextUtil.createProperties( DEFAULT_PROPERTIES ) ); props.load( propertyStream ); // // Figure out where our properties lie. // if( additionalPropertyFile == null ) { context.log("No "+PARAM_PROPERTYFILE+" defined for this context, using only default from "+DEFAULT_PROPERTYFILE); } else { context.log("Reading additional properties from "+additionalPropertyFile+" and merge to default."); Properties additionalProps = new Properties(); additionalPropertyStream = new FileInputStream( new File(additionalPropertyFile) ); if( additionalPropertyStream == null ) { throw new WikiException("Property file cannot be found!"+additionalPropertyFile); } additionalProps.load( additionalPropertyStream ); props.putAll(additionalProps); } return( props ); } catch( Exception e ) { context.log( Release.APPNAME+": Unable to load and setup properties from jspwiki.properties. "+e.getMessage() ); } finally { try { propertyStream.close(); if (additionalPropertyStream != null) { additionalPropertyStream.close(); } } catch( IOException e ) { context.log("Unable to close property stream - something must be seriously wrong."); } } return( null ); }