001 package railo.runtime.tag; 002 003 import railo.runtime.exp.PageException; 004 import railo.runtime.ext.tag.BodyTagTryCatchFinallyImpl; 005 import railo.runtime.interpreter.VariableInterpreter; 006 import railo.runtime.op.Caster; 007 008 /** 009 * Saves the generated content inside the tag body in a variable. 010 * 011 * 012 * 013 **/ 014 public final class SaveContent extends BodyTagTryCatchFinallyImpl { 015 016 /** The name of the variable in which to save the generated content inside the tag. */ 017 private String variable; 018 private boolean trim; 019 private boolean append; 020 021 @Override 022 public void release() { 023 super.release(); 024 variable=null; 025 trim=false; 026 append=false; 027 } 028 029 030 /** set the value variable 031 * The name of the variable in which to save the generated content inside the tag. 032 * @param variable value to set 033 **/ 034 public void setVariable(String variable) { 035 this.variable=variable; 036 } 037 038 039 public void setTrim(boolean trim) { 040 this.trim=trim; 041 } 042 043 /** 044 * if true, and a variable with the passed name already exists, the content will be appended to the variable instead of overwriting it 045 */ 046 public void setAppend(boolean append) { 047 this.append=append; 048 } 049 050 @Override 051 public int doStartTag() { 052 return EVAL_BODY_BUFFERED; 053 } 054 055 056 @Override 057 public int doAfterBody() throws PageException { 058 059 String value = trim ? bodyContent.getString().trim() : bodyContent.getString(); 060 061 if ( append ) { 062 063 value = Caster.toString( VariableInterpreter.getVariableEL( pageContext, variable, "" ), "" ) + value; // prepend the current variable or empty-string if not found 064 } 065 066 pageContext.setVariable( variable, value ); 067 bodyContent.clearBody(); 068 069 return SKIP_BODY; 070 } 071 072 073 }