/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.taglib.base;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TagSupport;

import com.feilong.core.io.UncheckedIOException;

/**
 * 自定义标签的父类,所有自定义标签的基类,包含通用的方法.
 * 
 * <h3>可以使用的方法:</h3>
 * 
 * <blockquote>
 * <ul>
 * <li>{@link #getHttpServletRequest()}</li>
 * <li>{@link #getHttpServletResponse()}</li>
 * <li>{@link #getHttpSession()}</li>
 * <li>{@link #print(Object)}</li>
 * <li>{@link #println(Object)}</li>
 * </ul>
 * </blockquote>
 * 
 * <h3>关于Return Code:</h3>
 * 
 * <blockquote>
 * <ul>
 * <li>{@link javax.servlet.jsp.tagext.IterationTag#EVAL_BODY_AGAIN EVAL_BODY_AGAIN} 对标签体循环处理</li>
 * <li>{@link javax.servlet.jsp.tagext.BodyTag#EVAL_BODY_BUFFERED EVAL_BODY_BUFFERED}(2) 表示需要处理标签体</li>
 * <li>{@link javax.servlet.jsp.tagext.Tag#EVAL_PAGE EVAL_PAGE} (6)：处理标签后，继续处理JSP后面的内容</li>
 * <li>{@link javax.servlet.jsp.tagext.Tag#SKIP_PAGE SKIP_PAGE}(5)： 忽略标签后面的JSP内容</li>
 * <li>{@link javax.servlet.jsp.tagext.Tag#EVAL_BODY_INCLUDE EVAL_BODY_INCLUDE}(1)将body的内容输出到存在的输出流中
 * 表示需要处理标签体,但绕过setBodyContent()和doInitBody()方法</li>
 * <li>{@link javax.servlet.jsp.tagext.Tag#SKIP_BODY SKIP_BODY} (0) ： 表示不用处理标签体，直接调用doEndTag()方法 跳过了开始和结束标签之间的代码。</li>
 * </ul>
 * </blockquote>
 * 
 * <p>
 * {@link TagSupport}与{@link BodyTagSupport}的区别,主要是标签处理类是否需要与标签体交互， 如果不需要交互的就用{@link TagSupport}，否则如果需要交互就用{@link BodyTagSupport}。 <br>
 * 交互就是标签处理类是否要读取标签体的内容和改变标签体返回的内容。<br>
 * </p>
 * {@link BodyTagSupport}继承了{@link TagSupport}.
 * 
 * @author feilong
 * @version 1.0.0 2012-3-13 01:46
 * @version 1.2.1 2015-6-12 15:38
 * @see javax.servlet.jsp.tagext.BodyTagSupport
 * @see javax.servlet.jsp.tagext.TagSupport
 * @since 1.0.0
 */
public abstract class BaseTag extends BodyTagSupport{

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = -5494214419937813707L;

    /**
     * 将文字输出到页面.
     *
     * @param object
     *            the object
     * @throws UncheckedIOException
     *             the unchecked io exception
     */
    protected void print(Object object) throws UncheckedIOException{
        JspWriter jspWriter = pageContext.getOut();
        try{
            jspWriter.print(object);
        }catch (IOException e){
            throw new UncheckedIOException(e);
        }
    }

    /**
     * 将文字输出到页面.
     *
     * @param object
     *            the object
     * @throws UncheckedIOException
     *             the unchecked io exception
     */
    protected void println(Object object) throws UncheckedIOException{
        JspWriter jspWriter = pageContext.getOut();
        try{
            jspWriter.println(object.toString());
        }catch (IOException e){
            throw new UncheckedIOException(e);
        }
    }

    /**
     * 获得HttpServletRequest.
     *
     * @return the http servlet request
     */
    protected final HttpServletRequest getHttpServletRequest(){
        return (HttpServletRequest) getServletRequest();
    }

    /**
     * 获得ServletRequest.
     *
     * @return the servlet request
     */
    protected final ServletRequest getServletRequest(){
        return this.pageContext.getRequest();
    }

    /**
     * 获得 HttpSession.
     *
     * @return HttpSession
     */
    protected final HttpSession getHttpSession(){
        return this.pageContext.getSession();
    }

    /**
     * 获得HttpServletResponse.
     *
     * @return the http servlet response
     */
    protected final HttpServletResponse getHttpServletResponse(){
        return (HttpServletResponse) pageContext.getResponse();
    }
}
@@ -951,16 +951,65 @@
 Support;
+%0Aimport javax.servlet.jsp.tagext.TryCatchFinally;
 %0A%0Aimport
@@ -2605,16 +2605,43 @@
 gSupport
+ implements TryCatchFinally
 %7B%0A%0A    /
@@ -4387,24 +4387,24 @@
 Response()%7B%0A
-
         retu
@@ -4460,10 +4460,373 @@
 );%0A    %7D
+%0A%0A    /*%0A     * (non-Javadoc)%0A     * %0A     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)%0A     */%0A    @Override%0A    public void doCatch(Throwable t) throws Throwable%7B%0A%0A    %7D%0A%0A    /*%0A     * (non-Javadoc)%0A     * %0A     * @see javax.servlet.jsp.tagext.TryCatchFinally#doFinally()%0A     */%0A    @Override%0A    public void doFinally()%7B%0A%0A    %7D
 %0A%7D

update BaseTag implements TryCatchFinally