Search in sources :

Example 16 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method showAd.

/**
 * Shows ad.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/ad", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showAd(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/ad.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModel.put("sideFullAd", "");
    dataModel.put("headerBanner", "");
    final JSONObject sideAdOption = optionQueryService.getOption(Option.ID_C_SIDE_FULL_AD);
    if (null != sideAdOption) {
        dataModel.put("sideFullAd", sideAdOption.optString(Option.OPTION_VALUE));
    }
    final JSONObject headerBanner = optionQueryService.getOption(Option.ID_C_HEADER_BANNER);
    if (null != headerBanner) {
        dataModel.put("headerBanner", headerBanner.optString(Option.OPTION_VALUE));
    }
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 17 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method showUser.

/**
 * Shows a user.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param userId   the specified user id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/user/{userId}", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showUser(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userId) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/user.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final JSONObject user = userQueryService.getUser(userId);
    Escapes.escapeHTML(user);
    dataModel.put(User.USER, user);
    final JSONObject result = roleQueryService.getRoles(1, Integer.MAX_VALUE, 10);
    final List<JSONObject> roles = (List<JSONObject>) result.opt(Role.ROLES);
    dataModel.put(Role.ROLES, roles);
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 18 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method updateSideAd.

/**
 * Updates side ad.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/ad/side", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateSideAd(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final String sideFullAd = request.getParameter("sideFullAd");
    JSONObject adOption = optionQueryService.getOption(Option.ID_C_SIDE_FULL_AD);
    if (null == adOption) {
        adOption = new JSONObject();
        adOption.put(Keys.OBJECT_ID, Option.ID_C_SIDE_FULL_AD);
        adOption.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_AD);
        adOption.put(Option.OPTION_VALUE, sideFullAd);
        optionMgmtService.addOption(adOption);
    } else {
        adOption.put(Option.OPTION_VALUE, sideFullAd);
        optionMgmtService.updateOption(Option.ID_C_SIDE_FULL_AD, adOption);
    }
    response.sendRedirect(Latkes.getServePath() + "/admin/ad");
}
Also used : JSONObject(org.json.JSONObject) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 19 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method showReservedWord.

/**
 * Shows a reserved word.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @param id       the specified reserved word id
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/reserved-word/{id}", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showReservedWord(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String id) throws Exception {
    final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
    context.setRenderer(renderer);
    renderer.setTemplateName("admin/reserved-word.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    final JSONObject word = optionQueryService.getOption(id);
    dataModel.put(Common.WORD, word);
    dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 20 with Before

use of org.b3log.latke.servlet.annotation.Before in project symphony by b3log.

the class AdminProcessor method addArticle.

/**
 * Adds an article.
 *
 * @param context  the specified context
 * @param request  the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/admin/add-article", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void addArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final String userName = request.getParameter(User.USER_NAME);
    final JSONObject author = userQueryService.getUserByName(userName);
    if (null == author) {
        final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
        context.setRenderer(renderer);
        renderer.setTemplateName("admin/error.ftl");
        final Map<String, Object> dataModel = renderer.getDataModel();
        dataModel.put(Keys.MSG, langPropsService.get("notFoundUserLabel"));
        dataModelService.fillHeaderAndFooter(request, response, dataModel);
        return;
    }
    final String timeStr = request.getParameter(Common.TIME);
    final String articleTitle = request.getParameter(Article.ARTICLE_TITLE);
    final String articleTags = request.getParameter(Article.ARTICLE_TAGS);
    final String articleContent = request.getParameter(Article.ARTICLE_CONTENT);
    String rewardContent = request.getParameter(Article.ARTICLE_REWARD_CONTENT);
    final String rewardPoint = request.getParameter(Article.ARTICLE_REWARD_POINT);
    long time = System.currentTimeMillis();
    try {
        final Date date = DateUtils.parseDate(timeStr, new String[] { "yyyy-MM-dd'T'HH:mm" });
        time = date.getTime();
        final int random = RandomUtils.nextInt(9999);
        time += random;
    } catch (final ParseException e) {
        LOGGER.log(Level.ERROR, "Parse time failed, using current time instead");
    }
    final JSONObject article = new JSONObject();
    article.put(Article.ARTICLE_TITLE, articleTitle);
    article.put(Article.ARTICLE_TAGS, articleTags);
    article.put(Article.ARTICLE_CONTENT, articleContent);
    article.put(Article.ARTICLE_REWARD_CONTENT, rewardContent);
    article.put(Article.ARTICLE_REWARD_POINT, Integer.valueOf(rewardPoint));
    article.put(User.USER_NAME, userName);
    article.put(Common.TIME, time);
    try {
        articleMgmtService.addArticleByAdmin(article);
    } catch (final ServiceException e) {
        final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
        context.setRenderer(renderer);
        renderer.setTemplateName("admin/error.ftl");
        final Map<String, Object> dataModel = renderer.getDataModel();
        dataModel.put(Keys.MSG, e.getMessage());
        dataModelService.fillHeaderAndFooter(request, response, dataModel);
        return;
    }
    response.sendRedirect(Latkes.getServePath() + "/admin/articles");
}
Also used : JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) JSONObject(org.json.JSONObject) ParseException(java.text.ParseException) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) Before(org.b3log.latke.servlet.annotation.Before) After(org.b3log.latke.servlet.annotation.After) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Aggregations

Before (org.b3log.latke.servlet.annotation.Before)169 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)169 JSONObject (org.json.JSONObject)166 After (org.b3log.latke.servlet.annotation.After)135 AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)105 ServiceException (org.b3log.latke.service.ServiceException)37 Date (java.util.Date)13 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 JSONArray (org.json.JSONArray)8 Auth (com.qiniu.util.Auth)7 ParseException (java.text.ParseException)6 List (java.util.List)6 ServletException (javax.servlet.ServletException)3 Configuration (com.qiniu.storage.Configuration)1 UploadManager (com.qiniu.storage.UploadManager)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1