Search in sources :

Example 86 with Resource

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

the class ConfigWebUtil method getFile.

/**
 * touch a file object by the string definition
 * @param config
 * @param directory
 * @param path
 * @param type
 * @return matching file
 */
public static Resource getFile(Config config, Resource directory, String path, short type) {
    path = replacePlaceholder(path, config);
    if (!StringUtil.isEmpty(path, true)) {
        Resource file = getFile(directory.getRealResource(path), type);
        if (file != null)
            return file;
        file = getFile(config.getResource(path), type);
        if (file != null)
            return file;
    }
    return null;
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 87 with Resource

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

the class ConfigWebUtil method loadLib.

static void loadLib(ConfigServerImpl configServer, ConfigImpl config) throws IOException {
    // get lib and classes resources
    Resource lib = config.getLibraryDirectory();
    Resource[] libs = lib.listResources(ExtensionResourceFilter.EXTENSION_JAR_NO_DIR);
    // get resources from server config and merge
    if (configServer != null) {
        ResourceClassLoader rcl = configServer.getResourceClassLoader();
        libs = ResourceUtil.merge(libs, rcl.getResources());
    }
    CFMLEngine engine = ConfigWebUtil.getEngine(config);
    BundleContext bc = engine.getBundleContext();
    Log log = config.getLog("application");
    BundleFile bf;
    List<Resource> list = new ArrayList<Resource>();
    for (int i = 0; i < libs.length; i++) {
        try {
            bf = BundleFile.newInstance(libs[i]);
            // jar is not a bundle
            if (bf == null) {
                // convert to a bundle
                BundleBuilderFactory factory = new BundleBuilderFactory(libs[i]);
                factory.setVersion("0.0.0.0");
                Resource tmp = SystemUtil.getTempFile("jar", false);
                factory.build(tmp);
                IOUtil.copy(tmp, libs[i]);
                bf = BundleFile.newInstance(libs[i]);
            }
            OSGiUtil.start(OSGiUtil.installBundle(bc, libs[i], true));
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            list.add(libs[i]);
            log.log(Log.LEVEL_ERROR, "OSGi", t);
        }
    }
    // set classloader
    ClassLoader parent = SystemUtil.getCoreClassLoader();
    config.setResourceClassLoader(new ResourceClassLoader(list.toArray(new Resource[list.size()]), parent));
}
Also used : Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) BundleBuilderFactory(lucee.runtime.osgi.BundleBuilderFactory) ResourceClassLoader(lucee.commons.io.res.util.ResourceClassLoader) ResourceClassLoader(lucee.commons.io.res.util.ResourceClassLoader) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleFile(lucee.runtime.osgi.BundleFile) BundleContext(org.osgi.framework.BundleContext)

Example 88 with Resource

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

the class ConfigWebUtil method getFile.

/**
 * generate a file object by the string definition
 * @param rootDir
 * @param strDir
 * @param defaultDir
 * @param configDir
 * @param type
 * @param config
 * @return file
 */
static Resource getFile(Resource rootDir, String strDir, String defaultDir, Resource configDir, short type, ConfigImpl config) {
    strDir = replacePlaceholder(strDir, config);
    if (!StringUtil.isEmpty(strDir, true)) {
        Resource res;
        if (strDir.indexOf("://") != -1) {
            // TODO better impl.
            res = getFile(config.getResource(strDir), type);
            if (res != null)
                return res;
        }
        res = getFile(rootDir.getRealResource(strDir), type);
        if (res != null)
            return res;
        res = getFile(config.getResource(strDir), type);
        if (res != null)
            return res;
    }
    if (defaultDir == null)
        return null;
    Resource file = getFile(configDir.getRealResource(defaultDir), type);
    return file;
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 89 with Resource

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

the class ConfigWebUtil method deployWebContext.

/**
 * deploys all content in "web-context-deployment" to a web context, used for new context mostly or update existings
 * @param cs
 * @param cw
 * @param throwError
 * @throws IOException
 */
public static void deployWebContext(ConfigServer cs, ConfigWeb cw, boolean throwError) throws IOException {
    Resource deploy = cs.getConfigDir().getRealResource("web-context-deployment"), trg;
    if (!deploy.isDirectory())
        return;
    trg = cw.getConfigDir().getRealResource("context");
    try {
        _deploy(cw, deploy, trg);
    } catch (IOException ioe) {
        if (throwError)
            throw ioe;
        SystemOut.printDate(cw.getErrWriter(), ExceptionUtil.getStacktrace(ioe, true));
    }
}
Also used : Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException)

Example 90 with Resource

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

the class DeployHandler method downloadExtension.

public static Resource downloadExtension(Config config, ExtensionDefintion ed, Log log) {
    String apiKey = config.getIdentification().getApiKey();
    URL url;
    RHExtensionProvider[] providers = ((ConfigImpl) config).getRHExtensionProviders();
    for (int i = 0; i < providers.length; i++) {
        HTTPResponse rsp = null;
        try {
            url = providers[i].getURL();
            StringBuilder qs = new StringBuilder();
            addQueryParam(qs, "ioid", apiKey);
            addQueryParam(qs, "version", ed.getVersion());
            url = new URL(url, "/rest/extension/provider/full/" + ed.getId() + qs);
            rsp = HTTPEngine.get(url, null, null, -1, false, "UTF-8", "", null, new Header[] { new HeaderImpl("accept", "application/cfml") });
            if (rsp.getStatusCode() != 200)
                throw new IOException("failed to load extension: " + ed);
            // copy it locally
            Resource res = SystemUtil.getTempDirectory().getRealResource(ed.getId() + "-" + ed.getVersion() + ".lex");
            ResourceUtil.touch(res);
            IOUtil.copy(rsp.getContentAsStream(), res, true);
            return res;
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (log != null)
                log.error("extension", t);
        } finally {
            HTTPEngine.closeEL(rsp);
        }
    }
    return null;
}
Also used : HeaderImpl(lucee.commons.net.http.httpclient.HeaderImpl) HTTPResponse(lucee.commons.net.http.HTTPResponse) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) URL(java.net.URL) RHExtensionProvider(lucee.runtime.extension.RHExtensionProvider) Header(lucee.commons.net.http.Header)

Aggregations

Resource (lucee.commons.io.res.Resource)309 IOException (java.io.IOException)100 ApplicationException (lucee.runtime.exp.ApplicationException)54 PageException (lucee.runtime.exp.PageException)40 ArrayList (java.util.ArrayList)31 Struct (lucee.runtime.type.Struct)28 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 ExpressionException (lucee.runtime.exp.ExpressionException)19 StructImpl (lucee.runtime.type.StructImpl)18 MalformedURLException (java.net.MalformedURLException)17 PageContextImpl (lucee.runtime.PageContextImpl)17 PageSource (lucee.runtime.PageSource)16 FileResource (lucee.commons.io.res.type.file.FileResource)15 SecurityException (lucee.runtime.exp.SecurityException)15 BundleException (org.osgi.framework.BundleException)15 ZipEntry (java.util.zip.ZipEntry)13 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)13 Array (lucee.runtime.type.Array)13 File (java.io.File)12