Merge from V3.3 to HEAD

20069 Fix for unreported issue where the Rendition Service's JavaScript API cannot be used to execute ad hoc rendition definitions.

Rendition Definitions can be created and executed programmatically. This works fine via the Java Foundation API, but is broken in the JavaScript API.
The rendition nodes are not correctly created for ad hoc rendition definitions created in JavaScript.
Note that the built-in rendition definitions work fine in JavaScript.

This fix:
    - ScriptRenditionDefinition now extends ScriptAction in order to reuse its parameter handling and execution code.
    - ScriptRenditionDefinition now mimics ScriptAction so you can call
            renditionDef.execute(testSourceNode); in JavaScript.
    - more test coverage in the test_renditionService.js to reproduce the issue.
    - adds debug logging in various places in the rendition service.
    - changes ScriptAction to be a non-final class so that it can be extended by ScriptRenditionDefinition.
    - fixes some fragile asserts in test code.
    - changes a few fields to protected visibility and provides an extension point so that the rendition service can execute its "actions" as renditions rather than simple actions.
    - trivial. tidied up some unused imports in ScriptNode.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20070 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2010-05-04 15:31:23 +00:00
parent f827a88a31
commit 30084dde24
8 changed files with 137 additions and 50 deletions

View File

@@ -31,8 +31,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
/**
* Script object representing the rendition service.
@@ -78,7 +76,16 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
*/
public ScriptRenditionDefinition createRenditionDefinition(String renditionName, String renderingEngineName)
{
QName renditionQName = createQName(renditionName);
QName renditionQName = createQName(renditionName);
if (logger.isDebugEnabled())
{
StringBuilder msg = new StringBuilder();
msg.append("Creating ScriptRenditionDefinition [")
.append(renditionName).append(", ")
.append(renderingEngineName).append("]");
logger.debug(msg.toString());
}
RenderingEngineDefinition engineDefinition = renditionService.getRenderingEngineDefinition(renderingEngineName);
RenditionDefinition rendDef = renditionService.createRenditionDefinition(renditionQName, renderingEngineName);
@@ -123,9 +130,28 @@ public class ScriptRenditionService extends BaseScopableProcessorExtension
public ScriptNode render(ScriptNode sourceNode, ScriptRenditionDefinition renditionDefQName)
{
if (logger.isDebugEnabled())
{
StringBuilder msg = new StringBuilder();
msg.append("Rendering source node '")
.append(sourceNode)
.append("' with renditionDefQName '").append(renditionDefQName)
.append("'");
logger.debug(msg.toString());
}
ChildAssociationRef chAssRef = this.renditionService.render(sourceNode.getNodeRef(),
renditionDefQName.getRenditionDefinition());
return new ScriptNode(chAssRef.getChildRef(), serviceRegistry);
NodeRef renditionNode = chAssRef.getChildRef();
if (logger.isDebugEnabled())
{
StringBuilder msg = new StringBuilder();
msg.append("Rendition: ").append(renditionNode);
logger.debug(msg.toString());
}
return new ScriptNode(renditionNode, serviceRegistry);
}