Search in sources :

Example 91 with Resource

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

the class DeployHandler method getExtension.

public static Resource getExtension(Config config, ExtensionDefintion ed, Log log) {
    // local
    ExtensionDefintion ext = getLocalExtension(config, ed, null);
    if (ext != null) {
        try {
            Resource src = ext.getSource();
            if (src.exists()) {
                Resource res = SystemUtil.getTempDirectory().getRealResource(ed.getId() + "-" + ed.getVersion() + ".lex");
                ResourceUtil.touch(res);
                IOUtil.copy(ext.getSource(), res);
                return res;
            }
        } catch (Exception e) {
        }
    }
    // remote
    return downloadExtension(config, ed, log);
}
Also used : ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) Resource(lucee.commons.io.res.Resource) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException)

Example 92 with Resource

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

the class ExportImportHandler method export.

public static void export(PageContext pc, ConfigServer cs, short types, String target, boolean addOptionalArtifacts, String regularMappingFilter, String componentMappingFilter, String customtagMappingFilter) throws IOException, PageException, ConverterException {
    Resource tmp = SystemUtil.getTempDirectory();
    Resource dir;
    // we need a new directory
    do {
        dir = tmp.getRealResource(CreateUniqueId.invoke());
    } while (dir.isDirectory());
    dir.createDirectory(true);
    Resource configFile = dir.getRealResource("config.json");
    try {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Resource> artifacts;
        artifacts = new HashMap<String, Resource>();
        map.put("artifacts", artifacts);
        // server
        map.put("server", _export((ConfigImpl) cs, types, dir.getRealResource("server"), "/server", addOptionalArtifacts, regularMappingFilter, componentMappingFilter, customtagMappingFilter));
        // webs
        Resource websDir = dir.getRealResource("webs");
        List<Map<String, Object>> webs = new ArrayList<Map<String, Object>>();
        map.put("webs", webs);
        String id;
        for (ConfigWeb cw : cs.getConfigWebs()) {
            id = cw.getIdentification().getId();
            webs.add(_export((ConfigImpl) cw, types, websDir.getRealResource(id), "/webs/" + id, addOptionalArtifacts, regularMappingFilter, componentMappingFilter, customtagMappingFilter));
        }
        // store config
        IOUtil.copy(toIS(JSONConverter.serialize(pc, map)), configFile, true);
        // zip everything
        CompressUtil.compress(CompressUtil.FORMAT_ZIP, dir, ResourceUtil.toResourceNotExisting(pc, target), false, -1);
    } finally {
        dir.delete();
    }
}
Also used : HashMap(java.util.HashMap) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 93 with Resource

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

the class ExportImportHandler method _export.

private static Map<String, Object> _export(ConfigImpl config, short types, Resource dir, String pathAppendix, boolean addOptionalArtifacts, String regularMappingFilter, String componentMappingFilter, String customtagMappingFilter) throws IOException {
    Map<String, Object> map = new HashMap<String, Object>();
    // Core
    if ((types & TYPE_CONFIGURATION) > 0) {
    }
    // Extension
    if ((types & TYPE_EXTENSION) > 0) {
        Resource extDir = dir.getRealResource("extensions");
        extDir.mkdirs();
        List<Object> extensions = new ArrayList<Object>();
        map.put("extensions", extensions);
        Map<String, String> m;
        for (RHExtension ext : config.getRHExtensions()) {
            m = new HashMap<String, String>();
            extensions.add(m);
            m.put("id", ext.getId());
            m.put("version", ext.getVersion());
            if (dir != null) {
                m.put("artifact", pathAppendix + "/extensions/" + ext.getExtensionFile().getName());
                if (addOptionalArtifacts)
                    IOUtil.copy(ext.getExtensionFile(), extDir.getRealResource(ext.getExtensionFile().getName()));
            }
        }
    }
    // Core
    if ((types & TYPE_CORE) > 0 && config instanceof ConfigServer) {
        map.put("core", CFMLEngineFactory.getInstance().getInfo().getVersion().toString());
    }
    // Files
    if ((types & TYPE_FILES) > 0) {
        Resource mapDir = dir.getRealResource("mappings");
        HashMap<String, Object> mappings = new HashMap<String, Object>();
        map.put("mappings", mappings);
        mappings.put("regular", exportMapping(config.getMappings(), mapDir.getRealResource("regular"), pathAppendix + "/mappings/regular/", regularMappingFilter));
        mappings.put("component", exportMapping(config.getComponentMappings(), mapDir.getRealResource("component"), pathAppendix + "/mappings/component/", componentMappingFilter));
        mappings.put("customtag", exportMapping(config.getCustomTagMappings(), mapDir.getRealResource("customtag"), pathAppendix + "/mappings/customtag/", customtagMappingFilter));
    }
    return map;
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) HashMap(java.util.HashMap) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList)

Example 94 with Resource

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

the class ResourceSupport method list.

@Override
public String[] list(ResourceFilter filter) {
    String[] files = list();
    if (files == null)
        return null;
    List list = new ArrayList();
    Resource res;
    for (int i = 0; i < files.length; i++) {
        res = getRealResource(files[i]);
        if (filter.accept(res))
            list.add(files[i]);
    }
    return (String[]) list.toArray(new String[list.size()]);
}
Also used : ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) List(java.util.List) ArrayList(java.util.ArrayList)

Example 95 with Resource

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

the class ResourceSupport method listResources.

@Override
public Resource[] listResources(ResourceFilter filter) {
    String[] files = list();
    if (files == null)
        return null;
    List list = new ArrayList();
    Resource res;
    for (int i = 0; i < files.length; i++) {
        res = this.getRealResource(files[i]);
        if (filter.accept(res))
            list.add(res);
    }
    return (Resource[]) list.toArray(new Resource[list.size()]);
}
Also used : ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) List(java.util.List) ArrayList(java.util.ArrayList)

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