use of org.alfresco.repo.rendition2.RenditionDefinition2 in project alfresco-repository by Alfresco.
the class ThumbnailRegistry method getEquivalentRenditionDefinition2.
private RenditionDefinition2 getEquivalentRenditionDefinition2(ThumbnailDefinition thumbnailDefinition) {
String renditionName = thumbnailDefinition.getName();
RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
if (renditionDefinition != null) {
String thumbnailTargetMimetype = thumbnailDefinition.getMimetype();
String renditionTargetMimetype = renditionDefinition.getTargetMimetype();
if (!renditionTargetMimetype.equals(thumbnailTargetMimetype)) {
renditionDefinition = null;
}
}
return renditionDefinition;
}
use of org.alfresco.repo.rendition2.RenditionDefinition2 in project alfresco-repository by Alfresco.
the class RenditionServiceImpl method getEquivalentRenditionDefinition2.
// Finds a RenditionDefinition2 with the same name (local part) and target mimetype.
private RenditionDefinition2 getEquivalentRenditionDefinition2(RenditionDefinition rendDefn) {
QName renditionQName = rendDefn.getRenditionName();
String renditionName = renditionQName.getLocalName();
RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
RenditionDefinition2 renditionDefinition2 = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
RenditionDefinition2 equivalentRenditionDefinition2 = null;
if (renditionDefinition2 != null) {
String targetMimetype = (String) rendDefn.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE);
String targetMimetype2 = renditionDefinition2.getTargetMimetype();
equivalentRenditionDefinition2 = targetMimetype.equals(targetMimetype2) ? renditionDefinition2 : null;
}
return equivalentRenditionDefinition2;
}
use of org.alfresco.repo.rendition2.RenditionDefinition2 in project alfresco-repository by Alfresco.
the class ThumbnailRegistry method isThumbnailDefinitionAvailable.
/**
* Checks to see if at this moment in time, the specified {@link ThumbnailDefinition}
* is able to thumbnail the source mimetype. Typically used with Thumbnail Definitions
* retrieved by name, and/or when dealing with transient {@link ContentTransformer}s.
* @param sourceUrl The URL of the source (optional)
* @param sourceMimetype The source mimetype
* @param sourceSize the size (in bytes) of the source. Use -1 if unknown.
* @param sourceNodeRef which is set in a copy of the thumbnailDefinition transformation options,
* so that it may be used by transformers and debug.
* @param thumbnailDefinition The {@link ThumbnailDefinition} to check for
*/
public boolean isThumbnailDefinitionAvailable(String sourceUrl, String sourceMimetype, long sourceSize, NodeRef sourceNodeRef, 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.
boolean supported = false;
String targetMimetype = thumbnailDefinition.getMimetype();
RenditionDefinition2 renditionDefinition = getEquivalentRenditionDefinition2(thumbnailDefinition);
if (renditionDefinition != null) {
Map<String, String> options = renditionDefinition.getTransformOptions();
String renditionName = renditionDefinition.getRenditionName();
supported = transformServiceRegistry.isSupported(sourceMimetype, sourceSize, 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);
supported = localTransformServiceRegistry.isSupported(sourceMimetype, sourceSize, targetMimetype, options, renditionName);
} finally {
TransformerDebug.setDebugOutput(orig);
}
}
return supported;
}
use of org.alfresco.repo.rendition2.RenditionDefinition2 in project alfresco-repository by Alfresco.
the class TransformationOptionsConverter method getTransformationOptions.
/**
* @deprecated as we do not plan to use TransformationOptions moving forwards as local transformations will also
* use the same options as the Transform Service.
*/
@Deprecated
TransformationOptions getTransformationOptions(String renditionName, Map<String, String> options) {
TransformationOptions transformationOptions = null;
Set<String> optionNames = options.keySet();
// The "pdf" rendition is special as it was incorrectly set up as an SWFTransformationOptions in 6.0
// It should have been simply a TransformationOptions.
boolean isPdfRendition = "pdf".equals(renditionName);
Set<String> subclassOptionNames = new HashSet<>(optionNames);
subclassOptionNames.removeAll(LIMIT_OPTIONS);
subclassOptionNames.remove(INCLUDE_CONTENTS);
boolean hasOptions = !subclassOptionNames.isEmpty();
if (isPdfRendition || hasOptions) {
// The "pdf" rendition used the wrong TransformationOptions subclass.
if (isPdfRendition || FLASH_OPTIONS.containsAll(subclassOptionNames)) {
SWFTransformationOptions opts = new SWFTransformationOptions();
transformationOptions = opts;
opts.setFlashVersion(isPdfRendition ? "9" : options.get(FLASH_VERSION));
} else // that use ImageTransformOptions to specify width, height etc.
if (IMAGE_OPTIONS.containsAll(subclassOptionNames) || PDF_OPTIONS.containsAll(subclassOptionNames)) {
ImageTransformationOptions opts = new ImageTransformationOptions();
transformationOptions = opts;
if (containsAny(subclassOptionNames, RESIZE_OPTIONS)) {
ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
opts.setResizeOptions(imageResizeOptions);
// PDF
ifSet(options, WIDTH, (v) -> imageResizeOptions.setWidth(Integer.parseInt(v)));
ifSet(options, HEIGHT, (v) -> imageResizeOptions.setHeight(Integer.parseInt(v)));
// ImageMagick
ifSet(options, RESIZE_WIDTH, (v) -> imageResizeOptions.setWidth(Integer.parseInt(v)));
ifSet(options, RESIZE_HEIGHT, (v) -> imageResizeOptions.setHeight(Integer.parseInt(v)));
ifSet(options, THUMBNAIL, (v) -> imageResizeOptions.setResizeToThumbnail(Boolean.parseBoolean(v)));
ifSet(options, RESIZE_PERCENTAGE, (v) -> imageResizeOptions.setPercentResize(Boolean.parseBoolean(v)));
set(options, ALLOW_ENLARGEMENT, (v) -> imageResizeOptions.setAllowEnlargement(Boolean.parseBoolean(v == null ? "true" : v)));
set(options, MAINTAIN_ASPECT_RATIO, (v) -> imageResizeOptions.setMaintainAspectRatio(Boolean.parseBoolean(v == null ? "true" : v)));
}
// ALPHA_REMOVE can be ignored as it is automatically added in the legacy code if the sourceMimetype is jpeg
set(options, AUTO_ORIENT, (v) -> opts.setAutoOrient(Boolean.parseBoolean(v == null ? "true" : v)));
boolean containsPaged = containsAny(subclassOptionNames, PAGED_OPTIONS);
boolean containsCrop = containsAny(subclassOptionNames, CROP_OPTIONS);
boolean containsTemporal = containsAny(subclassOptionNames, TEMPORAL_OPTIONS);
if (containsPaged || containsCrop || containsTemporal) {
List<TransformationSourceOptions> sourceOptionsList = new ArrayList<>();
if (containsPaged) {
// The legacy transformer options start at page 1, where as image magick and the local
// transforms start at 0;
PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
sourceOptionsList.add(pagedSourceOptions);
ifSet(options, START_PAGE, (v) -> pagedSourceOptions.setStartPageNumber(Integer.parseInt(v) + 1));
ifSet(options, END_PAGE, (v) -> pagedSourceOptions.setEndPageNumber(Integer.parseInt(v) + 1));
ifSet(options, PAGE, (v) -> {
int i = Integer.parseInt(v) + 1;
pagedSourceOptions.setStartPageNumber(i);
pagedSourceOptions.setEndPageNumber(i);
});
}
if (containsCrop) {
CropSourceOptions cropSourceOptions = new CropSourceOptions();
sourceOptionsList.add(cropSourceOptions);
ifSet(options, CROP_GRAVITY, (v) -> cropSourceOptions.setGravity(v));
ifSet(options, CROP_PERCENTAGE, (v) -> cropSourceOptions.setPercentageCrop(Boolean.parseBoolean(v)));
ifSet(options, CROP_WIDTH, (v) -> cropSourceOptions.setWidth(Integer.parseInt(v)));
ifSet(options, CROP_HEIGHT, (v) -> cropSourceOptions.setHeight(Integer.parseInt(v)));
ifSet(options, CROP_X_OFFSET, (v) -> cropSourceOptions.setXOffset(Integer.parseInt(v)));
ifSet(options, CROP_Y_OFFSET, (v) -> cropSourceOptions.setYOffset(Integer.parseInt(v)));
}
if (containsTemporal) {
TemporalSourceOptions temporalSourceOptions = new TemporalSourceOptions();
sourceOptionsList.add(temporalSourceOptions);
ifSet(options, DURATION, (v) -> temporalSourceOptions.setDuration(v));
ifSet(options, OFFSET, (v) -> temporalSourceOptions.setOffset(v));
}
opts.setSourceOptionsList(sourceOptionsList);
}
}
} else {
// This what the "pdf" rendition should have used in 6.0 and it is not unreasonable for a custom transformer
// and rendition to do the same.
transformationOptions = new TransformationOptions();
}
if (transformationOptions == null) {
StringJoiner sj = new StringJoiner("\n ");
sj.add("The RenditionDefinition2 " + renditionName + " contains options that cannot be mapped to TransformationOptions used by local transformers. " + " The TransformOptionConverter may need to be sub classed to support this conversion.");
HashSet<String> otherNames = new HashSet<>(optionNames);
otherNames.removeAll(FLASH_OPTIONS);
otherNames.removeAll(IMAGE_OPTIONS);
otherNames.removeAll(PDF_OPTIONS);
otherNames.removeAll(LIMIT_OPTIONS);
otherNames.forEach(sj::add);
sj.add("---");
optionNames.forEach(sj::add);
throw new IllegalArgumentException(sj.toString());
}
final TransformationOptions opts = transformationOptions;
ifSet(options, INCLUDE_CONTENTS, (v) -> opts.setIncludeEmbedded(Boolean.parseBoolean(v)));
if (containsAny(optionNames, LIMIT_OPTIONS)) {
TransformationOptionLimits limits = new TransformationOptionLimits();
transformationOptions.setLimits(limits);
ifSet(options, TIMEOUT, (v) -> limits.setTimeoutMs(Long.parseLong(v)));
limits.setMaxSourceSizeKBytes(maxSourceSizeKBytes);
limits.setReadLimitKBytes(readLimitTimeMs);
limits.setReadLimitTimeMs(readLimitKBytes);
limits.setMaxPages(maxPages);
limits.setPageLimit(pageLimit);
}
transformationOptions.setUse(renditionName);
return transformationOptions;
}
use of org.alfresco.repo.rendition2.RenditionDefinition2 in project alfresco-repository by Alfresco.
the class RenditionServiceImpl method usingRenditionService2.
@Override
public boolean usingRenditionService2(NodeRef sourceNodeRef, RenditionDefinition rendDefn) {
boolean useRenditionService2 = false;
QName renditionQName = rendDefn.getRenditionName();
String renditionName = renditionQName.getLocalName();
RenditionDefinition2 renditionDefinition2 = getEquivalentRenditionDefinition2(rendDefn);
boolean createdByRenditionService2 = renditionService2.isCreatedByRenditionService2(sourceNodeRef, renditionName);
if (renditionService2.isEnabled()) {
if (createdByRenditionService2) {
// rendition and the old service takes over again.
if (renditionDefinition2 != null) {
if (log.isDebugEnabled()) {
log.debug("OnContentUpdate ignored by original service as the rendition for \"" + sourceNodeRef + "\", \"" + renditionName + "\" new service has taken over.");
}
useRenditionService2 = true;
} else {
if (log.isDebugEnabled()) {
log.debug("OnContentUpdate remove rendition for \"" + sourceNodeRef + "\", \"" + renditionName + "\" so we switch back to the original service, as the new service does not have the definition.");
}
renditionService2.deleteRendition(sourceNodeRef, renditionName);
}
} else if (renditionDefinition2 != null) {
// aspect being added, so future renditions will also be done by the newer service.
if (log.isDebugEnabled()) {
log.debug("OnContentUpdate calling RenditionService2.render(\"" + sourceNodeRef + "\", \"" + renditionName + "\" so we switch to the new service.");
}
useRenditionService2 = true;
renditionService2.render(sourceNodeRef, renditionName);
}
} else if (createdByRenditionService2) {
// As the new service has been disabled the old service needs to take over, so the rendition is removed.
if (log.isDebugEnabled()) {
log.debug("OnContentUpdate remove rendition for \"" + sourceNodeRef + "\", \"" + renditionName + "\" so we switch back to the original service, as the new service is disabled.");
}
renditionService2.deleteRendition(sourceNodeRef, renditionName);
}
return useRenditionService2;
}
Aggregations