Search in sources :

Example 1 with RenditionLocation

use of org.alfresco.repo.rendition.RenditionLocation in project alfresco-repository by Alfresco.

the class HTMLRenderingEngine method createImagesDirectory.

/**
 * Creates a directory to store the images in.
 * The directory will be a sibling of the rendered
 *  HTML, and named similar to it.
 * Note this is only required if {@link #PARAM_IMAGES_SAME_FOLDER} is false (the default).
 */
private NodeRef createImagesDirectory(RenderingContext context) {
    // It should be a sibling of the HTML in it's eventual location
    // (not it's current temporary one!)
    RenditionLocation location = resolveRenditionLocation(context.getSourceNode(), context.getDefinition(), context.getDestinationNode());
    NodeRef parent = location.getParentRef();
    // Figure out what to call it, based on the HTML node
    String folderName = getImagesDirectoryName(context);
    // It is already there?
    // (eg from when the rendition is being re-run)
    NodeRef imgFolder = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, folderName);
    if (imgFolder != null)
        return imgFolder;
    // Create the directory
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    properties.put(ContentModel.PROP_NAME, folderName);
    imgFolder = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, QName.createQName(folderName), ContentModel.TYPE_FOLDER, properties).getChildRef();
    return imgFolder;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) RenditionLocation(org.alfresco.repo.rendition.RenditionLocation)

Example 2 with RenditionLocation

use of org.alfresco.repo.rendition.RenditionLocation in project alfresco-repository by Alfresco.

the class AbstractRenderingEngine method createOrUpdateRendition.

/**
 * @param sourceNode The node that has been rendered
 * @param tempRendition The relationship between the node and its rendition
 * @param renditionDefinition The definition of the rendition that has just been performed.
 *                            In the case of a composite rendition, this parameter refers
 *                            to that CompositeRendition and not to any of its component renditions.
 * @return ChildAssociationRef
 */
private ChildAssociationRef createOrUpdateRendition(NodeRef sourceNode, ChildAssociationRef tempRendition, RenditionDefinition renditionDefinition) {
    NodeRef tempRenditionNode = tempRendition.getChildRef();
    RenditionLocation renditionLocation = resolveRenditionLocation(sourceNode, renditionDefinition, tempRenditionNode);
    QName renditionQName = renditionDefinition.getRenditionName();
    RenditionNodeManager renditionNodeManager = new RenditionNodeManager(sourceNode, tempRenditionNode, renditionLocation, renditionDefinition, nodeService, renditionService, behaviourFilter);
    ChildAssociationRef renditionNode = renditionNodeManager.findOrCreateRenditionNode();
    // Set the name property on the rendition if it has not already been
    // set.
    String renditionName = getRenditionName(tempRenditionNode, renditionLocation, renditionDefinition);
    // to manager
    nodeService.setProperty(renditionNode.getChildRef(), ContentModel.PROP_NAME, renditionName);
    // Add temporary aspect for temporary rendition node
    // When this node id deleted, will not appear in user's trashcan
    nodeService.addAspect(tempRendition.getChildRef(), ContentModel.ASPECT_TEMPORARY, null);
    // Delete the temporary rendition.
    nodeService.removeChildAssociation(tempRendition);
    if (logger.isDebugEnabled()) {
        logger.debug("Removed temporary child-association " + tempRendition);
    }
    // Handle the rendition aspects
    manageRenditionAspects(sourceNode, renditionNode);
    // Verify that everything has gone to plan, and nothing got lost on the way!
    ChildAssociationRef renditionAssoc = renditionService.getRenditionByName(sourceNode, renditionQName);
    if (renditionAssoc == null) {
        String msg = "A rendition of name: " + renditionQName + " should have been created for source node: " + sourceNode;
        throw new RenditionServiceException(msg);
    }
    // Return the link between the source and the new, final rendition
    return renditionAssoc;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) RenditionNodeManager(org.alfresco.repo.rendition.RenditionNodeManager) RenditionLocation(org.alfresco.repo.rendition.RenditionLocation) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Aggregations

RenditionLocation (org.alfresco.repo.rendition.RenditionLocation)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 QName (org.alfresco.service.namespace.QName)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 RenditionNodeManager (org.alfresco.repo.rendition.RenditionNodeManager)1 RenditionServiceException (org.alfresco.service.cmr.rendition.RenditionServiceException)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1