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 doAfterBody() {
45          _bodyContentString = getBodyContent().getString();
46  
47          return SKIP_BODY;
48      }
49  
50      public int doEndTag() throws JspException {
51          try {
52              ServletContext servletContext = getServletContext();
53              HttpServletRequest request = getServletRequest();
54              StringServletResponse stringResponse = getServletResponse();
55  
56              Theme theme = (Theme)request.getAttribute(WebKeys.THEME);
57  
58              // Top
59  
60              if (isTheme()) {
61                  ThemeUtil.include(
62                      servletContext, request, stringResponse, pageContext,
63                      getTop(), theme);
64              }
65              else {
66                  RequestDispatcher requestDispatcher =
67                      servletContext.getRequestDispatcher(getTop());
68  
69                  requestDispatcher.include(request, stringResponse);
70              }
71  
72              pageContext.getOut().print(stringResponse.getString());
73  
74              // Body
75  
76              pageContext.getOut().print(_bodyContentString);
77  
78              // Bottom
79  
80              //res = getServletResponse();
81              stringResponse.recycle();
82  
83              if (isTheme()) {
84                  ThemeUtil.include(
85                      servletContext, request, stringResponse, pageContext,
86                      getBottom(), theme);
87              }
88              else {
89                  RequestDispatcher requestDispatcher =
90                      servletContext.getRequestDispatcher(getBottom());
91  
92                  requestDispatcher.include(request, stringResponse);
93              }
94  
95              pageContext.getOut().print(stringResponse.getString());
96  
97              return EVAL_PAGE;
98          }
99          catch (Exception e) {
100             throw new JspException(e);
101         }
102         finally {
103             clearParams();
104             clearProperties();
105         }
106     }
107 
108     public int doStartTag() {
109         return EVAL_BODY_BUFFERED;
110     }
111 
112     public String getBottom() {
113         return _bottom;
114     }
115 
116     public String getTop() {
117         return _top;
118     }
119 
120     public boolean isTheme() {
121         return false;
122     }
123 
124     public void setBottom(String bottom) {
125         _bottom = bottom;
126     }
127 
128     public void setTop(String top) {
129         _top = top;
130     }
131 
132     private String _bodyContentString = StringPool.BLANK;
133     private String _bottom;
134     private String _top;
135 
136 }