001    /**
002     * Copyright (c) 2000-2012 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.portal.struts;
016    
017    import com.liferay.portal.kernel.struts.StrutsAction;
018    import com.liferay.portal.kernel.struts.StrutsPortletAction;
019    
020    import java.util.Map;
021    import java.util.concurrent.ConcurrentHashMap;
022    
023    import org.apache.struts.action.Action;
024    
025    /**
026     * @author Mika Koivisto
027     * @author Raymond Augé
028     */
029    public class StrutsActionRegistryImpl implements StrutsActionRegistry {
030    
031            public Action getAction(String path) {
032                    Action action = _actions.get(path);
033    
034                    if (action != null) {
035                            return action;
036                    }
037    
038                    for (String curPath : _actions.keySet()) {
039                            if (path.startsWith(curPath)) {
040                                    return _actions.get(curPath);
041                            }
042                    }
043    
044                    return null;
045            }
046    
047            public Map<String, Action> getActions() {
048                    return _actions;
049            }
050    
051            public void register(String path, StrutsAction strutsAction) {
052                    Action action = new ActionAdapter(strutsAction);
053    
054                    _actions.put(path, action);
055            }
056    
057            public void register(String path, StrutsPortletAction strutsPortletAction) {
058                    Action action = new PortletActionAdapter(strutsPortletAction);
059    
060                    _actions.put(path, action);
061            }
062    
063            public void unregister(String path) {
064                    _actions.remove(path);
065            }
066    
067            private static Map<String, Action> _actions =
068                    new ConcurrentHashMap<String, Action>();
069    
070    }