} else {
throw new CmisRuntimeException("Invalid HTTP method!");
}
// execute
ObjectList results = service.query(repositoryId, statement, searchAllVersions, includeAllowableActions,
includeRelationships, renditionFilter, maxItems, skipCount, null);
if (results == null) {
throw new CmisRuntimeException("Results are null!");
}
// set headers
UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
UrlBuilder pagingUrl = compileUrlBuilder(baseUrl, RESOURCE_QUERY, null);
pagingUrl.addParameter(Constants.PARAM_Q, statement);
pagingUrl.addParameter(Constants.PARAM_SEARCH_ALL_VERSIONS, searchAllVersions);
pagingUrl.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
pagingUrl.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
UrlBuilder location = new UrlBuilder(pagingUrl);
location.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
location.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
response.setStatus(statusCode);
response.setContentType(Constants.MEDIATYPE_FEED);
// The Content-Location header is optional (CMIS specification 3.7.2.1).
// Since it can cause problems with long query statements it is
// deactivated.
// response.setHeader("Content-Location", location.toString());
// The Location header is not optional (CMIS specification 3.7.2.1).
response.setHeader("Location", location.toString());
// write XML
AtomFeed feed = new AtomFeed();
feed.startDocument(response.getOutputStream());
feed.startFeed(true);
// write basic Atom feed elements
GregorianCalendar now = new GregorianCalendar();
feed.writeFeedElements("query", "", "Query", now, null, results.getNumItems());
// write links
feed.writeServiceLink(baseUrl.toString(), repositoryId);
feed.writePagingLinks(pagingUrl, maxItems, skipCount, results.getNumItems(), results.hasMoreItems(),
AtomPubUtils.PAGE_SIZE);
if (results.getObjects() != null) {
AtomEntry entry = new AtomEntry(feed.getWriter());
int idCounter = 0;
for (ObjectData result : results.getObjects()) {
if (result == null) {
continue;
}
idCounter++;
writeQueryResultEntry(entry, result, "id-" + idCounter, now);