From c16bdad03f3534e31cd38bba87a58fb1623cdea7 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Thu, 8 Jan 2009 12:55:20 +0000 Subject: [PATCH] Fixed ALFCOM-2285: swf2pdf command is hard-coded - Added toMap() method to TransformationOptions - toMap() of SWFTransformationOptions adds 'flashVersion' property - RuntimeExecutableContentTransformer uses toMap() to override default properties - Changed 'transformer.Pdf2swf' bean to use RuntimeExecutableContentTransformer - Removed PDFToSWFContentTransformer git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12623 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/swf-transform-context.xml | 36 ++- .../executer/TransformActionExecuter.java | 8 +- .../RuntimeExecutableContentTransformer.java | 13 +- ...meExecutableContentTransformerOptions.java | 16 +- .../ImageMagickContentTransformerTest.java | 6 +- .../swf/PDFToSWFContentTransformer.java | 273 ------------------ .../swf/SWFTransformationOptions.java | 16 + .../CreateThumbnailActionExecuter.java | 1 - .../thumbnail/ThumbnailServiceImplTest.java | 4 - .../cmr/repository/TransformationOptions.java | 64 ++-- 10 files changed, 99 insertions(+), 338 deletions(-) delete mode 100644 source/java/org/alfresco/repo/content/transform/swf/PDFToSWFContentTransformer.java diff --git a/config/alfresco/swf-transform-context.xml b/config/alfresco/swf-transform-context.xml index 5bbae05e00..1a7261f65d 100644 --- a/config/alfresco/swf-transform-context.xml +++ b/config/alfresco/swf-transform-context.xml @@ -3,7 +3,40 @@ - + + + + + + + pdf2swf -V + + + + + 1 + + + + + + + + + pdf2swf -T ${flashVersion} ${source} -o ${target} + + + + + + + + + + 1 + + + @@ -12,7 +45,6 @@ - properties = new HashMap(5); // copy options over - if (options instanceof RuntimeExecutableContentTransformerOptions) + Map optionsMap = options.toMap(); + for (Map.Entry entry : optionsMap.entrySet()) { - RuntimeExecutableContentTransformerOptions runtimeOptions = (RuntimeExecutableContentTransformerOptions)options; - for (Map.Entry entry : runtimeOptions.getPropertyValues().entrySet()) - { - String key = entry.getKey(); - Object value = entry.getValue(); - properties.put(key, (value == null ? null : value.toString())); - } + String key = entry.getKey(); + Object value = entry.getValue(); + properties.put(key, (value == null ? null : value.toString())); } // add the source and target properties properties.put(VAR_SOURCE, sourceFile.getAbsolutePath()); diff --git a/source/java/org/alfresco/repo/content/transform/RuntimeExecutableContentTransformerOptions.java b/source/java/org/alfresco/repo/content/transform/RuntimeExecutableContentTransformerOptions.java index 5b233a4d7f..44cbe2be08 100644 --- a/source/java/org/alfresco/repo/content/transform/RuntimeExecutableContentTransformerOptions.java +++ b/source/java/org/alfresco/repo/content/transform/RuntimeExecutableContentTransformerOptions.java @@ -40,25 +40,27 @@ import org.alfresco.service.cmr.repository.TransformationOptions; public class RuntimeExecutableContentTransformerOptions extends TransformationOptions { /** Map of property values */ - private Map propertyValues = new HashMap(1); + private Map propertyValues = new HashMap(11); /** * Sets the map of property values that are used when executing the transformer * * @param propertyValues property value */ - public void setPropertyValues(Map propertyValues) + public void setPropertyValues(Map propertyValues) { this.propertyValues = propertyValues; } /** - * Gets the map of property values that are used when executing the transformer - * - * @return Map property values + * Overrides the base class implementation to add all values set in {@link #setPropertyValues(Map)} */ - public Map getPropertyValues() + @Override + public Map toMap() { - return propertyValues; + Map baseProps = super.toMap(); + Map props = new HashMap(baseProps); + props.putAll(propertyValues); + return props; } } diff --git a/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerTest.java b/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerTest.java index 2c256e84e0..4017d0c646 100644 --- a/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerTest.java +++ b/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerTest.java @@ -70,9 +70,11 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme { return; } - boolean reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_IMAGE_GIF, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions()); + boolean reliability = transformer.isTransformable( + MimetypeMap.MIMETYPE_IMAGE_GIF, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions()); assertEquals("Mimetype should not be supported", false, reliability); - reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_IMAGE_GIF, MimetypeMap.MIMETYPE_IMAGE_JPEG, new TransformationOptions()); + reliability = transformer.isTransformable( + MimetypeMap.MIMETYPE_IMAGE_GIF, MimetypeMap.MIMETYPE_IMAGE_JPEG, new TransformationOptions()); assertEquals("Mimetype should be supported", true, reliability); } } diff --git a/source/java/org/alfresco/repo/content/transform/swf/PDFToSWFContentTransformer.java b/source/java/org/alfresco/repo/content/transform/swf/PDFToSWFContentTransformer.java deleted file mode 100644 index 5b377a3a5b..0000000000 --- a/source/java/org/alfresco/repo/content/transform/swf/PDFToSWFContentTransformer.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (C) 2005-2008 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.content.transform.swf; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.content.transform.AbstractContentTransformer2; -import org.alfresco.service.cmr.repository.ContentIOException; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.TransformationOptions; -import org.alfresco.util.TempFileProvider; -import org.alfresco.util.exec.RuntimeExec; -import org.alfresco.util.exec.RuntimeExec.ExecutionResult; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * PDF to SWF content transformer - * - * @author Roy Wetherall - */ -public class PDFToSWFContentTransformer extends AbstractContentTransformer2 -{ - /** Logger */ - private static final Log logger = LogFactory.getLog(PDFToSWFContentTransformer.class); - - /** Used to indicate whether the transformaer in available or not */ - private boolean available = false; - - /** Stores the output from the check command */ - private String versionString; - - /** Check and transform command */ - private RuntimeExec checkCommand; - private RuntimeExec transformCommand; - - /** Default flash version to convert to */ - private static final String DEFAULT_FLASH_VERSION = "9"; - - /** Check command string */ - private static final String PDF2SWF_CHECK = "pdf2swf -V"; - - /** Transformation command string */ - private static final String PDF2SWF_COMMAND = "pdf2swf -t ${flashVersion} ${source} -o ${target}"; - private static final String VAR_SOURCE = "source"; - private static final String VAR_TARGET = "target"; - private static final String VAR_FLASH_VERSION = "flashVersion"; - - /** - * Get the check command for the PDF2SWF tool - * - * @return RuntimeExec check command - */ - private RuntimeExec getCheckCommand() - { - if (this.checkCommand == null) - { - this.checkCommand = createCommand(PDF2SWF_CHECK); - } - - return this.checkCommand; - } - - /** - * Get the transform command for the PDF2SWF tool - * - * @return RuntimeExec transform command - */ - private RuntimeExec getTransformCommand() - { - if (this.transformCommand == null) - { - this.transformCommand = createCommand(PDF2SWF_COMMAND); - } - - return this.transformCommand; - } - - /** - * Helper to create a runtime exec object for a given command string - * - * @param commandString command string - * @return RuntimeExec runtime exec command - */ - private RuntimeExec createCommand(String commandString) - { - // Create command - RuntimeExec result = new RuntimeExec(); - - // Set the command string - Map commandsByOS = new HashMap(1); - commandsByOS.put(".*", commandString); - result.setCommandMap(commandsByOS); - - // Set the error code - result.setErrorCodes("1"); - - return result; - } - - /** - * @see org.alfresco.repo.content.transform.AbstractContentTransformer2#register() - */ - @Override - public void register() - { - ExecutionResult result = getCheckCommand().execute(); - // check the return code - if (this.available = result.getSuccess()) - { - this.versionString = result.getStdOut().trim(); - } - else - { - logger.error("Failed to start SWF2PDF transformer: \n" + result); - } - - // call the base class to make sure that it gets registered - super.register(); - } - - /** - * @see org.alfresco.repo.content.transform.AbstractContentTransformer2#transformInternal(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions) - */ - @Override - protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) - throws Exception - { - // get mimetypes - String sourceMimetype = getMimetype(reader); - String targetMimetype = getMimetype(writer); - - // get the extensions to use - String sourceExtension = getMimetypeService().getExtension(sourceMimetype); - String targetExtension = getMimetypeService().getExtension(targetMimetype); - if (sourceExtension == null || targetExtension == null) - { - throw new AlfrescoRuntimeException("Unknown extensions for mimetypes: \n" + - " source mimetype: " + sourceMimetype + "\n" + - " source extension: " + sourceExtension + "\n" + - " target mimetype: " + targetMimetype + "\n" + - " target extension: " + targetExtension); - } - - // create required temp files - File sourceFile = TempFileProvider.createTempFile( - getClass().getSimpleName() + "_source_", - "." + sourceExtension); - File targetFile = TempFileProvider.createTempFile( - getClass().getSimpleName() + "_target_", - "." + targetExtension); - - String flashVersion = DEFAULT_FLASH_VERSION; - Map properties = new HashMap(5); - if (options instanceof SWFTransformationOptions) - { - SWFTransformationOptions swfOptions = (SWFTransformationOptions)options; - if (swfOptions.getFlashVersion() != null) - { - flashVersion = swfOptions.getFlashVersion(); - } - } - properties.put(VAR_FLASH_VERSION, "-T " + flashVersion); - - // add the source and target properties - properties.put(VAR_SOURCE, sourceFile.getAbsolutePath()); - properties.put(VAR_TARGET, targetFile.getAbsolutePath()); - - // pull reader file into source temp file - reader.getContent(sourceFile); - - // execute the transformation command - ExecutionResult result = null; - try - { - result = getTransformCommand().execute(properties); - } - catch (Throwable e) - { - throw new ContentIOException("Transformation failed during command execution: \n" + transformCommand, e); - } - - // check - if (!result.getSuccess()) - { - throw new ContentIOException("Transformation failed - status indicates an error: \n" + result); - } - - // check that the file was created - if (!targetFile.exists()) - { - throw new ContentIOException("Transformation failed - target file doesn't exist: \n" + result); - } - // copy the target file back into the repo - writer.putContent(targetFile); - - // done - if (logger.isDebugEnabled()) - { - logger.debug("PDF2SWF transformation completed: \n" + - " source: " + reader + "\n" + - " target: " + writer + "\n" + - " options: " + options + "\n" + - " result: \n" + result); - } - } - - /** - * @see org.alfresco.repo.content.transform.ContentTransformer#isTransformable(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions) - */ - public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options) - { - boolean result = false; - - if (this.available == true) - { - if (MimetypeMap.MIMETYPE_PDF.equals(sourceMimetype) == true && - MimetypeMap.MIMETYPE_FLASH.equals(targetMimetype) == true) - { - result = true; - } - } - - return result; - } - - /** - * Signals whether this transformer is available. - * - * @return true, if is available - */ - public boolean isAvailable() - { - return this.available; - } - - /** - * Gets the version string captured from the check command. - * - * @return the version string - */ - public String getVersionString() - { - return this.versionString; - } -} diff --git a/source/java/org/alfresco/repo/content/transform/swf/SWFTransformationOptions.java b/source/java/org/alfresco/repo/content/transform/swf/SWFTransformationOptions.java index 26316cf002..4565dc69a2 100644 --- a/source/java/org/alfresco/repo/content/transform/swf/SWFTransformationOptions.java +++ b/source/java/org/alfresco/repo/content/transform/swf/SWFTransformationOptions.java @@ -24,7 +24,11 @@ */ package org.alfresco.repo.content.transform.swf; +import java.util.HashMap; +import java.util.Map; + import org.alfresco.service.cmr.repository.TransformationOptions; +import org.alfresco.util.ParameterCheck; /** * SFW transformation options @@ -33,11 +37,14 @@ import org.alfresco.service.cmr.repository.TransformationOptions; */ public class SWFTransformationOptions extends TransformationOptions { + private static final String OPT_FLASH_VERSION = "flashVersion"; + /** The version of the flash to convert to */ private String flashVersion = "9"; public void setFlashVersion(String flashVersion) { + ParameterCheck.mandatory("flashVersion", flashVersion); this.flashVersion = flashVersion; } @@ -45,4 +52,13 @@ public class SWFTransformationOptions extends TransformationOptions { return flashVersion; } + + @Override + public Map toMap() + { + Map baseProps = super.toMap(); + Map props = new HashMap(baseProps); + props.put(OPT_FLASH_VERSION, flashVersion); + return props; + } } diff --git a/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java b/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java index 91dc984a73..c8076f87f2 100644 --- a/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java +++ b/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java @@ -30,7 +30,6 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ParameterDefinitionImpl; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; -import org.alfresco.repo.node.NodeRefPropertyMethodInterceptor; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java index 262f00faf1..85f2fb6d09 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java @@ -37,7 +37,6 @@ 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; @@ -94,7 +93,6 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest { } - /* public void testCreateThumbnailFromImage() throws Exception { // Check that the image transformations are available @@ -427,6 +425,4 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/thumbnail/script/test_thumbnailAPI.js"); this.scriptService.executeScript(location, model); } - - */ } diff --git a/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java b/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java index 29c18c0f94..f22dd8dbc1 100644 --- a/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java +++ b/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java @@ -30,13 +30,15 @@ import java.util.Map; import org.alfresco.service.namespace.QName; /** - * Tansformation options. - *

* Class containing values of options that are passed to content transformers. These options * are used to determine the applicability of a content transformer and also during the * transformation process to provide context or parameter values. + *

+ * This base class provides some common, optional contextual information about the source and + * target nodes and properties used by the transformation. * * @author Roy Wetherall + * @since 3.0.0 */ public class TransformationOptions { @@ -73,7 +75,8 @@ public class TransformationOptions * @param targetNodeRef the target node reference * @param targetContentProperty the target content property */ - public TransformationOptions(NodeRef sourceNodeRef, QName sourceContentProperty, NodeRef targetNodeRef, QName targetContentProperty) + public TransformationOptions( + NodeRef sourceNodeRef, QName sourceContentProperty, NodeRef targetNodeRef, QName targetContentProperty) { this.sourceNodeRef = sourceNodeRef; this.sourceContentProperty = sourceContentProperty; @@ -89,7 +92,10 @@ public class TransformationOptions */ public TransformationOptions(Map optionsMap) { - fromMapImpl(optionsMap); + this.sourceNodeRef = (NodeRef)optionsMap.get(OPT_SOURCE_NODEREF); + this.sourceContentProperty = (QName)optionsMap.get(OPT_SOURCE_CONTENT_PROPERTY); + this.targetNodeRef = (NodeRef)optionsMap.get(OPT_TARGET_NODEREF); + this.targetContentProperty = (QName)optionsMap.get(OPT_TARGET_CONTENT_PROPERTY); } /** @@ -171,40 +177,28 @@ public class TransformationOptions { return targetContentProperty; } - + /** - * Converts the transformation options object into an equivalent map - * - * @return + * Convert the transformation options into a map. + *

+ * Basic options (optional) are: + *

    + *
  • {@link #OPT_SOURCE_NODEREF}
  • + *
  • {@link #OPT_SOURCE_CONTENT_PROPERTY}
  • + *
  • {@link #OPT_TARGET_NODEREF}
  • + *
  • {@link #OPT_TARGET_CONTENT_PROPERTY}
  • + *
+ *

+ * Override this method to append option values to the map. Derived classes should call + * the base class before appending further values and returning the result. */ public Map toMap() { - return new HashMap(10); + Map optionsMap = new HashMap(7); + optionsMap.put(OPT_SOURCE_NODEREF, sourceNodeRef); + optionsMap.put(OPT_SOURCE_CONTENT_PROPERTY, sourceContentProperty); + optionsMap.put(OPT_TARGET_NODEREF, targetNodeRef); + optionsMap.put(OPT_TARGET_CONTENT_PROPERTY, targetContentProperty); + return optionsMap; } - - /** - * Places the values of the transformation options into a Map - * - * @param optionsMap the options map - */ - protected void toMapImpl(Map optionsMap) - { - optionsMap.put(OPT_SOURCE_NODEREF, getSourceNodeRef()); - optionsMap.put(OPT_SOURCE_CONTENT_PROPERTY, getSourceContentProperty()); - optionsMap.put(OPT_TARGET_NODEREF, getTargetNodeRef()); - optionsMap.put(OPT_TARGET_CONTENT_PROPERTY, getTargetContentProperty()); - } - - /** - * Populates the transformation options from a given Map of value. - * - * @param optionsMap the options map - */ - protected void fromMapImpl(Map optionsMap) - { - this.sourceNodeRef = (NodeRef)optionsMap.get(OPT_SOURCE_NODEREF); - this.sourceContentProperty = (QName)optionsMap.get(OPT_SOURCE_CONTENT_PROPERTY); - this.targetNodeRef = (NodeRef)optionsMap.get(OPT_TARGET_NODEREF); - this.targetContentProperty = (QName)optionsMap.get(OPT_TARGET_CONTENT_PROPERTY); - } }