📄 resengine.java
字号:
/*
* Created on 2005-08-08
*
* @author WuQiaoYun
*/
package com.cis.manage;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.BaseEngine;
import org.apache.tapestry.request.RequestContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.common.util.LruCache;
import com.common.util.PropertyLoader;
import com.common.util.ResCache;
/**
* 自定义引擎类,服务于Tapestry
* @author WuQiaoYun
*/
public class ResEngine extends BaseEngine {
/**
* 装载系统缺省语言设置
*/
public Locale getLocale() {
//iLocale= iLocale +1;
//System.out.println("Engine getLocale() 执行第【" + iLocale +"】次");
Locale locale=null;
try{
String defaultLanguage=PropertyLoader.getPptValue(Constants.DEFAULT_LANGUAGE_FILENAME, "resource_DefaultLanguage");
String defaultCountry=PropertyLoader.getPptValue(Constants.DEFAULT_LANGUAGE_FILENAME, "resource_DefaultCountry");
//System.out.println("--------ResEngine-------language----------=="+defaultLanguage);
//System.out.println("--------ResEngine-------defaultCountry----------=="+defaultCountry);
if (defaultLanguage!=null && !"".equals(defaultLanguage)){
if (defaultCountry!=null && !"".equals(defaultCountry)){
locale= new Locale(defaultLanguage,defaultCountry);
}
else{
locale=new Locale(defaultLanguage);
}
}
}
catch (Exception e){
e.printStackTrace();
}
if (locale==null) locale=super.getLocale();
return locale;
}
// private static int iLocale = 0;
//
// private static int iRequest = 0;
//
// private static boolean bStartAutoStatThread = false;
//
// private static int iStartAutoStatThread = 0;
//装载日志信息
private static final Log log = LogFactory.getLog(ResEngine.class);
/**
* APPLICATION_CONTEXT_KEY对应的Map中Key
*/
public static final String APPLICATION_CONTEXT_KEY = "appContext";
//是否清除Session
private transient boolean killSession;
//private transient IComponentMessagesSource messagesSource;
/**
* 缺省构造器
*/
public ResEngine() {
//log.info("Create a ResEngine Engine Instance.");
}
/**
* 通过Spring提供的WebApplicationContextUtils, 将ApplicationContext放置到Tapestry中。
*/
protected void setupForRequest(RequestContext context) {
super.setupForRequest(context);
//返回Global对象
Map global = (Map) getGlobal();
//先通过Global获得ApplicationContext,若为空,则用WebApplicationContextUtils装载
ApplicationContext ac = (ApplicationContext) global
.get(APPLICATION_CONTEXT_KEY);
// iRequest = iRequest +1;
// System.out.println("Engine setupForRequest() 执行第【" + iRequest +"】次");
if (ac == null) {
//用WebApplicationContextUtils装载ApplicationContext至TapeStry框架中
ac = WebApplicationContextUtils.getWebApplicationContext(context
.getServlet().getServletContext());
//保存至Global全局对象中
global.put(APPLICATION_CONTEXT_KEY, ac);
}
// if (!bStartAutoStatThread) {
// iStartAutoStatThread++;
// DataSource ds = (DataSource) ac.getBean("dataSource");
// new ThreadAutoStatPerDay(ds);
//
// System.out.println("成功启动线程!第【" + iStartAutoStatThread +"】次");
// bStartAutoStatThread = true;
// }
//每次请求时重新将用户对象传递至spring容器中的shopServiceTarget Bean对象, 供方法拦截器使用
/*ISecurityManager smi=((ISecurityManager)ac.getBean("securityServiceTarget"));
Visit visit = (Visit) getVisit();
if (visit!=null && visit.getUserInfoVO()!=null)
smi.setUserInfoVO(visit.getUserInfoVO());*/
//获取客户端信息
this.getClientInfo(context.getRequest());
}
/**
* 注销session,完成页面清理工作
*/
protected void cleanupAfterRequest(IRequestCycle cycle) {
super.cleanupAfterRequest(cycle);
// System.out.println("--------ResEngine--cleanupAfterRequest-----killSession----------"+killSession);
if (killSession) {
try {
HttpSession session = cycle.getRequestContext().getSession();
// System.out.println("--------ResEngine--cleanupAfterRequest-----session----------"+session);
if (session != null) {
session.invalidate();
}
} catch (IllegalStateException ex) {
}
}
}
/**
* 设置visit对象属性为空, 并且设置相关的标记无效。
* 退出系统,清空用户信息和授权信息
*/
public void logout()
{
//System.out.println("--------ResEngine---logout--------------");
Visit visit = (Visit) getVisit();
LruCache lc =ResCache.getCacheInstance();
if (visit != null){
//lc.remove(visit.getUserInfoVO());
//visit.setUserInfoVO(null);
visit.setUserCode(null);
visit.setPassWord(null);
//ResCurrentUser.set(null);
}
killSession = true;
}
/**
* 获得程序错误,页面链接错误等异常页面
*/
/* public String getExceptionPageName() {
return "ApplicationException";
}
*//**
* 捕获程序错误,页面链接错误异常
*//*
public void activateExceptionPage(IRequestCycle cycle,
ResponseOutputStream output, Throwable cause)
throws ServletException {
try {
IPage exceptionPage = cycle.getPage(getExceptionPageName());
System.out.println("-------exceptionPage----------"+cause);
cycle.activate(exceptionPage);
renderResponse(cycle, output);
} catch (Throwable ex) {
}
}
*/
/**
* 获得Session过期异常页面
*/
public String getStaleSessionPageName() { return "SessionException"; }
/**
* 获得staleLinkException异常页面
*/
public String getStaleLinkPageName() { return "StaleException"; }
/**
* 捕获staleLinkException异常
*/
/* public void handleStaleLinkException(StaleLinkException ex, IRequestCycle
cycle, ResponseOutputStream output) throws IOException, ServletException
{
String staleLinkPageName = getStaleLinkPageName();
IPage page =cycle.getPage(staleLinkPageName);
System.out.println("%%%handleStaleLinkException(ex.getMessage() = " + ex.getMessage() + ")");
redirect(staleLinkPageName, cycle, output, ex);
}
*/
/**
* 获取客户端的信息,如客户机的名称,IP地址等
* @param req 当前HttpServletRequest对象
*/
private void getClientInfo(HttpServletRequest req){
/*LruCache lruCache = ResCache.getCacheInstance();
Visit visit = (Visit)getVisit();
if (visit!=null && visit.getUserInfoVO()!=null){
AuthorizedInfoVO aivo = (AuthorizedInfoVO)lruCache.get(visit.getUserInfoVO());
if(aivo!=null){
ClientInfoVO cvo = new ClientInfoVO();
cvo.setComputerName(req.getLocalName());
cvo.setIPAddress(req.getLocalAddr());
aivo.setClientInfoVO(cvo);
//将客户端信息保存在缓存
lruCache.put(visit.getUserInfoVO(),aivo);
}
}*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -