Search in sources :

Example 1 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class EvaluatorPool method run.

/**
 * Die Methode run wird aufgerufen sobald, der CFML Transformer den uebersetzungsprozess angeschlossen hat.
 * Die metode run rauft darauf alle Evaluatoren auf die intern gespeicher wurden und loescht den internen Speicher.
 * @throws TemplateException
 */
public void run() throws TemplateException {
    {
        // tags
        Iterator<TagData> it = tags.iterator();
        while (it.hasNext()) {
            TagData td = it.next();
            SourceCode cfml = td.cfml;
            cfml.setPos(td.pos);
            try {
                if (td.libTag.getEvaluator() != null)
                    td.libTag.getEvaluator().evaluate(td.tag, td.libTag, td.flibs);
            } catch (EvaluatorException e) {
                // print.printST(e);
                clear();
                throw new TemplateException(cfml, e);
            } catch (Throwable e) {
                ExceptionUtil.rethrowIfNecessary(e);
                clear();
                throw new TemplateException(cfml, e);
            }
        }
        tags.clear();
    }
    // functions
    Iterator<FunctionData> it = functions.iterator();
    while (it.hasNext()) {
        FunctionData td = it.next();
        SourceCode cfml = td.cfml;
        cfml.setPos(td.pos);
        try {
            if (td.flf.getEvaluator() != null)
                td.flf.getEvaluator().evaluate(td.bif, td.flf);
        } catch (EvaluatorException e) {
            // print.printST(e);
            clear();
            throw new TemplateException(cfml, e);
        } catch (Throwable e) {
            ExceptionUtil.rethrowIfNecessary(e);
            clear();
            throw new TemplateException(cfml, e);
        }
    }
    functions.clear();
}
Also used : SourceCode(lucee.transformer.util.SourceCode) TemplateException(lucee.runtime.exp.TemplateException) Iterator(java.util.Iterator)

Example 2 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class Import method _executeTLD.

/**
 * @param fileTagLib
 * @return
 * @throws EvaluatorException
 */
private TagLib _executeTLD(Config config, Resource fileTagLib, String nameSpace, String nameSpaceSeparator, SourceCode cfml) throws TemplateException {
    // change extesnion
    String ext = ResourceUtil.getExtension(fileTagLib, null);
    if ("jar".equalsIgnoreCase(ext)) {
        // check anchestor file
        Resource newFileTagLib = ResourceUtil.changeExtension(fileTagLib, "tld");
        if (newFileTagLib.exists())
            fileTagLib = newFileTagLib;
        else // check inside jar
        {
            Resource tmp = getTLDFromJarAsFile(config, fileTagLib);
            if (tmp != null)
                fileTagLib = tmp;
        }
    }
    try {
        TagLib taglib = TagLibFactory.loadFromFile(fileTagLib, config.getIdentification());
        taglib.setNameSpace(nameSpace);
        taglib.setNameSpaceSeperator(nameSpaceSeparator);
        return taglib;
    } catch (TagLibException e) {
        throw new TemplateException(cfml, e.getMessage());
    }
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) TagLib(lucee.transformer.library.tag.TagLib) CustomTagLib(lucee.transformer.library.tag.CustomTagLib) Resource(lucee.commons.io.res.Resource) TagLibException(lucee.transformer.library.tag.TagLibException)

Example 3 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class Import method execute.

@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
    TagImport ti = (TagImport) tag;
    Attribute p = tag.getAttribute("prefix");
    Attribute t = tag.getAttribute("taglib");
    Attribute path = tag.getAttribute("path");
    if (p != null || t != null) {
        if (p == null)
            throw new TemplateException(data.srcCode, "Wrong Context, missing attribute [prefix] for tag " + tag.getFullname());
        if (t == null)
            throw new TemplateException(data.srcCode, "Wrong Context, missing attribute [taglib] for tag " + tag.getFullname());
        if (path != null)
            throw new TemplateException(data.srcCode, "Wrong context, you have an invalid attributes constellation for the tag " + tag.getFullname() + ", " + "you cannot mix attribute [path] with attributes [taglib] and [prefix]");
        return executePT(config, tag, libTag, flibs, data.srcCode);
    }
    if (path == null)
        throw new TemplateException(data.srcCode, "Wrong context, you have an invalid attributes constellation for the tag " + tag.getFullname() + ", " + "you need to define the attributes [prefix] and [taglib], the attribute [path] or simply define a attribute value");
    String strPath = ASMUtil.getAttributeString(tag, "path", null);
    if (strPath == null)
        throw new TemplateException(data.srcCode, "attribute [path] must be a constant value");
    ti.setPath(strPath);
    return null;
}
Also used : TagImport(lucee.transformer.bytecode.statement.tag.TagImport) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TemplateException(lucee.runtime.exp.TemplateException)

Example 4 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class Import method executePT.

private TagLib executePT(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, SourceCode sc) throws TemplateException {
    // Attribute prefix
    String nameSpace = ASMUtil.getAttributeString(tag, "prefix", null);
    if (nameSpace == null)
        throw new TemplateException(sc, "attribute [prefix] must be a constant value");
    nameSpace = nameSpace.trim();
    String nameSpaceSeparator = StringUtil.isEmpty(nameSpace) ? "" : ":";
    // Attribute taglib
    String textTagLib = ASMUtil.getAttributeString(tag, "taglib", null);
    if (textTagLib == null)
        throw new TemplateException(sc, "attribute [taglib] must be a constant value");
    textTagLib = textTagLib.replace('\\', '/');
    textTagLib = ConfigWebUtil.replacePlaceholder(textTagLib, config);
    // File TagLib
    String ext = ResourceUtil.getExtension(textTagLib, null);
    boolean hasTldExtension = "tld".equalsIgnoreCase(ext) || "tldx".equalsIgnoreCase(ext);
    Resource absFile = config.getResource(textTagLib);
    // TLD
    if (absFile.isFile())
        return _executeTLD(config, absFile, nameSpace, nameSpaceSeparator, sc);
    // Second Change
    if (textTagLib.startsWith("/")) {
        // config.getPhysical(textTagLib);
        PageSource ps = ((ConfigImpl) config).getPageSourceExisting(null, null, textTagLib, false, false, true, false);
        // config.getConfigDir()
        if (ps != null) {
            if (ps.physcalExists()) {
                Resource file = ps.getPhyscalFile();
                // TLD
                if (file.isFile())
                    return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
            }
            // CTD
            if (!hasTldExtension)
                return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
        }
    } else {
        PageSource ps = sc instanceof PageSourceCode ? ((PageSourceCode) sc).getPageSource() : null;
        Resource sourceFile = ps == null ? null : ps.getPhyscalFile();
        if (sourceFile != null) {
            Resource file = sourceFile.getParentResource().getRealResource(textTagLib);
            // TLD
            if (file.isFile())
                return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
            // CTD
            if (!hasTldExtension)
                return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
        }
    }
    throw new TemplateException(sc, "invalid definition of the attribute taglib [" + textTagLib + "]");
}
Also used : PageSourceCode(lucee.transformer.util.PageSourceCode) TemplateException(lucee.runtime.exp.TemplateException) Resource(lucee.commons.io.res.Resource) ConfigImpl(lucee.runtime.config.ConfigImpl) PageSource(lucee.runtime.PageSource)

Example 5 with TemplateException

use of lucee.runtime.exp.TemplateException 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)

Aggregations

TemplateException (lucee.runtime.exp.TemplateException)55 Position (lucee.transformer.Position)21 Expression (lucee.transformer.expression.Expression)18 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)15 LitString (lucee.transformer.expression.literal.LitString)14 ScriptBody (lucee.transformer.bytecode.ScriptBody)9 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 Body (lucee.transformer.bytecode.Body)8 BodyBase (lucee.transformer.bytecode.BodyBase)8 FunctionBody (lucee.transformer.bytecode.FunctionBody)8 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)8 Variable (lucee.transformer.expression.var.Variable)8 ExprString (lucee.transformer.expression.ExprString)7 TagLibTag (lucee.transformer.library.tag.TagLibTag)6 PageSourceCode (lucee.transformer.util.PageSourceCode)6 ArrayList (java.util.ArrayList)5 OpVariable (lucee.transformer.bytecode.op.OpVariable)5 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)5 Resource (lucee.commons.io.res.Resource)4 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)4