001package org.apache.turbine.pipeline;
002
003
004/*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements.  See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership.  The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License.  You may obtain a copy of the License at
012 *
013 *   http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied.  See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024import java.io.IOException;
025
026import org.apache.turbine.TurbineConstants;
027import org.apache.turbine.util.RunData;
028import org.apache.turbine.util.TurbineException;
029
030/**
031 * Implements the RunData target portion of the "Turbine classic"
032 * processing pipeline (from the Turbine 2.x series).
033 *
034 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
035 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
036 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
037 * @author <a href="mailto:mikeh@apache.org">Mike Haberman</a>
038 * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
039 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
040 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
041 * @version $Id$
042 */
043public class CleanUpValve
044    implements Valve
045{
046    /**
047     * Creates a new instance.
048     */
049    public CleanUpValve()
050    {
051        // empty constructor
052    }
053
054    /**
055     * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
056     */
057    @Override
058    public void invoke(PipelineData pipelineData, ValveContext context)
059        throws IOException, TurbineException
060    {
061        try
062        {
063            cleanUp(pipelineData);
064        }
065        catch (Exception e)
066        {
067            throw new TurbineException(e);
068        }
069
070        // Pass control to the next Valve in the Pipeline
071        context.invokeNext(pipelineData);
072    }
073
074    /**
075     * Perform clean up after processing the request.
076     *
077     * @param pipelineData The run-time data.
078     */
079    protected void cleanUp(PipelineData pipelineData)
080    {
081        RunData data = pipelineData.getRunData();
082        // If a module has set data.acl = null, remove acl from
083        // the session.
084        if (data.getACL() == null)
085        {
086            try
087            {
088                data.getSession().removeAttribute
089                    (TurbineConstants.ACL_SESSION_KEY);
090            }
091            catch (IllegalStateException invalidatedSession)
092            {
093                // Web was used to shut us down. Trying to clean up
094                // our stuff, but it's already been done for us.
095            }
096        }
097    }
098}