001    /**
002     * Copyright (c) 2000-2012 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.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 (Map.Entry<String, Action> entry : _actions.entrySet()) {
039                            if (path.startsWith(entry.getKey())) {
040                                    return entry.getValue();
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    }