package net.darkmist.alib.escape.jsp;

import java.io.IOException;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;

import net.darkmist.alib.escape.Escaper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

abstract class BaseTag implements Tag
{
	private static final Class<BaseTag> CLASS = BaseTag.class;
	private static final Logger logger = LoggerFactory.getLogger(CLASS);

	private Escaper escaper;
	private PageContext pc;
	private Tag parent;

	protected BaseTag(Escaper escaper)
	{
		this.escaper = escaper;
	}

	@Override
	public void setPageContext(PageContext pc_)
	{
		this.pc = pc_;
	}

	@Override
	public void setParent(Tag t)
	{
		parent = t;
	}

	@Override
	public Tag getParent()
	{
		return parent;
	}

	@Override
	public int doStartTag() throws JspTagException
	{
		pc.pushBody(escaper.escape(pc.getOut()));
		return EVAL_BODY_INCLUDE;
	}

	@Override
	public int doEndTag() throws JspTagException
	{
		pc.popBody();
		return EVAL_PAGE;
	}

	@Override
	public void release()
	{
		pc = null;
		parent = null;
	}
}

@@ -132,56 +132,29 @@
 jsp.
-PageContext;%0Aimport javax.servlet.jsp.tagext.Tag
+tagext.BodyTagSupport
 ;%0A%0Ai
@@ -279,22 +279,30 @@
 Tag 
-implements Tag
+extends BodyTagSupport
 %0A%7B%0A%09
@@ -460,54 +460,8 @@
 per;
-%0A%09private PageContext pc;%0A%09private Tag parent;
 %0A%0A%09p
@@ -550,223 +550,23 @@
 lic 
-void setPageContext(PageContext pc_)%0A%09%7B%0A%09%09this.pc = pc_;%0A%09%7D%0A%0A%09@Override%0A%09public void setParent(Tag t)%0A%09%7B%0A%09%09parent = t;%0A%09%7D%0A%0A%09@Override%0A%09public Tag getParent()%0A%09%7B%0A%09%09return parent;%0A%09%7D%0A%0A%09@Override%0A%09public int doStartTag
+int doAfterBody
 () t
@@ -596,20 +596,19 @@
 %7B%0A%09%09
-pc.pushBody(
+try%0A%09%09%7B%0A%09%09%09
 esca
@@ -622,95 +622,96 @@
 ape(
-pc.getOut()));%0A%09%09return EVAL_BODY_INCLUDE
+getPreviousOut(), bodyContent.getString())
 ;%0A
+%09
 %09%7D%0A
-%0A%09@Override%0A%09public int doEndTag() 
+%09%09catch (IOException e)%0A%09%09%7B%0A%09%09%09
 throw
-s
+ new
  Jsp
@@ -726,120 +726,106 @@
 tion
-%0A%09%7B%0A%09%09pc.popBody();%0A%09%09return EVAL_PAGE
+(%22IOException writing encoded output.%22, e)
 ;%0A
+%09
 %09%7D%0A%0A%09
-@Override%0A%09public void release()%0A%09%7B%0A%09%09pc = null;%0A%09%09parent = null
+%09bodyContent.clearBody();%0A%09%09return SKIP_BODY
 ;%0A%09%7D%0A
+%0A
 %7D%0A

Move back to old way...