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 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; }