Search in sources :

Example 1 with TagLib

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

the class ConfigImpl method addTag.

protected void addTag(String nameSpace, String nameSpaceSeperator, String name, int dialect, ClassDefinition cd) {
    if (dialect == CFMLEngine.DIALECT_BOTH) {
        addTag(nameSpace, nameSpaceSeperator, name, CFMLEngine.DIALECT_CFML, cd);
        addTag(nameSpace, nameSpaceSeperator, name, CFMLEngine.DIALECT_LUCEE, cd);
        return;
    }
    TagLib[] tlds = dialect == CFMLEngine.DIALECT_CFML ? cfmlTlds : luceeTlds;
    for (int i = 0; i < tlds.length; i++) {
        if (tlds[i].getNameSpaceAndSeparator().equalsIgnoreCase(nameSpace + nameSpaceSeperator)) {
            TagLibTag tlt = new TagLibTag(tlds[i]);
            tlt.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_DYNAMIC);
            tlt.setBodyContent("free");
            tlt.setTagClassDefinition(cd);
            tlt.setName(name);
            tlds[i].setTag(tlt);
        }
    }
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) TagLib(lucee.transformer.library.tag.TagLib)

Example 2 with TagLib

use of lucee.transformer.library.tag.TagLib 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 TagLib

use of lucee.transformer.library.tag.TagLib 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)

Example 4 with TagLib

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

the class CFMLTransformer method transform.

/**
 * Startmethode zum transfomieren einer CFMLString.
 * <br />
 * EBNF:<br />
 * <code>{body}</code>
 * @param config
 * @param sc CFMLString
 * @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 sourceLastModified
 * @param dotNotationUpperCase
 * @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
 */
public Page transform(Factory factory, ConfigImpl config, SourceCode sc, TagLib[] tlibs, FunctionLib[] flibs, long sourceLastModified, Boolean dotNotationUpperCase, boolean returnValue, boolean ignoreScope) throws TemplateException {
    boolean dnuc;
    if (dotNotationUpperCase == null) {
        if (sc instanceof PageSourceCode)
            dnuc = sc.getDialect() == CFMLEngine.DIALECT_CFML && ((MappingImpl) ((PageSourceCode) sc).getPageSource().getMapping()).getDotNotationUpperCase();
        else
            dnuc = sc.getDialect() == CFMLEngine.DIALECT_CFML && config.getDotNotationUpperCase();
    } else
        dnuc = dotNotationUpperCase;
    TagLib[][] _tlibs = new TagLib[][] { null, new TagLib[0] };
    _tlibs[TAG_LIB_GLOBAL] = tlibs;
    // reset page tlds
    if (_tlibs[TAG_LIB_PAGE].length > 0) {
        _tlibs[TAG_LIB_PAGE] = new TagLib[0];
    }
    Page page = new Page(factory, config, sc, null, ConfigWebUtil.getEngine(config).getInfo().getFullVersionInfo(), sourceLastModified, sc.getWriteLog(), sc.getDialect() == CFMLEngine.DIALECT_LUCEE || config.getSuppressWSBeforeArg(), config.getDefaultFunctionOutput(), returnValue, ignoreScope);
    TagData data = new TagData(factory, _tlibs, flibs, config.getCoreTagLib(sc.getDialect()).getScriptTags(), sc, page, dnuc, ignoreScope);
    // Body body=page;
    try {
        do {
            body(data, page, false, null);
            if (data.srcCode.isAfterLast())
                break;
            if (data.srcCode.forwardIfCurrent("</")) {
                int pos = data.srcCode.getPos();
                TagLib tagLib = nameSpace(data);
                if (tagLib == null) {
                    page.addPrintOut(data.factory, "</", null, null);
                } else {
                    String name = identifier(data.srcCode, true, true);
                    if (tagLib.getIgnoreUnknowTags()) {
                        TagLibTag tlt = tagLib.getTag(name);
                        if (tlt == null) {
                            data.srcCode.setPos(pos);
                            page.addPrintOut(data.factory, "</", null, null);
                        }
                    } else
                        throw new TemplateException(sc, "no matching start tag for end tag [" + tagLib.getNameSpaceAndSeparator() + name + "]");
                }
            } else
                throw new TemplateException(sc, "Error while transforming CFML File");
        } while (true);
        // call-back of evaluators
        data.ep.run();
        return page;
    } catch (TemplateException e) {
        data.ep.clear();
        throw e;
    }
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) PageSourceCode(lucee.transformer.util.PageSourceCode) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) TagLib(lucee.transformer.library.tag.TagLib) CustomTagLib(lucee.transformer.library.tag.CustomTagLib) Page(lucee.transformer.bytecode.Page) LitString(lucee.transformer.expression.literal.LitString)

Example 5 with TagLib

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

the class ApplicationContextSupport method initTagDefaultAttributeValues.

public static void initTagDefaultAttributeValues(Config config, Map<Collection.Key, Map<Collection.Key, Object>> tagDefaultAttributeValues, Struct sct, int dialect) {
    if (sct.size() == 0)
        return;
    ConfigImpl ci = ((ConfigImpl) config);
    // first check the core lib without namespace
    TagLib lib = ci.getCoreTagLib(dialect);
    _initTagDefaultAttributeValues(config, lib, tagDefaultAttributeValues, sct, false);
    if (sct.size() == 0)
        return;
    // then all the other libs including the namespace
    TagLib[] tlds = ci.getTLDs(dialect);
    for (int i = 0; i < tlds.length; i++) {
        _initTagDefaultAttributeValues(config, tlds[i], tagDefaultAttributeValues, sct, true);
        if (sct.size() == 0)
            return;
    }
}
Also used : TagLib(lucee.transformer.library.tag.TagLib) ConfigImpl(lucee.runtime.config.ConfigImpl)

Aggregations

TagLib (lucee.transformer.library.tag.TagLib)19 TagLibTag (lucee.transformer.library.tag.TagLibTag)9 TemplateException (lucee.runtime.exp.TemplateException)5 CustomTagLib (lucee.transformer.library.tag.CustomTagLib)5 Resource (lucee.commons.io.res.Resource)4 ConfigImpl (lucee.runtime.config.ConfigImpl)3 BodyBase (lucee.transformer.bytecode.BodyBase)3 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)3 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)3 LitString (lucee.transformer.expression.literal.LitString)3 TagLibException (lucee.transformer.library.tag.TagLibException)3 IOException (java.io.IOException)2 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)2 Position (lucee.transformer.Position)2 Body (lucee.transformer.bytecode.Body)2 Page (lucee.transformer.bytecode.Page)2 Tag (lucee.transformer.bytecode.statement.tag.Tag)2 ExprTransformer (lucee.transformer.cfml.ExprTransformer)2 AttributeEvaluatorException (lucee.transformer.cfml.attributes.AttributeEvaluatorException)2