1 17 package org.alfresco.repo.action.executer; 18 19 import java.util.HashMap ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.alfresco.repo.action.ParameterDefinitionImpl; 24 import org.alfresco.repo.content.transform.magick.ImageMagickContentTransformer; 25 import org.alfresco.service.cmr.action.Action; 26 import org.alfresco.service.cmr.action.ParameterDefinition; 27 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 28 import org.alfresco.service.cmr.repository.ContentReader; 29 import org.alfresco.service.cmr.repository.ContentWriter; 30 import org.alfresco.service.cmr.repository.NoTransformerException; 31 32 37 public class ImageTransformActionExecuter extends TransformActionExecuter 38 { 39 42 public static final String NAME = "transform-image"; 43 public static final String PARAM_CONVERT_COMMAND = "convert-command"; 44 45 private ImageMagickContentTransformer imageMagickContentTransformer; 46 47 52 public void setImageMagickContentTransformer(ImageMagickContentTransformer imageMagickContentTransformer) 53 { 54 this.imageMagickContentTransformer = imageMagickContentTransformer; 55 } 56 57 60 @Override 61 protected void addParameterDefintions(List <ParameterDefinition> paramList) 62 { 63 super.addParameterDefintions(paramList); 64 paramList.add(new ParameterDefinitionImpl(PARAM_CONVERT_COMMAND, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_CONVERT_COMMAND))); 65 } 66 67 70 protected void doTransform(Action ruleAction, ContentReader contentReader, ContentWriter contentWriter) 71 { 72 if (!this.imageMagickContentTransformer.isAvailable()) 74 { 75 throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype()); 76 } 77 String convertCommand = (String )ruleAction.getParameterValue(PARAM_CONVERT_COMMAND); 79 Map <String , Object > options = new HashMap <String , Object >(5); 81 options.put(ImageMagickContentTransformer.KEY_OPTIONS, convertCommand); 82 83 this.imageMagickContentTransformer.transform(contentReader, contentWriter, options); 84 } 85 } 86 | Popular Tags |