Merged V2.1-A to HEAD

7693: Pass contentReader and contentWriter noderef options to content transformer (when invoked from transform action).


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8667 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-04-03 10:28:12 +00:00
parent e5bfb7e8fa
commit a5b1a90a29
3 changed files with 20 additions and 24 deletions

View File

@@ -209,9 +209,6 @@
<property name="mimetypeService"> <property name="mimetypeService">
<ref bean="mimetypeService" /> <ref bean="mimetypeService" />
</property> </property>
<property name="transformerRegistry">
<ref bean="contentTransformerRegistry" />
</property>
<property name="applicableTypes"> <property name="applicableTypes">
<list> <list>
<value>{http://www.alfresco.org/model/content/1.0}content</value> <value>{http://www.alfresco.org/model/content/1.0}content</value>

View File

@@ -28,8 +28,6 @@ import java.util.List;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl; import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.transform.ContentTransformer;
import org.alfresco.repo.content.transform.ContentTransformerRegistry;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -55,7 +53,7 @@ import org.apache.commons.logging.LogFactory;
* @author Roy Wetherall * @author Roy Wetherall
*/ */
public class TransformActionExecuter extends ActionExecuterAbstractBase public class TransformActionExecuter extends ActionExecuterAbstractBase
{ {
/** Error messages */ /** Error messages */
public static final String ERR_OVERWRITE = "Unable to overwrite copy because more than one have been found."; public static final String ERR_OVERWRITE = "Unable to overwrite copy because more than one have been found.";
@@ -82,7 +80,6 @@ public class TransformActionExecuter extends ActionExecuterAbstractBase
private ContentService contentService; private ContentService contentService;
private CopyService copyService; private CopyService copyService;
private MimetypeService mimetypeService; private MimetypeService mimetypeService;
private ContentTransformerRegistry transformerRegistry;
/** /**
* Set the mime type service * Set the mime type service
@@ -134,16 +131,6 @@ public class TransformActionExecuter extends ActionExecuterAbstractBase
this.copyService = copyService; this.copyService = copyService;
} }
/**
* Set the transformer registry
*
* @param transformerRegistry the transformer registry
*/
public void setTransformerRegistry(ContentTransformerRegistry transformerRegistry)
{
this.transformerRegistry = transformerRegistry;
}
/** /**
* Add parameter definitions * Add parameter definitions
*/ */
@@ -298,15 +285,18 @@ public class TransformActionExecuter extends ActionExecuterAbstractBase
protected void doTransform( Action ruleAction, protected void doTransform( Action ruleAction,
NodeRef sourceNodeRef, ContentReader contentReader, NodeRef sourceNodeRef, ContentReader contentReader,
NodeRef destinationNodeRef, ContentWriter contentWriter) NodeRef destinationNodeRef, ContentWriter contentWriter)
{ {
// try to pre-empt the lack of a transformer // Transformation options
if (!this.contentService.isTransformable(contentReader, contentWriter)) TransformationOptions options = new TransformationOptions(sourceNodeRef, ContentModel.PROP_NAME, destinationNodeRef, ContentModel.PROP_NAME);
// try to pre-empt the lack of a transformer
if (this.contentService.isTransformable(contentReader, contentWriter, options) == false)
{ {
throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype()); throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype());
} }
// transform // transform
TransformationOptions options = new TransformationOptions(sourceNodeRef, ContentModel.PROP_NAME, destinationNodeRef, ContentModel.PROP_NAME);
this.contentService.transform(contentReader, contentWriter, options); this.contentService.transform(contentReader, contentWriter, options);
} }

View File

@@ -41,9 +41,9 @@ import org.alfresco.service.namespace.QName;
public class TransformationOptions public class TransformationOptions
{ {
/** Option map names to preserve backward compatibility */ /** Option map names to preserve backward compatibility */
public static final String OPT_SOURCE_NODEREF = "sourceNodeRef"; public static final String OPT_SOURCE_NODEREF = "contentReaderNodeRef";
public static final String OPT_SOURCE_CONTENT_PROPERTY = "sourceContentProperty"; public static final String OPT_SOURCE_CONTENT_PROPERTY = "sourceContentProperty";
public static final String OPT_TARGET_NODEREF = "targetNodeRef"; public static final String OPT_TARGET_NODEREF = "contentWriterNodeRef";
public static final String OPT_TARGET_CONTENT_PROPERTY = "targetContentProperty"; public static final String OPT_TARGET_CONTENT_PROPERTY = "targetContentProperty";
/** The source node reference */ /** The source node reference */
@@ -182,6 +182,11 @@ public class TransformationOptions
return new HashMap<String, Object>(10); return new HashMap<String, Object>(10);
} }
/**
* Places the values of the transformation options into a Map
*
* @param optionsMap the options map
*/
protected void toMapImpl(Map<String, Object> optionsMap) protected void toMapImpl(Map<String, Object> optionsMap)
{ {
optionsMap.put(OPT_SOURCE_NODEREF, getSourceNodeRef()); optionsMap.put(OPT_SOURCE_NODEREF, getSourceNodeRef());
@@ -190,12 +195,16 @@ public class TransformationOptions
optionsMap.put(OPT_TARGET_CONTENT_PROPERTY, getTargetContentProperty()); 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<String, Object> optionsMap) protected void fromMapImpl(Map<String, Object> optionsMap)
{ {
this.sourceNodeRef = (NodeRef)optionsMap.get(OPT_SOURCE_NODEREF); this.sourceNodeRef = (NodeRef)optionsMap.get(OPT_SOURCE_NODEREF);
this.sourceContentProperty = (QName)optionsMap.get(OPT_SOURCE_CONTENT_PROPERTY); this.sourceContentProperty = (QName)optionsMap.get(OPT_SOURCE_CONTENT_PROPERTY);
this.targetNodeRef = (NodeRef)optionsMap.get(OPT_TARGET_NODEREF); this.targetNodeRef = (NodeRef)optionsMap.get(OPT_TARGET_NODEREF);
this.targetContentProperty = (QName)optionsMap.get(OPT_TARGET_CONTENT_PROPERTY); this.targetContentProperty = (QName)optionsMap.get(OPT_TARGET_CONTENT_PROPERTY);
} }
} }