⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 presenthandler.java~4~

📁 java系统通用框架 很实用的东东 一般人都看的懂,
💻 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 + -