Revision 155 org.gvsig.dxf/trunk/org.gvsig.dxf/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFStoreParameters.java

View differences:

DXFStoreParameters.java
1 1
package org.gvsig.fmap.dal.store.dxf;
2 2

  
3 3
import java.io.File;
4
import java.io.IOException;
4 5

  
6
import org.apache.commons.io.FileUtils;
7
import org.apache.commons.io.FilenameUtils;
8
import org.cresques.cts.ICRSFactory;
5 9
import org.cresques.cts.IProjection;
10

  
11
import org.gvsig.fmap.crs.CRSFactory;
6 12
import org.gvsig.fmap.dal.DALLocator;
7 13
import org.gvsig.fmap.dal.DataManager;
8 14
import org.gvsig.fmap.dal.DataStoreParameters;
......
27 33

  
28 34
	private DelegatedDynObject parameters;
29 35

  
30
	
36

  
31 37
	public DXFStoreParameters() {
32 38
		this(PARAMETERS_DEFINITION_NAME);
33 39
	}
......
89 95

  
90 96
	public void setFile(File file) {
91 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

  
92 107
	}
93 108

  
94 109
	public void setFile(String file) {
95 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

  
96 121
	}
97 122

  
98 123
	public EditableFeatureType getDefaultFeatureType() {
......
106 131
	public void setDefaultFeatureType(FeatureType defaultFeatureType) {
107 132
		throw new UnsupportedOperationException();
108 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
    }
109 147
}

Also available in: Unified diff