/* this belongs to the WebRaveler package */ package webraveler.vurl; import java.util.*; import webraveler.http.HTTPRequest; import webraveler.http.HTTPResponse; import webraveler.ravel.Raveler; import webraveler.ravel.RavelerException; import webraveler.ravel.RavelerPlugin; import webraveler.ravel.RavelerUser; /** * Activates the given set of plugins * * @author The Web Raveler Development Squad * @version 1.0 */ public class PluginsActivated implements VURL { /** * */ public PluginsActivated () { } // PluginSequenceVURL() /** * Adds the specified plugins to the user's active plugins and updates the status of the plugins. * Returns a response indicating whether or not the operation was successful */ public HTTPResponse resolveVURL(String username, String query, HTTPRequest request,Raveler ravel) { /* Get the RavelerUser for the given username */ RavelerUser user = new RavelerUser(); String message = new String(); try { user = ravel.getUser(username); /* Parse the query */ /* First check if all the plugins should be activated */ String allTest = null; if (query != null && !query.equals("")) allTest = query.substring(0,3); if (allTest != null && allTest.equals("all")) { /* Determine whether to activate or deactivate all plugins */ int start = query.indexOf("="); String deter = query.substring(start+1,query.length()); if (deter.equals("on")) { /* Activate all the available plugins */ for (Enumeration f = ravel.getPlugins(); f.hasMoreElements() ;) { RavelerPlugin plugin = (RavelerPlugin) f.nextElement(); if (!user.activePlugins.contains(plugin.name) && !user.getStatus(plugin.name).equals("disabled")) { /* Add the plugin to the user's active plugins */ user.addActivePlugin(plugin.name); /* Set the status of the plugin to active */ user.setStatus(plugin.name,"active"); } //if } //for } //if else { /* Deactivate all the currently activated plugins */ if (!user.activePlugins.isEmpty()) { for (Enumeration f = user.activePlugins.elements(); f.hasMoreElements() ;) { String pluginName = (String) f.nextElement(); /* Change the status of the plugin to inactive */ user.setStatus(pluginName,"inactive"); } //for /* Remove all the plugins from the user's active plugins */ user.activePlugins.clear(); } //if } //else } //if else { /* Activate only the specified plugins */ int equalsIndex; int amperIndex=0; String pluginName; Vector modifiedPlugins = new Vector(); Hashtable pref; while ((equalsIndex = query.indexOf('=',amperIndex)) != -1) { /* Check if we are past the first part, if so increment the * amperIndex so that we don't include the & in the pluginName */ if (amperIndex != 0) amperIndex++; pluginName = query.substring(amperIndex,equalsIndex); /* Add the plugin to the newly active plugins vector */ modifiedPlugins.add(pluginName); /* Change the status of the plugin to active in the preferences for the user */ try { user.setStatus(pluginName,"active"); } catch (RavelerException re) { message = "
";} amperIndex = query.indexOf('&',equalsIndex); /* Check if we are at the last part, if so, stop */ if (amperIndex == -1) break; } //while /* Set the modified vector to the active plugins vector of the given user */ user.activePlugins = modifiedPlugins; /* Set the status of all the other plugins to inactive */ for (Enumeration f = ravel.getPlugins(); f.hasMoreElements();) { RavelerPlugin plugin = (RavelerPlugin) f.nextElement(); if (!user.activePlugins.contains(plugin.name) && !user.getStatus(plugin.name).equals("disabled")) { /* Change the status of the plugin to inactive in the preferences for the user */ user.setStatus(plugin.name,"inactive"); } //if } //for } //else message = ""; } catch (RavelerException re) { message = ""; } //catch /* Generate the response - include the user configuration page with note about plugins activated being changed */ UserConfigVURL userConfig = new UserConfigVURL(); userConfig.printMessage(message); HTTPResponse response = userConfig.resolveVURL(username,query,request,ravel); return response; } //resolveVURL }