List featureCollections = results.getFeature(); int numDecimals = getNumDecimals(featureCollections, geoServer, catalog); boolean padWithZeros = getPadWithZeros(featureCollections, geoServer, catalog); boolean forcedDecimal = getForcedDecimal(featureCollections, geoServer, catalog); WFSInfo wfs = getInfo(); Configuration configuration = customizeConfiguration(this.configuration, ns2metas, gft); boolean encodeMeasures = encodeMeasures(featureCollections, catalog); updateConfiguration( configuration, numDecimals, padWithZeros, forcedDecimal, encodeMeasures); Encoder encoder = createEncoder(configuration, ns2metas, gft); encoder.setSchemaLocation(getWfsNamespace(), getCanonicalWfsSchemaLocation()); } else { encoder.setSchemaLocation( getWfsNamespace(), buildSchemaURL(request.getBaseURL(), getRelativeWfsSchemaLocation())); setAdditionalSchemaLocations(encoder, request, wfs); if (isComplexFeature(results)) { complexFeatureStreamIntercept(results, output, encoder); } else { encode(results, output, encoder);
private void complexFeatureStreamIntercept( FeatureCollectionResponse results, OutputStream output, Encoder encoder) throws IOException { if (this.getXSLT() == null) { throw new FileNotFoundException("Unable to locate xslt resource file"); } // Create a temporary file for the xml dump. _dump is added to ensure the hash create is // more then 3 char. File featureOut = File.createTempFile(output.hashCode() + "_dump", ".xml"); // create a buffered output stream to write the output from encode to disk first BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(featureOut)); // create a buffered input stream to read the dumped xml file in BufferedInputStream in = new BufferedInputStream(new FileInputStream(featureOut)); try { // the output file has to be unique with each Class object to ensure concurrency encode(results, out, encoder); this.transform(in, this.getXSLT(), output); } catch (TransformerException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } finally { out.close(); in.close(); featureOut.delete(); } }
@Test public void testSingle() throws Exception { FeatureSource<? extends FeatureType, ? extends Feature> source = getFeatureSource(MockData.SEVEN); FeatureCollection<? extends FeatureType, ? extends Feature> features = source.getFeatures(); FeatureCollectionResponse fcType = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fcType.getFeature().add(features); ByteArrayOutputStream output = new ByteArrayOutputStream(); producer().write(fcType, output, request(MockData.SEVEN)); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(output.toByteArray())); assertEquals(7, document.getElementsByTagName("cdf:Seven").getLength()); }
GML3OutputFormat producer() { FeatureTypeSchemaBuilder sb = new FeatureTypeSchemaBuilder.GML3(getGeoServer()); WFSConfiguration configuration = new WFSConfiguration(getGeoServer(), sb, new WFS(sb)); return new GML3OutputFormat(getGeoServer(), configuration); }
@Test public void testMultipleSameNamespace() throws Exception { FeatureCollectionResponse fcType = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fcType.getFeature().add(getFeatureSource(MockData.SEVEN).getFeatures()); fcType.getFeature().add(getFeatureSource(MockData.FIFTEEN).getFeatures()); ByteArrayOutputStream output = new ByteArrayOutputStream(); producer().write(fcType, output, request(MockData.SEVEN, MockData.FIFTEEN)); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(output.toByteArray())); assertEquals( 7 + 15, document.getElementsByTagName("cdf:Seven").getLength() + document.getElementsByTagName("cdf:Fifteen").getLength()); }
@Test public void testMultipleDifferentNamespace() throws Exception { FeatureCollectionResponse fcType = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fcType.getFeature().add(getFeatureSource(MockData.SEVEN).getFeatures()); fcType.getFeature().add(getFeatureSource(MockData.POLYGONS).getFeatures()); int npolys = getFeatureSource(MockData.POLYGONS).getFeatures().size(); ByteArrayOutputStream output = new ByteArrayOutputStream(); producer().write(fcType, output, request(MockData.SEVEN, MockData.POLYGONS)); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(output.toByteArray())); assertEquals( 7 + npolys, document.getElementsByTagName("cdf:Seven").getLength() + document.getElementsByTagName("cgf:Polygons").getLength()); } }
outputFormat.write(features, out, opDescriptor);