?? presenthandler.java~4~
字號:
/*****************************************************************************
* (C) Copyright 2004 。
* 保留對所有使用、復制、修改和發布整個軟件和相關文檔的權利。
* 本計算機程序受著作權法和國際公約的保護,未經授權擅自復制或
* 傳播本程序的全部或部分,可能受到嚴厲的民事和刑事制裁,并
* 在法律允許的范圍內受到最大可能的起訴。
*/
/*****************************************************************************
* @作者:Golden Peng
* @版本: 1.0
* @時間: 2002-10-08
*/
/*****************************************************************************
* 修改記錄清單
* 修改人 :
* 修改記錄:
* 修改時間:
* 修改描述:
*
*/
package com.corp.bisc.ebiz.base;
/**
* 此處插入類型描述。
* 創建日期:(2002-5-15 10:00:48)
* @author:Administrator
*/
import java.util.*;
import org.w3c.dom.*;
import com.corp.bisc.ebiz.exception.*;
import javax.servlet.http.*;
import com.corp.bisc.ebiz.util.XMLUtil;
public class PresentHandler extends ObjectBase
{
final static public int HANDLER_TYPE_CODE = 1;
final static public int HANDLER_TYPE_EXP = 2;
final static public String HANDLER_TAG_CODE = "code";
final static public String HANDLER_TAG_EXP = "exception";
final static public int METHOD_TYPE_FORWARD = 1;
final static public int METHOD_TYPE_REDIRECT = 2;
final static public int METHOD_TYPE_INCLUDE = 3;
final static public int METHOD_TYPE_DOWNLOAD = 4;
final static public String HANDLER_DEF_ID = "*";
protected String handlerId;
protected int handlerType = HANDLER_TYPE_CODE | HANDLER_TYPE_EXP;
protected String handler;
protected int methodType = METHOD_TYPE_FORWARD;
/**
* PresentHandler 構造子注解。
*/
public PresentHandler()
{
super();
}
public String getHandlerId()
{
return handlerId;
}
public void init(Node cfgNode , String defaultPkg) throws InvalidConfigException
{
enter("init(Node)");
NamedNodeMap attribs = cfgNode.getAttributes();
Node idNode = attribs.getNamedItem("id");
Node methodNode = attribs.getNamedItem("method");
Node typeNode = attribs.getNamedItem("idtype");
Node handlerNode = attribs.getNamedItem("handler");
if (idNode == null)
throw new InvalidConfigException("PresentManager/PresentHandler/@id");
else
handlerId = idNode.getNodeValue();
if (handlerNode != null)
handler = handlerNode.getNodeValue();
if (methodNode != null)
{
String methodTypeText = methodNode.getNodeValue();
if (methodTypeText.equals("forward"))
{
methodType = METHOD_TYPE_FORWARD;
}
else if (methodTypeText.equals("redirect"))
{
methodType = METHOD_TYPE_REDIRECT;
}
else if (methodTypeText.equalsIgnoreCase("include"))
{
methodType = METHOD_TYPE_INCLUDE;
}
else if (methodTypeText.equalsIgnoreCase("download"))
{
methodType = METHOD_TYPE_DOWNLOAD;
}
else
{
throw new InvalidConfigException("PresentManager/PresentHandler/[@method=" + methodTypeText + "]");
}
}
if (typeNode != null)
{
String typeText = typeNode.getNodeValue();
if (typeText.equals(HANDLER_TAG_CODE))
{
handlerType = HANDLER_TYPE_CODE;
}
else if (typeText.equals(HANDLER_TAG_EXP))
{
handlerType = HANDLER_TYPE_EXP;
}
else
{
throw new InvalidConfigException("PresentManager/PresentHandler/[@idtype=" + typeText + "]");
}
}
if ((handlerType & HANDLER_TYPE_EXP) > 0 && !handlerId.equals(HANDLER_DEF_ID))
{
int index = handlerId.indexOf('.');
if (index == -1)
handlerId = defaultPkg + '.' + handlerId;
try
{
Class.forName(handlerId);
}
catch(ClassNotFoundException e)
{
throw new InvalidConfigException("PresentManager/PresentHandler/[@id=" + handlerId + ']');
}
}
leave("init(Node)");
}
public boolean isDefault()
{
return handlerId.equals(HANDLER_DEF_ID);
}
public void present(RequestContext context , ConfigRepository confRepository)
{
enter("present(RequestContext , ConfigRespository)");
// Don't output any data to the response if no handler is configured
if (handler == null || handler.length() == 0)
{
leave("present(RequestContext , ConfigRespository)");
return;
}
// Get the language preference from the request
String lang = context.getLanguage();
// get the language prefix according to language preference
LangConfig conf = confRepository.getLangManager().getLangConfig(lang);
String urlPath = handler;
if (conf != null)
urlPath = conf.getDirectory() + handler;
System.out.println("urlPath :" + urlPath);
// if it is jsp page , forward it; or redirect it if it is static page
HttpServletRequest req = context.getRequest();
HttpServletResponse res = context.getResponse();
try
{
switch (methodType){
case METHOD_TYPE_FORWARD:
{
req.getRequestDispatcher(urlPath).forward(req , res);
}
break;
case METHOD_TYPE_REDIRECT:
context.getResponse().sendRedirect(urlPath);
break;
case METHOD_TYPE_INCLUDE:
req.getRequestDispatcher(urlPath).include(req , res);
break;
case METHOD_TYPE_DOWNLOAD:
break;
}
}
catch(Exception e)
{
if (isErrorEnabled())
{
error("Can't not dispacth the url [" + urlPath + "]:" , e);
}
}
leave("present(RequestContext , ConfigRespository)");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -