* @param cswResponse the CSW response
* @return the resultant records
* @throws SearchException the search exception
*/
private CswRecords parseResponseForSitemap(String cswResponse) throws SearchException {
CswRecords cswRecords = new CswRecords();
try {
//System.err.println(cswResponse);
InputSource src = new InputSource(new StringReader(Val.chkStr(cswResponse)));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document dom = builder.parse(src);
String cswNamespace = "http://www.opengis.net/cat/csw/2.0.2";
String dcNamespace = "http://purl.org/dc/elements/1.1/";
String dctNamespace = "http://purl.org/dc/terms/";
String idScheme = "urn:x-esri:specification:ServiceType:ArcIMS:Metadata:DocID";
NodeList resultNodes = dom.getElementsByTagNameNS(cswNamespace,"SearchResults");
if (resultNodes.getLength() == 1) {
Node searchResultsNode = resultNodes.item(0);
if (searchResultsNode != null) {
Node ndHits = searchResultsNode.getAttributes().getNamedItem("numberOfRecordsMatched");
//Node ndHits = searchResultsNode.getAttributes().getNamedItemNS(cswNamespace,"numberOfRecordsMatched");
if (ndHits != null) {
int nHits = Val.chkInt(Val.chkStr(ndHits.getNodeValue()),-1);
cswRecords.setMaximumQueryHits(nHits);
}
}
}
NodeList recordNodes = dom.getElementsByTagNameNS(cswNamespace,"Record");
int nLen = recordNodes.getLength();
for (int i=0; i<nLen; i++) {
CswRecord record = new CswRecord();
String id = "";
String modified = "";
Node recordNode = recordNodes.item(i);
NodeList nlChildren = recordNode.getChildNodes();
int nChildren = nlChildren.getLength();
for (int nChild=0; nChild<nChildren; nChild++) {
Node ndChild = nlChildren.item(nChild);
String namespace = ndChild.getNamespaceURI();
String localname = ndChild.getLocalName();
if ((namespace != null) && (localname != null)) {
if (namespace.equals(dcNamespace) && localname.equals("identifier")) {
String scheme = "";
Node ndScheme = ndChild.getAttributes().getNamedItem("scheme");
if (ndScheme != null) {
scheme = Val.chkStr(ndScheme.getNodeValue());
}
if (scheme.equals(idScheme)) {
id = Val.chkStr(ndChild.getTextContent());
}
} else if (namespace.equals(dctNamespace) && localname.equals("modified")) {
modified = Val.chkStr(ndChild.getTextContent());
}
}
}
record.setId(id);
//System.err.println("id="+id+" modified="+modified);
if (modified.length() > 0) {
record.setModifiedDate(modified);
}
cswRecords.add(record);
}
} catch (Exception e) {
throw new SearchException(e);
}