Search in sources :

Example 6 with EvaluatorException

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

the class Function method checkFunctionName.

public static void checkFunctionName(String name, FunctionLib[] flibs, PageSource ps) throws EvaluatorException {
    FunctionLibFunction flf;
    for (int i = 0; i < flibs.length; i++) {
        flf = flibs[i].getFunction(name);
        if (flf != null && flf.getFunctionClassDefinition().getClazz(null) != CFFunction.class) {
            String path = null;
            if (ps != null) {
                path = ps.getDisplayPath();
                path = path.replace('\\', '/');
            }
            if (// TODO make better
            path == null || path.indexOf("/library/function/") == -1)
                throw new EvaluatorException("The name [" + name + "] is already used by a built in Function");
        }
    }
}
Also used : CFFunction(lucee.runtime.functions.system.CFFunction) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Example 7 with EvaluatorException

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

the class HttpParam method evaluate.

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

Example 8 with EvaluatorException

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

the class Interface method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    super.evaluate(tag, libTag);
    Body body = tag.getBody();
    List<Statement> statments = body.getStatements();
    Statement stat;
    Iterator<Statement> it = statments.iterator();
    Tag t;
    while (it.hasNext()) {
        stat = it.next();
        if (stat instanceof PrintOut) {
        // body.remove(stat);
        } else if (stat instanceof Tag) {
            t = (Tag) stat;
            if (stat instanceof TagImport) {
            // ignore
            } else if (stat instanceof TagFunction) {
                Function.throwIfNotEmpty(t);
                Attribute attr = t.getAttribute("access");
                if (attr != null) {
                    ExprString expr = t.getFactory().toExprString(attr.getValue());
                    if (!(expr instanceof LitString))
                        throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
                    String access = ((LitString) expr).getString().trim();
                    if (!"public".equalsIgnoreCase(access))
                        throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
                } else
                    t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
            } else
                throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
        }
    }
}
Also used : TagFunction(lucee.transformer.bytecode.statement.tag.TagFunction) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) Statement(lucee.transformer.bytecode.Statement) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) TagImport(lucee.transformer.bytecode.statement.tag.TagImport) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body)

Example 9 with EvaluatorException

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

the class Loop method execute.

@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
    TagLoop loop = (TagLoop) tag;
    // label
    try {
        if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
            LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
            String l = ls.getString();
            if (!StringUtil.isEmpty(l, true)) {
                loop.setLabel(l.trim());
                tag.removeAttribute("label");
            }
        }
    } catch (EvaluatorException e) {
        throw new TemplateException(null, e);
    }
    return null;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TemplateException(lucee.runtime.exp.TemplateException) LitString(lucee.transformer.expression.literal.LitString) TagLoop(lucee.transformer.bytecode.statement.tag.TagLoop)

Example 10 with EvaluatorException

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

the class Loop method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException {
    TagLoop loop = (TagLoop) tag;
    // attribute maxrows and endrow not allowd at the same time
    if (tag.containsAttribute("maxrows") && tag.containsAttribute("endrow"))
        throw new EvaluatorException("Wrong Context, you cannot use attribute maxrows and endrow at the same time.");
    // file loop
    if (tag.containsAttribute("file")) {
        if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
            throw new EvaluatorException("Wrong Context, when you use attribute file you must also use attribute index and/or item");
        loop.setType(TagLoop.TYPE_FILE);
        return;
    }
    // list loop
    if (tag.containsAttribute("list")) {
        if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
            throw new EvaluatorException("Wrong Context, when you use attribute list,you must define attribute index and/or item");
        loop.setType(TagLoop.TYPE_LIST);
        return;
    }
    // array loop
    if (tag.containsAttribute("array")) {
        if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
            throw new EvaluatorException("Wrong Context, when you use attribute array, you must define attribute index and/or item");
        loop.setType(TagLoop.TYPE_ARRAY);
        return;
    }
    // array loop
    if (tag.containsAttribute("times")) {
        if (tag.getAttributes().size() > 1)
            throw new EvaluatorException("Wrong Context, when you use attribute times, no other attributes are allowed");
        loop.setType(TagLoop.TYPE_TIMES);
        return;
    }
    // struct loop
    if (tag.containsAttribute("struct")) {
        if (!tag.containsAttribute("index") && !tag.containsAttribute("item") && !tag.containsAttribute("key") && !tag.containsAttribute("value"))
            throw new EvaluatorException("Wrong Context, when you use attribute struct, you must define attribute index (alias key) and/or item (alias value)");
        loop.setType(TagLoop.TYPE_STRUCT);
        return;
    }
    // collection loop
    if (tag.containsAttribute("collection")) {
        if (!tag.containsAttribute("index") && !tag.containsAttribute("item") && !tag.containsAttribute("key") && !tag.containsAttribute("value"))
            throw new EvaluatorException("Wrong Context, when you use attribute struct, you must define attribute index (alias key) and/or item (alias value)");
        loop.setType(TagLoop.TYPE_COLLECTION);
        return;
    }
    /*if(tag.containsAttribute("index")) {
			if(!tag.containsAttribute("from") || !tag.containsAttribute("to"))
				throw new EvaluatorException("Wrong Context, when you use attribute index you must also use attribute from and to or list or file");
			loop.setType(TagLoop.TYPE_INDEX);
            return;
		}*/
    if (tag.containsAttribute("from") || tag.containsAttribute("to")) {
        if (!tag.containsAttribute("from"))
            throw new EvaluatorException("Wrong Context, when you use attribute to, you must also use attribute from.");
        if (!tag.containsAttribute("to"))
            throw new EvaluatorException("Wrong Context, when you use attribute from, you must also use attribute to.");
        if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
            throw new EvaluatorException("Wrong Context, when you use attribute from and to, you must define attribute index or item.");
        if (tag.containsAttribute("index") && tag.containsAttribute("item"))
            throw new EvaluatorException("For this type of loop, you cannot use attribute index and item at the same time.");
        loop.setType(TagLoop.TYPE_FROM_TO);
        return;
    }
    // condition loop
    if (tag.containsAttribute("condition")) {
        if (tag.isScriptBase())
            throw new EvaluatorException("tag loop-condition is not supported within cfscript, use instead a while statement.");
        TagLib tagLib = tagLibTag.getTagLib();
        ExprTransformer transformer;
        String text = ASMUtil.getAttributeString(tag, "condition");
        try {
            transformer = tagLib.getExprTransfomer();
            Page page = ASMUtil.getAncestorPage(tag);
            ConfigImpl config = (ConfigImpl) page.getConfig();
            Expression expr = transformer.transform(BytecodeFactory.getInstance(config), page, new EvaluatorPool(), null, flibs, config.getCoreTagLib(page.getSourceCode().getDialect()).getScriptTags(), new SourceCode(text, false, page.getSourceCode().getDialect()), new TransfomerSettings(page.getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML && config.getDotNotationUpperCase(), page.getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML && config.getHandleUnQuotedAttrValueAsString(), page.ignoreScopes));
            tag.addAttribute(new Attribute(false, "condition", page.getFactory().toExprBoolean(expr), "boolean"));
        } catch (Exception e) {
            throw new EvaluatorException(e.getMessage());
        }
        loop.setType(TagLoop.TYPE_CONDITION);
        return;
    }
    // query loop
    if (tag.containsAttribute("query")) {
        loop.setType(TagLoop.TYPE_QUERY);
        return;
    }
    Info info = getParentInfo(loop);
    // query group
    if (tag.containsAttribute("group") && info.hasParentWithQuery) {
        loop.setType(TagLoop.TYPE_GROUP);
        return;
    }
    if (info.hasParentWithQuery) {
        if (info.hasParentWithGroup)
            loop.setType(TagLoop.TYPE_INNER_GROUP);
        else
            loop.setType(TagLoop.TYPE_INNER_QUERY);
        return;
    }
    /*
         if(hasQuery) 
        	output.setType(TagOutput.TYPE_QUERY);
        
        else if(tag.containsAttribute("group") && hasParentWithQuery)
        	output.setType(TagOutput.TYPE_GROUP);
        
        else if(hasParentWithQuery) {
        	if(hasParentWithGroup) output.setType(TagOutput.TYPE_INNER_GROUP);
        	else output.setType(TagOutput.TYPE_INNER_QUERY);
        }
        else
        	 output.setType(TagOutput.TYPE_NORMAL);
        
       
         */
    loop.setType(TagLoop.TYPE_NOTHING);
// throw new EvaluatorException("Wrong Context, invalid attributes in tag cfloop");
}
Also used : SourceCode(lucee.transformer.util.SourceCode) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprTransformer(lucee.transformer.cfml.ExprTransformer) Page(lucee.transformer.bytecode.Page) LitString(lucee.transformer.expression.literal.LitString) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TemplateException(lucee.runtime.exp.TemplateException) TransfomerSettings(lucee.transformer.cfml.TransfomerSettings) EvaluatorPool(lucee.transformer.cfml.evaluator.EvaluatorPool) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Expression(lucee.transformer.expression.Expression) TagLib(lucee.transformer.library.tag.TagLib) ConfigImpl(lucee.runtime.config.ConfigImpl) TagLoop(lucee.transformer.bytecode.statement.tag.TagLoop)

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