001    package railo.transformer.cfml.evaluator.func.impl;
002    
003    import railo.commons.lang.StringList;
004    import railo.runtime.exp.TemplateException;
005    import railo.runtime.interpreter.VariableInterpreter;
006    import railo.runtime.type.Collection;
007    import railo.runtime.type.scope.Scope;
008    import railo.runtime.type.util.ArrayUtil;
009    import railo.transformer.bytecode.expression.Expression;
010    import railo.transformer.bytecode.expression.type.CollectionKey;
011    import railo.transformer.bytecode.expression.type.CollectionKeyArray;
012    import railo.transformer.bytecode.expression.var.Argument;
013    import railo.transformer.bytecode.expression.var.BIF;
014    import railo.transformer.bytecode.literal.LitDouble;
015    import railo.transformer.bytecode.literal.LitString;
016    import railo.transformer.cfml.evaluator.FunctionEvaluator;
017    import railo.transformer.library.function.FunctionLibFunction;
018    
019    public class IsDefined implements FunctionEvaluator{
020    
021            public void evaluate(BIF bif, FunctionLibFunction flf) throws TemplateException {
022                    Argument arg = bif.getArguments()[0];
023                    Expression value = arg.getValue();
024                    if(value instanceof LitString) {
025                            String str=((LitString)value).getString();
026                            StringList sl = VariableInterpreter.parse(str,false);
027                            if(sl!=null){
028                                    // scope
029                                    str=sl.next();
030                                    int scope = VariableInterpreter.scopeString2Int(str);
031                                    if(scope==Scope.SCOPE_UNDEFINED)sl.reset();
032                                    
033                                    // keys
034                                    String[] arr=sl.toArray();
035                                    ArrayUtil.trim(arr);
036                                    
037                                    // update first arg
038                                    arg.setValue(LitDouble.toExprDouble(scope),"number");
039                                    
040                                    // add second argument
041                                    
042                                    if(arr.length==1){
043                                            Expression expr = new CollectionKey(arr[0]);//LitString.toExprString(str);
044                                            arg=new Argument(expr,Collection.Key.class.getName());
045                                            bif.addArgument(arg);   
046                                    }
047                                    else {
048                                            CollectionKeyArray expr=new CollectionKeyArray(arr);
049                                            //LiteralStringArray expr = new LiteralStringArray(arr);
050                                            arg=new Argument(expr,Collection.Key[].class.getName());
051                                            bif.addArgument(arg);
052                                    }
053                                    
054                            }
055                            
056                    }
057                    //print.out("bif:"+arg.getValue().getClass().getName());
058            }
059    
060    }