@@ -0,0 +1,2772 @@
+/*%0A * Copyright (C) 2016 B3Partners B.V.%0A *%0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A *%0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU General Public License for more details.%0A *%0A * You should have received a copy of the GNU General Public License%0A * along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0Apackage nl.b3p.viewer.features;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.io.PrintWriter;%0Aimport java.io.StringWriter;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport nl.b3p.viewer.config.app.ConfiguredAttribute;%0Aimport nl.b3p.viewer.config.services.AttributeDescriptor;%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0Aimport org.geotools.data.simple.SimpleFeatureSource;%0Aimport org.geotools.geojson.feature.FeatureJSON;%0Aimport org.json.JSONArray;%0Aimport org.json.JSONObject;%0Aimport org.opengis.feature.simple.SimpleFeature;%0A%0A/**%0A *%0A * @author meine%0A */%0Apublic class GeoJSONDownloader extends FeatureDownloader%7B%0A    private static final Log log = LogFactory.getLog(GeoJSONDownloader.class);%0A%0A    private FeatureJSON fjson;%0A    private JSONArray features = new JSONArray();%0A    %0A    public GeoJSONDownloader(List%3CConfiguredAttribute%3E attributes, SimpleFeatureSource fs, Map%3CString, AttributeDescriptor%3E featureTypeAttributes, Map%3CString, String%3E attributeAliases, String params) %7B%0A        super(attributes, fs, featureTypeAttributes, attributeAliases, params);%0A        %0A    %7D%0A%0A    @Override%0A    public void init() throws IOException %7B%0A        fjson = new FeatureJSON();%0A    %7D%0A%0A    @Override%0A    public void processFeature(SimpleFeature oldFeature) %7B%0A        try %7B%0A            StringWriter sw = new StringWriter();%0A            fjson.writeFeature(oldFeature, sw);%0A            JSONObject featureObject = new JSONObject(sw.toString());%0A            features.put(featureObject);%0A        %7D catch (IOException ex) %7B%0A            log.error(%22Cannot write feature: %22, ex);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public File write() throws IOException %7B%0A        JSONObject featureCollection = new JSONObject();%0A        featureCollection.put(%22type%22, %22FeatureCollection%22);%0A        featureCollection.put(%22features%22, features);%0A        %0A        File f = File.createTempFile(%22GeoJSON%22, %22.json%22);%0A        PrintWriter pw = new PrintWriter(f);%0A        pw.write(featureCollection.toString());%0A        pw.close();%0A        return f;%0A    %7D%0A    %0A%7D%0A

Create GeoJSON feature downloader