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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations