Search in sources :

Example 6 with ResourceFilter

use of lucee.commons.io.res.filter.ResourceFilter in project Lucee by lucee.

the class Zip method actionZip.

private void actionZip(ZipOutputStream zos, ZipParamSource zps) throws IOException, ApplicationException {
    // prefix
    String p = zps.getPrefix();
    if (StringUtil.isEmpty(p))
        p = this.prefix;
    if (!StringUtil.isEmpty(p)) {
        if (!StringUtil.endsWith(p, '/'))
            p += "/";
    } else
        p = "";
    if (zps.getSource().isFile()) {
        String ep = zps.getEntryPath();
        if (ep == null)
            ep = zps.getSource().getName();
        if (!StringUtil.isEmpty(p))
            ep = p + ep;
        add(zos, zps.getSource().getInputStream(), ep, zps.getSource().lastModified(), true);
    } else {
        // filter
        ResourceFilter f = zps.getFilter();
        if (f == null)
            f = this.filter;
        if (zps.isRecurse()) {
            if (f != null)
                f = new OrResourceFilter(new ResourceFilter[] { DirectoryResourceFilter.FILTER, f });
        } else {
            if (f == null)
                f = FileResourceFilter.FILTER;
        }
        addDir(zos, zps.getSource(), p, f);
    }
}
Also used : FileResourceFilter(lucee.commons.io.res.filter.FileResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) ResourceFilter(lucee.commons.io.res.filter.ResourceFilter) DirectoryResourceFilter(lucee.commons.io.res.filter.DirectoryResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter)

Example 7 with ResourceFilter

use of lucee.commons.io.res.filter.ResourceFilter in project Lucee by lucee.

the class ExportImportHandler method exportMapping.

private static List<Object> exportMapping(Mapping[] mappings, Resource dir, String pathAppendix, String filter) throws IOException {
    List<Object> list = new ArrayList<Object>();
    Map<String, Object> m;
    for (Mapping mapping : mappings) {
        MappingImpl mi = (MappingImpl) mapping;
        m = new HashMap<String, Object>();
        list.add(m);
        m.put("virtual", mapping.getVirtual());
        m.put("inspect", ConfigWebUtil.inspectTemplate(mi.getInspectTemplateRaw(), ""));
        m.put("toplevel", mapping.isTopLevel());
        m.put("readonly", mapping.isReadonly());
        m.put("hidden", mapping.isHidden());
        m.put("physicalFirst", mapping.isPhysicalFirst());
        m.put("hidden", mapping.isHidden());
        // archive
        if (mapping.hasArchive()) {
            Resource archive = mapping.getArchive();
            if (archive.isFile()) {
                Resource arcDir = dir.getRealResource("archive/");
                arcDir.mkdir();
                m.put("archive", pathAppendix + "archive/" + archive.getName());
                IOUtil.copy(archive, arcDir.getRealResource(archive.getName()));
            }
        }
        // physical
        if (mapping.hasPhysical()) {
            Resource physical = mi.getPhysical();
            if (physical.isDirectory()) {
                String id = CreateUniqueId.invoke();
                Resource phyDir = dir.getRealResource("physical/" + id);
                phyDir.mkdirs();
                m.put("physical", pathAppendix + "physical/" + id);
                ResourceFilter f = null;
                if (!StringUtil.isEmpty(filter)) {
                    f = new OrResourceFilter(new ResourceFilter[] { new WildcardPatternFilter(filter, ","), DirectoryResourceFilter.FILTER });
                }
                if (// PATCH this needs more digging
                !physical.getAbsolutePath().equals("/"))
                    ResourceUtil.copyRecursive(physical, phyDir, f);
            }
        }
    }
    return list;
}
Also used : OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) ResourceFilter(lucee.commons.io.res.filter.ResourceFilter) DirectoryResourceFilter(lucee.commons.io.res.filter.DirectoryResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.Mapping) WildcardPatternFilter(lucee.commons.io.res.util.WildcardPatternFilter) MappingImpl(lucee.runtime.MappingImpl)

Aggregations

ResourceFilter (lucee.commons.io.res.filter.ResourceFilter)7 OrResourceFilter (lucee.commons.io.res.filter.OrResourceFilter)6 Resource (lucee.commons.io.res.Resource)5 DirectoryResourceFilter (lucee.commons.io.res.filter.DirectoryResourceFilter)5 IOException (java.io.IOException)3 FileResourceFilter (lucee.commons.io.res.filter.FileResourceFilter)3 NotResourceFilter (lucee.commons.io.res.filter.NotResourceFilter)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 AndResourceFilter (lucee.commons.io.res.filter.AndResourceFilter)2 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)2 FileResource (lucee.commons.io.res.type.file.FileResource)2 MappingImpl (lucee.runtime.MappingImpl)2 SecurityManager (lucee.runtime.security.SecurityManager)2 ArrayList (java.util.ArrayList)1 Attributes (java.util.jar.Attributes)1 Manifest (java.util.jar.Manifest)1 ResourceMetaData (lucee.commons.io.res.ResourceMetaData)1 WildcardPatternFilter (lucee.commons.io.res.util.WildcardPatternFilter)1 Mapping (lucee.runtime.Mapping)1 DynamicAttributes (lucee.runtime.ext.tag.DynamicAttributes)1