Revision 46205
tags/org.gvsig.desktop-2.0.354/license.txt | ||
---|---|---|
1 |
gvSIG. Desktop Geographic Information System. |
|
2 |
|
|
3 |
Copyright (C) 2007-2020 gvSIG Association. |
|
4 |
|
|
5 |
This program is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU General Public License |
|
7 |
as published by the Free Software Foundation; either version 3 |
|
8 |
of the License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
|
|
18 |
For any additional information, do not hesitate to contact us |
|
19 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.exportto</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>${project.artifactId}</name> |
|
8 |
<description>Exportto project</description> |
|
9 |
|
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>org.gvsig.desktop.library</artifactId> |
|
13 |
<version>2.0.354</version> |
|
14 |
</parent> |
|
15 |
|
|
16 |
<dependencies> |
|
17 |
<dependency> |
|
18 |
<groupId>org.gvsig</groupId> |
|
19 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
24 |
<type>test-jar</type> |
|
25 |
<scope>test</scope> |
|
26 |
</dependency> |
|
27 |
</dependencies> |
|
28 |
|
|
29 |
<modules> |
|
30 |
<module>org.gvsig.exportto.lib</module> |
|
31 |
<module>org.gvsig.exportto.swing</module> |
|
32 |
</modules> |
|
33 |
</project> |
|
34 |
|
|
35 |
|
|
36 |
|
|
0 | 37 |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportParameters.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import java.text.DateFormat; |
|
4 |
import java.text.SimpleDateFormat; |
|
5 |
import java.util.Date; |
|
6 |
import org.gvsig.export.ExportAttributes; |
|
7 |
import org.gvsig.export.ExportLocator; |
|
8 |
import org.gvsig.fmap.dal.exception.DataException; |
|
9 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
11 |
import org.gvsig.export.ExportParameters; |
|
12 |
import org.gvsig.expressionevaluator.Expression; |
|
13 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
14 |
import org.gvsig.tools.ToolsLocator; |
|
15 |
import org.gvsig.tools.dynobject.DynStruct; |
|
16 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
17 |
import org.gvsig.tools.persistence.PersistentState; |
|
18 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
19 |
import org.slf4j.Logger; |
|
20 |
import org.slf4j.LoggerFactory; |
|
21 |
|
|
22 |
/** |
|
23 |
* |
|
24 |
* @author jjdelcerro |
|
25 |
*/ |
|
26 |
public abstract class AbstractExportParameters implements ExportParameters { |
|
27 |
|
|
28 |
private FeatureStore sourceFeatureStore; |
|
29 |
private Expression filterExpression; |
|
30 |
private int featuresToUse; |
|
31 |
private Object context; |
|
32 |
protected ExportAttributes exportAttributes = null; |
|
33 |
private Date date = new Date(); |
|
34 |
public ExportServiceFactory factory; |
|
35 |
|
|
36 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractExportParameters.class); |
|
37 |
private FeatureQuery featureQuery; |
|
38 |
|
|
39 |
public AbstractExportParameters(ExportServiceFactory factory) { |
|
40 |
this.factory = factory; |
|
41 |
this.exportAttributes = ExportLocator.getServiceManager().createExportAttributes(); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public boolean needsSelectTargetProjection() { |
|
46 |
return false; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public FeatureType getSourceFeatureType() { |
|
51 |
if (!(this.exportAttributes == null)) { |
|
52 |
return this.exportAttributes.getSourceFeatureType(); |
|
53 |
} else { |
|
54 |
return null; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
|
60 |
this.exportAttributes.setSourceFeatureType(sourceFeatureType, this.featureQuery); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public void setSourceFeatureStore(FeatureStore sourceFeatureStore) { |
|
65 |
this.sourceFeatureStore = sourceFeatureStore; |
|
66 |
try { |
|
67 |
FeatureType sourceFeatureType = sourceFeatureStore.getDefaultFeatureType(); |
|
68 |
this.exportAttributes.setSourceFeatureType(sourceFeatureType, this.featureQuery); |
|
69 |
} catch (DataException ex) { |
|
70 |
throw new RuntimeException("Can't set feature type", ex); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public FeatureStore getSourceFeatureStore() { |
|
76 |
return this.sourceFeatureStore; |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public Expression getFilterExpresion() { |
|
81 |
return this.filterExpression; |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public void setFilterExpresion(Expression expression) { |
|
86 |
this.filterExpression = expression; |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public FeatureQuery getFeatureQuery() { |
|
91 |
return this.featureQuery; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public void setFeatureQuery(FeatureQuery query) { |
|
96 |
this.featureQuery = query; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public int getFeaturesToUse() { |
|
101 |
return featuresToUse; |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public void setFeaturesToUse(int featuresToUse) { |
|
106 |
this.featuresToUse = featuresToUse; |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public Object getContext() { |
|
111 |
return context; |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public void setContext(Object context) { |
|
116 |
this.context = context; |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public ExportAttributes getExportAttributes() { |
|
121 |
return this.exportAttributes; |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public void setExportAttributes(ExportAttributes export) { |
|
126 |
this.exportAttributes = export; |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public ExportParameters clone() throws CloneNotSupportedException { |
|
131 |
ExportParameters clone = (ExportParameters) super.clone(); |
|
132 |
|
|
133 |
if (this.filterExpression != null) { |
|
134 |
clone.setFilterExpresion(this.filterExpression.clone()); |
|
135 |
} |
|
136 |
if (this.featureQuery!=null) { |
|
137 |
clone.setFeatureQuery(this.featureQuery.getCopy()); |
|
138 |
} |
|
139 |
if (this.exportAttributes != null) { |
|
140 |
clone.setExportAttributes(this.exportAttributes.clone()); |
|
141 |
} |
|
142 |
|
|
143 |
return clone; |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public Date getCreationDate() { |
|
148 |
return this.date; |
|
149 |
} |
|
150 |
|
|
151 |
public void setCreationDate(Date date) { |
|
152 |
this.date = date; |
|
153 |
} |
|
154 |
|
|
155 |
@Override |
|
156 |
public String getLabel() { |
|
157 |
StringBuilder builder = new StringBuilder(); |
|
158 |
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); |
|
159 |
String dateName; |
|
160 |
dateName = df.format(this.getCreationDate()); |
|
161 |
builder.append(dateName); |
|
162 |
builder.append(": "); |
|
163 |
|
|
164 |
String serviceName; |
|
165 |
if (this.getServiceName() != null) { |
|
166 |
serviceName = this.getServiceName(); |
|
167 |
} else { |
|
168 |
serviceName = "Null service"; |
|
169 |
} |
|
170 |
builder.append(serviceName); |
|
171 |
|
|
172 |
if (this.getSourceFeatureStore() != null) { |
|
173 |
String storeName = this.getSourceFeatureStore().getName(); |
|
174 |
builder.append(" - "); |
|
175 |
builder.append(storeName); |
|
176 |
} |
|
177 |
|
|
178 |
return builder.toString(); |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public Object getValue() { |
|
183 |
return this; |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public String toString() { |
|
188 |
return this.getLabel(); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public ExportServiceFactory getFactory() { |
|
193 |
return this.factory; |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
public FeatureType getTargetFeatureType() { |
|
198 |
if (this.getExportAttributes() == null) { |
|
199 |
LOGGER.warn("Not been able to get target feature type from export attributes because it's null"); |
|
200 |
return null; |
|
201 |
} |
|
202 |
return this.getExportAttributes().getTargetFeatureType(); |
|
203 |
} |
|
204 |
|
|
205 |
public static void registerPersistence() { |
|
206 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
207 |
if (manager.getDefinition("AbstractExportParameters") == null) { |
|
208 |
DynStruct definition = manager.addDefinition(AbstractExportParameters.class, |
|
209 |
"AbstractExportParameters", "AbstractExportParameters persistence definition", null, null); |
|
210 |
definition.addDynFieldInt("featuresToUse").setMandatory(false); |
|
211 |
definition.addDynFieldObject("filterExpression").setClassOfValue(Expression.class).setMandatory(false); |
|
212 |
definition.addDynFieldObject("exportAttributes").setClassOfValue(ExportAttributes.class).setMandatory(false); |
|
213 |
definition.addDynFieldDate("dateCreation").setMandatory(false); |
|
214 |
definition.addDynFieldString("factory"); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
219 |
state.set("featuresToUse", this.featuresToUse); |
|
220 |
state.set("filterExpression", this.filterExpression); |
|
221 |
state.set("exportAttributes", this.exportAttributes); |
|
222 |
state.set("dateCreation", this.date); |
|
223 |
state.set("factory", this.factory.getName()); |
|
224 |
} |
|
225 |
|
|
226 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
227 |
this.featuresToUse = state.getInt("featuresToUse"); |
|
228 |
this.filterExpression = (Expression) state.get("filterExpression"); |
|
229 |
this.exportAttributes = (ExportAttributes) state.get("exportAttributes"); |
|
230 |
this.date = state.getDate("dateCreation"); |
|
231 |
String nameFactory = state.getString("factory"); |
|
232 |
ExportServiceFactory statefactory = ExportLocator.getServiceManager().getServiceFactory(nameFactory); |
|
233 |
this.factory = statefactory; |
|
234 |
} |
|
235 |
|
|
236 |
|
|
237 |
@Override |
|
238 |
public void resetVolatileValues() { |
|
239 |
|
|
240 |
} |
|
241 |
|
|
242 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportParametersFile.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import org.apache.commons.io.FilenameUtils; |
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.gvsig.export.ExportParametersFile; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
8 |
import org.gvsig.tools.ToolsLocator; |
|
9 |
import org.gvsig.tools.dynobject.DynStruct; |
|
10 |
import org.gvsig.tools.folders.FoldersManager; |
|
11 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
12 |
import org.gvsig.tools.persistence.Persistent; |
|
13 |
import org.gvsig.tools.persistence.PersistentState; |
|
14 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
15 |
import org.gvsig.tools.util.HasAFile; |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
* @author jjdelcerro |
|
20 |
*/ |
|
21 |
public abstract class AbstractExportParametersFile |
|
22 |
extends AbstractExportParameters |
|
23 |
implements ExportParametersFile { |
|
24 |
|
|
25 |
public static class ExportParametersFileHelper implements HasAFile, Persistent { |
|
26 |
|
|
27 |
private File file; |
|
28 |
private File evaluatedFile; |
|
29 |
private String fileExtension; // Ej: ".shp" o ".dbf" |
|
30 |
|
|
31 |
public ExportParametersFileHelper() { |
|
32 |
this.fileExtension = ""; |
|
33 |
this.file = null; |
|
34 |
this.evaluatedFile = null; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public File getFile() { |
|
39 |
return this.file; |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public void setFile(File file) { |
|
44 |
this.evaluatedFile = null; |
|
45 |
if (file == null) { |
|
46 |
this.file = null; |
|
47 |
return; |
|
48 |
} |
|
49 |
if (ExpressionUtils.isDynamicFilename(file)) { |
|
50 |
this.file = file; |
|
51 |
return; |
|
52 |
} |
|
53 |
if (file.isAbsolute()) { |
|
54 |
this.file = new File(FilenameUtils.removeExtension(file.getAbsolutePath()) + this.fileExtension); |
|
55 |
return; |
|
56 |
} |
|
57 |
FoldersManager fm = ToolsLocator.getFoldersManager(); |
|
58 |
this.file = new File(fm.getHome(), FilenameUtils.removeExtension(file.getPath()) + this.fileExtension); |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
public File getEvaluatedFile() { |
|
63 |
if (this.file == null) { |
|
64 |
return null; |
|
65 |
} |
|
66 |
if (this.evaluatedFile == null) { |
|
67 |
this.evaluatedFile = ExpressionUtils.evaluateFilename(this.file); |
|
68 |
} |
|
69 |
return this.evaluatedFile; |
|
70 |
} |
|
71 |
public String getFileExtension() { |
|
72 |
return this.fileExtension; |
|
73 |
} |
|
74 |
|
|
75 |
public void setFileExtension(String fileExtension) { |
|
76 |
if( StringUtils.isBlank(fileExtension) ) { |
|
77 |
this.fileExtension = ""; |
|
78 |
return; |
|
79 |
} |
|
80 |
if( fileExtension.startsWith(".") ) { |
|
81 |
this.fileExtension = fileExtension; |
|
82 |
return; |
|
83 |
} |
|
84 |
this.fileExtension = "." + fileExtension; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
89 |
state.set("file", this.file); |
|
90 |
state.set("fileExtension", this.fileExtension); |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
95 |
this.file = state.getFile("file"); |
|
96 |
this.fileExtension = state.getString("fileExtension"); |
|
97 |
this.evaluatedFile = null; |
|
98 |
} |
|
99 |
|
|
100 |
public static void registerPersistence() { |
|
101 |
|
|
102 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
103 |
if (manager.getDefinition("ExportParametersFileHelper") == null) { |
|
104 |
DynStruct definition = manager.addDefinition(ExportParametersFileHelper.class, |
|
105 |
"ExportParametersFileHelper", "ExportParametersFileHelper persistence definition", null, null); |
|
106 |
definition.addDynFieldString("fileExtension"); |
|
107 |
definition.addDynFieldFile("file"); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
void resetVolatileValues() { |
|
112 |
this.evaluatedFile = null; |
|
113 |
} |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
protected ExportParametersFileHelper fileHelper; |
|
118 |
|
|
119 |
public AbstractExportParametersFile(ExportServiceFactory factory) { |
|
120 |
super(factory); |
|
121 |
this.fileHelper = new ExportParametersFileHelper(); |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public File getFile() { |
|
126 |
return this.fileHelper.getFile(); |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public void setFile(File file) { |
|
131 |
this.fileHelper.setFile(file); |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public File getEvaluatedFile() { |
|
136 |
return this.fileHelper.getEvaluatedFile(); |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
@Override |
|
141 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
142 |
super.saveToState(state); |
|
143 |
state.set("fileHelper", this.fileHelper); |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
148 |
super.loadFromState(state); |
|
149 |
this.fileHelper = (ExportParametersFileHelper) state.get("fileHelper"); |
|
150 |
} |
|
151 |
|
|
152 |
public static void registerPersistence() { |
|
153 |
|
|
154 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
155 |
if (manager.getDefinition("AbstractExportParametersFile") == null) { |
|
156 |
DynStruct definition = manager.addDefinition(AbstractExportParametersFile.class, |
|
157 |
"AbstractExportParametersFile", "AbstractExportParametersFile persistence definition", null, null); |
|
158 |
definition.addDynFieldObject("fileHelper"); |
|
159 |
definition.extend(manager.getDefinition("AbstractExportParameters")); |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
public final String getFileExtension() { |
|
164 |
return this.fileHelper.getFileExtension(); |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public void resetVolatileValues() { |
|
169 |
this.fileHelper.resetVolatileValues(); |
|
170 |
} |
|
171 |
|
|
172 |
|
|
173 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/ExportServiceFactory.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import org.gvsig.export.ExportParameters; |
|
4 |
|
|
5 |
/** |
|
6 |
* |
|
7 |
* @author jjdelcerro |
|
8 |
*/ |
|
9 |
public interface ExportServiceFactory { |
|
10 |
|
|
11 |
public String getName(); |
|
12 |
|
|
13 |
public String getLabel(); |
|
14 |
|
|
15 |
public String getDescription(); |
|
16 |
|
|
17 |
public ExportService createService(ExportParameters parameters); |
|
18 |
|
|
19 |
public ExportParameters createParameters(); |
|
20 |
|
|
21 |
public void setEnabled(boolean enabled); |
|
22 |
|
|
23 |
public boolean isEnabled(); |
|
24 |
|
|
25 |
public boolean hasTabularSupport(); |
|
26 |
|
|
27 |
public boolean hasVectorialSupport(); |
|
28 |
|
|
29 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/ExportGeometryHelper.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
4 |
import org.gvsig.fmap.dal.feature.Feature; |
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
* @author jjdelcerro |
|
9 |
*/ |
|
10 |
public interface ExportGeometryHelper { |
|
11 |
|
|
12 |
boolean canProcessGeometry(); |
|
13 |
|
|
14 |
int copyGeometry(Feature sourceFeature, EditableFeature targetFeature); |
|
15 |
|
|
16 |
String getLastErrorMessage(); |
|
17 |
|
|
18 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/ExportServiceManager.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import org.cresques.cts.ICoordTrans; |
|
5 |
import org.gvsig.export.ExportAttributes; |
|
6 |
import org.gvsig.export.ExportParameters; |
|
7 |
import org.gvsig.export.ExportParametersGeometry; |
|
8 |
import org.gvsig.export.Filter; |
|
9 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
10 |
import org.gvsig.fmap.geom.Geometry; |
|
11 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
|
12 |
import org.gvsig.tools.bookmarksandhistory.History; |
|
13 |
|
|
14 |
/** |
|
15 |
* |
|
16 |
* @author jjdelcerro |
|
17 |
*/ |
|
18 |
public interface ExportServiceManager { |
|
19 |
|
|
20 |
public interface FixGeometryStatus { |
|
21 |
public static final int STATE_OK = 0; |
|
22 |
public static final int STATE_SKIP = 1; |
|
23 |
public static final int STATE_ABORT = 2; |
|
24 |
|
|
25 |
public Geometry getGeometry(); |
|
26 |
public int getState(); |
|
27 |
public String getMessage(); |
|
28 |
} |
|
29 |
|
|
30 |
public List<ExportServiceFactory> getAllServiceFactories(); |
|
31 |
|
|
32 |
public List<ExportServiceFactory> getServiceFactories(Filter<ExportServiceFactory> filter); |
|
33 |
|
|
34 |
public ExportServiceFactory getServiceFactory(String name); |
|
35 |
|
|
36 |
public ExportService createService(ExportParameters paramaters); |
|
37 |
|
|
38 |
public ExportParameters createServiceParameters(String name); |
|
39 |
|
|
40 |
public void register(ExportServiceFactory factory); |
|
41 |
|
|
42 |
public FixGeometryStatus fixGeometry( |
|
43 |
ExportParametersGeometry parameters, |
|
44 |
ICoordTrans coord_trans, |
|
45 |
Geometry geometry |
|
46 |
); |
|
47 |
|
|
48 |
public ExportGeometryHelper createGeometryHelper( |
|
49 |
ExportParametersGeometry parameters, |
|
50 |
FeatureType theTargetFeatureType, |
|
51 |
FeatureType theSourceFeatureType |
|
52 |
); |
|
53 |
|
|
54 |
public ExportAttributes createExportAttributes(); |
|
55 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportServiceFactory.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
import org.gvsig.tools.ToolsLocator; |
|
6 |
import org.gvsig.tools.i18n.I18nManager; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author jjdelcerro |
|
11 |
*/ |
|
12 |
public abstract class AbstractExportServiceFactory implements ExportServiceFactory { |
|
13 |
|
|
14 |
private final String name; |
|
15 |
private final String description; |
|
16 |
|
|
17 |
private static final Map<ExportServiceFactory, Boolean>serviceEnabled = new HashMap<>(); |
|
18 |
private final String label; |
|
19 |
|
|
20 |
public AbstractExportServiceFactory( |
|
21 |
String name, |
|
22 |
String label, |
|
23 |
String description |
|
24 |
) { |
|
25 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
26 |
this.name = name; |
|
27 |
this.label = i18n.getTranslation(label); |
|
28 |
this.description = i18n.getTranslation(description); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public String getName() { |
|
33 |
return name; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public String getLabel() { |
|
38 |
return label; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public String getDescription() { |
|
43 |
return description; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public boolean isEnabled() { |
|
48 |
Boolean enabled = serviceEnabled.getOrDefault(this, true); |
|
49 |
return enabled; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public void setEnabled(boolean value) { |
|
54 |
serviceEnabled.put(this, value); |
|
55 |
} |
|
56 |
|
|
57 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/ExportService.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.export.spi; |
|
25 |
|
|
26 |
import java.util.List; |
|
27 |
import org.gvsig.export.ExportException; |
|
28 |
import org.gvsig.export.ExportParameters; |
|
29 |
import org.gvsig.fmap.dal.OpenDataStoreParameters; |
|
30 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
31 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
32 |
import org.gvsig.tools.task.MonitorableTask; |
|
33 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
34 |
|
|
35 |
/** |
|
36 |
* <p> |
|
37 |
* This service is used to export a source {@link FeatureStore} to a target |
|
38 |
* {@link FeatureStore}. |
|
39 |
* </p> |
|
40 |
* <p> |
|
41 |
* It inherits if {@link MonitorableTask}, and it means that the export process |
|
42 |
* can be monitorized by one or more observers that can listen all the export |
|
43 |
* events. |
|
44 |
* <p> |
|
45 |
* |
|
46 |
* @author gvSIG team |
|
47 |
* @version $Id$ |
|
48 |
*/ |
|
49 |
public interface ExportService extends MonitorableTask { |
|
50 |
|
|
51 |
public interface ExportFinishListener { |
|
52 |
|
|
53 |
public void cancelled(ExportService exportService); |
|
54 |
|
|
55 |
public void finished(ExportService exportService); |
|
56 |
} |
|
57 |
|
|
58 |
public ExportServiceFactory getFactory(); |
|
59 |
|
|
60 |
public ExportParameters getParameters() ; |
|
61 |
|
|
62 |
public void addFinishListener(ExportFinishListener listener); |
|
63 |
|
|
64 |
// public AttributeNamesTranslator getAttributeNamesTranslator(); |
|
65 |
|
|
66 |
public void export(FeatureSet featureSet) throws ExportException; |
|
67 |
|
|
68 |
public List<OpenDataStoreParameters> getTargetOpenStoreParameters() throws ExportException; |
|
69 |
|
|
70 |
public void setTaskStatus(SimpleTaskStatus taskStatus); |
|
71 |
|
|
72 |
} |
|
0 | 73 |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportParametersGeometry.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.export.spi; |
|
7 |
|
|
8 |
import org.cresques.cts.ICoordTrans; |
|
9 |
import org.cresques.cts.IProjection; |
|
10 |
import org.gvsig.export.ExportParameters; |
|
11 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
12 |
import org.gvsig.fmap.geom.GeometryManager; |
|
13 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
14 |
import org.gvsig.export.ExportParametersGeometry; |
|
15 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
16 |
import org.gvsig.fmap.geom.Geometry; |
|
17 |
import org.gvsig.tools.ToolsLocator; |
|
18 |
import org.gvsig.tools.dynobject.DynStruct; |
|
19 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
20 |
import org.gvsig.tools.persistence.PersistentState; |
|
21 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
22 |
|
|
23 |
/** |
|
24 |
* |
|
25 |
* @author jjdelcerro |
|
26 |
*/ |
|
27 |
public abstract class AbstractExportParametersGeometry |
|
28 |
extends AbstractExportParameters |
|
29 |
implements ExportParametersGeometry { |
|
30 |
|
|
31 |
private IProjection contextProjection; |
|
32 |
private IProjection sourceProjection; |
|
33 |
private IProjection targetProjection; |
|
34 |
|
|
35 |
private ICoordTrans sourceTransformation; |
|
36 |
private ICoordTrans targetTransformation; |
|
37 |
|
|
38 |
private int geometryChecks; |
|
39 |
private int geometryChecksAction; |
|
40 |
private boolean tryToFixGeometry; |
|
41 |
private String geometryFieldName; |
|
42 |
private int geometryType; |
|
43 |
private int geometrySubtype; |
|
44 |
|
|
45 |
public AbstractExportParametersGeometry(ExportServiceFactory factory) { |
|
46 |
super(factory); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public boolean needsSelectTargetProjection() { |
|
51 |
return true; |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void setContextProjection(IProjection projection) { |
|
56 |
this.contextProjection = projection; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public IProjection getContextProjection() { |
|
61 |
return this.contextProjection; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public void setSourceProjection(IProjection sourceProjection) { |
|
66 |
this.sourceProjection = sourceProjection; |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public IProjection getSourceProjection() { |
|
71 |
return sourceProjection; |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public ICoordTrans getSourceTransformation() { |
|
76 |
return sourceTransformation; |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public void setSourceTransformation(ICoordTrans contextTransformation) { |
|
81 |
this.sourceTransformation = contextTransformation; |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public void setTargetProjection(IProjection targetProjection) { |
|
86 |
this.targetProjection = targetProjection; |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public IProjection getTargetProjection() { |
|
91 |
if (this.targetProjection == null) { |
|
92 |
return this.sourceProjection; |
|
93 |
} |
|
94 |
return this.targetProjection; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public void setTargetTransformation(ICoordTrans transformation) { |
|
99 |
this.targetTransformation = transformation; |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public ICoordTrans getTargetTransformation() { |
|
104 |
return targetTransformation; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public int getGeometryChecks() { |
|
109 |
return this.geometryChecks; |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public int getGeometryChecksAction() { |
|
114 |
return this.geometryChecksAction; |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public boolean getTryToFixGeometry() { |
|
119 |
return this.tryToFixGeometry; |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public void setGeometryChecks(int geometryChecks) { |
|
124 |
this.geometryChecks = geometryChecks; |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public void setGeometryChecksAction(int geometryChecksAction) { |
|
129 |
this.geometryChecksAction = geometryChecksAction; |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public void setTryToFixGeometry(boolean tryToFixGeometry) { |
|
134 |
this.tryToFixGeometry = tryToFixGeometry; |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public String getSourceGeometryFieldName() { |
|
139 |
return this.geometryFieldName; |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public void setSourceGeometryFieldName(String geometryFieldName) { |
|
144 |
this.geometryFieldName = geometryFieldName; |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public int getTargetGeometryTypeAsInt() { |
|
149 |
return geometryType; |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public int getTargetGeometrySubtype() { |
|
154 |
return geometrySubtype; |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public void setTargetGeometryType(int geometryType) { |
|
159 |
this.geometryType = geometryType; |
|
160 |
} |
|
161 |
|
|
162 |
@Override |
|
163 |
public void setTargetGeometrySubtype(int subtype) { |
|
164 |
this.geometrySubtype = subtype; |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public void setTargetGeometryType(GeometryType type) { |
|
169 |
this.geometryType = type.getType(); |
|
170 |
this.geometrySubtype = type.getSubType(); |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public GeometryType getTargetGeometryType() { |
|
175 |
try { |
|
176 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
177 |
GeometryType type = geomManager.getGeometryType( |
|
178 |
geometryType, |
|
179 |
geometrySubtype |
|
180 |
); |
|
181 |
return type; |
|
182 |
} catch (Exception ex) { |
|
183 |
throw new RuntimeException("Can't create geoemtry type from type " + geometryType + ", subtype " + geometrySubtype + ".", ex); |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public ExportParameters clone() throws CloneNotSupportedException { |
|
189 |
AbstractExportParametersGeometry clone = (AbstractExportParametersGeometry) super.clone(); |
|
190 |
clone.setContextProjection(this.contextProjection); |
|
191 |
clone.setSourceProjection(this.sourceProjection); |
|
192 |
clone.setTargetProjection(this.targetProjection); |
|
193 |
clone.setSourceTransformation(this.sourceTransformation); |
|
194 |
clone.setTargetTransformation(this.targetTransformation); |
|
195 |
clone.setSourceGeometryFieldName(this.geometryFieldName); |
|
196 |
clone.setGeometryChecks(this.geometryChecks); |
|
197 |
clone.setGeometryChecksAction(this.geometryChecksAction); |
|
198 |
clone.setTryToFixGeometry(this.tryToFixGeometry); |
|
199 |
clone.setTargetGeometryType(this.geometryType); |
|
200 |
clone.setTargetGeometrySubtype(this.geometrySubtype); |
|
201 |
return clone; |
|
202 |
} |
|
203 |
|
|
204 |
public static void registerPersistence() { |
|
205 |
|
|
206 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
207 |
if (manager.getDefinition("AbstractExportParametersGeometry") == null) { |
|
208 |
DynStruct definition = manager.addDefinition(AbstractExportParametersGeometry.class, |
|
209 |
"AbstractExportParametersGeometry", "AbstractExportParametersGeometry persistence definition", null, null); |
|
210 |
definition.addDynFieldObject("contextProjection").setClassOfValue(IProjection.class); |
|
211 |
definition.addDynFieldObject("sourceProjection").setClassOfValue(IProjection.class); |
|
212 |
definition.addDynFieldObject("targetProjection").setClassOfValue(IProjection.class); |
|
213 |
definition.addDynFieldObject("sourceTransformation").setClassOfValue(ICoordTrans.class); |
|
214 |
definition.addDynFieldObject("targetTransformation").setClassOfValue(ICoordTrans.class); |
|
215 |
definition.addDynFieldInt("geometryChecks"); |
|
216 |
definition.addDynFieldInt("geometryChecksAction"); |
|
217 |
definition.addDynFieldBoolean("tryToFixGeometry"); |
|
218 |
definition.addDynFieldString("geometryFieldName"); |
|
219 |
definition.addDynFieldInt("geometryType"); |
|
220 |
definition.addDynFieldInt("geometrySubtype"); |
|
221 |
definition.extend(manager.getDefinition("AbstractExportParameters")); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
226 |
super.saveToState(state); |
|
227 |
state.set("contextProjection", this.contextProjection); |
|
228 |
state.set("sourceProjection", this.sourceProjection); |
|
229 |
state.set("targetProjection", this.targetProjection); |
|
230 |
state.set("sourceTransformation", this.sourceTransformation); |
|
231 |
state.set("targetTransformation", this.targetTransformation); |
|
232 |
state.set("geometryChecks", this.geometryChecks); |
|
233 |
state.set("geometryChecksAction", this.geometryChecksAction); |
|
234 |
state.set("tryToFixGeometry", this.tryToFixGeometry); |
|
235 |
state.set("geometryFieldName", this.geometryFieldName); |
|
236 |
state.set("geometryType", this.geometryType); |
|
237 |
state.set("geometrySubtype", this.geometrySubtype); |
|
238 |
} |
|
239 |
|
|
240 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
241 |
super.loadFromState(state); |
|
242 |
this.contextProjection = (IProjection) state.get("contextProjection"); |
|
243 |
this.sourceProjection = (IProjection) state.get("sourceProjection"); |
|
244 |
this.targetProjection = (IProjection) state.get("targetProjection"); |
|
245 |
this.sourceTransformation = (ICoordTrans) state.get("sourceTransformation"); |
|
246 |
this.targetTransformation = (ICoordTrans) state.get("targetTransformation"); |
|
247 |
this.geometryChecks = state.getInt("geometryChecks"); |
|
248 |
this.geometryChecksAction = state.getInt("geometryChecksAction"); |
|
249 |
this.tryToFixGeometry = state.getBoolean("tryToFixGeometry"); |
|
250 |
this.geometryFieldName = state.getString("geometryFieldName"); |
|
251 |
this.geometryType = state.getInt("geometryType"); |
|
252 |
this.geometrySubtype = state.getInt("geometrySubtype"); |
|
253 |
} |
|
254 |
|
|
255 |
@Override |
|
256 |
public ICoordTrans getTransformationToUse() { |
|
257 |
FeatureAttributeDescriptor geo_att = this.getSourceFeatureType().getDefaultGeometryAttribute(); |
|
258 |
|
|
259 |
IProjection sourceProjection; |
|
260 |
ICoordTrans coord_trans = null; |
|
261 |
Geometry reproj_geom; |
|
262 |
IProjection targetProjection = this.getTargetProjection(); |
|
263 |
if (geo_att != null) { |
|
264 |
sourceProjection = geo_att.getSRS(); |
|
265 |
// this comparison is perhaps too preventive |
|
266 |
// we could have two instances of same projection |
|
267 |
// so we would do more computations than needed |
|
268 |
if (sourceProjection != null && targetProjection != null && sourceProjection != targetProjection) { |
|
269 |
if (this.getTargetTransformation() != null) { |
|
270 |
coord_trans = this.getTargetTransformation(); |
|
271 |
} else { |
|
272 |
coord_trans = sourceProjection.getCT(targetProjection); |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
} |
|
277 |
return coord_trans; |
|
278 |
} |
|
279 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportParametersGeometryFile.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import org.gvsig.export.ExportParametersFile; |
|
5 |
import org.gvsig.export.spi.AbstractExportParametersFile.ExportParametersFileHelper; |
|
6 |
import org.gvsig.tools.ToolsLocator; |
|
7 |
import org.gvsig.tools.dynobject.DynStruct; |
|
8 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
9 |
import org.gvsig.tools.persistence.PersistentState; |
|
10 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
*/ |
|
16 |
public abstract class AbstractExportParametersGeometryFile |
|
17 |
extends AbstractExportParametersGeometry |
|
18 |
implements ExportParametersFile |
|
19 |
{ |
|
20 |
protected AbstractExportParametersFile.ExportParametersFileHelper fileHelper; |
|
21 |
|
|
22 |
public AbstractExportParametersGeometryFile(ExportServiceFactory factory) { |
|
23 |
super(factory); |
|
24 |
this.fileHelper = new ExportParametersFileHelper(); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public File getFile() { |
|
29 |
return this.fileHelper.getFile(); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void setFile(File file) { |
|
34 |
this.fileHelper.setFile(file); |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public File getEvaluatedFile() { |
|
39 |
return this.fileHelper.getEvaluatedFile(); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
44 |
super.saveToState(state); |
|
45 |
state.set("fileHelper", this.fileHelper); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
50 |
super.loadFromState(state); |
|
51 |
this.fileHelper = (ExportParametersFileHelper) state.get("fileHelper"); |
|
52 |
} |
|
53 |
|
|
54 |
public static void registerPersistence() { |
|
55 |
|
|
56 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
57 |
if (manager.getDefinition("AbstractExportParametersGeometryFile") == null) { |
|
58 |
DynStruct definition = manager.addDefinition(AbstractExportParametersGeometryFile.class, |
|
59 |
"AbstractExportParametersGeometryFile", "AbstractExportParametersGeometryFile persistence definition", null, null); |
|
60 |
definition.addDynFieldObject("fileHelper"); |
|
61 |
definition.extend(manager.getDefinition("AbstractExportParametersGeometry")); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public final String getFileExtension() { |
|
67 |
return this.fileHelper.getFileExtension(); |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
@Override |
|
72 |
public void resetVolatileValues() { |
|
73 |
this.fileHelper.resetVolatileValues(); |
|
74 |
} |
|
75 |
|
|
76 |
} |
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/spi/AbstractExportService.java | ||
---|---|---|
1 |
package org.gvsig.export.spi; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashSet; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Set; |
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.gvsig.export.ExportAttributes; |
|
9 |
import org.gvsig.export.ExportException; |
|
10 |
import org.gvsig.export.ExportLocator; |
|
11 |
import org.gvsig.export.ExportParameters; |
|
12 |
import org.gvsig.export.ExportParametersGeometry; |
|
13 |
import org.gvsig.export.spi.ExportServiceManager.FixGeometryStatus; |
|
14 |
import org.gvsig.fmap.dal.DALLocator; |
|
15 |
import org.gvsig.fmap.dal.DataManager; |
|
16 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
17 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
18 |
import org.gvsig.fmap.dal.OpenDataStoreParameters; |
|
19 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
20 |
import org.gvsig.fmap.dal.feature.Feature; |
|
21 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
22 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
23 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
24 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
25 |
import org.gvsig.tools.ToolsLocator; |
|
26 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
27 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
28 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
29 |
import org.slf4j.Logger; |
|
30 |
import org.slf4j.LoggerFactory; |
|
31 |
|
|
32 |
/** |
|
33 |
* |
|
34 |
* @author jjdelcerro |
|
35 |
*/ |
|
36 |
public abstract class AbstractExportService |
|
37 |
implements ExportService { |
|
38 |
|
|
39 |
protected static final Logger LOG = LoggerFactory.getLogger(AbstractExportService.class); |
|
40 |
|
|
41 |
private final ExportParameters parameters; |
|
42 |
private final Set<ExportFinishListener> finishListeners; |
|
43 |
// protected AttributeNamesTranslator attributeNamesTranslator; |
|
44 |
private SimpleTaskStatus taskStatus; |
|
45 |
private final ExportServiceFactory factory; |
|
46 |
|
|
47 |
protected AbstractExportService(ExportServiceFactory factory, ExportParameters parameters) { |
|
48 |
this.factory = factory; |
|
49 |
this.parameters = parameters; |
|
50 |
this.finishListeners = new HashSet<>(); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public ExportParameters getParameters() { |
|
55 |
return this.parameters; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public ExportServiceFactory getFactory() { |
|
60 |
return factory; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public void addFinishListener(ExportFinishListener listener) { |
|
65 |
this.finishListeners.add(listener); |
|
66 |
} |
|
67 |
|
|
68 |
protected void fireFinishedListener() { |
|
69 |
for (ExportFinishListener listener : finishListeners) { |
|
70 |
try { |
|
71 |
listener.finished(this); |
|
72 |
} catch (Exception ex) { |
|
73 |
|
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
protected void fireCancelledListeners() { |
|
79 |
for (ExportFinishListener listener : finishListeners) { |
|
80 |
try { |
|
81 |
listener.cancelled(this); |
|
82 |
} catch (Exception ex) { |
|
83 |
|
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public SimpleTaskStatus getTaskStatus() { |
|
90 |
if (this.taskStatus == null) { |
|
91 |
this.taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Export"); |
|
92 |
} |
|
93 |
return this.taskStatus; |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public void setTaskStatus(SimpleTaskStatus taskStatus) { |
|
98 |
this.taskStatus = taskStatus; |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public boolean isCancellationRequested() { |
|
103 |
return this.getTaskStatus().isCancellationRequested(); |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public void cancelRequest() { |
|
108 |
this.getTaskStatus().cancelRequest(); |
|
109 |
} |
|
110 |
|
|
111 |
// @Override |
|
112 |
// public AttributeNamesTranslator getAttributeNamesTranslator() { |
|
113 |
// if (attributeNamesTranslator == null) { |
|
114 |
// this.attributeNamesTranslator = ExportLocator.getServiceManager().createAttributeNamesTranslator(); |
|
115 |
// } |
|
116 |
// return this.attributeNamesTranslator; |
|
117 |
// } |
|
118 |
@Override |
|
119 |
public List<OpenDataStoreParameters> getTargetOpenStoreParameters() throws ExportException { |
|
120 |
List<OpenDataStoreParameters> r = new ArrayList<>(); |
|
121 |
r.add(this.createTargetOpenStoreParameters()); |
|
122 |
return r; |
|
123 |
} |
|
124 |
|
|
125 |
abstract protected DataServerExplorer createServerExplorer() throws ExportException; |
|
126 |
|
|
127 |
abstract protected NewDataStoreParameters createTargetNewStoreParameters() throws ExportException; |
|
128 |
|
|
129 |
abstract protected OpenDataStoreParameters createTargetOpenStoreParameters() throws ExportException; |
|
130 |
|
|
131 |
protected static class InvalidGeometryException extends ExportException { |
|
132 |
|
|
133 |
public InvalidGeometryException(Feature feature, String checkMessage) { |
|
134 |
super(checkMessage, feature); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public void export(FeatureSet featureSet) throws ExportException { |
|
140 |
DataServerExplorer explorer = createServerExplorer(); |
|
141 |
NewDataStoreParameters newStoreParameters = createTargetNewStoreParameters(); |
|
142 |
OpenDataStoreParameters openStoreParameters = createTargetOpenStoreParameters(); |
|
143 |
|
|
144 |
String providerName = newStoreParameters.getDataStoreName(); |
|
145 |
String explorerName = explorer.getProviderName(); |
|
146 |
|
|
147 |
DisposableIterator it = null; |
|
148 |
FeatureStore target = null; |
|
149 |
EditableFeature targetFeature = null; |
|
150 |
try { |
|
151 |
this.getTaskStatus().setRangeOfValues(0, featureSet.getSize()); |
|
152 |
|
|
153 |
DataManager dataManager = DALLocator.getDataManager(); |
|
154 |
|
|
155 |
dataManager.newStore(explorerName, providerName, newStoreParameters, true); |
|
156 |
target = (FeatureStore) dataManager.openStore(providerName, openStoreParameters); |
|
157 |
|
|
158 |
FeatureType theTargetFeatureType; |
|
159 |
if (this.getParameters().getExportAttributes().isActive()) { |
|
160 |
theTargetFeatureType = this.getParameters().getExportAttributes().getTargetFeatureType(); |
|
161 |
} else { |
|
162 |
theTargetFeatureType = target.getDefaultFeatureType(); |
|
163 |
} |
|
164 |
FeatureType theSourceFeatureType = featureSet.getDefaultFeatureType(); |
|
165 |
|
|
166 |
ExportGeometryHelper geomHelper = null; |
|
167 |
if (this.getParameters() instanceof ExportParametersGeometry) { |
|
168 |
geomHelper = ExportLocator.getServiceManager().createGeometryHelper( |
|
169 |
(ExportParametersGeometry) this.getParameters(), |
|
170 |
theTargetFeatureType, |
|
171 |
theSourceFeatureType |
|
172 |
); |
|
173 |
if (!geomHelper.canProcessGeometry()) { |
|
174 |
geomHelper = null; |
|
175 |
} |
|
176 |
} |
|
177 |
// ============================================ |
|
178 |
|
|
179 |
target.edit(FeatureStore.MODE_APPEND); |
|
180 |
it = featureSet.fastIterator(); |
|
181 |
|
|
182 |
long featureCount = 1; |
|
183 |
while (it.hasNext()) { |
|
184 |
this.getTaskStatus().setCurValue(featureCount); |
|
185 |
|
|
186 |
Feature sourceFeature = (Feature) it.next(); |
|
187 |
targetFeature = target.createNewFeature(true); //theTargetFeatureType, true); |
|
188 |
copyValues(sourceFeature, targetFeature); |
|
189 |
|
|
190 |
if (geomHelper != null) { |
|
191 |
switch (geomHelper.copyGeometry(sourceFeature, targetFeature)) { |
|
192 |
case FixGeometryStatus.STATE_OK: |
|
193 |
break; |
|
194 |
case FixGeometryStatus.STATE_SKIP: |
|
195 |
continue; |
|
196 |
case FixGeometryStatus.STATE_ABORT: |
|
197 |
throw new InvalidGeometryException(targetFeature, geomHelper.getLastErrorMessage()); |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
target.insert(targetFeature); |
|
202 |
|
|
203 |
featureCount++; |
|
204 |
|
|
205 |
if (this.getTaskStatus().isCancellationRequested()) { |
|
206 |
return; |
|
207 |
} |
|
208 |
} |
|
209 |
target.finishEditing(); |
|
210 |
this.getTaskStatus().terminate(); |
|
211 |
this.getTaskStatus().remove(); |
|
212 |
fireFinishedListener(); |
|
213 |
} catch (Exception e) { |
|
214 |
fireCancelledListeners(); |
|
215 |
throw new ExportException(e, targetFeature); |
|
216 |
} finally { |
|
217 |
DisposeUtils.dispose(it); |
|
218 |
DisposeUtils.dispose(featureSet); |
|
219 |
DisposeUtils.dispose(target); |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
protected void copyValues(Feature source, EditableFeature target) { |
|
224 |
FeatureType sourceType = source.getType(); |
|
225 |
FeatureType targetType = target.getType(); |
|
226 |
ExportAttributes exp = this.getParameters().getExportAttributes(); |
|
227 |
boolean isActive = exp.isActive(); |
|
228 |
for (FeatureAttributeDescriptor targetAttr : targetType) { |
|
229 |
if (targetAttr.isReadOnly() || targetAttr.isComputed()) { |
|
230 |
continue; |
|
231 |
} |
|
232 |
String targetAttrName = targetAttr.getName(); |
|
233 |
//translate field |
|
234 |
FeatureAttributeDescriptor sourceAttr; |
|
235 |
String sourceAttrName; |
|
236 |
if (isActive) { |
|
237 |
sourceAttrName = exp.getSourceName(targetAttrName); |
|
238 |
for (ExportAttributes.ExportAttribute exportAttribute : exp) { |
|
239 |
if (StringUtils.equals(exportAttribute.getNewName(), targetAttrName)) { |
|
240 |
sourceAttrName = exportAttribute.getName(); |
|
241 |
break; |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
sourceAttr = sourceType.getAttributeDescriptor(sourceAttrName); |
|
246 |
} else { |
|
247 |
sourceAttrName = targetAttrName; |
|
248 |
sourceAttr = sourceType.getAttributeDescriptor(targetAttrName); |
|
249 |
} |
|
250 |
if (sourceAttr != null) { |
|
251 |
Object value = source.get(sourceAttrName); |
|
252 |
if (value == null) { |
|
253 |
if (targetAttr.allowNull()) { |
|
254 |
target.set(targetAttrName, null); |
|
255 |
} |
|
256 |
} else { |
|
257 |
target.set(targetAttrName, value); |
|
258 |
} |
|
259 |
} else if (sourceAttr==null && source.hasValue(sourceAttrName)) { |
|
260 |
Object value = source.get(sourceAttrName); |
|
261 |
target.set(targetAttrName, value); |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
|
tags/org.gvsig.desktop-2.0.354/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/export/ExportManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.export; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.util.List; |
|
28 |
import org.cresques.cts.IProjection; |
|
29 |
import org.gvsig.export.spi.ExportServiceManager; |
|
30 |
|
|
31 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
32 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
|
33 |
import org.gvsig.tools.bookmarksandhistory.History; |
|
34 |
|
|
35 |
public interface ExportManager { |
|
36 |
|
|
37 |
public interface ExportFilter { |
|
38 |
|
|
39 |
public String getName(); |
|
40 |
|
|
41 |
public String getExpression(); |
|
42 |
} |
|
43 |
|
|
44 |
public void setHomeFolder(File homeFolder); |
|
45 |
|
|
46 |
public ExportProcess createProcess(); |
|
47 |
|
|
48 |
public ExportProcess createProcess(FeatureStore store); |
|
49 |
|
|
50 |
public ExportProcess createProcess(FeatureStore store, IProjection contextProjection); |
|
51 |
|
|
52 |
public List<ExportFilter> getFilters(); |
|
53 |
|
|
54 |
public ExportFilter getFilter(String name); |
Also available in: Unified diff