コード例 #1
0
  void setupExtras(org.geoserver.data.test.SystemTestData testData, Catalog catalog)
      throws IOException {
    // associate Lakes to Buildings as an extra style
    LayerInfo buildings = catalog.getLayerByName(getLayerId(BUILDINGS));
    buildings.getStyles().add(catalog.getStyleByName(LAKES.getLocalPart()));
    catalog.save(buildings);

    // add a layer group
    CatalogFactory factory = catalog.getFactory();
    LayerGroupInfo globalGroup = factory.createLayerGroup();
    globalGroup.setName(LAKES_GROUP);
    globalGroup.getLayers().add(catalog.getLayerByName(getLayerId(LAKES)));
    globalGroup.getLayers().add(catalog.getLayerByName(getLayerId(FORESTS)));
    globalGroup.getLayers().add(catalog.getLayerByName(getLayerId(BRIDGES)));
    catalog.add(globalGroup);

    // add a layer group containing a layer group
    LayerGroupInfo nestGroup = factory.createLayerGroup();
    nestGroup.setName(NEST_GROUP);
    nestGroup.getLayers().add(catalog.getLayerByName(getLayerId(LAKES)));
    nestGroup.getLayers().add(globalGroup);
    catalog.add(nestGroup);

    // add a workspace specific style
    WorkspaceInfo ws = catalog.getWorkspaceByName(CITE_PREFIX);
    testData.addStyle(ws, WS_STYLE, "Streams.sld", SystemTestData.class, catalog);
  };
コード例 #2
0
ファイル: SystemTestData.java プロジェクト: aaime/geoserver
  protected void createCatalog() throws IOException {
    CatalogImpl catalog = new CatalogImpl();
    catalog.setExtendedValidation(false);
    catalog.setResourceLoader(new GeoServerResourceLoader(data));

    catalog.addListener(
        new GeoServerPersister(catalog.getResourceLoader(), createXStreamPersister()));

    // workspaces
    addWorkspace(DEFAULT_PREFIX, DEFAULT_URI, catalog);
    addWorkspace(SF_PREFIX, SF_URI, catalog);
    addWorkspace(CITE_PREFIX, CITE_URI, catalog);
    addWorkspace(CDF_PREFIX, CDF_URI, catalog);
    addWorkspace(CGF_PREFIX, CGF_URI, catalog);

    // default style
    addStyle(DEFAULT_VECTOR_STYLE, catalog);
    addStyle(DEFAULT_RASTER_STYLE, catalog);

    this.catalog = catalog;
  }
コード例 #3
0
  void addLayerAndStyle(SystemTestData testData, QName name) throws IOException {
    testData.addVectorLayer(
        name, null, name.getLocalPart() + ".properties", getClass(), this.catalog);

    final String styleName = name.getLocalPart();
    testData.addStyle(styleName, getClass(), this.catalog);

    StyleInfo defaultStyle = this.catalog.getStyleByName(styleName);

    String layerId = getLayerId(name);
    LayerInfo layerInfo = this.catalog.getLayerByName(layerId);
    layerInfo.setDefaultStyle(defaultStyle);
    this.catalog.save(layerInfo);
  }
コード例 #4
0
 @Override
 protected void onSetUp(SystemTestData testData) throws Exception {
   super.onSetUp(testData);
   Catalog catalog = getCatalog();
   testData.addStyle("Bridge", "bridge.sld", getClass(), catalog);
   testData.addStyle("allsymbolizers", "allsymbolizers.sld", getClass(), catalog);
   testData.addStyle("labels", "labels.sld", getClass(), catalog);
   testData.addStyle("SingleFeature", "singlefeature.sld", getClass(), catalog);
   testData.addStyle("BridgeSubdir", "bridgesubdir.sld", getClass(), catalog);
   testData.addStyle("dynamicsymbolizer", "dynamicsymbolizer.sld", getClass(), catalog);
   testData.addStyle("relativeds", "relativeds.sld", getClass(), catalog);
   testData.addStyle("big-local-image", "big-local-image.sld", getClass(), catalog);
   testData.addStyle("big-mark", "big-mark.sld", getClass(), catalog);
   testData.copyTo(getClass().getResourceAsStream("bridge.png"), "styles/bridge.png");
   testData.copyTo(getClass().getResourceAsStream("planet-42.png"), "styles/planet-42.png");
   File stylesDir = new File(testData.getDataDirectoryRoot(), "styles");
   new File(stylesDir, "graphics").mkdir();
   testData.copyTo(
       getClass().getResourceAsStream("bridge.png"), "styles/graphics/bridgesubdir.png");
 }
コード例 #5
0
ファイル: ResourcePoolTest.java プロジェクト: hyl87/geoserver
  @Override
  protected void onSetUp(SystemTestData testData) throws Exception {
    super.onSetUp(testData);

    testData.addStyle("relative", "se_relativepath.sld", ResourcePoolTest.class, getCatalog());
    StyleInfo style = getCatalog().getStyleByName("relative");
    style.setSLDVersion(new Version("1.1.0"));
    getCatalog().save(style);
    File images = new File(testData.getDataDirectoryRoot(), "styles/images");
    assertTrue(images.mkdir());
    File image = new File("./src/test/resources/org/geoserver/catalog/rockFillSymbol.png");
    assertTrue(image.exists());
    FileUtils.copyFileToDirectory(image, images);
    rockFillSymbolFile = new File(images, image.getName()).getCanonicalFile();

    testData.addRasterLayer(
        TIMERANGES, "timeranges.zip", null, null, SystemTestData.class, getCatalog());
  }
コード例 #6
0
  void addLayerGroups(SystemTestData testData) throws Exception {
    // setup basic layergroups
    testData.addStyle("Accident3_2", getClass(), this.catalog);

    CoordinateReferenceSystem nativeCrs = CRS.decode("EPSG:4326", true);
    ReferencedEnvelope nativeBounds = new ReferencedEnvelope(-180, 180, -90, 90, nativeCrs);

    LayerGroupInfo layerGroup1 = catalog.getFactory().createLayerGroup();
    layerGroup1.setName("testLayerGroup1");
    layerGroup1.setBounds(nativeBounds);

    LayerGroupInfo layerGroup2 = catalog.getFactory().createLayerGroup();
    layerGroup2.setName("testLayerGroup2");
    layerGroup2.setBounds(nativeBounds);

    LayerGroupInfo layerGroup3 = catalog.getFactory().createLayerGroup();
    layerGroup3.setName("testLayerGroup3");
    layerGroup3.setBounds(nativeBounds);

    // add layers & styles
    layerGroup1.getLayers().add(catalog.getLayerByName(getLayerId(REGIONATED)));
    layerGroup1.getStyles().add(null);
    layerGroup1.getLayers().add(catalog.getLayerByName(getLayerId(ACCIDENT3)));
    layerGroup1.getStyles().add(catalog.getStyleByName("Accident3_2"));

    layerGroup2.getLayers().add(catalog.getLayerByName(getLayerId(REGIONATED)));
    layerGroup2.getLayers().add(catalog.getLayerByName(getLayerId(ACCIDENT)));
    layerGroup2.getLayers().add(catalog.getLayerByName(getLayerId(ACCIDENT2)));

    layerGroup3.getLayers().add(layerGroup2);
    layerGroup3.getLayers().add(catalog.getLayerByName(getLayerId(ACCIDENT3)));

    catalog.add(layerGroup1);
    catalog.add(layerGroup2);
    catalog.add(layerGroup3);
  }
コード例 #7
0
ファイル: SystemTestData.java プロジェクト: aaime/geoserver
  /**
   * Adds a vector layer to the catalog setup.
   *
   * <p>The layer is created within a store named <code>qName.getPrefix()</code>, creating it if it
   * does not exist. The resulting store is a {@link PropertyDataStore} that points at the directory
   * <code>getDataDirectoryRoot()/qName.getPrefix()</code>. Similarily the layer and store are
   * created within a workspace named <code>qName.getPrefix()</code>, which is created if it does
   * not already exist.
   *
   * <p>The properties data for the layer is copied from the classpath, with a file name of "<code>
   * filename</code>.properties". The <tt>scope</tt> parameter is used as the class from which to
   * load the properties file relative to.
   *
   * <p>The <tt>props</tt> parameter is used to define custom properties for the layer. See the
   * {@link LayerProperty} class for supported properties.
   */
  public void addVectorLayer(
      QName qName, Map<LayerProperty, Object> props, String filename, Class scope, Catalog catalog)
      throws IOException {
    String prefix = qName.getPrefix();
    String name = qName.getLocalPart();
    String uri = qName.getNamespaceURI();

    // configure workspace if it doesn;t already exist
    if (catalog.getWorkspaceByName(prefix) == null) {
      addWorkspace(prefix, uri, catalog);
    }

    // configure store if it doesn't already exist

    File storeDir = catalog.getResourceLoader().findOrCreateDirectory(prefix);

    DataStoreInfo store = catalog.getDataStoreByName(prefix);
    if (store == null) {
      store = catalog.getFactory().createDataStore();
      store.setName(prefix);
      store.setWorkspace(catalog.getWorkspaceByName(prefix));
      store.setEnabled(true);

      store.getConnectionParameters().put(PropertyDataStoreFactory.DIRECTORY.key, storeDir);
      store.getConnectionParameters().put(PropertyDataStoreFactory.NAMESPACE.key, uri);
      catalog.add(store);
    }

    // copy the properties file over

    catalog.getResourceLoader().copyFromClassPath(filename, new File(storeDir, filename), scope);

    // configure feature type
    FeatureTypeInfo featureType = catalog.getFactory().createFeatureType();
    featureType.setStore(store);
    featureType.setNamespace(catalog.getNamespaceByPrefix(prefix));
    featureType.setName(LayerProperty.NAME.get(props, name));
    featureType.setNativeName(FilenameUtils.getBaseName(filename));
    featureType.setTitle(name);
    featureType.setAbstract("abstract about " + name);

    Integer srs = LayerProperty.SRS.get(props, SRS.get(qName));
    if (srs == null) {
      srs = 4326;
    }
    featureType.setSRS("EPSG:" + srs);
    try {
      featureType.setNativeCRS(CRS.decode("EPSG:" + srs));
    } catch (Exception e) {
      LOGGER.warning("Failed to decode EPSG:" + srs + ", setting the native SRS to null");
    }
    featureType.setNumDecimals(8);
    featureType.getKeywords().add(new Keyword(name));
    featureType.setEnabled(true);
    featureType.setProjectionPolicy(
        LayerProperty.PROJECTION_POLICY.get(props, ProjectionPolicy.NONE));
    featureType.setLatLonBoundingBox(
        LayerProperty.LATLON_ENVELOPE.get(props, DEFAULT_LATLON_ENVELOPE));
    featureType.setNativeBoundingBox(LayerProperty.ENVELOPE.get(props, null));

    FeatureTypeInfo ft = catalog.getFeatureTypeByDataStore(store, name);
    LayerInfo layer = catalog.getLayerByName(new NameImpl(prefix, name));
    if (ft == null) {
      ft = featureType;
      catalog.add(featureType);
    } else {
      if (layer == null) {
        // handles the case of layer removed, but feature type not
        catalog.remove(ft);
        ft = featureType;
        catalog.add(featureType);
      } else {
        new CatalogBuilder(catalog).updateFeatureType(ft, featureType);
        catalog.save(ft);
      }
    }

    if (layer == null
        || !layer.getResource().getNamespace().equals(catalog.getNamespaceByPrefix(prefix))) {
      layer = catalog.getFactory().createLayer();
    }

    layer.setResource(ft);

    StyleInfo defaultStyle = null;
    if (LayerProperty.STYLE.get(props, null) != null) {
      defaultStyle = catalog.getStyleByName(LayerProperty.STYLE.get(props, null));
    } else {
      // look for a style matching the layer name
      defaultStyle = catalog.getStyleByName(name);
      if (defaultStyle == null) {
        // see if the resource exists and we just need to create it
        if (getClass().getResource(name + ".sld") != null) {
          addStyle(name, catalog);
          defaultStyle = catalog.getStyleByName(name);
        }
      }
    }

    if (defaultStyle == null) {
      defaultStyle = catalog.getStyleByName(DEFAULT_VECTOR_STYLE);
    }

    layer.getStyles().clear();
    layer.setDefaultStyle(defaultStyle);
    layer.setType(LayerInfo.Type.VECTOR);
    layer.setEnabled(true);

    if (layer.getId() == null) {
      catalog.add(layer);
    } else {
      catalog.save(layer);
    }
  }
コード例 #8
0
ファイル: SystemTestData.java プロジェクト: aaime/geoserver
 /**
  * Adds a style to the test setup.
  *
  * <p>To set up the style a file named <tt>name</tt>.sld is copied from the classpath relative to
  * the <tt>scope</tt> parameter.
  *
  * @param name The name of the style.
  * @param scope Class from which to load sld resource from.
  */
 public void addStyle(String name, Class scope, Catalog catalog) throws IOException {
   addStyle(name, name + ".sld", scope, catalog);
 }
コード例 #9
0
ファイル: SystemTestData.java プロジェクト: aaime/geoserver
 /**
  * Adds a style to the test setup.
  *
  * <p>To set up the style a file named <tt>name</tt>.sld is copied from the classpath relative to
  * this class.
  *
  * @param name The name of the style.
  */
 public void addStyle(String name, Catalog catalog) throws IOException {
   addStyle(name, getClass(), catalog);
 }