Search in sources :

Example 1 with AbstractContentTransformer2

use of org.alfresco.repo.content.transform.AbstractContentTransformer2 in project alfresco-repository by Alfresco.

the class ContentTransformServiceAdaptor method wrapLocalTransformer.

private ContentTransformer wrapLocalTransformer(String sourceUrl, String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions transformationOptions) {
    AbstractContentTransformer2 transformer = null;
    Map<String, String> options = converter.getOptions(transformationOptions, null, null);
    LocalTransform localTransform = localTransformServiceRegistryImpl.getLocalTransform(sourceMimetype, sourceSize, targetMimetype, options, null);
    if (localTransform != null) {
        transformer = new AbstractContentTransformer2() {

            @Override
            public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws ContentIOException {
                try {
                    transformInternal(reader, writer, transformationOptions);
                } catch (Exception e) {
                    throw new ContentIOException(e.getMessage(), e);
                }
            }

            @Override
            protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions transformationOptions) throws Exception {
                localTransform.transform(reader, writer, options, null, null);
            }

            @Override
            public void register() {
            }

            @Override
            public boolean isSupportedTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options) {
                return true;
            }

            @Override
            public String getName() {
                return "Wrapped<" + localTransformServiceRegistryImpl.findTransformerName(sourceMimetype, sourceSize, targetMimetype, options, null) + ">";
            }
        };
    }
    return transformer;
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) AbstractContentTransformer2(org.alfresco.repo.content.transform.AbstractContentTransformer2) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) UnsupportedTransformationException(org.alfresco.repo.content.transform.UnsupportedTransformationException) NoTransformerException(org.alfresco.service.cmr.repository.NoTransformerException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) LocalTransform(org.alfresco.repo.content.transform.LocalTransform) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 AbstractContentTransformer2 (org.alfresco.repo.content.transform.AbstractContentTransformer2)1 LocalTransform (org.alfresco.repo.content.transform.LocalTransform)1 UnsupportedTransformationException (org.alfresco.repo.content.transform.UnsupportedTransformationException)1 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 NoTransformerException (org.alfresco.service.cmr.repository.NoTransformerException)1 TransformationOptions (org.alfresco.service.cmr.repository.TransformationOptions)1