// Create the image uri, either from the id or the path. If none is
// specified, and we are not in jsp compilation mode, issue a warning
ResourceURI uri = null;
if (StringUtils.isNotBlank(imageId))
uri = new ImageResourceURIImpl(site, null, imageId);
if (uri == null && StringUtils.isNotBlank(imagePath))
uri = new ImageResourceURIImpl(site, imagePath, null);
if (uri == null && imageSubjects != null && imageSubjects.size() > 0) {
SearchQuery query = new SearchQueryImpl(site);
query.withVersion(Resource.LIVE);
query.withTypes(ImageResource.TYPE);
query.withSubjects(SearchQuery.Quantifier.All, imageSubjects.toArray(new String[imageSubjects.size()]));
SearchResult result;
try {
result = repository.find(query);
} catch (ContentRepositoryException e) {
logger.warn("Error searching for image with given subjects ({}): {}", StringUtils.join(imageSubjects, ", "), e.getMessage());
return SKIP_BODY;
}
if (result.getHitCount() > 1)
logger.warn("Search returned {} images for subjects '{}' on {}", new Object[] { result.getHitCount(), StringUtils.join(imageSubjects, ", "), request.getUrl() });
if (result.getHitCount() > 0)
uri = new ImageResourceURIImpl(site, null, result.getItems()[0].getId());
}
if (uri == null && StringUtils.isNotBlank(altImageId))
uri = new ImageResourceURIImpl(site, null, altImageId);
if (uri == null && StringUtils.isNotBlank(altImagePath))
uri = new ImageResourceURIImpl(site, altImagePath, null);
if (uri == null) {
logger.debug("None of the several possibilities returned a valid image on {}", request.getUrl());
return SKIP_BODY;
}