packageName = StringUtils.replaceChars(packageName, '.', '/');
packageName = "/" + packageName;
String controlName = ClassUtils.getShortClassName(controlClass);
ConfigService configService = getConfigService(servletContext);
LogService logService = configService.getLogService();
String descriptorFile = packageName + "/" + controlName + ".files";
logService.debug("Use deployment descriptor file:" + descriptorFile);
try {
InputStream is = getResourceAsStream(descriptorFile, ClickUtils.class);
List fileList = IOUtils.readLines(is);
if (fileList == null || fileList.isEmpty()) {
logService.info("there are no files to deploy for control " + controlClass.getName());
return;
}
// a target dir list is required cause the ClickUtils.deployFile() is too inflexible to autodetect
// required subdirectories.
List<String> targetDirList = new ArrayList<String>(fileList.size());
for (int i = 0; i < fileList.size(); i++) {
String filePath = (String) fileList.get(i);
String destination = "";
int index = filePath.lastIndexOf('/');
if (index != -1) {
destination = filePath.substring(0, index + 1);
}
targetDirList.add(i, targetDir + "/" + destination);
fileList.set(i, packageName + "/" + filePath);
}
for (int i = 0; i < fileList.size(); i++) {
String source = (String) fileList.get(i);
String targetDirName = targetDirList.get(i);
ClickUtils.deployFile(servletContext, source, targetDirName);
}
} catch (IOException e) {
String msg = "error occurred getting resource " + descriptorFile + ", error " + e;
logService.warn(msg);
}
}