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 lucee.transformer.bytecode.statement.tag.Tag; 022import lucee.transformer.bytecode.statement.tag.TagIf; 023import lucee.transformer.bytecode.util.ASMUtil; 024import lucee.transformer.cfml.evaluator.EvaluatorException; 025import lucee.transformer.cfml.evaluator.EvaluatorSupport; 026import lucee.transformer.library.tag.TagLibTag; 027 028 029 030/** 031 * 032 * Prueft den Kontext des Tag else. 033 * Das Tag <code>else</code> darf nur direkt innerhalb des Tag <code>if</code> liegen. 034 * Dem Tag <code>else</code> darf, innerhalb des Tag <code>if</code>, kein Tag <code>if</code> nachgestellt sein. 035 * Das Tag darf auch nur einmal vorkommen innerhalb des Tag if. 036 */ 037public final class Else extends EvaluatorSupport { 038 039 /** 040 * @see lucee.transformer.cfml.evaluator.EvaluatorSupport#evaluate(org.w3c.dom.Element, lucee.transformer.library.tag.TagLibTag) 041 */ 042 public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException { 043 String ns=libTag.getTagLib().getNameSpaceAndSeparator(); 044 String ifName=ns+"if"; 045 046 // check if tag is direct inside if 047 if(!ASMUtil.isParentTag(tag, TagIf.class)) { 048 throw new EvaluatorException("Wrong Context, tag "+libTag.getFullName()+" must be direct inside a "+ifName+" tag"); 049 } 050 051 // check if is there a elseif tag after this tag 052 if(ASMUtil.hasSisterTagAfter(tag,"elseif")) 053 throw new EvaluatorException("Wrong Context, tag cfelseif can't be after tag else"); 054 // check if tag else is unique 055 if(ASMUtil.hasSisterTagWithSameName(tag)) 056 throw new EvaluatorException("Wrong Context, tag else must be once inside the tag if"); 057 058 } 059 060}