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