001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.transformer.cfml.script; 020 021import lucee.runtime.exp.TemplateException; 022import lucee.transformer.bytecode.Page; 023import lucee.transformer.bytecode.cast.CastString; 024import lucee.transformer.bytecode.expression.Expression; 025import lucee.transformer.bytecode.literal.LitString; 026import lucee.transformer.bytecode.statement.tag.Attribute; 027import lucee.transformer.bytecode.statement.tag.Tag; 028import lucee.transformer.cfml.TransfomerSettings; 029import lucee.transformer.cfml.evaluator.EvaluatorPool; 030import lucee.transformer.cfml.tag.CFMLTransformer; 031import lucee.transformer.cfml.tag.TagDependentBodyTransformer; 032import lucee.transformer.library.function.FunctionLib; 033import lucee.transformer.library.tag.TagLib; 034import lucee.transformer.library.tag.TagLibTag; 035import lucee.transformer.util.CFMLString; 036 037public class CFMLOrJavaScriptTransformer implements TagDependentBodyTransformer { 038 039 private JavaScriptTransformer jst=new JavaScriptTransformer(); 040 private CFMLScriptTransformer cst=new CFMLScriptTransformer(); 041 042 @Override 043 public void transform(Page page,CFMLTransformer parent, EvaluatorPool ep,TagLib[][] tlibs, FunctionLib[] flibs, Tag tag, TagLibTag tagLibTag,TagLibTag[] scriptTags, CFMLString cfml,TransfomerSettings settings) 044 throws TemplateException { 045 Attribute attr = tag.getAttribute("language"); 046 if(attr!=null) { 047 Expression expr = CastString.toExprString(attr.getValue()); 048 if(!(expr instanceof LitString)) 049 throw new TemplateException(cfml,"Attribute language of the Tag script, must be a literal string value"); 050 String str = ((LitString)expr).getString().trim(); 051 if("java".equalsIgnoreCase(str)) jst.transform(page,parent, ep, tlibs,flibs, tag, tagLibTag,scriptTags, cfml,settings); 052 else if("cfml".equalsIgnoreCase(str)) cst.transform(page,parent, ep, tlibs,flibs, tag, tagLibTag,scriptTags, cfml,settings); 053 else 054 throw new TemplateException(cfml,"invalid value for attribute language from tag script ["+str+"], valid values are [cfml,java]"); 055 } 056 } 057 058}