mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RenditionService JS API.
Support for creating a RenditionDefinition from within JavaScript Support for executing such an ad hoc rendition definition. ScriptRendtionService now accepts long-form or short-form QNames where applicable. Replaced "rendering actions" with "rendition definitions" in some javadoc and some private or local variable names. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19269 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,9 +19,6 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.rendition;
|
package org.alfresco.repo.rendition;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.alfresco.repo.action.ActionImpl;
|
import org.alfresco.repo.action.ActionImpl;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.rendition.RenderCallback;
|
import org.alfresco.service.cmr.rendition.RenderCallback;
|
||||||
@@ -40,6 +37,7 @@ public class RenditionDefinitionImpl extends ActionImpl implements RenditionDefi
|
|||||||
* Serial version UID
|
* Serial version UID
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 4336392868488634875L;
|
private static final long serialVersionUID = 4336392868488634875L;
|
||||||
|
//TODO rename to renditionDefinitionName
|
||||||
protected static final String RENDITION_DEFINITION_NAME = "renderingActionName";
|
protected static final String RENDITION_DEFINITION_NAME = "renderingActionName";
|
||||||
|
|
||||||
public NodeRef renditionParent;
|
public NodeRef renditionParent;
|
||||||
|
@@ -118,9 +118,9 @@ public class RenditionDefinitionPersisterImpl implements RenditionDefinitionPers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RenditionDefinition loadRenditionDefinition(QName renderingActionName)
|
public RenditionDefinition loadRenditionDefinition(QName renditionDefinitionName)
|
||||||
{
|
{
|
||||||
NodeRef actionNode = findActionNode(renderingActionName);
|
NodeRef actionNode = findActionNode(renditionDefinitionName);
|
||||||
if (actionNode != null)
|
if (actionNode != null)
|
||||||
{
|
{
|
||||||
Action action = runtimeActionService.createAction(actionNode);
|
Action action = runtimeActionService.createAction(actionNode);
|
||||||
@@ -149,13 +149,13 @@ public class RenditionDefinitionPersisterImpl implements RenditionDefinitionPers
|
|||||||
runtimeActionService.saveActionImpl(actionNodeRef, renderingAction);
|
runtimeActionService.saveActionImpl(actionNodeRef, renderingAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NodeRef findActionNode(QName renderingActionName)
|
private NodeRef findActionNode(QName renditionDefinitionName)
|
||||||
{
|
{
|
||||||
checkRenderingActionRootNodeExists();
|
checkRenderingActionRootNodeExists();
|
||||||
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(//
|
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(//
|
||||||
RENDERING_ACTION_ROOT_NODE_REF,//
|
RENDERING_ACTION_ROOT_NODE_REF,//
|
||||||
ContentModel.ASSOC_CONTAINS,//
|
ContentModel.ASSOC_CONTAINS,//
|
||||||
renderingActionName);
|
renditionDefinitionName);
|
||||||
if (childAssocs.isEmpty())
|
if (childAssocs.isEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -163,9 +163,9 @@ public class RenditionDefinitionPersisterImpl implements RenditionDefinitionPers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (childAssocs.size() > 1)
|
if (childAssocs.size() > 1)
|
||||||
{//
|
{
|
||||||
throw new RenditionServiceException("Multiple rendering actions with the name: " + renderingActionName
|
throw new RenditionServiceException("Multiple rendition definitions with the name: "
|
||||||
+ " exist!");
|
+ renditionDefinitionName + " exist!");
|
||||||
}
|
}
|
||||||
return childAssocs.get(0).getChildRef();
|
return childAssocs.get(0).getChildRef();
|
||||||
}
|
}
|
||||||
|
@@ -141,18 +141,18 @@ public class RenditionServiceImpl implements RenditionService, RenditionDefiniti
|
|||||||
* org.alfresco.service.cmr.rendition.RenditionService#createRenditionDefinition
|
* org.alfresco.service.cmr.rendition.RenditionService#createRenditionDefinition
|
||||||
* (org.alfresco.service.namespace.QName, java.lang.String)
|
* (org.alfresco.service.namespace.QName, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public RenditionDefinition createRenditionDefinition(QName renderingActionName, String actionDefinitionName)
|
public RenditionDefinition createRenditionDefinition(QName renditionDefinitionName, String renderingEngineName)
|
||||||
{
|
{
|
||||||
if (log.isDebugEnabled())
|
if (log.isDebugEnabled())
|
||||||
{
|
{
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Creating rendition definition ")
|
msg.append("Creating rendition definition ")
|
||||||
.append(renderingActionName)
|
.append(renditionDefinitionName)
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(actionDefinitionName);
|
.append(renderingEngineName);
|
||||||
log.debug(msg.toString());
|
log.debug(msg.toString());
|
||||||
}
|
}
|
||||||
return new RenditionDefinitionImpl(GUID.generate(), renderingActionName, actionDefinitionName);
|
return new RenditionDefinitionImpl(GUID.generate(), renditionDefinitionName, renderingEngineName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -238,9 +238,9 @@ public class RenditionServiceImpl implements RenditionService, RenditionDefiniti
|
|||||||
* org.alfresco.service.cmr.rendition.RenditionService#loadRenderingAction
|
* org.alfresco.service.cmr.rendition.RenditionService#loadRenderingAction
|
||||||
* (org.alfresco.service.namespace.QName)
|
* (org.alfresco.service.namespace.QName)
|
||||||
*/
|
*/
|
||||||
public RenditionDefinition loadRenditionDefinition(QName renderingActionName)
|
public RenditionDefinition loadRenditionDefinition(QName renditionDefinitionName)
|
||||||
{
|
{
|
||||||
return this.renditionDefinitionPersister.loadRenditionDefinition(renderingActionName);
|
return this.renditionDefinitionPersister.loadRenditionDefinition(renditionDefinitionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1672,8 +1672,9 @@ public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
assertEquals("'" + renditionLocalName + "' renditionDefinition had wrong renditionName", renditionQName,
|
assertEquals("'" + renditionLocalName + "' renditionDefinition had wrong renditionName", renditionQName,
|
||||||
renditionDefinition.getRenditionName());
|
renditionDefinition.getRenditionName());
|
||||||
|
|
||||||
assertNotNull("'" + renditionLocalName + "' renditionDefinition had null renderingActionName parameter",
|
assertNotNull("'" + renditionLocalName + "' renditionDefinition had null " +
|
||||||
renditionDefinition.getParameterValue("renderingActionName"));
|
RenditionDefinitionImpl.RENDITION_DEFINITION_NAME + " parameter",
|
||||||
|
renditionDefinition.getParameterValue(RenditionDefinitionImpl.RENDITION_DEFINITION_NAME));
|
||||||
|
|
||||||
// All builtin renditions should be "runas" system
|
// All builtin renditions should be "runas" system
|
||||||
assertEquals(AuthenticationUtil.getSystemUserName(), renditionDefinition.getParameterValue(AbstractRenderingEngine.PARAM_RUN_AS));
|
assertEquals(AuthenticationUtil.getSystemUserName(), renditionDefinition.getParameterValue(AbstractRenderingEngine.PARAM_RUN_AS));
|
||||||
|
@@ -42,10 +42,6 @@ import org.alfresco.service.cmr.repository.TransformationOptions;
|
|||||||
*/
|
*/
|
||||||
public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
|
public class ImageRenderingEngine extends AbstractTransformationRenderingEngine
|
||||||
{
|
{
|
||||||
// TODO This rendering engine should only take input of MIME type image/*
|
|
||||||
// However, we'll defer the addition of an EngineInputFilter until after
|
|
||||||
// Sprint 3.
|
|
||||||
|
|
||||||
public static final String NAME = "imageRenderingEngine";
|
public static final String NAME = "imageRenderingEngine";
|
||||||
|
|
||||||
// Resize params
|
// Resize params
|
||||||
|
@@ -19,27 +19,39 @@
|
|||||||
package org.alfresco.repo.rendition.script;
|
package org.alfresco.repo.rendition.script;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.repo.jscript.ScriptAction;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.rendition.RenderingEngineDefinition;
|
||||||
import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.mozilla.javascript.Scriptable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RenditionDefinition JavaScript Object. This class is a JavaScript-friendly wrapper for
|
* RenditionDefinition JavaScript Object. This class is a JavaScript-friendly wrapper for
|
||||||
* the {@link RenditionDefinition renditionDefinition} class.
|
* the {@link RenditionDefinition renditionDefinition} class.
|
||||||
*
|
*
|
||||||
* @author Neil McErlean
|
* @author Neil McErlean
|
||||||
|
* @see org.alfresco.service.cmr.rendition.RenditionDefinition
|
||||||
*/
|
*/
|
||||||
public final class ScriptRenditionDefinition implements Serializable
|
public final class ScriptRenditionDefinition implements Serializable
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 8132935577891455490L;
|
private static final long serialVersionUID = 8132935577891455490L;
|
||||||
|
private final RenderingEngineDefinition engineDefinition;
|
||||||
private final RenditionDefinition renditionDefinition;
|
private final RenditionDefinition renditionDefinition;
|
||||||
private final NamespaceService namespaceService;
|
private final ServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
|
private final ScriptAction scriptAction;
|
||||||
|
|
||||||
public ScriptRenditionDefinition(NamespaceService namespaceService, RenditionDefinition renditionDefinition)
|
public ScriptRenditionDefinition(ServiceRegistry serviceRegistry, Scriptable scope,
|
||||||
|
RenderingEngineDefinition engineDefinition, RenditionDefinition renditionDefinition)
|
||||||
{
|
{
|
||||||
this.namespaceService = namespaceService;
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
this.engineDefinition = engineDefinition;
|
||||||
this.renditionDefinition = renditionDefinition;
|
this.renditionDefinition = renditionDefinition;
|
||||||
|
|
||||||
|
this.scriptAction = new ScriptAction(serviceRegistry, renditionDefinition, engineDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +62,17 @@ public final class ScriptRenditionDefinition implements Serializable
|
|||||||
public String getRenditionName()
|
public String getRenditionName()
|
||||||
{
|
{
|
||||||
QName qname = this.renditionDefinition.getRenditionName();
|
QName qname = this.renditionDefinition.getRenditionName();
|
||||||
return qname.toPrefixString(namespaceService);
|
return qname.toPrefixString(serviceRegistry.getNamespaceService());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRenderingEngineName()
|
||||||
|
{
|
||||||
|
return this.engineDefinition.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Serializable> getParameters()
|
||||||
|
{
|
||||||
|
return this.scriptAction.getParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,4 +84,9 @@ public final class ScriptRenditionDefinition implements Serializable
|
|||||||
|
|
||||||
return msg.toString();
|
return msg.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RenditionDefinition getRenditionDefinition()
|
||||||
|
{
|
||||||
|
return this.renditionDefinition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,12 +23,16 @@ import java.util.List;
|
|||||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||||
import org.alfresco.repo.jscript.ScriptNode;
|
import org.alfresco.repo.jscript.ScriptNode;
|
||||||
import org.alfresco.service.ServiceRegistry;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.rendition.RenderingEngineDefinition;
|
||||||
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.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.mozilla.javascript.Context;
|
||||||
|
import org.mozilla.javascript.Scriptable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Script object representing the rendition service.
|
* Script object representing the rendition service.
|
||||||
@@ -41,6 +45,7 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
|
|||||||
|
|
||||||
/** The Services registry */
|
/** The Services registry */
|
||||||
private ServiceRegistry serviceRegistry;
|
private ServiceRegistry serviceRegistry;
|
||||||
|
private RenditionService renditionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the service registry
|
* Set the service registry
|
||||||
@@ -50,37 +55,60 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
|
|||||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||||
{
|
{
|
||||||
this.serviceRegistry = serviceRegistry;
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
this.renditionService = serviceRegistry.getRenditionService();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RenditionDefinition loadRenditionDefinitionImpl(String shortFormQName)
|
private RenditionDefinition loadRenditionDefinitionImpl(String shortOrLongFormQName)
|
||||||
{
|
{
|
||||||
QName renditionName = QName.createQName(shortFormQName, serviceRegistry.getNamespaceService());
|
QName renditionName = createQName(shortOrLongFormQName);
|
||||||
RenditionDefinition rendDef = serviceRegistry.getRenditionService().loadRenditionDefinition(renditionName);
|
RenditionDefinition rendDef = renditionService.loadRenditionDefinition(renditionName);
|
||||||
return rendDef;
|
return rendDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link ScriptRenditionDefinition} and sets the rendition name and
|
||||||
|
* the rendering engine name to the specified values.
|
||||||
|
*
|
||||||
|
* @param renditionName A unique identifier used to specify the created
|
||||||
|
* {@link ScriptRenditionDefinition}.
|
||||||
|
* @param renderingEngineName The name of the rendering engine associated
|
||||||
|
* with this {@link ScriptRenditionDefinition}.
|
||||||
|
* @return the created {@link ScriptRenditionDefinition}.
|
||||||
|
* @see org.alfresco.service.cmr.rendition.RenditionService#createRenditionDefinition(QName, String)
|
||||||
|
*/
|
||||||
|
public ScriptRenditionDefinition createRenditionDefinition(String renditionName, String renderingEngineName)
|
||||||
|
{
|
||||||
|
QName renditionQName = createQName(renditionName);
|
||||||
|
|
||||||
|
RenderingEngineDefinition engineDefinition = renditionService.getRenderingEngineDefinition(renderingEngineName);
|
||||||
|
RenditionDefinition rendDef = renditionService.createRenditionDefinition(renditionQName, renderingEngineName);
|
||||||
|
|
||||||
|
return new ScriptRenditionDefinition(serviceRegistry, this.getScope(), engineDefinition, rendDef);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method renders the specified source node using the specified saved
|
* This method renders the specified source node using the specified saved
|
||||||
* rendition definition.
|
* rendition definition.
|
||||||
* @param sourceNode the source node to be rendered.
|
* @param sourceNode the source node to be rendered.
|
||||||
* @param renditionDefshortQName the rendition definition to be used e.g. cm:doclib
|
* @param renditionDefQName the rendition definition to be used e.g. "cm:doclib" or
|
||||||
|
* "{http://www.alfresco.org/model/content/1.0}imgpreview"
|
||||||
* @return the rendition scriptnode.
|
* @return the rendition scriptnode.
|
||||||
* @see org.alfresco.service.cmr.rendition.RenditionService#render(org.alfresco.service.cmr.repository.NodeRef, RenditionDefinition)
|
* @see org.alfresco.service.cmr.rendition.RenditionService#render(org.alfresco.service.cmr.repository.NodeRef, RenditionDefinition)
|
||||||
*/
|
*/
|
||||||
public ScriptNode render(ScriptNode sourceNode, String renditionDefshortQName)
|
public ScriptNode render(ScriptNode sourceNode, String renditionDefQName)
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Rendering source node '")
|
msg.append("Rendering source node '")
|
||||||
.append(sourceNode)
|
.append(sourceNode)
|
||||||
.append("' with renditionDef '").append(renditionDefshortQName)
|
.append("' with renditionDef '").append(renditionDefQName)
|
||||||
.append("'");
|
.append("'");
|
||||||
logger.debug(msg.toString());
|
logger.debug(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
RenditionDefinition rendDef = loadRenditionDefinitionImpl(renditionDefshortQName);
|
RenditionDefinition rendDef = loadRenditionDefinitionImpl(renditionDefQName);
|
||||||
ChildAssociationRef result = this.serviceRegistry.getRenditionService().render(sourceNode.getNodeRef(), rendDef);
|
ChildAssociationRef result = this.renditionService.render(sourceNode.getNodeRef(), rendDef);
|
||||||
NodeRef renditionNode = result.getChildRef();
|
NodeRef renditionNode = result.getChildRef();
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
@@ -92,6 +120,14 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
|
|||||||
|
|
||||||
return new ScriptNode(renditionNode, serviceRegistry);
|
return new ScriptNode(renditionNode, serviceRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScriptNode render(ScriptNode sourceNode, ScriptRenditionDefinition renditionDefQName)
|
||||||
|
{
|
||||||
|
ChildAssociationRef chAssRef = this.renditionService.render(sourceNode.getNodeRef(),
|
||||||
|
renditionDefQName.getRenditionDefinition());
|
||||||
|
return new ScriptNode(chAssRef.getChildRef(), serviceRegistry);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets all the renditions of the specified node.
|
* This method gets all the renditions of the specified node.
|
||||||
@@ -102,15 +138,15 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
|
|||||||
*/
|
*/
|
||||||
public ScriptNode[] getRenditions(ScriptNode node)
|
public ScriptNode[] getRenditions(ScriptNode node)
|
||||||
{
|
{
|
||||||
List<ChildAssociationRef> renditions = this.serviceRegistry.getRenditionService().getRenditions(node.getNodeRef());
|
List<ChildAssociationRef> renditions = this.renditionService.getRenditions(node.getNodeRef());
|
||||||
|
|
||||||
ScriptNode[] results = new ScriptNode[renditions.size()];
|
ScriptNode[] renditionObjs = new ScriptNode[renditions.size()];
|
||||||
for (int i = 0; i < renditions.size(); i++)
|
for (int i = 0; i < renditions.size(); i++)
|
||||||
{
|
{
|
||||||
results[i] = new ScriptNode(renditions.get(i).getChildRef(), serviceRegistry);
|
renditionObjs[i] = new ScriptNode(renditions.get(i).getChildRef(), serviceRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return renditionObjs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +162,7 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
|
|||||||
*/
|
*/
|
||||||
public ScriptNode[] getRenditions(ScriptNode node, String mimeTypePrefix)
|
public ScriptNode[] getRenditions(ScriptNode node, String mimeTypePrefix)
|
||||||
{
|
{
|
||||||
List<ChildAssociationRef> renditions = this.serviceRegistry.getRenditionService().getRenditions(node.getNodeRef(), mimeTypePrefix);
|
List<ChildAssociationRef> renditions = this.renditionService.getRenditions(node.getNodeRef(), mimeTypePrefix);
|
||||||
|
|
||||||
ScriptNode[] results = new ScriptNode[renditions.size()];
|
ScriptNode[] results = new ScriptNode[renditions.size()];
|
||||||
for (int i = 0; i < renditions.size(); i++)
|
for (int i = 0; i < renditions.size(); i++)
|
||||||
@@ -142,15 +178,39 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
|
|||||||
* the provided rendition name.
|
* the provided rendition name.
|
||||||
*
|
*
|
||||||
* @param node the source node for the renditions
|
* @param node the source node for the renditions
|
||||||
* @param renditionName the renditionName used to identify a rendition. e.g. cm:doclib
|
* @param renditionName the renditionName used to identify a rendition. e.g. cm:doclib or
|
||||||
|
* "{http://www.alfresco.org/model/content/1.0}imgpreview"
|
||||||
* @return the parent association for the rendition or <code>null</code> if there is no such rendition.
|
* @return the parent association for the rendition or <code>null</code> if there is no such rendition.
|
||||||
* @see org.alfresco.service.cmr.rendition.RenditionService#getRenditionByName(org.alfresco.service.cmr.repository.NodeRef, QName)
|
* @see org.alfresco.service.cmr.rendition.RenditionService#getRenditionByName(org.alfresco.service.cmr.repository.NodeRef, QName)
|
||||||
*/
|
*/
|
||||||
public ScriptNode getRenditionByName(ScriptNode node, String renditionName)
|
public ScriptNode getRenditionByName(ScriptNode node, String renditionName)
|
||||||
{
|
{
|
||||||
QName qname = QName.createQName(renditionName, serviceRegistry.getNamespaceService());
|
QName qname = createQName(renditionName);
|
||||||
ChildAssociationRef result = this.serviceRegistry.getRenditionService().getRenditionByName(node.getNodeRef(), qname);
|
ChildAssociationRef result = this.renditionService.getRenditionByName(node.getNodeRef(), qname);
|
||||||
|
|
||||||
return result == null ? null : new ScriptNode(result.getChildRef(), serviceRegistry);
|
return result == null ? null : new ScriptNode(result.getChildRef(), serviceRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method takes a string representing a QName and converts it to a QName
|
||||||
|
* object.
|
||||||
|
* @param qnameString the string can be either a short or long form qname.
|
||||||
|
* @return a QName object
|
||||||
|
*/
|
||||||
|
private QName createQName(String qnameString)
|
||||||
|
{
|
||||||
|
QName result;
|
||||||
|
if (qnameString.startsWith(Character.toString(QName.NAMESPACE_BEGIN)))
|
||||||
|
{
|
||||||
|
// It's a long-form qname string
|
||||||
|
result = QName.createQName(qnameString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// It's a short-form qname string
|
||||||
|
result = QName.createQName(qnameString, serviceRegistry.getNamespaceService());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
function testRenderNodeUsingRenditionDefinitionNames()
|
function testRenderNodeUsingRenditionDefinitionNames()
|
||||||
{
|
{
|
||||||
// Produce two different renditions of the same source node
|
// Produce two different renditions of the same source node
|
||||||
|
// One with a long-form qname and one with a short-form qname
|
||||||
var renditionDefName1 = "cm:doclib";
|
var renditionDefName1 = "cm:doclib";
|
||||||
var renditionDefName2 = "cm:imgpreview";
|
var renditionDefName2 = "{http://www.alfresco.org/model/content/1.0}imgpreview";
|
||||||
var rendition1 = renditionService.render(testSourceNode, renditionDefName1);
|
var rendition1 = renditionService.render(testSourceNode, renditionDefName1);
|
||||||
var rendition2 = renditionService.render(testSourceNode, renditionDefName2);
|
var rendition2 = renditionService.render(testSourceNode, renditionDefName2);
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ function testGetRenditions()
|
|||||||
var doclibRendition = renditionService.getRenditionByName(testSourceNode, "cm:doclib");
|
var doclibRendition = renditionService.getRenditionByName(testSourceNode, "cm:doclib");
|
||||||
test.assertNotNull(doclibRendition, "doclibRendition returned null.");
|
test.assertNotNull(doclibRendition, "doclibRendition returned null.");
|
||||||
|
|
||||||
var noSuchRendition = renditionService.getRenditionByName(testSourceNode, "cm:nonsense");
|
var noSuchRendition = renditionService.getRenditionByName(testSourceNode, "{http://www.alfresco.org/model/content/1.0}nonsense");
|
||||||
test.assertNull(noSuchRendition, "noSuchRendition should have been null.");
|
test.assertNull(noSuchRendition, "noSuchRendition should have been null.");
|
||||||
|
|
||||||
|
|
||||||
@@ -39,6 +40,38 @@ function testGetRenditions()
|
|||||||
test.assertEquals(0, swfRenditions.length);
|
test.assertEquals(0, swfRenditions.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testCreateRenditionDefinitionAndRender()
|
||||||
|
{
|
||||||
|
// Create a simple (non-composite) rendition definition.
|
||||||
|
|
||||||
|
// As long as we don't save this renditionDefinition, there should be no need to
|
||||||
|
// give it a name which is unique across multiple test executions.
|
||||||
|
var renditionDefName = "cm:adHocRenditionDef";
|
||||||
|
var renderingEngineName = "imageRenderingEngine";
|
||||||
|
|
||||||
|
var renditionDef = renditionService.createRenditionDefinition(renditionDefName, renderingEngineName);
|
||||||
|
|
||||||
|
test.assertNotNull(renditionDef, "ad hoc rendition definition was null.");
|
||||||
|
test.assertEquals(renditionDefName, renditionDef.renditionName);
|
||||||
|
test.assertEquals(renderingEngineName, renditionDef.renderingEngineName);
|
||||||
|
|
||||||
|
|
||||||
|
// Set some parameters.
|
||||||
|
renditionDef.parameters['rendition-nodetype'] = "cm:content";
|
||||||
|
renditionDef.parameters['xsize'] = 99;
|
||||||
|
|
||||||
|
// Read them back to check
|
||||||
|
test.assertEquals("cm:content", renditionDef.parameters['rendition-nodetype']);
|
||||||
|
test.assertEquals(99, renditionDef.parameters['xsize']);
|
||||||
|
|
||||||
|
// Now execute this rendition definition
|
||||||
|
var rendition = renditionService.render(testSourceNode, renditionDef);
|
||||||
|
|
||||||
|
test.assertNotNull(rendition, "rendition was null.");
|
||||||
|
test.assertTrue(rendition.hasAspect("rn:hiddenRendition"));
|
||||||
|
}
|
||||||
|
|
||||||
// Execute tests
|
// Execute tests
|
||||||
testRenderNodeUsingRenditionDefinitionNames();
|
testRenderNodeUsingRenditionDefinitionNames();
|
||||||
testGetRenditions();
|
testGetRenditions();
|
||||||
|
testCreateRenditionDefinitionAndRender();
|
||||||
|
@@ -87,7 +87,7 @@ public class ThumbnailServiceImplParameterTest
|
|||||||
renditionService = new RenditionServiceImpl()
|
renditionService = new RenditionServiceImpl()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public RenditionDefinition loadRenditionDefinition(QName renderingActionName)
|
public RenditionDefinition loadRenditionDefinition(QName renditionDefinitionName)
|
||||||
{
|
{
|
||||||
// We're intentionally returning null for this test.
|
// We're intentionally returning null for this test.
|
||||||
return null;
|
return null;
|
||||||
|
@@ -29,5 +29,5 @@ import org.alfresco.service.cmr.action.ActionDefinition;
|
|||||||
*/
|
*/
|
||||||
public interface RenderingEngineDefinition extends ActionDefinition
|
public interface RenderingEngineDefinition extends ActionDefinition
|
||||||
{
|
{
|
||||||
|
// Intentionally empty
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,7 @@ import org.alfresco.service.namespace.QName;
|
|||||||
public interface RenditionDefinition extends Action, Serializable
|
public interface RenditionDefinition extends Action, Serializable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return the name which uniquely identifies this rendering action.
|
* @return the name which uniquely identifies this rendition definition.
|
||||||
*/
|
*/
|
||||||
QName getRenditionName();
|
QName getRenditionName();
|
||||||
|
|
||||||
|
@@ -159,7 +159,6 @@ public interface RenditionService extends RenditionDefinitionPersister
|
|||||||
*/
|
*/
|
||||||
ChildAssociationRef getSourceNode(NodeRef renditionNode);
|
ChildAssociationRef getSourceNode(NodeRef renditionNode);
|
||||||
|
|
||||||
//TODO The result should be the link to the primary parent.
|
|
||||||
/**
|
/**
|
||||||
* This method synchronously renders content as specified by the given
|
* This method synchronously renders content as specified by the given
|
||||||
* {@link RenditionDefinition}. The content to be rendered is provided by
|
* {@link RenditionDefinition}. The content to be rendered is provided by
|
||||||
|
Reference in New Issue
Block a user