Wiki source code of Plugin-Bundle-Properties


Hide last authors
gru 1.1 1 {{content/}}
2
fse 8.1 3 The bundle properties offer the plug-in developer the possibility to configure plug-ins externally and thus control the runtime behaviour of the developed plug-ins.
gru 1.1 4
fse 8.1 5 The bundle properties can be used, for example, to make addresses and access information of web service endpoints configurable.
gru 1.1 6
fse 8.1 7 They are suitable for externally influencing certain plugin types, such as the //IPluginFormPreRender plugin //or the //IPluginServletAction plugin//, which themselves do not have their own configuration interface in {{formcycle case="dat"/}}.
gru 1.1 8
fse 8.1 9 == Definition of bundle properties by the plugin developer ==
gru 1.1 10
fse 8.1 11 {{figure image="plugin_props_config_en.png" title="FORMCYCLE Bundle-Properties: Display in interface" width="500"}}
12 By including the //IBundleProperties// interface, configurable options can be displayed in the {{formcycle case="dat"/}} interface.
gru 1.1 13 {{/figure}}
14
fse 8.1 15 The interface of {{formcycle case="dat"/}} offers the possibility to store new properties with name and value at the respective plug-in bundle.
16 In most cases, however, it is useful if the name (access key, must be unique within the bundle properties) and, if necessary, a default value for a property are stored.
17 and, if applicable, a default value for a property, are already defined by the plug-in developer.
18 \\On the one hand, this eliminates typing errors when the access key is created by the plug-in user, and on the other hand
19 on the other hand, the plug-in user receives a view of all configuration values supported by the plug-in developer.
gru 1.1 20
21
fse 8.1 22 == Interface IBundleProperties ==
gru 1.1 23
fse 8.1 24 The interface provides the following method signatures:
25
gru 1.1 26 {{panel title="{{code language='java'~}~}Map<String, IBundleConfigParam> getConfigProperties(IPluginResourceHelper resHelper, Locale currentLocale){{/code~}~}" triggerable="true" fullwidth="true"}}
27 (((
fse 8.1 28 The //getConfigProperties// method is used to configure property values that should be available to all Java classes within the plugin bundle.
gru 1.1 29 )))
fse 8.1 30 **Transfer values:**
gru 1.1 31 (((
32 * **IPluginResourceHelper**
fse 8.1 33 ** Objects to access the file resources contained in the plugin bundle.
gru 1.1 34 * **Locale**
fse 8.1 35 ** The //Locale// object defined for the currently logged-in user (contains information on the language and region).
36 This can be used to determine language-dependent texts.
gru 1.1 37 )))
fse 8.1 38 **Return values:**
gru 1.1 39 (((
fse 8.1 40 The method must return an object of type //java.util.Map// with Value objects of type //IBundleConfigParam//.
41 There are two possible implementations of //IBundleConfigParam//:
gru 1.1 42 )))
43
44 * **BundleConfigGroupItem**
fse 8.1 45 **This item can be used to structure the list display in the {{formcycle case="dat"/}} interface.
gru 1.1 46 * **BundleConfigParam**
fse 8.1 47 ** Used to define a bundle property. An object defines the following properties:
gru 1.1 48 **: //name//
fse 8.1 49 **:: The name or access key of a property.
gru 1.1 50 **: //description//
fse 8.1 51 **:: Description of a property. Displayed by //mouseover// over the //Property// name in the interface. Can be used to show the user of the plug-in more detailed information on the use or possible value ranges of the parameter.
gru 1.1 52 **: //mandatory//
fse 8.1 53 **:: Determines whether the parameter is displayed as a mandatory parameter in the interface and whether a validation for the presence of a value is carried out when saving.
gru 1.1 54 **: //crypticValue//
fse 8.1 55 **:: Determines whether the value of the property is to be masked as with a password field. Default value is {{code language="none"}}false{{/code}}.
gru 1.1 56 **: //defaultValue//
fse 8.1 57 **:: Allows the developer to set a default value. Default value is {{code language="none"}}null{{/code}}.
gru 1.1 58
59 {{/panel}}
60
fse 8.1 61 == Implementation example ==
gru 1.1 62
fse 8.1 63 The following code example shows a possible implementation:
gru 1.1 64
65 {{code language="java" title=""}}
66 @SuppressWarnings("serial")
67 public class MyBundleProperties implements IBundleProperties {
68
69 /**
70 * Returns a map with definitions of bundle configuration parameters. Key is the parameter name, value is a bundle
71 * parameter definition of type {@link IBundleConfigParam}.
fse 8.1 72 * @param resHelper ResourceHelper to determine i18n values from the plugin bundle, if they exists.
gru 1.1 73 * @param currentLocale the current locale
fse 8.1 74 * @return {@link Map} with objects of type {@link IBundleConfigParam} or <code>null</code>.
gru 1.1 75 */
76 @Override
77 public Map<String, IBundleConfigParam> getConfigProperties(IPluginResourceHelper resHelper, Locale currentLocale) {
78 Map<String, IBundleConfigParam> config = new LinkedHashMap<>();
fse 8.1 79 config.put("Group", new BundleConfigGroupItem("Supported parameters:"));
80 config.put("Parameter1", new BundleConfigParam("Parameter1", "Mandatory parameter in scope of plugin with default value", true, "Default value"));
81 config.put("Parameter2", new BundleConfigParam("Parameter2", "Mandatory parameter in the scope of the plug-in", true));
82 config.put("Parameter3", new BundleConfigParam("Parameter3", "Parameter in scope of plug-in with default value", false, "Initial value"));
83 config.put("Parameter4", new BundleConfigParam("Parameter4", "Parameter in scope of plugin", false));
gru 1.1 84 return config;
85 }
86
87 }
88
89 {{/code}}
90
fse 8.1 91 == Access to bundle properties within the plugin logic ==
gru 1.1 92
fse 8.1 93 Access to bundle properties within individual plugin implementations is provided via the //IFCPlugin// interface and its provided plugin lifecycle methods.
94 All [[Plugin Types>>doc:Formcycle.PluginDevelopment.Types.WebHome]] inherit from this interface, allowing access to bundle properties in all plugin implementations.
gru 1.1 95
fse 8.1 96 == Examples for reading bundle properties ==
gru 1.1 97
fse 8.1 98 The following example shows how to access the bundle properties within a //IPluginFormPreRender// implementation.
gru 1.1 99
fse 8.1 100 By default, a PreRender plugin is executed on all form calls in the scope of the client in which it was registered.
101 For example, if you want the //PreRenderer// to be executed only when certain forms are called, you can make this configurable using //Bundle-Properties//.
102 The following example reads in the {{code language="none"}}execute{{/code}} method reads the value of the //Bundle-Property// {{code language="none"}}activate.form.alias{{/code}}, which contains the names of forms (separated by commas).
103 Then these names are compared with the name of the current form in whose scope the //PreRenderer// is currently running. 
104 If the name of the current form does not match a name from the configured list, further processing of the PreRenderer is aborted.
gru 1.1 105
106 {{code language="java" title=""}}
107 public class MyPreRenderer implements IPluginFormPreRender {
108
109 private Properties bundleProperties = null;
110
111 /**
fse 8.1 112 * Name which makes plugin uniquely identifiable.
gru 1.1 113 */
114 @Override
115 public String getName() {
fse 8.1 116 return "My PreRenderer";
gru 1.1 117 }
118
119 /**
fse 8.1 120 * Plugin lifecycle method, which is called when the object instance is created.
gru 1.1 121 */
122 @Override
123 public void initialize(IPluginInitializeData initializeData) throws FCPluginException {
124 bundleProperties = initializeData.getProperties();
125 }
126
127 /**
fse 8.1 128 * Method for executing plugin logic.
gru 1.1 129 */
130 @Override
131 public IPluginFormPreRenderRetVal execute(IPluginFormPreRenderParams params) throws FCPluginException {
fse 8.1 132 // Read bundle property 'activate.form.alias'.
gru 1.1 133 Set<String> alias = getConfiguredFormAlias("activate.form.alias");
134
fse 8.1 135 // Is PreRender plugin enabled for current form instance?
gru 1.1 136 IExtendedFormRequestContext ctx = (IExtendedFormRequestContext)params.getFormRequestContext();
fse 8.1 137 if (!alias.contains(ctx.getProject().getName())) {
138 // no form activation found -> cancel processing
gru 1.1 139 return new PluginFormPreRenderRetVal(Collections.EMPTY_MAP, true);
140 }
141
fse 8.1 142 // further PreRender implementation
gru 1.1 143 // ....
144
145 return new PluginFormPreRenderRetVal(Collections.EMPTY_MAP, true);
146 }
147
148 /**
fse 8.1 149 * Function to determine a bundle property value.
150 * The determined value is separated by a comma
151 * and returned as a HashSet.
gru 1.1 152 * @param propertyName
fse 8.1 153 * @return a {@link HashSet}
gru 1.1 154 */
155 protected Set<String> getConfiguredFormAlias(String propertyName) {
156 String formAlias = bundleProperties.getProperty(propertyName, null);
157 if (XStringUtils.isBlank(formAlias)) { return Collections.emptySet(); }
158 String[] arr = XStringUtils.split(formAlias, ",");
159 return new HashSet<String>(Arrays.asList(arr));
160 }
161 }
162 {{/code}}