001    package railo.transformer.cfml.script;
002    
003    import railo.runtime.exp.TemplateException;
004    import railo.transformer.bytecode.Page;
005    import railo.transformer.bytecode.ScriptBody;
006    import railo.transformer.bytecode.statement.tag.Tag;
007    import railo.transformer.cfml.TransfomerSettings;
008    import railo.transformer.cfml.evaluator.EvaluatorPool;
009    import railo.transformer.cfml.expression.CFMLExprTransformer;
010    import railo.transformer.cfml.tag.CFMLTransformer;
011    import railo.transformer.cfml.tag.TagDependentBodyTransformer;
012    import railo.transformer.library.function.FunctionLib;
013    import railo.transformer.library.tag.TagLibTag;
014    import railo.transformer.util.CFMLString;
015    
016    
017    /**     
018     * Innerhalb des Tag script kann in CFML eine eigene Scriptsprache verwendet werden, 
019     * welche sich an Javascript orientiert. 
020     * Da der data.cfml Transformer keine Spezialfaelle zulaesst, 
021     * also Tags einfach anhand der eingegeben TLD einliest und transformiert, 
022     * aus diesem Grund wird der Inhalt des Tag script einfach als Zeichenkette eingelesen.
023     * Erst durch den Evaluator (siehe 3.3), der fuer das Tag script definiert ist, 
024     * wird der Inhalt des Tag script uebersetzt.
025     * 
026     */
027    public final class JavaScriptTransformer extends CFMLExprTransformer implements TagDependentBodyTransformer {
028            
029            public void transform(Page page,CFMLTransformer parent, EvaluatorPool ep,
030                            FunctionLib[] flibs, Tag tag, TagLibTag tagLibTag,TagLibTag[] scriptTags, CFMLString cfml,TransfomerSettings settings)
031                            throws TemplateException {
032                    
033                    StringBuilder sb=new StringBuilder();
034                    //MUST add again int startline=cfml.getLine();
035                    while(!cfml.isAfterLast() && !cfml.isCurrent("</",tagLibTag.getFullName())){
036                            sb.append(cfml.getCurrent());
037                            cfml.next();
038                    }
039                    //int endline=cfml.getLine();
040                    if(cfml.isAfterLast())
041                            throw new TemplateException(cfml,"missing end tag"); // TODO better error message
042                    
043                    
044                    if(true) throw new RuntimeException("not implemented");
045                    //MUST add again String dummyStart="public class Susi {public static void code(){"+StringUtil.repeatString("\n", startline-1);
046                    
047                    //MUST add again String dummyEnd="}}";
048                    //MUST add again String src=dummyStart+sb+dummyEnd;
049                    //MUST add again Label start=new Label();
050                    //MUST add again Label end=new Label();
051                    
052                    //MUST add again ByteArrayInputStream bais = new ByteArrayInputStream(src.getBytes());
053                    
054                    try {
055                            //MUST add again CompilationUnit cu = JavaParser.parse(bais);
056                            //MUST add again DataBag db = new DataBag();
057                            ScriptBody body=new ScriptBody();
058                            tag.setBody(body);
059                            //MUST add again new JavaParserVisitor(body,start,end).visit(cu, db);
060                            
061                    } 
062                    catch (Exception e) {
063                            throw new TemplateException(cfml,e);
064                    }
065            }
066    }