public static Style getStyleFromFile ( File file ) { Style style = null ; try { String name = file . getName ( ) ; if ( ! name . endsWith ( "sld" ) ) { String nameWithoutExtention = FileUtilities . getNameWithoutExtention ( file ) ; File sldFile = new File ( file . getParentFile ( ) , nameWithoutExtention + ".sld" ) ; if ( sldFile . exists ( ) ) { file = sldFile ; } else { // no style file here return null ; } } SLDHandler h = new SLDHandler ( ) ; StyledLayerDescriptor sld = h . parse ( file , null , null , null ) ; // SLDParser stylereader = new SLDParser(sf, file); // StyledLayerDescriptor sld = stylereader.parseSLD(); style = getDefaultStyle ( sld ) ; return style ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } }
Get the style from an sld file .