/**
 *
 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 * 
 **/
package lucee.runtime.tag;

import lucee.runtime.exp.PageException;
import lucee.runtime.ext.tag.BodyTagTryCatchFinallyImpl;
import lucee.runtime.interpreter.VariableInterpreter;
import lucee.runtime.op.Caster;

/**
 * Saves the generated content inside the tag body in a variable.
 *
 *
 *
 **/
public final class SaveContent extends BodyTagTryCatchFinallyImpl {

	/** The name of the variable in which to save the generated content inside the tag. */
	private String variable;
	private boolean trim;
	private boolean append;

	@Override
	public void release() {
		super.release();
		variable = null;
		trim = false;
		append = false;
	}

	/**
	 * set the value variable The name of the variable in which to save the generated content inside the
	 * tag.
	 * 
	 * @param variable value to set
	 **/
	public void setVariable(String variable) {
		this.variable = variable;
	}

	public void setTrim(boolean trim) {
		this.trim = trim;
	}

	/**
	 * if true, and a variable with the passed name already exists, the content will be appended to the
	 * variable instead of overwriting it
	 */
	public void setAppend(boolean append) {
		this.append = append;
	}

	@Override
	public int doStartTag() {
		return EVAL_BODY_BUFFERED;
	}

	@Override
	public int doAfterBody() throws PageException {

		String value = trim ? bodyContent.getString().trim() : bodyContent.getString();

		if (append) {

			value = Caster.toString(VariableInterpreter.getVariableEL(pageContext, variable, ""), "") + value; // prepend the current variable or empty-string if not found
		}
		pageContext.setVariable(variable, value);
		bodyContent.clearBody();

		return SKIP_BODY;
	}

}
@@ -780,16 +780,97 @@
 e.tag;%0A%0A
+import lucee.runtime.config.ConfigPro;%0Aimport lucee.runtime.config.ConfigWebPro;%0A
 import l
@@ -901,16 +901,16 @@
 eption;%0A
-
 import l
@@ -1335,16 +1335,53 @@
 n trim;%0A
+    private boolean setTrimManually;%0A
 %09private
@@ -1488,16 +1488,49 @@
  false;%0A
+        setTrimManually = false;%0A
 %09%09append
@@ -1836,16 +1836,53 @@
 = trim;%0A
+        this.setTrimManually = true;%0A
 %09%7D%0A%0A%09/**
@@ -2226,16 +2226,290 @@
 eption %7B
+%0A        //If trim-attribute is not set by the user, use the whitespace-setting%0A        if(!setTrimManually) %7B%0A            ConfigWebPro config = (ConfigWebPro) pageContext.getConfig();%0A            trim = config.getCFMLWriterType() != ConfigPro.CFML_WRITER_REFULAR;%0A        %7D
 %0A%0A%09%09Stri
@@ -2585,16 +2585,16 @@
 ing();%0A%0A
+
 %09%09if (ap
@@ -2601,17 +2601,16 @@
 pend) %7B%0A
-%0A
 %09%09%09value

Use whitespace-management setting when trim-attribute is not set by the user