From 0876d67c4d1e43f2bb1c8c2628fb106551fb9b23 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Wed, 3 Sep 2008 18:37:10 +0000 Subject: [PATCH] Thumbnail Service: text and html to image and swf now work git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10705 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/content-services-context.xml | 16 ++++++ config/alfresco/swf-transform-context.xml | 16 ++++++ .../repo/thumbnail/ThumbnailServiceImpl.java | 7 +-- .../thumbnail/ThumbnailServiceImplTest.java | 52 +++++++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/config/alfresco/content-services-context.xml b/config/alfresco/content-services-context.xml index 24a34ba4ac..f1ff67f080 100644 --- a/config/alfresco/content-services-context.xml +++ b/config/alfresco/content-services-context.xml @@ -271,6 +271,22 @@ + + + + + + + + + + application/pdf + + + + diff --git a/config/alfresco/swf-transform-context.xml b/config/alfresco/swf-transform-context.xml index b587b5012c..5bbae05e00 100644 --- a/config/alfresco/swf-transform-context.xml +++ b/config/alfresco/swf-transform-context.xml @@ -30,5 +30,21 @@ + + + + + + + + + + + application/pdf + + + diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java index 7c24d4bc03..676a0896e2 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java @@ -25,6 +25,7 @@ package org.alfresco.repo.thumbnail; import java.io.Serializable; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -55,7 +56,7 @@ import org.alfresco.util.ParameterCheck; public class ThumbnailServiceImpl implements ThumbnailService { /** Error messages */ - private static final String ERR_NO_CREATE = "Thumbnail could not be created as required transformation is not supported."; + private static final String ERR_NO_CREATE = "Thumbnail could not be created as required transformation is not supported from {0} to {1}"; private static final String ERR_DUPLICATE_NAME = "Thumbnail could not be created because of a duplicate name"; private static final String ERR_NO_PARENT = "Thumbnail has no parent so update cannot take place."; private static final String ERR_TOO_PARENT = "Thumbnail has more than one source content node. This is invalid so update cannot take place."; @@ -209,7 +210,7 @@ public class ThumbnailServiceImpl implements ThumbnailService if (this.contentService.isTransformable(reader, writer, transformationOptions) == false) { // Throw exception indicating that the thumbnail could not be created - throw new ThumbnailException(ERR_NO_CREATE); + throw new ThumbnailException(MessageFormat.format(ERR_NO_CREATE, reader.getMimetype(), writer.getMimetype())); } else { @@ -278,7 +279,7 @@ public class ThumbnailServiceImpl implements ThumbnailService if (this.contentService.isTransformable(reader, writer, transformationOptions) == false) { // Throw exception indicating that the thumbnail could not be created - throw new ThumbnailException(ERR_NO_CREATE); + throw new ThumbnailException(MessageFormat.format(ERR_NO_CREATE, reader.getMimetype(), writer.getMimetype())); } else { diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java index 4176596ce5..7614847067 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java @@ -37,6 +37,7 @@ import org.alfresco.repo.content.transform.AbstractContentTransformerTest; import org.alfresco.repo.content.transform.magick.ImageResizeOptions; import org.alfresco.repo.content.transform.magick.ImageTransformationOptions; import org.alfresco.repo.jscript.ClasspathScriptLocation; +import org.alfresco.repo.node.db.NodeDaoService; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentReader; @@ -348,6 +349,57 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest } } + public void testHTMLToImageAndSWF() throws Exception + { + NodeRef nodeRef = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_HTML); + ThumbnailDefinition def = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("medium"); + + if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_HTML, def.getMimetype(), def.getTransformationOptions()) != null) + { + NodeRef thumb = this.thumbnailService.createThumbnail( + nodeRef, + ContentModel.PROP_CONTENT, + def.getMimetype(), + def.getTransformationOptions(), + def.getName()); + assertNotNull(thumb); + ContentReader reader = this.contentService.getReader(thumb, ContentModel.PROP_CONTENT); + assertNotNull(reader); + assertEquals(def.getMimetype(), reader.getMimetype()); + assertTrue(reader.getSize() != 0); + } + + + def = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("webpreview"); + if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_HTML, def.getMimetype(), def.getTransformationOptions()) != null) + { + NodeRef thumb = this.thumbnailService.createThumbnail( + nodeRef, + ContentModel.PROP_CONTENT, + def.getMimetype(), + def.getTransformationOptions(), + def.getName()); + assertNotNull(thumb); + ContentReader reader = this.contentService.getReader(thumb, ContentModel.PROP_CONTENT); + assertNotNull(reader); + assertEquals(def.getMimetype(), reader.getMimetype()); + assertTrue(reader.getSize() != 0); + } + } + + public void testRegistry() + { + ThumbnailRegistry thumbnailRegistry = this.thumbnailService.getThumbnailRegistry(); + List defs = thumbnailRegistry.getThumnailDefintions(MimetypeMap.MIMETYPE_HTML); + System.out.println("Definitions ..."); + for (ThumbnailDefinition def : defs) + { + System.out.println("Thumbnail Available: " + def.getName()); + } + } + + + // == Test the JavaScript API == public void testJSAPI() throws Exception