From: Thomas J. <fa...@ap...> - 2002-11-05 01:00:29
|
Update of /var/lib/cvs/bWF2/src/de/bchat/bwf2 In directory apollo:/tmp/cvs-serv28249 Modified Files: bWF2Repository.java Log Message: added theme companion methods. get themes, parse the special theme.properties file, flush config... pretty weird. added bWF2Theme Index: bWF2Repository.java =================================================================== RCS file: /var/lib/cvs/bWF2/src/de/bchat/bwf2/bWF2Repository.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- bWF2Repository.java 27 Oct 2002 04:17:41 -0000 1.6 +++ bWF2Repository.java 5 Nov 2002 01:00:21 -0000 1.7 @@ -3,14 +3,20 @@ import java.util.HashMap; import java.util.Locale; import java.util.ResourceBundle; +import java.util.Enumeration; +import java.util.Iterator; import java.util.regex.Pattern; +import java.lang.reflect.Array; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import de.bchat.common.auth.Gpw; +import de.bchat.bwf2.theming.bWF2Theme; +import de.bchat.database.bchatDatabase; import org.apache.log4j.Logger; @@ -26,10 +32,14 @@ private static Gpw gpw = new Gpw(); private static String mContextPath; + private static String mWebPath; public static java.util.Properties mConfiguration = null; public static java.util.Properties mRegExStrings = null; + public static java.util.Properties mThemeProperties=null; public static HashMap mCompiledRegExps = new HashMap(); + public static HashMap mThemes = new HashMap(); + public static String[] mThemeNames = null; private static Logger log = Logger.getLogger("bWF2Repository"); @@ -48,13 +58,16 @@ try { File prop = new File(properties); mContextPath = prop.getParent(); + File web = new File(mContextPath); + mWebPath = web.getParent(); log.debug("Setting mContextPath to " + mContextPath); + log.debug("Setting mWebPath to " + mWebPath); mConfiguration.load(new FileInputStream(prop)); } catch(IOException iox) { log.error("Could not read properties", iox); throw iox; } - } + } public static Locale getDefaultLocale() { if(mDefaultLocale == null) { @@ -101,7 +114,7 @@ public static String getProperty(String key, String def) { if(mConfiguration == null) { try { - File info = new File(System.getProperties().getProperty("bWF2.properties", "bWF2.properties")); + File info = new File( mContextPath + File.separator + "bWF2.properties"); log.debug("Loading properties from file " + info.getAbsoluteFile()); FileInputStream content = new FileInputStream(info); mConfiguration = new java.util.Properties(); @@ -150,7 +163,9 @@ if(mRegExStrings == null) { try { getProperty("load","load"); //ensure the properties are loaded - File info = new File(mContextPath + File.separator + getProperty("bchat.regexps.DEFINITION_FILE", "regularExpressions.properties")); + File info = new File(mContextPath + + File.separator + + getProperty("bchat.regexps.DEFINITION_FILE", "regularExpressions.properties")); log.debug("Loading regular expressions from file " + info.getAbsoluteFile()); FileInputStream content = new FileInputStream(info); mRegExStrings = new java.util.Properties(); @@ -178,9 +193,106 @@ return mContextPath; } + public static String getWebPath() { + return mWebPath; + } + public static String genPassword() { String pwdLenS = (String)getProperty("bchat.common.auth.PWDLEN","8"); int pwdLen = (Integer.valueOf(pwdLenS)).intValue(); return gpw.generate(pwdLen); } + + public static bWF2Theme getTheme(String name) { + if(mThemes.get(name) == null) { + if(mThemeProperties == null) { + try { + getProperty("load","load"); + File info = new File(mContextPath + + File.separator + + getProperty("bchat.themes.DEFINITION_FILE", "themes.properties")); + log.debug("Loading theme information from file " + + getProperty("bchat.themes.DEFINITION_FILE", "themes.properties")); + FileInputStream content = new FileInputStream(info); + mThemeProperties= new java.util.Properties(); + mThemeProperties.load(content); + + mThemes = parseThemes(); + } catch(java.io.FileNotFoundException fnfe) { + log.error("configuration could not be loaded - file not found", fnfe); + mConfiguration = null; + } catch(java.io.IOException ioe) { + log.error("configuration could not be loaded - ioexception", ioe); + mConfiguration = null; + } + } + + + } + return (bWF2Theme)mThemes.get(name); + } + + private static HashMap parseThemes() { + HashMap themes = new HashMap(); + + Enumeration tenu = mThemeProperties.propertyNames(); + while(tenu.hasMoreElements()) { + String curkey = (String) tenu.nextElement(); + String cvalue = mThemeProperties.getProperty(curkey); + if(cvalue == null || cvalue.trim().equals("")) { //a new theme name + log.debug("found theme: " + curkey); + HashMap files = new HashMap(); + HashMap meta= new HashMap(); + + Enumeration eenu = mThemeProperties.propertyNames(); + while(eenu.hasMoreElements()) { + String ekey = (String) eenu.nextElement(); + if(ekey.startsWith(curkey+".")) { + if(ekey.startsWith(curkey+".file.")) { + files.put(ekey.substring((curkey+".file.").length(), ekey.length()), + mThemeProperties.getProperty(ekey)); + } else { + meta.put(ekey.substring(curkey.length()+1,ekey.length()), + mThemeProperties.getProperty(ekey)) ; + } + } + } + themes.put(curkey, new bWF2Theme(curkey, files, meta)); + } + } + + return themes; + } + + public static String[] getThemes() { + getTheme("make-sure-themes-are-loaded"); + + if(mThemeNames == null) { + mThemeNames = new String[mThemes.size()]; + int i=0; + Iterator tit = mThemes.keySet().iterator(); + while(tit.hasNext()) { + mThemeNames[i++] = (String)tit.next(); + } + } + + return mThemeNames; + } + + public static synchronized void flushConfigs() { + //Regular Expressions + mCompiledRegExps = new HashMap(); + mRegExStrings = null; + //Themes + mThemeNames = null; + mThemes = new HashMap(); + mThemeProperties = null; + //locale + mDefaultLocale = null; + //general configs + mConfiguration = null; + } + } + + |