root / org.gvsig.dxf / trunk / org.gvsig.dxf / org.gvsig.dxf.provider / src / main / java / org / gvsig / fmap / dal / store / dxf / DXFStoreParameters.java @ 155
History | View | Annotate | Download (4.15 KB)
1 |
package org.gvsig.fmap.dal.store.dxf; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.IOException; |
5 |
|
6 |
import org.apache.commons.io.FileUtils; |
7 |
import org.apache.commons.io.FilenameUtils; |
8 |
import org.cresques.cts.ICRSFactory; |
9 |
import org.cresques.cts.IProjection; |
10 |
|
11 |
import org.gvsig.fmap.crs.CRSFactory; |
12 |
import org.gvsig.fmap.dal.DALLocator; |
13 |
import org.gvsig.fmap.dal.DataManager; |
14 |
import org.gvsig.fmap.dal.DataStoreParameters; |
15 |
import org.gvsig.fmap.dal.FileHelper; |
16 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
17 |
import org.gvsig.fmap.dal.feature.FeatureType; |
18 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
19 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
20 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
21 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
22 |
import org.gvsig.fmap.geom.Geometry; |
23 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
24 |
|
25 |
public class DXFStoreParameters extends AbstractDataParameters implements |
26 |
DataStoreParameters, FilesystemStoreParameters, |
27 |
NewFeatureStoreParameters { |
28 |
|
29 |
public static final String PARAMETERS_DEFINITION_NAME = "DXFStoreParameters"; |
30 |
|
31 |
private static final String FILE_PARAMTER_NAME = "File"; |
32 |
private static final String CRS_PARAMTER_NAME = "CRS"; |
33 |
|
34 |
private DelegatedDynObject parameters;
|
35 |
|
36 |
|
37 |
public DXFStoreParameters() {
|
38 |
this(PARAMETERS_DEFINITION_NAME);
|
39 |
} |
40 |
|
41 |
protected DXFStoreParameters(String parametersDefinitionName) { |
42 |
this(parametersDefinitionName, DXFStoreProvider.NAME);
|
43 |
} |
44 |
|
45 |
public DXFStoreParameters(String parametersDefinitionName, String name) { |
46 |
super();
|
47 |
this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
|
48 |
this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
|
49 |
} |
50 |
|
51 |
public String getDataStoreName() { |
52 |
return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
53 |
} |
54 |
|
55 |
public String getDescription() { |
56 |
return this.getDynClass().getDescription(); |
57 |
} |
58 |
|
59 |
protected DelegatedDynObject getDelegatedDynObject() {
|
60 |
return parameters;
|
61 |
} |
62 |
|
63 |
public void setCRS(String srs) { |
64 |
setDynValue(CRS_PARAMTER_NAME, srs); |
65 |
} |
66 |
|
67 |
public void setCRS(IProjection srs) { |
68 |
setDynValue(CRS_PARAMTER_NAME, srs); |
69 |
} |
70 |
|
71 |
public IProjection getCRS() {
|
72 |
return (IProjection) getDynValue(CRS_PARAMTER_NAME);
|
73 |
} |
74 |
|
75 |
public String getFileName() { |
76 |
if( this.getFile() == null ) { |
77 |
return null; |
78 |
} |
79 |
return this.getFile().getPath(); |
80 |
} |
81 |
|
82 |
public boolean isValid() { |
83 |
if (getCRS() == null ) { |
84 |
return false; |
85 |
} |
86 |
if (getFileName() == null) { |
87 |
return false; |
88 |
} |
89 |
return true; |
90 |
} |
91 |
|
92 |
public File getFile() { |
93 |
return (File) this.getDynValue(FILE_PARAMTER_NAME); |
94 |
} |
95 |
|
96 |
public void setFile(File file) { |
97 |
this.setDynValue(FILE_PARAMTER_NAME, file);
|
98 |
|
99 |
if (getCRS() == null){ |
100 |
String wktEsri = loadPrj(file);
|
101 |
if (wktEsri != null) { |
102 |
IProjection proj = CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, wktEsri); |
103 |
setCRS(proj); |
104 |
} |
105 |
} |
106 |
|
107 |
} |
108 |
|
109 |
public void setFile(String file) { |
110 |
this.setDynValue(FILE_PARAMTER_NAME, file);
|
111 |
|
112 |
File dxfFile = (File) this.getDynValue(FILE_PARAMTER_NAME); |
113 |
if (getCRS() == null){ |
114 |
String wktEsri = loadPrj(dxfFile);
|
115 |
if (wktEsri != null) { |
116 |
IProjection proj = CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, wktEsri); |
117 |
setCRS(proj); |
118 |
} |
119 |
} |
120 |
|
121 |
} |
122 |
|
123 |
public EditableFeatureType getDefaultFeatureType() {
|
124 |
// FIXME: Esto no se si funciona.
|
125 |
DataManager manager = DALLocator.getDataManager(); |
126 |
EditableFeatureType featureType = manager.createFeatureType(); |
127 |
DXFStoreProvider.initializeFeatureType(featureType, null, Geometry.SUBTYPES.GEOM3D);
|
128 |
return featureType;
|
129 |
} |
130 |
|
131 |
public void setDefaultFeatureType(FeatureType defaultFeatureType) { |
132 |
throw new UnsupportedOperationException(); |
133 |
} |
134 |
|
135 |
|
136 |
private String loadPrj(File dxfFile){ |
137 |
File prjFile = new File(FilenameUtils.removeExtension(dxfFile.getAbsolutePath())+".prj"); |
138 |
if (prjFile.exists()) {
|
139 |
try {
|
140 |
return FileUtils.readFileToString(prjFile);
|
141 |
} catch (IOException e) { |
142 |
return null; |
143 |
} |
144 |
} |
145 |
return null; |
146 |
} |
147 |
} |