@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
throws Exception
{
Repository systemRepository = repositoryManager.getSystemRepository();
ValueFactory vf = systemRepository.getValueFactory();
try {
RepositoryConnection con = systemRepository.getConnection();
try {
// FIXME: The query result is cached here as we need to close the
// connection before returning. Would be much better to stream the
// query result directly to the client.
List<String> bindingNames = new ArrayList<String>();
List<BindingSet> bindingSets = new ArrayList<BindingSet>();
TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, REPOSITORY_LIST_QUERY).evaluate();
try {
// Determine the repository's URI
StringBuffer requestURL = request.getRequestURL();
if (requestURL.charAt(requestURL.length() - 1) != '/') {
requestURL.append('/');
}
String namespace = requestURL.toString();
while (queryResult.hasNext()) {
QueryBindingSet bindings = new QueryBindingSet(queryResult.next());
String id = bindings.getValue("id").stringValue();
bindings.addBinding("uri", vf.createURI(namespace, id));
bindingSets.add(bindings);
}
bindingNames.add("uri");