Search in sources :

Example 1 with TagLibException

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

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

the class ConfigImpl method setTldFile.

/**
 * set the optional directory of the tag library deskriptors
 * @param fileTld directory of the tag libray deskriptors
 * @throws TagLibException
 */
protected void setTldFile(Resource fileTld, int dialect) throws TagLibException {
    if (dialect == CFMLEngine.DIALECT_BOTH) {
        setTldFile(fileTld, CFMLEngine.DIALECT_CFML);
        setTldFile(fileTld, CFMLEngine.DIALECT_LUCEE);
        return;
    }
    TagLib[] tlds = dialect == CFMLEngine.DIALECT_CFML ? cfmlTlds : luceeTlds;
    if (fileTld == null)
        return;
    this.tldFile = fileTld;
    String key;
    Map<String, TagLib> map = new HashMap<String, TagLib>();
    // First fill existing to set
    for (int i = 0; i < tlds.length; i++) {
        key = getKey(tlds[i]);
        map.put(key, tlds[i]);
    }
    TagLib tl;
    // now overwrite with new data
    if (fileTld.isDirectory()) {
        Resource[] files = fileTld.listResources(new ExtensionResourceFilter(new String[] { "tld", "tldx" }));
        for (int i = 0; i < files.length; i++) {
            try {
                tl = TagLibFactory.loadFromFile(files[i], getIdentification());
                key = getKey(tl);
                if (!map.containsKey(key))
                    map.put(key, tl);
                else
                    overwrite(map.get(key), tl);
            } catch (TagLibException tle) {
                SystemOut.printDate(out, "can't load tld " + files[i]);
                tle.printStackTrace(getErrWriter());
            }
        }
    } else if (fileTld.isFile()) {
        tl = TagLibFactory.loadFromFile(fileTld, getIdentification());
        key = getKey(tl);
        if (!map.containsKey(key))
            map.put(key, tl);
        else
            overwrite(map.get(key), tl);
    }
    // now fill back to array
    tlds = new TagLib[map.size()];
    if (dialect == CFMLEngine.DIALECT_CFML)
        cfmlTlds = tlds;
    else
        luceeTlds = tlds;
    int index = 0;
    Iterator<TagLib> it = map.values().iterator();
    while (it.hasNext()) {
        tlds[index++] = it.next();
    }
}
Also used : HashMap(java.util.HashMap) TagLib(lucee.transformer.library.tag.TagLib) Resource(lucee.commons.io.res.Resource) CompressResource(lucee.commons.io.res.type.compress.CompressResource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) TagLibException(lucee.transformer.library.tag.TagLibException)

Example 3 with TagLibException

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

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

the class AbstrCFMLScriptTransformer method getTag.

private final Tag getTag(ExprData data, Body parent, TagLibTag tlt, Position start, Position end) throws TemplateException {
    try {
        Tag tag = tlt.getTag(data.factory, start, end);
        tag.setParent(parent);
        return tag;
    } catch (TagLibException e) {
        throw new TemplateException(data.srcCode, e);
    }
/*if(StringUtil.isEmpty(tlt.getTttClassName()))tag= new TagBase(line);
		else {
			try {
				Class<Tag> clazz = ClassUtil.loadClass(tlt.getTttClassName());
				Constructor<Tag> constr = clazz.getConstructor(new Class[]{Position.class});
				tag = constr.newInstance(new Object[]{line});
				
			} 
			catch (Exception e) {
            SystemOut.printDate(e);
				tag= new TagBase(line);
			}
		}*/
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) TagLibException(lucee.transformer.library.tag.TagLibException)

Aggregations

TagLibException (lucee.transformer.library.tag.TagLibException)4 TemplateException (lucee.runtime.exp.TemplateException)3 TagLib (lucee.transformer.library.tag.TagLib)3 Resource (lucee.commons.io.res.Resource)2 Tag (lucee.transformer.bytecode.statement.tag.Tag)2 CustomTagLib (lucee.transformer.library.tag.CustomTagLib)2 TagLibTag (lucee.transformer.library.tag.TagLibTag)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)1 CompressResource (lucee.commons.io.res.type.compress.CompressResource)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 Position (lucee.transformer.Position)1 BodyBase (lucee.transformer.bytecode.BodyBase)1 StatementBase (lucee.transformer.bytecode.statement.StatementBase)1 ExprTransformer (lucee.transformer.cfml.ExprTransformer)1 AttributeEvaluatorException (lucee.transformer.cfml.attributes.AttributeEvaluatorException)1 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)1 ProcessingDirectiveException (lucee.transformer.cfml.evaluator.impl.ProcessingDirectiveException)1 SimpleExprTransformer (lucee.transformer.cfml.expression.SimpleExprTransformer)1