@SuppressWarnings("unchecked") private void serializeToFeed( OutputStream outputStream, GeolocResultsDto geolocResultsDto, String feedVersion, int startPaginationIndex) { SyndFeed synFeed = new SyndFeedImpl(); Writer oWriter = null; try { synFeed.setFeedType(feedVersion); synFeed.setTitle(Constants.FEED_TITLE); synFeed.setLink(Constants.FEED_LINK); synFeed.setDescription(Constants.FEED_DESCRIPTION); List<SyndEntry> entries = new ArrayList<SyndEntry>(); for (GisFeatureDistance gisFeatureDistance : geolocResultsDto.getResult()) { SyndEntry entry = new SyndEntryImpl(); GeoRSSModule geoRSSModuleGML = new GMLModuleImpl(); OpenSearchModule openSearchModule = new OpenSearchModuleImpl(); geoRSSModuleGML.setLatitude(gisFeatureDistance.getLat()); geoRSSModuleGML.setLongitude(gisFeatureDistance.getLng()); openSearchModule.setItemsPerPage(Pagination.DEFAULT_MAX_RESULTS); openSearchModule.setTotalResults(geolocResultsDto.getNumFound()); openSearchModule.setStartIndex(startPaginationIndex); entry.getModules().add(openSearchModule); entry.getModules().add(geoRSSModuleGML); entry.setTitle(gisFeatureDistance.getName()); entry.setAuthor(Constants.MAIL_ADDRESS); entry.setLink(Constants.GISFEATURE_BASE_URL + +gisFeatureDistance.getFeatureId()); SyndContent description = new SyndContentImpl(); description.setType(OutputFormat.ATOM.getContentType()); description.setValue(gisFeatureDistance.getName()); entry.setDescription(description); entries.add(entry); } synFeed.setEntries(entries); try { oWriter = new OutputStreamWriter(outputStream, Constants.CHARSET); } catch (UnsupportedEncodingException e) { throw new RuntimeException("unknow encoding " + Constants.CHARSET); } // Copy synfeed to output SyndFeedOutput output = new SyndFeedOutput(); try { output.output(synFeed, oWriter); // Flush oWriter.flush(); } catch (Exception e) { throw new RuntimeException(e); } } finally { if (oWriter != null) try { oWriter.close(); } catch (IOException e) { throw new RuntimeException(e); } if (outputStream != null) try { outputStream.close(); } catch (IOException e) { throw new RuntimeException(e); } } }