package com.zuoxiaolong.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import com.zuoxiaolong.config.Configuration;
import com.zuoxiaolong.thread.BaiduPushTask;
import com.zuoxiaolong.thread.Executor;
import com.zuoxiaolong.thread.FetchTask;

/*
 * Copyright 2002-2015 the original author or authors.
 *
 * 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.
 */

/**
 * @author 左潇龙
 * @since 5/7/2015 3:33 PM
 */
public class ConfigurationListener implements ServletContextListener {
	
	private static final Logger logger = Logger.getLogger(ConfigurationListener.class);

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
    	if (logger.isInfoEnabled()) {
			logger.info("will begin init configuration...");
		}
        Configuration.init(servletContextEvent.getServletContext());
        if (logger.isInfoEnabled()) {
			logger.info("init configuration success...");
		}
        if (logger.isInfoEnabled()) {
			logger.info("starting fetch and generate thread...");
		}
        Executor.executeTask(new FetchTask());
        if (logger.isInfoEnabled()) {
			logger.info("fetch and generate thread has been started...");
		}
        if (logger.isInfoEnabled()) {
			logger.info("starting baidu push thread...");
		}
        Executor.executeTask(new BaiduPushTask());
        if (logger.isInfoEnabled()) {
			logger.info("baidu push thread has been started...");
		}
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
    }

}

@@ -39,121 +39,45 @@
 ort 
-javax.servlet.ServletContextEvent;%0Aimport javax.servlet.ServletContextListener;%0A%0Aimport org.apache.log4j.Logger;%0A
+com.zuoxiaolong.config.Configuration;
 %0Aimp
@@ -96,36 +96,37 @@
 iaolong.
-config.Configuration
+freemarker.Generators
 ;%0Aimport
@@ -244,16 +244,175 @@
 tchTask;
+%0Aimport com.zuoxiaolong.util.ImageUtil;%0Aimport org.apache.log4j.Logger;%0A%0Aimport javax.servlet.ServletContextEvent;%0Aimport javax.servlet.ServletContextListener;
 %0A%0A/*%0A * 
@@ -1571,32 +1571,176 @@
 ccess...%22);%0A%09%09%7D%0A
+        if (!Configuration.isProductEnv()) %7B%0A            ImageUtil.loadArticleImages();%0A            Generators.generate();%0A        %7D else %7B%0A    
         if (logg
@@ -1753,35 +1753,48 @@
 nfoEnabled()) %7B%0A
-%09%09%09
+                
 logger.info(%22sta
@@ -1823,36 +1823,50 @@
 te thread...%22);%0A
-%09%09%7D%0A
+            %7D%0A    
         Executor
@@ -1896,32 +1896,36 @@
 ask());%0A        
+    
 if (logger.isInf
@@ -1930,35 +1930,48 @@
 nfoEnabled()) %7B%0A
-%09%09%09
+                
 logger.info(%22fet
@@ -2008,36 +2008,50 @@
 n started...%22);%0A
-%09%09%7D%0A
+            %7D%0A    
         if (logg
@@ -2064,35 +2064,48 @@
 nfoEnabled()) %7B%0A
-%09%09%09
+                
 logger.info(%22sta
@@ -2130,28 +2130,42 @@
 hread...%22);%0A
-%09%09%7D%0A
+            %7D%0A    
         Exec
@@ -2203,32 +2203,36 @@
 ask());%0A        
+    
 if (logger.isInf
@@ -2237,35 +2237,48 @@
 nfoEnabled()) %7B%0A
-%09%09%09
+                
 logger.info(%22bai
@@ -2311,26 +2311,46 @@
 arted...%22);%0A
-%09%09
+            %7D%0A        
 %7D%0A    %7D%0A%0A   

develop env don't fetch articles.