Esempio n. 1
0
  StyledLayerDescriptor parse10(
      Object input, ResourceLocator resourceLocator, EntityResolver entityResolver)
      throws IOException {

    Reader reader = null;
    try {
      // we need to close the reader if we grab one, but if it's a file it has
      // to stay as such to allow relative resource resolution during the parse
      if (!(input instanceof File)) {
        reader = toReader(input);
        input = reader;
      }
      SLDParser p = createSld10Parser(input, resourceLocator, entityResolver);
      StyledLayerDescriptor sld = p.parseSLD();
      if (sld.getStyledLayers().length == 0) {
        // most likely a style that is not a valid sld, try to actually parse out a
        // style and then wrap it in an sld
        Style[] style = p.readDOM();
        if (style.length > 0) {
          NamedLayer l = styleFactory.createNamedLayer();
          l.addStyle(style[0]);
          sld.addStyledLayer(l);
        }
      }
      return sld;
    } finally {
      IOUtils.closeQuietly(reader);
    }
  }
 private Style getStyle(final String styleName) {
   Style style = STYLES.get(styleName);
   if (style == null) {
     StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
     SLDParser parser = new SLDParser(styleFactory);
     try {
       parser.setInput(getClass().getResource(styleName));
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
     StyledLayerDescriptor sld = parser.parseSLD();
     UserLayer layer = (UserLayer) sld.getStyledLayers()[0];
     style = layer.getUserStyles()[0];
     STYLES.put(styleName, style);
   }
   return style;
 }