/** * Retrieve the StyleInfo as a GeoTools Style object. Note this is just the data structure as * written, the matching external graphics are unmodified and may not be (yet) available on the * local system. * * @param s The style * @return A {@link Resource} */ protected @Nonnull Style parsedStyleResources(StyleInfo s) throws IOException { final Resource styleResource = style(s); if (styleResource.getType() == Type.UNDEFINED) { throw new FileNotFoundException("No such resource: " + s.getFilename()); } final DefaultResourceLocator locator = new ResourceAwareResourceLocator(); locator.setSourceUrl(Resources.toURL(styleResource)); StyledLayerDescriptor sld = Styles.handler(s.getFormat()) .parse(styleResource, s.getFormatVersion(), locator, null); final Style style = Styles.style(sld); assert style != null; return style; }
Parser createSld11Parser( Object input, ResourceLocator resourceLocator, EntityResolver entityResolver) { if (resourceLocator == null && input instanceof File) { // setup for resolution of relative paths final java.net.URL surl = URLs.fileToUrl((File) input); DefaultResourceLocator defResourceLocator = new DefaultResourceLocator(); defResourceLocator.setSourceUrl(surl); resourceLocator = defResourceLocator; } final ResourceLocator locator = resourceLocator; SLDConfiguration sld; if (locator != null) { sld = new SLDConfiguration() { protected void configureContext( org.picocontainer.MutablePicoContainer container) { container.registerComponentInstance(ResourceLocator.class, locator); }; }; } else { sld = new SLDConfiguration(); } Parser parser = new Parser(sld); if (entityResolver != null) { parser.setEntityResolver(entityResolver); } return parser; }
/** Internal setter for source url. */ void setSourceUrl(URL sourceUrl) { if (onlineResourceLocator instanceof DefaultResourceLocator) { ((DefaultResourceLocator) onlineResourceLocator).setSourceUrl(sourceUrl); } }
/** * Retrieve the styled layer descriptor prepared for direct GeoTools use. All file references * have been made absolute. * * @param s The style * @return A {@link StyledLayerDescriptor} */ public @Nonnull StyledLayerDescriptor parsedSld(final StyleInfo s) throws IOException { final Resource styleResource = style(s); if (styleResource.getType() == Type.UNDEFINED) { throw new IOException( "No such resource: " + s.getFilename() + (s.getWorkspace() != null ? " in workspace " + s.getWorkspace() : "")); } File input = styleResource.file(); DefaultResourceLocator locator = new GeoServerResourceLocator(); locator.setSourceUrl(Resources.toURL(styleResource)); EntityResolver entityResolver = getEntityResolver(); final StyledLayerDescriptor sld = Styles.handler(s.getFormat()) .parse(input, s.getFormatVersion(), locator, getEntityResolver()); return sld; }
protected void configureContext( org.picocontainer.MutablePicoContainer container) { DefaultResourceLocator locator = new DefaultResourceLocator(); locator.setSourceUrl(surl); container.registerComponentInstance(ResourceLocator.class, locator); }; };
public void testPreserveURLQueryWithColors() throws Exception { DefaultResourceLocator locator = new DefaultResourceLocator(); locator.setSourceUrl(getClass().getResource("test-data/blob.gif")); // Confirm still able to resolve to a File URL url = locator.locateResource("blob.gif?fill=#ff0000&stroke=#000000"); final String external = url.toExternalForm(); assertTrue(external.indexOf('?') > 0); assertEquals("fill=#ff0000&stroke=#000000", external.split("\\?")[1]); File file = URLs.urlToFile(url); assertTrue(file.exists()); }
public void testPreserveURLQuery() throws Exception { DefaultResourceLocator locator = new DefaultResourceLocator(); locator.setSourceUrl(getClass().getResource("test-data/blob.gif")); // Confirm still able to resolve to a File URL url = locator.locateResource("blob.gif?query=parameter"); assertEquals("query=parameter", url.getQuery()); File file = URLs.urlToFile(url); assertTrue(file.exists()); }
locator.setSourceUrl(testURL);
/** * Internal setter for source url. */ void setSourceUrl(URL sourceUrl) { this.sourceUrl = sourceUrl; if (onlineResourceLocator instanceof DefaultResourceLocator) { ((DefaultResourceLocator) onlineResourceLocator).setSourceUrl(sourceUrl); } }
public void testRelativeFileURL() throws Exception { DefaultResourceLocator locator = new DefaultResourceLocator(); locator.setSourceUrl(getClass().getResource("test-data/blob.gif")); checkURL(locator.locateResource("blob.gif")); checkURL(locator.locateResource("file:blob.gif")); checkURL(locator.locateResource("file://blob.gif")); checkURL(locator.locateResource("file://./blob.gif")); }
/** * Sets the resource locator so that relative external graphic files can be found. * * @param styleReader the new resource locator * @param url the url */ public static void setResourcelocator(SLDParser styleReader, URL url) { DefaultResourceLocator resourceLocator = new DefaultResourceLocator(); resourceLocator.setSourceUrl(url); styleReader.setOnLineResourceLocator(resourceLocator); }
@Override public StyledLayerDescriptor parse(Object input, Version version, @Nullable ResourceLocator resourceLocator, EntityResolver entityResolver) throws IOException { if (resourceLocator == null && input instanceof File) { resourceLocator = new DefaultResourceLocator(); ((DefaultResourceLocator)resourceLocator).setSourceUrl(DataUtilities.fileToURL((File) input)); } return Ysld.parse(toReader(input), Collections.singletonList(zoomFinder), resourceLocator, uomMapper); }
private Parser createSld11Parser(Object input, ResourceLocator resourceLocator, EntityResolver entityResolver) { if (resourceLocator == null && input instanceof File) { // setup for resolution of relative paths final java.net.URL surl = DataUtilities.fileToURL((File) input); DefaultResourceLocator defResourceLocator = new DefaultResourceLocator(); defResourceLocator.setSourceUrl(surl); resourceLocator = defResourceLocator; } final ResourceLocator locator = resourceLocator; SLDConfiguration sld; if (locator != null) { sld = new SLDConfiguration() { protected void configureContext(org.picocontainer.MutablePicoContainer container) { container.registerComponentInstance(ResourceLocator.class, locator); } ; } ; } else { sld = new SLDConfiguration(); } Parser parser = new Parser(sld); if (entityResolver != null) { parser.setEntityResolver(entityResolver); } return parser; }