/**
 * Implements the Cold Fusion Function writeoutput
 */
package railo.runtime.functions.other;


import java.io.PrintStream;

import railo.commons.lang.ExceptionUtil;
import railo.commons.lang.StringUtil;
import railo.runtime.PageContext;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.functions.dynamicEvaluation.Serialize;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;

public final class SystemOutput implements Function {
    public static boolean call(PageContext pc , Object obj) throws PageException {
        return call(pc, obj, false,false);
    }
    public static boolean call(PageContext pc , Object obj, boolean addNewLine) throws PageException {
        return call(pc, obj, addNewLine, false);
    }
    public static boolean call(PageContext pc , Object obj, boolean addNewLine,boolean doErrorStream) throws PageException {
    	String string;
    	if(Decision.isSimpleValue(obj))string=Caster.toString(obj);
    	else string=Serialize.call(pc, obj);
    	
    	
    	PrintStream stream = System.out;
    	//string+=":"+Thread.currentThread().getId();
    	if(doErrorStream) stream = System.err;
        if(string!=null && StringUtil.indexOfIgnoreCase(string,"<print-stack-trace>")!=-1){
        	String st = ExceptionUtil.getStacktrace(new Exception("Stack trace"), false);
        	string=StringUtil.replace(string, "<print-stack-trace>", "\n"+st+"\n", true).trim();
        }
        if(addNewLine)stream.println(string);
        else stream.print(string);
        
    	return true;
    }
}
@@ -1191,20 +1191,17 @@
 rr;%0A    
-    
+%09
 if(strin
@@ -1211,12 +1211,21 @@
 null
- && 
+) %7B%0A%09    %09if(
 Stri
@@ -1285,16 +1285,17 @@
 )!=-1)%7B%0A
+%09
         
@@ -1369,24 +1369,25 @@
 %22), false);%0A
+%09
         %09str
@@ -1464,24 +1464,25 @@
 ue).trim();%0A
+%09
         %7D%0A  
@@ -1475,24 +1475,226 @@
 %0A%09        %7D%0A
+%09    %09if(StringUtil.indexOfIgnoreCase(string,%22%3Chash-code%3E%22)!=-1)%7B%0A%09        %09String st = obj.hashCode()+%22%22;%0A%09        %09string=StringUtil.replace(string, %22%3Chash-code%3E%22, st, true).trim();%0A%09        %7D%0A    %09%7D%0A
         if(a

add support for outputting hashcode from a object