Revision 1746 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/folders/impl/DefaultFoldersManager.java

View differences:

DefaultFoldersManager.java
28 28
import java.io.IOException;
29 29
import java.lang.management.ManagementFactory;
30 30
import java.lang.management.RuntimeMXBean;
31
import java.util.Collections;
32 31
import java.util.HashMap;
33 32
import java.util.Iterator;
34 33
import java.util.Map;
34
import javax.swing.filechooser.FileSystemView;
35 35
import org.apache.commons.io.FileUtils;
36 36
import org.apache.commons.io.FilenameUtils;
37 37
import org.apache.commons.io.IOUtils;
......
51 51
    public DefaultFoldersManager() {
52 52
        String temp = System.getenv("GVSIG_TEMP");
53 53
        File f;
54
        if( StringUtils.isEmpty(temp) ) {
54
        if (StringUtils.isEmpty(temp)) {
55 55
            temp = FileUtils.getTempDirectoryPath();
56 56
            // f = FileUtils.getFile(temp, "tmp-gvsig"+getPID());
57 57
            f = FileUtils.getFile(temp, "tmp-gvsig");
......
65 65
            public void run() {
66 66
                cleanTemporaryFiles();
67 67
            }
68
        });        
68
        });
69 69
    }
70 70

  
71
    @Override
72
    public void setLastPath(String pathId, File path) {
73
        this.folders.put("last.path." + pathId, path);
74
    }
75

  
76
    @Override
77
    public File getLastPath(String pathId, File defaultValue) {
78
        File path = this.folders.get("last.path." + pathId);
79

  
80
        if (path != null) {
81
            return path;
82
        }
83
        if (defaultValue != null) {
84
            return defaultValue;
85
        }
86
        return FileSystemView.getFileSystemView().getHomeDirectory();
87
    }
88

  
71 89
    private int getPID() {
72 90
        try {
73 91
            RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
......
85 103

  
86 104
    @Override
87 105
    public void setTemporaryFolder(File folder) {
88
        if( folder == null ) {
106
        if (folder == null) {
89 107
            throw new IllegalArgumentException("Can't set temporary folder to null.");
90 108
        }
91 109
        this.temporaryFolder = folder.getAbsoluteFile();
......
94 112

  
95 113
    @Override
96 114
    public void cleanTemporaryFiles() {
97
        if( this.temporaryFolder == null ) {
115
        if (this.temporaryFolder == null) {
98 116
            logger.warn("Can't clean temporary folder, is null.");
99 117
        }
100 118
        try {
......
106 124

  
107 125
    @Override
108 126
    public File createTemporaryFolder() {
109
        if( this.temporaryFolder == null ) {
127
        if (this.temporaryFolder == null) {
110 128
            throw new RuntimeException("Can't create temporary folder, is null.");
111 129
        }
112 130
        try {
......
119 137

  
120 138
    @Override
121 139
    public File getTemporaryFile(String... pathComponents) {
122
        if( this.temporaryFolder == null ) {
140
        if (this.temporaryFolder == null) {
123 141
            throw new RuntimeException("Can't get temporary file, temporary folder is null.");
124 142
        }
125 143
        File f = FileUtils.getFile(temporaryFolder, pathComponents);
......
132 150
        String fullName = f.getAbsolutePath();
133 151
        String name = FilenameUtils.removeExtension(fullName);
134 152
        String extension = FilenameUtils.getExtension(fullName);
135
        if( StringUtils.isEmpty(extension) ) {
153
        if (StringUtils.isEmpty(extension)) {
136 154
            fullName = name + "-" + Long.toHexString(System.currentTimeMillis()) + "-" + Integer.toHexString(uniqueCounter);
137 155
        } else {
138 156
            fullName = name + "-" + Long.toHexString(System.currentTimeMillis()) + "-" + Integer.toHexString(uniqueCounter) + "." + extension;
......
143 161

  
144 162
    @Override
145 163
    public File createTemporaryFile(String basename, byte[] data) {
146
        if( this.temporaryFolder == null ) {
164
        if (this.temporaryFolder == null) {
147 165
            throw new RuntimeException("Can't create temporary file, temporary folder is null.");
148 166
        }
149 167
        File f = getTemporaryFile(basename);
......
168 186

  
169 187
    @Override
170 188
    public void set(String id, File file) {
171
        if( this.folders == null ) {
189
        if (this.folders == null) {
172 190
            this.folders = new HashMap<>();
173 191
        }
174 192
        this.folders.put(id, file);
......
176 194

  
177 195
    @Override
178 196
    public File get(String id) {
179
        if( this.folders == null ) {
197
        if (this.folders == null) {
180 198
            this.folders = new HashMap<>();
181 199
        }
182 200
        return this.folders.get(id);
......
184 202

  
185 203
    @Override
186 204
    public File get(String id, File defaultValue) {
187
        if( this.folders == null ) {
205
        if (this.folders == null) {
188 206
            this.folders = new HashMap<>();
189 207
        }
190
        if( this.folders.containsKey(id) ) {
208
        if (this.folders.containsKey(id)) {
191 209
            return this.folders.get(id);
192 210
        }
193 211
        return defaultValue;
......
195 213

  
196 214
    @Override
197 215
    public Iterator<String> iterator() {
198
        if( this.folders == null ) {
216
        if (this.folders == null) {
199 217
            this.folders = new HashMap<>();
200 218
        }
201 219
        return this.folders.keySet().iterator();
......
203 221

  
204 222
    @Override
205 223
    public boolean isEmpty() {
206
        return this.folders==null || this.folders.isEmpty();
224
        return this.folders == null || this.folders.isEmpty();
207 225
    }
208 226

  
209 227
}

Also available in: Unified diff