001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.kernel.portlet.Route;
018    import com.liferay.portal.kernel.portlet.Router;
019    
020    import java.util.ArrayList;
021    import java.util.List;
022    import java.util.Map;
023    
024    /**
025     * @author Connor McKay
026     * @author Brian Wing Shun Chan
027     */
028    public class RouterImpl implements Router {
029    
030            @Override
031            public Route addRoute(String pattern) {
032                    Route route = new RouteImpl(pattern);
033    
034                    _routes.add(route);
035    
036                    return route;
037            }
038    
039            @Override
040            public String parametersToUrl(Map<String, String> parameters) {
041                    for (Route route : _routes) {
042                            String url = route.parametersToUrl(parameters);
043    
044                            if (url != null) {
045                                    return url;
046                            }
047                    }
048    
049                    return null;
050            }
051    
052            @Override
053            public boolean urlToParameters(String url, Map<String, String> parameters) {
054                    for (Route route : _routes) {
055                            if (route.urlToParameters(url, parameters)) {
056                                    return true;
057                            }
058                    }
059    
060                    return false;
061            }
062    
063            private List<Route> _routes = new ArrayList<Route>();
064    
065    }