001 package railo.runtime.functions.conversion; 002 003 import railo.runtime.PageContext; 004 import railo.runtime.converter.ConverterException; 005 import railo.runtime.converter.JSConverter; 006 import railo.runtime.exp.PageException; 007 import railo.runtime.ext.function.Function; 008 import railo.runtime.op.Caster; 009 010 /** 011 * 012 */ 013 public final class ToScript implements Function { 014 015 public static String call(PageContext pc, Object var, String jsName) throws PageException { 016 return call(pc,var,jsName,true,false); 017 } 018 public static String call(PageContext pc, Object var, String jsName,boolean outputFormat) throws PageException { 019 return call(pc,var,jsName,outputFormat,false); 020 } 021 public static String call(PageContext pc, Object var, String jsName,boolean outputFormat, boolean asFormat) throws PageException { 022 //if(!Decision.isVariableName(jsName)) 023 // throw new FunctionException(pc,"toScript",2,"jsName","value does not contain a valid variable String"); 024 025 JSConverter converter = new JSConverter(); 026 converter.useShortcuts(asFormat); 027 converter.useWDDX(outputFormat); 028 029 030 try { 031 return converter.serialize(var,jsName); 032 } 033 catch (ConverterException e) { 034 throw Caster.toPageException(e); 035 } 036 } 037 }