001    /**
002     * Copyright (c) 2000-present 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.servlet.taglib.BaseDynamicInclude;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.util.WebKeys;
020    import com.liferay.portal.theme.ThemeDisplay;
021    
022    import javax.servlet.http.HttpServletRequest;
023    import javax.servlet.http.HttpServletResponse;
024    
025    import org.apache.struts.tiles.ComponentContext;
026    import org.apache.struts.tiles.taglib.ComponentConstants;
027    
028    import org.osgi.service.component.annotations.Component;
029    
030    /**
031     * @author Raymond Aug??
032     */
033    @Component
034    public class DoIncludeJSPDynamicInclude extends BaseDynamicInclude {
035    
036            @Override
037            public void include(
038                    HttpServletRequest request, HttpServletResponse response, String key) {
039    
040                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
041                            WebKeys.THEME_DISPLAY);
042    
043                    ComponentContext componentContext =
044                            (ComponentContext)request.getAttribute(
045                                    ComponentConstants.COMPONENT_CONTEXT);
046    
047                    if (componentContext == null) {
048                            themeDisplay.setTilesSelectable(true);
049                    }
050    
051                    String tilesContent = (String)componentContext.getAttribute("content");
052    
053                    themeDisplay.setTilesContent(tilesContent);
054    
055                    boolean tilesSelectable = GetterUtil.getBoolean(
056                            (String)componentContext.getAttribute("selectable"));
057    
058                    themeDisplay.setTilesSelectable(tilesSelectable);
059    
060                    String tilesTitle = (String)componentContext.getAttribute("title");
061    
062                    themeDisplay.setTilesTitle(tilesTitle);
063            }
064    
065            @Override
066            public void register(DynamicIncludeRegistry dynamicIncludeRegistry) {
067                    dynamicIncludeRegistry.register(
068                            "com.liferay.taglib.util.ThemeUtil#doIncludeJS");
069            }
070    
071    }