File bundleFile = createBundleFile(bundleId);
if (bundleFile.exists()) {
return;
}
StringBand sb = new StringBand(sources.size() * 2);
for (String src : sources) {
if (sb.length() != 0) {
sb.append(StringPool.NEWLINE);
}
String content;
if (isExternalResource(src)) {
try {
content = NetUtil.downloadString(src, localFilesEncoding);
} catch (IOException ioex) {
if (notFoundExceptionEnabled) {
throw ioex;
}
if (log.isWarnEnabled()) {
log.warn("Download failed: " + src + "; " + ioex.getMessage());
}
content = null;
}
} else {
if (downloadLocal == false) {
// load local resource from file system
String localFile = webRoot;
if (src.startsWith(contextPath + '/')) {
src = src.substring(contextPath.length());
}
if (src.startsWith(StringPool.SLASH)) {
// absolute path
localFile += src;
} else {
// relative path
localFile += '/' + FileNameUtil.getPathNoEndSeparator(actionPath) + '/' + src;
}
// trim link parameters, if any
int qmndx = localFile.indexOf('?');
if (qmndx != -1) {
localFile = localFile.substring(0, qmndx);
}
try {
content = FileUtil.readString(localFile);
} catch (IOException ioex) {
if (notFoundExceptionEnabled) {
throw ioex;
}
if (log.isWarnEnabled()) {
log.warn(ioex.getMessage());
}
content = null;
}
} else {
// download local resource
String localUrl = localAddressAndPort;
if (src.startsWith(StringPool.SLASH)) {
localUrl += contextPath + src;
} else {
localUrl += contextPath + FileNameUtil.getPath(actionPath) + '/' + src;
}
try {
content = NetUtil.downloadString(localUrl, localFilesEncoding);
} catch (IOException ioex) {
if (notFoundExceptionEnabled) {
throw ioex;
}
if (log.isWarnEnabled()) {
log.warn("Download failed: " + localUrl + "; " + ioex.getMessage());
}
content = null;
}
}
if (content != null) {
if (isCssResource(src)) {
content = fixCssRelativeUrls(content, src);
}
}
}
if (content != null) {
content = onResourceContent(content);
sb.append(content);
}
}
FileUtil.writeString(bundleFile, sb.toString());
if (log.isInfoEnabled()) {
log.info("Bundle created: " + bundleId);
}
}