* {@inheritDoc}
* @see eu.planets_project.ifr.core.storage.api.DigitalObjectManager#list(java.net.URI, eu.planets_project.ifr.core.storage.api.query.Query)
*/
public List<URI> list(URI pdURI, Query q) throws QueryValidationException {
if (q == null)
throw new QueryValidationException("null query not allowed");
if (!(q instanceof QueryString))
throw new QueryValidationException("Unsupported query type");
if (pdURI == null) {
// SRU hierarchy is flat (no sub-directories) - only allow 'null' as pdURI!
ArrayList<URI> resultList = new ArrayList<URI>();
try {
String url = baseURL + "&query=" + URLEncoder.encode(((QueryString) q).getQuery(), "UTF-8") +
"&maximumRecords=" + "10" /* limit!!! */ + "&recordSchema=dc";
GetMethod sruRequest = new GetMethod(url);
sruRequest.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, Integer.valueOf(TIMEOUT));
httpClient.executeMethod(sruRequest);
// Parse metadata records
SAXBuilder builder = new SAXBuilder();
List<SRUResult> results = parseDom(builder.build(sruRequest.getResponseBodyAsStream()));
// Extract URIs from metadata and return
for (SRUResult aResult : results) {
resultList.add(aResult.uri);
}
} catch (UnsupportedEncodingException e) {
log.severe(e.getMessage() + " (this should never happen");
} catch (IOException e) {
throw new QueryValidationException("Error connecting to SRU endpoint: " + e.getMessage());
} catch (JDOMException e) {
throw new QueryValidationException("Invalid SRU respons: " + e.getMessage());
}
return resultList;
} else {
return new ArrayList<URI>();