Search in sources :

Example 6 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class ClassUtilImpl method loadBIF.

@Override
public BIF loadBIF(PageContext pc, String name) throws InstantiationException, IllegalAccessException {
    // first of all we chek if itis a class
    Class<?> res = lucee.commons.lang.ClassUtil.loadClass(name, null);
    if (res != null) {
        if (Reflector.isInstaneOf(res, BIF.class)) {
            return (BIF) res.newInstance();
        }
        return new BIFProxy(res);
    }
    FunctionLib[] flds = ((ConfigWebImpl) pc.getConfig()).getFLDs(pc.getCurrentTemplateDialect());
    FunctionLibFunction flf;
    for (int i = 0; i < flds.length; i++) {
        flf = flds[i].getFunction(name);
        if (flf != null)
            return flf.getBIF();
    }
    return null;
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) BIFProxy(lucee.runtime.functions.BIFProxy) BIF(lucee.runtime.ext.function.BIF)

Example 7 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class XMLConfigWebFactory method loadFilesystem.

/**
 * @param configServer
 * @param config
 * @param doc
 * @throws ExpressionException
 * @throws TagLibException
 * @throws FunctionLibException
 */
private static void loadFilesystem(ConfigServerImpl configServer, ConfigImpl config, Document doc, boolean doNew) throws ExpressionException, TagLibException, FunctionLibException {
    if (configServer != null) {
        Resource src = configServer.getConfigDir().getRealResource("distribution");
        Resource trg = config.getConfigDir().getRealResource("context/");
        copyContextFiles(src, trg);
    }
    Resource configDir = config.getConfigDir();
    boolean hasCS = configServer != null;
    Element fileSystem = getChildByName(doc.getDocumentElement(), "file-system");
    if (fileSystem == null)
        fileSystem = getChildByName(doc.getDocumentElement(), "filesystem");
    String strAllowRealPath = null;
    String strDeployDirectory = null;
    // String strTempDirectory=null;
    String strTLDDirectory = null;
    String strFLDDirectory = null;
    String strTagDirectory = null;
    String strFunctionDirectory = null;
    // get library directories
    if (fileSystem != null) {
        strAllowRealPath = getAttr(fileSystem, "allow-realpath");
        strDeployDirectory = ConfigWebUtil.translateOldPath(fileSystem.getAttribute("deploy-directory"));
        // strTempDirectory=ConfigWebUtil.translateOldPath(fileSystem.getAttribute("temp-directory"));
        strTLDDirectory = ConfigWebUtil.translateOldPath(fileSystem.getAttribute("tld-directory"));
        strFLDDirectory = ConfigWebUtil.translateOldPath(fileSystem.getAttribute("fld-directory"));
        strTagDirectory = ConfigWebUtil.translateOldPath(fileSystem.getAttribute("tag-directory"));
        strFunctionDirectory = ConfigWebUtil.translateOldPath(fileSystem.getAttribute("function-directory"));
    }
    // set default directories if necessary
    if (StringUtil.isEmpty(strFLDDirectory))
        strFLDDirectory = "{lucee-config}/library/fld/";
    if (StringUtil.isEmpty(strTLDDirectory))
        strTLDDirectory = "{lucee-config}/library/tld/";
    if (StringUtil.isEmpty(strFunctionDirectory))
        strFunctionDirectory = "{lucee-config}/library/function/";
    if (StringUtil.isEmpty(strTagDirectory))
        strTagDirectory = "{lucee-config}/library/tag/";
    // Deploy Dir
    Resource dd = ConfigWebUtil.getFile(configDir, strDeployDirectory, "cfclasses", configDir, FileUtil.TYPE_DIR, config);
    config.setDeployDirectory(dd);
    // init TLDS
    if (hasCS) {
        config.setTLDs(ConfigImpl.duplicate(configServer.getTLDs(CFMLEngine.DIALECT_CFML), false), CFMLEngine.DIALECT_CFML);
        config.setTLDs(ConfigImpl.duplicate(configServer.getTLDs(CFMLEngine.DIALECT_LUCEE), false), CFMLEngine.DIALECT_LUCEE);
    } else {
        ConfigServerImpl cs = (ConfigServerImpl) config;
        config.setTLDs(ConfigImpl.duplicate(new TagLib[] { cs.cfmlCoreTLDs }, false), CFMLEngine.DIALECT_CFML);
        config.setTLDs(ConfigImpl.duplicate(new TagLib[] { cs.luceeCoreTLDs }, false), CFMLEngine.DIALECT_LUCEE);
    }
    // TLD Dir
    if (strTLDDirectory != null) {
        Resource tld = ConfigWebUtil.getFile(config, configDir, strTLDDirectory, FileUtil.TYPE_DIR);
        if (tld != null)
            config.setTldFile(tld, CFMLEngine.DIALECT_BOTH);
    }
    // Tag Directory
    if (strTagDirectory != null) {
        Resource dir = ConfigWebUtil.getFile(config, configDir, strTagDirectory, FileUtil.TYPE_DIR);
        createTagFiles(config, configDir, dir, doNew);
        if (dir != null) {
            config.setTagDirectory(dir);
        }
    }
    // allow realpath
    if (hasCS) {
        config.setAllowRealPath(configServer.allowRealPath());
    }
    if (!StringUtil.isEmpty(strAllowRealPath, true)) {
        config.setAllowRealPath(Caster.toBooleanValue(strAllowRealPath, true));
    }
    // Init flds
    if (hasCS) {
        config.setFLDs(ConfigImpl.duplicate(configServer.getFLDs(CFMLEngine.DIALECT_CFML), false), CFMLEngine.DIALECT_CFML);
        config.setFLDs(ConfigImpl.duplicate(configServer.getFLDs(CFMLEngine.DIALECT_LUCEE), false), CFMLEngine.DIALECT_LUCEE);
    } else {
        ConfigServerImpl cs = (ConfigServerImpl) config;
        config.setFLDs(ConfigImpl.duplicate(new FunctionLib[] { cs.cfmlCoreFLDs }, false), CFMLEngine.DIALECT_CFML);
        config.setFLDs(ConfigImpl.duplicate(new FunctionLib[] { cs.luceeCoreFLDs }, false), CFMLEngine.DIALECT_LUCEE);
    }
    // FLDs
    if (strFLDDirectory != null) {
        Resource fld = ConfigWebUtil.getFile(config, configDir, strFLDDirectory, FileUtil.TYPE_DIR);
        if (fld != null)
            config.setFldFile(fld, CFMLEngine.DIALECT_BOTH);
    }
    // Function files (CFML)
    if (strFunctionDirectory != null) {
        Resource dir = ConfigWebUtil.getFile(config, configDir, strFunctionDirectory, FileUtil.TYPE_DIR);
        createFunctionFiles(config, configDir, dir, doNew);
        if (dir != null)
            config.setFunctionDirectory(dir);
    }
}
Also used : TagLib(lucee.transformer.library.tag.TagLib) Element(org.w3c.dom.Element) Resource(lucee.commons.io.res.Resource) FunctionLib(lucee.transformer.library.function.FunctionLib)

Example 8 with FunctionLib

use of lucee.transformer.library.function.FunctionLib 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 9 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class FunctionException method getFunctionInfo.

private static String getFunctionInfo(PageContext pc, String functionName) {
    FunctionLib[] flds;
    int dialect = pc.getCurrentTemplateDialect();
    flds = ((ConfigImpl) pc.getConfig()).getFLDs(dialect);
    FunctionLibFunction function = null;
    for (int i = 0; i < flds.length; i++) {
        function = flds[i].getFunction(functionName.toLowerCase());
        if (function != null)
            break;
    }
    if (function == null)
        return "";
    StringBuilder rtn = new StringBuilder();
    rtn.append(function.getName() + "(");
    int optionals = 0;
    ArrayList<FunctionLibFunctionArg> args = function.getArg();
    for (int i = 0; i < args.size(); i++) {
        FunctionLibFunctionArg arg = args.get(i);
        if (i != 0)
            rtn.append(", ");
        if (!arg.getRequired()) {
            rtn.append("[");
            optionals++;
        }
        rtn.append(arg.getName());
        rtn.append(":");
        rtn.append(arg.getTypeAsString());
    }
    for (int i = 0; i < optionals; i++) rtn.append("]");
    rtn.append("):" + function.getReturnTypeAsString());
    return rtn.toString();
}
Also used : FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 10 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class ConfigImpl method setFldFile.

protected void setFldFile(Resource fileFld, int dialect) throws FunctionLibException {
    if (dialect == CFMLEngine.DIALECT_BOTH) {
        setFldFile(fileFld, CFMLEngine.DIALECT_CFML);
        setFldFile(fileFld, CFMLEngine.DIALECT_LUCEE);
        return;
    }
    FunctionLib[] flds = dialect == CFMLEngine.DIALECT_CFML ? cfmlFlds : luceeFlds;
    // merge all together (backward compatibility)
    if (flds.length > 1)
        for (int i = 1; i < flds.length; i++) {
            overwrite(flds[0], flds[i]);
        }
    flds = new FunctionLib[] { flds[0] };
    if (dialect == CFMLEngine.DIALECT_CFML) {
        cfmlFlds = flds;
        // TODO improve check
        if (cfmlFlds != flds)
            combinedCFMLFLDs = null;
    } else {
        luceeFlds = flds;
        // TODO improve check
        if (luceeFlds != flds)
            combinedLuceeFLDs = null;
    }
    if (fileFld == null)
        return;
    this.fldFile = fileFld;
    // overwrite with addional functions
    FunctionLib fl;
    if (fileFld.isDirectory()) {
        Resource[] files = fileFld.listResources(new ExtensionResourceFilter(new String[] { "fld", "fldx" }));
        for (int i = 0; i < files.length; i++) {
            try {
                fl = FunctionLibFactory.loadFromFile(files[i], getIdentification());
                overwrite(flds[0], fl);
            } catch (FunctionLibException fle) {
                SystemOut.printDate(out, "can't load fld " + files[i]);
                fle.printStackTrace(getErrWriter());
            }
        }
    } else {
        fl = FunctionLibFactory.loadFromFile(fileFld, getIdentification());
        overwrite(flds[0], fl);
    }
}
Also used : FunctionLibException(lucee.transformer.library.function.FunctionLibException) Resource(lucee.commons.io.res.Resource) CompressResource(lucee.commons.io.res.type.compress.CompressResource) FunctionLib(lucee.transformer.library.function.FunctionLib) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter)

Aggregations

FunctionLib (lucee.transformer.library.function.FunctionLib)11 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)6 Resource (lucee.commons.io.res.Resource)3 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)2 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)2 TagLib (lucee.transformer.library.tag.TagLib)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 lucee.aprint (lucee.aprint)1 CompressResource (lucee.commons.io.res.type.compress.CompressResource)1 MappingImpl (lucee.runtime.MappingImpl)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 BIF (lucee.runtime.ext.function.BIF)1 BIFProxy (lucee.runtime.functions.BIFProxy)1 LString (lucee.runtime.interpreter.ref.literal.LString)1 Key (lucee.runtime.type.Collection.Key)1 Query (lucee.runtime.type.Query)1