001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            public Route addRoute(String pattern) {
031                    Route route = new RouteImpl(pattern);
032    
033                    _routes.add(route);
034    
035                    return route;
036            }
037    
038            public String parametersToUrl(Map<String, String> parameters) {
039                    for (Route route : _routes) {
040                            String url = route.parametersToUrl(parameters);
041    
042                            if (url != null) {
043                                    return url;
044                            }
045                    }
046    
047                    return null;
048            }
049    
050            public boolean urlToParameters(String url, Map<String, String> parameters) {
051                    for (Route route : _routes) {
052                            if (route.urlToParameters(url, parameters)) {
053                                    return true;
054                            }
055                    }
056    
057                    return false;
058            }
059    
060            private List<Route> _routes = new ArrayList<Route>();
061    
062    }