@Override public void visit(Mark mark) { assertEquals( "ttf://Webdings", mark.getExternalMark() .getOnlineResource() .getLinkage() .toASCIIString()); } });
@Test public void testSEStyleWithRelativePathProtocol() throws IOException { StyleInfo si = getCatalog().getStyleByName("relative_protocol"); assertNotNull(si); Style style = si.getStyle(); PolygonSymbolizer ps = (PolygonSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); ExternalGraphic eg = (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0); URI uri = eg.getOnlineResource().getLinkage(); assertNotNull(uri); File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile(); assertEquals(rockFillSymbolFile, actual); }
@Test public void testSEStyleWithRelativePath() throws IOException { StyleInfo si = getCatalog().getStyleByName("relative"); assertNotNull(si); Style style = si.getStyle(); PolygonSymbolizer ps = (PolygonSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); ExternalGraphic eg = (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0); URI uri = eg.getOnlineResource().getLinkage(); assertNotNull(uri); File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile(); assertEquals(rockFillSymbolFile, actual); }
public URI getPublisher() { try { return capabilities .getService() .getContactInformation() .getContactInfo() .getOnLineResource() .getLinkage(); } catch (NullPointerException publisherNotAvailable) { } try { return new URI(serverURL.getProtocol() + ":" + serverURL.getHost()); } catch (URISyntaxException e) { } return null; }
/** * Returns a shape from an external mark definition * * @param mark * @return */ public Shape getShape(ExternalMark mark) { if (!"ttf".equals(mark.getFormat())) { return null; } String link = mark.getOnlineResource().getLinkage().toString(); // if it does not start with the right prefix, it's not our business if (!link.startsWith("ttf://")) return null; String family; try { family = URLDecoder.decode(link.substring(6), "UTF-8"); } catch (UnsupportedEncodingException e) { // UTF-8 not supported?? throw new RuntimeException(e); } int markIdx = mark.getMarkIndex(); char character = (char) markIdx; return getShape(family, character); }
SymbolsEncoder encode(ExternalGraphic eg) { OnLineResource r = eg.getOnlineResource(); if (r != null) { put("url", r.getLinkage().toString()); } put("format", eg.getFormat()); return this; } }
BufferedImage image = ImageIOExt.readBufferedImage( graphic.getOnlineResource().getLinkage().toURL()); if ((symbolScale > 0.0) && (symbolScale != 1.0)) { int w = (int) (image.getWidth() / symbolScale);
@SuppressWarnings("unchecked") @Test public void testRelativeExternalGraphicNoResolver() throws Exception { String yaml = "feature-styles:\n" + "- name: name\n" + " rules:\n" + " - symbolizers:\n" + " - point:\n" + " size: 32\n" + " symbols:\n" + " - external:\n" + " url: smileyface.png\n" + " format: image/png\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(p.getGraphic().graphicalSymbols().get(0), instanceOf(ExternalGraphic.class)); ExternalGraphic eg = (ExternalGraphic) p.getGraphic().graphicalSymbols().get(0); assertThat(eg.getLocation(), equalTo(new URL("file:smileyface.png"))); assertThat( eg.getOnlineResource().getLinkage(), anyOf(equalTo(new URI("smileyface.png")), equalTo(new URI("file:smileyface.png")))); }
@Test public void testRelativeExternalGraphicWithResolver() throws Exception { String yaml = "feature-styles:\n" + "- name: name\n" + " rules:\n" + " - symbolizers:\n" + " - point:\n" + " size: 32\n" + " symbols:\n" + " - external:\n" + " url: smileyface.png\n" + " format: image/png\n"; ResourceLocator locator = EasyMock.createMock(ResourceLocator.class); expect(locator.locateResource("smileyface.png")) .andReturn(new URL("http://itworked/smileyface.png")); replay(locator); StyledLayerDescriptor sld = Ysld.parse(yaml, Collections.<ZoomContextFinder>emptyList(), locator); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertThat(p.getGraphic().graphicalSymbols().get(0), instanceOf(ExternalGraphic.class)); ExternalGraphic eg = (ExternalGraphic) p.getGraphic().graphicalSymbols().get(0); assertThat(eg.getLocation(), equalTo(new URL("http://itworked/smileyface.png"))); assertThat( eg.getOnlineResource().getLinkage(), equalTo(new URI("http://itworked/smileyface.png"))); verify(locator); }
public void testExternalMark() throws URISyntaxException { OnLineResourceImpl or = new OnLineResourceImpl(); or.setLinkage(new URI("ttf://wingdings")); ExternalMark externalMark = sf.externalMark(or, "ttf", 15); Mark mark = sf.createMark(); mark.setExternalMark(externalMark); Mark clone = visitor.copy(mark); assertCopy(mark, clone); assertCopy(mark.getExternalMark(), clone.getExternalMark()); ExternalMark emCopy = clone.getExternalMark(); assertEquals("ttf", emCopy.getFormat()); assertEquals("ttf://wingdings", emCopy.getOnlineResource().getLinkage().toASCIIString()); assertEquals(15, emCopy.getMarkIndex()); }
public URI getPublisher() { try { return capabilities .getService() .getContactInformation() .getContactInfo() .getOnLineResource() .getLinkage(); } catch (NullPointerException publisherNotAvailable) { } try { return new URI(serverURL.getProtocol() + ":" + serverURL.getHost()); } catch (URISyntaxException e) { } return null; }
SymbolsEncoder encode(ExternalGraphic eg) { OnLineResource r = eg.getOnlineResource(); if (r != null) { put("url", r.getLinkage().toString()); } put("format", eg.getFormat()); return this; } }
assertThat(eg.getOnlineResource().getLinkage(), equalTo(image.toURI()));
@Test public void testUnneccessaryURLInjection() throws Exception { Style result; { Symbolizer symb = this.externalGraphic("http://example.com/NF.png", "image/png"); Style input = styleFromRules(catchAllRule(symb)); Map<String, String> properties = new HashMap<String, String>(); properties.put("0.0.0", ""); properties.put("0.0.0.url", "http://example.com/BC.png"); result = IconPropertyInjector.injectProperties(input, properties); } { FeatureTypeStyle fts = assumeSingleElement(result.featureTypeStyles()); Rule rule = assumeSingleElement(fts.rules()); PointSymbolizer symb = assertSingleElement(rule.symbolizers(), PointSymbolizer.class); ExternalGraphic eg = assertSingleElement( symb.getGraphic().graphicalSymbols(), ExternalGraphic.class); assertThat( eg.getOnlineResource().getLinkage().toString(), is("http://example.com/NF.png")); } }
@Test public void testSubstitutedGraphicStyle() throws Exception { Style result; { Symbolizer symb = this.externalGraphic("http://example.com/${PROV_ABBR}.png", "image/png"); Style input = styleFromRules(catchAllRule(symb)); Map<String, String> properties = new HashMap<String, String>(); properties.put("0.0.0", ""); properties.put("0.0.0.url", "http://example.com/BC.png"); result = IconPropertyInjector.injectProperties(input, properties); } { FeatureTypeStyle fts = assumeSingleElement(result.featureTypeStyles()); Rule rule = assumeSingleElement(fts.rules()); PointSymbolizer symb = assertSingleElement(rule.symbolizers(), PointSymbolizer.class); ExternalGraphic eg = assertSingleElement( symb.getGraphic().graphicalSymbols(), ExternalGraphic.class); assertThat( eg.getOnlineResource().getLinkage().toString(), is("http://example.com/BC.png")); } }
@Test public void testSimpleGraphicStyle() throws Exception { Style result; { Symbolizer symb = this.externalGraphic("http://example.com/foo.png", "image/png"); Style input = styleFromRules(catchAllRule(symb)); Map<String, String> properties = new HashMap<String, String>(); properties.put("0.0.0", ""); result = IconPropertyInjector.injectProperties(input, properties); } { FeatureTypeStyle fts = assumeSingleElement(result.featureTypeStyles()); Rule rule = assumeSingleElement(fts.rules()); PointSymbolizer symb = assertSingleElement(rule.symbolizers(), PointSymbolizer.class); ExternalGraphic eg = assertSingleElement( symb.getGraphic().graphicalSymbols(), ExternalGraphic.class); assertThat( eg.getOnlineResource().getLinkage().toString(), is("http://example.com/foo.png")); } }
@Test public void testFilteredRulesPickFirstExternal() throws Exception { Style result; { Filter f1 = filterFactory.less(filterFactory.property("foo"), filterFactory.literal(4)); Filter f2 = filterFactory.greaterOrEqual( filterFactory.property("foo"), filterFactory.literal(4)); PointSymbolizer symb1 = externalGraphic("http://example.com/foo.png", "image/png"); PointSymbolizer symb2 = externalGraphic("http://example.com/bar.png", "image/png"); Style input = styleFromRules(rule(f1, symb1), rule(f2, symb2)); Map<String, String> properties = new HashMap<String, String>(); properties.put("0.0.0", ""); result = IconPropertyInjector.injectProperties(input, properties); } { FeatureTypeStyle fts = assumeSingleElement(result.featureTypeStyles()); Rule rule = assertSingleElement(fts.rules()); PointSymbolizer symb = assertSingleElement(rule.symbolizers(), PointSymbolizer.class); ExternalGraphic eg = assertSingleElement( symb.getGraphic().graphicalSymbols(), ExternalGraphic.class); assertThat( eg.getOnlineResource().getLinkage().toString(), is("http://example.com/foo.png")); } }
@Test public void testFilteredRulesPickSecondExternal() throws Exception { Style result; { Filter f1 = filterFactory.less(filterFactory.property("foo"), filterFactory.literal(4)); Filter f2 = filterFactory.greaterOrEqual( filterFactory.property("foo"), filterFactory.literal(4)); PointSymbolizer symb1 = externalGraphic("http://example.com/foo.png", "image/png"); PointSymbolizer symb2 = externalGraphic("http://example.com/bar.png", "image/png"); Style input = styleFromRules(rule(f1, symb1), rule(f2, symb2)); Map<String, String> properties = new HashMap<String, String>(); properties.put("0.1.0", ""); result = IconPropertyInjector.injectProperties(input, properties); } { FeatureTypeStyle fts = assumeSingleElement(result.featureTypeStyles()); Rule rule = assertSingleElement(fts.rules()); PointSymbolizer symb = assertSingleElement(rule.symbolizers(), PointSymbolizer.class); ExternalGraphic eg = assertSingleElement( symb.getGraphic().graphicalSymbols(), ExternalGraphic.class); assertThat( eg.getOnlineResource().getLinkage().toString(), is("http://example.com/bar.png")); } }