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.kernel.util;
016    
017    import com.liferay.portal.kernel.dao.search.SearchContainer;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Shinn Lok
026     */
027    public class SearchContainerReference {
028    
029            public SearchContainerReference(
030                    HttpServletRequest request, String namespace) {
031    
032                    _request = request;
033                    _namespace = namespace;
034    
035                    request.setAttribute(WebKeys.SEARCH_CONTAINER_REFERENCE, this);
036            }
037    
038            public String getId() {
039                    return getId(SearchContainer.DEFAULT_VAR);
040            }
041    
042            public String getId(String var) {
043                    SearchContainer<?> searchContainer = _searchContainers.get(var);
044    
045                    if (searchContainer == null) {
046                            return StringPool.BLANK;
047                    }
048    
049                    return searchContainer.getId(_request, _namespace);
050            }
051    
052            public void register(SearchContainer<?> searchContainer) {
053                    register(SearchContainer.DEFAULT_VAR, searchContainer);
054            }
055    
056            public void register(String var, SearchContainer<?> searchContainer) {
057                    _searchContainers.put(var, searchContainer);
058            }
059    
060            private String _namespace;
061            private HttpServletRequest _request;
062            private Map<String, SearchContainer<?>> _searchContainers =
063                    new HashMap<String, SearchContainer<?>>();
064    
065    }