use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class PageConsole method removePage.
/**
* Removes a page by the specified request.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "msg": ""
* }
* </pre>
* </p>
*
* @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = "/console/page/*", method = HTTPRequestMethod.DELETE)
public void removePage(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
try {
final String pageId = request.getRequestURI().substring((Latkes.getContextPath() + "/console/page/").length());
pageMgmtService.removePage(pageId);
jsonObject.put(Keys.STATUS_CODE, true);
jsonObject.put(Keys.MSG, langPropsService.get("removeSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
jsonObject.put(Keys.STATUS_CODE, false);
jsonObject.put(Keys.MSG, langPropsService.get("removeFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class PageConsole method getPage.
/**
* Gets a page by the specified request.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean
* "page": {
* "oId": "",
* "pageTitle": "",
* "pageContent": ""
* "pageOrder": int,
* "pagePermalink": "",
* "pageCommentCount": int,
* }
* }
* </pre>
* </p>
*
* @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = "/console/page/*", method = HTTPRequestMethod.GET)
public void getPage(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
try {
final String requestURI = request.getRequestURI();
final String pageId = requestURI.substring((Latkes.getContextPath() + "/console/page/").length());
final JSONObject result = pageQueryService.getPage(pageId);
if (null == result) {
renderer.setJSONObject(QueryResults.defaultResult());
return;
}
renderer.setJSONObject(result);
result.put(Keys.STATUS_CODE, true);
result.put(Keys.MSG, langPropsService.get("getSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class PreferenceConsole method getQiniuPreference.
/**
* Gets Qiniu preference.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "qiniuAccessKey": "",
* "qiniuSecretKey": "",
* "qiniuDomain": "",
* "qiniuBucket": ""
* }
* </pre>
* </p>
*
* @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = PREFERENCE_URI_PREFIX + "qiniu", method = HTTPRequestMethod.GET)
public void getQiniuPreference(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
if (!userQueryService.isAdminLoggedIn(request)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
try {
final JSONObject qiniu = optionQueryService.getOptions(Option.CATEGORY_C_QINIU);
if (null == qiniu) {
renderer.setJSONObject(QueryResults.defaultResult());
return;
}
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
ret.put(Option.CATEGORY_C_QINIU, qiniu);
ret.put(Keys.STATUS_CODE, true);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class PreferenceConsole method updateReplyNotificationTemplate.
/**
* Updates reply template.
*
* @param request the specified http servlet request, for example, <pre>
* {
* "replyNotificationTemplate": {
* "subject": "",
* "body": ""
* }
* }
* </pre>
*
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = "/console/reply/notification/template", method = HTTPRequestMethod.PUT)
public void updateReplyNotificationTemplate(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final JSONObject replyNotificationTemplate = requestJSONObject.getJSONObject("replyNotificationTemplate");
preferenceMgmtService.updateReplyNotificationTemplate(replyNotificationTemplate);
final JSONObject ret = new JSONObject();
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
renderer.setJSONObject(ret);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("updateFailLabel"));
}
}
use of org.b3log.latke.servlet.renderer.JSONRenderer in project solo by b3log.
the class PreferenceConsole method getReplyNotificationTemplate.
/**
* Gets reply template.
*
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "replyNotificationTemplate": {
* "subject": "",
* "body": ""
* }
* }
* </pre>
* </p>
*
* @param request the specified http servlet request
* @param response the specified http servlet response
* @param context the specified http request context
* @throws Exception exception
*/
@RequestProcessing(value = "/console/reply/notification/template", method = HTTPRequestMethod.GET)
public void getReplyNotificationTemplate(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context) throws Exception {
if (!userQueryService.isLoggedIn(request, response)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
try {
final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
ret.put("replyNotificationTemplate", replyNotificationTemplate);
ret.put(Keys.STATUS_CODE, true);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
Aggregations