VariableOnlineResource extends AbstractSymbolizerNode implements ExternalGraphicSource, MarkGraphicSource { public PlanarImage getPlanarJAI(Map<String, Object> map) throws ParameterException { try { URL link = new URL(url.getValue(map)); if (!imageCache.containsKey(link)) { PlanarImage raw = JAI.create("url", link); imageCache.put(link, raw); Logger.getLogger(VariableOnlineResource.class.getName()).log(Level.INFO, "Download ExternalGraphic from: {0}", url); } return imageCache.get(link); } catch (Exception ex) { throw new ParameterException("Can't process the input URL",ex); } } VariableOnlineResource();  VariableOnlineResource(StringParameter url);  VariableOnlineResource(VariableOnlineResourceType onlineResource); StringParameter getUrl(); void setUrl(StringParameter url); PlanarImage getPlanarJAI(Map<String, Object> map); Rectangle2D.Double getJAIBounds(ViewBox viewBox,
                                           Map<String, Object> map, MapTransform mt,
                                           String mimeType); SVGIcon getSVGIcon(Map<String,Object> map); Rectangle2D.Double getSvgBounds(ViewBox viewBox,
                                           Map<String,Object> map, MapTransform mt,
                                           String mimeType); @Override Rectangle2D.Double updateCacheAndGetBounds(ViewBox viewBox,
                                                      Map<String,Object> map, MapTransform mt,
                                                      String mimeType); void drawSVG(Graphics2D g2, Map<String,Object> map, AffineTransform at, double opacity); void drawJAI(Graphics2D g2, Map<String,Object> map, AffineTransform at, MapTransform mt,
                        double opacity); @Override void draw(Graphics2D g2, Map<String,Object> map, AffineTransform at, MapTransform mt,
                     double opacity, String mimeType); @Override void setJAXBSource(ExternalGraphicType e); Font getFont(Map<String,Object> map); @Override void update(); @Override Shape getShape(ViewBox viewBox, Map<String,Object> map, Double scale,
            Double dpi, RealParameter markIndex, String mimeType); void setJAXBSource(MarkGraphicType m); @Override double getDefaultMaxWidth(Map<String,Object> map,
                                     Double scale, Double dpi,
                                     RealParameter markIndex, String mimeType); @Override List<SymbolizerNode> getChildren();  }
@Test public void testCacheEmptying() throws Exception { URL resource = VariableOnlineResourceTest.class.getResource("3.gif"); StringLiteral lit = new StringLiteral(resource.toString()); VariableOnlineResource vor = new VariableOnlineResource(lit); PlanarImage first = vor.getPlanarJAI(null); PlanarImage second = vor.getPlanarJAI(null); assertTrue(first == second); lit.setValue(VariableOnlineResourceTest.class.getResource("21.gif").toString()); lit.setValue(VariableOnlineResourceTest.class.getResource("3.gif").toString()); PlanarImage third = vor.getPlanarJAI(null); assertFalse(third == second); }
@Test public void testCacheRecode() throws Exception { Map<String,Object> input = new HashMap<String,Object>(); input.put("field", "s"); URL resourceF = VariableOnlineResourceTest.class.getResource("3.gif"); URL resourceD = VariableOnlineResourceTest.class.getResource("21.gif"); StringLiteral fb = new StringLiteral(resourceF.toString()); Recode2String rs = new Recode2String(fb,new StringAttribute("field")); rs.addMapItem("s",new StringLiteral(resourceD.toString())); VariableOnlineResource vor = new VariableOnlineResource(rs); PlanarImage first = vor.getPlanarJAI(input); PlanarImage second = vor.getPlanarJAI(input); assertTrue(first == second); rs.addMapItem("s",new StringLiteral(resourceF.toString())); rs.addMapItem("s",new StringLiteral(resourceD.toString())); PlanarImage third = vor.getPlanarJAI(input); assertFalse(third == second); second = vor.getPlanarJAI(input); fb.setValue(resourceD.toString()); third = vor.getPlanarJAI(input); assertFalse(second == third); }