Revision 40799 branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/DefaultSLDSupportManager.java

View differences:

DefaultSLDSupportManager.java
20 20
import org.gvsig.sldsupport.exception.SLDReadException;
21 21
import org.gvsig.sldsupport.exception.SLDWriteException;
22 22
import org.gvsig.sldsupport.exception.UnsupportedSLDVersionException;
23
import org.gvsig.sldsupport.impl.util.SLDUtils;
23 24
import org.gvsig.sldsupport.reader.SLDReader;
24 25
import org.gvsig.sldsupport.reader.SLDReaderFactory;
25 26
import org.gvsig.sldsupport.sld.SLDObject;
......
27 28
import org.gvsig.sldsupport.writer.SLDWriterFactory;
28 29
import org.slf4j.Logger;
29 30
import org.slf4j.LoggerFactory;
31
import org.xmlpull.v1.XmlPullParserException;
30 32

  
31 33
public class DefaultSLDSupportManager implements SLDSupportManager {
32 34
	
......
181 183
			throw new IOException("Null or non-existing file: "
182 184
					+ ((infile == null) ? "Null" : infile.getAbsolutePath()));
183 185
		}
186
		
187
		
188
		String ve = null;
189
		try {
190
			ve = SLDUtils.detectVersion(infile);
191
		} catch (XmlPullParserException e) {
192
		}
193
		
194
		System.out.println("Version = " + ve);
195
		
184 196
		InputStream instream = null;
185 197
		Iterator<String> iter = versionToReaders.keySet().iterator();
186 198
		String vitem = null;
......
189 201
		SLDReaderFactory fact_item = null;
190 202
		SLDReader ritem = null;
191 203
		SLDObject resp = null;
204
		boolean found = false;
192 205
		while (iter.hasNext()) {
193 206
			vitem = iter.next();
194 207
			sitem = versionToReaders.get(vitem);
195 208
			siter = sitem.iterator();
196 209
			while (siter.hasNext()) {
210
				
211
				found = true; // Used to decide message in exception
197 212
				fact_item = siter.next();
198 213
				ritem = fact_item.create();
199 214
				instream = new FileInputStream(infile);
200 215
				try {
201 216
					resp = ritem.read(instream);
202 217
				} catch (Exception exc) {
203
					logger.info("One of the readers was unable to parse file: "	+ infile.getAbsolutePath());
218
					logger.info("One of the readers was unable to parse file: "	+ infile.getAbsolutePath(), exc);
204 219
				}
205 220
				try { instream.close(); } catch (Exception exc) { }
206 221
				if (resp != null) {
......
208 223
				}
209 224
			}
210 225
		}
211
		throw new SLDReadException("No SLD readers found.");
226
		if (found) {
227
			throw new SLDReadException(	"No available SLD reader was able to parse file: "
228
					+ infile.getAbsolutePath());
229
		} else {
230
			throw new SLDReadException("No SLD readers found.");
231
		}
232
		
212 233
	}
213 234
	
214 235
//	public static String VERSION = "1.0.0";

Also available in: Unified diff