- protected void writeAttr(JsonGenerator g, Content content, String attr) {
- writeAttr(g, content, NamespaceUtils.parsePrefixedName(attr));
- }
-
- protected void writeAttr(JsonGenerator g, Content content, QNamed attr) {
- writeAttr(g, content, attr.qName());
- }
-
- protected void writeAttr(JsonGenerator g, Content content, QName attr) {
- // String value = content.attr(attr);
- Object value = content.get(attr);
- if (value != null) {
- // TODO specify NamespaceContext
- String key = NamespaceUtils.toPrefixedName(attr);
- if (value instanceof Double v)
- g.write(key, v);
- else if (value instanceof Long v)
- g.write(key, v);
- else if (value instanceof Integer v)
- g.write(key, v);
- else if (value instanceof Boolean v)
- g.write(key, v);
- else
- g.write(key, value.toString());
- }
- }
-
- protected void encodeCollectionAsGeoJSonOld(Stream<Content> features, OutputStream out) throws IOException {
-
- // BODY PROCESSING
- try (GeoJSONWriter geoJSONWriter = new GeoJSONWriter(out)) {
- geoJSONWriter.setPrettyPrinting(true);
- geoJSONWriter.setEncodeFeatureBounds(true);
-
- boolean gpx = true;
- SimpleFeatureType TYPE;
- try {
- if (gpx)
- TYPE = DataUtilities.createType("Content",
- "the_geom:Polygon:srid=4326,path:String,type:String,name:String");
- else
- TYPE = DataUtilities.createType("Content",
- "the_geom:Point:srid=4326,path:String,type:String,name:String");
- } catch (SchemaException e) {
- throw new RuntimeException(e);
- }
- SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
-
- features.forEach((c) -> {
- Geometry the_geom;
- if (gpx) {// experimental
- Content area = c.getContent("gpx/area.gpx").orElse(null);
- if (area == null)
- return;
- try (InputStream in = area.open(InputStream.class)) {
- SimpleFeature feature = GpxUtils.parseGpxToPolygon(in);
- the_geom = (Geometry) feature.getDefaultGeometry();
- } catch (IOException e) {
- throw new UncheckedIOException("Cannot parse " + c, e);
- }
- } else {
- if (!c.hasContentClass(EntityType.geopoint))
- return;
-
- double latitude = c.get(WGS84PosName.lat, Double.class).get();
- double longitude = c.get(WGS84PosName.lng, Double.class).get();
-
- Coordinate coordinate = new Coordinate(longitude, latitude);
- the_geom = geometryFactory.createPoint(coordinate);
-
- }
-
- featureBuilder.add(the_geom);
- String pth = c.getPath();
- featureBuilder.add(pth);
- if (c.hasContentClass(EntityType.local)) {
- String type = c.attr(EntityName.type);
- featureBuilder.add(type);
- } else {
- List<QName> contentClasses = c.getContentClasses();
- if (!contentClasses.isEmpty()) {
- featureBuilder.add(NamespaceUtils.toPrefixedName(contentClasses.get(0)));
- }
- }
- featureBuilder.add(NamespaceUtils.toPrefixedName(c.getName()));
-
- String uuid = c.attr(LdapAttr.entryUUID);
-
- SimpleFeature feature = featureBuilder.buildFeature(uuid);
- try {
- geoJSONWriter.write(feature);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- });
- }
- }
-