001 package railo.runtime.functions.cache; 002 003 import java.io.IOException; 004 005 import railo.commons.lang.StringUtil; 006 import railo.runtime.PageContext; 007 import railo.runtime.config.ConfigImpl; 008 import railo.runtime.exp.PageException; 009 import railo.runtime.ext.function.Function; 010 import railo.runtime.op.Caster; 011 import railo.runtime.type.Array; 012 import railo.runtime.type.ArrayImpl; 013 import railo.runtime.type.util.ListUtil; 014 015 /** 016 * 017 */ 018 public final class CacheGetProperties implements Function { 019 020 private static final long serialVersionUID = -8665995702411192700L; 021 022 public static Array call(PageContext pc) throws PageException { 023 return call(pc, null); 024 } 025 026 public static Array call(PageContext pc, String cacheName) throws PageException { 027 Array arr = new ArrayImpl(); 028 try { 029 if(StringUtil.isEmpty(cacheName)){ 030 addDefault(pc,ConfigImpl.CACHE_DEFAULT_OBJECT,arr); 031 addDefault(pc,ConfigImpl.CACHE_DEFAULT_TEMPLATE,arr); 032 addDefault(pc,ConfigImpl.CACHE_DEFAULT_QUERY,arr); 033 addDefault(pc,ConfigImpl.CACHE_DEFAULT_RESOURCE,arr); 034 addDefault(pc,ConfigImpl.CACHE_DEFAULT_FUNCTION,arr); 035 //arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_TEMPLATE).getCustomInfo()); 036 //arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_QUERY).getCustomInfo()); 037 //arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_RESOURCE).getCustomInfo()); 038 // MUST welcher muss zuers sein 039 } 040 else{ 041 String name; 042 String[] names=ListUtil.listToStringArray(cacheName, ','); 043 for(int i=0;i<names.length;i++){ 044 name=names[i].trim(); 045 if(name.equalsIgnoreCase("template")) 046 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_TEMPLATE).getCustomInfo()); 047 else if(name.equalsIgnoreCase("object")) 048 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_OBJECT).getCustomInfo()); 049 else if(name.equalsIgnoreCase("query")) 050 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_QUERY).getCustomInfo()); 051 else if(name.equalsIgnoreCase("resource")) 052 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_RESOURCE).getCustomInfo()); 053 else if(name.equalsIgnoreCase("function")) 054 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_FUNCTION).getCustomInfo()); 055 else 056 arr.appendEL(Util.getCache(pc.getConfig(),name).getCustomInfo()); 057 } 058 } 059 060 061 return arr; 062 } catch (IOException e) { 063 throw Caster.toPageException(e); 064 } 065 } 066 067 private static void addDefault(PageContext pc, int type, Array arr) { 068 try { 069 arr.appendEL(Util.getDefault(pc,type).getCustomInfo()); 070 } catch (IOException e) {} 071 } 072 }