1 17 package org.alfresco.repo.content.transform.magick; 18 19 import java.io.File ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.alfresco.error.AlfrescoRuntimeException; 24 import org.alfresco.service.cmr.repository.ContentIOException; 25 import org.alfresco.util.exec.RuntimeExec; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 34 public class ImageMagickContentTransformer extends AbstractImageMagickContentTransformer 35 { 36 37 public static final String KEY_OPTIONS = "options"; 38 39 public static final String VAR_OPTIONS = "options"; 40 41 public static final String VAR_SOURCE = "source"; 42 43 public static final String VAR_TARGET = "target"; 44 45 private static final Log logger = LogFactory.getLog(ImageMagickContentTransformer.class); 46 47 48 private RuntimeExec executer; 49 50 public ImageMagickContentTransformer() 51 { 52 } 53 54 68 public void setExecuter(RuntimeExec executer) 69 { 70 this.executer = executer; 71 } 72 73 78 public void init() 79 { 80 if (executer == null) 81 { 82 throw new AlfrescoRuntimeException("System runtime executer not set"); 83 } 84 super.init(); 85 } 86 87 90 protected void transformInternal(File sourceFile, File targetFile, Map <String , Object > options) throws Exception 91 { 92 Map <String , String > properties = new HashMap <String , String >(5); 93 properties.put(KEY_OPTIONS, (String ) options.get(KEY_OPTIONS)); 95 properties.put(VAR_SOURCE, sourceFile.getAbsolutePath()); 96 properties.put(VAR_TARGET, targetFile.getAbsolutePath()); 97 98 RuntimeExec.ExecutionResult result = executer.execute(properties); 100 if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0) 101 { 102 throw new ContentIOException("Failed to perform ImageMagick transformation: \n" + result); 103 } 104 if (logger.isDebugEnabled()) 106 { 107 logger.debug("ImageMagic executed successfully: \n" + executer); 108 } 109 } 110 } 111 | Popular Tags |