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.portal.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(
033                            getRequest(), getResponse(), getKey(), _ascendingPriority);
034    
035                    return super.doEndTag();
036            }
037    
038            @Override
039            public int doStartTag() {
040                    if (!DynamicIncludeUtil.hasDynamicInclude(getKey())) {
041                            return SKIP_BODY;
042                    }
043    
044                    return EVAL_BODY_INCLUDE;
045            }
046    
047            public boolean getAscendingPriority() {
048                    return _ascendingPriority;
049            }
050    
051            public String getKey() {
052                    return _key;
053            }
054    
055            public void setAscendingPriority(boolean ascendingPriority) {
056                    _ascendingPriority = ascendingPriority;
057            }
058    
059            public void setKey(String key) {
060                    _key = key;
061            }
062    
063            protected HttpServletRequest getRequest() {
064                    return (HttpServletRequest)pageContext.getRequest();
065            }
066    
067            protected HttpServletResponse getResponse() {
068                    return new JspWriterHttpServletResponse(pageContext);
069            }
070    
071            private boolean _ascendingPriority = true;
072            private String _key;
073    
074    }