Search in sources :

Example 16 with Resource

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

the class _GetElement method toStruct.

@Override
public Object toStruct() {
    Resource[] locs = getCfcLocations();
    Array arrLocs = new ArrayImpl();
    if (locs != null)
        for (int i = 0; i < locs.length; i++) {
            arrLocs.appendEL(getAbsolutePath(locs[i]));
        }
    Struct sct = new StructImpl();
    sct.setEL(AUTO_GEN_MAP, this.autogenmap());
    sct.setEL(CATALOG, StringUtil.emptyIfNull(getCatalog()));
    sct.setEL(CFC_LOCATION, arrLocs);
    sct.setEL(IS_DEFAULT_CFC_LOCATION, isDefaultCfcLocation());
    sct.setEL(DB_CREATE, dbCreateAsString(getDbCreate()));
    sct.setEL(DIALECT, StringUtil.emptyIfNull(getDialect()));
    sct.setEL(EVENT_HANDLING, eventHandling());
    sct.setEL(EVENT_HANDLER, eventHandler());
    sct.setEL(NAMING_STRATEGY, namingStrategy());
    sct.setEL(FLUSH_AT_REQUEST_END, flushAtRequestEnd());
    sct.setEL(LOG_SQL, logSQL());
    sct.setEL(SAVE_MAPPING, saveMapping());
    sct.setEL(SCHEMA, StringUtil.emptyIfNull(getSchema()));
    sct.setEL(SECONDARY_CACHE_ENABLED, secondaryCacheEnabled());
    sct.setEL(SQL_SCRIPT, StringUtil.toStringEmptyIfNull(getSqlScript()));
    sct.setEL(USE_DB_FOR_MAPPING, useDBForMapping());
    sct.setEL(CACHE_CONFIG, getAbsolutePath(getCacheConfig()));
    sct.setEL(CACHE_PROVIDER, StringUtil.emptyIfNull(getCacheProvider()));
    sct.setEL(ORM_CONFIG, getAbsolutePath(getOrmConfig()));
    return sct;
}
Also used : Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) Resource(lucee.commons.io.res.Resource) Struct(lucee.runtime.type.Struct)

Example 17 with Resource

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

the class OSGiUtil method installBundle.

/**
 * only installs a bundle, if the bundle does not already exist, if the bundle exists the existing bundle is unloaded first.
 * the bundle is not stored physically on the system.
 * @param factory
 * @param context
 * @param bundle
 * @return
 * @throws IOException
 * @throws BundleException
 */
public static Bundle installBundle(BundleContext context, InputStream bundleIS, boolean closeStream, boolean checkExistence) throws IOException, BundleException {
    // store locally to test the bundle
    String name = System.currentTimeMillis() + ".tmp";
    Resource dir = SystemUtil.getTempDirectory();
    Resource tmp = dir.getRealResource(name);
    int count = 0;
    while (tmp.exists()) tmp = dir.getRealResource((count++) + "_" + name);
    IOUtil.copy(bundleIS, tmp, closeStream);
    try {
        return installBundle(context, tmp, checkExistence);
    } finally {
        tmp.delete();
    }
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 18 with Resource

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

the class OSGiUtil method downloadBundle.

private static Resource downloadBundle(CFMLEngineFactory factory, final String symbolicName, String symbolicVersion, Identification id) throws IOException, BundleException {
    final Resource jarDir = ResourceUtil.toResource(factory.getBundleDirectory());
    final URL updateProvider = factory.getUpdateLocation();
    if (symbolicVersion == null)
        symbolicVersion = "latest";
    final URL updateUrl = new URL(updateProvider, "/rest/update/provider/download/" + symbolicName + "/" + symbolicVersion + "/" + (id != null ? id.toQueryString() : "") + (id == null ? "?" : "&") + "allowRedirect=true");
    log(Logger.LOG_DEBUG, "download bundle [" + symbolicName + ":" + symbolicVersion + "] ");
    int code;
    HttpURLConnection conn;
    try {
        conn = (HttpURLConnection) updateUrl.openConnection();
        conn.setRequestMethod("GET");
        conn.connect();
        code = conn.getResponseCode();
    } catch (UnknownHostException e) {
        throw new IOException("could not download the bundle  [" + symbolicName + ":" + symbolicVersion + "] from " + updateUrl, e);
    }
    // the update provider is not providing a download for this
    if (code != 200) {
        // the update provider can also provide a different (final) location for this
        if (code == 302) {
            String location = conn.getHeaderField("Location");
            // just in case we check invalid names
            if (location == null)
                location = conn.getHeaderField("location");
            if (location == null)
                location = conn.getHeaderField("LOCATION");
            // MUST remove
            System.out.println("download redirected:" + location);
            conn.disconnect();
            URL url = new URL(location);
            try {
                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                conn.connect();
                code = conn.getResponseCode();
            } catch (final UnknownHostException e) {
                log(e);
                throw new IOException("could not download the bundle  [" + symbolicName + ":" + symbolicVersion + "] from " + location, e);
            }
        }
        // no download available!
        if (code != 200) {
            final String msg = "Lucee is not able do download the bundle for [" + symbolicName + "] in version [" + symbolicVersion + "] from " + updateUrl + ", please donwload manually and copy to [" + jarDir + "]";
            log(Logger.LOG_ERROR, msg);
            conn.disconnect();
            throw new IOException(msg);
        }
    }
    // extract version if necessary
    if ("latest".equals(symbolicVersion)) {
        // copy to temp file
        Resource temp = SystemUtil.getTempFile("jar", false);
        IOUtil.copy((InputStream) conn.getContent(), temp, true);
        try {
            conn.disconnect();
            // extract version and create file with correct name
            BundleFile bf = new BundleFile(temp);
            Resource jar = jarDir.getRealResource(symbolicName + "-" + bf.getVersionAsString() + ".jar");
            IOUtil.copy(temp, jar);
            return jar;
        } finally {
            temp.delete();
        }
    } else {
        Resource jar = jarDir.getRealResource(symbolicName + "-" + symbolicVersion + ".jar");
        IOUtil.copy((InputStream) conn.getContent(), jar, true);
        conn.disconnect();
        return jar;
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) UnknownHostException(java.net.UnknownHostException) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) URL(java.net.URL)

Example 19 with Resource

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

the class Mapping method _init.

private static ArrayList<Source> _init(PageContext pc, Mapping mapping, Resource dir) throws PageException {
    Resource[] children = dir.listResources(FILTER);
    RestSettings settings = pc.getApplicationContext().getRestSettings();
    ArrayList<Source> sources = new ArrayList<Source>();
    PageSource ps;
    Component cfc;
    Struct meta;
    String path;
    for (int i = 0; i < children.length; i++) {
        try {
            ps = pc.toPageSource(children[i], null);
            cfc = ComponentLoader.loadComponent(pc, ps, children[i].getName(), true, true);
            meta = cfc.getMetaData(pc);
            if (Caster.toBooleanValue(meta.get(KeyConstants._rest, null), false)) {
                path = Caster.toString(meta.get(KeyConstants._restPath, null), null);
                sources.add(new Source(mapping, cfc.getPageSource(), path));
            }
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (!settings.getSkipCFCWithError())
                throw Caster.toPageException(t);
        }
    }
    return sources;
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) Component(lucee.runtime.Component) PageSource(lucee.runtime.PageSource) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 20 with Resource

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

the class DataSourceServiceImpl method getDrivers.

@Override
public Struct getDrivers() throws ServiceException, SecurityException {
    checkReadAccess();
    Struct rtn = new StructImpl();
    Struct driver;
    try {
        Resource luceeContext = ResourceUtil.toResourceExisting(pc(), "/lucee/admin/dbdriver/");
        Resource[] children = luceeContext.listResources(new ExtensionResourceFilter(Constants.getComponentExtensions()));
        String name;
        for (int i = 0; i < children.length; i++) {
            driver = new StructImpl();
            name = ListFirst.call(pc(), children[i].getName(), ".");
            driver.setEL(KeyConstants._name, name);
            driver.setEL("handler", children[i].getName());
            rtn.setEL(name, driver);
        }
    } catch (ExpressionException e) {
        throw new ServiceException(e.getMessage());
    }
    return rtn;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ServiceException(coldfusion.server.ServiceException) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct)

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