CSWISORecordParser { public CSWIsoRecord parse(final Node elem, final Locale locale, MathTransform transform) throws XPathExpressionException, ParseException, TransformException { int i; Node node; NodeList nodeList; CSWIsoRecord record = new CSWIsoRecord(); final Map<String, String> locales = getLocaleMap(elem); String value; XPathExpression pathToLocalizedValue = null; if (locales != null && locales.containsKey(locale.getISO3Language())) { pathToLocalizedValue = xpath.compile( "../gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale='#" + locales.get(locale.getISO3Language()) + "']"); } nodeList = (NodeList) XPATH_DI_SI.evaluate(elem, XPathConstants.NODESET); if (nodeList.getLength() > 0) { parseIdentifications(nodeList, record.getIdentifications(), transform, pathToLocalizedValue); } nodeList = (NodeList) XPATH_DATA_QUALITY.evaluate(elem, XPathConstants.NODESET); if (nodeList.getLength() > 0) { try { CSWISORecordDataQualityParser dataQualityParser = new CSWISORecordDataQualityParser(); record.setDataQualityObject(dataQualityParser.parseDataQualities(nodeList, pathToLocalizedValue)); } catch (Exception e) { log.warn("parseDataQualities FAIL! "+e.getMessage()); } } node = (Node) XPATH_DISTRIBUTION_INFO.evaluate(elem, XPathConstants.NODE); if (node != null) { parseDistributionInfo(node, record, pathToLocalizedValue); } node = (Node) XPATH_FILE_IDENTIFIER.evaluate(elem, XPathConstants.NODE); if (node != null) { record.setFileIdentifier(getLocalizedContent(node, pathToLocalizedValue)); } nodeList = (NodeList) XPATH_SCOPE_CODES.evaluate(elem, XPathConstants.NODESET); List<String> list = record.getScopeCodes(); for (i = 0; i < nodeList.getLength(); i++) { list.add(getText(nodeList.item(i))); } node = (Node) XPATH_METADATA_STANDARD_NAME.evaluate(elem, XPathConstants.NODE); if (node != null) { record.setMetadataStandardName(getLocalizedContent(node, pathToLocalizedValue)); } node = (Node) XPATH_METADATA_STANDARD_VERSION.evaluate(elem, XPathConstants.NODE); if (node != null) { record.setMetadataStandardVersion(getLocalizedContent(node, pathToLocalizedValue)); } node = (Node) XPATH_LANGUAGE.evaluate(elem, XPathConstants.NODE); if (node != null) { record.setMetadataLanguage(getLanguageIfAvailable(getLocalizedContent(node, pathToLocalizedValue))); } node = (Node) XPATH_METADATA_CHARSET.evaluate(elem, XPathConstants.NODE); if (node != null) { record.setMetadataCharacterSet(getLocalizedContent(node, pathToLocalizedValue)); } nodeList = (NodeList) XPATH_METADATA_RESPONSIBLE_PARTIES.evaluate(elem, XPathConstants.NODESET); List<CSWIsoRecord.ResponsibleParty> rpList = record.getMetadataResponsibleParties(); parseResponsibleParties(nodeList, rpList, pathToLocalizedValue); node = (Node) XPATH_METADATA_DATE.evaluate(elem, XPathConstants.NODE); if (node != null) { value = getLocalizedContent(node, pathToLocalizedValue); try{ record.setMetadataDateStamp(LocalDateTime.parse(value, DATE_TIME_FORMAT)); }catch (Exception e){ } } nodeList = (NodeList) XPATH_METADATA_REFERENCESYSTEM.evaluate(elem, XPathConstants.NODESET); List<String> referenceSystemList = record.getReferenceSystems(); for (i = 0; i < nodeList.getLength(); i++) { referenceSystemList.add(getText(nodeList.item(i))); } return record; } CSWISORecordParser(); CSWIsoRecord parse(final Node elem, final Locale locale, MathTransform transform);  }
@Test public void TestDateParsing() { Node metaDataNode = getMetadataNode(); MathTransform transform = getMathTransform(); Locale locale = new Locale("EN"); CSWISORecordParser parser; try { parser = new CSWISORecordParser(); CSWIsoRecord metadata = parser.parse(metaDataNode, locale, transform); JSONObject json = metadata.toJSON(); assertEquals("2017-04-21T11:24Z", json.get("metadataDateStamp")); } catch (Exception e) { e.printStackTrace(); } }