Merged BRANCHES/DEV/RGAUSS/HEAD-SOURCE-TARGET-TRANS-OPTIONS to HEAD:

45449: ALF-13254: TransformationOptions Should Have Separate Source and Target Options
        - Added SerializedTransformationOptionsAccessor interface which defines the methods used in the protected AbstractRenderingEngine.RenderContext class in a public manner
        - Changed AbstractRenderingEngine.RenderContext to implement SerializedTransformationOptionsAccessor
        - Added TransformationSourceOptions interface which also contains TransformationSourceOptionsSerializer interface which uses SerializedTransformationOptionsAccessor for deserialization
        - Added base AbstractTransformationSourceOptions class
        - Added PagedSourceOptions class which extends TransformationSourceOptions for start and end page options
        - Added TemporalSourceOptions class which extends TransformationSourceOptions for time-based offset and duration options
        - Changed TransformationOptions to contain TransformationSourceOptions held as a map with class as key
        - Changed ImageTransformationOptions to extend copyFrom
        - Changed ImageMagickContentTransformerWorker.getSourcePageRange to check for paged source options in the TransformationOptions passed in
        - Added ImageMagickContentTransformerTest.testPageSourceOptions to test null, default, page 2, and invalid options
        - Changed ThumbnailRenditionConvertor to iterate the transformationOptions.sourceOptionsList and use each serializer to add to the parameters
        - Changed AbstractTransformationRenderingEngine to iterate a list of TransformationSourceOptionsSerializers and use each to deserialize the RenderContext parameters and construct a TransformationSourceOptions object
        - Changed rendition-services-context.xml to set imageRenderingEngine's list of known sourceOptionsSerializers
        - Changed ThumbnailServiceImplParameterTest to test paged and temporal options
        - Added ThumbanailServiceImplTest.testCreateRenditionThumbnailFromPdfPage2 which tests grabbing the second page of a PDF


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@46062 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ray Gauss
2013-01-30 20:32:55 +00:00
parent 259ceebf47
commit 1c928e4c9f
15 changed files with 1005 additions and 27 deletions

View File

@@ -18,14 +18,23 @@
*/
package org.alfresco.repo.content.transform.magick;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.repo.content.filestore.FileContentWriter;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.content.transform.ContentTransformer;
import org.alfresco.repo.content.transform.ProxyContentTransformer;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.PagedSourceOptions;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.service.cmr.repository.TransformationSourceOptions;
import org.alfresco.util.TempFileProvider;
/**
* @see org.alfresco.repo.content.transform.magick.JMagickContentTransformer
@@ -73,6 +82,95 @@ public class ImageMagickContentTransformerTest extends AbstractContentTransforme
assertEquals("Mimetype should be supported", true, reliability);
}
protected void transform(String sourceMimetype, String targetMimetype, TransformationOptions options) throws IOException
{
String[] quickFiles = getQuickFilenames(sourceMimetype);
for (String quickFile : quickFiles)
{
String sourceExtension = quickFile.substring(quickFile.lastIndexOf('.')+1);
String targetExtension = mimetypeService.getExtension(targetMimetype);
// is there a test file for this conversion?
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(quickFile);
if (sourceFile == null)
{
continue; // no test file available for that extension
}
ContentReader sourceReader = new FileContentReader(sourceFile);
// make a writer for the target file
File targetFile = TempFileProvider.createTempFile(
getClass().getSimpleName() + "_" + getName() + "_" + sourceExtension + "_",
"." + targetExtension);
ContentWriter targetWriter = new FileContentWriter(targetFile);
// do the transformation
sourceReader.setMimetype(sourceMimetype);
targetWriter.setMimetype(targetMimetype);
transformer.transform(sourceReader.getReader(), targetWriter, options);
ContentReader targetReader = targetWriter.getReader();
assertTrue(targetReader.getSize() > 0);
}
}
public void testPageSourceOptions() throws Exception
{
// Test empty source options
ImageTransformationOptions options = new ImageTransformationOptions();
this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
// Test first page
options = new ImageTransformationOptions();
List<TransformationSourceOptions> sourceOptionsList = new ArrayList<TransformationSourceOptions>();
sourceOptionsList.add(PagedSourceOptions.getPage1Instance());
options.setSourceOptionsList(sourceOptionsList);
this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
// Test second page
options = new ImageTransformationOptions();
sourceOptionsList = new ArrayList<TransformationSourceOptions>();
PagedSourceOptions sourceOptions = new PagedSourceOptions();
sourceOptions.setStartPageNumber(2);
sourceOptions.setEndPageNumber(2);
sourceOptionsList.add(sourceOptions);
options.setSourceOptionsList(sourceOptionsList);
this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
// Test page range invalid for target type
options = new ImageTransformationOptions();
sourceOptionsList = new ArrayList<TransformationSourceOptions>();
sourceOptions = new PagedSourceOptions();
sourceOptions.setStartPageNumber(1);
sourceOptions.setEndPageNumber(2);
sourceOptionsList.add(sourceOptions);
options.setSourceOptionsList(sourceOptionsList);
try {
this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
fail("An exception regarding an invalid page range should have been thrown");
}
catch (Exception e)
{
// failure expected
}
// Test page out of range
options = new ImageTransformationOptions();
sourceOptionsList = new ArrayList<TransformationSourceOptions>();
sourceOptions = new PagedSourceOptions();
sourceOptions.setStartPageNumber(3);
sourceOptions.setEndPageNumber(3);
sourceOptionsList.add(sourceOptions);
options.setSourceOptionsList(sourceOptionsList);
try {
this.transform(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_IMAGE_PNG, options);
fail("An exception regarding an invalid page range should have been thrown");
}
catch (Exception e)
{
// failure expected
}
}
/**
* Mock mimetype service which returns a limited set of mimetypes
* as {@link AbstractContentTransformerTest#testAllConversions()} will

View File

@@ -25,6 +25,7 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.PagedSourceOptions;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.util.exec.RuntimeExec;
import org.alfresco.util.exec.RuntimeExec.ExecutionResult;
@@ -295,13 +296,13 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
}
/**
* Determines whether or not page range is required for the given source and target mimetypes.
* Determines whether or not a single page range is required for the given source and target mimetypes.
*
* @param sourceMimetype
* @param targetMimetype
* @return whether or not a page range must be specified for the transformer to read the target files
*/
private boolean isSourcePageRangeRequired(String sourceMimetype, String targetMimetype)
private boolean isSingleSourcePageRangeRequired(String sourceMimetype, String targetMimetype)
{
// Need a page source if we're transforming from PDF or TIFF to an image other than TIFF
return ((sourceMimetype.equals(MimetypeMap.MIMETYPE_PDF) ||
@@ -322,7 +323,43 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
*/
private String getSourcePageRange(TransformationOptions options, String sourceMimetype, String targetMimetype)
{
if (options.getPageLimit() == 1 || isSourcePageRangeRequired(sourceMimetype, targetMimetype))
// Check for PagedContentSourceOptions in the options
if (options instanceof ImageTransformationOptions)
{
ImageTransformationOptions imageOptions = (ImageTransformationOptions) options;
PagedSourceOptions pagedSourceOptions = imageOptions.getSourceOptions(PagedSourceOptions.class);
if (pagedSourceOptions != null)
{
if (pagedSourceOptions.getStartPageNumber() != null &&
pagedSourceOptions.getEndPageNumber() != null)
{
if (pagedSourceOptions.getStartPageNumber().equals(pagedSourceOptions.getEndPageNumber()))
{
return "[" + (pagedSourceOptions.getStartPageNumber() - 1) + "]";
}
else
{
if (isSingleSourcePageRangeRequired(sourceMimetype, targetMimetype))
{
throw new AlfrescoRuntimeException(
"A single page is required for targets of type " + targetMimetype);
}
return "[" + (pagedSourceOptions.getStartPageNumber() - 1) +
"-" + (pagedSourceOptions.getEndPageNumber() - 1) + "]";
}
}
else
{
// TODO specified start to end of doc and start of doc to specified end not yet supported
// Just grab a single page specified by either start or end
if (pagedSourceOptions.getStartPageNumber() != null)
return "[" + (pagedSourceOptions.getStartPageNumber() - 1) + "]";
if (pagedSourceOptions.getEndPageNumber() != null)
return "[" + (pagedSourceOptions.getEndPageNumber() - 1) + "]";
}
}
}
if (options.getPageLimit() == 1 || isSingleSourcePageRangeRequired(sourceMimetype, targetMimetype))
{
return "[0]";
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -143,4 +143,20 @@ public class ImageTransformationOptions extends TransformationOptions
{
this.autoOrient = autoOrient;
}
@Override
public void copyFrom(TransformationOptions origOptions) {
super.copyFrom(origOptions);
if (origOptions != null)
{
if (origOptions instanceof ImageTransformationOptions)
{
// Clone ImageTransformationOptions
this.setCommandOptions(((ImageTransformationOptions) origOptions).getCommandOptions());
this.setResizeOptions(((ImageTransformationOptions) origOptions).getResizeOptions());
this.setCropOptions(((ImageTransformationOptions) origOptions).getCropOptions());
this.setAutoOrient(((ImageTransformationOptions) origOptions).isAutoOrient());
}
}
}
}