001    //$HeadURL$
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    
037    package org.deegree.framework.file;
038    
039    import java.io.File;
040    import java.io.FileInputStream;
041    import java.io.FileOutputStream;
042    import java.io.IOException;
043    import java.util.Properties;
044    
045    import org.deegree.framework.log.ILogger;
046    import org.deegree.framework.log.LoggerFactory;
047    
048    /**
049     *
050     *
051     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
052     * @author last edited by: $Author: poth $
053     *
054     * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
055     */
056    public class FileMemory {
057    
058        private static ILogger LOG = LoggerFactory.getLogger( FileMemory.class );
059    
060        /**
061         *
062         * @param type
063         *            any string that is valid to be part of a file name
064         * @return last directory
065         */
066        public static File getLastDirectory( String type ) {
067            Properties prop = new Properties();
068            try {
069                File tmpFile = File.createTempFile( "deegree_file_memory", ".txt" );
070                String s = tmpFile.getAbsolutePath();
071                s = s.substring( 0, s.lastIndexOf( File.separator ) + 1 );
072                tmpFile = new File( s + "deegree_file_memory.txt" );
073                if ( tmpFile.exists() ) {
074                    FileInputStream fis = new FileInputStream( tmpFile );
075                    prop.load( fis );
076                    fis.close();
077                }
078            } catch ( IOException e ) {
079                LOG.logError( e.getMessage(), e );
080            }
081            String s = prop.getProperty( type );
082            if ( s == null ) {
083                return new File( "." );
084            }
085            return new File( s );
086        }
087    
088        /**
089         *
090         * @param type
091         *            any string that is valid to be part of a file name
092         * @param dir
093         */
094        public static void setLastDirectory( String type, File dir ) {
095            Properties prop = new Properties();
096            try {
097                File tmpFile = File.createTempFile( "deegree_file_memory", ".txt" );
098                String s = tmpFile.getAbsolutePath();
099                s = s.substring( 0, s.lastIndexOf( File.separator ) + 1 );
100                tmpFile = new File( s + "deegree_file_memory.txt" );
101                if ( tmpFile.exists() ) {
102                    FileInputStream fis = new FileInputStream( tmpFile );
103                    prop.load( fis );
104                    fis.close();
105                }
106            } catch ( IOException e ) {
107                LOG.logError( e.getMessage(), e );
108            }
109            prop.put( type, dir.getAbsolutePath() );
110            try {
111                File tmpFile = File.createTempFile( "deegree_file_memory", ".txt" );
112                String s = tmpFile.getAbsolutePath();
113                s = s.substring( 0, s.lastIndexOf( File.separator ) + 1 );
114                tmpFile = new File( s + "deegree_file_memory.txt" );
115                FileOutputStream fos = new FileOutputStream( tmpFile );
116                prop.store( fos, null );
117                fos.close();
118            } catch ( Exception e ) {
119                LOG.logError( e.getMessage(), e );
120            }
121        }
122    
123        /**
124         *
125         * @param type
126         *            any string that is valid to be part of a file name
127         * @return last file
128         */
129        public static File getLastFile( String type ) {
130            // TODO
131            return null;
132        }
133    
134        /**
135         *
136         * @param type
137         *            any string that is valid to be part of a file name
138         * @param file
139         */
140        public static void setLastFile( String type, File file ) {
141            // TODO
142        }
143    
144    }