1 50 51 package org.openlaszlo.iv.flash.util; 52 53 import org.openlaszlo.iv.flash.api.*; 54 55 import org.openlaszlo.iv.flash.cache.*; 56 import java.io.*; 57 import java.net.*; 58 import java.util.*; 59 60 68 public class PropertyManager { 69 70 73 public static boolean varCaseSensitive = true; 74 77 public static boolean symCaseSensitive = false; 78 81 public static boolean showErrorsInline = true; 82 85 public static boolean textMMStyle = false; 86 89 public static String fontPath = "fonts/"; 90 93 public static String defaultEncoding = null; 94 97 public static String mxLibrarySymbolPrefix = "__"; 98 101 public static String mxLibraryFontID = "[jgen]"; 102 103 private static Properties myProperties; 104 105 private static void loadCacheProperties( CacheSettings cs, String prefix ) { 106 cs.setMaxSize( getIntProperty( prefix+"CacheMaxSize", 0 ) ); 107 cs.setDefaultExpire( (long) (getDoubleProperty( prefix+"CacheDefaultExpire", 0.0 )*1000) ); 108 cs.setForce( getBoolProperty( prefix+"CacheForce", false ) ); 109 cs.setRecycle( getBoolProperty( prefix+"CacheRecycle", false ) ); 110 cs.setCheckModifiedSince( getBoolProperty( prefix+"CacheCheckModifiedSince", false ) ); 111 } 112 113 private static void saveCacheProperties( CacheSettings cs, String prefix ) { 114 setProperty( prefix+"CacheMaxSize", cs.getMaxSize() ); 115 setProperty( prefix+"CacheDefaultExpire", cs.getDefaultExpire()/1000.0 ); 116 setProperty( prefix+"CacheForce", cs.isForce() ); 117 setProperty( prefix+"CacheRecycle", cs.isRecycle() ); 118 setProperty( prefix+"CacheCheckModifiedSince", cs.isCheckModifiedSince() ); 119 } 120 121 128 public static void init( String propFileName ) { 129 if( propFileName == null ) propFileName = "iv.properties"; 130 load(propFileName); 131 varCaseSensitive = getBoolProperty( "org.openlaszlo.iv.flash.varCaseSensitive", true ); 132 symCaseSensitive = getBoolProperty( "org.openlaszlo.iv.flash.symCaseSensitive", false ); 133 showErrorsInline = getBoolProperty( "org.openlaszlo.iv.flash.showErrorsInline", true ); 134 textMMStyle = getBoolProperty( "org.openlaszlo.iv.flash.textBoundsMMStyle", false ); 135 fontPath = getProperty( "org.openlaszlo.iv.flash.fontPath", "fonts/" ); 136 defaultEncoding = getProperty( "org.openlaszlo.iv.flash.defaultEncoding" ); 137 mxLibrarySymbolPrefix = getProperty( "org.openlaszlo.iv.flash.mxLibrarySymbolPrefix", "__" ); 138 mxLibraryFontID = getProperty( "org.openlaszlo.iv.flash.mxLibraryFontID", "[jgen]" ); 139 if( defaultEncoding != null ) { 140 defaultEncoding = defaultEncoding.trim(); 141 if( defaultEncoding.length() == 0 || Util.isDefault(defaultEncoding) ) { 142 defaultEncoding = null; 143 } 144 } 145 } 146 147 152 public static void init() { 153 init("iv.properties"); 154 } 155 156 159 public static void load( String propFileName ) { 160 myProperties = new Properties(); 161 try { 162 myProperties.load( new FileInputStream( Util.getSysFile( propFileName ) ) ); 163 } catch( Exception e ) { 164 try { 165 myProperties.load( Util.getResource("/iv.properties").openStream() ); 166 } catch( Exception e1 ) { 167 Log.error(Resource.get(Resource.CANTLOADPROPERTIES), e1); 168 myProperties = new Properties(); 169 } 170 } 171 loadCacheProperties( getRequestCacheSettings(), "org.openlaszlo.iv.flash.request" ); 172 loadCacheProperties( getFontCacheSettings(), "org.openlaszlo.iv.flash.font" ); 173 loadCacheProperties( getMediaCacheSettings(), "org.openlaszlo.iv.flash.media" ); 174 loadCacheProperties( getXMLCacheSettings(), "org.openlaszlo.iv.flash.xml" ); 175 } 176 177 182 public static void save( String propFileName ) throws IOException { 183 saveCacheProperties( getRequestCacheSettings(), "org.openlaszlo.iv.flash.request" ); 184 saveCacheProperties( getFontCacheSettings(), "org.openlaszlo.iv.flash.font" ); 185 saveCacheProperties( getMediaCacheSettings(), "org.openlaszlo.iv.flash.media" ); 186 saveCacheProperties( getXMLCacheSettings(), "org.openlaszlo.iv.flash.xml" ); 187 setProperty( "org.openlaszlo.iv.flash.varCaseSensitive", varCaseSensitive ); 188 setProperty( "org.openlaszlo.iv.flash.symCaseSensitive", symCaseSensitive ); 189 setProperty( "org.openlaszlo.iv.flash.showErrorsInline", showErrorsInline ); 190 setProperty( "org.openlaszlo.iv.flash.textBoundsMMStyle", textMMStyle ); 191 setProperty( "org.openlaszlo.iv.flash.fontPath", fontPath ); 192 if( defaultEncoding != null ) setProperty( "org.openlaszlo.iv.flash.defaultEncoding", defaultEncoding ); 193 myProperties.save( new FileOutputStream( Util.getSysFile(propFileName) ), "" ); 195 } 196 197 203 public static void setProperty( String name, String value ) { 204 myProperties.put(name, value); 205 } 206 207 213 public static void setProperty( String name, int value ) { 214 myProperties.put(name, new Integer (value).toString()); 215 } 216 217 223 public static void setProperty( String name, boolean value ) { 224 myProperties.put(name, new Boolean (value).toString()); 225 } 226 227 233 public static void setProperty( String name, double value ) { 234 myProperties.put(name, new Double (value).toString()); 235 } 236 237 244 public static String getProperty( String name, String def ) { 245 String value = System.getProperty(name); 246 if( value != null ) return value; 247 return myProperties.getProperty(name, def); 248 } 249 250 256 public static String getProperty( String name ) { 257 String value = System.getProperty(name); 258 if( value != null ) return value; 259 return myProperties.getProperty(name); 260 } 261 262 269 public static int getIntProperty( String property, int def ) { 270 return Util.toInt( getProperty(property), def ); 271 } 272 273 280 public static long getLongProperty( String property, long def ) { 281 return Util.toLong( getProperty(property), def ); 282 } 283 284 291 public static boolean getBoolProperty( String property, boolean def ) { 292 return Util.toBool( getProperty(property), def ); 293 } 294 295 302 public static double getDoubleProperty( String property, double def ) { 303 return Util.toDouble( getProperty(property), def ); 304 } 305 306 public static Object getObjectProperty( Object key ) { 307 return myProperties.get(key); 308 } 309 310 public static void setObjectProperty( Object key, Object value ) { 311 myProperties.put(key, value); 312 } 313 314 319 public static CacheSettings getRequestCacheSettings() { 320 return RequestCache.getSettings(); 321 } 322 323 328 public static CacheSettings getFontCacheSettings() { 329 return FontCache.getSettings(); 330 } 331 332 337 public static CacheSettings getMediaCacheSettings() { 338 return MediaCache.getSettings(); 339 } 340 341 346 public static CacheSettings getXMLCacheSettings() { 347 return XMLCache.getSettings(); 348 } 349 350 } 351 | Popular Tags |