001 package railo.runtime.tag; 002 003 import java.io.IOException; 004 005 import javax.servlet.jsp.JspWriter; 006 007 import railo.commons.lang.StringUtil; 008 import railo.runtime.exp.ApplicationException; 009 import railo.runtime.exp.PageRuntimeException; 010 import railo.runtime.ext.tag.BodyTagTryCatchFinallyImpl; 011 import railo.runtime.op.Caster; 012 import railo.runtime.writer.CFMLWriter; 013 import railo.runtime.writer.WhiteSpaceWriter; 014 015 /** 016 * Suppresses extra white space and other output, produced by CFML within the tag's scope. 017 * 018 * 019 * 020 **/ 021 public final class ProcessingDirective extends BodyTagTryCatchFinallyImpl { 022 023 /** A string literal; the character encoding to use to read the page. The value may be enclosed in single or double quotation marks, or none. */ 024 //private String pageencoding=null; 025 026 private Boolean suppresswhitespace; 027 private boolean hasBody; 028 029 @Override 030 public void release() { 031 super.release(); 032 //pageencoding=null; 033 suppresswhitespace=null; 034 } 035 036 /** 037 * constructor for the tag class 038 **/ 039 public ProcessingDirective() { 040 } 041 042 /** set the value pageencoding 043 * A string literal; the character encoding to use to read the page. The value may be enclosed in single or double quotation marks, or none. 044 * @param pageencoding value to set 045 **/ 046 public void setPageencoding(String pageencoding) { 047 //pageContext. get HttpServletResponse().set ContentType("text/html; charset="+pageencoding); 048 //this.pageencoding=pageencoding; 049 } 050 051 public void setExecutionlog(boolean executionlog) { 052 } 053 054 055 056 057 /** set the value suppresswhitespace 058 * Boolean indicating whether to suppress the white space and other output generated by the 059 * CFML tags within the cfprocessingdirective block. 060 * @param suppresswhitespace value to set 061 **/ 062 public void setSuppresswhitespace(boolean suppresswhitespace) { 063 this.suppresswhitespace=Caster.toBoolean(suppresswhitespace); 064 } 065 066 067 @Override 068 public int doStartTag() throws ApplicationException { 069 if(suppresswhitespace!=null && !hasBody) { 070 throw new ApplicationException 071 ("for suppressing whitespaces you must define a end tag for tag [cfprocessingdirective]"); 072 } 073 if(suppresswhitespace!=null)return EVAL_BODY_BUFFERED; 074 return EVAL_BODY_INCLUDE; 075 } 076 077 @Override 078 public void doInitBody() { 079 } 080 081 @Override 082 public int doAfterBody() { 083 return SKIP_BODY; 084 } 085 086 087 /** 088 * sets if tag has a body or not 089 * @param hasBody 090 */ 091 public void hasBody(boolean hasBody) { 092 this.hasBody=hasBody; 093 } 094 095 @Override 096 public void doFinally() { 097 if(suppresswhitespace!=null) { 098 try { 099 JspWriter out = pageContext.getOut(); 100 if(suppresswhitespace.booleanValue()) { 101 if(out instanceof WhiteSpaceWriter)out.write(bodyContent.getString()); 102 else out.write(StringUtil.suppressWhiteSpace(bodyContent.getString())); 103 } 104 else { 105 if(out instanceof CFMLWriter){ 106 ((CFMLWriter)out).writeRaw(bodyContent.getString()); 107 } 108 else 109 out.write(bodyContent.getString()); 110 } 111 } catch (IOException e) { 112 throw new PageRuntimeException(Caster.toPageException(e)); 113 } 114 } 115 } 116 }