LOGGER.debug("Service has a valid region request: {}", region);
}
try {
final Referent referent = contextObject.getReferent();
final ImageRecord r = ReferentManager.getImageRecord(referent);
if (r != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Retrieving ImageRecord for: {}", r.getIdentifier());
}
if (transformCheck && transform != null) {
final HashMap<String, String> instProps = new HashMap<String, String>();
if (r.getInstProps() != null) {
instProps.putAll(r.getInstProps());
}
int l = contextObject.getRequesters().length;
final Requester[] req = contextObject.getRequesters();
if (l > 0 && req[0].getDescriptors().length > 0) {
final String rs = req[0].getDescriptors()[0].toString();
instProps.put(PROPS_REQUESTER, rs);
}
l = contextObject.getReferringEntities().length;
ReferringEntity[] rea;
rea = contextObject.getReferringEntities();
if (l > 0 && rea[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)) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Not using the OpenURL layer cache");
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
extractor.extractImage(r.getImageFile(), baos, params, format);
bytes = baos.toByteArray();
baos.close();
} else {
final String ext = getExtension(format);
final String hash = getTileHash(r, params);
String file = tileCache.get(hash + ext);
File f;
id = r.getIdentifier();
if (file == null || !(f = new File(file)).exists() && f.length() > 0) {
if (cacheDir != null) {
final File cacheDirFile = new File(cacheDir);
// If our cache dir doesn't exist, create it
if (!cacheDirFile.exists()) {
if (!cacheDirFile.mkdirs() && LOGGER.isWarnEnabled()) {
LOGGER.warn("Dirs not created: {}", cacheDirFile);
}
}
f = File.createTempFile("cache" + hash.hashCode() + "-", "." + ext, cacheDirFile);
} else {
f = File.createTempFile("cache" + hash.hashCode() + "-", "." + ext);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Temp file created: {}", f);
}
f.deleteOnExit();
file = f.getAbsolutePath();
djatokaCacheFile = file;
extractor.extractImage(r.getImageFile(), file, params, format);
if (tileCache.get(hash + ext) == null) {
tileCache.put(hash + ext, file);
bytes = IOUtils.getBytesFromFile(f);