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

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

?? velocitycommand.java

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

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

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

import dark.web.frame.Value;
import dark.web.frame.command.AbstractCommand;

import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.io.VelocityWriter;
import org.apache.velocity.runtime.RuntimeSingleton;
import org.apache.velocity.tools.view.ToolboxManager;
import org.apache.velocity.tools.view.context.ChainedContext;
import org.apache.velocity.util.SimplePool;

/**
 * <p>Title:            VelocityCommand</p>
 * <p>Description:      支持Velocity的Command處理超類
 * 						根據org.apache.velocity.servlet.VelocityServlet進行修改,
 * 						從而將Velocity整合進dwf框架</p>
 * <p>Copyright:        Copyright (c) 2005</p>
 * <p>Company:          DIS</p>
 * <p>Create Time:      2005-2-28 15:40:34</p>
 * @author             <a href="mailto:dark_he@hotmail.com">darkhe</a>
 * @version            1.0
 */
public abstract class VelocityCommand extends AbstractCommand
{

	/** Cache of writers */
	private static SimplePool writerPool = new SimplePool(40);
	
	/** A reference to the toolbox manager. */
	protected ToolboxManager toolboxManager = null;
	
	private String contentType = "text/html";
	
	/**  encoding for the output stream */	
	private String outputEncoding = "ISO-8859-1";
	
	/**
	 * Whether we've logged a deprecation warning for
	 * ServletResponse's <code>getOutputStream()</code>.
	 * @since VelocityTools 1.1
	 */
	private boolean warnOfOutputStreamDeprecation = true;
	
		
	public Template process(
		HttpServletRequest request,
		HttpServletResponse response,
		Context ctx)
		throws Exception
	{
		Value v = loadValue(request);

		Template t = process(request, response, ctx, v);

		saveValue(v, request);

		ctx.put("Value", v);
		ctx.put("Request", request);
		ctx.put("Response", response);
		ctx.put("Session", request.getSession());

		return t;
	}

	/**
	 * 子類必須實現當前方法以實現業務邏輯
	 * @param request
	 * @param response
	 * @param context
	 * @param v
	 * @return
	 * @throws Exception
	 */
	public abstract Template process(
		HttpServletRequest request,
		HttpServletResponse response,
		Context context,
		Value v)
		throws Exception;


	/**
	 * @throws ServletException
	 * @throws IOException
	 * @see dark.web.frame.Command#process()
	 */
	public void process() throws ServletException, IOException
	{
		Context context = null;

		HttpServletRequest request = getRequest();
		HttpServletResponse response = getResponse();
		
		try
		{
			/*
			 *  first, get a context
			 */

			context = createContext(request, response);

			/*
			 *   set the content type 
			 */
			response.setContentType(contentType);

			/*
			 *  let someone handle the request
			 */
			Template template = process(request, response, context);

			/*
			 *  bail if we can't find the template
			 */

			if (template == null)
			{
				log.warn("template is null");
				return;
			}

			/*
			 *  now merge it
			 */

			mergeTemplate(template, context, response);
		}
		catch (Exception e)
		{
			/*
			 *  call the error handler to let the derived class
			 *  do something useful with this failure.
			 */

			error(request, response, e);
		}
		finally
		{
			/*
			 *  call cleanup routine to let a derived class do some cleanup
			 */

			requestCleanup(request, response, context);
		}
	}
	
	
	/**
	  * Cleanup routine called at the end of the request processing sequence
	  * allows a derived class to do resource cleanup or other end of 
	  * process cycle tasks.  This default implementation does nothing.
	  *
	  * @param request servlet request from client 
	  * @param response servlet reponse 
	  * @param context Context created by the {@link #createContext}
	  */
	 protected void requestCleanup(HttpServletRequest request, 
								   HttpServletResponse response, 
								   Context context)
	 {
	 }


	 /**
	  * <p>Handle the template processing request.</p> 
	  *
	  * @param request client request
	  * @param response client response
	  * @param ctx  VelocityContext to fill
	  *
	  * @return Velocity Template object or null
	  */
	 protected Template handleRequest(HttpServletRequest request, 
									  HttpServletResponse response, 
									  Context ctx)
		 throws Exception
	 {
		 // If we get here from RequestDispatcher.include(), getServletPath()
		 // will return the original (wrong) URI requested.  The following special
		 // attribute holds the correct path.  See section 8.3 of the Servlet
		 // 2.3 specification.
		 String path = (String)request.getAttribute("javax.servlet.include.servlet_path");
		 if (path == null)
		 {
			 path = request.getServletPath();
		 }
		 return getTemplate(path);
	 }


	 /**
	  * <p>Creates and returns an initialized Velocity context.</p> 
	  * 
	  * A new context of class {@link ChainedContext} is created and 
	  * initialized.
	  *
	  * @param request servlet request from client
	  * @param response servlet reponse to client
	  */
	 protected Context createContext(HttpServletRequest request, 
									 HttpServletResponse response)
	 {
		 ChainedContext ctx = new ChainedContext(null, request, response, getServletContext());

		 /* if we have a toolbox manager, get a toolbox from it */
		 if (toolboxManager != null)
		 {
			 ctx.setToolbox(toolboxManager.getToolboxContext(ctx));
		 }
		 return ctx;
	 }


	 /**
	  * Retrieves the requested template.
	  *
	  * @param name The file name of the template to retrieve relative to the 
	  *             template root.
	  * @return The requested template.
	  * @throws ResourceNotFoundException if template not found
	  *          from any available source.
	  * @throws ParseErrorException if template cannot be parsed due
	  *          to syntax (or other) error.
	  * @throws Exception if an error occurs in template initialization
	  */
	 public Template getTemplate(String name)
		 throws ResourceNotFoundException, ParseErrorException, Exception
	 {
		 return RuntimeSingleton.getTemplate(name);
	 }

    
	 /**
	  * Retrieves the requested template with the specified character encoding.
	  *
	  * @param name The file name of the template to retrieve relative to the 
	  *             template root.
	  * @param encoding the character encoding of the template
	  * @return The requested template.
	  * @throws ResourceNotFoundException if template not found
	  *          from any available source.
	  * @throws ParseErrorException if template cannot be parsed due
	  *          to syntax (or other) error.
	  * @throws Exception if an error occurs in template initialization
	  */
	 public Template getTemplate(String name, String encoding)
		 throws ResourceNotFoundException, ParseErrorException, Exception
	 {
		 return RuntimeSingleton.getTemplate(name, encoding);
	 }


	 /**
	  * Merges the template with the context.  Only override this if you really, really
	  * really need to. (And don't call us with questions if it breaks :)
	  *
	  * @param template template object returned by the handleRequest() method
	  * @param context Context created by the {@link #createContext}
	  * @param response servlet reponse (used to get a Writer)
	  */
	 protected void mergeTemplate(Template template, 
								  Context context, 
								  HttpServletResponse response)
		 throws ResourceNotFoundException, ParseErrorException, 
				MethodInvocationException, IOException, 
				UnsupportedEncodingException, Exception
	 {
		 VelocityWriter vw = null;
		 Writer writer = getResponseWriter(response);
		 try
		 {
			 vw = (VelocityWriter)writerPool.get();
			 if (vw == null)
			 {
				 vw = new VelocityWriter(writer, 4 * 1024, true);
			 }
			 else
			 {
				 vw.recycle(writer);
			 }
			 template.merge(context, vw);
		 }
		 finally
		 {
			 if (vw != null)
			 {
				 try
				 {
					 // flush and put back into the pool
					 // don't close to allow us to play
					 // nicely with others.
					 vw.flush();
					 /* This hack sets the VelocityWriter's internal ref to the 
					  * PrintWriter to null to keep memory free while
					  * the writer is pooled. See bug report #18951 */
					 vw.recycle(null);
					 writerPool.put(vw);
				 }
				 catch (Exception e)
				 {
					 Velocity.debug("VelocityViewServlet: " + 
									"Trouble releasing VelocityWriter: " +
									e.getMessage());
				 }                
			 }
		 }
	 }

 
	 /**
	  * Invoked when there is an error thrown in any part of doRequest() processing.
	  * <br><br>
	  * Default will send a simple HTML response indicating there was a problem.
	  * 
	  * @param request original HttpServletRequest from servlet container.
	  * @param response HttpServletResponse object from servlet container.
	  * @param e  Exception that was thrown by some other part of process.
	  */
	 protected void error(HttpServletRequest request, 
						  HttpServletResponse response, 
						  Exception e)
		 throws ServletException
	 {
		 try
		 {
			 StringBuffer html = new StringBuffer();
			 html.append("<html>\n");
			 html.append("<head><title>Error</title></head>\n");
			 html.append("<body>\n");
			 html.append("<h2>VelocityCommand : Error processing the template</h2>\n");

			 Throwable cause = e;

			 String why = cause.getMessage();
			 if (why != null && why.trim().length() > 0)
			 {
				 html.append(why);
				 html.append("\n<br>\n");
			 }

			 // if it's an MIE, i want the real stack trace!
			 if (cause instanceof MethodInvocationException) 
			 {
				 // get the real cause
				 cause = ((MethodInvocationException)cause).getWrappedThrowable();
			 }

			 StringWriter sw = new StringWriter();
			 cause.printStackTrace(new PrintWriter(sw));

			 html.append("<pre>\n");
			 html.append(sw.toString());
			 html.append("</pre>\n");
			 html.append("</body>\n");
			 html.append("</html>");
			 getResponseWriter(response).write(html.toString());
		 }
		 catch (Exception e2)
		 {
			 // clearly something is quite wrong.
			 // let's log the new exception then give up and
			 // throw a servlet exception that wraps the first one
			 Velocity.error("VelocityCommand: Exception while printing error screen: "+e2);
			 throw new ServletException(e);
		 }
	 }

	 /**
	  * <p>Procure a Writer with correct encoding which can be used
	  * even if HttpServletResponse's <code>getOutputStream()</code> method
	  * has already been called.</p>
	  *
	  * <p>This is a transitional method which will be removed in a
	  * future version of Velocity.  It is not recommended that you
	  * override this method.</p>
	  *
	  * @param response The response.
	  * @return A <code>Writer</code>, possibly created using the
	  *        <code>getOutputStream()</code>.
	  */
	 protected Writer getResponseWriter(HttpServletResponse response)
		 throws UnsupportedEncodingException, IOException
	 {
		 Writer writer = null;
		 try
		 {
			 writer = response.getWriter();
		 }
		 catch (IllegalStateException e)
		 {
			 // ASSUMPTION: We already called getOutputStream(), so
			 // calls to getWriter() fail.  Use of OutputStreamWriter
			 // assures our desired character set
			 if (this.warnOfOutputStreamDeprecation)
			 {
				 this.warnOfOutputStreamDeprecation = false;
				 Velocity.warn("VelocityCommand: " +
							   "Use of ServletResponse's getOutputStream() " +
							   "method with VelocityViewServlet is " +
							   "deprecated -- support will be removed in " +
							   "an upcoming release");
			 }
			 // Assume the encoding has been set via setContentType().
			 String encoding = response.getCharacterEncoding();
			 if (encoding == null)
			 {
				 encoding = outputEncoding;
			 }
			 writer = new OutputStreamWriter(response.getOutputStream(),
											 encoding);
		 }
		 return writer;
	 }


	/**
	 * @return
	 */
	public String getContentType()
	{
		return contentType;
	}

	/**
	 * @param string
	 */
	public void setContentType(String string)
	{
		contentType = string;
	}

	/**
	 * @return
	 */
	public ToolboxManager getToolboxManager()
	{
		return toolboxManager;
	}

	/**
	 * @param manager
	 */
	public void setToolboxManager(ToolboxManager manager)
	{
		toolboxManager = manager;
	}

	/**
	 * @return
	 */
	public String getOutputEncoding()
	{
		return outputEncoding;
	}

	/**
	 * @param string
	 */
	public void setOutputEncoding(String string)
	{
		outputEncoding = string;
	}

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
视频一区在线播放| 从欧美一区二区三区| 狠狠色狠狠色综合日日91app| 丰满放荡岳乱妇91ww| 欧美视频一二三区| 国产无遮挡一区二区三区毛片日本| 亚洲另类在线视频| 国产真实乱偷精品视频免| 在线观看视频91| 国产精品久久久久影视| 久久激情综合网| 欧美人与z0zoxxxx视频| 国产精品成人在线观看 | 国产精品天美传媒沈樵| 日本伊人精品一区二区三区观看方式| 成人午夜精品在线| 欧美精品一区二区三区四区 | 欧美电视剧免费全集观看| 亚洲理论在线观看| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 亚洲激情在线播放| 99视频一区二区三区| 国产亚洲一区二区三区| 精品亚洲成a人在线观看| 欧美精品三级日韩久久| 亚洲欧美日韩国产一区二区三区 | 日韩在线卡一卡二| 欧美日韩国产成人在线免费| 亚洲色图都市小说| 色综合久久久网| 亚洲精品免费播放| 色综合久久中文字幕综合网| 综合久久久久久| 色香色香欲天天天影视综合网 | 精品噜噜噜噜久久久久久久久试看| 亚洲国产一区视频| 欧美日韩一二区| 午夜精品福利一区二区三区蜜桃| 欧美亚洲自拍偷拍| 日韩综合小视频| 欧美一激情一区二区三区| 免费成人在线影院| 欧美精品一区在线观看| 国产成人精品影视| 亚洲视频精选在线| 欧美色视频在线观看| 三级在线观看一区二区| 亚洲免费伊人电影| 日本电影欧美片| 一区二区三区在线播| 欧美日韩一区二区三区高清| 视频一区在线播放| 久久一区二区三区四区| 成人黄色大片在线观看| 亚洲精品乱码久久久久久日本蜜臀| 色狠狠色狠狠综合| 日本不卡不码高清免费观看| 欧美一区二区视频免费观看| 久久99精品国产91久久来源| 国产欧美1区2区3区| 91亚洲男人天堂| 亚洲永久免费av| 欧美电影免费提供在线观看| 国产精品一线二线三线精华| 国产精品二区一区二区aⅴ污介绍| 色猫猫国产区一区二在线视频| 亚洲风情在线资源站| 精品久久久久av影院| 成人av在线电影| 天天色综合天天| 国产喂奶挤奶一区二区三区| 色婷婷亚洲综合| 久久99精品久久久久久久久久久久 | 亚洲一区二区三区美女| 日韩精品一区二区三区swag| 成人av在线看| 美脚の诱脚舐め脚责91 | 26uuu久久天堂性欧美| 99国产精品久久久| 精品一区二区三区影院在线午夜| 亚洲日本青草视频在线怡红院| 在线电影一区二区三区| 成人午夜视频网站| 久久aⅴ国产欧美74aaa| 亚洲综合一二区| 国产精品传媒在线| 久久九九影视网| 欧美一卡2卡3卡4卡| 91久久香蕉国产日韩欧美9色| 国产老肥熟一区二区三区| 日韩高清一区在线| 成人免费毛片a| 麻豆精品一区二区av白丝在线| 亚洲色图清纯唯美| 中文天堂在线一区| 国产亚洲一二三区| 精品国产sm最大网站免费看| 欧美日韩国产123区| 91传媒视频在线播放| av日韩在线网站| 成人黄色电影在线 | 亚洲午夜久久久久久久久电影院 | 亚洲免费观看高清完整| 久久嫩草精品久久久精品| 欧美美女喷水视频| 欧美体内she精高潮| 色呦呦国产精品| 91欧美激情一区二区三区成人| 国产精品18久久久久久vr| 毛片一区二区三区| 蜜桃一区二区三区四区| 日韩高清一区在线| 日本 国产 欧美色综合| 午夜私人影院久久久久| 一区二区三区精品久久久| 亚洲人成影院在线观看| 亚洲色图视频免费播放| 亚洲手机成人高清视频| 亚洲免费色视频| 一区二区高清免费观看影视大全 | 久久综合给合久久狠狠狠97色69| 51精品视频一区二区三区| 国产欧美日韩激情| 国产精品伦理一区二区| 亚洲天堂av一区| 亚洲精品视频在线| 亚洲午夜久久久久久久久电影网 | 国产精品全国免费观看高清| 欧美激情一区二区三区不卡| 国产精品青草久久| 亚洲免费电影在线| 视频在线在亚洲| 久久99久久久久| 成人在线综合网站| 色婷婷精品久久二区二区蜜臀av| 91免费观看视频在线| 欧美日韩精品欧美日韩精品一综合| 777奇米成人网| 国产性色一区二区| 亚洲精品免费在线播放| 手机精品视频在线观看| 国产毛片一区二区| 色综合亚洲欧洲| 日韩欧美成人一区| 国产精品美女一区二区在线观看| 亚洲欧美日韩国产综合在线| 日韩高清在线不卡| 成人黄色在线视频| 欧美乱妇15p| 中文成人av在线| 日韩精品一区第一页| 国产九九视频一区二区三区| 色综合久久综合网97色综合| 欧美福利视频导航| 国产嫩草影院久久久久| 亚洲一卡二卡三卡四卡无卡久久| 美国三级日本三级久久99 | 91国偷自产一区二区三区观看| 在线不卡免费欧美| 国产精品拍天天在线| 日韩国产精品久久久久久亚洲| 国产一区 二区| 欧美日韩国产片| 久久久精品综合| 天天影视涩香欲综合网 | 精东粉嫩av免费一区二区三区| 99久久夜色精品国产网站| 日韩一区二区免费在线观看| 久久精品水蜜桃av综合天堂| 亚洲3atv精品一区二区三区| 成人午夜激情片| 亚洲精品一区二区三区影院| 午夜视频一区在线观看| 99久久久免费精品国产一区二区| 日韩欧美综合一区| 亚洲综合精品久久| www.成人网.com| 国产欧美一区二区精品性色| 天天操天天综合网| 91福利视频网站| 亚洲日本丝袜连裤袜办公室| 国内精品伊人久久久久av一坑| 欧美午夜免费电影| 亚洲日本va午夜在线电影| 国产乱码精品一区二区三区五月婷| 欧美乱妇15p| 亚洲一区欧美一区| 在线免费av一区| 亚洲欧美一区二区三区久本道91| 国产毛片精品国产一区二区三区| 91精品在线免费| 天堂一区二区在线免费观看| 在线免费av一区| 亚洲久草在线视频| 91碰在线视频| 亚洲色图.com| 在线观看欧美精品| 亚洲欧美激情一区二区| 91美女福利视频| 亚洲女同ⅹxx女同tv|