1 | /* |
2 | * Copyright 2004 The Apache Software Foundation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.apache.pluto.driver.tags; |
17 | |
18 | import java.io.IOException; |
19 | import java.io.PrintWriter; |
20 | |
21 | import javax.servlet.jsp.JspException; |
22 | import javax.servlet.jsp.tagext.TagSupport; |
23 | |
24 | /** |
25 | * The portlet render tag is used to print portlet rendering result (or error |
26 | * details) to the page. |
27 | * |
28 | * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a> |
29 | * @version 1.0 |
30 | * @since Oct 4, 2004 |
31 | */ |
32 | public class PortletRenderTag extends TagSupport { |
33 | |
34 | // TagSupport Impl --------------------------------------------------------- |
35 | |
36 | /** |
37 | * |
38 | * @see PortletTag |
39 | */ |
40 | public int doEndTag() throws JspException { |
41 | |
42 | // Ensure that the portlet render tag resides within a portlet tag. |
43 | PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass( |
44 | this, PortletTag.class); |
45 | if (parentTag == null) { |
46 | throw new JspException("Portlet render tag may only reside " |
47 | + "within a pluto:portlet tag."); |
48 | } |
49 | |
50 | // If the portlet is rendered successfully, print the rendering result. |
51 | if (parentTag.getStatus() == PortletTag.SUCCESS) { |
52 | try { |
53 | StringBuffer buffer = parentTag.getPortalServletResponse() |
54 | .getInternalBuffer().getBuffer(); |
55 | pageContext.getOut().print(buffer.toString()); |
56 | } catch (IOException ex) { |
57 | throw new JspException(ex); |
58 | } |
59 | } |
60 | // Otherwise, print the error stack trace. |
61 | else { |
62 | try { |
63 | pageContext.getOut().print("Error rendering portlet."); |
64 | pageContext.getOut().print("<pre>"); |
65 | parentTag.getThrowable().printStackTrace( |
66 | new PrintWriter(pageContext.getOut())); |
67 | pageContext.getOut().print("</pre>"); |
68 | } catch (IOException ex) { |
69 | throw new JspException(ex); |
70 | } |
71 | } |
72 | |
73 | // Return. |
74 | return SKIP_BODY; |
75 | } |
76 | |
77 | |
78 | } |
79 | |