use of org.alfresco.repo.content.transform.swf.SWFTransformationOptions 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.repo.content.transform.swf.SWFTransformationOptions in project alfresco-repository by Alfresco.
the class TransformationOptionsConverterTest method testSWFTransformationOptionsPage.
@Test
public // is no longer used as there are o transformers for it.
void testSWFTransformationOptionsPage() {
SWFTransformationOptions oldOptions = new SWFTransformationOptions();
PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
pagedSourceOptions.setStartPageNumber(1);
pagedSourceOptions.setEndPageNumber(1);
oldOptions.addSourceOptions(pagedSourceOptions);
assertConverterToMapAndBack(oldOptions, MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_PNG, "{maxSourceSizeKBytes=-1, use=null, contentReaderNodeRef=null, readLimitKBytes=-1, " + "contentWriterNodeRef=null, pageLimit=-1, flashVersion=9, timeoutMs=-1, maxPages=-1, " + "sourceContentProperty=null, targetContentProperty=null, includeEmbedded=null, readLimitTimeMs=-1}", "flashVersion=9 " + "timeout=-1 ", // SWFTransformationOptions are not used by ImageMagickContentTransformerWorker
false);
}
use of org.alfresco.repo.content.transform.swf.SWFTransformationOptions in project alfresco-repository by Alfresco.
the class TransformationOptionsConverter method getOptions.
public Map<String, String> getOptions(TransformationOptions options, String sourceMimetype, String targetMimetype) {
boolean sourceIsPdf = MIMETYPE_PDF.equals(sourceMimetype);
Map<String, String> map = new HashMap<>();
map.put(TIMEOUT, "-1");
if (options != null) {
if (options instanceof ImageTransformationOptions) {
ImageTransformationOptions opts = (ImageTransformationOptions) options;
// TODO We don't support this any more for security reasons, however it might be possible to
// extract some of the well know values and add them to the newer ImageMagick transform options.
String commandOptions = opts.getCommandOptions();
if (commandOptions != null && !commandOptions.isBlank()) {
logger.error("ImageMagick commandOptions are no longer supported for security reasons: " + commandOptions);
}
ImageResizeOptions imageResizeOptions = opts.getResizeOptions();
if (imageResizeOptions != null) {
int width = imageResizeOptions.getWidth();
int height = imageResizeOptions.getHeight();
ifSet(width != -1, map, RESIZE_WIDTH, width);
ifSet(height != -1, map, RESIZE_HEIGHT, height);
ifSet(imageResizeOptions.isResizeToThumbnail(), map, THUMBNAIL, true);
ifSet(imageResizeOptions.isPercentResize(), map, RESIZE_PERCENTAGE, true);
map.put(ALLOW_ENLARGEMENT, Boolean.toString(imageResizeOptions.getAllowEnlargement()));
map.put(MAINTAIN_ASPECT_RATIO, Boolean.toString(imageResizeOptions.isMaintainAspectRatio()));
}
ifSet(MimetypeMap.MIMETYPE_IMAGE_JPEG.equalsIgnoreCase(targetMimetype), map, ALPHA_REMOVE, true);
map.put(AUTO_ORIENT, Boolean.toString(opts.isAutoOrient()));
Collection<TransformationSourceOptions> sourceOptionsList = opts.getSourceOptionsList();
if (sourceOptionsList != null) {
for (TransformationSourceOptions transformationSourceOptions : sourceOptionsList) {
if (transformationSourceOptions instanceof PagedSourceOptions) {
PagedSourceOptions pagedSourceOptions = (PagedSourceOptions) transformationSourceOptions;
// The legacy transformer options start at page 1, where as image magick and the local
// transforms start at 0;
Integer startPageNumber = pagedSourceOptions.getStartPageNumber() - 1;
Integer endPageNumber = pagedSourceOptions.getEndPageNumber() - 1;
// PAGE is not an imagemagick option, but pdfRederer was incorrectly created initially using these options
if (startPageNumber == endPageNumber && sourceIsPdf) {
map.put(PAGE, Integer.toString(startPageNumber));
} else {
map.put(START_PAGE, Integer.toString(startPageNumber));
map.put(END_PAGE, Integer.toString(endPageNumber));
}
} else if (transformationSourceOptions instanceof CropSourceOptions) {
CropSourceOptions cropSourceOptions = (CropSourceOptions) transformationSourceOptions;
String gravity = cropSourceOptions.getGravity();
boolean percentageCrop = cropSourceOptions.isPercentageCrop();
int height = cropSourceOptions.getHeight();
int width = cropSourceOptions.getWidth();
int xOffset = cropSourceOptions.getXOffset();
int yOffset = cropSourceOptions.getYOffset();
ifSet(gravity != null, map, CROP_GRAVITY, gravity);
ifSet(percentageCrop, map, CROP_PERCENTAGE, percentageCrop);
ifSet(width != -1, map, CROP_WIDTH, width);
ifSet(height != -1, map, CROP_HEIGHT, height);
map.put(CROP_X_OFFSET, Integer.toString(xOffset));
map.put(CROP_Y_OFFSET, Integer.toString(yOffset));
} else if (transformationSourceOptions instanceof TemporalSourceOptions) {
TemporalSourceOptions temporalSourceOptions = (TemporalSourceOptions) transformationSourceOptions;
String duration = temporalSourceOptions.getDuration();
String offset = temporalSourceOptions.getOffset();
ifSet(duration != null, map, DURATION, duration);
ifSet(offset != null, map, OFFSET, offset);
} else {
logger.error("TransformationOption sourceOptionsList contained a " + transformationSourceOptions.getClass().getName() + ". It is not know how to convert this into newer transform options.");
}
}
}
} else if (options instanceof SWFTransformationOptions) {
SWFTransformationOptions opts = (SWFTransformationOptions) options;
map.put(FLASH_VERSION, opts.getFlashVersion());
} else if (options instanceof RuntimeExecutableContentTransformerOptions) {
RuntimeExecutableContentTransformerOptions opts = (RuntimeExecutableContentTransformerOptions) options;
map.putAll(opts.getPropertyValues());
} else if (!options.getClass().equals(TransformationOptions.class)) {
throw new IllegalArgumentException("Unable to convert " + options.getClass().getSimpleName() + " to new transform options held in a Map<String,String>.\n" + "The TransformOptionConverter may need to be sub classed to support this conversion.");
}
}
return map;
}
use of org.alfresco.repo.content.transform.swf.SWFTransformationOptions 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.content.transform.swf.SWFTransformationOptions in project alfresco-repository by Alfresco.
the class ThumbnailRenditionConvertor method convert.
/**
* Given the specified {@link TransformationOptions transformationOptions} and
* {@link ThumbnailParentAssociationDetails assocDetails},
* create and return a parameter Map which contains the equivalent {@link RenditionDefinition}
* configuration.
*
* @param transformationOptions TransformationOptions
* @param assocDetails ThumbnailParentAssociationDetails
* @return Map
*/
public Map<String, Serializable> convert(TransformationOptions transformationOptions, ThumbnailParentAssociationDetails assocDetails) {
Map<String, Serializable> parameters = new HashMap<String, Serializable>();
// All TransformationOptions-based renditions are considered to be "thumbnails".
// Therefore they should be created with a node type of cm:thumbnail
parameters.put(RenditionService.PARAM_RENDITION_NODETYPE, ContentModel.TYPE_THUMBNAIL);
// parameters common to all transformations
putParameterIfNotNull(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, transformationOptions.getSourceContentProperty(), parameters);
putParameterIfNotNull(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, transformationOptions.getTargetContentProperty(), parameters);
putParameterIfNotNull(RenditionService.PARAM_DESTINATION_NODE, transformationOptions.getTargetNodeRef(), parameters);
// putParameterIfNotNull(ImageRenderingEngine.PARAM_ASSOC_NAME, assocDetails.getAssociationName(), parameters);
// putParameterIfNotNull(ImageRenderingEngine.PARAM_ASSOC_TYPE, assocDetails.getAssociationType(), parameters);
putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_TIMEOUT_MS, transformationOptions.getTimeoutMs(), parameters);
putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_READ_LIMIT_TIME_MS, transformationOptions.getReadLimitTimeMs(), parameters);
putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_MAX_SOURCE_SIZE_K_BYTES, transformationOptions.getMaxSourceSizeKBytes(), parameters);
putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_READ_LIMIT_K_BYTES, transformationOptions.getReadLimitKBytes(), parameters);
putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_MAX_PAGES, transformationOptions.getMaxPages(), parameters);
putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_PAGE_LIMIT, transformationOptions.getPageLimit(), parameters);
putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_USE, transformationOptions.getUse(), parameters);
if (transformationOptions instanceof SWFTransformationOptions) {
SWFTransformationOptions swfTransformationOptions = (SWFTransformationOptions) transformationOptions;
putParameterIfNotNull(ReformatRenderingEngine.PARAM_FLASH_VERSION, swfTransformationOptions.getFlashVersion(), parameters);
} else if (transformationOptions instanceof ImageTransformationOptions) {
ImageTransformationOptions imTransformationOptions = (ImageTransformationOptions) transformationOptions;
putParameterIfNotNull(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, imTransformationOptions.getCommandOptions(), parameters);
putParameterIfNotNull(ImageRenderingEngine.PARAM_AUTO_ORIENTATION, imTransformationOptions.isAutoOrient(), parameters);
ImageResizeOptions imgResizeOptions = imTransformationOptions.getResizeOptions();
if (imgResizeOptions != null) {
int width = imgResizeOptions.getWidth();
parameters.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, width);
int height = imgResizeOptions.getHeight();
parameters.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, height);
boolean maintainAspectRatio = imgResizeOptions.isMaintainAspectRatio();
parameters.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, maintainAspectRatio);
boolean percentResize = imgResizeOptions.isPercentResize();
parameters.put(ImageRenderingEngine.PARAM_IS_PERCENT_RESIZE, percentResize);
boolean resizeToThumbnail = imgResizeOptions.isResizeToThumbnail();
parameters.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, resizeToThumbnail);
boolean allowEnlargement = imgResizeOptions.getAllowEnlargement();
parameters.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, allowEnlargement);
}
}
if (transformationOptions.getSourceOptionsList() != null) {
for (TransformationSourceOptions sourceOptions : transformationOptions.getSourceOptionsList()) {
sourceOptions.getSerializer().serialize(sourceOptions, parameters);
}
}
// TODO Handle RuntimeExecutableTransformationOptions
return parameters;
}
Aggregations