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