/** * Write a java.util.List out as a JSON Array. The values of the array will be converted using * ike standard primitive conversions. If the list contains List or Map objects, they will be * serialized as JSON Arrays and JSON Objects respectively. * * @param list a java.util.List to be serialized as JSON Array */ public JSONBuilder writeList(final List list) { this.array(); for (final Object o : list) { this.value(o); } return this.endArray(); }
/** Encodes linked features as a JSON array. */ private void encodeLinkedFeatures( String attributeName, List<Map<NameImpl, String>> linkedFeatures) { // start the JSON object jsonWriter.key(attributeName); jsonWriter.array(); // encode each linked feature for (Map<NameImpl, String> feature : linkedFeatures) { encodeAttributes(feature); } // end the linked features JSON array jsonWriter.endArray(); }
@Override public RawMap build(WMSMapContent mapContent) throws IOException { jsonWriter.endArray(); // end features jsonWriter.endObject();// end root object writer.flush(); writer.close(); out.close(); long length; RawMap map; if (out.isInMemory()) { byte[] data = out.getData(); length = data.length; map = new RawMap(mapContent, data, MIME_TYPE); } else { File f = out.getFile(); length = f.length(); map = new DeferredFileOutputStreamWebMap(mapContent, out, MIME_TYPE); } map.setResponseHeader("Content-Length", String.valueOf(length)); return map; } }
@Override public RawMap build(WMSMapContent mapContent) throws IOException { jsonWriter.endArray(); // end features jsonWriter.endObject(); // end root object writer.flush(); writer.close(); out.close(); long length; RawMap map; if (out.isInMemory()) { byte[] data = out.getData(); length = data.length; map = new RawMap(mapContent, data, MIME_TYPE); } else { File f = out.getFile(); length = f.length(); map = new DeferredFileOutputStreamWebMap(mapContent, out, MIME_TYPE); } map.setResponseHeader("Content-Length", String.valueOf(length)); return map; } }
private JSONBuilder writeGeomCollection(GeometryCollection collection) { this.key("geometries"); this.array(); for (int i = 0, n = collection.getNumGeometries(); i < n; i++) { writeGeom(collection.getGeometryN(i)); } return this.endArray(); }
return this.endArray();
/** * Encode a simple attribute, this means that this property will be encoded as a simple JSON * attribute if no attributes are available, otherwise it will be encoded as an array containing * the value and attributes values. */ private void encodeSimpleAttribute( String name, Object value, Map<NameImpl, String> attributes) { // let's see if we need to encode attributes or simple value if (attributes == null || attributes.isEmpty()) { // add a simple JSON attribute to the current object jsonWriter.key(name).value(value); return; } // we need to encode a list of attributes, let's first encode the main value jsonWriter.key(name).array(); jsonWriter.value(value); // encode the attributes list encodeAttributes(attributes); // close the values \ attributes array jsonWriter.endArray(); }
/** Encode a complex attribute as a JSON object. */ private void encodeComplexAttribute( ComplexAttribute attribute, Map<NameImpl, String> attributes) { // get the attribute name and start a JSON object String name = attribute.getName().getLocalPart(); jsonWriter.key(name); if (attributes != null && !attributes.isEmpty()) { // we have some attributes to encode jsonWriter.array(); } // let's see if we have actually some properties to encode if (attribute.getProperties() != null && !attribute.getProperties().isEmpty()) { jsonWriter.object(); // encode the object properties, since this is not a top feature or a // chained feature we don't need to explicitly handle the geometry attribute encodeProperties(null, attribute.getType(), attribute.getProperties()); // end the attribute JSON object jsonWriter.endObject(); } if (attributes != null && !attributes.isEmpty()) { // encode the attributes list encodeAttributes(attributes); jsonWriter.endArray(); } }
/** Encodes a list of features (chained features) as a JSON array. */ private void encodeChainedFeatures(String attributeName, List<Feature> chainedFeatures) { // start the JSON object jsonWriter.key(attributeName); jsonWriter.array(); for (Feature feature : chainedFeatures) { // encode each chained feature jsonWriter.object(); encodeProperties(null, feature.getType(), feature.getProperties()); jsonWriter.endObject(); } // end the JSON chained features array jsonWriter.endArray(); }
/** * Helper method that encodes a sequence of coordinates to the JSON output as an array. This * method will respect the configured axis order. If activated, coordinates measures (M) will be * encoded, otherwise measures will be ignored. * * @param coordinates the coordinates sequence that will be encoded * @return the JSON builder instance, this allow chained calls */ private JSONBuilder writeCoordinates(CoordinateSequence coordinates) throws JSONException { // start encoding the JSON array of coordinates this.array(); // each coordinate will be encoded has an array of ordinates for (int i = 0; i < coordinates.size(); i++) { // let's see if we need to encode measures, NaN values will not be encoded double m = encodeMeasures ? coordinates.getM(i) : Double.NaN; // encode the coordinate ordinates to the JSON output writeCoordinate(coordinates.getX(i), coordinates.getY(i), coordinates.getZ(i), m); } // we are done with the array return this.endArray(); }
/** * Writes a polygon * * @param geometry The polygon to write * @throws JSONException */ private void writePolygon(Polygon geometry) throws JSONException { this.array(); writeCoordinates(geometry.getExteriorRing().getCoordinateSequence()); for (int i = 0, ii = geometry.getNumInteriorRing(); i < ii; i++) { writeCoordinates(geometry.getInteriorRingN(i).getCoordinateSequence()); } this.endArray(); // end the linear ring // this.endObject(); //end the }
FeaturesInfo featuresInfo = writeFeatures(resultsList, operation, isComplex, jsonWriter); jsonWriter.endArray(); // end features boolean hasGeom = featuresInfo.hasGeometry; CoordinateReferenceSystem crs = featuresInfo.crs;
/** * Writes WFS3 compliant paging links * * @param response * @param operation * @param jw */ protected void writePagingLinks( FeatureCollectionResponse response, Operation operation, GeoJSONBuilder jw) { if (response.getPrevious() != null || response.getNext() != null) { jw.key("links"); jw.array(); String mimeType = getMimeType(response, operation); writeLink(jw, "previous page", mimeType, "previous", response.getPrevious()); writeLink(jw, "next page", mimeType, "next", response.getNext()); jw.endArray(); } }
/** * Turns an envelope into an array [minX,minY,maxX,maxY] * * @param env envelope representing bounding box * @return this */ protected JSONBuilder writeBoundingBox(Envelope env) { this.key("bbox"); this.array(); if (axisOrder == CRS.AxisOrder.NORTH_EAST) { roundedValue(env.getMinY()); roundedValue(env.getMinX()); roundedValue(env.getMaxY()); roundedValue(env.getMaxX()); } else { roundedValue(env.getMinX()); roundedValue(env.getMinY()); roundedValue(env.getMaxX()); roundedValue(env.getMaxY()); } return this.endArray(); }