Search in sources :

Example 11 with TagLib

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

the class XMLConfigWebFactory method doCheckChangesInLibraries.

private static void doCheckChangesInLibraries(ConfigImpl config) {
    // create current hash from libs
    TagLib[] ctlds = config.getTLDs(CFMLEngine.DIALECT_CFML);
    TagLib[] ltlds = config.getTLDs(CFMLEngine.DIALECT_LUCEE);
    FunctionLib[] cflds = config.getFLDs(CFMLEngine.DIALECT_CFML);
    FunctionLib[] lflds = config.getFLDs(CFMLEngine.DIALECT_LUCEE);
    // charset
    StringBuilder sb = new StringBuilder(config.getTemplateCharset().name());
    sb.append(';');
    // dot notation upper case
    _getDotNotationUpperCase(sb, config.getMappings());
    _getDotNotationUpperCase(sb, config.getCustomTagMappings());
    _getDotNotationUpperCase(sb, config.getComponentMappings());
    _getDotNotationUpperCase(sb, config.getFunctionMapping());
    _getDotNotationUpperCase(sb, config.getTagMapping());
    // _getDotNotationUpperCase(sb,config.getServerTagMapping());
    // _getDotNotationUpperCase(sb,config.getServerFunctionMapping());
    // suppress ws before arg
    sb.append(config.getSuppressWSBeforeArg());
    sb.append(';');
    // externalize strings
    sb.append(config.getExternalizeStringGTE());
    sb.append(';');
    // function output
    sb.append(config.getDefaultFunctionOutput());
    sb.append(';');
    // full null support
    sb.append(config.getFullNullSupport());
    sb.append(';');
    // fusiondebug or not (FD uses full path name)
    sb.append(config.allowRequestTimeout());
    sb.append(';');
    // tld
    for (int i = 0; i < ctlds.length; i++) {
        sb.append(ctlds[i].getHash());
    }
    for (int i = 0; i < ltlds.length; i++) {
        sb.append(ltlds[i].getHash());
    }
    // fld
    for (int i = 0; i < cflds.length; i++) {
        sb.append(cflds[i].getHash());
    }
    for (int i = 0; i < lflds.length; i++) {
        sb.append(lflds[i].getHash());
    }
    if (config instanceof ConfigWeb) {
        boolean hasChanged = false;
        sb.append(";").append(((ConfigWebImpl) config).getConfigServerImpl().getLibHash());
        try {
            String hashValue = HashUtil.create64BitHashAsString(sb.toString());
            // check and compare lib version file
            Resource libHash = config.getConfigDir().getRealResource("lib-hash");
            if (!libHash.exists()) {
                libHash.createNewFile();
                IOUtil.write(libHash, hashValue, SystemUtil.getCharset(), false);
                hasChanged = true;
            } else if (!IOUtil.toString(libHash, SystemUtil.getCharset()).equals(hashValue)) {
                IOUtil.write(libHash, hashValue, SystemUtil.getCharset(), false);
                hasChanged = true;
            }
        } catch (IOException e) {
        }
        // change Compile type
        if (hasChanged) {
            try {
                // first we delete the physical classes
                config.getClassDirectory().remove(true);
                // now we force the pagepools to flush
                flushPageSourcePool(config.getMappings());
                flushPageSourcePool(config.getCustomTagMappings());
                flushPageSourcePool(config.getComponentMappings());
                flushPageSourcePool(config.getFunctionMapping());
                flushPageSourcePool(config.getTagMapping());
                flushPageSourcePool(config.getTagMapping());
                if (config instanceof ConfigWeb) {
                    flushPageSourcePool(((ConfigWebImpl) config).getApplicationMapping());
                }
            /*else {
						ConfigWeb[] webs = ((ConfigServerImpl)config).getConfigWebs();
						for(int i=0;i<webs.length;i++){
							flushPageSourcePool(((ConfigWebImpl)webs[i]).getApplicationMapping());
						}
					}*/
            } catch (IOException e) {
                e.printStackTrace(config.getErrWriter());
            }
        }
    } else {
        ((ConfigServerImpl) config).setLibHash(HashUtil.create64BitHashAsString(sb.toString()));
    }
}
Also used : Resource(lucee.commons.io.res.Resource) FunctionLib(lucee.transformer.library.function.FunctionLib) IOException(java.io.IOException) lucee.aprint(lucee.aprint) TagLib(lucee.transformer.library.tag.TagLib)

Example 12 with TagLib

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

the class ConfigImpl method setTagDirectory.

protected void setTagDirectory(Resource tagDirectory) {
    // this.tagDirectory=tagDirectory;
    this.tagMapping = new MappingImpl(this, "/mapping-tag/", tagDirectory.getAbsolutePath(), null, ConfigImpl.INSPECT_NEVER, true, true, true, true, false, true, null, -1, -1);
    TagLib tlc = getCoreTagLib(CFMLEngine.DIALECT_CFML);
    TagLib tll = getCoreTagLib(CFMLEngine.DIALECT_LUCEE);
    // now overwrite with new data
    if (tagDirectory.isDirectory()) {
        String[] files = tagDirectory.list(new ExtensionResourceFilter(getMode() == ConfigImpl.MODE_STRICT ? Constants.getComponentExtensions() : Constants.getExtensions()));
        for (int i = 0; i < files.length; i++) {
            if (tlc != null)
                createTag(tlc, files[i]);
            if (tll != null)
                createTag(tll, files[i]);
        }
    }
}
Also used : TagLib(lucee.transformer.library.tag.TagLib) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) MappingImpl(lucee.runtime.MappingImpl)

Example 13 with TagLib

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

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

the class CFMLTransformer method nameSpace.

/**
 * Vergleicht folgende Zeichen mit den Namespacedefinitionen der Tag Libraries,
 * gibt eine Tag-Lib zurueck falls eine passt, ansonsten null.
 * <br />
 * EBNF:<br />
 * <code>< tagLib[].getNameSpaceAndSeperator() >(* Vergleicht Zeichen mit den Namespacedefinitionen der Tag Libraries. *) </code>
 * @return TagLib Passende Tag Lirary oder null.
 */
public static TagLib nameSpace(Data data) {
    boolean hasTag = false;
    int start = data.srcCode.getPos();
    TagLib tagLib = null;
    // loop over NameSpaces
    for (int i = 1; i >= 0; i--) {
        for (int ii = 0; ii < data.tlibs[i].length; ii++) {
            tagLib = data.tlibs[i][ii];
            char[] c = tagLib.getNameSpaceAndSeperatorAsCharArray();
            // Loop over char of NameSpace and Sepearator
            hasTag = true;
            for (int y = 0; y < c.length; y++) {
                if (!(data.srcCode.isValidIndex() && c[y] == data.srcCode.getCurrentLower())) {
                    // hasTag=true;
                    // } else {
                    hasTag = false;
                    data.srcCode.setPos(start);
                    break;
                }
                data.srcCode.next();
            }
            // break;
            if (hasTag)
                return tagLib;
        }
    // if(hasTag) return tagLib;
    }
    return null;
}
Also used : TagLib(lucee.transformer.library.tag.TagLib) CustomTagLib(lucee.transformer.library.tag.CustomTagLib)

Example 15 with TagLib

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

the class CFMLTransformer method executeEvaluator.

private boolean executeEvaluator(TagData data, TagLibTag tagLibTag, Tag tag) throws TemplateException {
    if (tagLibTag.hasTTE()) {
        try {
            TagLib lib = tagLibTag.getEvaluator().execute(data.config, tag, tagLibTag, data.flibs, data);
            if (lib != null) {
                // set
                for (int i = 0; i < data.tlibs[TAG_LIB_PAGE].length; i++) {
                    if (data.tlibs[TAG_LIB_PAGE][i].getNameSpaceAndSeparator().equalsIgnoreCase(lib.getNameSpaceAndSeparator())) {
                        boolean extIsCustom = data.tlibs[TAG_LIB_PAGE][i] instanceof CustomTagLib;
                        boolean newIsCustom = lib instanceof CustomTagLib;
                        // TagLib + CustomTagLib (visa/versa)
                        if (extIsCustom) {
                            ((CustomTagLib) data.tlibs[TAG_LIB_PAGE][i]).append(lib);
                            return true;
                        } else if (newIsCustom) {
                            ((CustomTagLib) lib).append(data.tlibs[TAG_LIB_PAGE][i]);
                            data.tlibs[TAG_LIB_PAGE][i] = lib;
                            return true;
                        }
                    }
                }
                // TODO make sure longer namespace ar checked firts to support subsets, same for core libs
                // insert
                TagLib[] newTlibs = new TagLib[data.tlibs[TAG_LIB_PAGE].length + 1];
                for (int i = 0; i < data.tlibs[TAG_LIB_PAGE].length; i++) {
                    newTlibs[i] = data.tlibs[TAG_LIB_PAGE][i];
                }
                newTlibs[data.tlibs[TAG_LIB_PAGE].length] = lib;
                data.tlibs[TAG_LIB_PAGE] = newTlibs;
            }
        } catch (EvaluatorException e) {
            throw new TemplateException(data.srcCode, e);
        }
    }
    return true;
}
Also used : EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) AttributeEvaluatorException(lucee.transformer.cfml.attributes.AttributeEvaluatorException) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) TagLib(lucee.transformer.library.tag.TagLib) CustomTagLib(lucee.transformer.library.tag.CustomTagLib) CustomTagLib(lucee.transformer.library.tag.CustomTagLib)

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