001    /**
002     * Implements the Cold Fusion Function isdefined
003     */
004    package railo.runtime.functions.decision;
005    
006    
007    import railo.runtime.PageContext;
008    import railo.runtime.ext.function.Function;
009    import railo.runtime.interpreter.VariableInterpreter;
010    import railo.runtime.type.Collection;
011    import railo.runtime.type.KeyImpl;
012    import railo.runtime.util.VariableUtilImpl;
013    
014    public final class IsDefined implements Function {
015            public static boolean call(PageContext pc , String varName) {
016                    
017            return VariableInterpreter.isDefined(pc,varName);
018                    //return pc.isDefined(varName);
019            }
020    
021            public static boolean call(PageContext pc , double scope,Collection.Key key) {
022                    try {
023                            Object coll = VariableInterpreter.scope(pc, (int)scope, false);
024                            if(coll==null) return false;
025                            coll=((VariableUtilImpl)pc.getVariableUtil()).get(pc,coll,key,null);
026                            if(coll==null)return false;
027                            //return pc.scope((int)scope).get(key,null)!=null; 
028                    } catch (Throwable t) {
029                    return false;
030                }
031                    return true;
032            }
033            public static boolean call(PageContext pc , double scope,String key) {
034                    return call(pc, scope, KeyImpl.getInstance(key));
035            }
036            
037            public static boolean call(PageContext pc , double scope,String[] varNames) {
038                    try {
039                            Object coll =VariableInterpreter.scope(pc, (int)scope, false); 
040                            //Object coll =pc.scope((int)scope); 
041                            for(int i=0;i<varNames.length;i++) {
042                                    coll=pc.getVariableUtil().getCollection(pc,coll,varNames[i],null);
043                                    if(coll==null)return false;
044                            }
045                    } catch (Throwable t) {
046                    return false;
047                }
048                    return true; 
049            }
050    }