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.rest.path;
020
021import java.util.Iterator;
022
023import lucee.runtime.op.Caster;
024import lucee.runtime.type.Array;
025import lucee.runtime.type.Struct;
026import lucee.runtime.type.util.ListUtil;
027
028public abstract class Path {
029        /**
030         * check if given path part match this path Path part defintion
031         * @param variables fill all key value pairs extracte from path to this Map
032         * @param path path to check
033         * @return true if the given path match, false otherwise 
034         */
035        public abstract boolean match(Struct variables,String path);
036
037        public static Path[] init(String path) {
038                Array arr = ListUtil.listToArrayRemoveEmpty(path,'/');
039                Path[] rtn=new Path[arr.size()];
040                Iterator it = arr.valueIterator();
041                int index=-1;
042                String str;
043                while(it.hasNext()){
044                        index++;
045                        str=Caster.toString(it.next(),null);
046                        //print.e("str:"+str);
047                        if(str.indexOf('{')!=-1) rtn[index]=ExpressionPath.getInstance(str);
048                        else rtn[index]=new LiteralPath(str);
049                }
050                return rtn;
051        }
052}