25 |
25 |
import java.net.MalformedURLException;
|
26 |
26 |
import java.net.URISyntaxException;
|
27 |
27 |
import java.net.URL;
|
28 |
|
import java.util.ArrayList;
|
29 |
|
import java.util.Collections;
|
30 |
28 |
import java.util.HashSet;
|
31 |
29 |
import java.util.Iterator;
|
32 |
|
import java.util.List;
|
33 |
30 |
import java.util.Map;
|
34 |
31 |
import java.util.Set;
|
35 |
32 |
|
... | ... | |
41 |
38 |
|
42 |
39 |
/**
|
43 |
40 |
* Utilities for manage {@link PersistentState} objects
|
44 |
|
*
|
|
41 |
*
|
45 |
42 |
* @author gvSIG Team
|
46 |
43 |
* @version $Id$
|
47 |
|
*
|
|
44 |
*
|
48 |
45 |
*/
|
49 |
46 |
public abstract class PersistenceUtils {
|
50 |
47 |
|
51 |
48 |
/**
|
52 |
49 |
* Adjust all <i>file-system related</i> values with <code>rootFolder</code>
|
53 |
50 |
* as root folder.
|
54 |
|
*
|
|
51 |
*
|
55 |
52 |
* @param state
|
56 |
53 |
* @param rootFolder
|
57 |
54 |
* @throws PersistenceException
|
58 |
55 |
*/
|
59 |
|
public static void fixMapContextFilePaths(PersistentState state, File rootFolder)
|
60 |
|
throws PersistenceException {
|
|
56 |
public static void fixMapContextFilePaths(PersistentState state,
|
|
57 |
File rootFolder) throws PersistenceException {
|
61 |
58 |
PersistentContext context = state.getContext();
|
62 |
59 |
|
63 |
60 |
@SuppressWarnings("unchecked")
|
... | ... | |
94 |
91 |
|
95 |
92 |
/**
|
96 |
93 |
* Fixes relative path to get an absolute one
|
97 |
|
*
|
|
94 |
*
|
98 |
95 |
* @param file
|
99 |
96 |
* @param rootFolder
|
100 |
97 |
* @return
|
... | ... | |
109 |
106 |
/**
|
110 |
107 |
* Returns a list of all <i>file-system related</i> <code>state</code>'s
|
111 |
108 |
* values
|
112 |
|
*
|
|
109 |
*
|
113 |
110 |
* @param state
|
114 |
111 |
* @return
|
115 |
112 |
* @throws PersistenceException
|
116 |
113 |
*/
|
117 |
|
public static List<File> getRelatedFiles(PersistentState state)
|
|
114 |
public static Set<File> getRelatedFiles(PersistentState state)
|
118 |
115 |
throws PersistenceException {
|
119 |
|
List<File> relatedFiles = new ArrayList<File>();
|
|
116 |
Set<File> relatedFiles = new HashSet<File>();
|
120 |
117 |
PersistentContext context = state.getContext();
|
121 |
118 |
|
122 |
119 |
@SuppressWarnings("unchecked")
|
... | ... | |
142 |
139 |
}
|
143 |
140 |
}
|
144 |
141 |
}
|
145 |
|
return Collections.unmodifiableList(relatedFiles);
|
|
142 |
return relatedFiles;
|
146 |
143 |
}
|
147 |
144 |
|
148 |
145 |
/**
|
... | ... | |
155 |
152 |
* <code>rootFolder</code> if it's provided. (only in file which
|
156 |
153 |
* <code>rootFolder</code> is ancestor of)
|
157 |
154 |
* </p>
|
158 |
|
*
|
|
155 |
*
|
159 |
156 |
* @param state
|
160 |
157 |
* to adjust
|
161 |
158 |
* @param transformMapping
|
... | ... | |
194 |
191 |
file =
|
195 |
192 |
getTransformedFile(file, transformMapping,
|
196 |
193 |
missingFilesInMapping, rootFolder);
|
197 |
|
value =
|
198 |
|
new URL("file", "", file.toURI().toString());
|
|
194 |
value = new URL("file", "", file.toString());
|
199 |
195 |
aState.set(field.getName(), value);
|
200 |
196 |
}
|
201 |
197 |
} catch (MalformedURLException e) {
|
... | ... | |
221 |
217 |
* if <code>rootBaseFolder</code> is provided, makes returned file relative
|
222 |
218 |
* to it (if <code>rootBaseFolder</code> is ancestor of returned file)
|
223 |
219 |
* </p>
|
224 |
|
*
|
|
220 |
*
|
225 |
221 |
* @param source
|
226 |
222 |
* @param transformMapping
|
227 |
223 |
* @param missing
|