mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RenditionService. Reintroduced the spring-based configuration of ThumbnailDefinitions.
Major overhaul to the ThumbnailDefinition - RenditionDefinition conversion code. Removed the imported rendition definitions acp, replacing it with the original rendering_actions_space xml. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19129 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
18
config/alfresco/bootstrap/renderingActionSpace.xml
Normal file
18
config/alfresco/bootstrap/renderingActionSpace.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<view:view xmlns:view="http://www.alfresco.org/view/repository/1.0"
|
||||||
|
xmlns:d="http://www.alfresco.org/model/dictionary/1.0" xmlns:cm="http://www.alfresco.org/model/content/1.0"
|
||||||
|
xmlns:sys="http://www.alfresco.org/model/system/1.0" xmlns="">
|
||||||
|
|
||||||
|
<cm:folder view:childName="${spaces.rendition.rendering_actions.childname}">
|
||||||
|
<view:properties>
|
||||||
|
<sys:store-protocol>workspace</sys:store-protocol>
|
||||||
|
<sys:store-identifier>SpacesStore</sys:store-identifier>
|
||||||
|
<sys:node-uuid>rendering_actions_space</sys:node-uuid>
|
||||||
|
<cm:name>${spaces.rendition.rendering_actions.name}</cm:name>
|
||||||
|
<cm:title>${spaces.rendition.rendering_actions.name}</cm:title>
|
||||||
|
<cm:description>${spaces.rendition.rendering_actions.description}</cm:description>
|
||||||
|
</view:properties>
|
||||||
|
</cm:folder>
|
||||||
|
|
||||||
|
</view:view>
|
||||||
|
|
Binary file not shown.
@@ -569,7 +569,7 @@
|
|||||||
|
|
||||||
<props>
|
<props>
|
||||||
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
||||||
<prop key="location">alfresco/bootstrap/systemRenditionDefinitions.acp</prop>
|
<prop key="location">alfresco/bootstrap/renderingActionSpace.xml</prop>
|
||||||
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
|
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
|
||||||
</props>
|
</props>
|
||||||
</list>
|
</list>
|
||||||
|
@@ -2036,7 +2036,7 @@
|
|||||||
<property name="bootstrapView">
|
<property name="bootstrapView">
|
||||||
<props>
|
<props>
|
||||||
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
||||||
<prop key="location">alfresco/bootstrap/systemRenditionDefinitions.acp</prop>
|
<prop key="location">alfresco/bootstrap/renderingActionSpace.xml</prop>
|
||||||
</props>
|
</props>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -48,19 +48,107 @@
|
|||||||
|
|
||||||
<!-- This bean is responsible for the conversion of thumbnail definitions to
|
<!-- This bean is responsible for the conversion of thumbnail definitions to
|
||||||
rendition definitions and vice versa -->
|
rendition definitions and vice versa -->
|
||||||
<bean id ="thumbnailRenditionConvertor" class="org.alfresco.repo.thumbnail.ThumbnailRenditionConvertor" />
|
<bean id ="thumbnailRenditionConvertor" class="org.alfresco.repo.thumbnail.ThumbnailRenditionConvertor" >
|
||||||
|
<property name="renditionService" ref="renditionService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- Thumbnail Register -->
|
<!-- Thumbnail Register -->
|
||||||
<bean id="thumbnailRegistry" class="org.alfresco.repo.thumbnail.ThumbnailRegistry">
|
<bean id="thumbnailRegistry" class="org.alfresco.repo.thumbnail.ThumbnailRegistry">
|
||||||
<property name="contentService" ref="ContentService"/>
|
<property name="contentService" ref="ContentService"/>
|
||||||
<property name="renditionService" ref="renditionService" />
|
<property name="renditionService" ref="renditionService" />
|
||||||
<property name="thumbnails">
|
<property name="thumbnailDefinitions">
|
||||||
<list>
|
<list>
|
||||||
<value>medium</value>
|
<!-- Small image thumbnail options -->
|
||||||
<value>doclib</value>
|
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||||
<value>webpreview</value>
|
<property name="name" value="medium" />
|
||||||
<value>imgpreview</value>
|
<property name="mimetype" value="image/jpeg"/>
|
||||||
<value>avatar</value>
|
<property name="transformationOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
|
||||||
|
<property name="resizeOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
|
||||||
|
<property name="width" value="100"/>
|
||||||
|
<property name="height" value="100"/>
|
||||||
|
<property name="maintainAspectRatio" value="true"/>
|
||||||
|
<property name="resizeToThumbnail" value="true" />
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
<property name="placeHolderResourcePath" value="alfresco/thumbnail/thumbnail_placeholder_medium.jpg" />
|
||||||
|
<property name="runAs" value="System"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- Slingshot Document Library image thumbnail options -->
|
||||||
|
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||||
|
<property name="name" value="doclib" />
|
||||||
|
<property name="mimetype" value="image/png"/>
|
||||||
|
<property name="transformationOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
|
||||||
|
<property name="resizeOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
|
||||||
|
<property name="width" value="100"/>
|
||||||
|
<property name="height" value="100"/>
|
||||||
|
<property name="maintainAspectRatio" value="true"/>
|
||||||
|
<property name="resizeToThumbnail" value="true" />
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
<property name="placeHolderResourcePath" value="alfresco/thumbnail/thumbnail_placeholder_doclib.png" />
|
||||||
|
<property name="runAs" value="System"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- Web Preview thumbnail options -->
|
||||||
|
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||||
|
<property name="name" value="webpreview" />
|
||||||
|
<property name="mimetype" value="application/x-shockwave-flash"/>
|
||||||
|
<property name="transformationOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.swf.SWFTransformationOptions">
|
||||||
|
<property name="flashVersion" value="9"/>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
<property name="runAs" value="System"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- Image preview thumbnail options -->
|
||||||
|
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||||
|
<property name="name" value="imgpreview" />
|
||||||
|
<property name="mimetype" value="image/png"/>
|
||||||
|
<property name="transformationOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
|
||||||
|
<property name="resizeOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
|
||||||
|
<property name="width" value="480"/>
|
||||||
|
<property name="height" value="480"/>
|
||||||
|
<property name="maintainAspectRatio" value="true"/>
|
||||||
|
<property name="resizeToThumbnail" value="true" />
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
<property name="placeHolderResourcePath" value="alfresco/thumbnail/thumbnail_placeholder_imgpreview.png" />
|
||||||
|
<property name="runAs" value="System"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- User avatar image thumbnail options -->
|
||||||
|
<bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
|
||||||
|
<property name="name" value="avatar" />
|
||||||
|
<property name="mimetype" value="image/png"/>
|
||||||
|
<property name="transformationOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
|
||||||
|
<property name="resizeOptions">
|
||||||
|
<bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
|
||||||
|
<property name="width" value="64"/>
|
||||||
|
<property name="height" value="64"/>
|
||||||
|
<property name="maintainAspectRatio" value="true"/>
|
||||||
|
<property name="resizeToThumbnail" value="true" />
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
<property name="placeHolderResourcePath" value="alfresco/thumbnail/thumbnail_placeholder_avatar.png" />
|
||||||
|
<property name="runAs" value="System"/>
|
||||||
|
</bean>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
<property name="thumbnailRenditionConvertor" ref="thumbnailRenditionConvertor" />
|
<property name="thumbnailRenditionConvertor" ref="thumbnailRenditionConvertor" />
|
||||||
|
@@ -59,6 +59,7 @@ import org.alfresco.service.cmr.repository.ContentReader;
|
|||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
@@ -331,7 +332,7 @@ public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
});
|
});
|
||||||
// Sleep to let the asynchronous action queue perform the updates to the renditions.
|
// Sleep to let the asynchronous action queue perform the updates to the renditions.
|
||||||
// TODO Is there a better way?
|
// TODO Is there a better way?
|
||||||
Thread.sleep(20000);
|
Thread.sleep(30000);
|
||||||
|
|
||||||
// Get the renditions and check their content for the new title
|
// Get the renditions and check their content for the new title
|
||||||
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||||
@@ -1612,24 +1613,27 @@ public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This test method ensures that all the 'built-in' renditionDefinitions are
|
* This test method ensures that all the 'built-in' renditionDefinitions are
|
||||||
* available after startup.
|
* available after startup and that their configuration is correct.
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testEnsureBuiltinRenditionDefinitionsAvailable() throws Exception
|
public void testBuiltinRenditionDefinitions() throws Exception
|
||||||
{
|
{
|
||||||
final List<String> renditionLocalNames = Arrays.asList(new String[] { "medium", "doclib", "imgpreview",
|
final RenditionDefinition mediumRenditionDef = loadAndValidateRenditionDefinition("medium");
|
||||||
"webpreview", "avatar" });
|
final RenditionDefinition doclibRenditionDef = loadAndValidateRenditionDefinition("doclib");
|
||||||
for (String renditionLocalName : renditionLocalNames)
|
final RenditionDefinition imgpreviewRenditionDef = loadAndValidateRenditionDefinition("imgpreview");
|
||||||
{
|
final RenditionDefinition webpreviewRenditionDef = loadAndValidateRenditionDefinition("webpreview");
|
||||||
validateRenditionDefinition(renditionLocalName);
|
final RenditionDefinition avatarRenditionDef = loadAndValidateRenditionDefinition("avatar");
|
||||||
}
|
|
||||||
|
assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, mediumRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
|
||||||
|
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, doclibRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
|
||||||
|
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, imgpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
|
||||||
|
assertEquals(MimetypeMap.MIMETYPE_FLASH, webpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
|
||||||
|
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, avatarRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateRenditionDefinition(String renditionLocalName)
|
private RenditionDefinition loadAndValidateRenditionDefinition(String renditionLocalName)
|
||||||
{
|
{
|
||||||
System.out.println("Validating rendition definition: " + renditionLocalName);
|
|
||||||
|
|
||||||
QName renditionQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, renditionLocalName);
|
QName renditionQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, renditionLocalName);
|
||||||
RenditionDefinition renditionDefinition = renditionService.loadRenditionDefinition(renditionQName);
|
RenditionDefinition renditionDefinition = renditionService.loadRenditionDefinition(renditionQName);
|
||||||
assertNotNull("'" + renditionLocalName + "' rendition definition was missing.", renditionDefinition);
|
assertNotNull("'" + renditionLocalName + "' rendition definition was missing.", renditionDefinition);
|
||||||
@@ -1639,8 +1643,10 @@ public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
assertNotNull("'" + renditionLocalName + "' renditionDefinition had null renderingActionName parameter",
|
assertNotNull("'" + renditionLocalName + "' renditionDefinition had null renderingActionName parameter",
|
||||||
renditionDefinition.getParameterValue("renderingActionName"));
|
renditionDefinition.getParameterValue("renderingActionName"));
|
||||||
|
|
||||||
assertEquals("RunAs param was wrong for " + renditionLocalName, AuthenticationUtil.getSystemUserName(),
|
// All builtin renditions should be "runas" system
|
||||||
renditionDefinition.getParameterValue(AbstractRenderingEngine.PARAM_RUN_AS));
|
assertEquals(AuthenticationUtil.getSystemUserName(), renditionDefinition.getParameterValue(AbstractRenderingEngine.PARAM_RUN_AS));
|
||||||
|
|
||||||
|
return renditionDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -39,6 +39,9 @@ public class ThumbnailDefinition
|
|||||||
/** Path to placeholder thumbnail */
|
/** Path to placeholder thumbnail */
|
||||||
private String placeHolderResourcePath;
|
private String placeHolderResourcePath;
|
||||||
|
|
||||||
|
/** Username to run the thumbnailrendition as */
|
||||||
|
private String runAs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
@@ -141,7 +144,17 @@ public class ThumbnailDefinition
|
|||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRunAs(String runAs)
|
||||||
|
{
|
||||||
|
this.runAs = runAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRunAs()
|
||||||
|
{
|
||||||
|
return this.runAs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@@ -23,13 +23,19 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
||||||
import org.alfresco.service.cmr.rendition.RenditionService;
|
import org.alfresco.service.cmr.rendition.RenditionService;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
import org.alfresco.service.cmr.thumbnail.ThumbnailException;
|
import org.alfresco.service.cmr.thumbnail.ThumbnailException;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.springframework.beans.BeansException;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.event.ApplicationContextEvent;
|
||||||
|
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registry of all the thumbnail details available
|
* Registry of all the thumbnail details available
|
||||||
@@ -37,7 +43,7 @@ import org.alfresco.service.namespace.QName;
|
|||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
* @author Neil McErlean
|
* @author Neil McErlean
|
||||||
*/
|
*/
|
||||||
public class ThumbnailRegistry
|
public class ThumbnailRegistry implements ApplicationContextAware, ApplicationListener<ApplicationContextEvent>
|
||||||
{
|
{
|
||||||
/** Content service */
|
/** Content service */
|
||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
@@ -45,11 +51,6 @@ public class ThumbnailRegistry
|
|||||||
/** Rendition service */
|
/** Rendition service */
|
||||||
private RenditionService renditionService;
|
private RenditionService renditionService;
|
||||||
|
|
||||||
private List<String> thumbnails;
|
|
||||||
|
|
||||||
/** This flag indicates whether the thumbnail definitions have been lazily loaded or not. */
|
|
||||||
private boolean thumbnailDefinitionsInited = false;
|
|
||||||
|
|
||||||
/** Map of thumbnail definition */
|
/** Map of thumbnail definition */
|
||||||
private Map<String, ThumbnailDefinition> thumbnailDefinitions = new HashMap<String, ThumbnailDefinition>();
|
private Map<String, ThumbnailDefinition> thumbnailDefinitions = new HashMap<String, ThumbnailDefinition>();
|
||||||
|
|
||||||
@@ -58,6 +59,8 @@ public class ThumbnailRegistry
|
|||||||
|
|
||||||
private ThumbnailRenditionConvertor thumbnailRenditionConvertor;
|
private ThumbnailRenditionConvertor thumbnailRenditionConvertor;
|
||||||
|
|
||||||
|
private RegistryLifecycle lifecycle = new RegistryLifecycle();
|
||||||
|
|
||||||
public void setThumbnailRenditionConvertor(
|
public void setThumbnailRenditionConvertor(
|
||||||
ThumbnailRenditionConvertor thumbnailRenditionConvertor)
|
ThumbnailRenditionConvertor thumbnailRenditionConvertor)
|
||||||
{
|
{
|
||||||
@@ -89,12 +92,47 @@ public class ThumbnailRegistry
|
|||||||
this.renditionService = renditionService;
|
this.renditionService = renditionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThumbnails(final List<String> thumbnails)
|
/**
|
||||||
|
* This method is used to inject the thumbnail definitions.
|
||||||
|
* @param thumbnailDefinitions
|
||||||
|
*/
|
||||||
|
public void setThumbnailDefinitions(final List<ThumbnailDefinition> thumbnailDefinitions)
|
||||||
{
|
{
|
||||||
this.thumbnails = thumbnails;
|
for (ThumbnailDefinition td : thumbnailDefinitions)
|
||||||
|
{
|
||||||
|
String thumbnailName = td.getName();
|
||||||
|
if (thumbnailName == null)
|
||||||
|
{
|
||||||
|
throw new ThumbnailException("When adding a thumbnail details object make sure the name is set.");
|
||||||
|
}
|
||||||
|
|
||||||
// We'll not populate the data fields in the ThumbnailRegistry here, instead preferring
|
this.thumbnailDefinitions.put(thumbnailName, td);
|
||||||
// to do it lazily later.
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Those thumbnail definitions that are injected by Spring are converted
|
||||||
|
* to rendition definitions and saved.
|
||||||
|
*/
|
||||||
|
private void initThumbnailDefinitions()
|
||||||
|
{
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Void>() {
|
||||||
|
public Void doWork() throws Exception
|
||||||
|
{
|
||||||
|
for (String thumbnailDefName : thumbnailDefinitions.keySet())
|
||||||
|
{
|
||||||
|
final ThumbnailDefinition thumbnailDefinition = thumbnailDefinitions.get(thumbnailDefName);
|
||||||
|
|
||||||
|
// Built-in thumbnailDefinitions do not provide any non-standard values
|
||||||
|
// for the ThumbnailParentAssociationDetails object. Hence the null
|
||||||
|
RenditionDefinition renditionDef = thumbnailRenditionConvertor.convert(thumbnailDefinition, null);
|
||||||
|
|
||||||
|
renditionService.saveRenditionDefinition(renditionDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, AuthenticationUtil.getSystemUserName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,36 +142,11 @@ public class ThumbnailRegistry
|
|||||||
*/
|
*/
|
||||||
public List<ThumbnailDefinition> getThumbnailDefinitions()
|
public List<ThumbnailDefinition> getThumbnailDefinitions()
|
||||||
{
|
{
|
||||||
if (thumbnailDefinitionsInited == false)
|
|
||||||
{
|
|
||||||
this.initThumbnailDefinitions();
|
|
||||||
thumbnailDefinitionsInited = true;
|
|
||||||
}
|
|
||||||
return new ArrayList<ThumbnailDefinition>(this.thumbnailDefinitions.values());
|
return new ArrayList<ThumbnailDefinition>(this.thumbnailDefinitions.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initThumbnailDefinitions()
|
|
||||||
{
|
|
||||||
for (String thumbnailDefinitionName : this.thumbnails)
|
|
||||||
{
|
|
||||||
QName qName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, thumbnailDefinitionName);
|
|
||||||
RenditionDefinition rAction = renditionService
|
|
||||||
.loadRenditionDefinition(qName);
|
|
||||||
|
|
||||||
ThumbnailDefinition thDefn = thumbnailRenditionConvertor.convert(rAction);
|
|
||||||
|
|
||||||
thumbnailDefinitions.put(thumbnailDefinitionName, thDefn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ThumbnailDefinition> getThumbnailDefinitions(String mimetype)
|
public List<ThumbnailDefinition> getThumbnailDefinitions(String mimetype)
|
||||||
{
|
{
|
||||||
if (thumbnailDefinitionsInited == false)
|
|
||||||
{
|
|
||||||
this.initThumbnailDefinitions();
|
|
||||||
thumbnailDefinitionsInited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ThumbnailDefinition> result = this.mimetypeMap.get(mimetype);
|
List<ThumbnailDefinition> result = this.mimetypeMap.get(mimetype);
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
@@ -163,6 +176,7 @@ public class ThumbnailRegistry
|
|||||||
* @return
|
* @return
|
||||||
* @deprecated Use {@link #getThumbnailDefinitions(String)} instead.
|
* @deprecated Use {@link #getThumbnailDefinitions(String)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public List<ThumbnailDefinition> getThumnailDefintions(String mimetype)
|
public List<ThumbnailDefinition> getThumnailDefintions(String mimetype)
|
||||||
{
|
{
|
||||||
return this.getThumbnailDefinitions(mimetype);
|
return this.getThumbnailDefinitions(mimetype);
|
||||||
@@ -175,11 +189,6 @@ public class ThumbnailRegistry
|
|||||||
*/
|
*/
|
||||||
public void addThumbnailDefinition(ThumbnailDefinition thumbnailDetails)
|
public void addThumbnailDefinition(ThumbnailDefinition thumbnailDetails)
|
||||||
{
|
{
|
||||||
if (thumbnailDefinitionsInited == false)
|
|
||||||
{
|
|
||||||
this.initThumbnailDefinitions();
|
|
||||||
thumbnailDefinitionsInited = true;
|
|
||||||
}
|
|
||||||
String thumbnailName = thumbnailDetails.getName();
|
String thumbnailName = thumbnailDetails.getName();
|
||||||
if (thumbnailName == null)
|
if (thumbnailName == null)
|
||||||
{
|
{
|
||||||
@@ -197,11 +206,48 @@ public class ThumbnailRegistry
|
|||||||
*/
|
*/
|
||||||
public ThumbnailDefinition getThumbnailDefinition(String thumbnailName)
|
public ThumbnailDefinition getThumbnailDefinition(String thumbnailName)
|
||||||
{
|
{
|
||||||
if (thumbnailDefinitionsInited == false)
|
|
||||||
{
|
|
||||||
this.initThumbnailDefinitions();
|
|
||||||
thumbnailDefinitionsInited = true;
|
|
||||||
}
|
|
||||||
return this.thumbnailDefinitions.get(thumbnailName);
|
return this.thumbnailDefinitions.get(thumbnailName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||||
|
*/
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
|
||||||
|
{
|
||||||
|
lifecycle.setApplicationContext(applicationContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
|
||||||
|
*/
|
||||||
|
public void onApplicationEvent(ApplicationContextEvent event)
|
||||||
|
{
|
||||||
|
lifecycle.onApplicationEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class hooks in to the spring application lifecycle and ensures that any
|
||||||
|
* ThumbnailDefinitions injected by spring are converted to RenditionDefinitions
|
||||||
|
* and saved.
|
||||||
|
*/
|
||||||
|
private class RegistryLifecycle extends AbstractLifecycleBean
|
||||||
|
{
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onBootstrap(ApplicationEvent event)
|
||||||
|
{
|
||||||
|
initThumbnailDefinitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.util.AbstractLifecycleBean#onShutdown(org.springframework.context.ApplicationEvent)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onShutdown(ApplicationEvent event)
|
||||||
|
{
|
||||||
|
// Intentionally empty
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,19 +32,104 @@ import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
|||||||
import org.alfresco.service.cmr.rendition.RenditionService;
|
import org.alfresco.service.cmr.rendition.RenditionService;
|
||||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||||
import org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails;
|
import org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails;
|
||||||
|
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper class to convert {@link TransformationOptions transformationOptions} (a thumbnail-specific
|
* A helper class to convert {@link ThumbnailDefinition thumbnail definition} and
|
||||||
* class) to rendition-specific parameters and vice versa.
|
* {@link TransformationOptions transformationOptions} (thumbnail-specific
|
||||||
|
* classes) to rendition-specific parameters and vice versa.
|
||||||
|
*
|
||||||
|
* The Thumbnail Service exposes parameters as simple data types on its various method
|
||||||
|
* signatures. See for example ThumbnailDefinition.createThumbnail(...) or updateThumbnail(...).
|
||||||
|
* The RenditionService replaces this approach with one based on the ActionService where
|
||||||
|
* parameters are added as a Map on the Action/RenditionDefinition object.
|
||||||
|
*
|
||||||
|
* @see ThumbnailService#createThumbnail(org.alfresco.service.cmr.repository.NodeRef, QName, String, TransformationOptions, String)
|
||||||
|
* @see ThumbnailService#createThumbnail(org.alfresco.service.cmr.repository.NodeRef, QName, String, TransformationOptions, String, ThumbnailParentAssociationDetails)
|
||||||
|
* @see ThumbnailService#updateThumbnail(org.alfresco.service.cmr.repository.NodeRef, TransformationOptions)
|
||||||
|
* @see RenditionDefinition
|
||||||
*
|
*
|
||||||
* @author Neil McErlean
|
* @author Neil McErlean
|
||||||
*/
|
*/
|
||||||
public class ThumbnailRenditionConvertor
|
public class ThumbnailRenditionConvertor
|
||||||
{
|
{
|
||||||
|
private RenditionService renditionService;
|
||||||
|
|
||||||
|
public void setRenditionService(RenditionService renditionService)
|
||||||
|
{
|
||||||
|
this.renditionService = renditionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Given the specified {@link ThumbnailDefinition thumbnailDefinition} and
|
||||||
|
* {@link ThumbnailParentAssociationDetails assocDetails},
|
||||||
|
* create and return an equivalent {@link RenditionDefinition} object.
|
||||||
|
*
|
||||||
|
* @param thumbnailDefinition
|
||||||
|
* @param assocDetails
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public RenditionDefinition convert(ThumbnailDefinition thumbnailDefinition, ThumbnailParentAssociationDetails assocDetails)
|
||||||
|
{
|
||||||
|
// We must always have a valid name for a thumbnail definition
|
||||||
|
if (thumbnailDefinition == null || thumbnailDefinition.getName() == null
|
||||||
|
|| thumbnailDefinition.getName().trim().length() == 0)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Thumbnail Definition and Name must be non-null and non-empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
|
||||||
|
Map<String, Serializable> parameters = this.convert(transformationOptions, assocDetails);
|
||||||
|
|
||||||
|
// Extract parameters defined directly within the ThumbnailDefinition object.
|
||||||
|
putParameterIfNotNull(AbstractRenderingEngine.PARAM_MIME_TYPE, thumbnailDefinition.getMimetype(), parameters);
|
||||||
|
putParameterIfNotNull(AbstractRenderingEngine.PARAM_PLACEHOLDER_RESOURCE_PATH, thumbnailDefinition.getPlaceHolderResourcePath(), parameters);
|
||||||
|
putParameterIfNotNull(AbstractRenderingEngine.PARAM_RUN_AS, thumbnailDefinition.getRunAs(), parameters);
|
||||||
|
|
||||||
|
QName namespacedRenditionName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, thumbnailDefinition.getName());
|
||||||
|
|
||||||
|
// The built-in RenditionDefinitions are all non-composites.
|
||||||
|
// They are either "imageRenderingEngine" or "reformat"
|
||||||
|
boolean isImageThumbnail = isImageBasedRendition(thumbnailDefinition);
|
||||||
|
|
||||||
|
String renderingEngineName = isImageThumbnail ? ImageRenderingEngine.NAME : ReformatRenderingEngine.NAME;
|
||||||
|
|
||||||
|
RenditionDefinition renditionDef = renditionService.createRenditionDefinition(namespacedRenditionName, renderingEngineName);
|
||||||
|
for (String paramName : parameters.keySet())
|
||||||
|
{
|
||||||
|
renditionDef.setParameterValue(paramName, parameters.get(paramName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return renditionDef;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method examines the various data values on the thumbnail definition and
|
||||||
|
* works out if it is an 'image' rendition or a 'reformat' rendition
|
||||||
|
* @param thumbnailDefinition
|
||||||
|
* @return <code>true</code> for an image-based RenditionDefinition, else <code>false</code>
|
||||||
|
*/
|
||||||
|
private boolean isImageBasedRendition(ThumbnailDefinition thumbnailDefinition)
|
||||||
|
{
|
||||||
|
final TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
|
||||||
|
|
||||||
|
return transformationOptions != null && transformationOptions instanceof ImageTransformationOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Given the specified {@link TransformationOptions transformationOptions} and
|
||||||
|
* {@link ThumbnailParentAssociationDetails assocDetails},
|
||||||
|
* create and return a parameter Map which contains the equivalent {@link RenditionDefinition}
|
||||||
|
* configuration.
|
||||||
|
*
|
||||||
|
* @param transformationOptions
|
||||||
|
* @param assocDetails
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Map<String, Serializable> convert(TransformationOptions transformationOptions, ThumbnailParentAssociationDetails assocDetails)
|
public Map<String, Serializable> convert(TransformationOptions transformationOptions, ThumbnailParentAssociationDetails assocDetails)
|
||||||
{
|
{
|
||||||
Map<String, Serializable> parameters = new HashMap<String, Serializable>();
|
Map<String, Serializable> parameters = new HashMap<String, Serializable>();
|
||||||
|
|
||||||
// parameters common to all transformations
|
// parameters common to all transformations
|
||||||
putParameterIfNotNull(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, transformationOptions.getSourceContentProperty(), parameters);
|
putParameterIfNotNull(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, transformationOptions.getSourceContentProperty(), parameters);
|
||||||
putParameterIfNotNull(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, transformationOptions.getTargetContentProperty(), parameters);
|
putParameterIfNotNull(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, transformationOptions.getTargetContentProperty(), parameters);
|
||||||
@@ -111,8 +196,6 @@ public class ThumbnailRenditionConvertor
|
|||||||
thDefn.setPlaceHolderResourcePath((String)placeHolderResourcePathParam);
|
thDefn.setPlaceHolderResourcePath((String)placeHolderResourcePathParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO src/target contentProp & nodeRef
|
|
||||||
|
|
||||||
TransformationOptions transformationOptions = null;
|
TransformationOptions transformationOptions = null;
|
||||||
Serializable flashVersion = renditionDefinition.getParameterValue(ReformatRenderingEngine.PARAM_FLASH_VERSION);
|
Serializable flashVersion = renditionDefinition.getParameterValue(ReformatRenderingEngine.PARAM_FLASH_VERSION);
|
||||||
if (flashVersion != null)
|
if (flashVersion != null)
|
||||||
@@ -132,7 +215,6 @@ public class ThumbnailRenditionConvertor
|
|||||||
Serializable xsize = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH);
|
Serializable xsize = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH);
|
||||||
if (xsize != null)
|
if (xsize != null)
|
||||||
{
|
{
|
||||||
// Saved actions with int parameters seem to be coming back as Longs. TODO Investigate
|
|
||||||
resizeOptions.setWidth(((Long) xsize).intValue());
|
resizeOptions.setWidth(((Long) xsize).intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ import org.alfresco.repo.content.MimetypeMap;
|
|||||||
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
|
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
|
||||||
import org.alfresco.repo.content.transform.swf.SWFTransformationOptions;
|
import org.alfresco.repo.content.transform.swf.SWFTransformationOptions;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
|
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine;
|
||||||
import org.alfresco.repo.rendition.executer.ImageRenderingEngine;
|
import org.alfresco.repo.rendition.executer.ImageRenderingEngine;
|
||||||
import org.alfresco.repo.rendition.executer.ReformatRenderingEngine;
|
import org.alfresco.repo.rendition.executer.ReformatRenderingEngine;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
@@ -202,20 +203,19 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
|
|
||||||
// We're prepending the cm namespace here.
|
// We're prepending the cm namespace here.
|
||||||
QName thumbnailQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, localThumbnailName);
|
QName thumbnailQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, localThumbnailName);
|
||||||
|
|
||||||
RenditionDefinition renderingAction = renditionService.loadRenditionDefinition(thumbnailQName);
|
// Convert the TransformationOptions and ThumbnailParentAssocDetails to
|
||||||
if (renderingAction == null)
|
// rendition-style parameters
|
||||||
{
|
|
||||||
// If the provided thumbnailName does not map to a built-in rendition definition
|
|
||||||
// then we must create a dynamic rendition definition for this thumbnail.
|
|
||||||
// To do this we must have a renderingEngineName.
|
|
||||||
//
|
|
||||||
// The transformation will either be a imageRenderingEngine or a reformat (pdf2swf)
|
|
||||||
String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
|
|
||||||
|
|
||||||
renderingAction = renditionService.createRenditionDefinition(thumbnailQName, renderingEngineName);
|
|
||||||
}
|
|
||||||
Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, assocDetails);
|
Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, assocDetails);
|
||||||
|
// Add the other parameters given in this method signature.
|
||||||
|
params.put(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, contentProperty);
|
||||||
|
params.put(AbstractRenderingEngine.PARAM_MIME_TYPE, mimetype);
|
||||||
|
|
||||||
|
// Create the renditionDefinition
|
||||||
|
String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
|
||||||
|
RenditionDefinition renderingAction = renditionService.createRenditionDefinition(thumbnailQName, renderingEngineName);
|
||||||
|
|
||||||
|
// Set the parameters
|
||||||
for (String key : params.keySet())
|
for (String key : params.keySet())
|
||||||
{
|
{
|
||||||
renderingAction.setParameterValue(key, params.get(key));
|
renderingAction.setParameterValue(key, params.get(key));
|
||||||
|
Reference in New Issue
Block a user