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.cache; 020 021import java.io.IOException; 022 023import lucee.commons.lang.StringUtil; 024import lucee.runtime.PageContext; 025import lucee.runtime.config.ConfigImpl; 026import lucee.runtime.exp.PageException; 027import lucee.runtime.ext.function.Function; 028import lucee.runtime.op.Caster; 029import lucee.runtime.type.Array; 030import lucee.runtime.type.ArrayImpl; 031import lucee.runtime.type.util.ListUtil; 032 033/** 034 * 035 */ 036public final class CacheGetProperties implements Function { 037 038 private static final long serialVersionUID = -8665995702411192700L; 039 040 public static Array call(PageContext pc) throws PageException { 041 return call(pc, null); 042 } 043 044 public static Array call(PageContext pc, String cacheName) throws PageException { 045 Array arr = new ArrayImpl(); 046 try { 047 if(StringUtil.isEmpty(cacheName)){ 048 addDefault(pc,ConfigImpl.CACHE_DEFAULT_OBJECT,arr); 049 addDefault(pc,ConfigImpl.CACHE_DEFAULT_TEMPLATE,arr); 050 addDefault(pc,ConfigImpl.CACHE_DEFAULT_QUERY,arr); 051 addDefault(pc,ConfigImpl.CACHE_DEFAULT_RESOURCE,arr); 052 addDefault(pc,ConfigImpl.CACHE_DEFAULT_FUNCTION,arr); 053 addDefault(pc,ConfigImpl.CACHE_DEFAULT_INCLUDE,arr); 054 //arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_TEMPLATE).getCustomInfo()); 055 //arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_QUERY).getCustomInfo()); 056 //arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_RESOURCE).getCustomInfo()); 057 // MUST welcher muss zuers sein 058 } 059 else{ 060 String name; 061 String[] names=ListUtil.listToStringArray(cacheName, ','); 062 for(int i=0;i<names.length;i++){ 063 name=names[i].trim(); 064 if(name.equalsIgnoreCase("template")) 065 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_TEMPLATE).getCustomInfo()); 066 else if(name.equalsIgnoreCase("object")) 067 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_OBJECT).getCustomInfo()); 068 else if(name.equalsIgnoreCase("query")) 069 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_QUERY).getCustomInfo()); 070 else if(name.equalsIgnoreCase("resource")) 071 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_RESOURCE).getCustomInfo()); 072 else if(name.equalsIgnoreCase("function")) 073 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_FUNCTION).getCustomInfo()); 074 else if(name.equalsIgnoreCase("include")) 075 arr.appendEL(Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_INCLUDE).getCustomInfo()); 076 else 077 arr.appendEL(Util.getCache(pc.getConfig(),name).getCustomInfo()); 078 } 079 } 080 081 082 return arr; 083 } catch (IOException e) { 084 throw Caster.toPageException(e); 085 } 086 } 087 088 private static void addDefault(PageContext pc, int type, Array arr) { 089 try { 090 arr.appendEL(Util.getDefault(pc,type).getCustomInfo()); 091 } catch (IOException e) {} 092 } 093}