@Test public void testTransformResponse() throws IOException { final String xslt = IOHelper.readString(this.getClass().getResourceAsStream("iceland.xsl")); final String xml = IOHelper.readString(this.getClass().getResourceAsStream("iceland.xml")); GetGeoPointDataService service = new GetGeoPointDataService(); assertNotNull(xslt); assertNotNull(xml); String response = service.transformResponse(xslt, xml); JSONObject json = JSONHelper.createJSONObject(response); assertNotNull(json); JSONObject parsed = json.optJSONObject("parsed"); assertEquals("Should have html as Mynd", parsed.optString("Mynd"), "<a target='_blank' href='http: assertNotNull(parsed.optString("Staður")); }
protected String transformResponse(final String xslt, final String response) { if (xslt == null || "".equals(xslt)) { return response; } ByteArrayInputStream respInStream = null; ByteArrayInputStream xsltInStream = null; Writer outWriter = null; try { final DocumentBuilderFactory factory = XmlHelper.newDocumentBuilderFactory(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); respInStream = new ByteArrayInputStream(response.getBytes("UTF-8")); final Document document = builder.parse(respInStream); xsltInStream = new ByteArrayInputStream(xslt.getBytes()); final StreamSource stylesource = new StreamSource(xsltInStream); final String transformedResponse = getFormattedJSONString(document, stylesource); if (transformedResponse == null || transformedResponse.isEmpty()) { log.info("got empty result from transform with:", xslt, " - Response:", response); return response; } return transformedResponse; } catch (Exception e) { log.error("Error transforming GFI response: ", response, "- with XSLT:", xslt, "Error:", e.getMessage()); } finally { if (respInStream != null) { try { respInStream.close(); } catch (Exception ignored) { } } if (xsltInStream != null) { try { xsltInStream.close(); } catch (Exception ignored) { } } if (outWriter != null) { try { outWriter.close(); } catch (Exception ignored) { } } } return Jsoup.clean(response, Whitelist.relaxed()); }
GetGeoPointDataService { protected String transformResponse(final String xslt, final String response) { if (xslt == null || "".equals(xslt)) { return response; } ByteArrayInputStream respInStream = null; ByteArrayInputStream xsltInStream = null; Writer outWriter = null; try { final DocumentBuilderFactory factory = XmlHelper.newDocumentBuilderFactory(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); respInStream = new ByteArrayInputStream(response.getBytes("UTF-8")); final Document document = builder.parse(respInStream); xsltInStream = new ByteArrayInputStream(xslt.getBytes()); final StreamSource stylesource = new StreamSource(xsltInStream); final String transformedResponse = getFormattedJSONString(document, stylesource); if (transformedResponse == null || transformedResponse.isEmpty()) { log.info("got empty result from transform with:", xslt, " - Response:", response); return response; } return transformedResponse; } catch (Exception e) { log.error("Error transforming GFI response: ", response, "- with XSLT:", xslt, "Error:", e.getMessage()); } finally { if (respInStream != null) { try { respInStream.close(); } catch (Exception ignored) { } } if (xsltInStream != null) { try { xsltInStream.close(); } catch (Exception ignored) { } } if (outWriter != null) { try { outWriter.close(); } catch (Exception ignored) { } } } return Jsoup.clean(response, Whitelist.relaxed()); } }
GetGeoPointDataService { protected String transformResponse(final String xslt, final String response) { if (xslt == null || "".equals(xslt)) { return response; } ByteArrayInputStream respInStream = null; ByteArrayInputStream xsltInStream = null; Writer outWriter = null; try { final DocumentBuilderFactory factory = XmlHelper.newDocumentBuilderFactory(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); respInStream = new ByteArrayInputStream(response.getBytes("UTF-8")); final Document document = builder.parse(respInStream); xsltInStream = new ByteArrayInputStream(xslt.getBytes()); final StreamSource stylesource = new StreamSource(xsltInStream); final String transformedResponse = getFormattedJSONString(document, stylesource); if (transformedResponse == null || transformedResponse.isEmpty()) { log.info("got empty result from transform with:", xslt, " - Response:", response); return response; } return transformedResponse; } catch (Exception e) { log.error("Error transforming GFI response: ", response, "- with XSLT:", xslt, "Error:", e.getMessage()); } finally { if (respInStream != null) { try { respInStream.close(); } catch (Exception ignored) { } } if (xsltInStream != null) { try { xsltInStream.close(); } catch (Exception ignored) { } } if (outWriter != null) { try { outWriter.close(); } catch (Exception ignored) { } } } return Jsoup.clean(response, Whitelist.relaxed()); }  }
GetGeoPointDataService { protected String transformResponse(final String xslt, final String response) { if (xslt == null || "".equals(xslt)) { return response; } ByteArrayInputStream respInStream = null; ByteArrayInputStream xsltInStream = null; Writer outWriter = null; try { final DocumentBuilderFactory factory = XmlHelper.newDocumentBuilderFactory(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); respInStream = new ByteArrayInputStream(response.getBytes("UTF-8")); final Document document = builder.parse(respInStream); xsltInStream = new ByteArrayInputStream(xslt.getBytes()); final StreamSource stylesource = new StreamSource(xsltInStream); final String transformedResponse = getFormattedJSONString(document, stylesource); if (transformedResponse == null || transformedResponse.isEmpty()) { log.info("got empty result from transform with:", xslt, " - Response:", response); return response; } return transformedResponse; } catch (Exception e) { log.error("Error transforming GFI response: ", response, "- with XSLT:", xslt, "Error:", e.getMessage()); } finally { if (respInStream != null) { try { respInStream.close(); } catch (Exception ignored) { } } if (xsltInStream != null) { try { xsltInStream.close(); } catch (Exception ignored) { } } if (outWriter != null) { try { outWriter.close(); } catch (Exception ignored) { } } } return Jsoup.clean(response, Whitelist.relaxed()); }  JSONObject getWMSFeatureInfo(final GFIRequestParams params); static String getSafeHtmlContent(String response, String url); JSONObject getRESTFeatureInfo(final GFIRestQueryParams params); static String getFormattedJSONString(Document document, StreamSource stylesource); }
GetGeoPointDataService { protected String transformResponse(final String xslt, final String response) { if (xslt == null || "".equals(xslt)) { return response; } ByteArrayInputStream respInStream = null; ByteArrayInputStream xsltInStream = null; Writer outWriter = null; try { final DocumentBuilderFactory factory = XmlHelper.newDocumentBuilderFactory(); factory.setNamespaceAware(true); final DocumentBuilder builder = factory.newDocumentBuilder(); respInStream = new ByteArrayInputStream(response.getBytes("UTF-8")); final Document document = builder.parse(respInStream); xsltInStream = new ByteArrayInputStream(xslt.getBytes()); final StreamSource stylesource = new StreamSource(xsltInStream); final String transformedResponse = getFormattedJSONString(document, stylesource); if (transformedResponse == null || transformedResponse.isEmpty()) { log.info("got empty result from transform with:", xslt, " - Response:", response); return response; } return transformedResponse; } catch (Exception e) { log.error("Error transforming GFI response: ", response, "- with XSLT:", xslt, "Error:", e.getMessage()); } finally { if (respInStream != null) { try { respInStream.close(); } catch (Exception ignored) { } } if (xsltInStream != null) { try { xsltInStream.close(); } catch (Exception ignored) { } } if (outWriter != null) { try { outWriter.close(); } catch (Exception ignored) { } } } return Jsoup.clean(response, Whitelist.relaxed()); }  JSONObject getWMSFeatureInfo(final GFIRequestParams params); static String getSafeHtmlContent(String response, String url); JSONObject getRESTFeatureInfo(final GFIRestQueryParams params); static String getFormattedJSONString(Document document, StreamSource stylesource); static final String TYPE; static final String LAYER_ID; static final String PRESENTATION_TYPE; static final String CONTENT; static final String PARSED; static final String GFI_CONTENT; static final String KEY_INFO; static final String MESSAGE_NO_SUPPORT; static final String REST_KEY_FEATURES; static final String REST_KEY_ATTRIBUTES; static final String PRESENTATION_TYPE_JSON; static final String PRESENTATION_TYPE_TEXT; }