Search in sources :

Example 36 with Resource

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

the class XMLConfigAdmin method _updateConfigs.

private static void _updateConfigs(Config config, InputStream is, String realpath, boolean closeStream, List<Resource> filesDeployed, boolean store) throws PageException, IOException, SAXException, BundleException {
    // MUST get that dynamically
    Resource configs = config.getConfigDir();
    Resource trg = configs.getRealResource(realpath);
    if (trg.exists())
        trg.remove(true);
    Resource p = trg.getParentResource();
    if (!p.isDirectory())
        p.createDirectory(true);
    IOUtil.copy(is, trg.getOutputStream(false), closeStream, true);
    filesDeployed.add(trg);
    if (store)
        _storeAndReload((ConfigImpl) config);
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 37 with Resource

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

the class XMLConfigAdmin method _removeWebContexts.

private boolean _removeWebContexts(Config config, String realpath, boolean _store) throws PageException, IOException, SAXException, BundleException {
    if (config instanceof ConfigServer) {
        ConfigServer cs = ((ConfigServer) config);
        // remove files from deploy folder
        Resource deploy = cs.getConfigDir().getRealResource("web-context-deployment");
        Resource trg = deploy.getRealResource(realpath);
        if (trg.exists()) {
            trg.remove(true);
            ResourceUtil.removeEmptyFolders(deploy, null);
        }
        // remove files from lucee web context
        boolean store = false;
        ConfigWeb[] webs = cs.getConfigWebs();
        for (int i = 0; i < webs.length; i++) {
            if (_removeContext(webs[i], realpath, _store)) {
                store = true;
            }
        }
        return store;
    }
    return false;
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 38 with Resource

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

the class XMLConfigAdmin method updateArchive.

public void updateArchive(Config config, Resource archive) throws PageException {
    Log logger = ((ConfigImpl) config).getLog("deploy");
    String type = null, virtual = null, name = null;
    boolean readOnly, topLevel, hidden, physicalFirst;
    short inspect;
    int listMode, listType;
    InputStream is = null;
    ZipFile file = null;
    try {
        file = new ZipFile(FileWrapper.toFile(archive));
        ZipEntry entry = file.getEntry("META-INF/MANIFEST.MF");
        // no manifest
        if (entry == null) {
            DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
            throw new ApplicationException("cannot deploy " + Constants.NAME + " Archive [" + archive + "], file is to old, the file does not have a MANIFEST.");
        }
        is = file.getInputStream(entry);
        Manifest manifest = new Manifest(is);
        Attributes attr = manifest.getMainAttributes();
        // id = unwrap(attr.getValue("mapping-id"));
        type = StringUtil.unwrap(attr.getValue("mapping-type"));
        virtual = StringUtil.unwrap(attr.getValue("mapping-virtual-path"));
        name = ListUtil.trim(virtual, "/");
        readOnly = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-readonly")), false);
        topLevel = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-top-level")), false);
        listMode = ConfigWebUtil.toListenerMode(StringUtil.unwrap(attr.getValue("mapping-listener-mode")), -1);
        listType = ConfigWebUtil.toListenerType(StringUtil.unwrap(attr.getValue("mapping-listener-type")), -1);
        inspect = ConfigWebUtil.inspectTemplate(StringUtil.unwrap(attr.getValue("mapping-inspect")), Config.INSPECT_UNDEFINED);
        if (inspect == Config.INSPECT_UNDEFINED) {
            Boolean trusted = Caster.toBoolean(StringUtil.unwrap(attr.getValue("mapping-trusted")), null);
            if (trusted != null) {
                if (trusted.booleanValue())
                    inspect = Config.INSPECT_NEVER;
                else
                    inspect = Config.INSPECT_ALWAYS;
            }
        }
        hidden = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-hidden")), false);
        physicalFirst = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("mapping-physical-first")), false);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
        throw Caster.toPageException(t);
    } finally {
        IOUtil.closeEL(is);
        ZipUtil.close(file);
    }
    try {
        Resource trgDir = config.getConfigDir().getRealResource("archives").getRealResource(type).getRealResource(name);
        Resource trgFile = trgDir.getRealResource(archive.getName());
        trgDir.mkdirs();
        // delete existing files
        ResourceUtil.deleteContent(trgDir, null);
        ResourceUtil.moveTo(archive, trgFile, true);
        logger.log(Log.LEVEL_INFO, "archive", "add " + type + " mapping [" + virtual + "] with archive [" + trgFile.getAbsolutePath() + "]");
        if ("regular".equalsIgnoreCase(type))
            _updateMapping(virtual, null, trgFile.getAbsolutePath(), "archive", inspect, topLevel, listMode, listType, readOnly);
        else if ("cfc".equalsIgnoreCase(type))
            _updateComponentMapping(virtual, null, trgFile.getAbsolutePath(), "archive", inspect);
        else if ("ct".equalsIgnoreCase(type))
            _updateCustomTag(virtual, null, trgFile.getAbsolutePath(), "archive", inspect);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        DeployHandler.moveToFailedFolder(config.getDeployDirectory(), archive);
        throw Caster.toPageException(t);
    }
}
Also used : Log(lucee.commons.io.log.Log) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) Resource(lucee.commons.io.res.Resource) Manifest(java.util.jar.Manifest) ApplicationException(lucee.runtime.exp.ApplicationException) IsZipFile(lucee.runtime.functions.system.IsZipFile) ZipFile(java.util.zip.ZipFile)

Example 39 with Resource

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

the class XMLConfigAdmin method deployFilesFromStream.

private static void deployFilesFromStream(Config config, Resource root, InputStream is, String realpath, boolean closeStream, List<Resource> filesDeployed) throws PageException, IOException, SAXException {
    // MUST this makes no sense at this point
    if (config instanceof ConfigServer) {
        ConfigWeb[] webs = ((ConfigServer) config).getConfigWebs();
        if (webs.length == 0)
            return;
        if (webs.length == 1) {
            deployFilesFromStream(webs[0], root, is, realpath, closeStream, filesDeployed);
            return;
        }
        try {
            byte[] barr = IOUtil.toBytes(is);
            for (int i = 0; i < webs.length; i++) {
                deployFilesFromStream(webs[i], root, new ByteArrayInputStream(barr), realpath, true, filesDeployed);
            }
        } finally {
            if (closeStream)
                IOUtil.closeEL(is);
        }
        return;
    }
    // ConfigWeb
    Resource trg = root.getRealResource(realpath);
    if (trg.exists())
        trg.remove(true);
    Resource p = trg.getParentResource();
    if (!p.isDirectory())
        p.createDirectory(true);
    IOUtil.copy(is, trg.getOutputStream(false), closeStream, true);
    filesDeployed.add(trg);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(lucee.commons.io.res.Resource)

Example 40 with Resource

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

the class XMLConfigAdmin method installBundle.

public static Object installBundle(Config config, InputStream is, String name, String extensionVersion, boolean closeStream, boolean convert2bundle) throws IOException, BundleException {
    Resource tmp = SystemUtil.getTempDirectory().getRealResource(name);
    try {
        IOUtil.copy(is, tmp, closeStream);
        BundleFile bf = installBundle(config, tmp, extensionVersion, convert2bundle);
        if (bf != null)
            return bf;
        return tmp;
    } finally {
        tmp.delete();
    }
}
Also used : Resource(lucee.commons.io.res.Resource) BundleFile(lucee.runtime.osgi.BundleFile)

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