/** * Convert raw xml to StyledLayerDescriptorInfo. * * @param sld * @return StyledLayerDescriptorInfo * @throws SldException */ public StyledLayerDescriptorInfo toSldI(RawSld sld) throws SldException { try { return parseXml(sld.getName(), sld.getXml()); } catch (JiBXException e) { throw new SldException("Validation error", e); } }
public List<SldInfo> findTemplates() throws SldException { List<SldInfo> res = new ArrayList<SldInfo>(); for (RawSld raw : allSlds.values()) { res.add(new SldInfoImpl(raw.getName(), raw.getTitle())); } return res; }
private RawSld parseSldI(StyledLayerDescriptorInfo sld) throws JiBXException { RawSld res = new RawSld(); IBindingFactory bfact; bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class); IMarshallingContext mctx = bfact.createMarshallingContext(); StringWriter writer = new StringWriter(); mctx.setOutput(writer); mctx.getXmlWriter().setIndentSpaces(2, "\n", ' '); mctx.marshalDocument(sld); res.setXml(writer.toString()); res.setName(sld.getName()); res.setVersion(sld.getVersion()); res.setTitle(sld.getTitle() == null ? getTitle(sld, "?") : sld.getTitle()); return res; }
/** * Test by unmarshalling. * * @param sld * @throws SldException */ public boolean validate(RawSld sld) throws SldException { try { parseXml("", sld.getXml()); return true; } catch (JiBXException e) { return false; } }
@PostConstruct void init() throws SldException { if (getDirectory() != null) { try { if (getDirectory().getFile().exists()) { if (getDirectory().getFile().isDirectory()) { File[] sldFiles = getDirectory() .getFile() .listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".sld") || name.endsWith(".xml"); } }); for (File file : sldFiles) { RawSld raw = new RawSld(); raw.setXml(FileUtils.readFileToString(file, FILE_ENCODING)); String fileName = StringUtils.stripFilenameExtension(file.getName()); StyledLayerDescriptorInfo tmp = parseXml(fileName, raw.getXml()); raw.setName(fileName); raw.setTitle(tmp.getTitle()); raw.setVersion(tmp.getVersion()); log.info("added sld '{}' to service", fileName); allSlds.put(raw.getName(), raw); } } } } catch (Exception e) { // NOSONAR log.warn("Error while initilizing SLD service.", e); } } }