Package org.b3log.latke.servlet.renderer

Examples of org.b3log.latke.servlet.renderer.JSONRenderer


     * @param context the specified context
     */
    @RequestProcessing(value = "/reset", method = HTTPRequestMethod.POST)
    public void reset(final HTTPRequestContext context) {
        final HttpServletRequest request = context.getRequest();
        final JSONRenderer renderer = new JSONRenderer();

        context.setRenderer(renderer);
        final JSONObject jsonObject = new JSONObject();

        renderer.setJSONObject(jsonObject);

        try {
            final JSONObject requestJSONObject;

            requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
View Full Code Here


        if (!userUtils.isAdminLoggedIn(request)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        final JSONRenderer renderer = new JSONRenderer();
        context.setRenderer(renderer);

        final JSONObject ret = new JSONObject();
        renderer.setJSONObject(ret);

        LOGGER.log(Level.INFO, "Cache status[cachedBytes={0}, cachedCount={1}]",
                   new Object[]{PageCaches.getCache().getCachedBytes(), PageCaches.getCache().getCachedCount()});

        try {
            final JSONObject preference = preferenceQueryService.getPreference();
            final boolean pageCacheEnabled = preference.getBoolean(Preference.PAGE_CACHE_ENABLED);
            ret.put(Preference.PAGE_CACHE_ENABLED, pageCacheEnabled);

            ret.put(Common.PAGE_CACHED_CNT, PageCaches.getKeys().size());

            ret.put(Keys.STATUS_CODE, true);

        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);

            final JSONObject jsonObject = QueryResults.defaultResult();
            renderer.setJSONObject(jsonObject);
            jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage());
        }
    }
View Full Code Here

        if (!userUtils.isLoggedIn(request, response)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        final JSONRenderer renderer = new JSONRenderer();
        context.setRenderer(renderer);

        final JSONObject ret = new JSONObject();
        renderer.setJSONObject(ret);

        try {
            final String requestURI = request.getRequestURI();
            final String path = requestURI.substring("/console/plugins/admin-cache/pages/".length());

            final JSONObject requestJSONObject = Requests.buildPaginationRequest(path);

            final int currentPageNum = requestJSONObject.getInt(Pagination.PAGINATION_CURRENT_PAGE_NUM);
            final int pageSize = requestJSONObject.getInt(Pagination.PAGINATION_PAGE_SIZE);
            final int windowSize = requestJSONObject.getInt(Pagination.PAGINATION_WINDOW_SIZE);

            List<String> keys = new ArrayList<String>(PageCaches.getKeys());
            // Paginates
            final int pageCount =
                    (int) Math.ceil((double) keys.size() / (double) pageSize);
            final JSONObject pagination = new JSONObject();
            ret.put(Pagination.PAGINATION, pagination);
            final List<Integer> pageNums = Paginator.paginate(currentPageNum, pageSize, pageCount, windowSize);
            pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
            pagination.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);

            final int start = pageSize * (currentPageNum - 1);
            int end = start + pageSize;
            end = end > keys.size() ? keys.size() : end;

            keys = keys.subList(start, end);

            // Retrives cached pages
            final List<JSONObject> pages = new ArrayList<JSONObject>();
            for (final String key : keys) {
                LOGGER.log(Level.FINER, "Cached page[key={0}]", key);

                JSONObject cachedPage = PageCaches.get(key);

                if (null != cachedPage) {
                    // Do a copy for properties removing and retrieving
                    cachedPage = new JSONObject(cachedPage,
                                                JSONObject.getNames(cachedPage));
                    cachedPage.remove(CACHED_CONTENT);
                    pages.add(cachedPage);
                }
            }

            ret.put(Page.PAGES, pages);

            ret.put(Keys.STATUS_CODE, true);
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);

            final JSONObject jsonObject = QueryResults.defaultResult();
            renderer.setJSONObject(jsonObject);
            jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage());
        }
    }
View Full Code Here

            response.sendError(HttpServletResponse.SC_FORBIDDEN);

            return;
        }

        final JSONRenderer renderer = new JSONRenderer();
        context.setRenderer(renderer);

        final JSONObject ret = new JSONObject();
        renderer.setJSONObject(ret);

        try {
            final String path = request.getRequestURI().substring(
                    (Latkes.getContextPath() + "/console/plugins/admin-cache/enable/").length());

            final boolean pageCacheEnabled = "true".equals(path) ? true : false;

            final JSONObject preference = preferenceQueryService.getPreference();
            preference.put(Preference.PAGE_CACHE_ENABLED, pageCacheEnabled);

            preferenceMgmtService.updatePreference(preference);

            ret.put(Keys.STATUS_CODE, true);
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, "Sets page cache error: {0}", e.getMessage());

            final JSONObject jsonObject = QueryResults.defaultResult();
            renderer.setJSONObject(jsonObject);
            jsonObject.put(Keys.MSG, "Admin Cache plugin exception: " + e.getMessage());
        }
    }
View Full Code Here

            response.sendRedirect("/");

            return;
        }

        final JSONRenderer renderer = new JSONRenderer();

        context.setRenderer(renderer);

        final JSONObject ret = QueryResults.defaultResult();

        renderer.setJSONObject(ret);

        try {
            final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);

            final String userName = requestJSONObject.optString(User.USER_NAME);
View Full Code Here

        if (!userQueryService.isLoggedIn(request, response)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        final JSONRenderer renderer = new JSONRenderer();

        context.setRenderer(renderer);

        final JSONObject ret = new JSONObject();

        renderer.setJSONObject(ret);

        try {
            final String commentId = request.getRequestURI().substring((Latkes.getContextPath() + "/console/page/comment/").length());

            if (!commentQueryService.canAccessComment(commentId, request)) {
View Full Code Here

        if (!userQueryService.isLoggedIn(request, response)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        final JSONRenderer renderer = new JSONRenderer();

        context.setRenderer(renderer);

        final JSONObject ret = new JSONObject();

        renderer.setJSONObject(ret);

        try {
            final String commentId = request.getRequestURI().substring((Latkes.getContextPath() + "/console/article/comment/").length());

            if (!commentQueryService.canAccessComment(commentId, request)) {
View Full Code Here

        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 path = requestURI.substring((Latkes.getContextPath() + "/console/comments/").length());

            final JSONObject requestJSONObject = Requests.buildPaginationRequest(path);

            final JSONObject result = commentQueryService.getComments(requestJSONObject);

            result.put(Keys.STATUS_CODE, true);

            renderer.setJSONObject(result);
        } 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"));
        }
    }
View Full Code Here

        if (!userQueryService.isLoggedIn(request, response)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        final JSONRenderer renderer = new JSONRenderer();

        context.setRenderer(renderer);

        try {
            final JSONObject ret = new JSONObject();

            renderer.setJSONObject(ret);

            final String requestURI = request.getRequestURI();
            final String articleId = requestURI.substring((Latkes.getContextPath() + "/console/comments/article/").length());

            final List<JSONObject> comments = commentQueryService.getComments(articleId);

            ret.put(Comment.COMMENTS, comments);
            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"));
        }
    }
View Full Code Here

        if (!userQueryService.isLoggedIn(request, response)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        final JSONRenderer renderer = new JSONRenderer();

        context.setRenderer(renderer);

        try {
            final JSONObject ret = new JSONObject();

            renderer.setJSONObject(ret);

            final String requestURI = request.getRequestURI();
            final String pageId = requestURI.substring((Latkes.getContextPath() + "/console/comments/page/").length());

            final List<JSONObject> comments = commentQueryService.getComments(pageId);

            ret.put(Comment.COMMENTS, comments);
            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"));
        }
    }
View Full Code Here

TOP

Related Classes of org.b3log.latke.servlet.renderer.JSONRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.