/** @param layerTree */
    private void handleLayerTree(final LayerTree layerTree) {
      final List<LayerInfo> data = new ArrayList<LayerInfo>(layerTree.getData());
      final Collection<LayerTree> children = layerTree.getChildrens();

      Collections.sort(
          data,
          new Comparator<LayerInfo>() {
            public int compare(LayerInfo o1, LayerInfo o2) {
              return o1.getName().compareTo(o2.getName());
            }
          });

      for (LayerInfo layer : data) {
        // no sense in exposing a geometryless layer through wms...
        boolean wmsExposable = false;
        if (layer.getType() == Type.RASTER || layer.getType() == Type.WMS) {
          wmsExposable = true;
        } else {
          try {
            wmsExposable =
                layer.getType() == Type.VECTOR
                    && ((FeatureTypeInfo) layer.getResource())
                            .getFeatureType()
                            .getGeometryDescriptor()
                        != null;
          } catch (Exception e) {
            LOGGER.log(
                Level.SEVERE,
                "An error occurred trying to determine if" + " the layer is geometryless",
                e);
          }
        }

        // ask for enabled() instead of isEnabled() to account for disabled resource/store
        if (layer.enabled() && wmsExposable) {
          try {
            handleLayer(layer);
          } catch (Exception e) {
            // report what layer we failed on to help the admin locate and fix it
            throw new ServiceException(
                "Error occurred trying to write out metadata for layer: " + layer.getName(), e);
          }
        }
      }

      for (LayerTree childLayerTree : children) {
        start("Layer");
        element("Name", childLayerTree.getName());
        element("Title", childLayerTree.getName());
        handleLayerTree(childLayerTree);
        end("Layer");
      }
    }
Esempio n. 2
0
  LayerInfo createLayer(ResourceInfo r, String name, NamespaceInfo ns) {
    String lId = newId();
    StyleInfo s = styles.peekLast();

    final LayerInfo l = createNiceMock(LayerInfo.class);
    layers.add(l);

    expect(l.getId()).andReturn(lId).anyTimes();
    expect(l.getName()).andReturn(name).anyTimes();
    expect(l.getType()).andReturn(LayerInfo.Type.VECTOR).anyTimes();
    expect(l.getResource()).andReturn(r).anyTimes();
    expect(l.getDefaultStyle()).andReturn(s).anyTimes();
    expect(l.isEnabled()).andReturn(true).anyTimes();
    expect(l.isAdvertised()).andReturn(true).anyTimes();

    expect(catalog.getLayer(lId)).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(name)).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(ns.getPrefix() + ":" + name)).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(new NameImpl(ns.getPrefix(), name))).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(new NameImpl(ns.getURI(), name))).andReturn(l).anyTimes();
    expect(catalog.getLayers(r)).andReturn(Arrays.asList(l)).anyTimes();
    l.accept((CatalogVisitor) anyObject());
    expectLastCall()
        .andAnswer(
            new VisitAnswer() {
              @Override
              protected void doVisit(CatalogVisitor visitor) {
                visitor.visit(l);
              }
            })
        .anyTimes();

    callback.onLayer(name, l, this);
    return l;
  }
Esempio n. 3
0
 /**
  * Returns the appropriate icon for the specified layer. This one distinguishes the geometry type
  * inside vector layers.
  *
  * @param info
  * @return
  */
 public ResourceReference getSpecificLayerIcon(LayerInfo info) {
   if (info.getType() == Type.RASTER) {
     return RASTER_ICON;
   } else if (info.getType() == Type.VECTOR) {
     try {
       FeatureTypeInfo fti = (FeatureTypeInfo) info.getResource();
       GeometryDescriptor gd = fti.getFeatureType().getGeometryDescriptor();
       return getVectoryIcon(gd);
     } catch (Exception e) {
       return GEOMETRY_ICON;
     }
   } else if (info.getType() == Type.WMS) {
     return MAP_ICON;
   } else {
     return UNKNOWN_ICON;
   }
 }
Esempio n. 4
0
  public MapLayerInfo(LayerInfo layerInfo) {
    this.layerInfo = layerInfo;
    this.remoteFeatureSource = null;
    ResourceInfo resource = layerInfo.getResource();

    // handle InlineFeatureStuff
    this.name = resource.getPrefixedName();
    this.label = resource.getTitle();
    this.description = resource.getAbstract();

    this.type = layerInfo.getType().getCode();
  }
  MapLayerInfo createMapLayer(String name, String ns) {
    ResourceInfo r = createMock(ResourceInfo.class);
    expect(r.getName()).andReturn(name);
    expect(r.getPrefixedName()).andReturn(ns + ":" + name);
    expect(r.getTitle()).andReturn(name);
    expect(r.getAbstract()).andReturn(name);
    replay(r);

    LayerInfo l = createMock(LayerInfo.class);
    expect(l.getResource()).andReturn(r);
    expect(l.getType()).andReturn(LayerInfo.Type.VECTOR);
    replay(l);

    return new MapLayerInfo(l);
  }
Esempio n. 6
0
  public void validate(LayerInfo lyr, boolean isNew) {
    if (lyr.isEnabled() == false) {
      // short-circuit - for disabled layers we don't need to validate
      // anything because it won't cause service exceptions for anyone
      return;
    }

    if (lyr.getResource() == null
        || (hasGeometry(lyr)
            && (lyr.getResource().getSRS() == null
                || lyr.getResource().getLatLonBoundingBox() == null)))
      throw new RuntimeException("Layer's resource is not fully configured");

    // Resource-dependent checks
    if (lyr.getType() == PublishedType.RASTER) {
      if (!(lyr.getResource() instanceof CoverageInfo))
        throw new RuntimeException("Layer with type RASTER doesn't have a coverage associated");
      CoverageInfo cvinfo = (CoverageInfo) lyr.getResource();
      try {
        cvinfo
            .getCatalog()
            .getResourcePool()
            .getGridCoverageReader(cvinfo, GeoTools.getDefaultHints());
      } catch (Throwable t) {
        throw new RuntimeException("Couldn't connect to raster layer's resource");
      }
    } else if (lyr.getType() == PublishedType.VECTOR) {
      if (!(lyr.getResource() instanceof FeatureTypeInfo))
        throw new RuntimeException("Layer with type VECTOR doesn't have a featuretype associated");
      FeatureTypeInfo ftinfo = (FeatureTypeInfo) lyr.getResource();
    } else throw new RuntimeException("Layer is neither RASTER nor VECTOR type");

    // Style-dependent checks
    if (hasGeometry(lyr) && (lyr.getDefaultStyle() == null || lyr.getStyles().contains(null)))
      throw new RuntimeException("Layer has null styles!");
  }
    /**
     * Calls super.handleFeatureType to add common FeatureType content such as Name, Title and
     * LatLonBoundingBox, and then writes WMS specific layer properties as Styles, Scale Hint, etc.
     *
     * @throws IOException
     * @task TODO: write wms specific elements.
     */
    @SuppressWarnings("deprecation")
    protected void handleLayer(final LayerInfo layer) {
      // HACK: by now all our layers are queryable, since they reference
      // only featuretypes managed by this server
      AttributesImpl qatts = new AttributesImpl();
      boolean queryable = wmsConfig.isQueryable(layer);
      qatts.addAttribute("", "queryable", "queryable", "", queryable ? "1" : "0");
      start("Layer", qatts);
      element("Name", layer.getResource().getNamespace().getPrefix() + ":" + layer.getName());
      // REVISIT: this is bad, layer should have title and anbstract by itself
      element("Title", layer.getResource().getTitle());
      element("Abstract", layer.getResource().getAbstract());
      handleKeywordList(layer.getResource().getKeywords());

      /**
       * @task REVISIT: should getSRS() return the full URL? no - the spec says it should be a set
       *     of <SRS>EPSG:#</SRS>...
       */
      final String srs = layer.getResource().getSRS();
      element("SRS", srs);

      // DJB: I want to be nice to the people reading the capabilities
      // file - I'm going to get the
      // human readable name and stick it in the capabilities file
      // NOTE: this isnt well done because "comment()" isnt in the
      // ContentHandler interface...
      try {
        CoordinateReferenceSystem crs = layer.getResource().getCRS();
        String desc = "WKT definition of this CRS:\n" + crs;
        comment(desc);
      } catch (Exception e) {
        if (LOGGER.isLoggable(Level.WARNING)) {
          LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
        }
      }

      Envelope bbox;
      try {
        bbox = layer.getResource().boundingBox();
      } catch (Exception e) {
        throw new RuntimeException(
            "Unexpected error obtaining bounding box for layer " + layer.getName(), e);
      }
      Envelope llbbox = layer.getResource().getLatLonBoundingBox();

      handleLatLonBBox(llbbox);
      // the native bbox might be null
      if (bbox != null) {
        handleBBox(bbox, srs);
      }

      // handle dimensions
      String timeMetadata = null;
      String elevationMetadata = null;

      if (layer.getType() == Type.VECTOR) {
        dimensionHelper.handleVectorLayerDimensions(layer);
      } else if (layer.getType() == Type.RASTER) {
        dimensionHelper.handleRasterLayerDimensions(layer);
      }

      // handle data attribution
      handleAttribution(layer);

      // handle metadata URLs
      handleMetadataList(layer.getResource().getMetadataLinks());

      if (layer.getResource() instanceof WMSLayerInfo) {
        // do nothing for the moment, we may want to list the set of cascaded named styles
        // in the future (when we add support for that)
      } else {
        // add the layer style
        start("Style");

        StyleInfo defaultStyle = layer.getDefaultStyle();
        if (defaultStyle == null) {
          throw new NullPointerException("Layer " + layer.getName() + " has no default style");
        }
        Style ftStyle;
        try {
          ftStyle = defaultStyle.getStyle();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
        element("Name", defaultStyle.getName());
        element("Title", ftStyle.getTitle());
        element("Abstract", ftStyle.getAbstract());
        handleLegendURL(layer.getName(), layer.getLegend(), null);
        end("Style");

        Set<StyleInfo> styles = layer.getStyles();

        for (StyleInfo styleInfo : styles) {
          try {
            ftStyle = styleInfo.getStyle();
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
          start("Style");
          element("Name", styleInfo.getName());
          element("Title", ftStyle.getTitle());
          element("Abstract", ftStyle.getAbstract());
          handleLegendURL(layer.getName(), null, styleInfo);
          end("Style");
        }
      }

      end("Layer");
    }
Esempio n. 8
0
 /**
  * Returns the appropriate icon for the specified layer
  *
  * @param info
  * @return
  */
 public ResourceReference getLayerIcon(LayerInfo info) {
   ResourceReference icon = UNKNOWN_ICON;
   if (info.getType() == Type.VECTOR) icon = VECTOR_ICON;
   else if (info.getType() == Type.RASTER) icon = RASTER_ICON;
   return icon;
 }