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;
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.LiteralStringArray;
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(new LitDouble(scope,-1),"number");
039                                    
040                                    // add second argument
041                                    
042                                    if(arr.length==1){
043                                            Expression expr = new CollectionKey(arr[0],-1);//LitString.toExprString(str);
044                                            arg=new Argument(expr,Collection.Key.class.getName());
045                                            bif.addArgument(arg);   
046                                    }
047                                    else {
048                                            LiteralStringArray expr = new LiteralStringArray(arr,-1);
049                                            arg=new Argument(expr,String[].class.getName());
050                                            bif.addArgument(arg);
051                                    }
052                                    
053                            }
054                            
055                    }
056                    //print.out("bif:"+arg.getValue().getClass().getName());
057            }
058    
059    }