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.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    }