@Override protected void encodeFeature(Feature feature) { super.encodeFeature(feature); writeExtraFeatureProperties(feature, operation, jsonWriter); } };
/** capabilities output format string. */ public String getCapabilitiesElementName() { return JSONType.getJSONType(getOutputFormat()).toString(); }
/** 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(); }
/** 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(); }
/** * 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(); } }
/** * 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(); }
@Test public void testMimeType() { // MimeType assertNotSame(JSONType.json, JSONType.jsonp); assertTrue(JSONType.isJsonMimeType(JSONType.json)); // enable JsonP programmatically JSONType.setJsonpEnabled(true); // check jsonp is enabled assertTrue(JSONType.useJsonp(JSONType.jsonp)); // disable JsonP JSONType.setJsonpEnabled(false); assertFalse(JSONType.useJsonp(JSONType.jsonp)); }
/** * Check if the passed MimeType is a valid jsonp and if jsonp is enabled * * @param type the MimeType string representation to check * @return true if type is equalsIgnoreCase to {@link #jsonp} and jsonp is enabled * @see {@link JSONType#isJsonMimeType(String)} */ public static boolean useJsonp(String type) { return JSONType.isJsonpEnabled() && JSONType.isJsonpMimeType(type); }
@Test public void testJSONType() { // ENUM type JSONType json = JSONType.JSON; assertEquals(JSONType.JSON, json); JSONType jsonp = JSONType.JSONP; assertEquals(JSONType.JSONP, jsonp); assertEquals(JSONType.JSON, JSONType.getJSONType(JSONType.json)); assertEquals(JSONType.JSONP, JSONType.getJSONType(JSONType.jsonp)); }
/** * get an array containing all the MimeType handled by this object * * @return return a string array of handled MimeType */ public static String[] getSupportedTypes() { if (isJsonpEnabled()) return new String[] {json, simple_json, jsonp}; else return new String[] {json, simple_json}; }
@Test public void testDescribePrimitiveGeoFeatureJSON() throws Exception { String output = getAsString( "wfs?service=WFS&request=DescribeFeatureType&version=1.0.0&outputFormat=" + JSONType.json + "&typeName=" + getLayerId(SystemTestData.PRIMITIVEGEOFEATURE)); testOutput(output); }
@Override protected void writeCollectionCRS(GeoJSONBuilder jsonWriter, CoordinateReferenceSystem crs) throws IOException { // write the CRS block only if needed if (!CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)) { super.writeCollectionCRS(jsonWriter, crs); } }
private JSONBuilder writeCoordinate(double x, double y) { return writeCoordinate(x, y, Double.NaN); }
@Test public void testGetFeatureAxisSwap() throws Exception { // Check that a NORTH_EAST source is swapped doAxisSwapTest(POINT_LATLON, CRS.AxisOrder.NORTH_EAST); }
@Override public String getMimeType(Object value, Operation operation) throws ServiceException { return getOutputFormat(); } }
/** Returns the mime type */ public String getMimeType(Object value, Operation operation) throws ServiceException { if (jsonp) { return JSONType.JSONP.getMimeType(); } else { return JSONType.JSON.getMimeType(); } }
public GeoJSONGetFeatureResponse(GeoServer gs, String format) { super(gs, format); jsonp = JSONType.isJsonpMimeType(format); }
public void write(List<FeatureCollection> collections) { for (FeatureCollection collection : collections) { // encode the feature collection making sure that the collection is closed try (FeatureIterator iterator = collection.features()) { encodeFeatureCollection(iterator); } } }
private JSONBuilder writeCoordinate(double x, double y, double z) { return writeCoordinate(x, y, z, Double.NaN); }
@Test public void testGetFeatureNoAxisSwap() throws Exception { // Check that an EAST_NORTH source is not swapped doAxisSwapTest(POINT_LONLAT, CRS.AxisOrder.EAST_NORTH); }