001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.pipeline.valve.impl;
018:
019: import java.io.IOException;
020: import java.io.PrintWriter;
021: import java.util.Stack;
022:
023: import javax.servlet.RequestDispatcher;
024: import javax.servlet.ServletException;
025: import javax.servlet.http.HttpServletRequest;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.apache.jetspeed.pipeline.PipelineException;
030: import org.apache.jetspeed.pipeline.valve.AbstractValve;
031: import org.apache.jetspeed.pipeline.valve.LayoutValve;
032: import org.apache.jetspeed.pipeline.valve.ValveContext;
033: import org.apache.jetspeed.request.RequestContext;
034:
035: /**
036: * <p>
037: * VerySimpleLayoutValveImpl
038: * </p>
039: *
040: * Like the descriptions said this is a <b><i>very</i></b> simple
041: * layout valve and should not be used in production.
042: *
043: *
044: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
045: * @version $Id: VerySimpleLayoutValveImpl.java 516448 2007-03-09 16:25:47Z ate $
046: *
047: */
048: public class VerySimpleLayoutValveImpl extends AbstractValve implements
049: LayoutValve {
050: private static final Log log = LogFactory
051: .getLog(VerySimpleLayoutValveImpl.class);
052:
053: /**
054: * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext)
055: */
056: public void invoke(RequestContext request, ValveContext context)
057: throws PipelineException {
058: try {
059: log.info("Invoking the VerySimpleLayoutValve...");
060: HttpServletRequest httpRequest = request.getRequest();
061: RequestDispatcher rd = httpRequest
062: .getRequestDispatcher("/pages/SimpleLayoutHeader.jsp");
063: rd.include(httpRequest, request.getResponse());
064:
065: Stack renderStack = (Stack) httpRequest
066: .getAttribute(CleanupValveImpl.RENDER_STACK_ATTR);
067: if (renderStack == null) {
068: renderStack = new Stack();
069: httpRequest
070: .setAttribute(
071: CleanupValveImpl.RENDER_STACK_ATTR,
072: renderStack);
073: }
074: renderStack.push("/pages/SimpleLayoutFooter.jsp");
075:
076: } catch (Exception e) {
077: try {
078: log
079: .error(
080: "VerySimpleLayout: Unable to include layout header. Layout not processed",
081: e);
082: PrintWriter pw = request.getResponse().getWriter();
083: pw
084: .write("VerySimpleLayoutFailed failed to include servlet resources. (details below) <br/>");
085: pw.write("Exception: " + e.getClass().getName()
086: + " <br/>");
087: pw.write("Message: " + e.getMessage() + " <br/>");
088: writeStackTrace(e.getStackTrace(), pw);
089:
090: if (e instanceof ServletException
091: && ((ServletException) e).getRootCause() != null) {
092: Throwable rootCause = ((ServletException) e)
093: .getRootCause();
094: pw
095: .write("Root Cause: "
096: + rootCause.getClass().getName()
097: + " <br/>");
098: pw.write("Message: " + rootCause.getMessage()
099: + " <br/>");
100: writeStackTrace(rootCause.getStackTrace(), pw);
101: }
102: } catch (IOException e1) {
103: // don't worry
104: }
105:
106: } finally {
107: context.invokeNext(request);
108: }
109:
110: }
111:
112: /**
113: * @see java.lang.Object#toString()
114: */
115: public String toString() {
116: return "VerySimpleLayoutValveImpl";
117: }
118:
119: protected static final void writeStackTrace(
120: StackTraceElement[] traceArray, PrintWriter pw) {
121: pw.write("<p>Stack Trace: </p>");
122: for (int i = 0; i < traceArray.length; i++) {
123: pw.write(" " + traceArray[i].toString()
124: + "<br />");
125: }
126: }
127:
128: }
|