1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.ui;
24  
25  import com.liferay.portal.kernel.servlet.StringServletResponse;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.model.Theme;
28  import com.liferay.portal.util.WebKeys;
29  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
30  import com.liferay.taglib.util.ThemeUtil;
31  
32  import javax.servlet.RequestDispatcher;
33  import javax.servlet.ServletContext;
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.jsp.JspException;
36  
37  /**
38   * <a href="BoxTag.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class BoxTag extends ParamAndPropertyAncestorTagImpl {
43  
44      public int doStartTag() {
45          return EVAL_BODY_BUFFERED;
46      }
47  
48      public int doAfterBody() {
49          _bodyContentString = getBodyContent().getString();
50  
51          return SKIP_BODY;
52      }
53  
54      public int doEndTag() throws JspException {
55          try {
56              ServletContext servletContext = getServletContext();
57              HttpServletRequest request = getServletRequest();
58              StringServletResponse stringResponse = getServletResponse();
59  
60              Theme theme = (Theme)request.getAttribute(WebKeys.THEME);
61  
62              // Top
63  
64              if (isTheme()) {
65                  ThemeUtil.include(
66                      servletContext, request, stringResponse, pageContext,
67                      getTop(), theme);
68              }
69              else {
70                  RequestDispatcher requestDispatcher =
71                      servletContext.getRequestDispatcher(getTop());
72  
73                  requestDispatcher.include(request, stringResponse);
74              }
75  
76              pageContext.getOut().print(stringResponse.getString());
77  
78              // Body
79  
80              pageContext.getOut().print(_bodyContentString);
81  
82              // Bottom
83  
84              //res = getServletResponse();
85              stringResponse.recycle();
86  
87              if (isTheme()) {
88                  ThemeUtil.include(
89                      servletContext, request, stringResponse, pageContext,
90                      getBottom(), theme);
91              }
92              else {
93                  RequestDispatcher requestDispatcher =
94                      servletContext.getRequestDispatcher(getBottom());
95  
96                  requestDispatcher.include(request, stringResponse);
97              }
98  
99              pageContext.getOut().print(stringResponse.getString());
100 
101             return EVAL_PAGE;
102         }
103         catch (Exception e) {
104             throw new JspException(e);
105         }
106         finally {
107             clearParams();
108             clearProperties();
109         }
110     }
111 
112     public boolean isTheme() {
113         return false;
114     }
115 
116     public String getTop() {
117         return _top;
118     }
119 
120     public void setTop(String top) {
121         _top = top;
122     }
123 
124     public String getBottom() {
125         return _bottom;
126     }
127 
128     public void setBottom(String bottom) {
129         _bottom = bottom;
130     }
131 
132     private String _top;
133     private String _bottom;
134     private String _bodyContentString = StringPool.BLANK;
135 
136 }