// listing the repositories
if (request.getParameter("repositories") != null) {
ServiceReference caveRepositoryServiceReference = bundleContext.getServiceReference(CaveRepositoryService.class.getName());
if (caveRepositoryServiceReference != null) {
CaveRepositoryService caveRepositoryService = (CaveRepositoryService) bundleContext.getService(caveRepositoryServiceReference);
if (caveRepositoryService != null) {
CaveRepository[] caveRepositories = caveRepositoryService.getRepositories();
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
for (CaveRepository caveRepository : caveRepositories) {
writer.println(caveRepository.getName());
}
writer.flush();
writer.close();
}
bundleContext.ungetService(caveRepositoryServiceReference);
}
return;
}
// wrapping content (repository.xml or directly artifacts)
try {
URL url = null;
if (uri.endsWith("-repository.xml")) {
// the user wants to get the Cave repository repository.xml
// the expected format is {cave-repo-name}-repository.xml
int index = uri.indexOf("-repository.xml");
String caveRepositoryName = uri.substring(0, index);
ServiceReference caveRepositoryServiceReference = bundleContext.getServiceReference(CaveRepositoryService.class.getName());
if (caveRepositoryServiceReference != null) {
CaveRepositoryService caveRepositoryService = (CaveRepositoryService) bundleContext.getService(caveRepositoryServiceReference);
if (caveRepositoryService != null) {
CaveRepository caveRepository = caveRepositoryService.getRepository(caveRepositoryName);
if (caveRepository != null) {
url = caveRepository.getRepositoryXml();
response.setContentType("text/xml");
}
}