public static void substituteExternalGraphics( Rule rule, URL externalGraphicsUrl ) {
        String urlString = externalGraphicsUrl.toString();
        String format = "";
        if (urlString.toLowerCase().endsWith(".png")) {
            format = "image/png";
        } else if (urlString.toLowerCase().endsWith(".jpg")) {
            format = "image/jpg";
        } else if (urlString.toLowerCase().endsWith(".svg")) {
            format = "image/svg+xml";
        } else {
            urlString = "";
            try {
                externalGraphicsUrl = new URL("file:");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }

        PointSymbolizer pointSymbolizer = StyleUtilities.pointSymbolizerFromRule(rule);
        Graphic graphic = SLD.graphic(pointSymbolizer);
        graphic.graphicalSymbols().clear();
        ExternalGraphic exGraphic = sf.createExternalGraphic(externalGraphicsUrl, format);

        graphic.graphicalSymbols().add(exGraphic);
    }
public static void substituteExternalGraphics ( Rule rule , URL externalGraphicsUrl ) { String urlString = externalGraphicsUrl . toString ( ) ; String format = "" ; if ( urlString . toLowerCase ( ) . endsWith ( ".png" ) ) { format = "image/png" ; } else if ( urlString . toLowerCase ( ) . endsWith ( ".jpg" ) ) { format = "image/jpg" ; } else if ( urlString . toLowerCase ( ) . endsWith ( ".svg" ) ) { format = "image/svg+xml" ; } else { urlString = "" ; try { externalGraphicsUrl = new URL ( "file:" ) ; } catch ( MalformedURLException e ) { e . printStackTrace ( ) ; } } PointSymbolizer pointSymbolizer = StyleUtilities . pointSymbolizerFromRule ( rule ) ; Graphic graphic = SLD . graphic ( pointSymbolizer ) ; graphic . graphicalSymbols ( ) . clear ( ) ; ExternalGraphic exGraphic = sf . createExternalGraphic ( externalGraphicsUrl , format ) ; graphic . graphicalSymbols ( ) . add ( exGraphic ) ; }
Change the external graphic in a rule.

@param rule the rule of which the external graphic has to be changed.
@param path the path of the image.