Search in sources :

Example 21 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class Component method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag tlt) throws EvaluatorException {
    /*if(tag instanceof TagOther) {
			print.e(((TagOther)tag).getFullname());
		}*/
    TagCIObject tc = (TagCIObject) tag;
    Statement pPage = tag.getParent();
    // String className=tag.getTagLibTag().getTagClassName();
    Page page;
    // move components inside script to root
    if (pPage instanceof Page) {
        page = (Page) pPage;
    } else {
        // is in script
        Tag p = ASMUtil.getParentTag(tag);
        if ((pPage = p.getParent()) instanceof Page && p.getTagLibTag().getName().equalsIgnoreCase(((Page) pPage).getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME)) {
            // chnaged order of the condition, not sure if this is ok
            page = (Page) pPage;
            // move imports from script to component body
            List<Statement> children = p.getBody().getStatements();
            Iterator<Statement> it = children.iterator();
            Statement stat;
            Tag t;
            while (it.hasNext()) {
                stat = it.next();
                if (!(stat instanceof Tag))
                    continue;
                t = (Tag) stat;
                if (t.getTagLibTag().getName().equals("import")) {
                    tag.getBody().addStatement(t);
                }
            }
            // move to page
            ASMUtil.move(tag, page);
        // if(!inline)ASMUtil.replace(p, tag, false);
        } else
            throw new EvaluatorException("Wrong Context, tag " + tlt.getFullName() + " can't be inside other tags, tag is inside tag " + p.getFullname());
    }
    // Page page=(Page) pPage;
    Boolean insideCITemplate = isInsideCITemplate(page);
    boolean main = isMainComponent(page, tc);
    // is a full grown component or a inline component
    if (insideCITemplate == Boolean.FALSE) {
        throw new EvaluatorException("Wrong Context, " + tlt.getFullName() + " tag must be inside a file with the extension " + Constants.getCFMLComponentExtension() + " or " + Constants.getLuceeComponentExtension());
    }
    // if(count>1)
    // throw new EvaluatorException("inside one cfc file only one tag "+tlt.getFullName()+" is allowed, now we have "+count);
    boolean isComponent = tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Component");
    /*boolean isInterface="lucee.runtime.tag.Interface".equals(tlt.getTagClassName());
		if(main) {
			if(isComponent)			page.setIsComponent(true);
			else if(isInterface)	page.setIsInterface(true);
		}*/
    tc.setMain(main);
    // Attributes
    // Name
    String name = null;
    if (!main) {
        Map<String, Attribute> attrs = tag.getAttributes();
        if (attrs.size() > 0) {
            Attribute first = attrs.values().iterator().next();
            if (first.isDefaultValue()) {
                name = first.getName();
            }
        }
        if (name == null) {
            Attribute attr = tag.getAttribute("name");
            if (attr != null) {
                Expression expr = tag.getFactory().toExprString(attr.getValue());
                if (!(expr instanceof LitString))
                    throw new EvaluatorException("Name of the component " + tlt.getFullName() + ", must be a literal string value");
                name = ((LitString) expr).getString();
            } else
                throw new EvaluatorException("Missing name of the component " + tlt.getFullName() + "");
        }
        tc.setName(name);
    }
    // output
    // "output=true" is handled in "lucee.transformer.cfml.attributes.impl.Function"
    Attribute attr = tag.getAttribute("output");
    if (attr != null) {
        Expression expr = tag.getFactory().toExprBoolean(attr.getValue());
        if (!(expr instanceof LitBoolean))
            throw new EvaluatorException("Attribute output of the Tag " + tlt.getFullName() + ", must contain a static boolean value (true or false, yes or no)");
    // boolean output = ((LitBoolean)expr).getBooleanValue();
    // if(!output) ASMUtil.removeLiterlChildren(tag, true);
    }
    // extends
    attr = tag.getAttribute("extends");
    if (attr != null) {
        Expression expr = tag.getFactory().toExprString(attr.getValue());
        if (!(expr instanceof LitString))
            throw new EvaluatorException("Attribute extends of the Tag " + tlt.getFullName() + ", must contain a literal string value");
    }
    // implements
    if (isComponent) {
        attr = tag.getAttribute("implements");
        if (attr != null) {
            Expression expr = tag.getFactory().toExprString(attr.getValue());
            if (!(expr instanceof LitString))
                throw new EvaluatorException("Attribute implements of the Tag " + tlt.getFullName() + ", must contain a literal string value");
        }
    }
    // modifier
    if (isComponent) {
        attr = tag.getAttribute("modifier");
        if (attr != null) {
            Expression expr = tag.getFactory().toExprString(attr.getValue());
            if (!(expr instanceof LitString))
                throw new EvaluatorException("Attribute modifier of the Tag " + tlt.getFullName() + ", must contain a literal string value");
            LitString ls = (LitString) expr;
            int mod = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, -1);
            if (mod == -1)
                throw new EvaluatorException("Value [" + ls.getString() + "] from attribute modifier of the Tag " + tlt.getFullName() + " is invalid,valid values are [none,abstract,final]");
        }
    }
}
Also used : Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Statement(lucee.transformer.bytecode.Statement) Page(lucee.transformer.bytecode.Page) LitBoolean(lucee.transformer.expression.literal.LitBoolean) LitString(lucee.transformer.expression.literal.LitString) LitString(lucee.transformer.expression.literal.LitString) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Expression(lucee.transformer.expression.Expression) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) LitBoolean(lucee.transformer.expression.literal.LitBoolean) TagCIObject(lucee.transformer.bytecode.statement.tag.TagCIObject)

Example 22 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class Continue method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String loopName = ns + "loop";
    String whileName = ns + "while";
    // label
    String label = null;
    Attribute attrLabel = tag.getAttribute("label");
    if (attrLabel != null) {
        TagContinue tc = (TagContinue) tag;
        label = Break.variableToString(tag, attrLabel, null);
        if (label != null) {
            tc.setLabel(label = label.trim());
            tag.removeAttribute("label");
        } else if (ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
            LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
            label = ls.getString();
            if (!StringUtil.isEmpty(label, true)) {
                tc.setLabel(label = label.trim());
                tag.removeAttribute("label");
            } else
                label = null;
        }
    }
    if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
        LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
        TagContinue tc = (TagContinue) tag;
        label = ls.getString();
        if (!StringUtil.isEmpty(label, true)) {
            tc.setLabel(label = label.trim());
            tag.removeAttribute("label");
        } else
            label = null;
    }
    if (!ASMUtil.hasAncestorContinueFCStatement(tag, label)) {
        if (tag.isScriptBase()) {
            if (StringUtil.isEmpty(label))
                throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...)");
            throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...) with the label [" + label + "]");
        }
        if (StringUtil.isEmpty(label))
            throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag");
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag with the label [" + label + "]");
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) TagContinue(lucee.transformer.bytecode.statement.tag.TagContinue) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) LitString(lucee.transformer.expression.literal.LitString)

Example 23 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class Function method throwIfNotEmpty.

public static void throwIfNotEmpty(Tag tag) throws EvaluatorException {
    Body body = tag.getBody();
    List<Statement> statments = body.getStatements();
    Statement stat;
    Iterator<Statement> it = statments.iterator();
    TagLibTag tlt;
    while (it.hasNext()) {
        stat = it.next();
        if (stat instanceof Tag) {
            tlt = ((Tag) stat).getTagLibTag();
            if (!tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Argument"))
                throw new EvaluatorException("tag " + tlt.getFullName() + " is not allowed inside a function declaration");
        }
    /*else if(stat instanceof PrintOut) {
				//body.remove(stat);
			}*/
    }
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Statement(lucee.transformer.bytecode.Statement) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) StaticBody(lucee.transformer.bytecode.StaticBody) Body(lucee.transformer.bytecode.Body)

Example 24 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class InvokeArgument method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String invokeName = ns + "invoke";
    // check if tag is direct inside if
    if (!ASMUtil.hasAncestorTag(tag, invokeName))
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + invokeName + " tag");
}
Also used : EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException)

Example 25 with EvaluatorException

use of lucee.transformer.cfml.evaluator.EvaluatorException in project Lucee by lucee.

the class MailPart method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    // check parent
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String mailName = ns + "mail";
    if (!ASMUtil.hasAncestorTag(tag, mailName))
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + mailName + " tag");
}
Also used : EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException)

Aggregations

EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)28 LitString (lucee.transformer.expression.literal.LitString)10 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 Tag (lucee.transformer.bytecode.statement.tag.Tag)6 Body (lucee.transformer.bytecode.Body)5 Statement (lucee.transformer.bytecode.Statement)5 ExprString (lucee.transformer.expression.ExprString)5 Expression (lucee.transformer.expression.Expression)5 TagLibTag (lucee.transformer.library.tag.TagLibTag)5 TemplateException (lucee.runtime.exp.TemplateException)4 Page (lucee.transformer.bytecode.Page)4 TransformerException (lucee.transformer.TransformerException)3 StaticBody (lucee.transformer.bytecode.StaticBody)3 Literal (lucee.transformer.expression.literal.Literal)3 TagIf (lucee.transformer.bytecode.statement.tag.TagIf)2 TagLoop (lucee.transformer.bytecode.statement.tag.TagLoop)2 LitBoolean (lucee.transformer.expression.literal.LitBoolean)2 TagLib (lucee.transformer.library.tag.TagLib)2 SourceCode (lucee.transformer.util.SourceCode)2 Iterator (java.util.Iterator)1