if (!ResourceUtils.hasChanged(request, scaledResourceFile)) {
return Response.notModified().build();
}
ResourceURI resourceURI = resource.getURI();
final ContentRepository contentRepository = getContentRepository(site, false);
// When there is no scaling required, just return the original
if (ImageScalingMode.None.equals(style.getScalingMode())) {
return getResourceContent(request, resource, language);
}
// Find a serializer
ResourceSerializer<?, ?> serializer = serializerService.getSerializerByType(resourceURI.getType());
if (serializer == null)
throw new WebApplicationException(Status.PRECONDITION_FAILED);
// Does the serializer come with a preview generator?
PreviewGenerator previewGenerator = serializer.getPreviewGenerator(resource);
if (previewGenerator == null)
throw new WebApplicationException(Status.NOT_FOUND);
// Load the resource contents from the repository
InputStream resourceInputStream = null;
long contentLength = -1;
// Load the input stream from the scaled image
InputStream contentRepositoryIs = null;
FileOutputStream fos = null;
try {
long resourceLastModified = ResourceUtils.getModificationDate(resource, language).getTime();
if (!scaledResourceFile.isFile() || scaledResourceFile.lastModified() < resourceLastModified) {
if (!force)
throw new WebApplicationException(Response.Status.NOT_FOUND);
contentRepositoryIs = contentRepository.getContent(resourceURI, language);
scaledResourceFile = ImageStyleUtils.createScaledFile(resource, language, style);
scaledResourceFile.setLastModified(Math.max(new Date().getTime(), resourceLastModified));
fos = new FileOutputStream(scaledResourceFile);
logger.debug("Creating scaled image '{}' at {}", resource, scaledResourceFile);