}
} catch (PermissionDeniedException pde) {
throw new XPathException(pde.getMessage(), pde);
}
DocumentImpl docImage = null;
BinaryDocument binImage = null;
@SuppressWarnings("unused")
BinaryDocument doc = null;
BufferedImage bImage = null;
@SuppressWarnings("unused")
byte[] imgData = null;
Image image = null;
ByteArrayOutputStream os = null;
try {
Iterator<DocumentImpl> i = allPictures.iterator(dbbroker);
while (i.hasNext()) {
docImage = (DocumentImpl) i.next();
// is not already existing??
if (!((fileExist(context.getBroker(), existingThumbsCol, docImage, prefix)) || (fileExist(
existingThumbsArray, docImage, prefix)))) {
if (docImage.getResourceType() == DocumentImpl.BINARY_FILE)
// TODO maybe extends for gifs too.
if (docImage.getMetadata().getMimeType().startsWith(
"image/jpeg")) {
binImage = (BinaryDocument) docImage;
// get a byte array representing the image
try {
InputStream is = dbbroker.getBinaryResource(binImage);
image = ImageIO.read(is);
} catch (IOException ioe) {
throw new XPathException(this,ioe.getMessage());
}
try {
bImage = ImageModule.createThumb(image, maxThumbHeight,
maxThumbWidth);
} catch (Exception e) {
throw new XPathException(this, e.getMessage());
}
if (isSaveToDataBase) {
os = new ByteArrayOutputStream();
try {
ImageIO.write(bImage, "jpg", os);
} catch (Exception e) {
throw new XPathException(this, e.getMessage());
}
try {
doc = thumbCollection.addBinaryResource(
transaction, dbbroker,
XmldbURI.create(prefix
+ docImage.getFileURI()), os
.toByteArray(), "image/jpeg");
} catch (Exception e) {
throw new XPathException(this, e.getMessage());
}
// result.add(new
// StringValue(""+docImage.getFileURI()+"|"+thumbCollection.getURI()+THUMBPREFIX
// + docImage.getFileURI()));
} else {
try {
ImageIO
.write(
bImage,
"jpg",
new File(thumbPath.toString()
+ "/" + prefix
+ docImage.getFileURI()));
} catch (Exception e) {
throw new XPathException(this, e.getMessage());
}
// result.add(new StringValue(
// thumbPath.toString() + "/"
// + THUMBPREFIX
// + docImage.getFileURI()));
}
}
} else {
// result.add(new StringValue(""+docImage.getURI()+"|"
// + ((existingThumbsCol != null) ? ""
// + existingThumbsCol.getURI() : thumbDir
// .toString()) + "/" + prefix
// + docImage.getFileURI()));
result.add(new StringValue(docImage.getFileURI().toString()));
}
}
} catch(PermissionDeniedException pde) {
throw new XPathException(this, pde.getMessage(), pde);
}