示例#1
0
  private OWSContextType createJaxbMapContext() {
    // Create jaxbcontext data
    ObjectFactory ows_context_factory = new ObjectFactory();
    net.opengis.ows._2.ObjectFactory ows_factory = new net.opengis.ows._2.ObjectFactory();

    OWSContextType mapContextSerialisation = ows_context_factory.createOWSContextType();

    // GeneralType
    mapContextSerialisation.setGeneral(ows_context_factory.createGeneralType());

    // GeneralType:Bounding Box
    if (boundingBox != null) {
      BoundingBoxType bbox = ows_factory.createBoundingBoxType();
      bbox.getLowerCorner().add(boundingBox.getMinX());
      bbox.getLowerCorner().add(boundingBox.getMinY());
      bbox.getUpperCorner().add(boundingBox.getMaxX());
      bbox.getUpperCorner().add(boundingBox.getMaxY());
      mapContextSerialisation.getGeneral().setBoundingBox(ows_factory.createBoundingBox(bbox));
    }
    // GeneralType:Title
    Map<Locale, String> titles = description.getTitles();
    if (!titles.isEmpty()) {
      // Take the first one
      for (Entry<Locale, String> entry : titles.entrySet()) {
        LanguageStringType title = ows_factory.createLanguageStringType();
        title.setLang(LocalizedText.toLanguageTag(entry.getKey()));
        title.setValue(entry.getValue());
        mapContextSerialisation.getGeneral().setTitle(title);
        break; // Ows-context does not support multi-lingual
      }
    }
    // GeneralType:Abstract
    Map<Locale, String> abstracts = description.getAbstractTexts();
    if (!abstracts.isEmpty()) {
      // Take the first one
      for (Entry<Locale, String> entry : abstracts.entrySet()) {
        LanguageStringType mapAbstract = ows_factory.createLanguageStringType();
        mapAbstract.setLang(LocalizedText.toLanguageTag(entry.getKey()));
        mapAbstract.setValue(entry.getValue());
        mapContextSerialisation.getGeneral().setAbstract(mapAbstract);
        break; // Ows-context does not support multi-lingual
      }
    }
    // ResourceList
    ResourceListType rs = ows_context_factory.createResourceListType();
    mapContextSerialisation.setResourceList(rs);

    // LayerList
    if (layerModel != null) {
      List<LayerType> rootLayerList = rs.getLayer();
      ILayer[] rootLayers = layerModel.getChildren();
      for (ILayer layer : rootLayers) {
        if (layer.isSerializable()) {
          rootLayerList.add(createJAXBFromLayer(layer, this));
        }
      }
    }
    return mapContextSerialisation;
  }
示例#2
0
  private static LayerType createJAXBFromLayer(ILayer layer, MapContext mapContext) {
    ObjectFactory ows_context_factory = new ObjectFactory();
    LayerType layerType = ows_context_factory.createLayerType();
    Description description = layer.getDescription();
    description.initJAXBType(layerType);
    layerType.setHidden(!layer.isVisible());
    ILayer[] childrens = layer.getChildren();
    for (ILayer child : childrens) {
      if (child.isSerializable()) {
        layerType.getLayer().add(createJAXBFromLayer(child, mapContext));
      }
    }
    // If not a Layer Collection
    if (!(layer instanceof LayerCollection) && layer.getStyles() != null) {
      StyleListType slt = ows_context_factory.createStyleListType();
      layerType.setStyleList(slt);
      for (Style style : layer.getStyles()) {
        StyleType st = ows_context_factory.createStyleType();
        slt.getStyle().add(st);
        SLDType sltType = ows_context_factory.createSLDType();
        st.setSLD(sltType);
        sltType.setAbstractStyle(style.getJAXBElement());
      }
    }

    // Serialisation of dataSource as a DataUrl string
    // Create jaxb instances
    URLType dataURL = ows_context_factory.createURLType();
    if (!(layer instanceof LayerCollection)) {
      OnlineResourceType resource = ows_context_factory.createOnlineResourceType();
      dataURL.setOnlineResource(resource);

      String resourceSerialisation = "";
      URI srcUri = layer.getDataUri();
      if (srcUri != null) {
        // If file, use MapContext relative path
        if (srcUri.getScheme().equalsIgnoreCase("file") && mapContext.getLocation() != null) {
          srcUri = URIUtility.relativize(mapContext.getLocation(), srcUri);
        }
        resourceSerialisation = srcUri.toString();
      }
      resource.setHref(resourceSerialisation);
      if (resource.isSetHref()) {
        layerType.setDataURL(dataURL);
      }
    }
    return layerType;
  }