01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.pipeline.valve.impl;
18:
19: import java.util.Stack;
20:
21: import javax.servlet.RequestDispatcher;
22: import javax.servlet.http.HttpServletRequest;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.apache.jetspeed.pipeline.PipelineException;
27: import org.apache.jetspeed.pipeline.valve.AbstractValve;
28: import org.apache.jetspeed.pipeline.valve.CleanupValve;
29: import org.apache.jetspeed.pipeline.valve.ValveContext;
30: import org.apache.jetspeed.request.RequestContext;
31:
32: /**
33: * <p>
34: * CleanupValveImpl
35: * </p>
36: *
37: * All this valve does right now is look for JSP pages that were
38: * pushed onto the <code>org.apache.jetspeed.renderStack</code>
39: * request attribute, and attempts to includde them.
40: *
41: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
42: * @version $Id: CleanupValveImpl.java 516448 2007-03-09 16:25:47Z ate $
43: *
44: */
45: public class CleanupValveImpl extends AbstractValve implements
46: CleanupValve {
47:
48: public static final String RENDER_STACK_ATTR = "org.apache.jetspeed.renderStack";
49:
50: private static final Log log = LogFactory
51: .getLog(CleanupValveImpl.class);
52:
53: public CleanupValveImpl() {
54: }
55:
56: /**
57: * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext)
58: */
59: public void invoke(RequestContext request, ValveContext context)
60: throws PipelineException {
61:
62: // Complete any renderings that are on the rendering stack
63:
64: // TODO: we should abstract the rendering as we will
65: // want to eventually support other types of templates
66: // other than JSPs.
67: HttpServletRequest httpRequest = request.getRequest();
68: Stack renderStack = (Stack) httpRequest
69: .getAttribute(RENDER_STACK_ATTR);
70: String fragment = null;
71: try {
72: if (renderStack != null) {
73: while (!renderStack.empty()) {
74: fragment = (String) renderStack.pop();
75: RequestDispatcher rd = httpRequest
76: .getRequestDispatcher(fragment);
77: rd.include(httpRequest, request.getResponse());
78: }
79: }
80: } catch (Exception e) {
81: log
82: .error("CleanupValveImpl: failed while trying to render fragment "
83: + fragment);
84: log
85: .error(
86: "CleanupValveImpl: Unable to complete all renderings",
87: e);
88: }
89: }
90:
91: /**
92: * @see java.lang.Object#toString()
93: */
94: public String toString() {
95: return "CleanupValveImpl";
96: }
97:
98: }
|