KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > executer > ImageTransformActionExecuter


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.action.executer;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
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 /**
33  * Transfor action executer
34  *
35  * @author Roy Wetherall
36  */

37 public class ImageTransformActionExecuter extends TransformActionExecuter
38 {
39     /**
40      * Action constants
41      */

42     public static final String JavaDoc NAME = "transform-image";
43     public static final String JavaDoc PARAM_CONVERT_COMMAND = "convert-command";
44     
45     private ImageMagickContentTransformer imageMagickContentTransformer;
46     
47     /**
48      * Set the image magick content transformer
49      *
50      * @param imageMagickContentTransformer the conten transformer
51      */

52     public void setImageMagickContentTransformer(ImageMagickContentTransformer imageMagickContentTransformer)
53     {
54         this.imageMagickContentTransformer = imageMagickContentTransformer;
55     }
56     
57     /**
58      * Add parameter definitions
59      */

60     @Override JavaDoc
61     protected void addParameterDefintions(List JavaDoc<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     /**
68      * @see org.alfresco.repo.action.executer.TransformActionExecuter#doTransform(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter)
69      */

70     protected void doTransform(Action ruleAction, ContentReader contentReader, ContentWriter contentWriter)
71     {
72         // check if the transformer is going to work, i.e. is available
73
if (!this.imageMagickContentTransformer.isAvailable())
74         {
75             throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype());
76         }
77         // Try and transform the content
78
String JavaDoc convertCommand = (String JavaDoc)ruleAction.getParameterValue(PARAM_CONVERT_COMMAND);
79         // create some options for the transform
80
Map JavaDoc<String JavaDoc, Object JavaDoc> options = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>(5);
81         options.put(ImageMagickContentTransformer.KEY_OPTIONS, convertCommand);
82         
83         this.imageMagickContentTransformer.transform(contentReader, contentWriter, options);
84     }
85 }
86
Popular Tags