Search in sources :

Example 1 with WildCardFilter

use of lucee.commons.io.res.util.WildCardFilter in project Lucee by lucee.

the class MetaData method get.

public List<String> get(String wildcard) throws IOException {
    synchronized (data) {
        List<String> list = new ArrayList<String>();
        Iterator<Entry<String, String>> it = data.entrySet().iterator();
        WildCardFilter filter = new WildCardFilter(wildcard);
        Entry<String, String> entry;
        String value;
        while (it.hasNext()) {
            entry = it.next();
            value = entry.getValue();
            if (filter.accept(value)) {
                list.add(entry.getKey());
                it.remove();
            }
        }
        if (list.size() > 0)
            JavaConverter.serialize(data, file);
        return list;
    }
}
Also used : Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) WildCardFilter(lucee.commons.io.res.util.WildCardFilter)

Example 2 with WildCardFilter

use of lucee.commons.io.res.util.WildCardFilter in project Lucee by lucee.

the class JavaProxy method loadClassByPath.

private static Class<?> loadClassByPath(PageContext pc, String className, String[] paths) throws PageException {
    PageContextImpl pci = (PageContextImpl) pc;
    java.util.List<Resource> resources = new ArrayList<Resource>();
    if (paths != null && paths.length > 0) {
        // load resources
        for (int i = 0; i < paths.length; i++) {
            Resource res = ResourceUtil.toResourceExisting(pc, paths[i]);
            if (res.isDirectory()) {
                // a directory was passed, add all of the jar files from it
                FileResource dir = (FileResource) res;
                Resource[] jars = dir.listResources((ResourceNameFilter) new WildCardFilter("*.jar"));
                for (Resource jar : jars) {
                    resources.add(jar);
                }
            } else {
                resources.add(res);
            }
        }
    // throw new FunctionException(pc, "JavaProxy", 2, "path", "argument path has to be a array of strings or a single string, where every string is defining a path");
    }
    // load class
    try {
        ClassLoader cl = resources.isEmpty() ? pci.getClassLoader() : pci.getClassLoader(resources.toArray(new Resource[resources.size()]));
        Class clazz = null;
        try {
            clazz = ClassUtil.loadClass(cl, className);
        } catch (ClassException ce) {
            // try java.lang if no package definition
            if (className.indexOf('.') == -1) {
                try {
                    clazz = ClassUtil.loadClass(cl, "java.lang." + className);
                } catch (ClassException e) {
                    throw ce;
                }
            } else
                throw ce;
        }
        return clazz;
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) ArrayList(java.util.ArrayList) FileResource(lucee.commons.io.res.type.file.FileResource) ClassException(lucee.commons.lang.ClassException) PageContextImpl(lucee.runtime.PageContextImpl) ClassException(lucee.commons.lang.ClassException) SecurityException(lucee.runtime.exp.SecurityException) PageException(lucee.runtime.exp.PageException) WildCardFilter(lucee.commons.io.res.util.WildCardFilter)

Aggregations

ArrayList (java.util.ArrayList)2 WildCardFilter (lucee.commons.io.res.util.WildCardFilter)2 Entry (java.util.Map.Entry)1 Resource (lucee.commons.io.res.Resource)1 FileResource (lucee.commons.io.res.type.file.FileResource)1 ClassException (lucee.commons.lang.ClassException)1 PageContextImpl (lucee.runtime.PageContextImpl)1 PageException (lucee.runtime.exp.PageException)1 SecurityException (lucee.runtime.exp.SecurityException)1