Search in sources :

Example 1 with TagImport

use of lucee.transformer.bytecode.statement.tag.TagImport 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 2 with TagImport

use of lucee.transformer.bytecode.statement.tag.TagImport 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 3 with TagImport

use of lucee.transformer.bytecode.statement.tag.TagImport in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method getImports.

private static void getImports(List<String> list, Body body) throws TransformerException {
    if (ASMUtil.isEmpty(body))
        return;
    Statement stat;
    List stats = body.getStatements();
    int len = stats.size();
    for (int i = 0; i < len; i++) {
        stat = (Statement) stats.get(i);
        // IFunction
        if (stat instanceof TagImport && !StringUtil.isEmpty(((TagImport) stat).getPath(), true)) {
            ImportDefintion id = ImportDefintionImpl.getInstance(((TagImport) stat).getPath(), null);
            if (id != null && (!list.contains(id.toString()) && !list.contains(id.getPackage() + ".*"))) {
                list.add(id.toString());
            }
            stats.remove(i);
            len--;
            i--;
        } else if (stat instanceof HasBody)
            getImports(list, ((HasBody) stat).getBody());
        else if (stat instanceof HasBodies) {
            Body[] bodies = ((HasBodies) stat).getBodies();
            for (int y = 0; y < bodies.length; y++) {
                getImports(list, bodies[y]);
            }
        }
    }
}
Also used : ImportDefintion(lucee.runtime.component.ImportDefintion) TagImport(lucee.transformer.bytecode.statement.tag.TagImport) HasBodies(lucee.transformer.bytecode.statement.HasBodies) HasBody(lucee.transformer.bytecode.statement.HasBody) List(java.util.List) ArrayList(java.util.ArrayList) HasBody(lucee.transformer.bytecode.statement.HasBody)

Aggregations

TagImport (lucee.transformer.bytecode.statement.tag.TagImport)3 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ImportDefintion (lucee.runtime.component.ImportDefintion)1 TemplateException (lucee.runtime.exp.TemplateException)1 Body (lucee.transformer.bytecode.Body)1 Statement (lucee.transformer.bytecode.Statement)1 HasBodies (lucee.transformer.bytecode.statement.HasBodies)1 HasBody (lucee.transformer.bytecode.statement.HasBody)1 PrintOut (lucee.transformer.bytecode.statement.PrintOut)1 Tag (lucee.transformer.bytecode.statement.tag.Tag)1 TagFunction (lucee.transformer.bytecode.statement.tag.TagFunction)1 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)1 ExprString (lucee.transformer.expression.ExprString)1 LitString (lucee.transformer.expression.literal.LitString)1 TagLibTag (lucee.transformer.library.tag.TagLibTag)1