|
1 | 1 | //============================================================================= |
2 | | -//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the |
| 2 | +//=== Copyright (C) 2001-2025 Food and Agriculture Organization of the |
3 | 3 | //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) |
4 | 4 | //=== and United Nations Environment Programme (UNEP) |
5 | 5 | //=== |
@@ -221,9 +221,8 @@ private void collectRecordsFromJson(JsonNode jsonObj, |
221 | 221 | params.recordIdPath, e.getMessage())); |
222 | 222 | } |
223 | 223 | String apiUrlPath = params.url.split("\\?")[0]; |
224 | | - URL apiUrl = null; |
225 | 224 | try { |
226 | | - apiUrl = new URL(apiUrlPath); |
| 225 | + URL apiUrl = new URL(apiUrlPath); |
227 | 226 | String nodeUrl = new StringBuilder(apiUrl.getProtocol()).append("://").append(apiUrl.getAuthority()).toString(); |
228 | 227 | Element xml = convertJsonRecordToXml(jsonRecord, uuid, apiUrlPath, nodeUrl); |
229 | 228 | uuids.put(uuid, xml); |
@@ -277,10 +276,8 @@ private void collectRecordsFromXml(Element xmlObj, |
277 | 276 | log.debug(String.format("%d records found in XML response.", xmlNodes.size())); |
278 | 277 |
|
279 | 278 | xmlNodes.forEach(element -> { |
280 | | - String uuid = |
281 | | - null; |
282 | 279 | try { |
283 | | - uuid = getXmlElementTextValue(Xml.selectSingle(element, params.recordIdPath, element.getAdditionalNamespaces())); |
| 280 | + String uuid = getXmlElementTextValue(Xml.selectSingle(element, params.recordIdPath, element.getAdditionalNamespaces())); |
284 | 281 | uuids.put(uuid, applyConversion(element, null)); |
285 | 282 | } catch (JDOMException e) { |
286 | 283 | log.error(String.format("Failed to extract UUID for record. Error is %s.", |
@@ -333,7 +330,7 @@ protected List<String> buildListOfUrl(SimpleUrlParams params, int numberOfRecord |
333 | 330 | } |
334 | 331 |
|
335 | 332 | final String pageFromParamValue = params.url.replaceAll(".*[?&]" + params.pageFromParam + "=([0-9]+).*", "$1"); |
336 | | - boolean startAtZero = false; |
| 333 | + boolean startAtZero; |
337 | 334 | if (StringUtils.isNumeric(pageFromParamValue)) { |
338 | 335 | startAtZero = Integer.parseInt(pageFromParamValue) == 0; |
339 | 336 | } else { |
@@ -370,7 +367,7 @@ private Element convertJsonRecordToXml(JsonNode jsonRecord, String uuid, String |
370 | 367 | recordAsXml = Xml.stripNonValidXMLCharacters(recordAsXml) |
371 | 368 | .replace("<@", "<") |
372 | 369 | .replace("</@", "</") |
373 | | - .replaceAll("(:)(?![^<>]*<)", "_"); // this removes colon from property names |
| 370 | + .replaceAll("(:|%)(?![^<>]*<)", "_"); // this removes colon and % from property names |
374 | 371 | Element recordAsElement = Xml.loadString(recordAsXml, false); |
375 | 372 | recordAsElement.addContent(new Element("uuid").setText(uuid)); |
376 | 373 | recordAsElement.addContent(new Element("apiUrl").setText(apiUrl)); |
|
0 commit comments