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.taglib.ui;
016    
017    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateUtil;
018    import com.liferay.taglib.util.IncludeTag;
019    
020    import java.util.HashMap;
021    import java.util.List;
022    import java.util.Map;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Eduardo Garcia
028     */
029    public class DDMTemplateRendererTag extends IncludeTag {
030    
031            @Override
032            public int processStartTag() throws Exception {
033                    _portletDisplayDDMTemplateId =
034                            PortletDisplayTemplateUtil.getPortletDisplayTemplateDDMTemplateId(
035                                    _displayStyleGroupId, _displayStyle);
036    
037                    if (_portletDisplayDDMTemplateId > 0) {
038                            return SKIP_BODY;
039                    }
040    
041                    return EVAL_BODY_INCLUDE;
042            }
043    
044            public void setContextObjects(Map<String, Object> contextObjects) {
045                    _contextObjects = contextObjects;
046            }
047    
048            public void setDisplayStyle(String displayStyle) {
049                    _displayStyle = displayStyle;
050            }
051    
052            public void setDisplayStyleGroupId(long displayStyleGroupId) {
053                    _displayStyleGroupId = displayStyleGroupId;
054            }
055    
056            public void setEntries(List<?> entries) {
057                    _entries = entries;
058            }
059    
060            @Override
061            protected void cleanUp() {
062                    _contextObjects = new HashMap<String, Object>();
063                    _displayStyle = null;
064                    _displayStyleGroupId = 0;
065                    _entries = null;
066                    _portletDisplayDDMTemplateId = 0;
067            }
068    
069            @Override
070            protected String getPage() {
071                    return _PAGE;
072            }
073    
074            @Override
075            protected void setAttributes(HttpServletRequest request) {
076                    request.setAttribute(
077                            "liferay-ui:ddm-template-renderer:contextObjects", _contextObjects);
078                    request.setAttribute(
079                            "liferay-ui:ddm-template-renderer:entries", _entries);
080                    request.setAttribute(
081                            "liferay-ui:ddm-template-renderer:portletDisplayDDMTemplateId",
082                            String.valueOf(_portletDisplayDDMTemplateId));
083            }
084    
085            private static final String _PAGE =
086                    "/html/taglib/ui/ddm_template_renderer/page.jsp";
087    
088            private Map<String, Object> _contextObjects = new HashMap<String, Object>();
089            private String _displayStyle;
090            private long _displayStyleGroupId;
091            private List<?> _entries;
092            private long _portletDisplayDDMTemplateId;
093    
094    }