Search in sources :

Example 71 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class ComponentListPackage method _listArchive.

private static String[] _listArchive(PageContext pc, String path, Mapping mapping) throws IOException {
    String packageName = StringUtil.replace(path, File.separator, ".", false);
    Resource archive = mapping.getArchive();
    if (archive != null) {
        // TODO nor working with pathes with none ascci characters, eith none ascci characters, the java class path is renamed, so make sure you rename the path as well
        String strDir = "zip://" + archive + "!" + File.separator + path;
        Resource dir = ResourceUtil.toResourceNotExisting(pc, strDir, true, false);
        if (dir.isDirectory()) {
            java.util.List<String> list = new ArrayList<String>();
            // we use the class files here to get the info, the source files are optional and perhaps not present.
            Resource[] children = dir.listResources(FILTER_CLASS);
            String className, c, sourceName = null;
            for (int i = 0; i < children.length; i++) {
                className = children[i].getName();
                className = className.substring(0, className.length() - 6);
                className = packageName + "." + className;
                try {
                    Class<?> clazz = mapping.getArchiveClass(className);
                    sourceName = ASMUtil.getSourceInfo(pc.getConfig(), clazz, true).name;
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                }
                if (StringUtil.isEmpty(sourceName)) {
                    c = IOUtil.toString(children[i], (Charset) null);
                    int loc = c.indexOf("<clinit>");
                    if (loc != -1) {
                        c = c.substring(0, loc);
                        c = ListUtil.last(c, "/\\", true).trim();
                        if (Constants.isComponentExtension(ResourceUtil.getExtension(c, "")))
                            list.add(c);
                    }
                } else
                    list.add(sourceName);
            }
            if (list.size() > 0)
                return list.toArray(new String[list.size()]);
        }
    }
    return null;
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset)

Example 72 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class DirectoryCreate method call.

public static String call(PageContext pc, String path, boolean createPath, boolean ignoreExists) throws PageException {
    Resource dir = ResourceUtil.toResourceNotExisting(pc, path);
    Directory.actionCreate(pc, dir, null, createPath, -1, null, null, ignoreExists ? FileUtil.NAMECONFLICT_SKIP : FileUtil.NAMECONFLICT_ERROR);
    return null;
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 73 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class DirectoryList method _call.

public static Object _call(PageContext pc, String path, boolean recurse, int listInfo, Object oFilter, String sort, int type) throws PageException {
    Resource dir = ResourceUtil.toResourceNotExisting(pc, path);
    ResourceFilter filter = UDFFilter.createResourceAndResourceNameFilter(oFilter);
    return Directory.actionList(pc, dir, null, type, filter, listInfo, recurse, sort);
}
Also used : ResourceFilter(lucee.commons.io.res.filter.ResourceFilter) Resource(lucee.commons.io.res.Resource)

Example 74 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class FileExists method call.

public static boolean call(PageContext pc, Object obj, Object oAllowRealPath) throws PageException {
    if (oAllowRealPath == null)
        return call(pc, obj);
    Resource res = Caster.toResource(pc, obj, false, Caster.toBooleanValue(oAllowRealPath));
    if (res == null)
        return false;
    pc.getConfig().getSecurityManager().checkFileLocation(res);
    return res.isFile();
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 75 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class FileGetMimeType method call.

public static String call(PageContext pc, Object oSrc, boolean checkHeader) throws PageException {
    Resource src = Caster.toResource(pc, oSrc, false);
    pc.getConfig().getSecurityManager().checkFileLocation(src);
    String mimeType = ResourceUtil.getMimeType(src, null);
    if (StringUtil.isEmpty(mimeType, true))
        return "application/octet-stream";
    return mimeType;
}
Also used : Resource(lucee.commons.io.res.Resource)

Aggregations

Resource (lucee.commons.io.res.Resource)309 IOException (java.io.IOException)100 ApplicationException (lucee.runtime.exp.ApplicationException)54 PageException (lucee.runtime.exp.PageException)40 ArrayList (java.util.ArrayList)31 Struct (lucee.runtime.type.Struct)28 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 ExpressionException (lucee.runtime.exp.ExpressionException)19 StructImpl (lucee.runtime.type.StructImpl)18 MalformedURLException (java.net.MalformedURLException)17 PageContextImpl (lucee.runtime.PageContextImpl)17 PageSource (lucee.runtime.PageSource)16 FileResource (lucee.commons.io.res.type.file.FileResource)15 SecurityException (lucee.runtime.exp.SecurityException)15 BundleException (org.osgi.framework.BundleException)15 ZipEntry (java.util.zip.ZipEntry)13 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)13 Array (lucee.runtime.type.Array)13 File (java.io.File)12