Search in sources :

Example 6 with ExtensionResourceFilter

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()]);
}
Also used : ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter)

Example 7 with ExtensionResourceFilter

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);
        }*/
}
Also used : ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) ResourceFilter(lucee.commons.io.res.filter.ResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) IOException(java.io.IOException)

Example 8 with ExtensionResourceFilter

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);
}
Also used : Resource(lucee.commons.io.res.Resource) DynamicAttributes(lucee.runtime.ext.tag.DynamicAttributes) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) MappingImpl(lucee.runtime.MappingImpl) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) DirectoryResourceFilter(lucee.commons.io.res.filter.DirectoryResourceFilter) NotResourceFilter(lucee.commons.io.res.filter.NotResourceFilter) ResourceFilter(lucee.commons.io.res.filter.ResourceFilter) ApplicationException(lucee.runtime.exp.ApplicationException) NotResourceFilter(lucee.commons.io.res.filter.NotResourceFilter) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter)

Example 9 with ExtensionResourceFilter

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);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) BundleFile(lucee.runtime.osgi.BundleFile) Query(lucee.runtime.type.Query) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 10 with ExtensionResourceFilter

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);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) Query(lucee.runtime.type.Query)

Aggregations

ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)16 Resource (lucee.commons.io.res.Resource)13 IOException (java.io.IOException)5 MappingImpl (lucee.runtime.MappingImpl)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 Query (lucee.runtime.type.Query)3 QueryImpl (lucee.runtime.type.QueryImpl)3 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 OrResourceFilter (lucee.commons.io.res.filter.OrResourceFilter)2 ResourceFilter (lucee.commons.io.res.filter.ResourceFilter)2 CompressResource (lucee.commons.io.res.type.compress.CompressResource)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 PageException (lucee.runtime.exp.PageException)2 FunctionLib (lucee.transformer.library.function.FunctionLib)2 FunctionLibException (lucee.transformer.library.function.FunctionLibException)2 TagLib (lucee.transformer.library.tag.TagLib)2 TagLibException (lucee.transformer.library.tag.TagLibException)2 ServiceException (coldfusion.server.ServiceException)1