private void loadOwsContext() throws LayerException { if (jaxbMapContext != null) { // Load bounding box if (jaxbMapContext.getGeneral().getBoundingBox() != null) { List<Double> lowerCorner = jaxbMapContext.getGeneral().getBoundingBox().getValue().getLowerCorner(); List<Double> upperCorner = jaxbMapContext.getGeneral().getBoundingBox().getValue().getUpperCorner(); if (lowerCorner.size() >= 2 && upperCorner.size() >= 2) { setBoundingBox( new Envelope( lowerCorner.get(0), upperCorner.get(0), lowerCorner.get(1), upperCorner.get(1))); } } // Load title Description nextDescription = new Description(); if (jaxbMapContext.getGeneral().getTitle() != null) { LanguageStringType title = jaxbMapContext.getGeneral().getTitle(); Locale locale; if (title.getLang() != null) { locale = LocalizedText.forLanguageTag(title.getLang()); } else { locale = Locale.getDefault(); } nextDescription.addTitle(locale, title.getValue()); } // Load abstract if (jaxbMapContext.getGeneral().getAbstract() != null) { LanguageStringType mapAbstract = jaxbMapContext.getGeneral().getAbstract(); Locale locale; if (mapAbstract.getLang() != null) { locale = LocalizedText.forLanguageTag(mapAbstract.getLang()); } else { locale = Locale.getDefault(); } nextDescription.addAbstract(locale, mapAbstract.getValue()); } setDescription(nextDescription); // Collect DataSource URI already loaded // Load layers and DataSource // Root layer correspond to ResourceList setRootLayer(createLayerCollection("root")); for (LayerType lt : jaxbMapContext.getResourceList().getLayer()) { try { parseJaxbLayer(lt, getLayerModel()); } catch (LayerException ex) { // The layer is not created if a layer exception is thrown LOGGER.error(I18N.tr("The layer has not been imported"), ex); } } } }
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; }