Search in sources :

Example 1 with ResourceProvider

use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.

the class CFMLEngineImpl method getConfigDirectory.

/**
 * loads Configuration File from System, from init Parameter from web.xml
 *
 * @param sg
 * @param configServer
 * @param countExistingContextes
 * @return return path to directory
 */
private Resource getConfigDirectory(ServletConfig sg, ConfigServerImpl configServer, int countExistingContextes, RefBoolean isCustomSetting) throws PageServletException {
    isCustomSetting.setValue(true);
    ServletContext sc = sg.getServletContext();
    String strConfig = sg.getInitParameter("configuration");
    if (StringUtil.isEmpty(strConfig))
        strConfig = sg.getInitParameter("lucee-web-directory");
    if (StringUtil.isEmpty(strConfig))
        strConfig = System.getProperty("lucee.web.dir");
    if (StringUtil.isEmpty(strConfig)) {
        isCustomSetting.setValue(false);
        strConfig = "{web-root-directory}/WEB-INF/lucee/";
    } else // only for backward compatibility
    if (strConfig.startsWith("/WEB-INF/lucee/"))
        strConfig = "{web-root-directory}" + strConfig;
    strConfig = StringUtil.removeQuotes(strConfig, true);
    // static path is not allowed
    if (countExistingContextes > 1 && strConfig != null && strConfig.indexOf('{') == -1) {
        String text = "static path [" + strConfig + "] for servlet init param [lucee-web-directory] is not allowed, path must use a web-context specific placeholder.";
        System.err.println(text);
        throw new PageServletException(new ApplicationException(text));
    }
    strConfig = SystemUtil.parsePlaceHolder(strConfig, sc, configServer.getLabels());
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    Resource root = frp.getResource(ReqRspUtil.getRootPath(sc));
    Resource res;
    Resource configDir = ResourceUtil.createResource(res = root.getRealResource(strConfig), FileUtil.LEVEL_PARENT_FILE, FileUtil.TYPE_DIR);
    if (configDir == null) {
        configDir = ResourceUtil.createResource(res = frp.getResource(strConfig), FileUtil.LEVEL_GRAND_PARENT_FILE, FileUtil.TYPE_DIR);
    }
    if (configDir == null && !isCustomSetting.toBooleanValue()) {
        try {
            res.createDirectory(true);
            configDir = res;
        } catch (IOException e) {
            throw new PageServletException(Caster.toPageException(e));
        }
    }
    if (configDir == null) {
        throw new PageServletException(new ApplicationException("path [" + strConfig + "] is invalid"));
    }
    if (!configDir.exists() || ResourceUtil.isEmptyDirectory(configDir, null)) {
        Resource railoRoot;
        // there is a railo directory
        if (configDir.getName().equals("lucee") && (railoRoot = configDir.getParentResource().getRealResource("railo")).isDirectory()) {
            try {
                copyRecursiveAndRename(railoRoot, configDir);
            } catch (IOException e) {
                try {
                    configDir.createDirectory(true);
                } catch (IOException ioe) {
                }
                return configDir;
            }
            // zip the railo-server di and delete it (optional)
            try {
                Resource p = railoRoot.getParentResource();
                CompressUtil.compress(CompressUtil.FORMAT_ZIP, railoRoot, p.getRealResource("railo-web-context-old.zip"), false, -1);
                ResourceUtil.removeEL(railoRoot, true);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        } else {
            try {
                configDir.createDirectory(true);
            } catch (IOException e) {
            }
        }
    }
    return configDir;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) ResourceProvider(lucee.commons.io.res.ResourceProvider) Resource(lucee.commons.io.res.Resource) ServletContext(javax.servlet.ServletContext) PageServletException(lucee.runtime.exp.PageServletException) IOException(java.io.IOException)

Example 2 with ResourceProvider

use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.

the class GetVFSMetaData method call.

public static Struct call(PageContext pc, String scheme) {
    ResourceProvider[] providers = pc.getConfig().getResourceProviders();
    ResourceProvider provider;
    scheme = scheme.trim();
    Struct sct = new StructImpl();
    for (int i = 0; i < providers.length; i++) {
        provider = providers[i];
        if (provider.getScheme().equalsIgnoreCase(scheme)) {
            // MUST sct=provider.getMetaData();
            sct.setEL("Scheme", provider.getScheme());
            sct.setEL("Attributes", provider.isAttributesSupported());
            sct.setEL("CaseSensitive", provider.isCaseSensitive());
            sct.setEL("Mode", provider.isModeSupported());
            sct.setEL("Enabled", Boolean.TRUE);
            return sct;
        }
    }
    sct.setEL("Enabled", Boolean.FALSE);
    return sct;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ResourceProvider(lucee.commons.io.res.ResourceProvider) Struct(lucee.runtime.type.Struct)

Example 3 with ResourceProvider

use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.

the class MacAddressWrap method getRuningContextRoot.

/**
 * @return return running context root
 */
public static Resource getRuningContextRoot() {
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    try {
        return frp.getResource(".").getCanonicalResource();
    } catch (IOException e) {
    }
    URL url = InfoImpl.class.getClassLoader().getResource(".");
    try {
        return frp.getResource(FileUtil.URLToFile(url).getAbsolutePath());
    } catch (MalformedURLException e) {
        return null;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ResourceProvider(lucee.commons.io.res.ResourceProvider) IOException(java.io.IOException) URL(java.net.URL) InfoImpl(lucee.runtime.engine.InfoImpl)

Example 4 with ResourceProvider

use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.

the class MacAddressWrap method getClassPathesFromClassLoader.

/**
 * get class pathes from all url ClassLoaders
 *
 * @param ucl
 *            URL Class Loader
 * @param pathes
 *            Hashmap with allpathes
 */
private static void getClassPathesFromClassLoader(URLClassLoader ucl, ArrayList<Resource> pathes) {
    ClassLoader pcl = ucl.getParent();
    // parent first
    if (pcl instanceof URLClassLoader)
        getClassPathesFromClassLoader((URLClassLoader) pcl, pathes);
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    // get all pathes
    URL[] urls = ucl.getURLs();
    for (int i = 0; i < urls.length; i++) {
        Resource file = frp.getResource(urls[i].getPath());
        if (file.exists())
            pathes.add(ResourceUtil.getCanonicalResourceEL(file));
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) ResourceProvider(lucee.commons.io.res.ResourceProvider) Resource(lucee.commons.io.res.Resource) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL)

Example 5 with ResourceProvider

use of lucee.commons.io.res.ResourceProvider in project Lucee by lucee.

the class MacAddressWrap method getHomeDirectory.

/**
 * returns the Hoome Directory of the System
 *
 * @return home directory
 */
public static Resource getHomeDirectory() {
    if (homeFile != null)
        return homeFile;
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    String homeStr = System.getProperty("user.home");
    if (homeStr != null) {
        homeFile = frp.getResource(homeStr);
        homeFile = ResourceUtil.getCanonicalResourceEL(homeFile);
    }
    return homeFile;
}
Also used : ResourceProvider(lucee.commons.io.res.ResourceProvider)

Aggregations

ResourceProvider (lucee.commons.io.res.ResourceProvider)13 Resource (lucee.commons.io.res.Resource)4 CompressResourceProvider (lucee.commons.io.res.type.compress.CompressResourceProvider)3 ClassException (lucee.commons.lang.ClassException)3 IOException (java.io.IOException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1 RamResourceProviderOld (lucee.commons.io.res.type.ram.RamResourceProviderOld)1 Config (lucee.runtime.config.Config)1 InfoImpl (lucee.runtime.engine.InfoImpl)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 PageServletException (lucee.runtime.exp.PageServletException)1 Array (lucee.runtime.type.Array)1 Query (lucee.runtime.type.Query)1 QueryImpl (lucee.runtime.type.QueryImpl)1 Struct (lucee.runtime.type.Struct)1