Plugin functions

Plugins can be appended to the Menu box by implementing one of the interfaces in package

com.objectplanet.survey.plugin.interfaces.menu

One plugin can have multiple functions. Each function will appear as a link in the Menu box.

Number of functions. 

Number of functions provided bu the plugins is returned by getFunctionCount() method in the Plugin. If your plugin provide 2 functions, just return the number 2.

Function label. 

Method getFunctionLabel(int functionNo, HashMap resources) should return a descriptive name of the plugin function. The name will appear in the Menu box as link label.

public String getFunctionLabel(int functionNo, HashMap resources) {
        switch (functionNo) {
                case 1:
                        return "Recognize address";
                case 2:
                        return "Recognize name";
                }
        return "Unsupported function";
}
                                        

Function security. 

Plugin is self responsible for permission checks. This can be done by implementing method hasFunctionAccess(long userId, int functionNo, HashMap resources)

Function html. 

Gets the HTML code for plugin function. The code must include all HTML needed between the form tags. Here is example plugin with two function:

public String getFunctionHTML(int functionNo, HashMap resources) {
        StringBuffer pluginFunctionHTML = new StringBuffer();

        switch (functionNo) {
                case 1:
                        pluginFunctionHTML.append("<table>");
                        pluginFunctionHTML.append("     <tr><td class='form label'>Your mail address:</td>");
                        pluginFunctionHTML.append("             <td class='form value'>");
                        pluginFunctionHTML.append("                     <INPUT TYPE='text' class=width200 name='plugin_email' value=''>");
                        pluginFunctionHTML.append("             </td>");
                        pluginFunctionHTML.append("     </tr>");
                        pluginFunctionHTML.append("     <tr><td></td><td class=buttons>");
                        pluginFunctionHTML.append("                     <INPUT TYPE=submit class=button value='Ok'>");
                        pluginFunctionHTML.append("             </td>");
                        pluginFunctionHTML.append("     </tr>");
                        pluginFunctionHTML.append("</table>");
                        break;
                case 2:
                        pluginFunctionHTML.append("<table>");
                        pluginFunctionHTML.append("     <tr><td class='form label'>Your name:</td>");
                        pluginFunctionHTML.append("             <td class='form value'>");
                        pluginFunctionHTML.append("                     <INPUT TYPE='text' class=width200 name='plugin_name' value=''>");
                        pluginFunctionHTML.append("             </td>");
                        pluginFunctionHTML.append("     </tr>");
                        pluginFunctionHTML.append("     <tr><td></td><td class=buttons>");
                        pluginFunctionHTML.append("                     <INPUT TYPE=submit class=button value='Ok'>");
                        pluginFunctionHTML.append("             </td>");
                        pluginFunctionHTML.append("     </tr>");
                        pluginFunctionHTML.append("</table>");
                        break;
        }
        return pluginFunctionHTML.toString();
                                        

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 processFunctionHTML(int functionNo, HashMap resources) method. It is then up to the plugin to process the html. It is recommended that the look & feel of Opinio is used.

Processing function html. 

The processFunctionHTML(int functionNo, HashMap resources) method is called by Opinio when user submits the function page. Example of the method implementation:

        public ProcessResult processFunctionHTML(int functionNo, HashMap resources) {
                // retrieve request object
                HttpServletRequest request = (HttpServletRequest) resources.get("HttpRequest");

                // process the html based on function number
                switch (functionNo) {
                        case 1:
                                String email = request.getParameter("plugin_email");
                                if (email == null || email.equals("")) {
                                return new ProcessResult("Email cannot be blank!", true);
                                }
                                return new ProcessResult("Entered email is " + email, false);
                        case 2:
                                String name = request.getParameter("plugin_name");
                                if (name == null || name.equals("")) {
                                return new ProcessResult("Name cannot be blank!", true);
                                }
                                return new ProcessResult("Entered name is " + name, false);
                }
                return super.processFunctionHTML(functionNo, resources);
        }
                                        

The method returns ProcessResult 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 function screen will be displayed again. 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 function html. Note that ProcessResult of type error is returned, the processFunctionHTML(int, 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.

Plugin source. The source of this plugin example can be found in the distribution: SurveyFunctionExamplePlugin