/*
 * Copyright (c) 2010-2017, b3log.org & hacpai.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.b3log.solo.processor.renderer;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer;
import org.b3log.solo.SoloServletListener;

import javax.servlet.ServletContext;
import java.io.IOException;

/**
 * <a href="http://freemarker.org">FreeMarker</a> HTTP response renderer for administrator console and initialization
 * rendering.
 *
 * @author <a href="http://88250.b3log.org">Liang Ding</a>
 * @version 1.0.1.2, Nov 2, 2016
 * @since 0.4.1
 */
public final class ConsoleRenderer extends AbstractFreeMarkerRenderer {

    /**
     * Logger.
     */
    private static final Logger LOGGER = Logger.getLogger(ConsoleRenderer.class.getName());

    /**
     * FreeMarker configuration.
     */
    public static final Configuration TEMPLATE_CFG;

    static {
        TEMPLATE_CFG = new Configuration();
        TEMPLATE_CFG.setDefaultEncoding("UTF-8");

        final ServletContext servletContext = SoloServletListener.getServletContext();

        TEMPLATE_CFG.setServletContextForTemplateLoading(servletContext, "");
        TEMPLATE_CFG.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        TEMPLATE_CFG.setLogTemplateExceptions(false);
    }

    @Override
    protected Template getTemplate(final String templateDirName, final String templateName) {
        try {
            return TEMPLATE_CFG.getTemplate(templateName);
        } catch (final IOException e) {
            return null;
        }
    }

    @Override
    protected void beforeRender(final HTTPRequestContext context) throws Exception {
    }

    @Override
    protected void afterRender(final HTTPRequestContext context) throws Exception {
    }
}

@@ -1284,22 +1284,23 @@
 0.1.
-2, Nov 2
+3, Jul 16
 , 201
-6
+7
 %0A * 
@@ -1404,22 +1404,40 @@
 %0A     * 
-Logger
+FreeMarker configuration
 .%0A     *
@@ -1447,14 +1447,13 @@
    p
-rivate
+ublic
  sta
@@ -1466,115 +1466,58 @@
 nal 
-Logger LOGGER = Logger.getLogger(ConsoleRenderer.class.getName());%0A%0A    /**%0A     * FreeMarker configuration
+Configuration TEMPLATE_CFG;%0A%0A    /**%0A     * Logger
 .%0A  
@@ -1519,37 +1519,38 @@
 r.%0A     */%0A    p
-ublic
+rivate
  static final Co
@@ -1551,34 +1551,63 @@
 nal 
-Configuration TEMPLATE_CFG
+Logger LOGGER = Logger.getLogger(ConsoleRenderer.class)
 ;%0A%0A 
@@ -1659,16 +1659,43 @@
 uration(
+Configuration.VERSION_2_3_0
 );%0A     

Clean code