1   /**
2    * Copyright (c) 2000-2008 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 ctx = getServletContext();
58              HttpServletRequest req = getServletRequest();
59              StringServletResponse res = getServletResponse();
60  
61              Theme theme = (Theme)req.getAttribute(WebKeys.THEME);
62  
63              // Top
64  
65              if (isTheme()) {
66                  ThemeUtil.include(ctx, req, res, pageContext, getTop(), theme);
67              }
68              else {
69                  RequestDispatcher rd = ctx.getRequestDispatcher(getTop());
70  
71                  rd.include(req, res);
72              }
73  
74              pageContext.getOut().print(res.getString());
75  
76              // Body
77  
78              pageContext.getOut().print(_bodyContentString);
79  
80              // Bottom
81  
82              //res = getServletResponse();
83              res.recycle();
84  
85              if (isTheme()) {
86                  ThemeUtil.include(
87                      ctx, req, res, pageContext, getBottom(), theme);
88              }
89              else {
90                  RequestDispatcher rd = ctx.getRequestDispatcher(getBottom());
91  
92                  rd.include(req, res);
93              }
94  
95              pageContext.getOut().print(res.getString());
96  
97              return EVAL_PAGE;
98          }
99          catch (Exception e) {
100             throw new JspException(e);
101         }
102         finally {
103             clearParams();
104         }
105     }
106 
107     public boolean isTheme() {
108         return false;
109     }
110 
111     public String getTop() {
112         return _top;
113     }
114 
115     public void setTop(String top) {
116         _top = top;
117     }
118 
119     public String getBottom() {
120         return _bottom;
121     }
122 
123     public void setBottom(String bottom) {
124         _bottom = bottom;
125     }
126 
127     private String _top;
128     private String _bottom;
129     private String _bodyContentString = StringPool.BLANK;
130 
131 }