001 /** 002 * Implements the Cold Fusion Function gettempfile 003 */ 004 package railo.runtime.functions.system; 005 006 import java.io.IOException; 007 008 import railo.commons.io.res.Resource; 009 import railo.commons.io.res.util.ResourceUtil; 010 import railo.runtime.PageContext; 011 import railo.runtime.exp.ExpressionException; 012 import railo.runtime.exp.PageException; 013 import railo.runtime.ext.function.Function; 014 import railo.runtime.op.Caster; 015 016 public final class GetTempFile implements Function { 017 public static String call(PageContext pc , String strDir, String prefix) throws PageException { 018 Resource dir = ResourceUtil.toResourceExisting(pc, strDir); 019 pc.getConfig().getSecurityManager().checkFileLocation(dir); 020 if(!dir.isDirectory()) throw new ExpressionException(strDir+" is not a directory"); 021 int count=1; 022 Resource file; 023 while((file=dir.getRealResource(prefix+pc.getId()+count+".tmp")).exists()) { 024 count++; 025 } 026 try { 027 file.createFile(false); 028 //file.createNewFile(); 029 return file.getCanonicalPath(); 030 } 031 catch (IOException e) { 032 throw Caster.toPageException(e); 033 } 034 } 035 }