use of lucee.commons.io.res.filter.NotResourceFilter 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.NotResourceFilter in project Lucee by lucee.
the class Admin method doCreateArchive.
private void doCreateArchive(short mappingType) throws PageException {
String virtual = getString("admin", action, "virtual").toLowerCase();
String strFile = getString("admin", action, "file");
Resource file = ResourceUtil.toResourceNotExisting(pageContext, strFile);
boolean addCFMLFiles = getBoolV("addCFMLFiles", true);
boolean addNonCFMLFiles = getBoolV("addNonCFMLFiles", true);
Boolean ignoreScopes = getBool("ignoreScopes", null);
// compile
MappingImpl mapping = (MappingImpl) doCompileMapping(mappingType, virtual, true, ignoreScopes);
// class files
if (mapping == null)
throw new ApplicationException("there is no mapping for [" + virtual + "]");
if (!mapping.hasPhysical())
throw new ApplicationException("mapping [" + virtual + "] has no physical directory");
Resource classRoot = mapping.getClassRootDirectory();
Resource temp = SystemUtil.getTempDirectory().getRealResource("mani-" + IDGenerator.stringId());
Resource mani = temp.getRealResource("META-INF/MANIFEST.MF");
try {
if (file.exists())
file.delete();
if (!file.exists())
file.createFile(true);
ResourceFilter filter;
// include everything, no filter needed
if (addCFMLFiles && addNonCFMLFiles)
filter = null;
else // CFML Files but no other files
if (addCFMLFiles) {
if (mappingType == MAPPING_CFC)
filter = new ExtensionResourceFilter(ArrayUtil.toArray(Constants.getComponentExtensions(), "class", "MF"), true, true);
else
filter = new ExtensionResourceFilter(ArrayUtil.toArray(Constants.getExtensions(), "class", "MF"), true, true);
} else // No CFML Files, but all other files
if (addNonCFMLFiles) {
filter = new NotResourceFilter(new ExtensionResourceFilter(Constants.getExtensions(), false, true));
} else // no files at all
{
filter = new ExtensionResourceFilter(new String[] { "class", "MF" }, true, true);
}
String id = HashUtil.create64BitHashAsString(mapping.getStrPhysical(), Character.MAX_RADIX);
// String id = MD5.getDigestAsString(mapping.getStrPhysical());
String type;
if (mappingType == MAPPING_CFC)
type = "cfc";
else if (mappingType == MAPPING_CT)
type = "ct";
else
type = "regular";
String token = HashUtil.create64BitHashAsString(System.currentTimeMillis() + "", Character.MAX_RADIX);
// create manifest
Manifest mf = new Manifest();
// StringBuilder manifest=new StringBuilder();
// Write OSGi specific stuff
Attributes attrs = mf.getMainAttributes();
attrs.putValue("Bundle-ManifestVersion", Caster.toString(BundleBuilderFactory.MANIFEST_VERSION));
attrs.putValue("Bundle-SymbolicName", id);
attrs.putValue("Bundle-Name", ListUtil.trim(mapping.getVirtual().replace('/', '.'), "."));
attrs.putValue("Bundle-Description", "this is a " + type + " mapping generated by " + Constants.NAME + ".");
attrs.putValue("Bundle-Version", "1.0.0." + token);
// attrs.putValue("Import-Package","lucee.*");
attrs.putValue("Require-Bundle", "lucee.core");
// Mapping
attrs.putValue("mapping-id", id);
attrs.putValue("mapping-type", type);
attrs.putValue("mapping-virtual-path", mapping.getVirtual());
attrs.putValue("mapping-hidden", Caster.toString(mapping.isHidden()));
attrs.putValue("mapping-physical-first", Caster.toString(mapping.isPhysicalFirst()));
attrs.putValue("mapping-readonly", Caster.toString(mapping.isReadonly()));
attrs.putValue("mapping-top-level", Caster.toString(mapping.isTopLevel()));
attrs.putValue("mapping-inspect", ConfigWebUtil.inspectTemplate(mapping.getInspectTemplateRaw(), ""));
attrs.putValue("mapping-listener-type", ConfigWebUtil.toListenerType(mapping.getListenerType(), ""));
attrs.putValue("mapping-listener-mode", ConfigWebUtil.toListenerMode(mapping.getListenerMode(), ""));
mani.createFile(true);
IOUtil.write(mani, ManifestUtil.toString(mf, 100, null, null), "UTF-8", false);
// source files
Resource[] sources;
if (!addCFMLFiles && !addNonCFMLFiles)
sources = new Resource[] { temp, classRoot };
else
sources = new Resource[] { temp, mapping.getPhysical(), classRoot };
CompressUtil.compressZip(ResourceUtil.listResources(sources, filter), file, filter);
if (getBoolV("append", false)) {
if (mappingType == MAPPING_CFC) {
admin.updateComponentMapping(mapping.getVirtual(), mapping.getStrPhysical(), strFile, mapping.isPhysicalFirst() ? "physical" : "archive", mapping.getInspectTemplateRaw());
} else if (mappingType == MAPPING_CT) {
admin.updateCustomTag(mapping.getVirtual(), mapping.getStrPhysical(), strFile, mapping.isPhysicalFirst() ? "physical" : "archive", mapping.getInspectTemplateRaw());
} else
admin.updateMapping(mapping.getVirtual(), mapping.getStrPhysical(), strFile, mapping.isPhysicalFirst() ? "physical" : "archive", mapping.getInspectTemplateRaw(), mapping.isTopLevel(), mapping.getListenerMode(), mapping.getListenerType(), mapping.isReadonly());
store();
}
} catch (IOException e) {
throw Caster.toPageException(e);
} finally {
ResourceUtil.removeEL(temp, true);
}
adminSync.broadcast(attributes, config);
}
Aggregations