]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5437: Adding support for image thumbnail creation.
authorRichard Millet <remillet@berkeley.edu>
Wed, 1 Aug 2012 22:06:23 +0000 (15:06 -0700)
committerRichard Millet <remillet@berkeley.edu>
Wed, 1 Aug 2012 22:06:23 +0000 (15:06 -0700)
3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/core-types-contrib.xml
services/common/pom.xml
services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java
services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/ThumbnailConverter.java [new file with mode: 0644]

index 8be0f16199d9c5be60ea6eafdf643c147b1aee6d..c6d4461c3385bdd80e4ad4b0eb3dceb6b69f55ce 100644 (file)
@@ -1,29 +1,62 @@
 <?xml version="1.0"?>
 <component name="org.collectionspace.collectionspace_core.coreTypes">
-  <extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
-    <schema name="collectionspace_core" prefix="collectionspace_core" src="schemas/collectionspace_core.xsd"/>
-    <schema name="subitem" prefix="subitem" src="schemas/subitem.xsd"/>
-  </extension>
-  <extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
-    <doctype name="CollectionSpaceDocument" extends="Document">
-      <schema name="common"/>
-      <schema name="dublincore"/>
-      <schema name="collectionspace_core"/>
-    </doctype>
-  </extension>  
-  <extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
-    <doctype name="CollectionSpace_Core" extends="Document">
-      <schema name="common"/>
-      <schema name="dublincore"/>
-      <schema name="collectionspace_core"/>
-    </doctype>
-  </extension>
-  <extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
-    <doctype name="Subitem" extends="Document">
-      <schema name="common"/>
-      <schema name="dublincore"/>
-      <schema name="collectionspace_core"/>
-      <schema name="subitem"/>
-    </doctype>
-  </extension>
+       <extension target="org.nuxeo.ecm.core.schema.TypeService"
+               point="schema">
+               <schema name="collectionspace_core" prefix="collectionspace_core"
+                       src="schemas/collectionspace_core.xsd" />
+               <schema name="subitem" prefix="subitem" src="schemas/subitem.xsd" />
+       </extension>
+       <extension target="org.nuxeo.ecm.core.schema.TypeService"
+               point="doctype">
+               <doctype name="CollectionSpaceDocument" extends="Document">
+                       <schema name="common" />
+                       <schema name="dublincore" />
+                       <schema name="collectionspace_core" />
+               </doctype>
+       </extension>
+       <extension target="org.nuxeo.ecm.core.schema.TypeService"
+               point="doctype">
+               <doctype name="CollectionSpace_Core" extends="Document">
+                       <schema name="common" />
+                       <schema name="dublincore" />
+                       <schema name="collectionspace_core" />
+               </doctype>
+       </extension>
+       <extension target="org.nuxeo.ecm.core.schema.TypeService"
+               point="doctype">
+               <doctype name="Subitem" extends="Document">
+                       <schema name="common" />
+                       <schema name="dublincore" />
+                       <schema name="collectionspace_core" />
+                       <schema name="subitem" />
+               </doctype>
+       </extension>
+
+       <!-- Support for creation of document/blob thumbnails.  All of this code was take from the following two
+            blog posts:
+               http://dev.blogs.nuxeo.com/2012/06/qa-friday-thumbnails-pdf-psd-documents.html
+               http://dev.blogs.nuxeo.com/2012/06/monday-dev-heaven-adding-thumbnail-preview-document-content-nuxeo.html
+       -->
+       <extension target="org.nuxeo.ecm.core.schema.TypeService"
+               point="schema">
+               <schema name="thumbnail" src="schemas/thumbnail.xsd" prefix="thumb" />
+       </extension>
+       <extension target="org.nuxeo.ecm.core.schema.TypeService"
+               point="doctype">
+               <facet name="Thumbnail">
+                       <schema name="thumbnail" />
+               </facet>
+       </extension>
+       <extension target="org.nuxeo.ecm.platform.commandline.executor.service.CommandLineExecutorComponent" point="command">
+               <command name="toThumbnail" enabled="true">
+                       <commandLine>convert</commandLine>
+                       <parameterString>-strip -thumbnail 100x100 -background transparent -gravity center -extent 100x100 -format png -quality 75 #{inputFilePath}[0] #{outputFilePath}</parameterString>
+                       <winParameterString>-strip -thumbnail 100x100 -background transparent -gravity center -extent 100x100 -format png -quality 75 #{inputFilePath}[0] #{outputFilePath}</winParameterString>
+                       <installationDirective>You need to install ImageMagick.</installationDirective>
+               </command>
+       </extension>
+       <extension target="org.nuxeo.ecm.core.convert.service.ConversionServiceImpl" point="converter">
+               <converter name="toThumbnail" class="org.collectionspace.services.common.imaging.nuxeo.ThumbnailConverter">
+               </converter>
+       </extension>
 </component>
index 2491dc659ea256d6e38bd6bbb2b5c2ce2196a732..5b3123691ab751d47026ff35ac1e8d8d1639d8d7 100644 (file)
             <artifactId>nuxeo-core-io</artifactId>\r
             <version>${nuxeo.core.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.nuxeo.ecm.core</groupId>\r
+            <artifactId>nuxeo-core-convert</artifactId>\r
+            <version>${nuxeo.core.version}</version>\r
+        </dependency>\r
 <!-- \r
         <dependency>\r
             <groupId>org.nuxeo.ecm.core</groupId>\r
index 3f123b6b6d831745177ce0a12a0b18c40cbcb16c..ff9b10ee69682b4fe589d9b0c37670ef3ae6b232 100644 (file)
@@ -885,7 +885,8 @@ public class NuxeoImageUtils {
                        }\r
 \r
                return result;\r
-       }       \r
+       }\r
+       \r
 }\r
 \r
 /*\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/ThumbnailConverter.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/ThumbnailConverter.java
new file mode 100644 (file)
index 0000000..d6074af
--- /dev/null
@@ -0,0 +1,75 @@
+package org.collectionspace.services.common.imaging.nuxeo;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuxeo.ecm.core.api.Blob;
+import org.nuxeo.ecm.core.api.blobholder.BlobHolder;
+import org.nuxeo.ecm.core.api.impl.blob.FileBlob;
+import org.nuxeo.ecm.core.convert.api.ConversionException;
+import org.nuxeo.ecm.core.convert.cache.SimpleCachableBlobHolder;
+import org.nuxeo.ecm.core.convert.extension.Converter;
+import org.nuxeo.ecm.core.convert.extension.ConverterDescriptor;
+import org.nuxeo.ecm.core.storage.sql.coremodel.SQLBlob;
+import org.nuxeo.ecm.platform.commandline.executor.api.CmdParameters;
+import org.nuxeo.ecm.platform.commandline.executor.api.CommandAvailability;
+import org.nuxeo.ecm.platform.commandline.executor.api.CommandLineExecutorService;
+import org.nuxeo.ecm.platform.commandline.executor.api.ExecResult;
+import org.nuxeo.ecm.platform.picture.core.im.IMImageUtils;
+import org.nuxeo.runtime.api.Framework;
+import org.nuxeo.runtime.services.streaming.FileSource;
+import org.nuxeo.runtime.services.streaming.StreamSource;
+
+public class ThumbnailConverter extends IMImageUtils implements Converter {
+       private static final Log log = LogFactory.getLog(ThumbnailConverter.class);
+
+       @Override
+       public BlobHolder convert(BlobHolder blobHolder,
+                       Map<String, Serializable> parameters) throws ConversionException {
+               try {
+                       // Make sure the toThumbnail command is available
+                       CommandLineExecutorService cles = Framework
+                                       .getLocalService(CommandLineExecutorService.class);
+                       CommandAvailability commandAvailability = cles
+                                       .getCommandAvailability("toThumbnail");
+                       if (!commandAvailability.isAvailable()) {
+                               return null;
+                       }
+                       // get the input and output of the command
+                       Blob blob = blobHolder.getBlob();
+                       File inputFile = null;
+                       if (blob instanceof FileBlob) {
+                               inputFile = ((FileBlob) blob).getFile();
+                       } else if (blob instanceof SQLBlob) {
+                               StreamSource source = ((SQLBlob) blob).getBinary()
+                                               .getStreamSource();
+                               inputFile = ((FileSource) source).getFile();
+                       }
+                       if (inputFile == null) {
+                               return null;
+                       }
+                       CmdParameters params = new CmdParameters();
+                       File outputFile = File.createTempFile("nuxeoImageTarget", "."
+                                       + "png");
+                       params.addNamedParameter("inputFilePath", inputFile);
+                       params.addNamedParameter("outputFilePath", outputFile);
+
+                       ExecResult res = cles.execCommand("toThumbnail", params);
+                       if (!res.isSuccessful()) {
+                               return null;
+                       }
+                       Blob targetBlob = new FileBlob(outputFile);
+                       Framework.trackFile(outputFile, targetBlob);
+                       return new SimpleCachableBlobHolder(targetBlob);
+               } catch (Exception e) {
+                       throw new ConversionException("Thumbnail conversion has failed", e);
+               }
+       }
+
+       @Override
+       public void init(ConverterDescriptor descriptor) {
+       }
+}