appinitcontextlistener.java

来自「本平台是以web2.0为基本的标准」· Java 代码 · 共 46 行

JAVA
46
字号
package com.afuer.chat;

import java.io.File;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * This <code>ContextListener</code> is to perform application initialization.
 */
public class AppInitContextListener implements ServletContextListener {
    private static Log log = LogFactory.getLog(ChatConfig.class);

    public void contextInitialized(ServletContextEvent event) {
        try {
            ServletContext context = event.getServletContext();

            ChatConfig.init(context.getRealPath("WEB-INF/elchat.properties"));
            ChatConfig config = ChatConfig.getInstance();

            EmotIcon.init(context.getRealPath("WEB-INF/emoticon.properties"));
            Command.init(context.getRealPath("WEB-INF/command.properties"));

            String persistFile = config.getMessagePath() + config.getId().replaceAll("[\\s|\\.\\/]", "_")
                    + "_messages.xml";
            if (!new File(config.getMessagePath()).exists()) {
                persistFile = context.getRealPath("WEB-INF/messages.xml");
            }
            Chat.init(persistFile);
        }
        catch (Exception ex) {
            ex.printStackTrace();
            log.fatal("Exception in AppInitContextListener", ex);
        }
    }

    public void contextDestroyed(ServletContextEvent event) {
        ;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?