super.endElement(uri, name, raw);
}
}
protected void performSearchMethod(String query) throws SAXException {
OptionsMethod optionsMethod = null;
SearchMethod searchMethod = null;
try {
DOMStreamer propertyStreamer = new DOMStreamer(this.xmlConsumer);
optionsMethod = new OptionsMethod(this.targetUrl);
searchMethod = new SearchMethod(this.targetUrl, query);
HttpURL url = new HttpURL(this.targetUrl);
HttpState state = new HttpState();
state.setCredentials(null, new UsernamePasswordCredentials(
url.getUser(),
url.getPassword()));
HttpConnection conn = new HttpConnection(url.getHost(), url.getPort());
// eventcaching stuff
SourceValidity extraValidity = makeWebdavEventValidity(url);
if(extraValidity!=null && m_validity!=null)
m_validity.add(extraValidity);
// end eventcaching stuff
WebdavResource resource = new WebdavResource(new HttpURL(this.targetUrl));
if(!resource.exists()) {
throw new SAXException("The WebDAV resource don't exist");
}
optionsMethod.execute(state, conn);
if(!optionsMethod.isAllowed("SEARCH")) {
throw new SAXException("The server doesn't support the SEARCH method");
}
int httpstatus = searchMethod.execute(state, conn);
this.contentHandler.startElement(DASL_QUERY_NS,
RESULT_ROOT_TAG,
PREFIX + ":" + RESULT_ROOT_TAG,
XMLUtils.EMPTY_ATTRIBUTES);
// something might have gone wrong, report it
// 207 = multistatus webdav response
if(httpstatus != 207) {
this.contentHandler.startElement(DASL_QUERY_NS,
ERROR_ROOT_TAG,
PREFIX + ":" + ERROR_ROOT_TAG,
XMLUtils.EMPTY_ATTRIBUTES);
// dump whatever the server said
propertyStreamer.stream(searchMethod.getResponseDocument());
this.contentHandler.endElement(DASL_QUERY_NS,
ERROR_ROOT_TAG,
PREFIX + ":" + ERROR_ROOT_TAG);
} else {
// show results
Enumeration enumeration = searchMethod.getAllResponseURLs();
while (enumeration.hasMoreElements()) {
String path = (String) enumeration.nextElement();
Enumeration properties = searchMethod.getResponseProperties(path);
AttributesImpl attr = new AttributesImpl();
attr.addAttribute(DASL_QUERY_NS, PATH_NODE_NAME, PREFIX + ":" + PATH_NODE_NAME, "CDATA",path);
this.contentHandler.startElement(DASL_QUERY_NS,
RESOURCE_NODE_NAME,
PREFIX + ":" + RESOURCE_NODE_NAME,
attr);
while(properties.hasMoreElements()) {
BaseProperty metadata = (BaseProperty) properties.nextElement();
Element propertyElement = metadata.getElement();
propertyStreamer.stream(propertyElement);
}
this.contentHandler.endElement(DASL_QUERY_NS,
RESOURCE_NODE_NAME,
PREFIX + ":" + RESOURCE_NODE_NAME);
}
}
this.contentHandler.endElement(DASL_QUERY_NS,
RESULT_ROOT_TAG,
PREFIX + ":" + RESULT_ROOT_TAG);
} catch (SAXException e) {
throw new SAXException("Unable to fetch the query data:", e);
} catch (HttpException e1) {
this.getLogger().error("Unable to contact Webdav server", e1);
throw new SAXException("Unable to connect with server: ", e1);
} catch (IOException e2) {
throw new SAXException("Unable to connect with server: ", e2);
} catch (NullPointerException e) {
throw new SAXException("Unable to fetch the query data:", e);
} catch (Exception e) {
throw new SAXException("Generic Error:", e);
} finally {
// cleanup
if(searchMethod!=null)
searchMethod.releaseConnection();
if(optionsMethod!=null)
optionsMethod.releaseConnection();
}
}