1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
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 }