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 **/
019/**
020 * Implements the CFML Function getfunctionlist
021 */
022package lucee.runtime.functions.other;
023
024import java.util.Iterator;
025import java.util.Map;
026import java.util.Map.Entry;
027
028import lucee.runtime.PageContext;
029import lucee.runtime.config.ConfigImpl;
030import lucee.runtime.exp.PageException;
031import lucee.runtime.ext.function.Function;
032import lucee.runtime.type.Struct;
033import lucee.runtime.type.StructImpl;
034import lucee.transformer.library.function.FunctionLib;
035import lucee.transformer.library.function.FunctionLibFunction;
036import lucee.transformer.library.tag.TagLib;
037
038public final class GetFunctionList implements Function {
039        
040        private static Struct functions;
041        
042        public synchronized static lucee.runtime.type.Struct call(PageContext pc) throws PageException {
043                
044                
045                if(functions==null) {
046                        Struct sct=new StructImpl();
047                        //synchronized(sct) {
048                                //hasSet=true;
049                        FunctionLib[] flds;
050                        flds = ((ConfigImpl)pc.getConfig()).getFLDs();
051                        FunctionLibFunction func;
052                        Map<String, FunctionLibFunction> _functions;
053                        Iterator<Entry<String, FunctionLibFunction>> it;
054                        Entry<String, FunctionLibFunction> e;
055                        for(int i=0;i<flds.length;i++) {
056                                _functions = flds[i].getFunctions();
057                                it = _functions.entrySet().iterator();
058                                
059                                while(it.hasNext()){
060                                        e = it.next();
061                                        func = e.getValue();
062                                        if(func.getStatus()!=TagLib.STATUS_HIDDEN && func.getStatus()!=TagLib.STATUS_UNIMPLEMENTED)
063                                                sct.set(e.getKey(),"");
064                                }
065                        }
066                        functions=sct;
067                        //}
068                }
069                return functions;
070        }
071}