private void handleSldFromStyleStore( File file, String namedLayer, Map<String, String> map, String layerName, Map<String, Pair<File, URL>> legends, Map<String, Boolean> glgUrls) { // already loaded from workspace String styleId = file.getName().substring(0, file.getName().length() - 4); StyleStore store = styleManager.get(styleId); if (store != null) { LOG.info("Using SLD file loaded from style store."); for (Style s : store.getAll(namedLayer)) { s.setName(map.get(s.getName())); registry.put(layerName, s, false); Pair<File, URL> p = legends.get(s.getName()); if (p != null && p.first != null) { s.setLegendFile(p.first); } else if (p != null) { s.setLegendURL(p.second); } s.setPrefersGetLegendGraphicUrl( glgUrls.get(s.getName()) != null && glgUrls.get(s.getName())); } return; } }
private void extractFromSld( SLDStyleType sty, XMLAdapter adapter, File stylesDir, String layerName, Map<String, Pair<File, URL>> legends, Map<String, Boolean> glgUrls, Map<String, String> map) throws Throwable { String name = null, lastName = null; for (JAXBElement<?> elem : sty.getNameAndUserStyleAndLegendConfigurationFile()) { if (elem.getName().getLocalPart().equals("Name")) { name = elem.getValue().toString(); } else if (elem.getName().getLocalPart().equals("LegendConfigurationFile")) { File legendFile = new File(adapter.resolve(elem.getValue().toString()).toURI()); Style style = findStyle(legendFile, stylesDir, layerName); if (style != null) { if (name != null) { style.setName(name); } registry.putLegend(layerName, style, false); } } else if (elem.getName().getLocalPart().equals("LegendGraphicFile")) { LegendGraphicFile lgf = (LegendGraphicFile) elem.getValue(); URL url = adapter.resolve(lgf.getValue()); if (url.toURI().getScheme().equals("file")) { File legend = new File(url.toURI()); legends.put(lastName, new Pair<File, URL>(legend, null)); } else { legends.put(lastName, new Pair<File, URL>(null, url)); } glgUrls.put(lastName, lgf.isOutputGetLegendGraphicUrl()); } else if (elem.getName().getLocalPart().equals("UserStyle")) { if (name == null) { name = elem.getValue().toString(); } LOG.debug( "Will load user style with name '{}', it will be known as '{}'.", elem.getValue(), name); map.put(elem.getValue().toString(), name); lastName = name; name = null; } } }