svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.shape / src / main / java / org / gvsig / export / shape / service / ExportShapeParametersImpl.java @ 44555
History | View | Annotate | Download (3.84 KB)
1 |
package org.gvsig.export.shape.service; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import org.apache.commons.io.FilenameUtils; |
5 |
import org.gvsig.export.ExportParameters; |
6 |
import org.gvsig.export.dbf.service.ExportDBFService; |
7 |
import org.gvsig.export.spi.AbstractExportParametersGeometry; |
8 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
9 |
import org.gvsig.export.spi.CutAttributeNamesTranslator; |
10 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 |
import org.gvsig.tools.ToolsLocator; |
13 |
import org.gvsig.tools.dynobject.DynStruct; |
14 |
import org.gvsig.tools.folders.FoldersManager; |
15 |
import org.gvsig.tools.persistence.PersistenceManager; |
16 |
import org.gvsig.tools.persistence.PersistentState; |
17 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
18 |
|
19 |
/**
|
20 |
*
|
21 |
* @author jjdelcerro
|
22 |
*/
|
23 |
public class ExportShapeParametersImpl |
24 |
extends AbstractExportParametersGeometry
|
25 |
implements ExportShapeParameters {
|
26 |
|
27 |
private String encoding; |
28 |
private File file; |
29 |
private boolean useSimplifiedExport = true; |
30 |
|
31 |
public ExportShapeParametersImpl(ExportShapeServiceFactory factory) {
|
32 |
super(factory);
|
33 |
AttributeNamesTranslator attr = new CutAttributeNamesTranslator(ExportDBFService.MAX_FIELD_NAME_LENGTH);
|
34 |
this.exportAttributes.setNamesTranslator(attr);
|
35 |
} |
36 |
|
37 |
public ExportShapeParametersImpl() {
|
38 |
super(null); |
39 |
} |
40 |
|
41 |
@Override
|
42 |
public String getServiceName() { |
43 |
return ExportShapeServiceFactory.SERVICE_NAME;
|
44 |
} |
45 |
|
46 |
@Override
|
47 |
public String getEncoding() { |
48 |
return this.encoding; |
49 |
} |
50 |
|
51 |
@Override
|
52 |
public void setEncoding(String encoding) { |
53 |
this.encoding = encoding;
|
54 |
} |
55 |
|
56 |
@Override
|
57 |
public File getFile() { |
58 |
return this.file; |
59 |
} |
60 |
|
61 |
@Override
|
62 |
public void setFile(File file) { |
63 |
if (ExpressionUtils.isDynamicFilename(file)) {
|
64 |
this.file = file;
|
65 |
} else {
|
66 |
if (file.isAbsolute()) {
|
67 |
this.file = new File(FilenameUtils.removeExtension(file.getAbsolutePath()) + ".shp"); |
68 |
} else {
|
69 |
FoldersManager fm = ToolsLocator.getFoldersManager(); |
70 |
this.file = new File(fm.getHome(), file.getPath() + ".shp"); |
71 |
} |
72 |
} |
73 |
} |
74 |
|
75 |
@Override
|
76 |
public boolean getUseSimplifiedExport() { |
77 |
return this.useSimplifiedExport; |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public void setUseSimplifiedExport(boolean useSimplifiedExport) { |
82 |
this.useSimplifiedExport = useSimplifiedExport;
|
83 |
} |
84 |
|
85 |
@Override
|
86 |
public void setSourceFeatureType(FeatureType sourceFeatureType) { |
87 |
super.setSourceFeatureType(sourceFeatureType);
|
88 |
|
89 |
} |
90 |
|
91 |
public static void registerPersistence() { |
92 |
|
93 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
94 |
if (manager.getDefinition("ExportShapeParametersImpl") == null) { |
95 |
DynStruct definition = manager.addDefinition(ExportShapeParametersImpl.class, |
96 |
"ExportShapeParametersImpl", "ExportShapeParametersImpl persistence definition", null, null); |
97 |
definition.addDynFieldString("encoding");
|
98 |
definition.addDynFieldFile("file");
|
99 |
definition.addDynFieldBoolean("useSimplifiedExport");
|
100 |
definition.extend(manager.getDefinition("AbstractExportParametersGeometry"));
|
101 |
} |
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void saveToState(PersistentState state) throws PersistenceException { |
106 |
super.saveToState(state);
|
107 |
state.set("encoding", this.encoding); |
108 |
state.set("file", this.file); |
109 |
state.set("useSimplifiedExport", this.useSimplifiedExport); |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void loadFromState(PersistentState state) throws PersistenceException { |
114 |
super.loadFromState(state);
|
115 |
this.encoding = state.getString("encoding"); |
116 |
this.file = state.getFile("file"); |
117 |
this.useSimplifiedExport = state.getBoolean("useSimplifiedExport"); |
118 |
} |
119 |
|
120 |
} |