1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.pipeline.valve.impl;
1819import java.util.Stack;
2021import javax.servlet.RequestDispatcher;
22import javax.servlet.http.HttpServletRequest;
2324import org.apache.commons.logging.Log;
25import org.apache.commons.logging.LogFactory;
26import org.apache.jetspeed.pipeline.PipelineException;
27import org.apache.jetspeed.pipeline.valve.AbstractValve;
28import org.apache.jetspeed.pipeline.valve.CleanupValve;
29import org.apache.jetspeed.pipeline.valve.ValveContext;
30import org.apache.jetspeed.request.RequestContext;
3132/***33 * <p>34 * CleanupValveImpl35 * </p>36 * 37 * All this valve does right now is look for JSP pages that were38 * 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 */45publicclassCleanupValveImplextendsAbstractValve implements CleanupValve46 {
4748publicstaticfinal String RENDER_STACK_ATTR = "org.apache.jetspeed.renderStack";
4950privatestaticfinal Log log = LogFactory.getLog(CleanupValveImpl.class);
515253publicCleanupValveImpl()
54 {
55 }
5657/***58 * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext)59 */60publicvoid invoke(RequestContext request, ValveContext context) throws PipelineException
61 {
6263// Complete any renderings that are on the rendering stack 6465// TODO: we should abstract the rendering as we will66// want to eventually support other types of templates67// other than JSPs.68 HttpServletRequest httpRequest = request.getRequest();
69 Stack renderStack = (Stack) httpRequest.getAttribute(RENDER_STACK_ATTR);
70 String fragment = null;
71try72 {
73if (renderStack != null)
74 {
75while (!renderStack.empty())
76 {
77 fragment = (String) renderStack.pop();
78 RequestDispatcher rd = httpRequest.getRequestDispatcher(fragment);
79 rd.include(httpRequest, request.getResponse());
80 }
81 }
82 }
83catch (Exception e)
84 {
85 log.error("CleanupValveImpl: failed while trying to render fragment " + fragment);
86 log.error("CleanupValveImpl: Unable to complete all renderings", e);
87 }
88 }
8990/***91 * @see java.lang.Object#toString()92 */93public String toString()
94 {
95return"CleanupValveImpl";
96 }
9798 }