001 package railo.transformer.cfml.script; 002 003 import railo.runtime.exp.TemplateException; 004 import railo.transformer.bytecode.Page; 005 import railo.transformer.bytecode.cast.CastString; 006 import railo.transformer.bytecode.expression.Expression; 007 import railo.transformer.bytecode.literal.LitString; 008 import railo.transformer.bytecode.statement.tag.Attribute; 009 import railo.transformer.bytecode.statement.tag.Tag; 010 import railo.transformer.cfml.TransfomerSettings; 011 import railo.transformer.cfml.evaluator.EvaluatorPool; 012 import railo.transformer.cfml.tag.CFMLTransformer; 013 import railo.transformer.cfml.tag.TagDependentBodyTransformer; 014 import railo.transformer.library.function.FunctionLib; 015 import railo.transformer.library.tag.TagLibTag; 016 import railo.transformer.util.CFMLString; 017 018 public class CFMLOrJavaScriptTransformer implements TagDependentBodyTransformer { 019 020 private JavaScriptTransformer jst=new JavaScriptTransformer(); 021 private CFMLScriptTransformer cst=new CFMLScriptTransformer(); 022 023 public void transform(Page page,CFMLTransformer parent, EvaluatorPool ep,FunctionLib[] flibs, Tag tag, TagLibTag tagLibTag,TagLibTag[] scriptTags, CFMLString cfml,TransfomerSettings settings) 024 throws TemplateException { 025 Attribute attr = tag.getAttribute("language"); 026 if(attr!=null) { 027 Expression expr = CastString.toExprString(attr.getValue()); 028 if(!(expr instanceof LitString)) 029 throw new TemplateException(cfml,"Attribute language of the Tag script, must be a literal string value"); 030 String str = ((LitString)expr).getString().trim(); 031 if("java".equalsIgnoreCase(str)) jst.transform(page,parent, ep, flibs, tag, tagLibTag,scriptTags, cfml,settings); 032 else if("cfml".equalsIgnoreCase(str)) cst.transform(page,parent, ep, flibs, tag, tagLibTag,scriptTags, cfml,settings); 033 else 034 throw new TemplateException(cfml,"invalid value for attribute language from tag script ["+str+"], valid values are [cfml,java]"); 035 } 036 } 037 038 }