001 //$HeadURL$
002 /*---------------- FILE HEADER ------------------------------------------
003 This file is part of deegree.
004 Copyright (C) 2001-2008 by:
005 Department of Geography, University of Bonn
006 http://www.giub.uni-bonn.de/deegree/
007 lat/lon GmbH
008 http://www.lat-lon.de
009
010 This library is free software; you can redistribute it and/or
011 modify it under the terms of the GNU Lesser General Public
012 License as published by the Free Software Foundation; either
013 version 2.1 of the License, or (at your option) any later version.
014 This library is distributed in the hope that it will be useful,
015 but WITHOUT ANY WARRANTY; without even the implied warranty of
016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017 Lesser General Public License for more details.
018 You should have received a copy of the GNU Lesser General Public
019 License along with this library; if not, write to the Free Software
020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021 Contact:
022
023 Andreas Poth
024 lat/lon GmbH
025 Aennchenstr. 19
026 53177 Bonn
027 Germany
028 E-Mail: poth@lat-lon.de
029
030 Prof. Dr. Klaus Greve
031 Department of Geography
032 University of Bonn
033 Meckenheimer Allee 166
034 53115 Bonn
035 Germany
036 E-Mail: greve@giub.uni-bonn.de
037 ---------------------------------------------------------------------------*/
038
039 package org.deegree.framework.file;
040
041 import java.io.File;
042 import java.io.FileInputStream;
043 import java.io.FileOutputStream;
044 import java.io.IOException;
045 import java.util.Properties;
046
047 import org.deegree.framework.log.ILogger;
048 import org.deegree.framework.log.LoggerFactory;
049
050 /**
051 *
052 *
053 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
054 * @author last edited by: $Author: poth $
055 *
056 * @version. $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
057 */
058 public class FileMemory {
059
060 private static ILogger LOG = LoggerFactory.getLogger( FileMemory.class );
061
062
063 /**
064 *
065 * @param type any string that is valid to be part of a file name
066 * @return last directory
067 */
068 public static File getLastDirectory( String type ) {
069 Properties prop = new Properties();
070 try {
071 File tmpFile = File.createTempFile( "deegree_file_memory", ".txt" );
072 String s = tmpFile.getAbsolutePath();
073 s = s.substring( 0, s.lastIndexOf( File.separator ) + 1 );
074 tmpFile = new File( s + "deegree_file_memory.txt");
075 if ( tmpFile.exists() ) {
076 FileInputStream fis = new FileInputStream( tmpFile );
077 prop.load( fis );
078 fis.close();
079 }
080 } catch ( IOException e ) {
081 LOG.logError( e.getMessage(), e );
082 }
083 String s = prop.getProperty( type );
084 if ( s == null ) {
085 return new File( "." );
086 }
087 return new File( s );
088 }
089
090 /**
091 *
092 * @param type any string that is valid to be part of a file name
093 * @param dir
094 */
095 public static void setLastDirectory( String type, File dir ) {
096 Properties prop = new Properties();
097 try {
098 File tmpFile = File.createTempFile( "deegree_file_memory", ".txt" );
099 String s = tmpFile.getAbsolutePath();
100 s = s.substring( 0, s.lastIndexOf( File.separator ) + 1 );
101 tmpFile = new File( s + "deegree_file_memory.txt");
102 if ( tmpFile.exists() ) {
103 FileInputStream fis = new FileInputStream( tmpFile );
104 prop.load( fis );
105 fis.close();
106 }
107 } catch ( IOException e ) {
108 LOG.logError( e.getMessage(), e );
109 }
110 prop.put( type, dir.getAbsolutePath() );
111 try {
112 File tmpFile = File.createTempFile( "deegree_file_memory", ".txt" );
113 String s = tmpFile.getAbsolutePath();
114 s = s.substring( 0, s.lastIndexOf( File.separator ) + 1 );
115 tmpFile = new File( s + "deegree_file_memory.txt");
116 FileOutputStream fos = new FileOutputStream( tmpFile );
117 prop.store( fos, null );
118 fos.close();
119 } catch ( Exception e ) {
120 LOG.logError( e.getMessage(), e );
121 }
122 }
123
124 /**
125 *
126 * @param type 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 any string that is valid to be part of a file name
137 * @param file
138 */
139 public static void setLastFile( String type, File file ) {
140 //TODO
141 }
142
143 }