Search in sources :

Example 11 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class AbstractRenderingEngine method getParamWithDefault.

/**
 * Gets the value for the named parameter. Checks the type of the parameter
 * is the same as the type of <code>defaultValue</code> and throws a
 * {@link RenditionServiceException} if it isn't. Returns
 * <code>defaultValue</code> if the parameter value is <code>null</code>
 *
 * @param paramName String
 * @param defaultValue T
 * @param definition RenditionDefinition
 * @param <T> T
 * @return T
 */
@SuppressWarnings("unchecked")
public static <T> T getParamWithDefault(String paramName, T defaultValue, RenditionDefinition definition) {
    if (defaultValue == null)
        throw new RenditionServiceException("The defaultValue cannot be null!", new NullPointerException());
    Class<? extends T> clazz = (Class<? extends T>) defaultValue.getClass();
    T result = getCheckedParam(paramName, clazz, definition);
    if (result == null)
        result = defaultValue;
    return result;
}
Also used : RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Example 12 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException 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)

Example 13 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class BaseTemplateRenderingEngine method getTemplateNode.

protected NodeRef getTemplateNode(RenderingContext context) {
    NodeRef node = context.getCheckedParam(PARAM_TEMPLATE_NODE, NodeRef.class);
    if (node == null) {
        String path = context.getCheckedParam(PARAM_TEMPLATE_PATH, String.class);
        if (path != null && path.length() > 0) {
            StoreRef storeRef = context.getDestinationNode().getStoreRef();
            List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), path, null, namespaceService, false);
            if (refs.size() != 1) {
                throw new RenditionServiceException("Could not find template node for path: " + path);
            }
            node = refs.get(0);
        }
    }
    return node;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Example 14 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class HTMLRenderingEngine method buildContentHandler.

/**
 * Builds a Tika-compatible SAX content handler, which will
 *  be used to generate+capture the XHTML
 */
private ContentHandler buildContentHandler(Writer output, RenderingContext context) {
    // Create the main transformer
    SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler handler;
    try {
        handler = factory.newTransformerHandler();
    } catch (TransformerConfigurationException e) {
        throw new RenditionServiceException("SAX Processing isn't available - " + e);
    }
    handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
    handler.setResult(new StreamResult(output));
    handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
    // Change the image links as they go past
    String dirName = null, imgPrefix = null;
    if (context.getParamWithDefault(PARAM_IMAGES_SAME_FOLDER, false)) {
        imgPrefix = getImagesPrefixName(context);
    } else {
        dirName = getImagesDirectoryName(context);
    }
    ContentHandler contentHandler = new TikaImageRewritingContentHandler(handler, dirName, imgPrefix);
    // If required, wrap it to only return the body
    boolean bodyOnly = context.getParamWithDefault(PARAM_BODY_CONTENTS_ONLY, false);
    if (bodyOnly) {
        contentHandler = new BodyContentHandler(contentHandler);
    }
    // All done
    return contentHandler;
}
Also used : BodyContentHandler(org.apache.tika.sax.BodyContentHandler) TransformerHandler(javax.xml.transform.sax.TransformerHandler) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StreamResult(javax.xml.transform.stream.StreamResult) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) BodyContentHandler(org.apache.tika.sax.BodyContentHandler) ContentHandler(org.xml.sax.ContentHandler)

Example 15 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class CompositeRenderingEngine method executeRenditionImpl.

/*
     * (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);
    }
}
Also used : CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Aggregations

RenditionServiceException (org.alfresco.service.cmr.rendition.RenditionServiceException)20 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 RenditionDefinition (org.alfresco.service.cmr.rendition.RenditionDefinition)7 CompositeRenditionDefinition (org.alfresco.service.cmr.rendition.CompositeRenditionDefinition)5 QName (org.alfresco.service.namespace.QName)5 ContentReader (org.alfresco.service.cmr.repository.ContentReader)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)2 RenderingContext (org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext)2 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)2 RenditionPreventedException (org.alfresco.service.cmr.rendition.RenditionPreventedException)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 NodeService (org.alfresco.service.cmr.repository.NodeService)2 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)2 BodyContentHandler (org.apache.tika.sax.BodyContentHandler)2 Test (org.junit.Test)2