}
responseFormat = "text/plain";
status = HttpServletResponse.SC_NOT_FOUND;
} else {
try {
ImageRecord r = ReferentManager.getImageRecord(contextObject.getReferent());
if (r != null) {
if (transformCheck && transform != null) {
HashMap<String, String> instProps = new HashMap<String, String>();
if (r.getInstProps() != null)
instProps.putAll(r.getInstProps());
if (contextObject.getRequesters().length > 0
&& contextObject.getRequesters()[0]
.getDescriptors().length > 0) {
String requester = contextObject.getRequesters()[0]
.getDescriptors()[0].toString();
instProps.put(PROPS_REQUESTER, requester);
}
if (contextObject.getReferringEntities().length > 0
&& contextObject.getReferringEntities()[0].getDescriptors().length > 0) {
instProps.put(PROPS_REFERRING_ENTITY,
contextObject.getReferringEntities()[0].getDescriptors()[0].toString());
}
if (instProps.size() > 0) {
transform.setInstanceProps(instProps);
}
params.setTransform(transform);
}
if (!cacheTiles || !isCacheable(params)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
extractorFactory.getDjatokaExtractorProcessorForFile(r.getImageFile()).extractImage(r.getImageFile(), baos, params, format);
bytes = baos.toByteArray();
baos.close();
} else {
String ext = getExtension(format);
String hash = getTileHash(r, params);
String file = tileCache.get(hash + ext);
File f;
if (file == null
|| (file != null && !((f = new File(file)).exists() && f.length() > 0))) {
if (file != null) {
f = new File(file);
if (f.exists()) { // then implies f.length() == 0, which means f is corrupted.
f.delete();
}
tileCache.remove(hash + ext);
} else {
tileCache.remove(hash + ext); // In case the cache dir was manually (externally) cleared, then assure tile file gets recreated.
}
if (getCacheDir() != null) {
f = File.createTempFile("cache" + hash.hashCode() + "-", "." + ext, new File(getCacheDir()));
} else {
f = File.createTempFile("cache" + hash.hashCode() + "-", "." + ext);
}
f.deleteOnExit();
file = f.getAbsolutePath();
extractorFactory.getDjatokaExtractorProcessorForFile(r.getImageFile()).extractImage(r.getImageFile(), file, params, format);
if (tileCache.get(hash + ext) == null) {
tileCache.put(hash + ext, file);
bytes = IOUtils.getBytesFromFile(f);
logger.debug("makingTile: " + file + " " + bytes.length + " params: " + params);
} else {