001 package railo.runtime.tag; 002 003 import java.io.IOException; 004 005 import javax.servlet.jsp.JspException; 006 007 import railo.runtime.ext.tag.BodyTagTryCatchFinallyImpl; 008 import railo.runtime.listener.ApplicationContextSupport; 009 import railo.runtime.writer.BodyContentImpl; 010 011 public final class Silent extends BodyTagTryCatchFinallyImpl { 012 013 014 private Boolean bufferOutput=true; 015 private BodyContentImpl bc; 016 private boolean wasSilent; 017 018 019 020 /** 021 * @param bufferoutput the bufferoutput to set 022 */ 023 public void setBufferoutput(boolean bufferOutput) { 024 this.bufferOutput = bufferOutput?Boolean.TRUE:Boolean.FALSE; 025 } 026 027 028 @Override 029 public int doStartTag() throws JspException { 030 if(bufferOutput==null) 031 bufferOutput=((ApplicationContextSupport)pageContext.getApplicationContext()).getBufferOutput()?Boolean.TRUE:Boolean.FALSE; 032 033 if(bufferOutput.booleanValue()) bc = (BodyContentImpl) pageContext.pushBody(); 034 else wasSilent=pageContext.setSilent(); 035 036 return EVAL_BODY_INCLUDE; 037 } 038 039 040 @Override 041 public void doCatch(Throwable t) throws Throwable { 042 if(bufferOutput.booleanValue()){ 043 try { 044 bc.flush(); 045 } catch (IOException e) {} 046 pageContext.popBody(); 047 bc=null; 048 } 049 else if(!wasSilent)pageContext.unsetSilent(); 050 super.doCatch(t); 051 } 052 053 054 @Override 055 public void doFinally() { 056 if(bufferOutput.booleanValue()){ 057 if(bc!=null){ 058 bc.clearBody(); 059 pageContext.popBody(); 060 } 061 } 062 else if(!wasSilent)pageContext.unsetSilent(); 063 } 064 065 066 @Override 067 public void release() { 068 super.release(); 069 bc=null; 070 this.bufferOutput=null; 071 } 072 073 074 }