コード例 #1
0
 @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);
     }
   }
 }
コード例 #2
0
 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;
 }