1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.pipeline.valve.impl;
18
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import java.util.Stack;
22
23 import javax.servlet.RequestDispatcher;
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServletRequest;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.jetspeed.pipeline.PipelineException;
30 import org.apache.jetspeed.pipeline.valve.AbstractValve;
31 import org.apache.jetspeed.pipeline.valve.LayoutValve;
32 import org.apache.jetspeed.pipeline.valve.ValveContext;
33 import org.apache.jetspeed.request.RequestContext;
34
35 /***
36 * <p>
37 * VerySimpleLayoutValveImpl
38 * </p>
39 *
40 * Like the descriptions said this is a <b><i>very</i></b> simple
41 * layout valve and should not be used in production.
42 *
43 *
44 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
45 * @version $Id: VerySimpleLayoutValveImpl.java 516448 2007-03-09 16:25:47Z ate $
46 *
47 */
48 public class VerySimpleLayoutValveImpl extends AbstractValve implements LayoutValve
49 {
50 private static final Log log = LogFactory.getLog(VerySimpleLayoutValveImpl.class);
51
52 /***
53 * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext)
54 */
55 public void invoke(RequestContext request, ValveContext context) throws PipelineException
56 {
57 try
58 {
59 log.info("Invoking the VerySimpleLayoutValve...");
60 HttpServletRequest httpRequest = request.getRequest();
61 RequestDispatcher rd = httpRequest.getRequestDispatcher("/pages/SimpleLayoutHeader.jsp");
62 rd.include(httpRequest, request.getResponse());
63
64 Stack renderStack = (Stack) httpRequest.getAttribute(CleanupValveImpl.RENDER_STACK_ATTR);
65 if (renderStack == null)
66 {
67 renderStack = new Stack();
68 httpRequest.setAttribute(CleanupValveImpl.RENDER_STACK_ATTR, renderStack);
69 }
70 renderStack.push("/pages/SimpleLayoutFooter.jsp");
71
72 }
73 catch (Exception e)
74 {
75 try
76 {
77 log.error("VerySimpleLayout: Unable to include layout header. Layout not processed", e);
78 PrintWriter pw = request.getResponse().getWriter();
79 pw.write("VerySimpleLayoutFailed failed to include servlet resources. (details below) <br/>");
80 pw.write("Exception: " + e.getClass().getName() + " <br/>");
81 pw.write("Message: " + e.getMessage() + " <br/>");
82 writeStackTrace(e.getStackTrace(), pw);
83
84 if (e instanceof ServletException && ((ServletException) e).getRootCause() != null)
85 {
86 Throwable rootCause = ((ServletException) e).getRootCause();
87 pw.write("Root Cause: " + rootCause.getClass().getName() + " <br/>");
88 pw.write("Message: " + rootCause.getMessage() + " <br/>");
89 writeStackTrace(rootCause.getStackTrace(), pw);
90 }
91 }
92 catch (IOException e1)
93 {
94
95 }
96
97 }
98 finally
99 {
100 context.invokeNext(request);
101 }
102
103 }
104
105 /***
106 * @see java.lang.Object#toString()
107 */
108 public String toString()
109 {
110 return "VerySimpleLayoutValveImpl";
111 }
112
113 protected static final void writeStackTrace(StackTraceElement[] traceArray, PrintWriter pw)
114 {
115 pw.write("<p>Stack Trace: </p>");
116 for (int i = 0; i < traceArray.length; i++)
117 {
118 pw.write(" " + traceArray[i].toString() + "<br />");
119 }
120 }
121
122 }