001    /**
002     * Implements the CFML Function directoryexists
003     */
004    package railo.runtime.functions.system;
005    
006    import railo.commons.io.res.Resource;
007    import railo.commons.io.res.util.ResourceUtil;
008    import railo.runtime.PageContext;
009    import railo.runtime.exp.PageException;
010    import railo.runtime.ext.function.Function;
011    import railo.runtime.op.Caster;
012    
013    public final class DirectoryExists implements Function {
014            public static boolean call(PageContext pc , String path) throws PageException {
015                    return call(pc, path,pc.getConfig().allowRealPath());
016            }
017            public static boolean call(PageContext pc , String path,Object oAllowRealPath) throws PageException {
018                    Resource file;
019                    if(oAllowRealPath==null) return call(pc, path);
020                    boolean allowRealPath = Caster.toBooleanValue(oAllowRealPath);
021                    if(allowRealPath) {
022                            file=ResourceUtil.toResourceNotExisting(pc, path,allowRealPath);
023                            // TODO das else braucht es eigentlich nicht mehr
024                    }
025                    else {
026                            // ARP
027                            file=pc.getConfig().getResource(path);
028                            if(file!=null && !file.isAbsolute()) return false;
029                    }
030                     
031                pc.getConfig().getSecurityManager().checkFileLocation(file);
032                return file.isDirectory() && file.exists();
033            }
034    }