예제 #1
0
 /**
  * Recursive function to parse a layer tree
  *
  * @param lt
  * @param parentLayer
  */
 private void parseJaxbLayer(LayerType lt, ILayer parentLayer) throws LayerException {
   // Test if lt is a group
   if (!lt.getLayer().isEmpty() || (lt.getDataURL() == null)) {
     // it will create a LayerCollection
     parseJaxbLayerCollection(lt, parentLayer);
   } else {
     // it corresponding to a leaf layer
     // We need to read the data declaration and create the layer
     URLType dataUrl = lt.getDataURL();
     if (dataUrl != null) {
       OnlineResourceType resType = dataUrl.getOnlineResource();
       try {
         URI layerURI = new URI(resType.getHref());
         // The resource is given as relative to MapContext location
         if (!layerURI.isAbsolute() && getLocation() != null) {
           try {
             // Resolve the relative resource ex: new Uri("myFile.shp")
             layerURI = getLocation().resolve(layerURI);
           } catch (IllegalArgumentException ex) {
             LOGGER.warn(
                 "Error while trying to find an absolute path for an external resource", ex);
           }
         }
         // Get table name
         ILayer leafLayer = createLayer(layerURI);
         leafLayer.setDescription(new Description(lt));
         leafLayer.setVisible(!lt.isHidden());
         // Parse styles
         if (lt.isSetStyleList()) {
           for (StyleType st : lt.getStyleList().getStyle()) {
             if (st.isSetSLD()) {
               if (st.getSLD().isSetAbstractStyle()) {
                 leafLayer.addStyle(
                     new Style(
                         (JAXBElement<net.opengis.se._2_0.core.StyleType>)
                             st.getSLD().getAbstractStyle(),
                         leafLayer));
               }
             }
           }
         }
         parentLayer.addLayer(leafLayer);
       } catch (URISyntaxException ex) {
         throw new LayerException(
             I18N.tr("Unable to parse the href URI {0}.", resType.getHref()), ex);
       } catch (InvalidStyle ex) {
         throw new LayerException(
             I18N.tr("Unable to load the description of the layer {0}", lt.getTitle().toString()),
             ex);
       }
     }
   }
 }
예제 #2
0
 /**
  * Recursive function to parse a layer tree
  *
  * @param lt
  * @param parentLayer
  */
 private void parseJaxbLayerCollection(LayerType lt, ILayer parentLayer) throws LayerException {
   LayerCollection layerCollection = new LayerCollection(lt);
   for (LayerType ltc : lt.getLayer()) {
     try {
       parseJaxbLayer(ltc, layerCollection);
     } catch (LayerException ex) {
       // The layer is not created if a layer exception is thrown
       // Create a warning, because the MapContext is loaded
       LOGGER.warn(I18N.tr("The layer has not been imported"), ex);
     }
   }
   parentLayer.addLayer(layerCollection);
 }