Esempio n. 1
0
  void parse(String layerName, XMLAdapter adapter, List<SLDStyleType> styles) {
    File stylesDir = new File(workspace.getLocation(), "styles");

    for (SLDStyleType sty : styles) {
      try {
        File file = new File(adapter.resolve(sty.getFile()).toURI());

        String namedLayer = sty.getNamedLayer();
        LOG.debug("Will read styles from SLD '{}', for named layer '{}'.", file, namedLayer);
        Map<String, String> map = new HashMap<String, String>();
        Map<String, Pair<File, URL>> legends = new HashMap<String, Pair<File, URL>>();
        Map<String, Boolean> glgUrls = new HashMap<String, Boolean>();
        extractFromSld(sty, adapter, stylesDir, layerName, legends, glgUrls, map);

        if (file.getParentFile().equals(stylesDir)) {
          handleSldFromStyleStore(file, namedLayer, map, layerName, legends, glgUrls);
        }

        handleExternalSld(file, namedLayer, layerName, map, legends, glgUrls);
      } catch (Throwable e) {
        LOG.trace("Stack trace", e);
        LOG.info(
            "Style file '{}' for layer '{}' could not be parsed: '{}'.",
            new Object[] {sty.getFile(), layerName, e.getLocalizedMessage()});
      }
    }
  }
Esempio n. 2
0
  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;
      }
    }
  }
 /**
  * @param datasource
  * @param adapter
  * @return a corresponding raster, null if files could not be fund
  */
 public static AbstractRaster fromDatasource(RasterDataSource datasource, XMLAdapter adapter) {
   if (datasource != null) {
     String defCRS = datasource.getCrs();
     CRS crs = null;
     if (defCRS != null) {
       crs = new CRS(defCRS);
     }
     RasterFileSetType directory = datasource.getRasterDirectory();
     RasterFileType file = datasource.getRasterFile();
     try {
       if (directory != null) {
         File rasterFiles = new File(adapter.resolve(directory.getValue()).getFile());
         boolean recursive = directory.isRecursive() == null ? false : directory.isRecursive();
         RasterIOOptions options = new RasterIOOptions();
         if (crs != null) {
           options.add(RasterIOOptions.CRS, crs.getName());
         }
         return buildTiledRaster(rasterFiles, directory.getFilePattern(), recursive, options);
       }
       if (file != null) {
         final File loc = new File(adapter.resolve(file.getValue()).getFile());
         AbstractRaster raster = loadRasterFromFile(loc);
         raster.setCoordinateSystem(crs);
         return raster;
       }
     } catch (MalformedURLException e) {
       if (directory != null) {
         LOG.warn(
             "Could not resolve the file {}, corresponding data will not be available.",
             directory.getValue());
       } else {
         LOG.warn(
             "Could not resolve the file {}, corresponding data will not be available.",
             file.getValue());
       }
     } catch (IOException e) {
       LOG.warn(
           "Could not load the file {}, corresponding data will not be available.",
           file.getValue());
     }
   }
   throw new NullPointerException("The configured raster datasource may not be null.");
 }
  @Override
  public GeoCouchFeatureStore create(URL configURL) throws ResourceInitException {

    GeoCouchFeatureStore fs = null;
    try {
      GeoCouchFeatureStoreConfig config =
          (GeoCouchFeatureStoreConfig)
              JAXBUtils.unmarshall(CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, configURL, workspace);

      XMLAdapter resolver = new XMLAdapter();
      resolver.setSystemId(configURL.toString());

      String srs = config.getStorageCRS();
      srs = srs.trim();
      ICRS crs = CRSManager.getCRSRef(srs);

      String couchUrl = config.getGeoCouchUrl();
      if (!couchUrl.endsWith("/")) {
        couchUrl += "/";
      }

      List<String> configSchemas = config.getGMLSchema();
      String[] schemas = new String[configSchemas.size()];
      int i = -1;
      for (String s : configSchemas) {
        schemas[++i] = resolver.resolve(s).toString();
      }

      GMLAppSchemaReader decoder = new GMLAppSchemaReader(null, null, schemas);
      AppSchema schema = decoder.extractAppSchema();

      fs = new GeoCouchFeatureStore(crs, schema, couchUrl);

    } catch (Throwable e) {

      String msg =
          "Error in feature store configuration file '" + configURL + "': " + e.getMessage();
      LOG.error(msg);
      throw new ResourceInitException(msg, e);
    }
    return fs;
  }
 /**
  * @param datasource
  * @param adapter
  * @return a corresponding raster
  */
 public static MultiResolutionRaster fromDatasource(
     MultiResolutionDataSource datasource, XMLAdapter adapter) {
   if (datasource != null) {
     String defCRS = datasource.getCrs();
     CRS crs = null;
     if (defCRS != null) {
       crs = new CRS(defCRS);
     }
     MultiResolutionRaster mrr = new MultiResolutionRaster();
     mrr.setCoordinateSystem(crs);
     for (Resolution resolution : datasource.getResolution()) {
       JAXBElement<? extends AbstractGeospatialDataSourceType> dsElement =
           resolution.getAbstractGeospatialDataSource();
       RasterDataSource ds = (RasterDataSource) dsElement.getValue();
       RasterFileSetType directory = ds.getRasterDirectory();
       File resolutionDir;
       try {
         resolutionDir = new File(adapter.resolve(directory.getValue()).getFile());
         RasterIOOptions options = new RasterIOOptions();
         if (crs != null) {
           options.add(RasterIOOptions.CRS, crs.getName());
         }
         AbstractRaster rasterLevel =
             buildTiledRaster(
                 resolutionDir, directory.getFilePattern(), directory.isRecursive(), options);
         // double res = RasterBuilder.getPixelResolution( resolution.getRes(), resolutionDir );
         mrr.addRaster(rasterLevel);
       } catch (MalformedURLException e) {
         LOG.warn(
             "Could not resolve the file {}, corresponding data will not be available.",
             directory.getValue());
       }
     }
     return mrr;
   }
   throw new NullPointerException("The configured multi resolution datasource may not be null.");
 }