use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class ArticleProcessor method getRandomArticles.
/**
* Gets random articles with the specified context.
*
* @param context the specified context
* @throws Exception exception
*/
@RequestProcessing(value = "/get-random-articles.do", method = HTTPRequestMethod.POST)
public void getRandomArticles(final HTTPRequestContext context) throws Exception {
final JSONObject jsonObject = new JSONObject();
final JSONObject preference = preferenceQueryService.getPreference();
final int displayCnt = preference.getInt(Option.ID_C_RANDOM_ARTICLES_DISPLAY_CNT);
if (0 == displayCnt) {
jsonObject.put(Common.RANDOM_ARTICLES, new ArrayList<JSONObject>());
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
renderer.setJSONObject(jsonObject);
return;
}
Stopwatchs.start("Get Random Articles");
final List<JSONObject> randomArticles = getRandomArticles(preference);
jsonObject.put(Common.RANDOM_ARTICLES, randomArticles);
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
renderer.setJSONObject(jsonObject);
Stopwatchs.end();
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class ArticleProcessor method getArticleContent.
/**
* Gets article content with the specified context.
*
* @param context the specified context
* @param request the specified request
*/
@RequestProcessing(value = "/get-article-content", method = HTTPRequestMethod.GET)
public void getArticleContent(final HTTPRequestContext context, final HttpServletRequest request) {
final String articleId = request.getParameter("id");
if (Strings.isEmptyOrNull(articleId)) {
return;
}
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
String content;
try {
content = articleQueryService.getArticleContent(request, articleId);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, "Can not get article content", e);
return;
}
if (null == content) {
return;
}
renderer.setContent(content);
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class ArticleProcessor method getRelevantArticles.
/**
* Gets relevant articles with the specified context.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/article/id/*/relevant/articles", method = HTTPRequestMethod.GET)
public void getRelevantArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final JSONObject jsonObject = new JSONObject();
final JSONObject preference = preferenceQueryService.getPreference();
final int displayCnt = preference.getInt(Option.ID_C_RELEVANT_ARTICLES_DISPLAY_CNT);
if (0 == displayCnt) {
jsonObject.put(Common.RANDOM_ARTICLES, new ArrayList<JSONObject>());
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
renderer.setJSONObject(jsonObject);
return;
}
Stopwatchs.start("Get Relevant Articles");
final String requestURI = request.getRequestURI();
final String articleId = StringUtils.substringBetween(requestURI, "/article/id/", "/relevant/articles");
if (Strings.isEmptyOrNull(articleId)) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
final JSONObject article = articleQueryService.getArticleById(articleId);
if (null == article) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
final List<JSONObject> relevantArticles = articleQueryService.getRelevantArticles(article, preference);
jsonObject.put(Common.RELEVANT_ARTICLES, relevantArticles);
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
renderer.setJSONObject(jsonObject);
Stopwatchs.end();
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class LoginProcessor method showLogin.
/**
* Shows login page.
*
* @param context the specified context
* @throws Exception exception
*/
@RequestProcessing(value = "/login", method = HTTPRequestMethod.GET)
public void showLogin(final HTTPRequestContext context) throws Exception {
final HttpServletRequest request = context.getRequest();
String destinationURL = request.getParameter(Common.GOTO);
if (Strings.isEmptyOrNull(destinationURL)) {
destinationURL = Latkes.getServePath() + Common.ADMIN_INDEX_URI;
}
final HttpServletResponse response = context.getResponse();
userMgmtService.tryLogInWithCookie(request, response);
if (null != userService.getCurrentUser(request)) {
// User has already logged in
response.sendRedirect(destinationURL);
return;
}
renderPage(context, "login.ftl", destinationURL, request);
}
use of org.b3log.latke.servlet.annotation.RequestProcessing in project solo by b3log.
the class LoginProcessor method showForgot.
/**
* Shows forgotten password page.
*
* @param context the specified context
* @throws Exception exception
*/
@RequestProcessing(value = "/forgot", method = HTTPRequestMethod.GET)
public void showForgot(final HTTPRequestContext context) throws Exception {
final HttpServletRequest request = context.getRequest();
String destinationURL = request.getParameter(Common.GOTO);
if (Strings.isEmptyOrNull(destinationURL)) {
destinationURL = Latkes.getServePath() + Common.ADMIN_INDEX_URI;
}
renderPage(context, "reset-pwd.ftl", destinationURL, request);
}
Aggregations