use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class LegacyTransformerDebug method transformationsByTransformer.
/**
* Returns a String and /or debug that provides a list of supported transformations for each
* transformer.
* @param transformerName restricts the list to one transformer. Unrestricted if null.
* @param toString indicates that a String value should be returned in addition to any debug.
* @param format42 indicates the old 4.1.4 format should be used which did not order the transformers
* and only included top level transformers.
* @param renditionName to which the transformation will be put (such as "Index", "Preview", null).
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
public String transformationsByTransformer(String transformerName, boolean toString, boolean format42, String renditionName) {
// (for example a test transform).
if (getStringBuilder() != null) {
return null;
}
Collection<ContentTransformer> transformers = format42 || transformerName != null ? sortTransformersByName(transformerName) : transformerRegistry.getTransformers();
Collection<String> sourceMimetypes = format42 ? getSourceMimetypes(null) : mimetypeService.getMimetypes();
Collection<String> targetMimetypes = format42 ? sourceMimetypes : mimetypeService.getMimetypes();
TransformationOptions options = new TransformationOptions();
options.setUse(renditionName);
StringBuilder sb = null;
try {
if (toString) {
sb = new StringBuilder();
setStringBuilder(sb);
}
pushMisc();
for (ContentTransformer transformer : transformers) {
try {
pushMisc();
int mimetypePairCount = 0;
boolean first = true;
for (String sourceMimetype : sourceMimetypes) {
for (String targetMimetype : targetMimetypes) {
if (transformer.isTransformable(sourceMimetype, -1, targetMimetype, options)) {
long maxSourceSizeKBytes = transformer.getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
activeTransformer(++mimetypePairCount, transformer, sourceMimetype, targetMimetype, maxSourceSizeKBytes, first);
first = false;
}
}
}
if (first) {
inactiveTransformer(transformer);
}
} finally {
popMisc();
}
}
} finally {
popMisc();
setStringBuilder(null);
}
stripFinishedLine(sb);
return stripLeadingNumber(sb);
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class ThumbnailRenditionConvertor method convert.
/**
* Given the specified {@link ThumbnailDefinition thumbnailDefinition} and
* {@link ThumbnailParentAssociationDetails assocDetails},
* create and return an equivalent {@link RenditionDefinition} object.
*
* @param thumbnailDefinition ThumbnailDefinition
* @param assocDetails ThumbnailParentAssociationDetails
* @return RenditionDefinitions
*/
public RenditionDefinition convert(ThumbnailDefinition thumbnailDefinition, ThumbnailParentAssociationDetails assocDetails) {
// We must always have a valid name for a thumbnail definition
if (thumbnailDefinition == null || thumbnailDefinition.getName() == null || thumbnailDefinition.getName().trim().length() == 0) {
throw new IllegalArgumentException("Thumbnail Definition and Name must be non-null and non-empty.");
}
TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
Map<String, Serializable> parameters = this.convert(transformationOptions, assocDetails);
// Extract parameters defined directly within the ThumbnailDefinition object.
putParameterIfNotNull(AbstractRenderingEngine.PARAM_MIME_TYPE, thumbnailDefinition.getMimetype(), parameters);
putParameterIfNotNull(AbstractRenderingEngine.PARAM_PLACEHOLDER_RESOURCE_PATH, thumbnailDefinition.getPlaceHolderResourcePath(), parameters);
putParameterIfNotNull(AbstractRenderingEngine.PARAM_RUN_AS, thumbnailDefinition.getRunAs(), parameters);
QName namespacedRenditionName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, thumbnailDefinition.getName());
// The built-in RenditionDefinitions are all non-composites.
// They are either "imageRenderingEngine" or "reformat"
boolean isImageThumbnail = isImageBasedRendition(thumbnailDefinition);
String renderingEngineName = isImageThumbnail ? ImageRenderingEngine.NAME : ReformatRenderingEngine.NAME;
RenditionDefinition renditionDef = renditionService.createRenditionDefinition(namespacedRenditionName, renderingEngineName);
for (String paramName : parameters.keySet()) {
renditionDef.setParameterValue(paramName, parameters.get(paramName));
}
return renditionDef;
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class ThumbnailRenditionConvertor method convert.
public ThumbnailDefinition convert(RenditionDefinition renditionDefinition) {
ThumbnailDefinition thDefn = new ThumbnailDefinition();
Map<String, Serializable> params = renditionDefinition.getParameterValues();
// parameters common to all the built-in thumbnail definitions
Serializable mimeTypeParam = params.get(AbstractRenderingEngine.PARAM_MIME_TYPE);
thDefn.setMimetype((String) mimeTypeParam);
thDefn.setName(renditionDefinition.getRenditionName().getLocalName());
Serializable placeHolderResourcePathParam = params.get(AbstractRenderingEngine.PARAM_PLACEHOLDER_RESOURCE_PATH);
if (placeHolderResourcePathParam != null) {
thDefn.setPlaceHolderResourcePath((String) placeHolderResourcePathParam);
}
TransformationOptions transformationOptions = null;
Serializable flashVersion = renditionDefinition.getParameterValue(ReformatRenderingEngine.PARAM_FLASH_VERSION);
if (flashVersion != null) {
// Thumbnails based on SWFTransformationOptions
transformationOptions = new SWFTransformationOptions();
SWFTransformationOptions swfTranOpts = (SWFTransformationOptions) transformationOptions;
swfTranOpts.setFlashVersion((String) flashVersion);
} else {
// Thumbnails based on ImageTransformationOptions
transformationOptions = new ImageTransformationOptions();
ImageTransformationOptions imgTrOpts = (ImageTransformationOptions) transformationOptions;
ImageResizeOptions resizeOptions = new ImageResizeOptions();
Serializable xsize = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_WIDTH);
if (xsize != null) {
resizeOptions.setWidth(((Integer) xsize).intValue());
}
Serializable ysize = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_HEIGHT);
if (ysize != null) {
resizeOptions.setHeight(((Integer) ysize).intValue());
}
Serializable maintainAspectRatio = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO);
if (maintainAspectRatio != null) {
resizeOptions.setMaintainAspectRatio((Boolean) maintainAspectRatio);
}
Serializable resizeToThumbnail = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL);
if (resizeToThumbnail != null) {
resizeOptions.setResizeToThumbnail((Boolean) resizeToThumbnail);
}
Serializable allowEnlargement = renditionDefinition.getParameterValue(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT);
if (allowEnlargement != null) {
resizeOptions.setAllowEnlargement((Boolean) allowEnlargement);
}
imgTrOpts.setResizeOptions(resizeOptions);
}
thDefn.setTransformationOptions(transformationOptions);
TransformationOptionLimits limits = transformationOptions.getLimits();
Serializable v = params.get(OPT_TIMEOUT_MS);
if (v != null) {
limits.setTimeoutMs((Long) v);
}
v = params.get(OPT_READ_LIMIT_TIME_MS);
if (v != null) {
limits.setReadLimitTimeMs((Long) v);
}
v = params.get(OPT_MAX_SOURCE_SIZE_K_BYTES);
if (v != null) {
limits.setMaxSourceSizeKBytes((Long) v);
}
v = params.get(OPT_READ_LIMIT_K_BYTES);
if (v != null) {
limits.setReadLimitKBytes((Long) v);
}
v = params.get(OPT_MAX_PAGES);
if (v != null) {
limits.setMaxPages((Integer) v);
}
v = params.get(OPT_PAGE_LIMIT);
if (v != null) {
limits.setPageLimit((Integer) v);
}
return thDefn;
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class CreateThumbnailActionExecuter method executeImpl.
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
// Check if thumbnailing is generally disabled
if (!thumbnailService.getThumbnailsEnabled()) {
if (logger.isDebugEnabled()) {
logger.debug("Thumbnail transformations are not enabled");
}
return;
}
if (this.nodeService.exists(actionedUponNodeRef) == true) {
// Get the thumbnail Name
String thumbnailName = (String) action.getParameterValue(PARAM_THUMBANIL_NAME);
// Get the details of the thumbnail
ThumbnailRegistry registry = this.thumbnailService.getThumbnailRegistry();
ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
if (details == null) {
// Throw exception
throw new AlfrescoRuntimeException("The thumbnail name '" + thumbnailName + "' is not registered");
}
// Get the content property
QName contentProperty = (QName) action.getParameterValue(PARAM_CONTENT_PROPERTY);
if (contentProperty == null) {
contentProperty = ContentModel.PROP_CONTENT;
}
// If there isn't a currently active transformer for this, log and skip
Serializable contentProp = nodeService.getProperty(actionedUponNodeRef, contentProperty);
if (contentProp == null) {
logger.info("Creation of thumbnail, null content for " + details.getName());
return;
}
if (contentProp instanceof ContentData) {
ContentData content = (ContentData) contentProp;
String mimetype = content.getMimetype();
if (!registry.isThumbnailDefinitionAvailable(content.getContentUrl(), mimetype, content.getSize(), actionedUponNodeRef, details)) {
logger.debug("Unable to create thumbnail '" + details.getName() + "' for " + mimetype + " as no transformer is currently available");
return;
}
if (mimetypeMaxSourceSizeKBytes != null) {
Long maxSourceSizeKBytes = mimetypeMaxSourceSizeKBytes.get(mimetype);
if (maxSourceSizeKBytes != null && maxSourceSizeKBytes >= 0 && maxSourceSizeKBytes < (content.getSize() / 1024L)) {
logger.debug("Unable to create thumbnail '" + details.getName() + "' for " + mimetype + " as content is too large (" + (content.getSize() / 1024L) + "K > " + maxSourceSizeKBytes + "K)");
// avoid transform
return;
}
}
}
// Create the thumbnail
try {
TransformationOptions options = details.getTransformationOptions();
this.thumbnailService.createThumbnail(actionedUponNodeRef, contentProperty, details.getMimetype(), options, thumbnailName, null);
} catch (ContentServiceTransientException cste) {
// any transient failures in the thumbnail creation must be handled as transient failures of the action to execute.
StringBuilder msg = new StringBuilder();
msg.append("Creation of thumbnail '").append(details.getName()).append("' declined");
if (logger.isDebugEnabled()) {
logger.debug(msg.toString());
}
throw new ActionServiceTransientException(msg.toString(), cste);
} catch (Exception exception) {
final String msg = "Creation of thumbnail '" + details.getName() + "' failed";
logger.info(msg);
// See AddFailedThumbnailActionExecuter
throw new AlfrescoRuntimeException(msg, exception);
}
}
}
use of org.alfresco.service.cmr.repository.TransformationOptions in project alfresco-repository by Alfresco.
the class ThumbnailRegistry method getMaxSourceSizeBytes.
/**
* Returns the maximum source size of any content that may transformed between the supplied
* sourceMimetype and thumbnailDefinition's targetMimetype using its transformation options.
* @param sourceMimetype String
* @param thumbnailDefinition ThumbnailDefinition
* @return 0 if there are no transformers, -1 if there is no limit or if positive the size in bytes.
*/
public long getMaxSourceSizeBytes(String sourceMimetype, ThumbnailDefinition thumbnailDefinition) {
// Use RenditionService2 if it knows about the definition, otherwise use localTransformServiceRegistry.
// Needed as disabling local transforms should not disable thumbnails if they can be done remotely.
long maxSize = 0;
String targetMimetype = thumbnailDefinition.getMimetype();
RenditionDefinition2 renditionDefinition = getEquivalentRenditionDefinition2(thumbnailDefinition);
if (renditionDefinition != null) {
Map<String, String> options = renditionDefinition.getTransformOptions();
String renditionName = renditionDefinition.getRenditionName();
maxSize = transformServiceRegistry.findMaxSize(sourceMimetype, targetMimetype, options, renditionName);
} else {
boolean orig = TransformerDebug.setDebugOutput(false);
try {
TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
String renditionName = thumbnailDefinition.getName();
Map<String, String> options = converter.getOptions(transformationOptions, sourceMimetype, targetMimetype);
maxSize = localTransformServiceRegistry.findMaxSize(sourceMimetype, targetMimetype, options, renditionName);
} finally {
TransformerDebug.setDebugOutput(orig);
}
}
return maxSize;
}
Aggregations