001    package railo.transformer.cfml.evaluator.impl;
002    
003    import railo.commons.lang.StringUtil;
004    import railo.transformer.bytecode.cast.CastString;
005    import railo.transformer.bytecode.literal.LitString;
006    import railo.transformer.bytecode.statement.tag.Attribute;
007    import railo.transformer.bytecode.statement.tag.Tag;
008    import railo.transformer.bytecode.statement.tag.TagContinue;
009    import railo.transformer.bytecode.util.ASMUtil;
010    import railo.transformer.cfml.evaluator.EvaluatorException;
011    import railo.transformer.cfml.evaluator.EvaluatorSupport;
012    import railo.transformer.library.tag.TagLibTag;
013    
014    
015    
016    /**
017     * Prueft den Kontext des Tag continue.
018     * Das Tag <code>break</code> darf nur innerhalb des Tag <code>loop, while, foreach</code> liegen.
019     */
020    public final class Continue extends EvaluatorSupport {
021    
022            @Override
023            public void evaluate(Tag tag,TagLibTag libTag) throws EvaluatorException { 
024                    String ns=libTag.getTagLib().getNameSpaceAndSeparator();
025                    String loopName=ns+"loop";
026                    String whileName=ns+"while";
027                    
028                    // label
029                    String label=null;
030                    Attribute attrLabel = tag.getAttribute("label");
031                    if(attrLabel!=null){
032                            TagContinue tc=(TagContinue) tag;
033                            label=Break.variableToString(tag,attrLabel,null);
034                            if(label!=null){
035                                    tc.setLabel(label=label.trim());
036                                    tag.removeAttribute("label");
037                            }
038                            else if(ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
039                                    LitString ls=(LitString) CastString.toExprString(tag.getAttribute("label").getValue());
040                                    label = ls.getString();
041                                    if(!StringUtil.isEmpty(label,true)) {
042                                            tc.setLabel(label=label.trim());
043                                            tag.removeAttribute("label");
044                                    }
045                                    else label=null;
046                            }
047                    }
048                    
049                    if(ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
050                            LitString ls=(LitString) CastString.toExprString(tag.getAttribute("label").getValue());
051                            TagContinue tc=(TagContinue) tag;
052                            label = ls.getString();
053                            if(!StringUtil.isEmpty(label,true)) {
054                                    tc.setLabel(label=label.trim());
055                                    tag.removeAttribute("label");
056                            }
057                            else label=null;
058                    }
059                    
060                    if(!ASMUtil.hasAncestorContinueFCStatement(tag,label)) {
061                            if(tag.isScriptBase()) {
062                                    if(StringUtil.isEmpty(label))
063                                            throw new EvaluatorException("Wrong Context, "+libTag.getName()+" must be inside a loop (for,while,loop ...)");
064                                    throw new EvaluatorException("Wrong Context, "+libTag.getName()+" must be inside a loop (for,while,loop ...) with the label ["+label+"]");
065                                    
066                            }
067                            if(StringUtil.isEmpty(label))
068                                    throw new EvaluatorException("Wrong Context, tag "+libTag.getFullName()+" must be inside a "+loopName+" or "+whileName+" tag");
069                            throw new EvaluatorException("Wrong Context, tag "+libTag.getFullName()+" must be inside a "+loopName+" or "+whileName+" tag with the label ["+label+"]");
070                            
071                    }
072            }
073    }