1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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   */
43  public class BoxTag extends ParamAndPropertyAncestorTagImpl {
44  
45      public int doStartTag() {
46          return EVAL_BODY_BUFFERED;
47      }
48  
49      public int doAfterBody() {
50          _bodyContentString = getBodyContent().getString();
51  
52          return SKIP_BODY;
53      }
54  
55      public int doEndTag() throws JspException {
56          try {
57              ServletContext servletContext = getServletContext();
58              HttpServletRequest request = getServletRequest();
59              StringServletResponse stringResponse = getServletResponse();
60  
61              Theme theme = (Theme)request.getAttribute(WebKeys.THEME);
62  
63              // Top
64  
65              if (isTheme()) {
66                  ThemeUtil.include(
67                      servletContext, request, stringResponse, pageContext,
68                      getTop(), theme);
69              }
70              else {
71                  RequestDispatcher requestDispatcher =
72                      servletContext.getRequestDispatcher(getTop());
73  
74                  requestDispatcher.include(request, stringResponse);
75              }
76  
77              pageContext.getOut().print(stringResponse.getString());
78  
79              // Body
80  
81              pageContext.getOut().print(_bodyContentString);
82  
83              // Bottom
84  
85              //res = getServletResponse();
86              stringResponse.recycle();
87  
88              if (isTheme()) {
89                  ThemeUtil.include(
90                      servletContext, request, stringResponse, pageContext,
91                      getBottom(), theme);
92              }
93              else {
94                  RequestDispatcher requestDispatcher =
95                      servletContext.getRequestDispatcher(getBottom());
96  
97                  requestDispatcher.include(request, stringResponse);
98              }
99  
100             pageContext.getOut().print(stringResponse.getString());
101 
102             return EVAL_PAGE;
103         }
104         catch (Exception e) {
105             throw new JspException(e);
106         }
107         finally {
108             clearParams();
109             clearProperties();
110         }
111     }
112 
113     public boolean isTheme() {
114         return false;
115     }
116 
117     public String getTop() {
118         return _top;
119     }
120 
121     public void setTop(String top) {
122         _top = top;
123     }
124 
125     public String getBottom() {
126         return _bottom;
127     }
128 
129     public void setBottom(String bottom) {
130         _bottom = bottom;
131     }
132 
133     private String _top;
134     private String _bottom;
135     private String _bodyContentString = StringPool.BLANK;
136 
137 }