| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
package net.sourceforge.pebble.web.action; |
| 33 | |
|
| 34 | |
import net.sourceforge.pebble.Constants; |
| 35 | |
import net.sourceforge.pebble.domain.BlogServiceException; |
| 36 | |
import net.sourceforge.pebble.domain.Blog; |
| 37 | |
import net.sourceforge.pebble.plugins.PluginConfigType; |
| 38 | |
import net.sourceforge.pebble.web.security.RequireSecurityToken; |
| 39 | |
import net.sourceforge.pebble.web.view.ForwardView; |
| 40 | |
import net.sourceforge.pebble.web.view.View; |
| 41 | |
|
| 42 | |
import javax.servlet.ServletException; |
| 43 | |
import javax.servlet.http.HttpServletRequest; |
| 44 | |
import javax.servlet.http.HttpServletResponse; |
| 45 | |
import java.util.Enumeration; |
| 46 | |
import java.util.Properties; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@RequireSecurityToken |
| 54 | 0 | public class SavePluginsAction extends SecureAction { |
| 55 | |
|
| 56 | |
public static final String PLUGIN_TYPE_PLACEHOLDER_PREFIX = "pluginType_"; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException { |
| 66 | 0 | Blog blog = (Blog)getModel().get(Constants.BLOG_KEY); |
| 67 | |
|
| 68 | 0 | String submit = request.getParameter("submit"); |
| 69 | 0 | if (submit != null && submit.length() > 0) { |
| 70 | 0 | Properties pluginProperties = blog.getPluginProperties().getProperties(); |
| 71 | 0 | Enumeration params = request.getParameterNames(); |
| 72 | 0 | while (params.hasMoreElements()) { |
| 73 | 0 | String key = (String)params.nextElement(); |
| 74 | |
|
| 75 | 0 | if (key.equals("submit")) { |
| 76 | |
|
| 77 | 0 | } else if (key.startsWith(PluginConfigType.PLUGIN_PROPERTY_NAME_PREFIX)) { |
| 78 | 0 | String value = request.getParameterValues(key)[0]; |
| 79 | 0 | String property = key.substring(PluginConfigType.PLUGIN_PROPERTY_NAME_PREFIX.length()); |
| 80 | 0 | if (value == null || value.length() == 0) { |
| 81 | 0 | pluginProperties.remove(property); |
| 82 | |
} else { |
| 83 | 0 | pluginProperties.setProperty(property, value); |
| 84 | |
} |
| 85 | 0 | } else if (key.startsWith(PLUGIN_TYPE_PLACEHOLDER_PREFIX)) { |
| 86 | |
|
| 87 | 0 | String pluginType = key.substring(PLUGIN_TYPE_PLACEHOLDER_PREFIX.length()); |
| 88 | 0 | if (request.getParameter(pluginType) == null) { |
| 89 | 0 | blog.setProperty(pluginType, ""); |
| 90 | |
} |
| 91 | 0 | } else { |
| 92 | |
|
| 93 | 0 | String[] values = request.getParameterValues(key); |
| 94 | 0 | StringBuilder builder = new StringBuilder(); |
| 95 | 0 | String separator = ""; |
| 96 | 0 | for (String value : values) { |
| 97 | 0 | builder.append(separator).append(value); |
| 98 | 0 | separator = "\n"; |
| 99 | |
} |
| 100 | 0 | blog.setProperty(key, builder.toString()); |
| 101 | |
} |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
try { |
| 105 | 0 | blog.storeProperties(); |
| 106 | 0 | blog.getPluginProperties().store(); |
| 107 | 0 | } catch (BlogServiceException e) { |
| 108 | 0 | throw new ServletException(e); |
| 109 | 0 | } |
| 110 | |
} |
| 111 | |
|
| 112 | 0 | return new ForwardView("/reloadBlog.secureaction?redirectUrl=/aboutBlog.secureaction"); |
| 113 | |
} |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
public String[] getRoles(HttpServletRequest request) { |
| 122 | 0 | return new String[]{ |
| 123 | |
Constants.BLOG_ADMIN_ROLE, |
| 124 | |
Constants.BLOG_OWNER_ROLE |
| 125 | |
}; |
| 126 | |
} |
| 127 | |
|
| 128 | |
} |