Changeset 2101 for FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/handlers/PropertiesLoader.java
- Timestamp:
- 2008-06-23 00:00:48 (7 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/handlers/PropertiesLoader.java
r1685 r2101 26 26 import java.util.Properties; 27 27 28 import net.fckeditor.tool.Utils;29 30 28 import org.slf4j.Logger; 31 29 import org.slf4j.LoggerFactory; 32 30 33 31 /** 34 * Handler to hold the basic properties.<br> 35 * The main default file is 'default.properties' in the deepth of the classpath and should be 36 * untouched. If there is a file named 'fckeditor.properties' in the root of the classpath, it will 37 * be loaded. Values which are loaded before, will be overwritten.<br> 38 * If you won't use an extra properties file to adjust the defaults, you can use 39 * {@link #setProperty(String, String)} instead. 32 * This handler gives you access to properties stored in 33 * <code>/net/fckeditor/handlers/default.properties</code> and 34 * <code>/fckeditor.properties</code>.<br /> 35 * This class loads the properties files as follows: 36 * <ol> 37 * <li>Load <code>default.properties</code></li> 38 * <li>Load <code>fckeditor.properties</code> if present.</li> 39 * </ol> 40 * <em>Attention</em>: Properties specified in 41 * <code>fckeditor.properties</code> will override properties loaded from 42 * <code>default.properties</code>. (intended behavior)<br /> 43 * <em>Hint</em>: You may set properties programmatically with 44 * {@link #setProperty(String, String)} instead or additionally. 40 45 * 41 46 * @version $Id$ … … 47 52 static { 48 53 try { 49 // 1. load systemdefaults54 // 1. load library defaults 50 55 properties.load(new BufferedInputStream(PropertiesLoader.class 51 56 .getResourceAsStream("default.properties"))); … … 54 59 InputStream in = PropertiesLoader.class.getResourceAsStream("/fckeditor.properties"); 55 60 if (in == null) 56 logger.warn("Can't find userproperties!");61 logger.warn("Can't find fckeditor.properties!"); 57 62 else { 58 63 try { 59 64 properties.load(new BufferedInputStream(in)); 60 logger.info(" User'sproperties loaded successfully!");65 logger.info("fckeditor.properties loaded successfully!"); 61 66 } catch (IOException e) { 62 logger.error("Error while loading userproperties!", e);63 throw new RuntimeException("Can't load userproperties!", e);67 logger.error("Error while loading fckeditor.properties!", e); 68 throw new RuntimeException("Can't load fckeditor.properties!", e); 64 69 } 65 70 } 66 71 } catch (IOException e) { 67 logger.error("Error while loading default properties!", e);68 throw new RuntimeException("Can't load default properties!", e);72 logger.error("Error while loading default.properties!", e); 73 throw new RuntimeException("Can't load default.properties!", e); 69 74 } 70 75 } 71 76 72 77 /** 73 * Getter for a property of 'key'.78 * Getter for a property. 74 79 * 75 80 * @param key 76 * the propery key77 * @return the value in this property list with the specified key value.81 * The property key. 82 * @return The value for the specified key. 78 83 * @see Properties#getProperty(String) 79 84 */ … … 83 88 84 89 /** 85 * Setter for a property. If the property already exists, the value will be overwritten.<br> 86 * Hint: This method is intended for an alternative way to set user defaults programmatically 87 * instead of using the 'fckeditor.properties'. It should never used inside FCKeditor.Java !!! 90 * Setter for a property. If the property already exists, the value will be 91 * overridden.<br /> 92 * <em>Hint</em>: This method is intended as an alternative way to set 93 * properties programmatically instead of using the 94 * <code>fckeditor.properties</code>. It should never used inside 95 * FCKeditor.Java!!! 88 96 * 89 97 * @param key 90 * key the propery key98 * The property key. 91 99 * @param value 92 * @throws IllegalArgumentException 93 * if 'key' is empty. 100 * The property value. 94 101 * @see Properties#setProperty(String, String) 95 102 */ 96 103 public static void setProperty(final String key, final String value) { 97 if (Utils.isEmpty(key))98 new IllegalArgumentException("The 'key' of a property schouldn't be null!");99 104 properties.setProperty(key, value); 100 105 }