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.writer.BodyContentImpl;
009    
010    public final class Silent extends BodyTagTryCatchFinallyImpl {
011    
012    
013        private boolean bufferoutput=true;
014            private BodyContentImpl bc;
015            private boolean wasSilent;
016    
017    
018    
019            /**
020             * @param bufferoutput the bufferoutput to set
021             */
022            public void setBufferoutput(boolean bufferoutput) {
023                    this.bufferoutput = bufferoutput;
024            }
025    
026    
027            /**
028         * @see railo.runtime.ext.tag.TagImpl#doStartTag()
029         */
030        public int doStartTag() throws JspException {
031            if(bufferoutput) bc = (BodyContentImpl) pageContext.pushBody();
032            else wasSilent=pageContext.setSilent();
033            
034            return EVAL_BODY_INCLUDE;
035        }
036        
037    
038            /**
039             *
040             * @see railo.runtime.ext.tag.BodyTagTryCatchFinallyImpl#doCatch(java.lang.Throwable)
041             */
042            public void doCatch(Throwable t) throws Throwable {
043                    if(bufferoutput){
044                    try {
045                                    bc.flush();
046                            } catch (IOException e) {}
047                            pageContext.popBody();
048                            bc=null;
049            }
050            else if(!wasSilent)pageContext.unsetSilent();
051                super.doCatch(t);
052            }
053    
054        
055        /**
056         * @see railo.runtime.ext.tag.BodyTagTryCatchFinallyImpl#doFinally()
057         */
058        public void doFinally() {
059            if(bufferoutput){
060                    if(bc!=null){
061                            bc.clearBody();
062                            pageContext.popBody();
063                    }
064            }
065            else if(!wasSilent)pageContext.unsetSilent();
066        }
067    
068    
069            /**
070             *
071             * @see railo.runtime.ext.tag.BodyTagImpl#release()
072             */
073            public void release() {
074                    super.release();
075                    bc=null;
076                    this.bufferoutput=true;
077            }
078    
079    
080    }