亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美精品第1页| 欧美mv和日韩mv的网站| 日本va欧美va瓶| 亚洲综合在线五月| 亚洲色图一区二区| 亚洲欧美日本韩国| 亚洲综合在线观看视频| 最新中文字幕一区二区三区| 中文字幕av一区二区三区高 | 色女孩综合影院| 亚洲成av人片在线观看无码| 免费观看在线色综合| 免费高清在线一区| 国内精品国产成人国产三级粉色| 久久91精品国产91久久小草| 国产乱人伦精品一区二区在线观看| 麻豆精品一区二区| 国产精一区二区三区| 91免费看`日韩一区二区| 欧美亚洲丝袜传媒另类| 欧美一区二区三区免费在线看| 日韩精品专区在线影院观看| 国产日韩综合av| 一区二区三区色| 麻豆精品一二三| 99久久精品情趣| 日韩三级免费观看| 中文字幕在线播放不卡一区| 婷婷成人激情在线网| 国产精品一区二区久激情瑜伽 | www.亚洲人| 欧美久久久影院| 久久精品一区二区三区四区| 一区二区三区精品| 国产一区在线视频| 欧美专区日韩专区| 欧美国产欧美综合| 奇米四色…亚洲| 色婷婷av一区二区三区gif| 日韩视频免费观看高清在线视频| 国产精品毛片久久久久久久| 日韩va欧美va亚洲va久久| 成人一区在线观看| 欧美人动与zoxxxx乱| 国产精品美日韩| 免费国产亚洲视频| 欧美三级欧美一级| **欧美大码日韩| 国产一区二区三区四| 欧美日韩精品一二三区| 亚洲三级电影全部在线观看高清| 美女网站一区二区| 欧美私模裸体表演在线观看| 中文成人综合网| 国产99一区视频免费| 日韩欧美国产精品| 日日嗨av一区二区三区四区| 91美女在线看| 中文幕一区二区三区久久蜜桃| 捆绑变态av一区二区三区| 欧美日韩激情一区二区| 一区二区三区在线不卡| 色88888久久久久久影院野外| 久久精品一区二区三区不卡牛牛| 美女国产一区二区| 日韩欧美亚洲国产另类| 亚洲成人资源在线| 欧美男女性生活在线直播观看| 亚洲同性同志一二三专区| 成人理论电影网| 18涩涩午夜精品.www| 99re热视频这里只精品| 中文字幕一区二区三区色视频 | 青娱乐精品视频在线| 欧美日韩精品一区二区三区蜜桃| 亚洲永久精品国产| 欧美精品自拍偷拍| 日韩电影免费一区| 欧美成人欧美edvon| 国产一区二区三区视频在线播放| 精品成人一区二区三区四区| 久久99国产精品尤物| 国产亚洲污的网站| 91色婷婷久久久久合中文| 一区二区在线观看av| 欧美视频中文一区二区三区在线观看| 亚洲成人精品一区| 91精品国产综合久久久久久漫画| 秋霞午夜鲁丝一区二区老狼| 欧美精品一区二区不卡| 国产成人av网站| 国产精品成人一区二区三区夜夜夜| www.成人在线| 亚洲h动漫在线| 2021中文字幕一区亚洲| 99久久精品免费看国产| 亚洲超碰精品一区二区| 91精品国产综合久久精品图片| 激情小说亚洲一区| 国产精品青草综合久久久久99| 91偷拍与自偷拍精品| 日韩有码一区二区三区| 国产亚洲精品aa午夜观看| 色综合网色综合| 蜜臀av性久久久久av蜜臀妖精| 国产欧美日韩中文久久| 91国偷自产一区二区开放时间| 日韩主播视频在线| 中文字幕久久午夜不卡| 91精品国产综合久久久久久| 成人一二三区视频| 欧美午夜一区二区三区免费大片| 亚洲成人动漫一区| 久久嫩草精品久久久精品一| 一本大道av伊人久久综合| 蜜臀av一区二区在线免费观看| 中文字幕一区二区三区四区| 欧美一卡二卡三卡| 在线欧美日韩国产| 国产精品综合久久| 亚洲chinese男男1069| 欧美国产精品一区二区| 7777精品伊人久久久大香线蕉 | 欧美久久一区二区| 成人福利电影精品一区二区在线观看| 亚洲r级在线视频| 亚洲欧美成aⅴ人在线观看 | 成人综合婷婷国产精品久久蜜臀| 亚洲电影在线免费观看| 国产精品午夜免费| 精品少妇一区二区三区免费观看| 色婷婷激情一区二区三区| 国产精品自在欧美一区| 蜜桃视频第一区免费观看| 亚洲免费观看高清完整版在线观看 | 国产欧美一区二区三区鸳鸯浴| 欧美日韩一区不卡| 91色婷婷久久久久合中文| 色综合天天在线| 欧美va天堂va视频va在线| 一本久久a久久精品亚洲| 精品写真视频在线观看| 亚洲v日本v欧美v久久精品| 亚洲丝袜制服诱惑| 国产精品超碰97尤物18| 337p日本欧洲亚洲大胆精品 | 欧美浪妇xxxx高跟鞋交| 91极品视觉盛宴| 色综合激情五月| 97久久超碰国产精品| a亚洲天堂av| av亚洲精华国产精华| 波多野结衣中文字幕一区 | 日韩亚洲欧美一区| 69堂精品视频| 91麻豆精品国产91久久久资源速度 | 久久麻豆一区二区| 精品国产凹凸成av人网站| 精品国精品自拍自在线| 日韩你懂的在线播放| 欧美mv和日韩mv国产网站| 欧美不卡一区二区| 精品国产91九色蝌蚪| 久久这里只精品最新地址| 国产日韩综合av| 亚洲欧洲另类国产综合| 一区视频在线播放| 亚洲电影中文字幕在线观看| 日本亚洲视频在线| 激情久久五月天| 成人美女视频在线观看| 日本黄色一区二区| 欧美性大战xxxxx久久久| 欧美一级艳片视频免费观看| 久久九九久精品国产免费直播| 一区免费观看视频| 日韩国产欧美视频| 成人开心网精品视频| 欧美日韩在线播放一区| 精品久久久久久久久久久久久久久久久 | 国产成人综合亚洲网站| 99久久精品国产导航| 51精品久久久久久久蜜臀| 国产女同互慰高潮91漫画| 亚洲美女精品一区| 日韩综合在线视频| 粉嫩av一区二区三区在线播放| 一本到一区二区三区| 精品剧情在线观看| 亚洲最大成人综合| 国产精品1区2区3区在线观看| 在线看日本不卡| 国产亚洲欧洲997久久综合| 亚洲国产精品一区二区久久| 国产精品综合一区二区三区| 在线观看国产一区二区| 久久久久久亚洲综合影院红桃| 亚洲小说春色综合另类电影| 国产精品中文字幕欧美| 91精品国产综合久久久久久|