User user = securityService.getUser();
if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN))
throw new WebApplicationException(Status.FORBIDDEN);
Site site = getSite(request);
ContentRepository repository = getContentRepository(site, false);
if (repository == null)
throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
SearchQuery q = null;
StringBuffer result = new StringBuffer();
result.append("<index");
result.append(" state=\"").append(repository.isIndexing() ? "indexing" : "normal").append("\"");
result.append(" readonly=\"").append(repository.isReadOnly() ? "true" : "false").append("\"");
result.append(">");
try {
result.append("<resources>").append(repository.getResourceCount()).append("</resources>");
result.append("<revisions>").append(repository.getVersionCount() - repository.getResourceCount()).append("</revisions>");
q = new SearchQueryImpl(site).withTypes(Page.TYPE).withPreferredVersion(Resource.LIVE);
result.append("<pages>").append(repository.find(q).getDocumentCount()).append("</pages>");
q = new SearchQueryImpl(site).withTypes(FileResource.TYPE).withPreferredVersion(Resource.LIVE);
result.append("<files>").append(repository.find(q).getDocumentCount()).append("</files>");
q = new SearchQueryImpl(site).withTypes(ImageResource.TYPE).withPreferredVersion(Resource.LIVE);
result.append("<images>").append(repository.find(q).getDocumentCount()).append("</images>");
q = new SearchQueryImpl(site).withTypes(MovieResource.TYPE).withPreferredVersion(Resource.LIVE);
result.append("<movies>").append(repository.find(q).getDocumentCount()).append("</movies>");
} catch (ContentRepositoryException e) {
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
result.append("</index>");