1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.kernel.servlet.StringServletResponse;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.kernel.util.WebKeys;
20  import com.liferay.portal.model.Theme;
21  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
22  import com.liferay.taglib.util.ThemeUtil;
23  
24  import javax.servlet.RequestDispatcher;
25  import javax.servlet.ServletContext;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * <a href="BoxTag.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class BoxTag extends ParamAndPropertyAncestorTagImpl {
35  
36      public int doAfterBody() {
37          _bodyContentString = getBodyContent().getString();
38  
39          return SKIP_BODY;
40      }
41  
42      public int doEndTag() throws JspException {
43          try {
44              ServletContext servletContext = getServletContext();
45              HttpServletRequest request = getServletRequest();
46              StringServletResponse stringResponse = getServletResponse();
47  
48              Theme theme = (Theme)request.getAttribute(WebKeys.THEME);
49  
50              // Top
51  
52              if (isTheme()) {
53                  ThemeUtil.include(
54                      servletContext, request, stringResponse, pageContext,
55                      getTop(), theme);
56              }
57              else {
58                  RequestDispatcher requestDispatcher =
59                      servletContext.getRequestDispatcher(getTop());
60  
61                  requestDispatcher.include(request, stringResponse);
62              }
63  
64              pageContext.getOut().print(stringResponse.getString());
65  
66              // Body
67  
68              pageContext.getOut().print(_bodyContentString);
69  
70              // Bottom
71  
72              //res = getServletResponse();
73              stringResponse.recycle();
74  
75              if (isTheme()) {
76                  ThemeUtil.include(
77                      servletContext, request, stringResponse, pageContext,
78                      getBottom(), theme);
79              }
80              else {
81                  RequestDispatcher requestDispatcher =
82                      servletContext.getRequestDispatcher(getBottom());
83  
84                  requestDispatcher.include(request, stringResponse);
85              }
86  
87              pageContext.getOut().print(stringResponse.getString());
88  
89              return EVAL_PAGE;
90          }
91          catch (Exception e) {
92              throw new JspException(e);
93          }
94          finally {
95              clearParams();
96              clearProperties();
97          }
98      }
99  
100     public int doStartTag() {
101         return EVAL_BODY_BUFFERED;
102     }
103 
104     public String getBottom() {
105         return _bottom;
106     }
107 
108     public String getTop() {
109         return _top;
110     }
111 
112     public boolean isTheme() {
113         return false;
114     }
115 
116     public void setBottom(String bottom) {
117         _bottom = bottom;
118     }
119 
120     public void setTop(String top) {
121         _top = top;
122     }
123 
124     private String _bodyContentString = StringPool.BLANK;
125     private String _bottom;
126     private String _top;
127 
128 }