// For the base URL of assets within a module, use the server URL and
// point it to the webdav repository
String hostname = System.getProperty(Constants.WEBSERVER_URL_PROP) + "webdav/content/modules/installed/" + moduleName;
/* Fetch the module repository, return an error if it does not exist */
ModuleRepository mr = module.getRepository();
if (mr == null || mr.getResources() == null || mr.getResources().length == 0) {
/*
* If the repository doesn't exist (perhaps from a missing repository.xml
* file, then create a fallback response with this server as the
* master.
*/
logger.info("A repository.xml file does not exist for module: " + moduleName);
logger.info("Sending this server as fallback: " + hostname);
ModuleRepository newRepository = new ModuleRepository();
Repository rep = new Repository();
rep.url = hostname;
rep.isServer = true;
newRepository.setMaster(rep);
/* Write the XML encoding to a writer and return it */
StringWriter sw = new StringWriter();
try {
/* Formulate the HTTP response and send the string */
newRepository.encode(sw);
ResponseBuilder rb = Response.ok(sw.toString());
return rb.build();
} catch (javax.xml.bind.JAXBException excp) {
/* Log an error and return an error response */
logger.warning("ModuleManager: unable to serialize repository for " + moduleName);
ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
return rb.build();
}
}
/* Since we potentially edit fields below, make a copy of the repository */
ModuleRepository newRepository = new ModuleRepository(mr);
/* Replace the master if its string is the special %WL_SERVER% */
if (newRepository.getMaster() != null && newRepository.getMaster().url.compareTo(ModuleRepository.WL_SERVER) == 0) {
Repository rep = new Repository();
rep.url = hostname;
rep.isServer = true;
newRepository.setMaster(rep);
}
/* Replace the mirrors if its string is the special %WL_SERVER% */
Repository mirrors[] = newRepository.getMirrors();
if (mirrors != null) {
for (int i = 0; i < mirrors.length; i++) {
if (mirrors[i] != null && mirrors[i].url.compareTo(ModuleRepository.WL_SERVER) == 0) {
Repository rep = new Repository();
rep.url = hostname;
rep.isServer = true;
mirrors[i] = rep;
}
}
newRepository.setMirrors(mirrors);
}
/* Write the XML encoding to a writer and return it */
StringWriter sw = new StringWriter();
try {
/* Formulate the HTTP response and send the string */
newRepository.encode(sw);
ResponseBuilder rb = Response.ok(sw.toString());
return rb.build();
} catch (javax.xml.bind.JAXBException excp) {
/* Log an error and return an error response */
logger.warning("ModuleManager: unable to serialize repository for " + moduleName);