Search in sources :

Example 1 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class ErrorProcessor method showErrorPage.

/**
     * Shows the user template page.
     *
     * @param context the specified context
     * @param request the specified HTTP servlet request
     * @param response the specified HTTP servlet response
     * @throws IOException io exception
     */
@RequestProcessing(value = "/error/*.html", method = HTTPRequestMethod.GET)
public void showErrorPage(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    final String requestURI = request.getRequestURI();
    String templateName = StringUtils.substringAfterLast(requestURI, "/");
    templateName = StringUtils.substringBefore(templateName, ".") + ".ftl";
    LOGGER.log(Level.DEBUG, "Shows error page[requestURI={0}, templateName={1}]", new Object[] { requestURI, templateName });
    final ConsoleRenderer renderer = new ConsoleRenderer();
    context.setRenderer(renderer);
    renderer.setTemplateName("error/" + templateName);
    final Map<String, Object> dataModel = renderer.getDataModel();
    try {
        final Map<String, String> langs = langPropsService.getAll(Locales.getLocale(request));
        dataModel.putAll(langs);
        final JSONObject preference = preferenceQueryService.getPreference();
        filler.fillBlogHeader(request, response, dataModel, preference);
        filler.fillBlogFooter(request, dataModel, preference);
        dataModel.put(Common.LOGIN_URL, userService.createLoginURL(Common.ADMIN_INDEX_URI));
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, e.getMessage(), e);
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } catch (final IOException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) IOException(java.io.IOException) IOException(java.io.IOException) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 2 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class AdminConsole method showAdminPreferenceFunction.

/**
     * Shows administrator preference function with the specified context.
     *
     * @param request the specified request
     * @param context the specified context
     */
@RequestProcessing(value = "/admin-preference.do", method = HTTPRequestMethod.GET)
public void showAdminPreferenceFunction(final HttpServletRequest request, final HTTPRequestContext context) {
    final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
    context.setRenderer(renderer);
    final String templateName = "admin-preference.ftl";
    renderer.setTemplateName(templateName);
    final Locale locale = Latkes.getLocale();
    final Map<String, String> langs = langPropsService.getAll(locale);
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModel.putAll(langs);
    dataModel.put(Option.ID_C_LOCALE_STRING, locale.toString());
    JSONObject preference = null;
    try {
        preference = preferenceQueryService.getPreference();
    } catch (final ServiceException e) {
        LOGGER.log(Level.ERROR, "Loads preference failed", e);
    }
    final StringBuilder timeZoneIdOptions = new StringBuilder();
    final String[] availableIDs = TimeZone.getAvailableIDs();
    for (int i = 0; i < availableIDs.length; i++) {
        final String id = availableIDs[i];
        String option;
        if (id.equals(preference.optString(Option.ID_C_TIME_ZONE_ID))) {
            option = "<option value=\"" + id + "\" selected=\"true\">" + id + "</option>";
        } else {
            option = "<option value=\"" + id + "\">" + id + "</option>";
        }
        timeZoneIdOptions.append(option);
    }
    dataModel.put("timeZoneIdOptions", timeZoneIdOptions.toString());
    fireFreeMarkerActionEvent(templateName, dataModel);
}
Also used : Locale(java.util.Locale) JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 3 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class AdminConsole method showAdminIndex.

/**
     * Shows administrator index with the specified context.
     *
     * @param request the specified request
     * @param context the specified context
     */
@RequestProcessing(value = "/admin-index.do", method = HTTPRequestMethod.GET)
public void showAdminIndex(final HttpServletRequest request, final HTTPRequestContext context) {
    final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
    context.setRenderer(renderer);
    final String templateName = "admin-index.ftl";
    renderer.setTemplateName(templateName);
    final Map<String, String> langs = langPropsService.getAll(Latkes.getLocale());
    final Map<String, Object> dataModel = renderer.getDataModel();
    dataModel.putAll(langs);
    final JSONObject currentUser = userQueryService.getCurrentUser(request);
    final String userName = currentUser.optString(User.USER_NAME);
    dataModel.put(User.USER_NAME, userName);
    final String roleName = currentUser.optString(User.USER_ROLE);
    dataModel.put(User.USER_ROLE, roleName);
    final String email = currentUser.optString(User.USER_EMAIL);
    final String userAvatar = currentUser.optString(UserExt.USER_AVATAR);
    if (!Strings.isEmptyOrNull(userAvatar)) {
        dataModel.put(Common.GRAVATAR, userAvatar);
    } else {
        final String gravatar = Thumbnails.getGravatarURL(email, "128");
        dataModel.put(Common.GRAVATAR, gravatar);
    }
    try {
        final JSONObject qiniu = optionQueryService.getOptions(Option.CATEGORY_C_QINIU);
        dataModel.put(Option.ID_C_QINIU_DOMAIN, "");
        dataModel.put("qiniuUploadToken", "");
        if (null != qiniu && StringUtils.isNotBlank(qiniu.optString(Option.ID_C_QINIU_ACCESS_KEY)) && StringUtils.isNotBlank(qiniu.optString(Option.ID_C_QINIU_SECRET_KEY)) && StringUtils.isNotBlank(qiniu.optString(Option.ID_C_QINIU_BUCKET)) && StringUtils.isNotBlank(qiniu.optString(Option.ID_C_QINIU_DOMAIN))) {
            try {
                final Auth auth = Auth.create(qiniu.optString(Option.ID_C_QINIU_ACCESS_KEY), qiniu.optString(Option.ID_C_QINIU_SECRET_KEY));
                final String uploadToken = auth.uploadToken(qiniu.optString(Option.ID_C_QINIU_BUCKET), null, 3600 * 6, null);
                dataModel.put("qiniuUploadToken", uploadToken);
                dataModel.put(Option.ID_C_QINIU_DOMAIN, qiniu.optString(Option.ID_C_QINIU_DOMAIN));
            } catch (final Exception e) {
                LOGGER.log(Level.ERROR, "Qiniu settings error", e);
            }
        }
        final JSONObject preference = preferenceQueryService.getPreference();
        dataModel.put(Option.ID_C_LOCALE_STRING, preference.getString(Option.ID_C_LOCALE_STRING));
        dataModel.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
        dataModel.put(Option.ID_C_BLOG_SUBTITLE, preference.getString(Option.ID_C_BLOG_SUBTITLE));
        dataModel.put(Common.VERSION, SoloServletListener.VERSION);
        dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
        dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
        dataModel.put(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT, preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT));
        dataModel.put(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE, preference.getInt(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE));
        dataModel.put(Option.ID_C_LOCALE_STRING, preference.getString(Option.ID_C_LOCALE_STRING));
        dataModel.put(Option.ID_C_EDITOR_TYPE, preference.getString(Option.ID_C_EDITOR_TYPE));
        dataModel.put(Skin.SKIN_DIR_NAME, preference.getString(Skin.SKIN_DIR_NAME));
        Keys.fillRuntime(dataModel);
        filler.fillMinified(dataModel);
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, "Admin index render failed", e);
    }
    fireFreeMarkerActionEvent(templateName, dataModel);
}
Also used : JSONObject(org.json.JSONObject) Auth(com.qiniu.util.Auth) JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) EventException(org.b3log.latke.event.EventException) ServiceException(org.b3log.latke.service.ServiceException) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 4 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class IndexProcessor method register.

/**
     * Show register page.
     *
     * @param context the specified context
     * @param request the specified HTTP servlet request
     * @param response the specified HTTP servlet response
     */
@RequestProcessing(value = "/register", method = HTTPRequestMethod.GET)
public void register(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) {
    final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
    context.setRenderer(renderer);
    renderer.setTemplateName("register.ftl");
    final Map<String, Object> dataModel = renderer.getDataModel();
    try {
        final Map<String, String> langs = langPropsService.getAll(Locales.getLocale(request));
        dataModel.putAll(langs);
        final JSONObject preference = preferenceQueryService.getPreference();
        filler.fillBlogFooter(request, dataModel, preference);
        filler.fillMinified(dataModel);
    } catch (final ServiceException e) {
        LOGGER.log(Level.ERROR, e.getMessage(), e);
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } catch (final IOException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
}
Also used : JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) IOException(java.io.IOException) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Example 5 with ConsoleRenderer

use of org.b3log.solo.processor.renderer.ConsoleRenderer in project solo by b3log.

the class InitProcessor method showInit.

/**
     * Shows initialization page.
     *
     * @param context the specified http request context
     * @param request the specified http servlet request
     * @param response the specified http servlet response
     * @throws Exception exception
     */
@RequestProcessing(value = "/init", method = HTTPRequestMethod.GET)
public void showInit(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    if (initService.isInited()) {
        response.sendRedirect("/");
        return;
    }
    final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
    renderer.setTemplateName("init.ftl");
    context.setRenderer(renderer);
    final Map<String, Object> dataModel = renderer.getDataModel();
    final Map<String, String> langs = langPropsService.getAll(Locales.getLocale(request));
    dataModel.putAll(langs);
    dataModel.put(Common.VERSION, SoloServletListener.VERSION);
    dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
    dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
    Keys.fillRuntime(dataModel);
    filler.fillMinified(dataModel);
}
Also used : JSONObject(org.json.JSONObject) ConsoleRenderer(org.b3log.solo.processor.renderer.ConsoleRenderer) AbstractFreeMarkerRenderer(org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer) RequestProcessing(org.b3log.latke.servlet.annotation.RequestProcessing)

Aggregations

ConsoleRenderer (org.b3log.solo.processor.renderer.ConsoleRenderer)8 JSONObject (org.json.JSONObject)8 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)7 AbstractFreeMarkerRenderer (org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer)7 ServiceException (org.b3log.latke.service.ServiceException)3 IOException (java.io.IOException)2 Locale (java.util.Locale)2 Auth (com.qiniu.util.Auth)1 EventException (org.b3log.latke.event.EventException)1