Plugin setup

All plugins can have a setup screen accessible from the plugin list. The setup is available only for users with all access rights (super users). To create a setup screen for your plugin, implement the two methods

Method getSetupHTML(HashMap resources). 

Gets the HTML code for plugin setup screen. The code must include all HTML needed between the form tags. For example, the code could be:

        public String getSetupHTML(HashMap resources) {
                StringBuffer html = new StringBuffer();
                html.append("<table>");
                html.append("  <tr>");
                html.append("    <td class='form label'>Name:</td>");
                html.append("    <td class='form value'><input type=text name=plugin_name class='width200'></td>");
                html.append("  </tr>");
                html.append("  <tr>");
                html.append("    <td class='form label'>Address:</td>");
                html.append("    <td class='form value'><input type=password name=plugin_address class='width200'></td>");
                html.append("  </tr>");
                html.append("  <tr>");
                html.append("    <td class='form'></td>");
                html.append("    <td class='form value'><input type=submit value='Save' name=plugin_savebutton class='button'></td>");
                html.append("  </tr>");
                html.append("</table>");
                return html.toString();
        }
                                        

Important

All input field names must start with "plugin". This is to avoid any conflicts with any fields produced by Opinio.

The example includes two fields: "plugin_name" and "plugin_address". When the user enters the values and clicks the submit button (must also be provided in the code), Opinio will receive the form and return it through a call to the processSetupHTML(HashMap resources) method. It is then up to the plugin to process the setup html. This method is not required by the plugin. If not implemented, a standard no-op text is returned.

It is recommended that the look & feel of Opinio is used.

Method processSetupHTML(HashMap resources). 

The processSetup() method is called by Opinio, and may look like this:

        public ProcessResult processSetupHTML(HashMap resources) {
                // retrieve request object from resources
                HttpServletRequest request = (HttpServletRequest) resources.get(PluginConstants.RESOURCE_HTTP_REQUEST);
                String nameValue = request.getParameter("plugin_name");
                String addressValue = request.getParameter("plugin_address");

                ... // do something with the values

                return new ProcessResult("The plugin configuration was saved successfully", false);
        }
                                        

It is up to the implementor (developer) of this method to process the values appropriately. The method returns the result object with message to show to the user. Let the user know what happened with the processing of the form values. If null returned, the plugin list screen will be displayed. If result of type confirmation is returned, confirmation message will be displayed, based on user preferences. If result of type error is returned, the error message will be displayed over the setup screen html. Note that ProcessResult of type error is returned, the getSetupHTML(HashMap) will be called again. Implement the logic that retrieves the values from the request and put the values to the form fields, so that user can correct them.

Remember, it is up to the plugin author to make the setup values persistent. Functionality for making this easier will be added in future versions. Look in the example plugin included with the distribution on how to make the configuration persistent.