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.other;
020
021import java.util.HashSet;
022import java.util.Iterator;
023import java.util.Map;
024import java.util.Set;
025
026import lucee.runtime.PageContext;
027import lucee.runtime.config.ConfigImpl;
028import lucee.runtime.exp.PageException;
029import lucee.runtime.functions.arrays.ArraySort;
030import lucee.runtime.op.Caster;
031import lucee.runtime.type.Array;
032import lucee.runtime.type.util.ArrayUtil;
033import lucee.transformer.library.function.FunctionLib;
034import lucee.transformer.library.function.FunctionLibFunction;
035import lucee.transformer.library.tag.TagLib;
036
037public class GetFunctionKeywords {
038        private static Array keywords;
039        
040
041        public synchronized static Array call(PageContext pc) throws PageException {
042
043                if(keywords==null) {
044                        Set<String> set=new HashSet<String>();
045                        FunctionLib[] flds;
046                        flds = ((ConfigImpl)pc.getConfig()).getFLDs();
047                        Map<String, FunctionLibFunction> functions;
048                        Iterator<FunctionLibFunction> it;
049                        FunctionLibFunction flf;
050                        String[] arr;
051                        for(int i=0;i<flds.length;i++) {
052                                functions = flds[i].getFunctions();
053                                it = functions.values().iterator();
054                                
055                                while(it.hasNext()){
056                                        flf = it.next();
057                                        if(flf.getStatus()!=TagLib.STATUS_HIDDEN && flf.getStatus()!=TagLib.STATUS_UNIMPLEMENTED && !ArrayUtil.isEmpty(flf.getKeywords())){ 
058                                                arr = flf.getKeywords();
059                                                if(arr!=null)for(int y=0;y<arr.length;y++) {
060                                                        set.add(arr[y].toLowerCase());
061                                                }
062                                                
063                                        }
064                                }
065                        }
066                        keywords=Caster.toArray(set);
067                        ArraySort.call(pc, keywords, "textnocase");
068                        //}
069                }
070                return keywords;
071        }
072
073}