Search in sources :

Example 1 with OnLineResourceImpl

use of org.geotools.metadata.iso.citation.OnLineResourceImpl in project sldeditor by robward-scisys.

the class UpdateGraphicalSymbol method processGraphicalSymbol.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.data.ProcessGraphicSymbolInterface#processGraphicalSymbol(java.net.URL, java.util.List, java.util.List)
     */
@Override
public void processGraphicalSymbol(URL resourceLocator, List<GraphicalSymbol> graphicalSymbolList, List<String> externalImageList) {
    for (GraphicalSymbol symbol : graphicalSymbolList) {
        if (symbol instanceof ExternalGraphic) {
            ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) symbol;
            OnLineResourceImpl onlineResource = (OnLineResourceImpl) externalGraphic.getOnlineResource();
            String currentValue = null;
            URL currentValueURL = null;
            try {
                currentValueURL = onlineResource.getLinkage().toURL();
                currentValue = currentValueURL.toExternalForm();
            } catch (MalformedURLException e) {
                ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
            }
            if ((resourceLocator == null) || RelativePath.hasHost(currentValueURL)) {
                // Just report back the external image
                URI uri = null;
                try {
                    uri = new URI(currentValue);
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            } else {
                try {
                    File file = new File(currentValueURL.getFile());
                    File folder = new File(resourceLocator.getFile());
                    currentValue = RelativePath.getRelativePath(file, folder);
                    // If the backslashes are not converted to forward slashes
                    // creating the URI does not work
                    currentValue = currentValue.replace('\\', '/');
                    OnLineResourceImpl updatedOnlineResource = new OnLineResourceImpl();
                    URI uri = new URI(currentValue);
                    updatedOnlineResource.setLinkage(uri);
                    externalGraphic.setOnlineResource(updatedOnlineResource);
                    externalGraphic.setURI(uri.toASCIIString());
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GraphicalSymbol(org.opengis.style.GraphicalSymbol) OnLineResourceImpl(org.geotools.metadata.iso.citation.OnLineResourceImpl) URISyntaxException(java.net.URISyntaxException) ExternalGraphic(org.geotools.styling.ExternalGraphic) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Aggregations

File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 OnLineResourceImpl (org.geotools.metadata.iso.citation.OnLineResourceImpl)1 ExternalGraphic (org.geotools.styling.ExternalGraphic)1 ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)1 GraphicalSymbol (org.opengis.style.GraphicalSymbol)1