亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? velocitycontroller.java

?? 這是我自己開發的一個MVC框架
?? JAVA
字號:
package dark.web.frame.velocity.controller;

/**
 * <p>Title:            支持Velocity的控制器</p>
 * <p>Description:      根據org.apache.velocity.servlet.VelocityViewServlet進行修改,
 * 						從而將Velocity整合進dwf框架</p>
 * <p>Copyright:        Copyright (c) 2005</p>
 * <p>Company:          DIS</p>
 * <p>Create Time:      2005-2-28 16:24:43</p>
 * @author             <a href="mailto:dark_he@hotmail.com">darkhe</a>
 * @version            1.0
 */

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dark.web.frame.Controller;
import dark.web.frame.Helper;
import dark.web.frame.controller.FrontController;
import dark.web.frame.velocity.command.VelocityCommand;
import dark.web.frame.velocity.form.VelocityForm;
import dark.web.frame.velocity.page.UnknownVelocityPage;
import dark.web.frame.velocity.page.VelocityPage;

import org.apache.velocity.app.Velocity;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeSingleton;
import org.apache.velocity.tools.view.ToolboxManager;
import org.apache.velocity.tools.view.servlet.ServletLogger;
import org.apache.velocity.tools.view.servlet.ServletToolboxManager;
import org.apache.velocity.tools.view.servlet.WebappLoader;

public abstract class VelocityController
	extends FrontController
	implements Controller
{
	/** The HTTP content type context key. */
	public static final String CONTENT_TYPE = "default.contentType";

	/** The default content type for the response */
	public static final String DEFAULT_CONTENT_TYPE = "text/html";
  
	/** Default encoding for the output stream */
	public static final String DEFAULT_OUTPUT_ENCODING = "ISO-8859-1";

	/**
	 * Key used to access the ServletContext in 
	 * the Velocity application attributes.
	 */
	public static final String SERVLET_CONTEXT_KEY = 
		ServletContext.class.getName();


	/**
	 * Key used to access the toolbox configuration file path from the
	 * Servlet or webapp init parameters ("org.apache.velocity.toolbox").
	 */
	protected static final String TOOLBOX_KEY = 
		"toolbox";

	/**
	 * This is the string that is looked for when getInitParameter is
	 * called ("org.apache.velocity.properties").
	 */
	protected static final String INIT_PROPS_KEY =
		"velocity";

	/** A reference to the toolbox manager. */
	protected ToolboxManager toolboxManager = null;


	/**
	 * The default content type.  When necessary, includes the
	 * character set to use when encoding textual output.
	 */
	protected String defaultContentType;
	

	/**
	 * <p>Initializes servlet, toolbox and Velocity template engine.
	 * Called by the servlet container on loading.</p>
	 *
	 * @param config servlet configuation
	 */
	public void init(ServletConfig config) throws ServletException
	{
		super.init(config);

		// do whatever we have to do to init Velocity
		initVelocity(config);

		// init this servlet's toolbox (if any)
		initToolbox(config);

		// we can get these now that velocity is initialized
		defaultContentType = 
			RuntimeSingleton.getString(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);

		String encoding = 
			RuntimeSingleton.getString(RuntimeSingleton.OUTPUT_ENCODING,
									   DEFAULT_OUTPUT_ENCODING);

		// For non Latin-1 encodings, ensure that the charset is
		// included in the Content-Type header.
		if (!DEFAULT_OUTPUT_ENCODING.equalsIgnoreCase(encoding))
		{
			int index = defaultContentType.lastIndexOf("charset");
			if (index < 0)
			{
				// the charset specifier is not yet present in header.
				// append character encoding to default content-type
				defaultContentType += "; charset=" + encoding;
			}
			else
			{
				// The user may have configuration issues.
				Velocity.warn("VelocityController: Charset was already " +
							  "specified in the Content-Type property.  " +
							  "Output encoding property will be ignored.");
			}
		}

		Velocity.info("VelocityController: Default content-type is: " + 
					  defaultContentType);
	}


	/**
	 * Initializes the ServletToolboxManager for this servlet's
	 * toolbox (if any).
	 *
	 * @param config servlet configuation
	 */
	protected void initToolbox(ServletConfig config) throws ServletException
	{
		ServletContext servletContext = config.getServletContext();

		/* check the servlet config for a toolbox */
		String file = config.getInitParameter(TOOLBOX_KEY);

		/* check the servlet context for a toolbox */
		if (file == null || file.length() == 0) 
		{
			file = servletContext.getInitParameter(TOOLBOX_KEY);
		}

		/* if we have a toolbox, get a manager for it */
		if (file != null)
		{
			toolboxManager = 
				ServletToolboxManager.getInstance(servletContext, file);
		}
		else
		{
			Velocity.info("VelocityController: No toolbox entry in configuration.");
		}
	}


	/**
	 * Initializes the Velocity runtime, first calling 
	 * loadConfiguration(ServletConfig) to get a 
	 * org.apache.commons.collections.ExtendedProperties
	 * of configuration information
	 * and then calling Velocity.init().  Override this
	 * to do anything to the environment before the 
	 * initialization of the singleton takes place, or to 
	 * initialize the singleton in other ways.
	 *
	 * @param config servlet configuration parameters
	 */
	protected void initVelocity(ServletConfig config) throws ServletException
	{
		Velocity.setApplicationAttribute(SERVLET_CONTEXT_KEY, getServletContext());

		// default to servletlogger, which logs to the servlet engines log
		Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, 
							 ServletLogger.class.getName());

		// by default, load resources with webapp resource loader
		Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
		Velocity.setProperty("webapp.resource.loader.class", 
							 WebappLoader.class.getName());

		try
		{
			InputStream is = Helper.getInputStream(config.getServletContext(), INIT_PROPS_KEY);
			
			Properties p = new Properties();

			p.load(is);
			/*
			 *  now, lets get the two elements we care about, the 
			 *  template path and the log, and fix those from relative
			 *  to the webapp root, to absolute on the filesystem, which is
			 *  what velocity needs
			 */

			String path = p.getProperty("file.resource.loader.path");

			if (path != null)
			{
				path = getServletContext().getRealPath(path);
				log.info("file.resource.loader.path=" + path);

				p.setProperty("file.resource.loader.path", path);
			}

			path = p.getProperty("runtime.log");

			if (path != null)
			{
				path = getServletContext().getRealPath(path);
				log.info("runtime.log=" + path);

				p.setProperty("runtime.log", path);
			}

			Velocity.init(p);

			log.info("初始化Velocity引擎成功......");
		}
		catch (IOException e)
		{
			log.error("初始化Velocity引擎出錯", e);
		}
		catch (Exception e)
		{
			log.error("初始化Velocity引擎出錯", e);
		}

	}
     

	/**
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 * @see dark.web.frame.Controller#doRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	public void doRequest(
		HttpServletRequest request,
		HttpServletResponse response)
		throws ServletException, IOException
	{
		// 獲取page.postfix和command.postfix
		// 從而根據用戶的請求后綴的不同調用頁面處理程序或者命令處理程序
		String page_postfix = configuration.getString("page.postfix");
		String command_postfix = configuration.getString("command.postfix");

		if (page_postfix.equals(getRequestPostfix(request)))
			// 調用頁面處理程序		
		{

			String uri = request.getRequestURI();

			VelocityPage page = getVelocityPage((HttpServletRequest) request);

			// 初始化頁面類
			page.init(
				getServletContext(),
				getServletConfig(),
				request,
				response);

			// 設置velocity模版
			page.setTarget(uri);

			// 檢證頁面類的執行權限
			if (page.isAuthentic())
			{
				// 執行真實的商業邏輯
				page.process();
			}
		}
		else if (command_postfix.equals(getRequestPostfix(request)))
			// 調用命令處理程序		
		{
			// 如果要求做表單驗證,則處理之
			if (isValidate(request))
			{

				String input = getInput(request);

				// 如果用戶沒有指定請求轉發路徑,則指定default value
				if (input.equals(""))
				{
					input = configuration.getString("default.input");

					log.warn(
						"dont't specify parameter $INPUT, use default.input:"
							+ input);
					request.setAttribute(
						"$WARM",
						"dont't specify parameter $INPUT, use default.input"
							+ input);
				}

				VelocityForm form = getVelocityForm(request);

				// 初始化表單驗證類
				form.init(getServletContext(), request, response, getMessage());

				// 設置default的ContentType
				form.setContentType(defaultContentType);
			
				// 設置defautl的OutputEncoding
				form.setOutputEncoding(DEFAULT_OUTPUT_ENCODING);
			
				// 傳入toolboxManager
				form.setToolboxManager(toolboxManager);
				
				// 設置當前表單驗證的用戶請求轉發路徑
				form.setInput(input);

				// 檢證表單驗證類的執行權限
				if (form.isAuthentic())
				{
					// 執行實際的驗證操作
					form.validate(request, response);

					if (!form.isPass())
					{
						// 如果isPass()返回false,
						// 則說明驗證出表單錯誤,
						// 立即停止程序處理
						//log.debug("表單驗證失敗");													
						return;
					}
					//log.debug("表單驗證成功");
					//log.debug("form.isPass()=" + form.isPass());	
				}
			}

			String target = getTarget(request);

			// 如果用戶沒有指定請求轉發路徑,則指定default value
			if (target.equals(""))
			{
				target = configuration.getString("default.target");

				log.warn(
					"don't specify paramter $TARGER, use default.target:"
						+ target);
				request.setAttribute(
					"$WARM",
					"don't specify paramter $TARGER, use default.target:"
						+ target);
			}

			VelocityCommand command = getVelocityCommand(request);

			// 初始化命令類
			command.init(
				getServletContext(),
				getServletConfig(),
				request,
				response);

			// 設置default的ContentType
			command.setContentType(defaultContentType);
			
			// 設置defautl的OutputEncoding
			command.setOutputEncoding(DEFAULT_OUTPUT_ENCODING);
			
			// 傳入toolboxManager
			command.setToolboxManager(toolboxManager);
						
			// 設置當前命令的用戶請求轉發路徑
			command.setTarget(target);
			
			// 檢證命令類的執行權限
			if (command.isAuthentic())
			{
				// 執行真實的商業邏輯
				command.process();
			}
		}

	}

	/**
	 * @param request
	 * @return
	 */
	protected VelocityForm getVelocityForm(HttpServletRequest request)
		throws ServletException
	{
		try
		{
			return (VelocityForm) getFormClass(request).newInstance();
		}
		catch (Exception e)
		{
			throw new ServletException(e);
		}
	}

	/**	
	 * @param req
	 * @return
	 */
	protected VelocityCommand getVelocityCommand(HttpServletRequest request)
		throws ServletException
	{
		try
		{
			return (VelocityCommand) getCommandClass(request).newInstance();
		}
		catch (Exception e)
		{
			throw new ServletException(e);
		}
	}

	/**
	 * @param request
	 * @return
	 */
	protected VelocityPage getVelocityPage(HttpServletRequest request)
		throws ServletException
	{
		try
		{
			return (VelocityPage) getVelocityPageClass(request).newInstance();
		}
		catch (Exception e)
		{
			throw new ServletException(e);
		}
	}

	/**
	 * 通過類名串值到得類對象
	 * @param req
	 */
	protected Class getVelocityPageClass(HttpServletRequest request)
	{
		Class result = null;

		String cp = configuration.getString("page.package");

		String pageName = getPageName(request);
		String pageClassName = cp + "." + pageName;

		try
		{
			result = Class.forName(pageClassName);
		}
		catch (ClassNotFoundException e)
		{
			log.info(
				"class:"
					+ pageClassName
					+ " not found, return UnknownVelocityPage.class");
			result = UnknownVelocityPage.class;
		}

		return result;
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人在线视频一区| 一区二区三区中文字幕| 不卡的看片网站| 久久国产精品无码网站| 亚洲欧美另类小说| 中文字幕成人网| 国产色91在线| 欧美经典一区二区| 国产精品嫩草99a| 国产精品久久久久aaaa樱花| 国产精品午夜免费| 蜜桃视频免费观看一区| 国产专区欧美精品| 国产成人精品免费| 9i在线看片成人免费| 在线视频你懂得一区二区三区| 色综合久久久久网| 欧美日韩黄色影视| 91麻豆精品国产91久久久更新时间| 91精品婷婷国产综合久久竹菊| 亚洲精品午夜久久久| 午夜精品一区在线观看| 亚洲777理论| 国内精品伊人久久久久av一坑 | 国产精品国模大尺度视频| 另类调教123区| 日韩三级视频在线看| 久久综合狠狠综合久久激情| 国产色爱av资源综合区| 国内外精品视频| 欧美mv日韩mv国产| 国产精品久久久久久久久久免费看| 国产专区综合网| 26uuu国产电影一区二区| 韩国av一区二区三区四区| 精品国产乱码久久久久久久久| 国产精品久久精品日日| 成人亚洲一区二区一| 中文字幕在线不卡| 久久99精品久久久久久国产越南| 99久久精品国产一区二区三区| 7878成人国产在线观看| 日韩激情视频在线观看| 成人精品免费视频| 国产精品久久久久久久久免费桃花 | 欧美极品xxx| a亚洲天堂av| 亚洲一区二区影院| 国产乱码精品一区二区三区忘忧草| 91久久一区二区| 国产亚洲一区二区三区四区 | 欧美aaaaaa午夜精品| thepron国产精品| 亚洲色大成网站www久久九九| 国产一区二区三区最好精华液| 欧美久久一二三四区| 一个色在线综合| 欧美一区二区视频网站| 亚洲精品乱码久久久久久久久 | eeuss国产一区二区三区| 夜夜揉揉日日人人青青一国产精品| 欧美日韩一区二区三区不卡| 亚洲欧美怡红院| 91精品黄色片免费大全| 久久国产福利国产秒拍| 亚洲色图视频网| 欧美一区二区免费| 99视频精品免费视频| 午夜免费久久看| 国产免费久久精品| 欧美精品一二三四| 丁香网亚洲国际| 欧美激情资源网| 91精品国产综合久久小美女| 成人永久免费视频| 视频一区二区三区入口| 欧美—级在线免费片| 欧美一区二区三区在线视频| 成人免费av网站| 蜜臀国产一区二区三区在线播放| 国产精品免费aⅴ片在线观看| 欧美日韩一级二级| 97久久精品人人澡人人爽| 美脚の诱脚舐め脚责91| 亚洲一区二区精品久久av| 国产欧美一区二区三区鸳鸯浴 | 久久久久高清精品| 国内久久精品视频| 五月婷婷另类国产| 自拍av一区二区三区| 国产欧美日韩麻豆91| 日韩欧美国产wwwww| 国产乱对白刺激视频不卡| 亚洲综合成人在线视频| 久久精品亚洲精品国产欧美| 在线不卡中文字幕播放| 在线一区二区三区做爰视频网站| 国产精品白丝av| 久久精品国产精品青草| 日本欧美一区二区三区乱码| 欧美变态tickle挠乳网站| 欧美午夜一区二区三区| 精品一区二区三区视频在线观看| 亚洲影视资源网| 亚洲免费观看高清完整版在线观看 | 国内外精品视频| 免费日本视频一区| 美女被吸乳得到大胸91| 三级不卡在线观看| 婷婷综合另类小说色区| 亚洲国产视频在线| 精品久久99ma| 日韩一区二区三区在线观看| 91麻豆精品国产| 欧美一区二区大片| 日韩欧美一区二区三区在线| 日韩视频一区二区三区在线播放| 欧美日韩精品欧美日韩精品一 | 亚洲国产aⅴ天堂久久| 一区二区三区产品免费精品久久75 | 天堂久久一区二区三区| 亚欧色一区w666天堂| 日韩高清不卡一区二区三区| 日韩精品国产欧美| 裸体健美xxxx欧美裸体表演| 久久国产成人午夜av影院| 激情六月婷婷久久| 成人综合婷婷国产精品久久蜜臀| 成人小视频在线观看| www.欧美亚洲| 欧美自拍偷拍一区| 在线不卡免费av| 26uuuu精品一区二区| 中文字幕一区日韩精品欧美| 亚洲精品一二三区| 日本视频一区二区三区| 国产精品自拍三区| 99久久久精品| 欧美日韩国产精品自在自线| 欧美成人精精品一区二区频| 欧美高清在线视频| 亚洲一区视频在线| 国产在线视频不卡二| 99久久免费精品| 欧美日韩色综合| 久久综合一区二区| 亚洲免费在线视频一区 二区| 日韩av一区二区在线影视| 精品无人区卡一卡二卡三乱码免费卡 | 91精彩视频在线观看| 欧美一区二区视频在线观看2022 | 一区二区不卡在线视频 午夜欧美不卡在| 一区二区三区日韩精品视频| 蜜桃av一区二区在线观看| 大尺度一区二区| 欧美军同video69gay| 久久久久久久久免费| 亚洲精品日韩一| 国产一区二区导航在线播放| 色婷婷综合久久久中文字幕| 26uuu欧美日本| 亚洲一区二区中文在线| 丁香一区二区三区| 日韩欧美一二区| 一区二区欧美国产| 国产成人99久久亚洲综合精品| 欧美精品日韩综合在线| 国产精品美女久久久久久| 日本三级韩国三级欧美三级| 一本大道久久a久久精二百| 欧美tk—视频vk| 五月天久久比比资源色| 99久久久国产精品免费蜜臀| 欧美精品一区二区三区在线| 亚洲国产aⅴ成人精品无吗| 成人高清视频在线| 久久影院电视剧免费观看| 婷婷久久综合九色综合绿巨人| 成人18视频在线播放| 久久综合五月天婷婷伊人| 奇米影视一区二区三区| 色哟哟日韩精品| 亚洲欧洲另类国产综合| 国产精品一线二线三线| 91麻豆精品久久久久蜜臀| 一区二区三区蜜桃网| 97se亚洲国产综合在线| 国产精品短视频| 成人亚洲一区二区一| 久久久久久免费网| 国产在线精品一区二区三区不卡 | 精品av久久707| 日本va欧美va精品发布| 欧美日产在线观看| 五月天欧美精品| 日韩一区二区在线播放| 免费成人美女在线观看.| 日韩欧美国产一区二区在线播放| 午夜精品在线看| 欧美精品三级日韩久久|