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.evaluator.impl;
020
021import java.util.Iterator;
022import java.util.List;
023
024import lucee.transformer.bytecode.Body;
025import lucee.transformer.bytecode.Statement;
026import lucee.transformer.bytecode.cast.CastString;
027import lucee.transformer.bytecode.expression.ExprString;
028import lucee.transformer.bytecode.literal.LitString;
029import lucee.transformer.bytecode.statement.PrintOut;
030import lucee.transformer.bytecode.statement.tag.Attribute;
031import lucee.transformer.bytecode.statement.tag.Tag;
032import lucee.transformer.bytecode.statement.tag.TagFunction;
033import lucee.transformer.bytecode.statement.tag.TagImport;
034import lucee.transformer.cfml.evaluator.EvaluatorException;
035import lucee.transformer.library.tag.TagLibTag;
036
037public class Interface extends Component {
038        /**
039         * @see lucee.transformer.cfml.evaluator.EvaluatorSupport#evaluate(org.w3c.dom.Element, lucee.transformer.library.tag.TagLibTag)
040         */
041        public void evaluate(Tag tag,TagLibTag libTag) throws EvaluatorException { 
042                super.evaluate(tag,libTag);
043                Body body = tag.getBody();
044                List statments = body.getStatements();
045                Statement stat;
046                Iterator it = statments.iterator();
047                Tag t;
048                while(it.hasNext()) {
049                        stat=(Statement) it.next();
050                        
051                        if(stat instanceof PrintOut) {
052                                //body.remove(stat);
053                        }
054                        else if(stat instanceof Tag) {
055                                t=(Tag) stat;
056                                if(stat instanceof TagImport) {
057                                        // ignore
058                                }
059                                else if(stat instanceof TagFunction) {
060                                        
061                                        Function.throwIfNotEmpty(t);
062                                        Attribute attr = t.getAttribute("access");
063                                        
064                                        if(attr!=null) {
065                                                ExprString expr = CastString.toExprString(attr.getValue());
066                                                
067                                                if(!(expr instanceof LitString))
068                                                        throw new EvaluatorException(
069                                                "the attribute access of the Tag function inside an interface must contain a constant value");
070                                                String access = ((LitString)expr).getString().trim();
071                                                if(!"public".equalsIgnoreCase(access))
072                                                        throw new EvaluatorException(
073                                                "the attribute access of the tag function inside an interface definition can only have the value [public] not ["+access+"]");
074                                        }
075                                        else t.addAttribute(new Attribute(false,"access",LitString.toExprString("public"),"string"));
076                                        
077                                }
078                                else throw new EvaluatorException("tag "+libTag.getFullName()+" can only contain function definitions.");
079                        }
080                }
081                
082                
083        }
084
085}