@Test public void parseResult() throws Exception { final StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(getClass().getResourceAsStream("GetRecords-response.xml")); MetadataCatalogueResultParser RESULT_PARSER = new MetadataCatalogueResultParser(); final Iterator<OMElement> results = getResultsElement(stAXOMBuilder).getChildrenWithLocalName("MD_Metadata"); final long start = System.currentTimeMillis(); while(results.hasNext()) { final SearchResultItem item = RESULT_PARSER.parseResult(results.next(), "fi"); } assertTrue("Didn't get exception", true); }
public SearchResultItem parseResult(final OMElement elem, final String locale) throws Exception { final Map<String, String> locales = getLocaleMap(elem); AXIOMXPath pathToLocalizedValue = null; if(locales != null && locales.containsKey(locale)) { pathToLocalizedValue = XmlHelper.buildXPath("../gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale='#" + locales.get(locale) + "']", NAMESPACE_CTX); } final OMElement idNode = (OMElement) XPATH_IDENTIFICATION.selectSingleNode(elem); final SearchResultItem item = new SearchResultItem(); final OMElement titleNode = (OMElement) XPATH_IDENTIFICATION_TITLE.selectSingleNode(idNode); item.setTitle(getLocalizedContent(titleNode, pathToLocalizedValue)); final OMElement descNode = (OMElement) XPATH_IDENTIFICATION_DESC.selectSingleNode(idNode); item.setDescription(getLocalizedContent(descNode, pathToLocalizedValue)); final OMElement imageNode = (OMElement) XPATH_IDENTIFICATION_IMAGE.selectSingleNode(idNode); item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); final OMElement orgNode = (OMElement) XPATH_IDENTIFICATION_ORGANIZATION.selectSingleNode(idNode); item.addValue(MetadataField.RESULT_KEY_ORGANIZATION, getLocalizedContent(orgNode, pathToLocalizedValue)); final OMElement bboxNode = (OMElement) XPATH_IDENTIFICATION_BBOX.selectSingleNode(idNode); setupBBox(item, bboxNode); final OMElement distInfoNode = (OMElement) XPATH_DISTINFO.selectSingleNode(elem); item.setGmdURL(getLocalizedContent(distInfoNode, pathToLocalizedValue)); final OMElement uuidNode = (OMElement) XPATH_FILEID.selectSingleNode(elem); final List<OMElement> operatesOnNodes = XPATH_IDENTIFICATION_UUID.selectNodes(idNode); final OMElement codeNode = (OMElement) XPATH_IDENTIFICATION_CODELIST.selectSingleNode(idNode); final OMElement dateNode = (OMElement) XPATH_IDENTIFICATION_DATE.selectSingleNode(idNode); final OMElement maintenanceAndUpdateFrequencyNode = (OMElement) XPATH_IDENTIFICATION_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST.selectSingleNode(idNode); JSONObject identification = new JSONObject(); identification.put(KEY_IDENTIFICATION_CODELIST, getAttributeValue(codeNode, QName.valueOf("codeListValue"))); identification.put(KEY_IDENTIFICATION_DATE, getLocalizedContent(dateNode, pathToLocalizedValue)); identification.put(KEY_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST, getAttributeValue(maintenanceAndUpdateFrequencyNode, QName.valueOf("codeListValue"))); item.addValue(KEY_IDENTIFICATION, identification); log.debug("==1"); final OMElement codeListValue = (OMElement) XPATH_CODELISTVALUE.selectSingleNode(elem); log.debug("====: " + codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.setNatureOfTarget(codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.addValue(KEY_NATUREOFTHETARGET, item.getNatureOfTarget()); for(OMElement operatesOnNode : operatesOnNodes){ if(operatesOnNode != null){ if(operatesOnNode.getAllAttributes() == null) log.debug("attributes == null"); Iterator<OMAttribute> i = operatesOnNode.getAllAttributes(); if(i.hasNext()){ OMAttribute ao = (OMAttribute)i.next(); log.debug("AO value: " + ao.getAttributeValue()); item.addUuId(ao.getAttributeValue()); } } } item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); item.setResourceId(getLocalizedContent(uuidNode, pathToLocalizedValue)); return item; }
MetadataCatalogueResultParser { public SearchResultItem parseResult(final OMElement elem, final String locale) throws Exception { final Map<String, String> locales = getLocaleMap(elem); AXIOMXPath pathToLocalizedValue = null; if(locales != null && locales.containsKey(locale)) { pathToLocalizedValue = XmlHelper.buildXPath("../gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale='#" + locales.get(locale) + "']", NAMESPACE_CTX); } final OMElement idNode = (OMElement) XPATH_IDENTIFICATION.selectSingleNode(elem); final SearchResultItem item = new SearchResultItem(); final OMElement titleNode = (OMElement) XPATH_IDENTIFICATION_TITLE.selectSingleNode(idNode); item.setTitle(getLocalizedContent(titleNode, pathToLocalizedValue)); final OMElement descNode = (OMElement) XPATH_IDENTIFICATION_DESC.selectSingleNode(idNode); item.setDescription(getLocalizedContent(descNode, pathToLocalizedValue)); final OMElement imageNode = (OMElement) XPATH_IDENTIFICATION_IMAGE.selectSingleNode(idNode); item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); final OMElement orgNode = (OMElement) XPATH_IDENTIFICATION_ORGANIZATION.selectSingleNode(idNode); item.addValue(MetadataField.RESULT_KEY_ORGANIZATION, getLocalizedContent(orgNode, pathToLocalizedValue)); final OMElement bboxNode = (OMElement) XPATH_IDENTIFICATION_BBOX.selectSingleNode(idNode); setupBBox(item, bboxNode); final OMElement distInfoNode = (OMElement) XPATH_DISTINFO.selectSingleNode(elem); item.setGmdURL(getLocalizedContent(distInfoNode, pathToLocalizedValue)); final OMElement uuidNode = (OMElement) XPATH_FILEID.selectSingleNode(elem); final List<OMElement> operatesOnNodes = XPATH_IDENTIFICATION_UUID.selectNodes(idNode); final OMElement codeNode = (OMElement) XPATH_IDENTIFICATION_CODELIST.selectSingleNode(idNode); final OMElement dateNode = (OMElement) XPATH_IDENTIFICATION_DATE.selectSingleNode(idNode); final OMElement maintenanceAndUpdateFrequencyNode = (OMElement) XPATH_IDENTIFICATION_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST.selectSingleNode(idNode); JSONObject identification = new JSONObject(); identification.put(KEY_IDENTIFICATION_CODELIST, getAttributeValue(codeNode, QName.valueOf("codeListValue"))); identification.put(KEY_IDENTIFICATION_DATE, getLocalizedContent(dateNode, pathToLocalizedValue)); identification.put(KEY_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST, getAttributeValue(maintenanceAndUpdateFrequencyNode, QName.valueOf("codeListValue"))); item.addValue(KEY_IDENTIFICATION, identification); log.debug("==1"); final OMElement codeListValue = (OMElement) XPATH_CODELISTVALUE.selectSingleNode(elem); log.debug("====: " + codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.setNatureOfTarget(codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.addValue(KEY_NATUREOFTHETARGET, item.getNatureOfTarget()); for(OMElement operatesOnNode : operatesOnNodes){ if(operatesOnNode != null){ if(operatesOnNode.getAllAttributes() == null) log.debug("attributes == null"); Iterator<OMAttribute> i = operatesOnNode.getAllAttributes(); if(i.hasNext()){ OMAttribute ao = (OMAttribute)i.next(); log.debug("AO value: " + ao.getAttributeValue()); item.addUuId(ao.getAttributeValue()); } } } item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); item.setResourceId(getLocalizedContent(uuidNode, pathToLocalizedValue)); return item; } }
MetadataCatalogueResultParser { public SearchResultItem parseResult(final OMElement elem, final String locale) throws Exception { final Map<String, String> locales = getLocaleMap(elem); AXIOMXPath pathToLocalizedValue = null; if(locales != null && locales.containsKey(locale)) { pathToLocalizedValue = XmlHelper.buildXPath("../gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale='#" + locales.get(locale) + "']", NAMESPACE_CTX); } final OMElement idNode = (OMElement) XPATH_IDENTIFICATION.selectSingleNode(elem); final SearchResultItem item = new SearchResultItem(); final OMElement titleNode = (OMElement) XPATH_IDENTIFICATION_TITLE.selectSingleNode(idNode); item.setTitle(getLocalizedContent(titleNode, pathToLocalizedValue)); final OMElement descNode = (OMElement) XPATH_IDENTIFICATION_DESC.selectSingleNode(idNode); item.setDescription(getLocalizedContent(descNode, pathToLocalizedValue)); final OMElement imageNode = (OMElement) XPATH_IDENTIFICATION_IMAGE.selectSingleNode(idNode); item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); final OMElement orgNode = (OMElement) XPATH_IDENTIFICATION_ORGANIZATION.selectSingleNode(idNode); item.addValue(MetadataField.RESULT_KEY_ORGANIZATION, getLocalizedContent(orgNode, pathToLocalizedValue)); final OMElement bboxNode = (OMElement) XPATH_IDENTIFICATION_BBOX.selectSingleNode(idNode); setupBBox(item, bboxNode); final OMElement distInfoNode = (OMElement) XPATH_DISTINFO.selectSingleNode(elem); item.setGmdURL(getLocalizedContent(distInfoNode, pathToLocalizedValue)); final OMElement uuidNode = (OMElement) XPATH_FILEID.selectSingleNode(elem); final List<OMElement> operatesOnNodes = XPATH_IDENTIFICATION_UUID.selectNodes(idNode); final OMElement codeNode = (OMElement) XPATH_IDENTIFICATION_CODELIST.selectSingleNode(idNode); final OMElement dateNode = (OMElement) XPATH_IDENTIFICATION_DATE.selectSingleNode(idNode); final OMElement maintenanceAndUpdateFrequencyNode = (OMElement) XPATH_IDENTIFICATION_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST.selectSingleNode(idNode); JSONObject identification = new JSONObject(); identification.put(KEY_IDENTIFICATION_CODELIST, getAttributeValue(codeNode, QName.valueOf("codeListValue"))); identification.put(KEY_IDENTIFICATION_DATE, getLocalizedContent(dateNode, pathToLocalizedValue)); identification.put(KEY_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST, getAttributeValue(maintenanceAndUpdateFrequencyNode, QName.valueOf("codeListValue"))); item.addValue(KEY_IDENTIFICATION, identification); log.debug("==1"); final OMElement codeListValue = (OMElement) XPATH_CODELISTVALUE.selectSingleNode(elem); log.debug("====: " + codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.setNatureOfTarget(codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.addValue(KEY_NATUREOFTHETARGET, item.getNatureOfTarget()); for(OMElement operatesOnNode : operatesOnNodes){ if(operatesOnNode != null){ if(operatesOnNode.getAllAttributes() == null) log.debug("attributes == null"); Iterator<OMAttribute> i = operatesOnNode.getAllAttributes(); if(i.hasNext()){ OMAttribute ao = (OMAttribute)i.next(); log.debug("AO value: " + ao.getAttributeValue()); item.addUuId(ao.getAttributeValue()); } } } item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); item.setResourceId(getLocalizedContent(uuidNode, pathToLocalizedValue)); return item; } MetadataCatalogueResultParser(); }
MetadataCatalogueResultParser { public SearchResultItem parseResult(final OMElement elem, final String locale) throws Exception { final Map<String, String> locales = getLocaleMap(elem); AXIOMXPath pathToLocalizedValue = null; if(locales != null && locales.containsKey(locale)) { pathToLocalizedValue = XmlHelper.buildXPath("../gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale='#" + locales.get(locale) + "']", NAMESPACE_CTX); } final OMElement idNode = (OMElement) XPATH_IDENTIFICATION.selectSingleNode(elem); final SearchResultItem item = new SearchResultItem(); final OMElement titleNode = (OMElement) XPATH_IDENTIFICATION_TITLE.selectSingleNode(idNode); item.setTitle(getLocalizedContent(titleNode, pathToLocalizedValue)); final OMElement descNode = (OMElement) XPATH_IDENTIFICATION_DESC.selectSingleNode(idNode); item.setDescription(getLocalizedContent(descNode, pathToLocalizedValue)); final OMElement imageNode = (OMElement) XPATH_IDENTIFICATION_IMAGE.selectSingleNode(idNode); item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); final OMElement orgNode = (OMElement) XPATH_IDENTIFICATION_ORGANIZATION.selectSingleNode(idNode); item.addValue(MetadataField.RESULT_KEY_ORGANIZATION, getLocalizedContent(orgNode, pathToLocalizedValue)); final OMElement bboxNode = (OMElement) XPATH_IDENTIFICATION_BBOX.selectSingleNode(idNode); setupBBox(item, bboxNode); final OMElement distInfoNode = (OMElement) XPATH_DISTINFO.selectSingleNode(elem); item.setGmdURL(getLocalizedContent(distInfoNode, pathToLocalizedValue)); final OMElement uuidNode = (OMElement) XPATH_FILEID.selectSingleNode(elem); final List<OMElement> operatesOnNodes = XPATH_IDENTIFICATION_UUID.selectNodes(idNode); final OMElement codeNode = (OMElement) XPATH_IDENTIFICATION_CODELIST.selectSingleNode(idNode); final OMElement dateNode = (OMElement) XPATH_IDENTIFICATION_DATE.selectSingleNode(idNode); final OMElement maintenanceAndUpdateFrequencyNode = (OMElement) XPATH_IDENTIFICATION_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST.selectSingleNode(idNode); JSONObject identification = new JSONObject(); identification.put(KEY_IDENTIFICATION_CODELIST, getAttributeValue(codeNode, QName.valueOf("codeListValue"))); identification.put(KEY_IDENTIFICATION_DATE, getLocalizedContent(dateNode, pathToLocalizedValue)); identification.put(KEY_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST, getAttributeValue(maintenanceAndUpdateFrequencyNode, QName.valueOf("codeListValue"))); item.addValue(KEY_IDENTIFICATION, identification); log.debug("==1"); final OMElement codeListValue = (OMElement) XPATH_CODELISTVALUE.selectSingleNode(elem); log.debug("====: " + codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.setNatureOfTarget(codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.addValue(KEY_NATUREOFTHETARGET, item.getNatureOfTarget()); for(OMElement operatesOnNode : operatesOnNodes){ if(operatesOnNode != null){ if(operatesOnNode.getAllAttributes() == null) log.debug("attributes == null"); Iterator<OMAttribute> i = operatesOnNode.getAllAttributes(); if(i.hasNext()){ OMAttribute ao = (OMAttribute)i.next(); log.debug("AO value: " + ao.getAttributeValue()); item.addUuId(ao.getAttributeValue()); } } } item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); item.setResourceId(getLocalizedContent(uuidNode, pathToLocalizedValue)); return item; } MetadataCatalogueResultParser(); SearchResultItem parseResult(final OMElement elem, final String locale); }
MetadataCatalogueResultParser { public SearchResultItem parseResult(final OMElement elem, final String locale) throws Exception { final Map<String, String> locales = getLocaleMap(elem); AXIOMXPath pathToLocalizedValue = null; if(locales != null && locales.containsKey(locale)) { pathToLocalizedValue = XmlHelper.buildXPath("../gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale='#" + locales.get(locale) + "']", NAMESPACE_CTX); } final OMElement idNode = (OMElement) XPATH_IDENTIFICATION.selectSingleNode(elem); final SearchResultItem item = new SearchResultItem(); final OMElement titleNode = (OMElement) XPATH_IDENTIFICATION_TITLE.selectSingleNode(idNode); item.setTitle(getLocalizedContent(titleNode, pathToLocalizedValue)); final OMElement descNode = (OMElement) XPATH_IDENTIFICATION_DESC.selectSingleNode(idNode); item.setDescription(getLocalizedContent(descNode, pathToLocalizedValue)); final OMElement imageNode = (OMElement) XPATH_IDENTIFICATION_IMAGE.selectSingleNode(idNode); item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); final OMElement orgNode = (OMElement) XPATH_IDENTIFICATION_ORGANIZATION.selectSingleNode(idNode); item.addValue(MetadataField.RESULT_KEY_ORGANIZATION, getLocalizedContent(orgNode, pathToLocalizedValue)); final OMElement bboxNode = (OMElement) XPATH_IDENTIFICATION_BBOX.selectSingleNode(idNode); setupBBox(item, bboxNode); final OMElement distInfoNode = (OMElement) XPATH_DISTINFO.selectSingleNode(elem); item.setGmdURL(getLocalizedContent(distInfoNode, pathToLocalizedValue)); final OMElement uuidNode = (OMElement) XPATH_FILEID.selectSingleNode(elem); final List<OMElement> operatesOnNodes = XPATH_IDENTIFICATION_UUID.selectNodes(idNode); final OMElement codeNode = (OMElement) XPATH_IDENTIFICATION_CODELIST.selectSingleNode(idNode); final OMElement dateNode = (OMElement) XPATH_IDENTIFICATION_DATE.selectSingleNode(idNode); final OMElement maintenanceAndUpdateFrequencyNode = (OMElement) XPATH_IDENTIFICATION_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST.selectSingleNode(idNode); JSONObject identification = new JSONObject(); identification.put(KEY_IDENTIFICATION_CODELIST, getAttributeValue(codeNode, QName.valueOf("codeListValue"))); identification.put(KEY_IDENTIFICATION_DATE, getLocalizedContent(dateNode, pathToLocalizedValue)); identification.put(KEY_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST, getAttributeValue(maintenanceAndUpdateFrequencyNode, QName.valueOf("codeListValue"))); item.addValue(KEY_IDENTIFICATION, identification); log.debug("==1"); final OMElement codeListValue = (OMElement) XPATH_CODELISTVALUE.selectSingleNode(elem); log.debug("====: " + codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.setNatureOfTarget(codeListValue.getAttributeValue(QNAME_CODELISTVALUE)); item.addValue(KEY_NATUREOFTHETARGET, item.getNatureOfTarget()); for(OMElement operatesOnNode : operatesOnNodes){ if(operatesOnNode != null){ if(operatesOnNode.getAllAttributes() == null) log.debug("attributes == null"); Iterator<OMAttribute> i = operatesOnNode.getAllAttributes(); if(i.hasNext()){ OMAttribute ao = (OMAttribute)i.next(); log.debug("AO value: " + ao.getAttributeValue()); item.addUuId(ao.getAttributeValue()); } } } item.setContentURL(getLocalizedContent(imageNode, pathToLocalizedValue)); item.setResourceId(getLocalizedContent(uuidNode, pathToLocalizedValue)); return item; } MetadataCatalogueResultParser(); SearchResultItem parseResult(final OMElement elem, final String locale); static final String KEY_IDENTIFICATION; static final String KEY_IDENTIFICATION_DATE; static final String KEY_IDENTIFICATION_CODELIST; static final String KEY_MAINTENANCE_AND_UPDATE_FREQUENCY_CODELIST; static final String KEY_NATUREOFTHETARGET; }