]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5361: Services now provides a generic document JPEG image for non-image deriva...
authorRichard Millet <remillet@berkeley.edu>
Thu, 12 Jul 2012 06:26:05 +0000 (23:26 -0700)
committerRichard Millet <remillet@berkeley.edu>
Thu, 12 Jul 2012 06:26:05 +0000 (23:26 -0700)
services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java
services/common/src/main/resources/documentImage.jpg [new file with mode: 0644]

index 0b1b86f838e108d2f333813ab9e17fb74b1d3b23..3f123b6b6d831745177ce0a12a0b18c40cbcb16c 100644 (file)
  */\r
 package org.collectionspace.services.common.imaging.nuxeo;\r
 \r
+import java.awt.Color;\r
+import java.awt.Font;\r
+import java.awt.Graphics;\r
+import java.awt.image.BufferedImage;\r
 import java.io.File;\r
 import java.io.ByteArrayOutputStream;\r
 import java.io.InputStream;\r
@@ -36,6 +40,9 @@ import java.math.BigInteger;
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
+import java.util.Random;\r
+\r
+import javax.imageio.ImageIO;\r
 \r
 import org.nuxeo.runtime.api.Framework;\r
 //import org.nuxeo.runtime.api.ServiceManager;\r
@@ -153,6 +160,10 @@ public class NuxeoImageUtils {
        public static final String SCHEMA_IPTC = "iptc";\r
        public static final String SCHEMA_IMAGE_METADATA = "image_metadata";\r
 \r
+       private static final int THUMB_SIZE_HEIGHT = 100;\r
+\r
+       private static final int THUMB_SIZE_WIDTH = 75;\r
+\r
        // static DefaultBinaryManager binaryManager = new DefaultBinaryManager();\r
        // //can we get this from Nuxeo? i.e.,\r
        // Framework.getService(BinaryManger.class)\r
@@ -813,6 +824,7 @@ public class NuxeoImageUtils {
                        Boolean getContentFlag,\r
                        StringBuffer outMimeType) {\r
                BlobOutput result = new BlobOutput();\r
+               boolean isNonImageDerivative = false;\r
 \r
                if (repositoryId != null && repositoryId.isEmpty() == false)\r
                        try {\r
@@ -839,6 +851,9 @@ public class NuxeoImageUtils {
                                        }\r
                                } else {\r
                                        docBlob = docBlobHolder.getBlob();\r
+                                       if (derivativeTerm != null) { // If its a derivative request on a non-image blob, then return just a document image thumnail\r
+                                               isNonImageDerivative = true;\r
+                                       }\r
                                }\r
 \r
                                //\r
@@ -849,13 +864,19 @@ public class NuxeoImageUtils {
                                BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob);\r
                                result.setBlobsCommon(blobsCommon);\r
                                if (getContentFlag == true) {\r
-                                       InputStream remoteStream = docBlob.getStream();\r
+                                       InputStream remoteStream = null;\r
+                                       if (isNonImageDerivative == false) {\r
+                                               remoteStream = docBlob.getStream();\r
+                                       } else {\r
+                                               remoteStream = NuxeoImageUtils.class.getClassLoader() // for now, non-image derivatives are just placeholder document images\r
+                                                   .getResourceAsStream("documentImage.jpg");\r
+                                               outMimeType.append(MIME_JPEG);\r
+                                       }\r
                                        BufferedInputStream bufferedInputStream = new BufferedInputStream(\r
                                                        remoteStream);  // FIXME: REM - To improve performance, try\r
                                                                                        // BufferedInputStream(InputStream in, int size)?\r
                                        result.setBlobInputStream(bufferedInputStream);\r
                                }\r
-\r
                        } catch (Exception e) {\r
                                if (logger.isErrorEnabled() == true) {\r
                                        logger.error(e.getMessage(), e);\r
@@ -864,7 +885,7 @@ public class NuxeoImageUtils {
                        }\r
 \r
                return result;\r
-       }\r
+       }       \r
 }\r
 \r
 /*\r
diff --git a/services/common/src/main/resources/documentImage.jpg b/services/common/src/main/resources/documentImage.jpg
new file mode 100644 (file)
index 0000000..89d5066
Binary files /dev/null and b/services/common/src/main/resources/documentImage.jpg differ