use of lucee.commons.io.res.filter.ExtensionResourceFilter in project Lucee by lucee.
the class FunctionLibFactory method loadFromDirectory.
/**
* Laedt mehrere FunctionLib's die innerhalb eines Verzeichnisses liegen.
* @param dir Verzeichnis im dem die FunctionLib's liegen.
* @param saxParser Definition des Sax Parser mit dem die FunctionLib's eingelesen werden sollen.
* @return FunctionLib's als Array
* @throws FunctionLibException
*/
public static FunctionLib[] loadFromDirectory(Resource dir, Identification id) throws FunctionLibException {
if (!dir.isDirectory())
return new FunctionLib[0];
ArrayList<FunctionLib> arr = new ArrayList<FunctionLib>();
Resource[] files = dir.listResources(new ExtensionResourceFilter(new String[] { "fld", "fldx" }));
for (int i = 0; i < files.length; i++) {
if (files[i].isFile())
arr.add(FunctionLibFactory.loadFromFile(files[i], id));
}
return arr.toArray(new FunctionLib[arr.size()]);
}
use of lucee.commons.io.res.filter.ExtensionResourceFilter 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.ExtensionResourceFilter 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);
}
use of lucee.commons.io.res.filter.ExtensionResourceFilter in project Lucee by lucee.
the class Admin method doGetJars.
private void doGetJars() throws PageException {
Resource lib = config.getLibraryDirectory();
lucee.runtime.type.Query qry = new QueryImpl(new Key[] { KeyConstants._name, KeyConstants._source, KeyConstants._info }, new String[] { "varchar", "varchar", "varchar" }, 0, "jars");
if (lib.isDirectory()) {
Resource[] children = lib.listResources(new ExtensionResourceFilter(new String[] { ".jar", ".zip" }, false, true));
for (int i = 0; i < children.length; i++) {
qry.addRow();
qry.setAt(KeyConstants._name, i + 1, children[i].getName());
qry.setAt(KeyConstants._source, i + 1, children[i].getAbsolutePath());
try {
qry.setAt(KeyConstants._info, i + 1, new BundleFile(children[i]).info());
} catch (Exception e) {
}
}
}
pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
use of lucee.commons.io.res.filter.ExtensionResourceFilter in project Lucee by lucee.
the class Admin method doGetDebuggingList.
private void doGetDebuggingList() throws PageException {
Resource luceeContext = ResourceUtil.toResourceExisting(pageContext, "/lucee/templates/debugging/");
Resource[] children = luceeContext.listResources(new ExtensionResourceFilter(Constants.getTemplateExtensions()));
String rtnVar = getString("admin", action, "returnVariable");
lucee.runtime.type.Query qry = new QueryImpl(new String[] { "name" }, children.length, rtnVar);
for (int i = 0; i < children.length; i++) {
qry.setAt("name", i + 1, children[i].getName());
}
pageContext.setVariable(rtnVar, qry);
}
Aggregations