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.util;
016    
017    import com.liferay.kernel.servlet.taglib.DynamicIncludeUtil;
018    import com.liferay.taglib.TagSupport;
019    import com.liferay.taglib.servlet.JspWriterHttpServletResponse;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.http.HttpServletResponse;
023    import javax.servlet.jsp.JspException;
024    
025    /**
026     * @author Carlos Sierra Andr??s
027     */
028    public class DynamicIncludeTag extends TagSupport {
029    
030            @Override
031            public int doEndTag() throws JspException {
032                    DynamicIncludeUtil.include(getRequest(), getResponse(), getKey());
033    
034                    return super.doEndTag();
035            }
036    
037            @Override
038            public int doStartTag() {
039                    if (!DynamicIncludeUtil.hasDynamicInclude(getKey())) {
040                            return SKIP_BODY;
041                    }
042    
043                    return EVAL_BODY_INCLUDE;
044            }
045    
046            public String getKey() {
047                    return _key;
048            }
049    
050            public void setKey(String key) {
051                    _key = key;
052            }
053    
054            protected HttpServletRequest getRequest() {
055                    return (HttpServletRequest)pageContext.getRequest();
056            }
057    
058            protected HttpServletResponse getResponse() {
059                    return new JspWriterHttpServletResponse(pageContext);
060            }
061    
062            private String _key;
063    
064    }