use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.
the class WFSGetFeatureWizard method addPages.
@Override
public void addPages() {
super.addPages();
/**
* Page for specifying the WFS capabilities URL.
*/
AbstractWFSCapabilitiesPage<WFSGetFeatureConfig> capPage = new AbstractWFSCapabilitiesPage<WFSGetFeatureConfig>(this) {
@Override
protected boolean updateConfiguration(WFSGetFeatureConfig configuration, URL capabilitiesUrl, WFSCapabilities capabilities) {
if (capabilities != null && capabilities.getGetFeatureOp() != null) {
WFSOperation op = capabilities.getGetFeatureOp();
configuration.setGetFeatureUri(URI.create(op.getHttpGetUrl()));
configuration.setVersion(capabilities.getVersion());
return true;
}
setErrorMessage("Invalid capabilities or WFS does not support GetFeature KVP");
return false;
}
};
addPage(capPage);
addPage(new AbstractFeatureTypesPage<WFSGetFeatureConfig>(this, capPage, "Please specify the feature types to request") {
private boolean selectAll = false;
@Override
protected void updateState(Set<QName> selected) {
// at least one type must be specified
setPageComplete(!selected.isEmpty());
}
@Override
protected Collection<? extends QName> initialSelection(Set<QName> types) {
// select all by default
if (selectAll) {
return types;
}
return super.initialSelection(types);
}
@Override
protected Set<QName> filterTypes(Set<QName> types) {
// relevant types
if (schemaSpaceID != null) {
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
if (ss != null) {
Set<QName> relevantElements = new HashSet<>();
SchemaSpace schemas = ss.getSchemas(schemaSpaceID);
for (TypeDefinition type : schemas.getMappingRelevantTypes()) {
XmlElements elms = type.getConstraint(XmlElements.class);
for (XmlElement elm : elms.getElements()) {
relevantElements.add(elm.getName());
}
}
Set<QName> selection = new HashSet<>(types);
selection.retainAll(relevantElements);
// don't filter if we have no match at all
if (!selection.isEmpty()) {
selectAll = true;
return selection;
}
}
}
selectAll = false;
return super.filterTypes(types);
}
@Override
protected boolean updateConfiguration(WFSGetFeatureConfig configuration, Set<QName> selected) {
configuration.getTypeNames().clear();
configuration.getTypeNames().addAll(selected);
return true;
}
});
// bounding box
addPage(new BBOXPage(this, capPage));
// additional params
addPage(new GetFeatureParamsPage(this));
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.
the class WFSFeatureCollectionWriter method createFeatureCollectionElement.
private XmlElement createFeatureCollectionElement(WFSVersion version, XmlIndex targetIndex) {
String wfsNs = version.wfsNamespace;
XmlElement memberElement = null;
switch(version) {
case V1_1_0:
memberElement = targetIndex.getElements().get(new QName(GMLConstants.NS_GML, "_Feature"));
break;
case V2_0_0:
case V2_0_2:
for (XmlElement element : targetIndex.getElements().values()) {
if (element.getName().getLocalPart().equals("AbstractFeature") && element.getName().getNamespaceURI().startsWith(GMLConstants.GML_NAMESPACE_CORE)) {
memberElement = element;
break;
}
}
break;
}
if (memberElement == null) {
throw new IllegalStateException("Unable to identify member types for feature collection");
}
addValidationSchema(version.wfsNamespace, new LocatableURI(version.schemaLocation), "wfs");
List<XmlElement> memberElements = SubstitutionGroupProperty.collectSubstitutions(memberElement.getName(), memberElement.getType());
TypeDefinition fcType = WFSSchemaHelper.createFeatureCollectionType(version, memberElements);
return new XmlElement(new QName(wfsNs, "FeatureCollection"), fcType, null);
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.
the class GmlInstanceCollectionTest method testWVAInstances.
private void testWVAInstances(InstanceCollection instances) {
String ns = "http://www.esdi-humboldt.org/waterVA";
String gmlNs = "http://www.opengis.net/gml";
ResourceIterator<Instance> it = instances.iterator();
try {
assertTrue(it.hasNext());
Instance instance = it.next();
assertNotNull(instance);
// check type and element
TypeDefinition type = instance.getDefinition();
assertEquals(new QName(ns, "Watercourses_VA_Type"), type.getName());
XmlElements elements = type.getConstraint(XmlElements.class);
Collection<? extends XmlElement> elementCollection = elements.getElements();
assertEquals(1, elementCollection.size());
XmlElement element = elementCollection.iterator().next();
assertEquals(new QName(ns, "Watercourses_VA"), element.getName());
// check instance
// check a simple property first (FGW_ID)
Object[] fgwID = instance.getProperty(new QName(ns, "FGW_ID"));
assertNotNull(fgwID);
assertEquals(1, fgwID.length);
assertEquals("81011403", fgwID[0]);
// the_geom
Object[] the_geom = instance.getProperty(new QName(ns, "the_geom"));
assertNotNull(the_geom);
assertEquals(1, the_geom.length);
assertTrue(the_geom[0] instanceof Instance);
// MultiLineString
Object[] multiLineString = ((Instance) the_geom[0]).getProperty(new QName(gmlNs, "MultiLineString"));
assertNotNull(multiLineString);
assertEquals(1, multiLineString.length);
assertTrue(multiLineString[0] instanceof Instance);
// TODO the MultiLineString should have a GeometryProperty value
// with a MultiLineString as geometry and a CRS definition
// ...getValue()
// srsName
Object[] srsName = ((Instance) multiLineString[0]).getProperty(new QName("srsName"));
assertNotNull(srsName);
assertEquals(1, srsName.length);
assertEquals("EPSG:31251", srsName[0].toString());
// lineStringMember
Object[] lineStringMember = ((Instance) multiLineString[0]).getProperty(new QName(gmlNs, "lineStringMember"));
assertNotNull(lineStringMember);
assertEquals(1, lineStringMember.length);
assertTrue(lineStringMember[0] instanceof Instance);
// LineString
Object[] lineString = ((Instance) lineStringMember[0]).getProperty(new QName(gmlNs, "LineString"));
assertNotNull(lineString);
assertEquals(1, lineString.length);
assertTrue(lineString[0] instanceof Instance);
// TODO the LineString should have a GeometryProperty value with a
// LineString as geometry and a CRS definition
// ...getValue()
// choice
Object[] choice_1 = ((Instance) lineString[0]).getProperty(new QName(gmlNs + "/LineStringType", "choice_1"));
assertNotNull(choice_1);
assertEquals(1, choice_1.length);
assertTrue(choice_1[0] instanceof Group);
// coordinates
Object[] coordinates = ((Group) choice_1[0]).getProperty(new QName(gmlNs, "coordinates"));
assertNotNull(coordinates);
assertEquals(1, coordinates.length);
assertTrue(coordinates[0] instanceof Instance);
assertTrue(((Instance) coordinates[0]).getValue().toString().contains("-39799.68820381"));
// only one instance should be present
assertFalse(it.hasNext());
} finally {
it.close();
}
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.
the class RootElementPage method updateConfiguration.
/**
* @see IOWizardPage#updateConfiguration(IOProvider)
*/
@Override
public boolean updateConfiguration(XmlWriterBase provider) {
ISelection sel = list.getSelection();
if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection) sel).getFirstElement();
if (selected instanceof XmlElement) {
QName name = ((XmlElement) selected).getName();
provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAMESPACE, Value.of(name.getNamespaceURI()));
provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAME, Value.of(name.getLocalPart()));
return true;
}
}
provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAMESPACE, null);
provider.setParameter(StreamGmlWriter.PARAM_ROOT_ELEMENT_NAME, null);
return false;
}
use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.
the class StreamGmlWriter method checkCompatibility.
/**
* @see AbstractInstanceWriter#checkCompatibility()
*/
@Override
public void checkCompatibility() throws IOProviderConfigurationException {
super.checkCompatibility();
XmlIndex xmlIndex = getXMLIndex();
if (xmlIndex == null) {
fail("No XML target schema");
}
if (requiresDefaultContainer()) {
XmlElement element;
try {
element = findDefaultContainter(xmlIndex, null);
} catch (Exception e) {
// ignore
element = null;
}
if (element == null) {
fail("Cannot find container element in schema.");
}
}
}
Aggregations