001    /**
002     * Copyright (c) 2000-2013 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            @Override
032            public Action getAction(String path) {
033                    Action action = _actions.get(path);
034    
035                    if (action != null) {
036                            return action;
037                    }
038    
039                    for (Map.Entry<String, Action> entry : _actions.entrySet()) {
040                            if (path.startsWith(entry.getKey())) {
041                                    return entry.getValue();
042                            }
043                    }
044    
045                    return null;
046            }
047    
048            @Override
049            public Map<String, Action> getActions() {
050                    return _actions;
051            }
052    
053            @Override
054            public void register(String path, StrutsAction strutsAction) {
055                    Action action = new ActionAdapter(strutsAction);
056    
057                    _actions.put(path, action);
058            }
059    
060            @Override
061            public void register(String path, StrutsPortletAction strutsPortletAction) {
062                    Action action = new PortletActionAdapter(strutsPortletAction);
063    
064                    _actions.put(path, action);
065            }
066    
067            @Override
068            public void unregister(String path) {
069                    _actions.remove(path);
070            }
071    
072            private static Map<String, Action> _actions =
073                    new ConcurrentHashMap<String, Action>();
074    
075    }