in src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoader.java [149:215]
private boolean registerBundleInternal(final Session metadataSession, final Bundle bundle, final boolean isRetry,
final boolean isUpdate) {
// check if bundle has initial content
final Iterator<PathEntry> pathIter = PathEntry.getContentPaths(bundle);
if (pathIter == null) {
log.debug("Bundle {} has no initial content", bundle.getSymbolicName());
return true;
}
try {
bundleHelper.createRepositoryPath(metadataSession, BundleContentLoaderListener.BUNDLE_CONTENT_NODE);
// check if the content has already been loaded
final Map<String, Object> bundleContentInfo = bundleHelper.getBundleContentInfo(metadataSession, bundle,
true);
// if we don't get an info, someone else is currently loading
if (bundleContentInfo == null) {
return false;
}
boolean success = false;
List<String> createdNodes = null;
try {
final boolean contentAlreadyLoaded = ((Boolean) bundleContentInfo
.get(BundleContentLoaderListener.PROPERTY_CONTENT_LOADED)).booleanValue();
boolean isBundleUpdated = false;
Calendar lastLoadedAt = (Calendar) bundleContentInfo
.get(BundleContentLoaderListener.PROPERTY_CONTENT_LOADED_AT);
if (lastLoadedAt != null && lastLoadedAt.getTimeInMillis() < bundle.getLastModified()) {
isBundleUpdated = true;
}
if (!isUpdate && !isBundleUpdated && contentAlreadyLoaded) {
log.info("Content of bundle already loaded {}.", bundle.getSymbolicName());
} else {
createdNodes = installContent(metadataSession, bundle, pathIter,
contentAlreadyLoaded && !isBundleUpdated);
if (isRetry) {
// log success of retry
log.info("Retrying to load initial content for bundle {} succeeded.", bundle.getSymbolicName());
}
}
success = true;
return true;
} finally {
bundleHelper.unlockBundleContentInfo(metadataSession, bundle, success, createdNodes);
}
} catch (ContentReaderUnavailableException crue) {
// if we are retrying we already logged this message once, so we
// won't log it again
if (!isRetry) {
log.warn("Cannot load initial content for bundle {} : {}", bundle.getSymbolicName(), crue.getMessage());
}
} catch (RepositoryException re) {
// if we are retrying we already logged this message once, so we
// won't log it again
if (!isRetry) {
log.error(
"Cannot load initial content for bundle " + bundle.getSymbolicName() + " : " + re.getMessage(),
re);
}
}
return false;
}