Changeset 6627
- Timestamp:
- Nov 25, 2014, 12:57:24 PM (8 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java
r6600 r6627 694 694 } 695 695 696 697 /** 698 Get a configuration setting for an extension. 699 @param extensionId The ID of the extension to save a setting for 700 @param key The name of the setting 701 @return The value or null if it doesn't exists 702 @since 3.4 703 */ 704 public String getSetting(String extensionId, String key) 705 { 706 return settings.getSetting(extensionId, key); 707 } 708 709 /** 710 Set a configuration setting for an extension. Do not forget to 711 {@link #saveSettings()}. 712 @param extensionId The ID of the extension to save a setting for 713 @param key The name of the setting 714 @param value The value of the setting, use null to remove 715 @since 3.4 716 */ 717 public void setSetting(String extensionId, String key, String value) 718 { 719 checkPermission(Permission.WRITE, "Extension[id=" + extensionId + "]"); 720 settings.setSetting(extensionId, key, value); 721 } 722 696 723 /** 697 724 Get an list returning all XML/JAR files which contains installed -
trunk/src/core/net/sf/basedb/core/Presets.java
r6473 r6627 201 201 202 202 /** 203 Check if a preset with the given name exists. 204 @since 3.4 205 */ 206 public boolean exists(String name) 207 { 208 return presets.containsKey(name); 209 } 210 211 /** 203 212 Delete a named preset. 204 213 @param name The name of the preset to delete … … 348 357 349 358 /** 359 Get the number of settings in the preset. 360 @since 3.4 361 */ 362 public int size() 363 { 364 return settings.size(); 365 } 366 367 /** 350 368 Get all keys in this preset. The returned list is a 351 369 copy of the settings and are not affected by later -
trunk/src/core/net/sf/basedb/util/extensions/manager/Settings.java
r5616 r6627 155 155 156 156 /** 157 Get a preset containing settings for the given extesion. If no 158 settings exists, null is returned. Do not make modifications to 159 the returned preset since the result is undefined. Use 160 {@link #setSetting(String, String, String)} to set values. 161 @since 3.4 162 */ 163 public Preset getSettingsForExtension(String extensionId) 164 { 165 return presets.exists(extensionId) ? presets.getPreset(extensionId) : null; 166 } 167 168 /** 169 Set a configuration setting for an extension. Do not forget to 170 {@link #save()}. 171 @param extensionId The ID of the extension to save a setting for 172 @param key The name of the setting 173 @param value The value of the setting, use null to remove 174 @since 3.4 175 */ 176 public synchronized void setSetting(String extensionId, String key, String value) 177 { 178 if (value == null && !presets.exists(extensionId)) return; 179 180 Preset p = presets.getPreset(extensionId); 181 p.setSetting(key, value); 182 if (p.size() == 0) presets.deletePreset(extensionId); 183 hasChanged = true; 184 } 185 186 /** 187 Get a configuration setting for an extension. 188 @param extensionId The ID of the extension to save a setting for 189 @param key The name of the setting 190 @return The value or null if it doesn't exists 191 @since 3.4 192 */ 193 public String getSetting(String extensionId, String key) 194 { 195 Preset p = getSettingsForExtension(extensionId); 196 return p == null ? null : p.getSetting(key); 197 } 198 199 /** 157 200 Check if the given file is marked as installed. 158 201 @since 3.0 -
trunk/src/core/net/sf/basedb/util/extensions/xml/XmlLoader.java
r6473 r6627 43 43 import org.jdom2.output.XMLOutputter; 44 44 45 import net.sf.basedb.core.Application; 45 46 import net.sf.basedb.core.BaseException; 46 47 import net.sf.basedb.core.InvalidUseOfNullException; 48 import net.sf.basedb.core.Presets.Preset; 47 49 import net.sf.basedb.core.StringUtil; 48 50 import net.sf.basedb.core.Version; … … 608 610 if (rfTag != null) 609 611 { 610 RendererFactory rf = createFactory(rfTag, classLoader, RendererFactory.class );612 RendererFactory rf = createFactory(rfTag, classLoader, RendererFactory.class, null); 611 613 extensionPoint.setRendererFactory(rf); 612 614 extensionPoint.setAllowRendererOverrider( … … 617 619 if (ehfTag != null) 618 620 { 619 ErrorHandlerFactory ehf = createFactory(ehfTag, classLoader, ErrorHandlerFactory.class );621 ErrorHandlerFactory ehf = createFactory(ehfTag, classLoader, ErrorHandlerFactory.class, null); 620 622 extensionPoint.setErrorHandlerFactory(ehf); 621 623 } … … 745 747 Element afTag = epTag.getChild("action-factory", ns); 746 748 ActionFactory af = null; 749 Preset config = Application.getExtensionsManager().getSettings().getSettingsForExtension(id); 747 750 if (afTag != null) 748 751 { 749 af = createFactory(afTag, classLoader, ActionFactory.class );752 af = createFactory(afTag, classLoader, ActionFactory.class, config); 750 753 } 751 754 … … 755 758 if (rfTag != null) 756 759 { 757 rf = createFactory(rfTag, classLoader, RendererFactory.class );760 rf = createFactory(rfTag, classLoader, RendererFactory.class, config); 758 761 } 759 762 … … 899 902 @return An initialised factory 900 903 */ 901 protected <F> F createFactory(Element factoryTag, ClassLoader classLoader, Class<F> factoryType )904 protected <F> F createFactory(Element factoryTag, ClassLoader classLoader, Class<F> factoryType, Preset config) 902 905 throws ClassNotFoundException, NoSuchMethodException, 903 906 IllegalAccessException, InstantiationException … … 908 911 ClassUtil.checkAndLoadClass(classLoader, factoryClassName, true, factoryType); 909 912 F factory = factoryType.cast(factoryClass.newInstance()); 910 initBeanWithReflection(factory, factoryTag.getChild("parameters", ns) );913 initBeanWithReflection(factory, factoryTag.getChild("parameters", ns), config); 911 914 return factory; 912 915 } … … 927 930 @param root The root element, if null nothing is done 928 931 */ 929 protected void initBeanWithReflection(Object bean, Element root )932 protected void initBeanWithReflection(Object bean, Element root, Preset config) 930 933 { 931 934 if (root == null) return; … … 945 948 946 949 // The value passed as an argument to the setter method 947 String value = Values.getStringOrNull(child.getText()); 950 String value = config != null ? Values.getStringOrNull(config.getSetting(childName)) : null; 951 if (value == null) 952 { 953 value = Values.getStringOrNull(child.getText()); 954 } 948 955 949 956 if (value == null)
Note: See TracChangeset
for help on using the changeset viewer.