    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/portlet/modules/actions/LogoutUser.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005       Department of Geography, University of Bonn
    006     and
    007       lat/lon GmbH
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035    ----------------------------------------------------------------------------*/
    036    package org.deegree.portal.portlet.modules.actions;
    037
    038    import java.io.File;
    039    import java.io.FileOutputStream;
    040    import java.io.IOException;
    041    import java.util.Enumeration;
    042
    043    import javax.servlet.http.HttpSession;
    044    import javax.xml.parsers.ParserConfigurationException;
    045
    046    import org.deegree.framework.xml.XMLFragment;
    047    import org.deegree.portal.context.ViewContext;
    048    import org.deegree.portal.context.XMLFactory;
    049
    050    /**
    051     * This class can be used within listener classes that will be called if a user logs out from a
    052     * portal. All contexts used at this moment will be stored in the users WMC directory having
    053     * filenames starting with 'VIEWCONTEXT'.<BR>
    054     * At the moment a concrete listener is available for Jetspeed 1.6
    055     *
    056     * @see org.deegree.portal.portlet.modules.actions.IGeoJetspeed16LogoutUser
    057     *
    058     *
    059     * @version $Revision: 18195 $
    060     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    061     * @author last edited by: $Author: mschneider $
    062     *
    063     * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    064     *
    065     * @since 2.0
    066     */
    067    class LogoutUser {
    068
    069        /**
    070         *
    071         * @param dir
    072         * @param ses
    073         * @throws IOException
    074         * @throws ParserConfigurationException
    075         */
    076        void storeCurrentContexts( File dir, HttpSession ses )
    077                                throws ParserConfigurationException, IOException {
    078
    079            Enumeration en = ses.getAttributeNames();
    080            // because a porlat may use more than one web map context
    081            // parallel at different map windows we must iterate over
    082            // all session attributes indicating a WMC currently in use
    083            if ( en != null ) {
    084
    085                while ( en.hasMoreElements() ) {
    086                    String name = (String) en.nextElement();
    087                    Object val = ses.getAttribute( name );
    088                    if ( val != null && val instanceof ViewContext
    089                         && name.indexOf( AbstractPortletPerform.CURRENT_WMC ) > -1 ) {
    090                        storeContext( dir, name, (ViewContext) val );
    091                    }
    092                }
    093            }
    094        }
    095
    096        /**
    097         * stores the passed web map context as loggedout WMC into the current users WMC directory
    098         *
    099         * @param dir
    100         * @param name
    101         * @param context
    102         * @throws ParserConfigurationException
    103         * @throws IOException
    104         */
    105        private void storeContext( File dir, String name, ViewContext context )
    106                                throws ParserConfigurationException, IOException {
    107
    108            XMLFragment xml = XMLFactory.export( context );
    109
    110            File file = new File( dir.getAbsolutePath() + '/' + name + ".xml" );
    111
    112            FileOutputStream fos = new FileOutputStream( file );
    113            xml.write( fos );
    114            fos.close();
    115
    116        }
    117
    118    }