StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
// try SLD 1.1 first
SLDConfiguration config = new SLDConfiguration();
Reader reader = null;
try {
Parser parser = new Parser( config );
reader = new FileReader(file);
Object object = parser.parse( reader );
if( object instanceof StyledLayerDescriptor){
StyledLayerDescriptor sld = (StyledLayerDescriptor) object;
Style[] array = SLDs.styles( sld );
if( array != null && array.length > 0 ){
return array[0];
}
}
else if ( object instanceof NamedStyle ){
NamedStyle style = (NamedStyle) object;
return style;
}
}
catch(Exception ignore){
// we are ignoring this error and will try the more forgiving option below
UiPlugin.trace(SLDs.class,"SLD 1.1 configuration failed to parse "+file, ignore);
}
finally {
if( reader != null){
reader.close();
}
}
// parse it up
SLDParser parser = new SLDParser(styleFactory);
try {
parser.setInput(file);
Style[] array = parser.readXML();
if( array != null && array.length > 0 ){
return array[0];
}
} catch (FileNotFoundException e) {
return null; // well that is unexpected since f.exists()