use of lucee.commons.io.res.filter.OrResourceFilter in project Lucee by lucee.
the class Directory method actionCopy.
public static void actionCopy(PageContext pc, Resource directory, String strDestination, String serverPassword, boolean createPath, Object acl, String storage, final ResourceFilter filter, boolean recurse, int nameconflict) throws PageException {
// check directory
SecurityManager securityManager = pc.getConfig().getSecurityManager();
securityManager.checkFileLocation(pc.getConfig(), directory, serverPassword);
if (!directory.exists())
throw new ApplicationException("directory [" + directory.toString() + "] doesn't exist");
if (!directory.isDirectory())
throw new ApplicationException("file [" + directory.toString() + "] exists, but isn't a directory");
if (!directory.canRead())
throw new ApplicationException("no access to read directory [" + directory.toString() + "]");
if (StringUtil.isEmpty(strDestination))
throw new ApplicationException("attribute destination is not defined");
// real to source
Resource newdirectory = toDestination(pc, strDestination, directory);
if (nameconflict == NAMECONFLICT_ERROR && newdirectory.exists())
throw new ApplicationException("new directory [" + newdirectory.toString() + "] already exist");
securityManager.checkFileLocation(pc.getConfig(), newdirectory, serverPassword);
try {
boolean clearEmpty = false;
// has already a filter
ResourceFilter f = null;
if (filter != null) {
if (!recurse) {
f = new AndResourceFilter(new ResourceFilter[] { filter, new NotResourceFilter(DirectoryResourceFilter.FILTER) });
} else {
clearEmpty = true;
f = new OrResourceFilter(new ResourceFilter[] { filter, DirectoryResourceFilter.FILTER });
}
} else {
if (!recurse)
f = new NotResourceFilter(DirectoryResourceFilter.FILTER);
}
if (!createPath) {
Resource p = newdirectory.getParentResource();
if (p != null && !p.exists())
throw new ApplicationException("parent directory for [" + newdirectory + "] doesn't exist");
}
ResourceUtil.copyRecursive(directory, newdirectory, f);
if (clearEmpty)
ResourceUtil.removeEmptyFolders(newdirectory, f == null ? null : new NotResourceFilter(filter));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw new ApplicationException(t.getMessage());
}
// set S3 stuff
setS3Attrs(pc, directory, acl, storage);
}
use of lucee.commons.io.res.filter.OrResourceFilter in project Lucee by lucee.
the class CompressUtil method extractZip.
private static void extractZip(Resource zipFile, Resource targetDir) throws IOException {
if (!targetDir.exists() || !targetDir.isDirectory())
throw new IOException(targetDir + " is not a existing directory");
if (!zipFile.exists())
throw new IOException(zipFile + " is not a existing file");
if (zipFile.isDirectory()) {
Resource[] files = zipFile.listResources(new OrResourceFilter(new ResourceFilter[] { new ExtensionResourceFilter("zip"), new ExtensionResourceFilter("jar"), new ExtensionResourceFilter("war"), new ExtensionResourceFilter("tar"), new ExtensionResourceFilter("ear") }));
if (files == null)
throw new IOException("directory " + zipFile + " is empty");
extract(FORMAT_ZIP, files, targetDir);
return;
}
// read the zip file and build a query from its contents
unzip(zipFile, targetDir);
/*ZipInputStream zis=null;
try {
zis = new ZipInputStream( IOUtil.toBufferedInputStream(zipFile.getInputStream()) ) ;
ZipEntry entry;
while ( ( entry = zis.getNextEntry()) != null ) {
Resource target=targetDir.getRealResource(entry.getName());
if(entry.isDirectory()) {
target.mkdirs();
}
else {
Resource parent=target.getParentResource();
if(!parent.exists())parent.mkdirs();
IOUtil.copy(zis,target,false);
}
target.setLastModified(entry.getTime());
zis.closeEntry() ;
}
}
finally {
IOUtil.closeEL(zis);
}*/
}
use of lucee.commons.io.res.filter.OrResourceFilter 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);
}
}
use of lucee.commons.io.res.filter.OrResourceFilter 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;
}
Aggregations