001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.functions.file; 020 021import lucee.commons.io.res.Resource; 022import lucee.runtime.PageContext; 023import lucee.runtime.exp.PageException; 024import lucee.runtime.op.Caster; 025import lucee.runtime.type.Struct; 026import lucee.runtime.type.StructImpl; 027import lucee.runtime.type.dt.DateTimeImpl; 028import lucee.runtime.type.util.KeyConstants; 029 030public class GetFileInfo { 031 032 public static Struct call(PageContext pc, Object oSrc) throws PageException { 033 Resource src = Caster.toResource(pc,oSrc,true); 034 pc.getConfig().getSecurityManager().checkFileLocation(src); 035 036 Struct sct=new StructImpl(); 037 038 sct.set("canRead", Caster.toBoolean(src.isReadable())); 039 sct.set("canWrite", Caster.toBoolean(src.isWriteable())); 040 sct.set("isHidden", Caster.toBoolean(src.getAttribute(Resource.ATTRIBUTE_HIDDEN))); 041 sct.set("lastmodified",new DateTimeImpl(pc,src.lastModified(),false) ); 042 sct.set(KeyConstants._name,src.getName() ); 043 sct.set(KeyConstants._parent,src.getParent() ); 044 sct.set(KeyConstants._path,src.getAbsolutePath() ); 045 sct.set(KeyConstants._size, Caster.toDouble(src.length())); 046 if(src.isDirectory())sct.set(KeyConstants._type, "directory"); 047 else if(src.isFile())sct.set(KeyConstants._type, "file"); 048 else sct.set(KeyConstants._type, ""); 049 050 // supported only by lucee 051 sct.set("isArchive", Caster.toBoolean(src.getAttribute(Resource.ATTRIBUTE_ARCHIVE))); 052 sct.set("isSystem", Caster.toBoolean(src.getAttribute(Resource.ATTRIBUTE_SYSTEM))); 053 sct.set("scheme", src.getResourceProvider().getScheme()); 054 sct.set("isCaseSensitive", Caster.toBoolean(src.getResourceProvider().isCaseSensitive())); 055 sct.set("isAttributesSupported", Caster.toBoolean(src.getResourceProvider().isAttributesSupported())); 056 sct.set("isModeSupported", Caster.toBoolean(src.getResourceProvider().isModeSupported())); 057 058 return sct; 059 } 060}