001    package railo.transformer.cfml.evaluator.impl;
002    
003    import railo.transformer.bytecode.Statement;
004    import railo.transformer.bytecode.statement.tag.Tag;
005    import railo.transformer.bytecode.statement.tag.TagOutput;
006    import railo.transformer.cfml.evaluator.EvaluatorException;
007    import railo.transformer.cfml.evaluator.EvaluatorSupport;
008    import railo.transformer.library.tag.TagLibTag;
009    
010    
011    /**
012     * Prueft den Kontext des Tag output.
013     * Das Tag output darf nicht innerhalb eines output Tag verschachtelt sein, 
014     * ausser das aeussere Tag besitzt ein group Attribute. Das innere Tag darf jedoch kein group Attribute besitzen.
015    
016     */
017    public final class Output extends EvaluatorSupport {
018    
019            /**
020             * @see railo.transformer.cfml.evaluator.EvaluatorSupport#evaluate(org.w3c.dom.Element, railo.transformer.library.tag.TagLibTag)
021             */
022            public void evaluate(Tag tag,TagLibTag libTag) throws EvaluatorException { 
023                    
024                    TagOutput output=(TagOutput) tag;
025                    
026            // check if inside a query tag
027                    TagOutput parent = output;
028            boolean hasParentWithGroup=false;
029            boolean hasParentWithQuery=false;
030                    boolean hasQuery=tag.containsAttribute("query");
031                    
032                    while((parent=getParentTagOutput(parent))!=null) {
033                if(!hasParentWithQuery)hasParentWithQuery=parent.hasQuery();
034                if(!hasParentWithGroup)hasParentWithGroup=parent.hasGroup();
035                if(hasParentWithQuery && hasParentWithGroup)break;
036                    }
037            
038            if(hasQuery && hasParentWithQuery) 
039                            throw new EvaluatorException("Nesting of tags cfoutput with attribute query is not allowed");
040    
041            if(hasQuery) 
042                    output.setType(TagOutput.TYPE_QUERY);
043            
044            else if(tag.containsAttribute("group") && hasParentWithQuery)
045                    output.setType(TagOutput.TYPE_GROUP);
046            
047            else if(hasParentWithQuery) {
048                    if(hasParentWithGroup) output.setType(TagOutput.TYPE_INNER_GROUP);
049                    else output.setType(TagOutput.TYPE_INNER_QUERY);
050            }
051            else
052                     output.setType(TagOutput.TYPE_NORMAL);
053            
054            
055            
056            // attribute maxrows and endrow not allowd at the same time
057            if(tag.containsAttribute("maxrows") && tag.containsAttribute("endrow"))
058                    throw new EvaluatorException("Wrong Context, you cannot use attribute maxrows and endrow at the same time.");
059            
060            
061            }
062            
063            public static TagOutput getParentTagOutput(TagOutput stat) {
064                    Statement parent = stat;
065                    
066                    
067                    while(true)     {
068                            parent=parent.getParent();
069                            if(parent==null)return null;
070                            if(parent instanceof TagOutput) return (TagOutput) parent;
071                    }
072            }
073    }
074    
075    
076    
077