<?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>
--- /dev/null
+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) {
+ }
+}