Search in sources :

Example 16 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.

the class CFMLTransformer method transform.

/**
 * Startmethode zum transfomieren einer CFML Datei.
 * <br />
 * EBNF:<br />
 * <code>{body}</code>
 * @param config
 * @param ps CFML File
 * @param tlibs Tag Library Deskriptoren, nach denen innerhalb der CFML Datei geprueft werden soll.
 * @param flibs Function Library Deskriptoren, nach denen innerhalb der Expressions der CFML Datei geprueft werden soll.
 * @param returnValue if true the method returns the value of the last expression executed inside when you call the method "call"
 * @return uebersetztes CFXD Dokument Element.
 * @throws TemplateException
 * @throws IOException
 */
public Page transform(Factory factory, ConfigImpl config, PageSource ps, TagLib[] tlibs, FunctionLib[] flibs, boolean returnValue, boolean ignoreScopes) throws TemplateException, IOException {
    Page p;
    SourceCode sc;
    boolean writeLog = config.getExecutionLogEnabled();
    Charset charset = config.getTemplateCharset();
    boolean dotUpper = ps.getDialect() == CFMLEngine.DIALECT_CFML && ((MappingImpl) ps.getMapping()).getDotNotationUpperCase();
    // parse regular
    while (true) {
        try {
            sc = new PageSourceCode(ps, charset, writeLog);
            p = transform(factory, config, sc, tlibs, flibs, ps.getResource().lastModified(), dotUpper, returnValue, ignoreScopes);
            break;
        } catch (ProcessingDirectiveException pde) {
            if (pde.getWriteLog() != null)
                writeLog = pde.getWriteLog().booleanValue();
            if (pde.getDotNotationUpperCase() != null)
                dotUpper = pde.getDotNotationUpperCase().booleanValue();
            if (!StringUtil.isEmpty(pde.getCharset()))
                charset = pde.getCharset();
        }
    }
    // could it be a component?
    boolean isCFML = ps.getDialect() == CFMLEngine.DIALECT_CFML;
    boolean isCFMLCompExt = isCFML && Constants.isCFMLComponentExtension(ResourceUtil.getExtension(ps.getResource(), ""));
    boolean possibleUndetectedComponent = false;
    // we don't have a component or interface
    if (p.isPage()) {
        if (isCFML)
            possibleUndetectedComponent = isCFMLCompExt;
        else if (Constants.isLuceeComponentExtension(ResourceUtil.getExtension(ps.getResource(), ""))) {
            Expression expr;
            Statement stat;
            PrintOut po;
            LitString ls;
            List<Statement> statements = p.getStatements();
            // check the root statements for component
            Iterator<Statement> it = statements.iterator();
            String str;
            while (it.hasNext()) {
                stat = it.next();
                if (stat instanceof PrintOut && (expr = ((PrintOut) stat).getExpr()) instanceof LitString) {
                    ls = (LitString) expr;
                    str = ls.getString();
                    if (str.indexOf(Constants.LUCEE_COMPONENT_TAG_NAME) != -1 || str.indexOf(Constants.LUCEE_INTERFACE_TAG_NAME) != -1 || // cfml name is supported as alias
                    str.indexOf(Constants.CFML_COMPONENT_TAG_NAME) != -1) {
                        possibleUndetectedComponent = true;
                        break;
                    }
                }
            }
        }
    }
    /*if(p.isPage() && (isCFML?
				Constants.isCFMLComponentExtension(ResourceUtil.getExtension(ps.getResource(),"")):
				Constants.isLuceeComponentExtension(ResourceUtil.getExtension(ps.getResource(),""))) &&
				isPossibleRawScript(sc,config.getIdentification())){*/
    if (possibleUndetectedComponent) {
        Page _p;
        TagLibTag scriptTag = CFMLTransformer.getTLT(sc, isCFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME, config.getIdentification());
        sc.setPos(0);
        SourceCode original = sc;
        // try inside a cfscript
        String text = "<" + scriptTag.getFullName() + ">" + original.getText() + "\n</" + scriptTag.getFullName() + ">";
        sc = new PageSourceCode(ps, text, charset, writeLog);
        try {
            while (true) {
                if (sc == null) {
                    sc = new PageSourceCode(ps, charset, writeLog);
                    text = "<" + scriptTag.getFullName() + ">" + sc.getText() + "\n</" + scriptTag.getFullName() + ">";
                    sc = new PageSourceCode(ps, text, charset, writeLog);
                }
                try {
                    _p = transform(factory, config, sc, tlibs, flibs, ps.getResource().lastModified(), dotUpper, returnValue, ignoreScopes);
                    break;
                } catch (ProcessingDirectiveException pde) {
                    if (pde.getWriteLog() != null)
                        writeLog = pde.getWriteLog().booleanValue();
                    if (pde.getDotNotationUpperCase() != null)
                        dotUpper = pde.getDotNotationUpperCase().booleanValue();
                    if (!StringUtil.isEmpty(pde.getCharset()))
                        charset = pde.getCharset();
                    sc = null;
                }
            }
        } catch (ComponentTemplateException e) {
            throw e.getTemplateException();
        }
        // we only use that result if it is a component now
        if (_p != null && !_p.isPage())
            return _p;
    }
    if (isCFMLCompExt && !p.isComponent() && !p.isInterface()) {
        String msg = "template [" + ps.getDisplayPath() + "] must contain a component or an interface.";
        if (sc != null)
            throw new TemplateException(sc, msg);
        throw new TemplateException(msg);
    }
    return p;
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) PageSourceCode(lucee.transformer.util.PageSourceCode) SourceCode(lucee.transformer.util.SourceCode) PageSourceCode(lucee.transformer.util.PageSourceCode) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) Statement(lucee.transformer.bytecode.Statement) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) Charset(java.nio.charset.Charset) Page(lucee.transformer.bytecode.Page) ProcessingDirectiveException(lucee.transformer.cfml.evaluator.impl.ProcessingDirectiveException) LitString(lucee.transformer.expression.literal.LitString) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.

the class CFMLTransformer method tag.

/**
 * Liest einen Tag ein, prueft hierbei ob das Tag innerhalb einer der geladenen Tag-Lib existiert,
 * ansonsten wird ein Tag einfach als literal-string aufgenommen.
 * <br />
 * EBNF:<br />
 * <code>name-space identifier spaces attributes ("/>" | ">" [body "</" identifier spaces ">"]);(* Ob dem Tag ein Body und ein End-Tag folgt ist abhaengig von Definition des body-content in Tag-Lib, gleices gilt fuer appendix *)</code>
 * @param parent uebergeornetes Tag
 * @param parseExpression sollen Expresson innerhalb des Body geparste werden oder nicht.
 * @return Gibt zurueck ob es sich um ein Tag as einer Tag-Lib handelte oder nicht.
 * @throws TemplateException
 */
private boolean tag(TagData data, Body parent, boolean parseExpression) throws TemplateException {
    // lucee.print.ln("--->"+data.cfml.getCurrent());
    boolean hasBody = false;
    Position line = data.srcCode.getPosition();
    // int column=data.cfml.getColumn();
    int start = data.srcCode.getPos();
    data.srcCode.next();
    // read in namespace of tag
    TagLib tagLib = nameSpace(data);
    // return if no matching tag lib
    if (tagLib == null) {
        data.srcCode.previous();
        return false;
    }
    // Get matching tag from tag lib
    String strNameNormal = identifier(data.srcCode, false, true);
    if (strNameNormal == null) {
        data.srcCode.setPos((data.srcCode.getPos() - tagLib.getNameSpaceAndSeparator().length()) - 1);
        return false;
    }
    String strName = strNameNormal.toLowerCase();
    String appendix = null;
    TagLibTag tagLibTag = tagLib.getTag(strName);
    // get taglib
    if (tagLibTag == null) {
        tagLibTag = tagLib.getAppendixTag(strName);
        if (tagLibTag == null) {
            if (tagLib.getIgnoreUnknowTags()) {
                data.srcCode.setPos(start);
                return false;
            }
            throw new TemplateException(data.srcCode, "undefined tag [" + tagLib.getNameSpaceAndSeparator() + strName + "]");
        }
        appendix = StringUtil.removeStartingIgnoreCase(strNameNormal, tagLibTag.getName());
    }
    // CFXD Element
    Tag tag;
    try {
        tag = tagLibTag.getTag(data.factory, line, data.srcCode.getPosition());
    } catch (Exception e) {
        throw new TemplateException(data.srcCode, e);
    }
    parent.addStatement(tag);
    // get tag from tag library
    if (appendix != null) {
        tag.setAppendix(appendix);
        tag.setFullname(tagLibTag.getFullName().concat(appendix));
    } else {
        tag.setFullname(tagLibTag.getFullName());
    }
    // if(tag.getFullname().equalsIgnoreCase("cfcomponent"))data.page.setIsComponent(true);	// MUST to hardcoded, to better
    // else if(tag.getFullname().equalsIgnoreCase("cfinterface"))data.page.setIsInterface(true);	// MUST to hardcoded, to better
    tag.setTagLibTag(tagLibTag);
    comment(data.srcCode, true);
    // Tag Translator Evaluator
    if (tagLibTag.hasTTE()) {
        data.ep.add(tagLibTag, tag, data.flibs, data.srcCode);
    }
    // get Attributes
    attributes(data, tagLibTag, tag);
    if (tagLibTag.hasAttributeEvaluator()) {
        try {
            tagLibTag = tagLibTag.getAttributeEvaluator().evaluate(tagLibTag, tag);
        } catch (AttributeEvaluatorException e) {
            throw new TemplateException(data.srcCode, e);
        }
    }
    // TODO muss erlaubt sein
    if (data.srcCode.forwardIfCurrent('>')) {
        hasBody = tagLibTag.getHasBody();
    } else if (data.srcCode.forwardIfCurrent('/', '>')) {
        if (tagLibTag.getHasBody())
            tag.setBody(new BodyBase(data.factory));
    } else {
        throw createTemplateException(data.srcCode, "tag [" + tagLibTag.getFullName() + "] is not closed", tagLibTag);
    }
    // Body
    if (hasBody) {
        // get Body
        if (tagLibTag.isTagDependent()) {
            // get TagDependentBodyTransformer
            TagDependentBodyTransformer tdbt = null;
            try {
                tdbt = tagLibTag.getBodyTransformer();
            } catch (TagLibException e) {
                throw new TemplateException(data.srcCode, e);
            }
            if (tdbt == null)
                throw createTemplateException(data.srcCode, "Tag dependent body Transformer is invalid for Tag [" + tagLibTag.getFullName() + "]", tagLibTag);
            tag.setBody(tdbt.transform(data.factory, data.root, data.ep, data.tlibs, data.flibs, tagLibTag.getFullName(), data.scriptTags, data.srcCode, data.settings));
            // get TagLib of end Tag
            if (!data.srcCode.forwardIfCurrent("</")) {
                // MUST this is a patch, do a more proper implementation
                TemplateException te = new TemplateException(data.srcCode, "invalid construct");
                if (tdbt instanceof CFMLScriptTransformer && ASMUtil.containsComponent(tag.getBody())) {
                    throw new CFMLScriptTransformer.ComponentTemplateException(te);
                }
                throw te;
            }
            TagLib tagLibEnd = nameSpace(data);
            // same NameSpace
            if (!(tagLibEnd != null && tagLibEnd.getNameSpaceAndSeparator().equals(tagLib.getNameSpaceAndSeparator())))
                throw new TemplateException(data.srcCode, "invalid construct");
            // get end Tag
            String strNameEnd = identifier(data.srcCode, true, true).toLowerCase();
            // not the same name Tag
            if (!strName.equals(strNameEnd)) {
                data.srcCode.setPos(start);
                throw new TemplateException(data.srcCode, "Start and End Tag has not the same Name [" + tagLib.getNameSpaceAndSeparator() + strName + "-" + tagLibEnd.getNameSpaceAndSeparator() + strNameEnd + "]");
            }
            data.srcCode.removeSpace();
            if (!data.srcCode.forwardIfCurrent('>'))
                throw new TemplateException(data.srcCode, "End Tag [" + tagLibEnd.getNameSpaceAndSeparator() + strNameEnd + "] not closed");
        } else {
            // get body of Tag
            BodyBase body = new BodyBase(data.factory);
            body.setParent(tag);
            // parseExpression=(tagLibTag.getParseBody())?true:parseExpression;
            if (tagLibTag.getParseBody())
                parseExpression = true;
            while (true) {
                // Load Expession Transformer from TagLib
                ExprTransformer transfomer = null;
                if (parseExpression) {
                    try {
                        transfomer = tagLibTag.getTagLib().getExprTransfomer();
                    } catch (TagLibException e) {
                        throw new TemplateException(data.srcCode, e);
                    }
                }
                // call body
                body(data, body, parseExpression, transfomer);
                // no End Tag
                if (data.srcCode.isAfterLast()) {
                    if (tagLibTag.isBodyReq()) {
                        data.srcCode.setPos(start);
                        throw createTemplateException(data.srcCode, "No matching end tag found for tag [" + tagLibTag.getFullName() + "]", tagLibTag);
                    }
                    body.moveStatmentsTo(parent);
                    return executeEvaluator(data, tagLibTag, tag);
                }
                // Invalid Construct
                int posBeforeEndTag = data.srcCode.getPos();
                if (!data.srcCode.forwardIfCurrent('<', '/'))
                    throw createTemplateException(data.srcCode, "Missing end tag for [" + tagLibTag.getFullName() + "]", tagLibTag);
                // get TagLib of end Tag
                int _start = data.srcCode.getPos();
                TagLib tagLibEnd = nameSpace(data);
                // same NameSpace
                if (tagLibEnd != null) {
                    String strNameEnd = "";
                    // lucee.print.ln(data.cfml.getLine()+" - "+data.cfml.getColumn()+" - "+tagLibEnd.getNameSpaceAndSeperator()+".equals("+tagLib.getNameSpaceAndSeperator()+")");
                    if (tagLibEnd.getNameSpaceAndSeparator().equals(tagLib.getNameSpaceAndSeparator())) {
                        // get end Tag
                        strNameEnd = identifier(data.srcCode, true, true).toLowerCase();
                        // not the same name Tag
                        // new part
                        data.srcCode.removeSpace();
                        if (strName.equals(strNameEnd)) {
                            if (!data.srcCode.forwardIfCurrent('>'))
                                throw new TemplateException(data.srcCode, "End Tag [" + tagLibEnd.getNameSpaceAndSeparator() + strNameEnd + "] not closed");
                            break;
                        }
                    }
                    // new part
                    if (tagLibTag.isBodyReq()) {
                        TagLibTag endTag = tagLibEnd.getTag(strNameEnd);
                        if (endTag != null && !endTag.getHasBody())
                            throw new TemplateException(data.srcCode, "End Tag [" + tagLibEnd.getNameSpaceAndSeparator() + strNameEnd + "] is not allowed, for this tag only a Start Tag is allowed");
                        data.srcCode.setPos(start);
                        if (tagLibEnd.getIgnoreUnknowTags() && (tagLibEnd.getTag(strNameEnd)) == null) {
                            data.srcCode.setPos(_start);
                        } else
                            throw new TemplateException(data.srcCode, "Start and End Tag has not the same Name [" + tagLib.getNameSpaceAndSeparator() + strName + "-" + tagLibEnd.getNameSpaceAndSeparator() + strNameEnd + "]");
                    } else {
                        body.moveStatmentsTo(parent);
                        data.srcCode.setPos(posBeforeEndTag);
                        return executeEvaluator(data, tagLibTag, tag);
                    }
                // / new part
                }
                body.addPrintOut(data.factory, "</", null, null);
            }
            tag.setBody(body);
        }
    }
    if (tag instanceof StatementBase)
        ((StatementBase) tag).setEnd(data.srcCode.getPosition());
    return executeEvaluator(data, tagLibTag, tag);
}
Also used : CFMLScriptTransformer(lucee.transformer.cfml.script.CFMLScriptTransformer) TagLibTag(lucee.transformer.library.tag.TagLibTag) AttributeEvaluatorException(lucee.transformer.cfml.attributes.AttributeEvaluatorException) Position(lucee.transformer.Position) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) SimpleExprTransformer(lucee.transformer.cfml.expression.SimpleExprTransformer) ExprTransformer(lucee.transformer.cfml.ExprTransformer) LitString(lucee.transformer.expression.literal.LitString) TagLibException(lucee.transformer.library.tag.TagLibException) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) AttributeEvaluatorException(lucee.transformer.cfml.attributes.AttributeEvaluatorException) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TagLibException(lucee.transformer.library.tag.TagLibException) TemplateException(lucee.runtime.exp.TemplateException) IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) ProcessingDirectiveException(lucee.transformer.cfml.evaluator.impl.ProcessingDirectiveException) StatementBase(lucee.transformer.bytecode.statement.StatementBase) TagLib(lucee.transformer.library.tag.TagLib) CustomTagLib(lucee.transformer.library.tag.CustomTagLib) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 18 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag 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 19 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag 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 20 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.

the class Mail method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    if (tag.containsAttribute("query")) {
        TagLib lib = libTag.getTagLib();
        TagLibTag outputTag = lib.getTag("output");
        TagOutput output = new TagOutput(tag.getFactory(), tag.getStart(), null);
        output.setFullname(outputTag.getFullName());
        output.setTagLibTag(outputTag);
        output.addAttribute(new Attribute(false, "output", tag.getFactory().TRUE(), "boolean"));
        output.addAttribute(new Attribute(false, "formail", tag.getFactory().TRUE(), "boolean"));
        // output.getBody();
        Body body = new BodyBase(tag.getFactory());
        output.setBody(body);
        ASMUtil.replace(tag, output, false);
        body.addStatement(tag);
        output.addAttribute(tag.removeAttribute("query"));
        if (tag.containsAttribute("group"))
            output.addAttribute(tag.removeAttribute("group"));
        if (tag.containsAttribute("groupcasesensitive"))
            output.addAttribute(tag.removeAttribute("groupcasesensitive"));
        if (tag.containsAttribute("startrow"))
            output.addAttribute(tag.removeAttribute("startrow"));
        if (tag.containsAttribute("maxrows"))
            output.addAttribute(tag.removeAttribute("maxrows"));
        new Output().evaluate(output, outputTag);
    }
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) TagOutput(lucee.transformer.bytecode.statement.tag.TagOutput) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TagLib(lucee.transformer.library.tag.TagLib) TagOutput(lucee.transformer.bytecode.statement.tag.TagOutput) Body(lucee.transformer.bytecode.Body) BodyBase(lucee.transformer.bytecode.BodyBase)

Aggregations

TagLibTag (lucee.transformer.library.tag.TagLibTag)28 Tag (lucee.transformer.bytecode.statement.tag.Tag)12 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)11 TagLib (lucee.transformer.library.tag.TagLib)9 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)8 Body (lucee.transformer.bytecode.Body)7 TemplateException (lucee.runtime.exp.TemplateException)6 Position (lucee.transformer.Position)6 BodyBase (lucee.transformer.bytecode.BodyBase)6 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)6 LitString (lucee.transformer.expression.literal.LitString)6 Statement (lucee.transformer.bytecode.Statement)5 Entry (java.util.Map.Entry)3 Key (lucee.runtime.type.Collection.Key)3 Struct (lucee.runtime.type.Struct)3 FunctionBody (lucee.transformer.bytecode.FunctionBody)3 Page (lucee.transformer.bytecode.Page)3 ScriptBody (lucee.transformer.bytecode.ScriptBody)3 Expression (lucee.transformer.expression.Expression)3 ArrayList (java.util.ArrayList)2