Revision 45775 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVStoreParameters.java
CSVStoreParameters.java | ||
---|---|---|
35 | 35 |
import org.gvsig.basicformats.PRJFile; |
36 | 36 |
import org.gvsig.fmap.dal.DALLocator; |
37 | 37 |
import org.gvsig.fmap.dal.FileHelper; |
38 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
38 | 39 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
39 | 40 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
40 | 41 |
import org.gvsig.fmap.dal.feature.FeatureType; |
... | ... | |
131 | 132 |
@Override |
132 | 133 |
public void setDynValue(String name, Object value) { |
133 | 134 |
super.setDynValue(name, value); |
134 |
if( StringUtils.equalsIgnoreCase(name, FILE)) { |
|
135 |
File f = this.getFile(); |
|
136 |
if( f!=null ) { |
|
137 |
IProjection proj = null; |
|
138 |
FeatureType ftype = this.getFeatureType(); |
|
139 |
if( ftype!=null ) { |
|
140 |
this.setDynValue(AUTOMATICTYPESDETECTION, defaultValueOfAutomaticTypesDetection); |
|
141 |
proj = ftype.getDefaultSRS(); |
|
142 |
if( proj!=null ) { |
|
143 |
this.setDynValue(CRS_PARAMTER_NAME, proj); |
|
144 |
} |
|
145 |
FeatureAttributeDescriptor attrgeom = ftype.getDefaultGeometryAttribute(); |
|
146 |
if( attrgeom!=null ) { |
|
147 |
this.setDynValue(GEOMETRY_COLUMN, attrgeom.getName()); |
|
148 |
this.setDynValue(GEOMETRY_TYPE, attrgeom.getGeomType().getType()); |
|
149 |
this.setDynValue(GEOMETRY_SUBTYPE, attrgeom.getGeomType().getSubType()); |
|
150 |
} else { |
|
151 |
this.setDynValue(GEOMETRY_COLUMN, null); |
|
152 |
this.setDynValue(GEOMETRY_TYPE, Geometry.TYPES.UNKNOWN); |
|
153 |
this.setDynValue(GEOMETRY_SUBTYPE, Geometry.SUBTYPES.UNKNOWN); |
|
154 |
} |
|
155 |
Tags ftypeTags = ftype.getTags(); |
|
156 |
for (String tagname : ftypeTags) { |
|
157 |
if( StringUtils.startsWithIgnoreCase(tagname, "csvparameters.") ) { |
|
158 |
String paramname = tagname.substring(15); |
|
159 |
String paramvalue = ftypeTags.getString(tagname,null); |
|
160 |
if( paramvalue!=null ) { |
|
161 |
this.setDynValue(paramname, paramvalue); |
|
162 |
} |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public void validate() throws ValidateDataParametersException { |
|
139 |
File f = this.getFile(); |
|
140 |
if( f!=null ) { |
|
141 |
IProjection proj = null; |
|
142 |
FeatureType ftype = this.getFeatureType(); |
|
143 |
if( ftype!=null ) { |
|
144 |
this.setDynValue(AUTOMATICTYPESDETECTION, defaultValueOfAutomaticTypesDetection); |
|
145 |
proj = ftype.getDefaultSRS(); |
|
146 |
if( proj!=null ) { |
|
147 |
this.setDynValue(CRS_PARAMTER_NAME, proj); |
|
148 |
} |
|
149 |
FeatureAttributeDescriptor attrgeom = ftype.getDefaultGeometryAttribute(); |
|
150 |
if( attrgeom!=null ) { |
|
151 |
this.setDynValue(GEOMETRY_COLUMN, attrgeom.getName()); |
|
152 |
this.setDynValue(GEOMETRY_TYPE, attrgeom.getGeomType().getType()); |
|
153 |
this.setDynValue(GEOMETRY_SUBTYPE, attrgeom.getGeomType().getSubType()); |
|
154 |
} else { |
|
155 |
this.setDynValue(GEOMETRY_COLUMN, null); |
|
156 |
this.setDynValue(GEOMETRY_TYPE, Geometry.TYPES.UNKNOWN); |
|
157 |
this.setDynValue(GEOMETRY_SUBTYPE, Geometry.SUBTYPES.UNKNOWN); |
|
158 |
} |
|
159 |
Tags ftypeTags = ftype.getTags(); |
|
160 |
for (String tagname : ftypeTags) { |
|
161 |
if( StringUtils.startsWithIgnoreCase(tagname, "csvparameters.") ) { |
|
162 |
String paramname = tagname.substring(15); |
|
163 |
String paramvalue = ftypeTags.getString(tagname,null); |
|
164 |
if( paramvalue!=null ) { |
|
165 |
this.setDynValue(paramname, paramvalue); |
|
163 | 166 |
} |
164 | 167 |
} |
165 | 168 |
} |
166 |
if( proj==null ) {
|
|
167 |
PRJFile prjfile = FormatsFile.getPRJFile(f);
|
|
168 |
if( prjfile!= null ) {
|
|
169 |
this.setDynValue(CRS_PARAMTER_NAME, prjfile.getCRS());
|
|
170 |
}
|
|
169 |
}
|
|
170 |
if( proj==null ) {
|
|
171 |
PRJFile prjfile = FormatsFile.getPRJFile(f);
|
|
172 |
if( prjfile!= null ) {
|
|
173 |
this.setDynValue(CRS_PARAMTER_NAME, prjfile.getCRS());
|
|
171 | 174 |
} |
172 |
String charsetName = getCharset(this);
|
|
173 |
if( StringUtils.isBlank(charsetName) ) {
|
|
174 |
CPGFile cpgfile = FormatsFile.getCPGFile(f);
|
|
175 |
if( cpgfile!=null ) {
|
|
176 |
this.setDynValue(CHARSET, cpgfile.getCharsetName());
|
|
177 |
}
|
|
175 |
}
|
|
176 |
String charsetName = getCharset(this);
|
|
177 |
if( StringUtils.isBlank(charsetName) ) {
|
|
178 |
CPGFile cpgfile = FormatsFile.getCPGFile(f);
|
|
179 |
if( cpgfile!=null ) {
|
|
180 |
this.setDynValue(CHARSET, cpgfile.getCharsetName());
|
|
178 | 181 |
} |
179 | 182 |
} |
180 | 183 |
} |
184 |
super.validate(); |
|
181 | 185 |
} |
182 |
|
|
186 |
|
|
183 | 187 |
@Override |
184 | 188 |
public boolean isValid() { |
185 | 189 |
if ( getFileName(this) == null ) { |
Also available in: Unified diff