+ protected void encodeCollectionAsGML(Stream<Content> features, OutputStream out) throws IOException {
+ String entityType = "entity";
+ URL schemaLocation = getClass().getResource("/org/argeo/app/api/entity.xsd");
+ String namespace = "http://www.argeo.org/ns/entity";
+
+ GML gml = new GML(Version.WFS1_1);
+ gml.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
+ gml.setNamespace("local", namespace);
+
+ SimpleFeatureType featureType = gml.decodeSimpleFeatureType(schemaLocation,
+ new NameImpl(namespace, entityType + "Feature"));
+
+// CoordinateReferenceSystem crs=DefaultGeographicCRS.WGS84;
+// QName featureName = new QName(namespace,"apafFieldFeature");
+// GMLConfiguration configuration = new GMLConfiguration();
+// FeatureType parsed = GTXML.parseFeatureType(configuration, featureName, crs);
+// SimpleFeatureType featureType = DataUtilities.simple(parsed);
+
+ SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
+
+ DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
+
+ features.forEach((c) -> {
+// boolean gpx = false;
+ Geometry the_geom = null;
+ Polygon the_area = null;
+// if (gpx) {
+ Content area = c.getContent("gpx/area.gpx").orElse(null);
+ if (area != null) {
+
+ try (InputStream in = area.open(InputStream.class)) {
+ the_area = GpxUtils.parseGpxTrackTo(in, Polygon.class);
+ } catch (IOException e) {
+ throw new UncheckedIOException("Cannot parse " + c, e);
+ }
+ }
+// } else {
+ if (c.hasContentClass(EntityType.geopoint)) {
+ double latitude = c.get(WGS84PosName.lat, Double.class).get();
+ double longitude = c.get(WGS84PosName.lon, Double.class).get();
+
+ Coordinate coordinate = new Coordinate(longitude, latitude);
+ the_geom = JTS.GEOMETRY_FACTORY.createPoint(coordinate);
+ }
+
+// }
+ if (the_geom != null)
+ featureBuilder.set(new NameImpl(namespace, "geopoint"), the_geom);
+ if (the_area != null)
+ featureBuilder.set(new NameImpl(namespace, "area"), the_area);
+
+ List<AttributeDescriptor> attrDescs = featureType.getAttributeDescriptors();
+ for (AttributeDescriptor attrDesc : attrDescs) {
+ if (attrDesc instanceof GeometryAttribute)
+ continue;
+ Name name = attrDesc.getName();
+ QName qName = new QName(name.getNamespaceURI(), name.getLocalPart());
+ String value = c.attr(qName);
+ if (value == null) {
+ value = c.attr(name.getLocalPart());
+ }
+ if (value != null) {
+ featureBuilder.set(name, value);
+ }
+ }
+
+ String uuid = c.attr(LdapAttr.entryUUID);
+
+ SimpleFeature feature = featureBuilder.buildFeature(uuid);
+ featureCollection.add(feature);
+
+ });
+ gml.encode(out, featureCollection);
+ out.close();
+
+ }
+
+ /*
+ * DEPENDENCY INJECTION
+ */
+
+ public void addFeatureAdapter(FeatureAdapter featureAdapter, Map<String, Object> properties) {
+ List<String> typeNames = LangUtils.toStringList(properties.get(WfsKvp.TYPE_NAMES.getKey()));
+ if (typeNames.isEmpty()) {
+ log.warn("FeatureAdapter " + featureAdapter.getClass() + " does not declare type names. Ignoring it...");
+ return;
+ }
+
+ for (String tn : typeNames) {
+ QName typeName = NamespaceUtils.parsePrefixedName(tn);
+ featureAdapters.put(typeName, featureAdapter);
+ }
+ }
+
+ public void removeFeatureAdapter(FeatureAdapter featureAdapter, Map<String, Object> properties) {
+ List<String> typeNames = LangUtils.toStringList(properties.get(WfsKvp.TYPE_NAMES.getKey()));
+ if (!typeNames.isEmpty()) {
+ // ignore if noe type name declared
+ return;
+ }
+
+ for (String tn : typeNames) {
+ QName typeName = NamespaceUtils.parsePrefixedName(tn);
+ featureAdapters.remove(typeName);
+ }
+ }
+