Commit 6e37d9ab authored by Liang Ding's avatar Liang Ding

#12401

parent 0168859e
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package org.b3log.solo.processor.console; package org.b3log.solo.processor.console;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.inject.Inject; import org.b3log.latke.ioc.inject.Inject;
...@@ -41,13 +40,12 @@ import javax.servlet.http.HttpServletRequest; ...@@ -41,13 +40,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Map; import java.util.Map;
/** /**
* Plugin console request processing. * Plugin console request processing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:wmainlove@gmail.com">Love Yao</a> * @author <a href="mailto:wmainlove@gmail.com">Love Yao</a>
* @version 1.1.0.0, Jan 17, 2013 * @version 1.1.0.1, Mar 3, 2018
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -89,20 +87,15 @@ public class PluginConsole { ...@@ -89,20 +87,15 @@ public class PluginConsole {
* </pre> * </pre>
* </p> * </p>
* *
* @param request the specified http servlet request * @param context the specified http request context
* @param response the specified http servlet response * @param requestJSONObject the specified requeset json object
* @param context the specified http request context
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = "/console/plugin/status/", method = HTTPRequestMethod.PUT) @RequestProcessing(value = "/console/plugin/status/", method = HTTPRequestMethod.PUT)
public void setPluginStatus(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) public void setPluginStatus(final HTTPRequestContext context, final JSONObject requestJSONObject) throws Exception {
throws Exception {
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String pluginId = requestJSONObject.getString(Keys.OBJECT_ID); final String pluginId = requestJSONObject.getString(Keys.OBJECT_ID);
final String status = requestJSONObject.getString(Plugin.PLUGIN_STATUS); final String status = requestJSONObject.getString(Plugin.PLUGIN_STATUS);
...@@ -175,22 +168,16 @@ public class PluginConsole { ...@@ -175,22 +168,16 @@ public class PluginConsole {
/** /**
* get the info of the specified pluginoId,just fot the plugin-setting. * get the info of the specified pluginoId,just fot the plugin-setting.
* *
* @param request the specified http servlet request * @param context the specified http request context
* @param response the specified http servlet response * @param requestJSONObject the specified request json object
* @param context the specified http request context * @param renderer the specified {@link ConsoleRenderer}
* @param renderer the specified {@link ConsoleRenderer}
* @throws Exception exception
*/ */
@RequestProcessing(value = "/console/plugin/toSetting", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/plugin/toSetting", method = HTTPRequestMethod.POST)
public void toSetting(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context, public void toSetting(final HTTPRequestContext context, final JSONObject requestJSONObject, final ConsoleRenderer renderer) {
final ConsoleRenderer renderer) throws Exception {
context.setRenderer(renderer); context.setRenderer(renderer);
try { try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final String pluginId = requestJSONObject.getString(Keys.OBJECT_ID); final String pluginId = requestJSONObject.getString(Keys.OBJECT_ID);
final String setting = pluginQueryService.getPluginSetting(pluginId); final String setting = pluginQueryService.getPluginSetting(pluginId);
renderer.setTemplateName("admin-plugin-setting.ftl"); renderer.setTemplateName("admin-plugin-setting.ftl");
...@@ -200,41 +187,32 @@ public class PluginConsole { ...@@ -200,41 +187,32 @@ public class PluginConsole {
dataModel.put(Plugin.PLUGIN_SETTING, setting); dataModel.put(Plugin.PLUGIN_SETTING, setting);
dataModel.put(Keys.OBJECT_ID, pluginId); dataModel.put(Keys.OBJECT_ID, pluginId);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e); LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult(); final JSONObject jsonObject = QueryResults.defaultResult();
final JSONRenderer jsonRenderer = new JSONRenderer(); final JSONRenderer jsonRenderer = new JSONRenderer();
jsonRenderer.setJSONObject(jsonObject); jsonRenderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel")); jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
} }
} }
/** /**
* update the setting of the plugin. * update the setting of the plugin.
* *
* @param request the specified http servlet request * @param context the specified http request context
* @param response the specified http servlet response * @param requestJSONObject the specified request json object
* @param context the specified http request context * @param renderer the specified {@link ConsoleRenderer}
* @param renderer the specified {@link ConsoleRenderer}
* @throws Exception exception
*/ */
@RequestProcessing(value = "/console/plugin/updateSetting", method = HTTPRequestMethod.POST) @RequestProcessing(value = "/console/plugin/updateSetting", method = HTTPRequestMethod.POST)
public void updateSetting(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context, public void updateSetting(final HTTPRequestContext context, final JSONObject requestJSONObject, final JSONRenderer renderer) {
final JSONRenderer renderer) throws Exception {
context.setRenderer(renderer); context.setRenderer(renderer);
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response); final String pluginoId = requestJSONObject.optString(Keys.OBJECT_ID);
final String pluginoId = requestJSONObject.getString(Keys.OBJECT_ID); final String settings = requestJSONObject.optString(Plugin.PLUGIN_SETTING);
final String settings = requestJSONObject.getString(Plugin.PLUGIN_SETTING);
final JSONObject ret = pluginMgmtService.updatePluginSetting(pluginoId, settings); final JSONObject ret = pluginMgmtService.updatePluginSetting(pluginoId, settings);
renderer.setJSONObject(ret); renderer.setJSONObject(ret);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment