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
061: .getLogger(FileMemory.class);
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",
072: ".txt");
073: String s = tmpFile.getAbsolutePath();
074: s = s.substring(0, s.lastIndexOf(File.separator) + 1);
075: tmpFile = new File(s + "deegree_file_memory.txt");
076: if (tmpFile.exists()) {
077: FileInputStream fis = new FileInputStream(tmpFile);
078: prop.load(fis);
079: fis.close();
080: }
081: } catch (IOException e) {
082: LOG.logError(e.getMessage(), e);
083: }
084: String s = prop.getProperty(type);
085: if (s == null) {
086: return new File(".");
087: }
088: return new File(s);
089: }
090:
091: /**
092: *
093: * @param type any string that is valid to be part of a file name
094: * @param dir
095: */
096: public static void setLastDirectory(String type, File dir) {
097: Properties prop = new Properties();
098: try {
099: File tmpFile = File.createTempFile("deegree_file_memory",
100: ".txt");
101: String s = tmpFile.getAbsolutePath();
102: s = s.substring(0, s.lastIndexOf(File.separator) + 1);
103: tmpFile = new File(s + "deegree_file_memory.txt");
104: if (tmpFile.exists()) {
105: FileInputStream fis = new FileInputStream(tmpFile);
106: prop.load(fis);
107: fis.close();
108: }
109: } catch (IOException e) {
110: LOG.logError(e.getMessage(), e);
111: }
112: prop.put(type, dir.getAbsolutePath());
113: try {
114: File tmpFile = File.createTempFile("deegree_file_memory",
115: ".txt");
116: String s = tmpFile.getAbsolutePath();
117: s = s.substring(0, s.lastIndexOf(File.separator) + 1);
118: tmpFile = new File(s + "deegree_file_memory.txt");
119: FileOutputStream fos = new FileOutputStream(tmpFile);
120: prop.store(fos, null);
121: fos.close();
122: } catch (Exception e) {
123: LOG.logError(e.getMessage(), e);
124: }
125: }
126:
127: /**
128: *
129: * @param type any string that is valid to be part of a file name
130: * @return last file
131: */
132: public static File getLastFile(String type) {
133: //TODO
134: return null;
135: }
136:
137: /**
138: *
139: * @param type any string that is valid to be part of a file name
140: * @param file
141: */
142: public static void setLastFile(String type, File file) {
143: //TODO
144: }
145:
146: }
|