root / 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 / compilation / process / WriteMapContextDefinition.java @ 2
History | View | Annotate | Download (3.51 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.educa.thematicmap.impl.compilation.process; |
23 |
|
24 |
import java.io.File; |
25 |
import java.io.OutputStream; |
26 |
|
27 |
import org.apache.commons.io.IOUtils; |
28 |
|
29 |
import org.gvsig.educa.thematicmap.compilation.CompilationException; |
30 |
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompiler; |
31 |
import org.gvsig.educa.thematicmap.impl.util.FileUtils; |
32 |
import org.gvsig.educa.thematicmap.impl.util.PersistenceUtils; |
33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
35 |
import org.gvsig.tools.persistence.PersistentState; |
36 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
37 |
|
38 |
/**
|
39 |
* <p>
|
40 |
* {@link ThematicMapCompiler} process step
|
41 |
* </p>
|
42 |
* <p>
|
43 |
* This steps write MapContext description file into work folder. Normalize file
|
44 |
* routes to its final location in the Thematic Map
|
45 |
* </p>
|
46 |
* <p>
|
47 |
* From {@link ProcessData} Uses:
|
48 |
* <ul>
|
49 |
* <li>{@link ProcessData#mapContext}</li>
|
50 |
* <li>{@link ProcessData#workFolder}</li>
|
51 |
* <li>{@link ProcessData#fileMapping}</li>
|
52 |
* </ul>
|
53 |
* </p>
|
54 |
*
|
55 |
* @author gvSIG Team
|
56 |
* @version $Id$
|
57 |
*
|
58 |
*/
|
59 |
public class WriteMapContextDefinition implements ProcessStep { |
60 |
|
61 |
private final PersistenceManager persitenceMan; |
62 |
|
63 |
public WriteMapContextDefinition() {
|
64 |
persitenceMan = ToolsLocator.getPersistenceManager(); |
65 |
} |
66 |
|
67 |
public String getStepDescriptionKey() { |
68 |
return "Write_MapContext_definition"; |
69 |
} |
70 |
|
71 |
public String getStepDescription() { |
72 |
return "Write MapContext definition"; |
73 |
} |
74 |
|
75 |
public void doProcess(ProcessData data, int stepPercent) |
76 |
throws CompilationException {
|
77 |
PersistentState mapContextState; |
78 |
try {
|
79 |
mapContextState = persitenceMan.getState(data.mapContext); |
80 |
} catch (PersistenceException e) {
|
81 |
data.status.setError("Problem getting MapContext state", e);
|
82 |
return;
|
83 |
} |
84 |
try {
|
85 |
PersistenceUtils.relocateFiles(mapContextState, data.fileMapping, |
86 |
data.workFolder); |
87 |
} catch (PersistenceException e) {
|
88 |
data.status.setError( |
89 |
"Problem relocate file paths of mapContext's definition", e);
|
90 |
return;
|
91 |
} |
92 |
data.mapContextFile = new File(data.mapContextFolder, "mapContext.xml"); |
93 |
OutputStream os = null; |
94 |
try {
|
95 |
try {
|
96 |
os = FileUtils.openOutputStream(data.mapContextFile); |
97 |
persitenceMan.saveState(mapContextState, os); |
98 |
} catch (Exception e) { |
99 |
data.status.setError("Problem storing MapContext file", e);
|
100 |
return;
|
101 |
} |
102 |
} finally {
|
103 |
IOUtils.closeQuietly(os); |
104 |
} |
105 |
} |
106 |
|
107 |
} |