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