Revision 56
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.lib/org.gvsig.educa.thematicmap.lib.api/src/main/java/org/gvsig/educa/thematicmap/map/ThematicMap.java | ||
---|---|---|
32 | 32 |
* </p> |
33 | 33 |
* This class' instances contains information about a installed <i>Thematic |
34 | 34 |
* Map</i> |
35 |
* |
|
35 |
*
|
|
36 | 36 |
* @author <a href="http://www.disid.com">DiSiD Technologies S.L.</a> |
37 | 37 |
* @version $Rev$ |
38 | 38 |
* @since {version} |
... | ... | |
41 | 41 |
|
42 | 42 |
/** |
43 | 43 |
* Gets information about this <i>Thematic Map</i> |
44 |
* |
|
44 |
*
|
|
45 | 45 |
* @return |
46 | 46 |
*/ |
47 | 47 |
ThematicMapInformation getInformation(); |
... | ... | |
55 | 55 |
* </p> |
56 | 56 |
* unzip folder is defined in {@link ThematicMapManager#getTemporalFolder()} |
57 | 57 |
* </p> |
58 |
* |
|
58 |
*
|
|
59 | 59 |
* @throws InvalidThematicMapFormatException |
60 | 60 |
* @throws CantLoadContextException |
61 | 61 |
* @throws IOException |
... | ... | |
65 | 65 |
|
66 | 66 |
/** |
67 | 67 |
* Informs if <i>Thematic Map</i> it's already opened or not |
68 |
* |
|
68 |
*
|
|
69 | 69 |
* @return if it's opened |
70 | 70 |
*/ |
71 | 71 |
boolean isOpen(); |
72 | 72 |
|
73 | 73 |
/** |
74 | 74 |
* Unloads all data loaded in memory and cleans its temporal folder |
75 |
* |
|
75 |
*
|
|
76 | 76 |
* @throws IOException |
77 | 77 |
* if any problem is found cleaning temporal folder |
78 |
* |
|
78 |
*
|
|
79 | 79 |
*/ |
80 | 80 |
void close() throws IOException; |
81 | 81 |
|
82 | 82 |
/** |
83 | 83 |
* Gets MapContext with <i>Thematic Map</i> representation |
84 |
* |
|
84 |
*
|
|
85 | 85 |
* @return MapContext instance |
86 | 86 |
* @throws IllegalStateException |
87 | 87 |
* if {@link #isOpen()} == false |
... | ... | |
89 | 89 |
MapContext getMapContext(); |
90 | 90 |
|
91 | 91 |
/** |
92 |
* |
|
92 |
* Gets the file which ThematicMap data |
|
93 |
* |
|
93 | 94 |
* @return |
94 | 95 |
*/ |
95 | 96 |
String getSourceFilePath(); |
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.lib/org.gvsig.educa.thematicmap.lib.api/src/main/java/org/gvsig/educa/thematicmap/ThematicMapFileServices.java | ||
---|---|---|
25 | 25 |
import java.io.IOException; |
26 | 26 |
import java.util.zip.ZipException; |
27 | 27 |
|
28 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
29 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
30 |
|
|
28 | 31 |
/** |
29 | 32 |
* Thematic Map Utilities related to files |
30 |
*
|
|
33 |
* |
|
31 | 34 |
* @author gvSIG Team |
32 | 35 |
* @version $Id$ |
36 |
* |
|
37 |
*/ |
|
38 |
/** |
|
39 |
* @author gvSIG Team |
|
40 |
* @version $Id$ |
|
33 | 41 |
* |
34 | 42 |
*/ |
35 | 43 |
public interface ThematicMapFileServices { |
... | ... | |
179 | 187 |
*/ |
180 | 188 |
File getRelativeTo(File path, File basePath); |
181 | 189 |
|
190 |
/** |
|
191 |
* <p> |
|
192 |
* Load a mapContext from a file adjusting file paths which are supposed |
|
193 |
* relatives to a folder |
|
194 |
* </p> |
|
195 |
* |
|
196 |
* @param mapContext |
|
197 |
* persistence file |
|
198 |
* @param relativaPathFolder |
|
199 |
* for files refered in mapContext |
|
200 |
* @return |
|
201 |
* @throws IOException |
|
202 |
* @throws PersistenceException |
|
203 |
*/ |
|
204 |
MapContext loadMapContext(File mapContext, File relativaPathFolder) |
|
205 |
throws IOException, PersistenceException; |
|
182 | 206 |
} |
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.lib/org.gvsig.educa.thematicmap.lib.impl/src/main/java/org/gvsig/educa/thematicmap/impl/map/ThematicMapLoader.java | ||
---|---|---|
32 | 32 |
import org.slf4j.Logger; |
33 | 33 |
import org.slf4j.LoggerFactory; |
34 | 34 |
|
35 |
import org.gvsig.educa.thematicmap.ThematicMapFileServices; |
|
36 |
import org.gvsig.educa.thematicmap.ThematicMapLocator; |
|
35 | 37 |
import org.gvsig.educa.thematicmap.impl.util.FileUtils; |
36 | 38 |
import org.gvsig.educa.thematicmap.impl.util.IOUtils; |
37 |
import org.gvsig.educa.thematicmap.impl.util.PersistenceUtils; |
|
38 | 39 |
import org.gvsig.educa.thematicmap.map.CantLoadContextException; |
39 | 40 |
import org.gvsig.educa.thematicmap.map.InvalidInstalledThematicMapException; |
40 | 41 |
import org.gvsig.educa.thematicmap.map.InvalidThematicMapFormatException; |
... | ... | |
66 | 67 |
|
67 | 68 |
private final PackageInfoReader packageInfoReader; |
68 | 69 |
|
70 |
private final ThematicMapFileServices fileServices; |
|
71 |
|
|
69 | 72 |
/** |
70 | 73 |
* |
71 | 74 |
*/ |
72 | 75 |
public ThematicMapLoader() { |
73 | 76 |
installerManager = InstallerLocator.getInstallerManager(); |
74 | 77 |
packageInfoReader = installerManager.getDefaultPackageInfoReader(); |
78 |
fileServices = ThematicMapLocator.getFileServices(); |
|
75 | 79 |
} |
76 | 80 |
|
77 | 81 |
/** |
... | ... | |
108 | 112 |
.concat(mapContextFile.getAbsolutePath())); |
109 | 113 |
} |
110 | 114 |
|
111 |
InputStream is = null; |
|
115 |
// Load map context |
|
116 |
MapContext mapContext; |
|
112 | 117 |
try { |
113 |
try { |
|
114 |
// open file |
|
115 |
is = FileUtils.openInputStream(mapContextFile); |
|
116 | 118 |
|
117 |
// load Persistence status from file |
|
118 |
PersistentState persistenceStatus = |
|
119 |
persistenceManager.loadState(is); |
|
119 |
mapContext = |
|
120 |
fileServices.loadMapContext(mapContextFile, deployFolder); |
|
120 | 121 |
|
121 |
// Adjust all path in persistence status to deploy folder |
|
122 |
PersistenceUtils.fixMapContextFilePaths(persistenceStatus, |
|
123 |
deployFolder); |
|
124 |
|
|
125 |
// Create a new mapContext Instance and load it form persistence |
|
126 |
// status |
|
127 |
MapContext mapContext = |
|
128 |
(MapContext) persistenceManager.create(persistenceStatus); |
|
129 |
|
|
130 |
if (mapContext == null) { |
|
131 |
throw new CantLoadContextException(mapFile, mapContextFile, |
|
132 |
"mapContext not loaded", null); |
|
133 |
} |
|
134 |
|
|
135 |
return mapContext; |
|
136 |
} catch (Exception e) { |
|
137 |
throw new CantLoadContextException(mapFile, mapContextFile, e); |
|
122 |
if (mapContext == null) { |
|
123 |
throw new CantLoadContextException(mapFile, mapContextFile, |
|
124 |
"mapContext not loaded", null); |
|
138 | 125 |
} |
139 | 126 |
|
140 |
} finally { |
|
141 |
IOUtils.closeQuietly(is); |
|
127 |
return mapContext; |
|
128 |
} catch (Exception e) { |
|
129 |
throw new CantLoadContextException(mapFile, mapContextFile, e); |
|
142 | 130 |
} |
143 | 131 |
} |
144 | 132 |
|
org.gvsig.educa.thematicmap/trunk/org.gvsig.educa.thematicmap/org.gvsig.educa.thematicmap.lib/org.gvsig.educa.thematicmap.lib.impl/src/main/java/org/gvsig/educa/thematicmap/impl/DefaultThematicMapFileServices.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import java.io.File; |
25 | 25 |
import java.io.IOException; |
26 |
import java.io.InputStream; |
|
26 | 27 |
import java.util.zip.ZipException; |
27 | 28 |
|
28 | 29 |
import org.gvsig.educa.thematicmap.ThematicMapFileServices; |
29 | 30 |
import org.gvsig.educa.thematicmap.impl.util.FileUtils; |
31 |
import org.gvsig.educa.thematicmap.impl.util.IOUtils; |
|
32 |
import org.gvsig.educa.thematicmap.impl.util.PersistenceUtils; |
|
33 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
34 |
import org.gvsig.tools.ToolsLocator; |
|
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
36 |
import org.gvsig.tools.persistence.PersistentState; |
|
37 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
30 | 38 |
|
31 | 39 |
/** |
32 | 40 |
* @author gvSIG Team |
... | ... | |
35 | 43 |
*/ |
36 | 44 |
public class DefaultThematicMapFileServices implements ThematicMapFileServices { |
37 | 45 |
|
46 |
private final PersistenceManager persistenceManager; |
|
47 |
|
|
48 |
/** |
|
49 |
* |
|
50 |
*/ |
|
51 |
public DefaultThematicMapFileServices() { |
|
52 |
persistenceManager = ToolsLocator.getPersistenceManager(); |
|
53 |
} |
|
54 |
|
|
38 | 55 |
public void unzipFile(File zipFile, File outputFloder) throws ZipException, |
39 | 56 |
IOException { |
40 | 57 |
FileUtils.unzipFile(zipFile, outputFloder); |
... | ... | |
72 | 89 |
return FileUtils.getRelativeTo(path, basePath); |
73 | 90 |
} |
74 | 91 |
|
92 |
public MapContext loadMapContext(File mapContext, File relativaPathFolder) |
|
93 |
throws IOException, PersistenceException { |
|
94 |
InputStream is = null; |
|
95 |
try { |
|
96 |
// open file |
|
97 |
is = FileUtils.openInputStream(mapContext); |
|
98 |
|
|
99 |
// load Persistence status from file |
|
100 |
PersistentState persistenceStatus = |
|
101 |
persistenceManager.loadState(is); |
|
102 |
|
|
103 |
// Adjust all path in persistence status to deploy folder |
|
104 |
PersistenceUtils.fixMapContextFilePaths(persistenceStatus, |
|
105 |
relativaPathFolder); |
|
106 |
|
|
107 |
// Create a new mapContext Instance and load it form persistence |
|
108 |
// status |
|
109 |
return (MapContext) persistenceManager.create(persistenceStatus); |
|
110 |
|
|
111 |
} finally { |
|
112 |
IOUtils.closeQuietly(is); |
|
113 |
} |
|
114 |
} |
|
75 | 115 |
} |
Also available in: Unified diff