// directory
File file = DataUtilities.urlToFile(graphic.getLocation());
File styles = null;
File graphicFile = null;
if(file.isAbsolute()) {
GeoServerDataDirectory dataDir = (GeoServerDataDirectory) GeoServerExtensions.bean("dataDirectory");
// we grab the canonical path to make sure we can compare them, no relative parts in them and so on
styles = dataDir.findOrCreateStyleDir().getCanonicalFile();
graphicFile = file.getCanonicalFile();
file = graphicFile;
if(file.getAbsolutePath().startsWith(styles.getAbsolutePath())) {
// ok, part of the styles directory, extract only the relative path
file = new File(file.getAbsolutePath().substring(styles.getAbsolutePath().length() + 1));