mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125781 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
125 lines
5.0 KiB
Java
125 lines
5.0 KiB
Java
|
|
package org.alfresco.repo.rendition.executer;
|
|
|
|
import org.alfresco.service.cmr.action.Action;
|
|
import org.alfresco.service.cmr.action.ActionService;
|
|
import org.alfresco.service.cmr.rendition.CompositeRenditionDefinition;
|
|
import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
|
import org.alfresco.service.cmr.rendition.RenditionService;
|
|
import org.alfresco.service.cmr.rendition.RenditionServiceException;
|
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
|
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;
|
|
|
|
/**
|
|
* This RenderingEngine is used for rendering
|
|
* {@link CompositeRenditionDefinition}s, which specify a list of
|
|
* {@link RenditionDefinition}s. The {@link CompositeRenderingEngine} iterates
|
|
* over the {@link RenditionDefinition}s sequentially and feeds the output of
|
|
* one definition in as the input of the next definition. The output of the last
|
|
* definition executed is the output of this rendering engine.
|
|
*
|
|
* @author Nick Smith
|
|
*/
|
|
public class CompositeRenderingEngine extends AbstractRenderingEngine
|
|
{
|
|
/** Logger */
|
|
private static Log logger = LogFactory.getLog(CompositeRenderingEngine.class);
|
|
|
|
public static final String NAME = "compositeRenderingEngine";
|
|
|
|
private ActionService actionService;
|
|
|
|
/*
|
|
* (non-Javadoc)
|
|
* @see org.alfresco.repo.rendition.executer.AbstractRenderingEngine#executeRenditionImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
|
|
*/
|
|
@Override
|
|
protected void executeRenditionImpl(Action action, NodeRef sourceNode)
|
|
{
|
|
checkSourceNodeExists(sourceNode);
|
|
if (action instanceof CompositeRenditionDefinition)
|
|
{
|
|
CompositeRenditionDefinition compositeDefinition = (CompositeRenditionDefinition) action;
|
|
ChildAssociationRef renditionAssoc = executeCompositeRendition(compositeDefinition, sourceNode);
|
|
|
|
// Setting result.
|
|
compositeDefinition.setParameterValue(PARAM_RESULT, renditionAssoc);
|
|
}
|
|
else
|
|
{
|
|
String msg = "This method requires that the RenditionDefinition be of type CompositeRenditionDefinition";
|
|
logger.warn(msg);
|
|
throw new RenditionServiceException(msg);
|
|
}
|
|
}
|
|
|
|
private ChildAssociationRef executeCompositeRendition(CompositeRenditionDefinition definition, NodeRef sourceNode)
|
|
{
|
|
NodeRef source = sourceNode;
|
|
ChildAssociationRef result = null;
|
|
QName assocType = definition.getRenditionAssociationType();
|
|
NodeRef parent = definition.getRenditionParent();
|
|
for (RenditionDefinition subDefinition : definition.getActions())
|
|
{
|
|
ChildAssociationRef nextResult = executeSubDefinition(source, subDefinition, parent, assocType);
|
|
if (result != null)
|
|
{
|
|
// Clean up temporary renditions.
|
|
nodeService.removeChild(parent, result.getChildRef());
|
|
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug("removeChild parentRef:" + parent + ", childRef;" + result.getChildRef());
|
|
}
|
|
}
|
|
result = nextResult;
|
|
source = nextResult.getChildRef();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Executes the specified subdefinition. Note that each of these component rendition definitions
|
|
* will be executed with the {@link RenditionService#PARAM_IS_COMPONENT_RENDITION is-component-rendition}
|
|
* flag set to true. This is so that the common pre- and post-rendition code in
|
|
* {@link AbstractRenderingEngine#executeImpl(Action, NodeRef)} will only be executed at the start
|
|
* and at the end of the chain of components.
|
|
*/
|
|
private ChildAssociationRef executeSubDefinition(NodeRef source,//
|
|
RenditionDefinition subDefinition,//
|
|
NodeRef parent,//
|
|
QName assocType)
|
|
{
|
|
subDefinition.setRenditionParent(parent);
|
|
subDefinition.setRenditionAssociationType(assocType);
|
|
|
|
subDefinition.setParameterValue(RenditionService.PARAM_IS_COMPONENT_RENDITION, true);
|
|
actionService.executeAction(subDefinition, source);
|
|
ChildAssociationRef newResult = (ChildAssociationRef) subDefinition.getParameterValue(PARAM_RESULT);
|
|
return newResult;
|
|
}
|
|
|
|
/*
|
|
* @see
|
|
* org.alfresco.repo.rendition.executer.AbstractRenderingEngine#render(org
|
|
* .alfresco
|
|
* .repo.rendition.executer.AbstractRenderingEngine.RenderingContext)
|
|
*/
|
|
@Override
|
|
protected void render(RenderingContext data)
|
|
{
|
|
throw new RenditionServiceException("This method should never be caleld!");
|
|
}
|
|
|
|
/**
|
|
* @param actionService the actionService to set
|
|
*/
|
|
public void setActionService(ActionService actionService)
|
|
{
|
|
this.actionService = actionService;
|
|
}
|
|
}
|