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.ScriptBody;
024import lucee.transformer.bytecode.statement.tag.Tag;
025import lucee.transformer.cfml.TransfomerSettings;
026import lucee.transformer.cfml.evaluator.EvaluatorPool;
027import lucee.transformer.cfml.expression.CFMLExprTransformer;
028import lucee.transformer.cfml.tag.CFMLTransformer;
029import lucee.transformer.cfml.tag.TagDependentBodyTransformer;
030import lucee.transformer.library.function.FunctionLib;
031import lucee.transformer.library.tag.TagLib;
032import lucee.transformer.library.tag.TagLibTag;
033import lucee.transformer.util.CFMLString;
034
035
036/**     
037 * Innerhalb des Tag script kann in CFML eine eigene Scriptsprache verwendet werden, 
038 * welche sich an Javascript orientiert. 
039 * Da der data.cfml Transformer keine Spezialfaelle zulaesst, 
040 * also Tags einfach anhand der eingegeben TLD einliest und transformiert, 
041 * aus diesem Grund wird der Inhalt des Tag script einfach als Zeichenkette eingelesen.
042 * Erst durch den Evaluator (siehe 3.3), der fuer das Tag script definiert ist, 
043 * wird der Inhalt des Tag script uebersetzt.
044 * 
045 */
046public final class JavaScriptTransformer extends CFMLExprTransformer implements TagDependentBodyTransformer {
047        
048        @Override
049        public void transform(Page page,CFMLTransformer parent, EvaluatorPool ep,
050                        TagLib[][] tlibs, FunctionLib[] flibs, Tag tag, TagLibTag tagLibTag,TagLibTag[] scriptTags, CFMLString cfml,TransfomerSettings settings)
051                        throws TemplateException {
052                
053                StringBuilder sb=new StringBuilder();
054                //MUST add again int startline=cfml.getLine();
055                while(!cfml.isAfterLast() && !cfml.isCurrent("</",tagLibTag.getFullName())){
056                        sb.append(cfml.getCurrent());
057                        cfml.next();
058                }
059                //int endline=cfml.getLine();
060                if(cfml.isAfterLast())
061                        throw new TemplateException(cfml,"missing end tag"); // TODO better error message
062                
063                
064                if(true) throw new RuntimeException("not implemented");
065                //MUST add again String dummyStart="public class Susi {public static void code(){"+StringUtil.repeatString("\n", startline-1);
066                
067                //MUST add again String dummyEnd="}}";
068                //MUST add again String src=dummyStart+sb+dummyEnd;
069                //MUST add again Label start=new Label();
070                //MUST add again Label end=new Label();
071                
072                //MUST add again ByteArrayInputStream bais = new ByteArrayInputStream(src.getBytes());
073                
074                try {
075                        //MUST add again CompilationUnit cu = JavaParser.parse(bais);
076                        //MUST add again DataBag db = new DataBag();
077                        ScriptBody body=new ScriptBody();
078                        tag.setBody(body);
079                        //MUST add again new JavaParserVisitor(body,start,end).visit(cu, db);
080                        
081                } 
082                catch (Exception e) {
083                        throw new TemplateException(cfml,e);
084                }
085        }
086}