    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: CleanUpValve.java 1706239 2015-10-01 13:18:35Z tv $
    042 */
    043public class CleanUpValve
    044    extends AbstractValve
    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    public void invoke(PipelineData pipelineData, ValveContext context)
    058        throws IOException, TurbineException
    059    {
    060        try
    061        {
    062            cleanUp(pipelineData);
    063        }
    064        catch (Exception e)
    065        {
    066            throw new TurbineException(e);
    067        }
    068
    069        // Pass control to the next Valve in the Pipeline
    070        context.invokeNext(pipelineData);
    071    }
    072
    073    /**
    074     * Perform clean up after processing the request.
    075     *
    076     * @param pipelineData The run-time data.
    077     */
    078    protected void cleanUp(PipelineData pipelineData)
    079        throws Exception
    080    {
    081        RunData data = getRunData(pipelineData);
    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}