// if the point symbolizer uses an external graphic use it
if ((symbolizer.getGraphic() != null)
&& (symbolizer.getGraphic().getExternalGraphics() != null)
&& (symbolizer.getGraphic().getExternalGraphics().length > 0)) {
ExternalGraphic graphic = symbolizer.getGraphic()
.getExternalGraphics()[0];
try {
if ("file".equals(graphic.getLocation().getProtocol())) {
// it is a local file, reference locally from "styles"
// 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));
} else {
// we wont' transform this, other dirs are not published
file = null;
}
}
if (file != null && styles != null) {
iconHref = ResponseUtils.buildURL(mapContext.getRequest().getBaseUrl(),
"styles/" + styles.toURI().relativize(graphicFile.toURI()),
null, URLType.RESOURCE);
}
} else if ("http".equals(graphic.getLocation()
.getProtocol())) {
iconHref = graphic.getLocation().toString();
} else {
// TODO: should we check for http:// and use it
// directly?
// other protocols?
}