disabledMediaTypes)
- {
- this.disabledMediaTypes = disabledMediaTypes;
- }
-
- @Override
- public boolean select(Metadata metadata)
- {
- String contentType = metadata.get(Metadata.CONTENT_TYPE);
- if (contentType == null || contentType.equals("") || disabledMediaTypes == null)
- {
- return true;
- }
- return !disabledMediaTypes.contains(contentType);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformer.java
deleted file mode 100644
index 80f5b4f6ea..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformer.java
+++ /dev/null
@@ -1,506 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.service.cmr.repository.ContentAccessor;
-import org.alfresco.service.cmr.repository.ContentIOException;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.MimetypeService;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.springframework.beans.factory.BeanNameAware;
-import org.springframework.extensions.surf.util.ParameterCheck;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Provides basic services for {@link org.alfresco.repo.content.transform.ContentTransformer}
- * implementations.
- *
- * This class maintains the performance measures for the transformers as well, making sure that
- * there is an extra penalty for transformers that fail regularly.
- *
- * @deprecated
- * Deprecated since 3.0. The abstract base class org.alfresco.repo.content.transform.AbstractContentTransformer2 should now be used instead.
- *
- * @author Derek Hulley
- */
-@Deprecated
-public abstract class AbstractContentTransformer implements ContentTransformer, BeanNameAware
-{
- private static final Log logger = LogFactory.getLog(AbstractContentTransformer.class);
-
- private MimetypeService mimetypeService;
- private ContentTransformerRegistry registry;
- @SuppressWarnings("deprecation")
- private List explicitTransformations;
- private double averageTime = 0.0;
- private long count = 0L;
-
- /** The bean name. */
- private String beanName;
-
- /**
- * All transformers start with an average transformation time of 0.0ms.
- */
- @SuppressWarnings("deprecation")
- protected AbstractContentTransformer()
- {
- averageTime = 0.0;
- explicitTransformations = new ArrayList(0);
- }
-
- /**
- * The registry to auto-register with
- *
- * @param registry the transformer registry
- */
- public void setRegistry(ContentTransformerRegistry registry)
- {
- this.registry = registry;
- }
-
- /**
- * Helper setter of the mimetype service. This is not always required.
- *
- * @param mimetypeService MimetypeService
- */
- public void setMimetypeService(MimetypeService mimetypeService)
- {
- this.mimetypeService = mimetypeService;
- }
-
- /**
- * @return Returns the mimetype helper
- */
- protected MimetypeService getMimetypeService()
- {
- return mimetypeService;
- }
-
- /**
- * @return Returns the explicit transformations that were enabled for this transformer
- */
- @SuppressWarnings("deprecation")
- protected List getExplicitTransformations()
- {
- return explicitTransformations;
- }
-
- /**
- * Set the transformations that this transformer can do regardless of what it returns
- * via the reliability check.
- *
- * @param explicitTransformations explicit key mappings
- */
- @SuppressWarnings("deprecation")
- public void setExplicitTransformations(List explicitTransformations)
- {
- this.explicitTransformations = explicitTransformations;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- sb.append(this.getClass().getSimpleName())
- .append("[ average=").append((long)averageTime).append("ms")
- .append("]");
- return sb.toString();
- }
-
- /**
- * Registers this instance with the {@link #setRegistry(ContentTransformerRegistry) registry}
- * if it is present.
- */
- public void register()
- {
- if (registry == null)
- {
- logger.warn("Property 'registry' has not been set. Ignoring auto-registration: \n" +
- " transformer: " + this);
- return;
- }
- // first register any explicit transformations
- //if (explicitTransformations != null)
- //{
- // for (ContentTransformerRegistry.TransformationKey key : explicitTransformations)
- // / {
- // registry.addExplicitTransformer(key, this);
- // }
- //}
- // register this instance for the fallback case
- registry.addTransformer(this);
- }
-
- /**
- * Convenience to fetch and check the mimetype for the given content
- *
- * @param content the reader/writer for the content
- * @return Returns the mimetype for the content
- * @throws AlfrescoRuntimeException if the content doesn't have a mimetype
- */
- protected String getMimetype(ContentAccessor content)
- {
- String mimetype = content.getMimetype();
- if (mimetype == null)
- {
- throw new AlfrescoRuntimeException("Mimetype is mandatory for transformation: " + content);
- }
- // done
- return mimetype;
- }
-
- /**
- * Added for backward compatibility of existing content transformers
- *
- * @param sourceMimetype the source mimetype
- * @param targetMimetype the target mimetype
- * @return double the reliability value of the content transformer ranging from 0 to 1
- */
- protected abstract double getReliability(String sourceMimetype, String targetMimetype);
-
- /**
- * Convenience method to check the reliability of a transformation
- *
- * @param reader ContentReader
- * @param writer ContentWriter
- * @throws AlfrescoRuntimeException if the reliability isn't > 0
- */
- protected void checkReliability(ContentReader reader, ContentWriter writer)
- {
- String sourceMimetype = getMimetype(reader);
- String targetMimetype = getMimetype(writer);
- double reliability = getReliability(sourceMimetype, targetMimetype);
- if (reliability <= 0.0)
- {
- throw new AlfrescoRuntimeException("Zero scoring transformation attempted: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer);
- }
- // it all checks out OK
- }
-
- /**
- * {@inheritDoc}
- *
- * Implementation calls the deprecated overloaded method without the sourceSize parameter.
- * Note: source size checked has not been added to this deprecated class.
- */
- @Override
- public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- return
- isTransformableMimetype(sourceMimetype, targetMimetype, options) &&
- isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
- }
-
- /**
- * @deprecated use version with extra sourceSize parameter.
- */
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- ParameterCheck.mandatoryString("sourceMimetype", sourceMimetype);
- ParameterCheck.mandatoryString("targetMimetype", targetMimetype);
-
- double reliability = getReliability(sourceMimetype, targetMimetype);
- boolean result = true;
- if (reliability <= 0.0)
- {
- result = false;
- }
- return result;
- }
-
- /**
- * Checks the supplied mimetypes are supported by calling the deprecated
- * {@link #isTransformable(String, String, TransformationOptions)} method.
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype,
- TransformationOptions options)
- {
- return isTransformable(sourceMimetype, targetMimetype, options);
- }
-
- /**
- * Always returns {@code true} to indicate size is not an issue.
- */
- @Override
- public boolean isTransformableSize(String sourceMimetype, long sourceSize,
- String targetMimetype, TransformationOptions options)
- {
- return true;
- }
-
- /**
- * Always returns {@code -1} to indicate an unlimited size.
- */
- @Override
- public long getMaxSourceSizeKBytes(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return -1;
- }
-
- /**
- * @see org.alfresco.repo.content.transform.ContentTransformer#isTransformable(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- @SuppressWarnings("deprecation")
- public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- boolean result = false;
-
- if (this.explicitTransformations != null)
- {
- for (ContentTransformerRegistry.TransformationKey transformationKey : this.explicitTransformations)
- {
- if (transformationKey.getSourceMimetype().equals(sourceMimetype) == true &&
- transformationKey.getTargetMimetype().equals(targetMimetype) == true)
- {
- result = true;
- break;
- }
- }
- }
-
- return result;
- }
-
- /**
- * Method to be implemented by subclasses wishing to make use of the common infrastructural code
- * provided by this class.
- *
- * @param reader the source of the content to transform
- * @param writer the target to which to write the transformed content
- * @param options a map of options to use when performing the transformation. The map
- * will never be null.
- * @throws Exception exceptions will be handled by this class - subclasses can throw anything
- */
- protected abstract void transformInternal(
- ContentReader reader,
- ContentWriter writer,
- Map options) throws Exception;
-
- /**
- * @see #transform(ContentReader, ContentWriter, Map)
- * @see #transformInternal(ContentReader, ContentWriter, Map)
- */
- public final void transform(ContentReader reader, ContentWriter writer) throws ContentIOException
- {
- Map optionsMap = null;
- transform(reader, writer, optionsMap);
- }
-
- /**
- * @see org.alfresco.repo.content.transform.ContentTransformer#transform(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- public final void transform(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws ContentIOException
- {
- Map optionsMap = options.toMap();
- transform(reader, writer, optionsMap);
- }
-
- /**
- * Performs the following:
- *
- * - Times the transformation
- * - Ensures that the transformation is allowed
- * - Calls the subclass implementation of {@link #transformInternal(ContentReader, ContentWriter, Map)}
- * - Transforms any exceptions generated
- * - Logs a successful transformation
- *
- * Subclass need only be concerned with performing the transformation.
- *
- * If the options provided are null, then an empty map will be created.
- */
- @SuppressWarnings("deprecation")
- public final void transform(
- ContentReader reader,
- ContentWriter writer,
- Map options) throws ContentIOException
- {
- // begin timing
- long before = System.currentTimeMillis();
-
- // check options map
- if (options == null)
- {
- options = Collections.emptyMap();
- }
-
- try
- {
- // Check the reliability
- checkReliability(reader, writer);
-
- // Transform
- transformInternal(reader, writer, options);
- }
- catch (Throwable e)
- {
- // Make sure that this transformation gets set back i.t.o. time taken.
- // This will ensure that transformers that compete for the same transformation
- // will be prejudiced against transformers that tend to fail
- recordTime(10000); // 10 seconds, i.e. rubbish
-
- throw new ContentIOException("Content conversion failed: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " options: " + options,
- e);
- }
- finally
- {
- // check that the reader and writer are both closed
- if (reader.isChannelOpen())
- {
- logger.error("Content reader not closed by transformer: \n" +
- " reader: " + reader + "\n" +
- " transformer: " + this);
- }
- if (writer.isChannelOpen())
- {
- logger.error("Content writer not closed by transformer: \n" +
- " writer: " + writer + "\n" +
- " transformer: " + this);
- }
- }
-
- // record time
- long after = System.currentTimeMillis();
- recordTime(after - before);
-
- // done
- if (logger.isDebugEnabled())
- {
- logger.debug("Completed transformation: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " options: " + options + "\n" +
- " transformer: " + this);
- }
- }
-
- /**
- * @return Returns the calculated running average of the current transformations
- */
- public synchronized long getTransformationTime()
- {
- return (long) averageTime;
- }
-
- public long getTransformationTime(String sourceMimetype, String targetMimetype)
- {
- return (long) averageTime;
- }
-
- /**
- * Records and updates the average transformation time for this transformer.
- *
- * Subclasses should call this after every transformation in order to keep
- * the running average of the transformation times up to date.
- *
- * This method is thread-safe. The time spent in this method is negligible
- * so the impact will be minor.
- *
- * @param transformationTime the time it took to perform the transformation.
- * The value may be 0.
- */
- protected final synchronized void recordTime(long transformationTime)
- {
- if (count == Long.MAX_VALUE)
- {
- // we have reached the max count - reduce it by half
- // the average fluctuation won't be extreme
- count /= 2L;
- }
- // adjust the average
- count++;
- double diffTime = ((double) transformationTime) - averageTime;
- averageTime += diffTime / (double) count;
- }
-
- /**
- * Sets the Spring bean name.
- */
- @Override
- public void setBeanName(String beanName)
- {
- this.beanName = beanName;
- }
-
- /**
- * Returns the Spring bean name.
- */
- public String getBeanName()
- {
- return beanName;
- }
-
- /**
- * Returns transformer name. Uses the Spring bean name, but if null uses the class name.
- */
- public String getName()
- {
- return (beanName == null) ? getClass().getSimpleName() : beanName;
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((beanName == null) ? 0 : beanName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- AbstractContentTransformer other = (AbstractContentTransformer) obj;
- if (beanName == null)
- {
- if (other.beanName != null)
- return false;
- }
- else if (!beanName.equals(other.beanName))
- return false;
- return true;
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformer2.java b/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformer2.java
deleted file mode 100644
index 1f0f601d53..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformer2.java
+++ /dev/null
@@ -1,669 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.AbstractStreamAwareProxy;
-import org.alfresco.repo.content.StreamAwareContentReaderProxy;
-import org.alfresco.repo.content.StreamAwareContentWriterProxy;
-import org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter;
-import org.alfresco.service.cmr.repository.ContentIOException;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentServiceTransientException;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptionLimits;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Provides basic services for {@link org.alfresco.repo.content.transform.ContentTransformer}
- * implementations.
- *
- * This class maintains the performance measures for the transformers as well, making sure that
- * there is an extra penalty for transformers that fail regularly.
- *
- * @author Derek Hulley
- * @author Roy Wetherall
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public abstract class AbstractContentTransformer2 extends AbstractContentTransformerLimits
-{
- private static final Log logger = LogFactory.getLog(AbstractContentTransformer2.class);
-
- private ExecutorService executorService;
-
- private ContentTransformerRegistry registry;
- private boolean registerTransformer;
- private boolean retryTransformOnDifferentMimeType;
- private boolean strictMimeTypeCheck;
-
- /**
- * A flag that indicates that the transformer should be started in it own Thread so
- * that it may be interrupted rather than using the timeout in the Reader.
- * Need only be set for transformers that read their source data quickly but then
- * take a long time to process the data (such as {@link PoiOOXMLContentTransformer}.
- */
- private Boolean useTimeoutThread = false;
-
- /**
- * Extra time added the timeout when using a Thread for the transformation so that
- * a timeout from the Reader has a chance to happen first.
- */
- private long additionalThreadTimout = 2000;
-
- private static ThreadLocal depth = new ThreadLocal()
- {
- @Override
- protected Integer initialValue()
- {
- return 0;
- }
- };
-
- /**
- * All transformers start with an average transformation time of 0.0 ms,
- * unless there is an Alfresco global property {@code .time}.
- * May also be set for given combinations of source and target mimetypes.
- */
- protected AbstractContentTransformer2()
- {
- }
-
- /**
- * The registry to auto-register with
- *
- * @param registry the transformer registry
- */
- public void setRegistry(ContentTransformerRegistry registry)
- {
- this.registry = registry;
- }
-
- /**
- * @param registerTransformer as been available for selection.
- * If {@code false} this indicates that the transformer may only be
- * used as part of another transformer.
- */
- public void setRegisterTransformer(boolean registerTransformer)
- {
- this.registerTransformer = registerTransformer;
- }
-
- @Override
- public String toString()
- {
- return this.getClass().getSimpleName();
- }
-
- /**
- * Registers this instance with the {@link #setRegistry(ContentTransformerRegistry) registry}
- * if it is present.
- *
- * THIS IS A CUSTOM SPRING INIT METHOD
- */
- public void register()
- {
- super.register();
- if (registry == null)
- {
- logger.warn("Property 'registry' has not been set. Ignoring auto-registration: \n" +
- " transformer: " + this.getName());
- }
- else if (registerTransformer)
- {
- registry.addTransformer(this);
- }
- else
- {
- registry.addComponentTransformer(this);
- logger.debug("Property 'registerTransformer' have not been set, so transformer (" +
- this.getName() + ") may only be used as a component of a complex transformer.");
- }
- }
-
- /**
- * Convenience method to check the transformability of a transformation
- *
- * @param reader content reader
- * @param writer content writer
- * @param options transformation options
- * @throws AlfrescoRuntimeException if the the transformation isn't supported
- */
- protected void checkTransformable(ContentReader reader, ContentWriter writer, TransformationOptions options)
- {
- String sourceMimetype = getMimetype(reader);
- String targetMimetype = getMimetype(writer);
- long sourceSize = reader.getSize();
- boolean transformable = isTransformable(sourceMimetype, sourceSize, targetMimetype, options);
- if (transformable == false)
- {
- // This method is only called once a transformer has been selected, so it should be able to
- // handle the mimetypes but might not be able to handle all the limits as it might be part of
- // of a complex (compound) transformer. So report the max size if set.
- long maxSourceSizeKBytes = getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
- boolean sizeOkay = maxSourceSizeKBytes < 0 || (maxSourceSizeKBytes > 0 && sourceSize <= maxSourceSizeKBytes*1024);
- AlfrescoRuntimeException e = new UnsupportedTransformationException("Unsupported transformation: " +
- getBeanName()+' '+sourceMimetype+" to "+targetMimetype+' '+
- (sizeOkay
- ? ""
- : transformerDebug.fileSize(sourceSize)+" > "+ transformerDebug.fileSize(maxSourceSizeKBytes*1024)));
- throw transformerDebug.setCause(e);
- }
- // it all checks out OK
- }
-
- /**
- * Method to be implemented by subclasses wishing to make use of the common infrastructural code
- * provided by this class.
- *
- * @param reader the source of the content to transform
- * @param writer the target to which to write the transformed content
- * @param options a map of options to use when performing the transformation. The map
- * will never be null.
- * @throws Exception exceptions will be handled by this class - subclasses can throw anything
- */
- protected abstract void transformInternal(
- ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception;
-
- /**
- * @see #transform(ContentReader, ContentWriter, Map)
- * @see #transformInternal(ContentReader, ContentWriter, TransformationOptions)
- */
- public final void transform(ContentReader reader, ContentWriter writer) throws ContentIOException
- {
- transform(reader, writer, new TransformationOptions());
- }
-
- /**
- * @see org.alfresco.repo.content.transform.ContentTransformer#transform(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws ContentIOException
- {
- try
- {
- depth.set(depth.get()+1);
-
- // begin timing
- long before = System.currentTimeMillis();
-
- String sourceMimetype = reader.getMimetype();
- String targetMimetype = writer.getMimetype();
-
- // check options map
- if (options == null)
- {
- options = new TransformationOptions();
- }
-
- try
- {
- if (transformerDebug.isEnabled())
- {
- ((LegacyTransformerDebug)transformerDebug).pushTransform(this, reader.getContentUrl(), sourceMimetype,
- targetMimetype, reader.getSize(), options);
- }
-
- // MNT-16381: check the mimetype of the file supplied by the user
- // matches the sourceMimetype of the reader. Intermediate files are
- // not checked.
- strictMimetypeCheck(reader, options, sourceMimetype);
-
- // Check the transformability
- checkTransformable(reader, writer, options);
-
- // Pass on any limits to the reader
- setReaderLimits(reader, writer, options);
-
- // Transform
- // MNT-12238: CLONE - CLONE - Upload of PPTX causes very high memory usage leading to system instability
- // Limiting transformation up to configured amount of milliseconds to avoid very high RAM consumption
- // and OOM during transforming problematic documents
- TransformationOptionLimits limits = getLimits(reader.getMimetype(), writer.getMimetype(), options);
-
- long timeoutMs = limits.getTimeoutMs();
- if (!useTimeoutThread || (null == limits) || (-1 == timeoutMs))
- {
- transformInternal(reader, writer, options);
- }
- else
- {
- Future> submittedTask = null;
- StreamAwareContentReaderProxy proxiedReader = new StreamAwareContentReaderProxy(reader);
- StreamAwareContentWriterProxy proxiedWriter = new StreamAwareContentWriterProxy(writer);
-
- try
- {
- submittedTask = getExecutorService().submit(new TransformInternalCallable(proxiedReader, proxiedWriter, options));
- submittedTask.get(timeoutMs + additionalThreadTimout, TimeUnit.MILLISECONDS);
- }
- catch (TimeoutException e)
- {
- releaseResources(submittedTask, proxiedReader, proxiedWriter);
- throw new TimeoutException("Transformation failed due to timeout limit");
- }
- catch (InterruptedException e)
- {
- releaseResources(submittedTask, proxiedReader, proxiedWriter);
- throw new InterruptedException("Transformation failed, because the thread of the transformation was interrupted");
- }
- catch (ExecutionException e)
- {
- Throwable cause = e.getCause();
- if (cause instanceof TransformInternalCallableException)
- {
- cause = ((TransformInternalCallableException) cause).getCause();
- }
-
- throw cause;
- }
- }
-
- // record time
- long after = System.currentTimeMillis();
- recordTime(sourceMimetype, targetMimetype, after - before);
- }
- catch (ContentServiceTransientException cste)
- {
- // A transient failure has occurred within the content transformer.
- // This should not be interpreted as a failure and therefore we should not
- // update the transformer's average time.
- if (logger.isDebugEnabled())
- {
- logger.debug("Transformation has been transiently declined: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " options: " + options + "\n" +
- " transformer: " + this);
- }
- // the finally block below will still perform tidyup. Otherwise we're done.
- // We rethrow the exception
- throw cste;
- }
- catch (UnsupportedTransformationException e)
- {
- // Don't record an error or even the time, as this is normal in compound transformations.
- transformerDebug.debug(" Failed", e);
- throw e;
- }
- catch (Throwable e)
- {
- // Make sure that this transformation gets set back i.t.o. time taken.
- // This will ensure that transformers that compete for the same transformation
- // will be prejudiced against transformers that tend to fail
- long after = System.currentTimeMillis();
- recordError(sourceMimetype, targetMimetype, after - before);
-
- // Ask Tika to detect the document, and report back on if
- // the current mime type is plausible
- String differentType = getMimetypeService().getMimetypeIfNotMatches(reader.getReader());
-
- // Report the error
- if (differentType == null)
- {
- transformerDebug.debug(" Failed", e);
- throw new ContentIOException("Content conversion failed: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " options: " + options.toString(false) + "\n" +
- " limits: " + getLimits(reader, writer, options),
- e);
- }
- else
- {
- transformerDebug.debug(" Failed: Mime type was '"+differentType+"'", e);
-
- if (retryTransformOnDifferentMimeType)
- {
- // MNT-11015 fix.
- // Set a new reader to refresh the input stream.
- reader = reader.getReader();
- // set the actual file MIME type detected by Tika for content reader
- reader.setMimetype(differentType);
-
- // Get correct transformer according actual file MIME type and try to transform file with
- // actual transformer
- ContentTransformer transformer = this.registry.getTransformer(differentType, reader.getSize(),
- targetMimetype, options);
- if (null != transformer)
- {
- transformer.transform(reader, writer, options);
- }
- else
- {
- transformerDebug.debug(" Failed", e);
- throw new ContentIOException("Content conversion failed: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " options: " + options.toString(false) + "\n" +
- " limits: " + getLimits(reader, writer, options) + "\n" +
- " claimed mime type: " + reader.getMimetype() + "\n" +
- " detected mime type: " + differentType + "\n" +
- " transformer not found" + "\n",
- e
- );
- }
- }
- else
- {
- throw new ContentIOException("Content conversion failed: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " options: " + options.toString(false) + "\n" +
- " limits: " + getLimits(reader, writer, options) + "\n" +
- " claimed mime type: " + reader.getMimetype() + "\n" +
- " detected mime type: " + differentType,
- e
- );
- }
- }
- }
- finally
- {
- transformerDebug.popTransform();
-
- // check that the reader and writer are both closed
- if (reader.isChannelOpen())
- {
- logger.error("Content reader not closed by transformer: \n" +
- " reader: " + reader + "\n" +
- " transformer: " + this);
- }
- if (writer.isChannelOpen())
- {
- logger.error("Content writer not closed by transformer: \n" +
- " writer: " + writer + "\n" +
- " transformer: " + this);
- }
- }
-
- // done
- if (logger.isDebugEnabled())
- {
- logger.debug("Completed transformation: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " options: " + options + "\n" +
- " transformer: " + this);
- }
- }
- finally
- {
- depth.set(depth.get()-1);
- }
- }
-
- private void strictMimetypeCheck(ContentReader reader, TransformationOptions options, String sourceMimetype)
- throws UnsupportedTransformationException
- {
- if (strictMimeTypeCheck && depth.get() == 1)
- {
- String differentType = getMimetypeService().getMimetypeIfNotMatches(reader.getReader());
-
- if (!transformerConfig.strictMimetypeCheck(sourceMimetype, differentType))
- {
- String fileName = ((LegacyTransformerDebug)transformerDebug).getFileName(options, true, 0);
- String readerSourceMimetype = reader.getMimetype();
- String message = "Transformation of ("+fileName+
- ") has not taken place because the declared mimetype ("+
- readerSourceMimetype+") does not match the detected mimetype ("+
- differentType+").";
- logger.warn(message);
- throw new UnsupportedTransformationException(message);
- }
- }
- }
-
- /**
- * Cancels task
and closes content accessors
- *
- * @param task - {@link Future} task instance which specifies a transformation action
- * @param proxiedReader - {@link AbstractStreamAwareProxy} instance which represents channel closing mechanism for content reader
- * @param proxiedWriter - {@link AbstractStreamAwareProxy} instance which represents channel closing mechanism for content writer
- */
- private void releaseResources(Future> task, AbstractStreamAwareProxy proxiedReader, AbstractStreamAwareProxy proxiedWriter)
- {
- if (null != task)
- {
- task.cancel(true);
- }
-
- if (null != proxiedReader)
- {
- proxiedReader.release();
- }
-
- if (null != proxiedWriter)
- {
- proxiedWriter.release();
- }
- }
-
- public final void transform(
- ContentReader reader,
- ContentWriter writer,
- Map options) throws ContentIOException
- {
- this.transform(reader, writer, new TransformationOptions(options));
- }
-
- /**
- * @return Returns the calculated running average of the current transformations
- */
- public synchronized long getTransformationTime()
- {
- return transformerConfig.getStatistics(this, null, null, true).getAverageTime();
- }
-
- /**
- * @return Returns the calculated running average of the current transformations
- */
- public synchronized long getTransformationTime(String sourceMimetype, String targetMimetype)
- {
- return transformerConfig.getStatistics(this, sourceMimetype, targetMimetype, true).getAverageTime();
- }
-
- /**
- * @deprecated use method with mimetypes.
- */
- protected final synchronized void recordTime(long transformationTime)
- {
- recordTime(TransformerConfig.ANY, TransformerConfig.ANY, transformationTime);
- }
-
- /**
- * Records and updates the average transformation time for this transformer.
- *
- * Subclasses should call this after every transformation in order to keep
- * the running average of the transformation times up to date.
- *
- * This method is thread-safe. The time spent in this method is negligible
- * so the impact will be minor.
- *
- * @param sourceMimetype String
- * @param targetMimetype String
- * @param transformationTime the time it took to perform the transformation.
- */
- protected final synchronized void recordTime(String sourceMimetype, String targetMimetype,
- long transformationTime)
- {
- transformerConfig.getStatistics(this, sourceMimetype, targetMimetype, true).recordTime(transformationTime);
- if (depth.get() == 1)
- {
- transformerConfig.getStatistics(null, sourceMimetype, targetMimetype, true).recordTime(transformationTime);
- }
- }
-
- /**
- * Gets the ExecutorService
to be used for timeout-aware extraction.
- *
- * If no ExecutorService
has been defined a default of Executors.newCachedThreadPool()
is used during {@link AbstractMappingMetadataExtracter}.
- *
- * @return the defined or default ExecutorService
- */
- protected ExecutorService getExecutorService()
- {
- if (null == executorService)
- {
- executorService = Executors.newCachedThreadPool();
- }
-
- return executorService;
- }
-
- /**
- * Sets the ExecutorService
to be used for timeout-aware transformation.
- *
- * @param executorService - {@link ExecutorService} instance for timeouts
- */
- public void setExecutorService(ExecutorService executorService)
- {
- this.executorService = executorService;
- }
-
- /**
- * {@link Callable} wrapper for the {@link AbstractContentTransformer2#transformInternal(ContentReader, ContentWriter, TransformationOptions)} method to handle timeouts.
- */
- private class TransformInternalCallable implements Callable
- {
- private ContentReader reader;
-
- private ContentWriter writer;
-
- private TransformationOptions options;
-
- public TransformInternalCallable(ContentReader reader, ContentWriter writer, TransformationOptions options)
- {
- this.reader = reader;
- this.writer = writer;
- this.options = options;
- }
-
- @Override
- public Void call() throws Exception
- {
- try
- {
- transformInternal(reader, writer, options);
- return null;
- }
- catch (Throwable e)
- {
- throw new TransformInternalCallableException(e);
- }
- }
- }
-
- /**
- * Exception wrapper to handle any {@link Throwable} from {@link AbstractContentTransformer2#transformInternal(ContentReader, ContentWriter, TransformationOptions)}
- */
- private class TransformInternalCallableException extends Exception
- {
- private static final long serialVersionUID = 7740560508772740658L;
-
- public TransformInternalCallableException(Throwable cause)
- {
- super(cause);
- }
- }
-
- /**
- * @param useTimeoutThread - {@link Boolean} value which specifies timeout limiting mechanism for the current transformer
- * @see AbstractContentTransformer2#useTimeoutThread
- */
- public void setUseTimeoutThread(Boolean useTimeoutThread)
- {
- if (null == useTimeoutThread)
- {
- useTimeoutThread = true;
- }
-
- this.useTimeoutThread = useTimeoutThread;
- }
-
- public void setAdditionalThreadTimout(long additionalThreadTimout)
- {
- this.additionalThreadTimout = additionalThreadTimout;
- }
-
- public Boolean isTransformationLimitedInternally()
- {
- return useTimeoutThread;
- }
-
- /**
- * Records an error and updates the average time as if the transformation took a
- * long time, so that it is less likely to be called again.
- * @param sourceMimetype String
- * @param targetMimetype String
- * @param transformationTime the time it took to perform the transformation.
- */
- protected final synchronized void recordError(String sourceMimetype, String targetMimetype,
- long transformationTime)
- {
- transformerConfig.getStatistics(this, sourceMimetype, targetMimetype, true).recordError(transformationTime);
- if (depth.get() == 1)
- {
- transformerConfig.getStatistics(null, sourceMimetype, targetMimetype, true).recordError(transformationTime);
- }
- }
-
- public Object getRetryTransformOnDifferentMimeType()
- {
- return retryTransformOnDifferentMimeType;
- }
-
- public void setRetryTransformOnDifferentMimeType(boolean retryTransformOnDifferentMimeType)
- {
- this.retryTransformOnDifferentMimeType = retryTransformOnDifferentMimeType;
- }
-
- public boolean getStrictMimeTypeCheck()
- {
- return strictMimeTypeCheck;
- }
-
- public void setStrictMimeTypeCheck(boolean strictMimeTypeCheck)
- {
- this.strictMimeTypeCheck = strictMimeTypeCheck;
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformerLimits.java b/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformerLimits.java
deleted file mode 100644
index e9f54bf6f5..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractContentTransformerLimits.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import static org.alfresco.service.cmr.repository.TransformationOptionLimits.OPT_MAX_PAGES;
-import static org.alfresco.service.cmr.repository.TransformationOptionLimits.OPT_MAX_SOURCE_SIZE_K_BYTES;
-import static org.alfresco.service.cmr.repository.TransformationOptionLimits.OPT_PAGE_LIMIT;
-import static org.alfresco.service.cmr.repository.TransformationOptionLimits.OPT_READ_LIMIT_K_BYTES;
-import static org.alfresco.service.cmr.repository.TransformationOptionLimits.OPT_READ_LIMIT_TIME_MS;
-import static org.alfresco.service.cmr.repository.TransformationOptionLimits.OPT_TIMEOUT_MS;
-
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.repo.content.AbstractContentReader;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptionLimits;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-
-/**
- * Provides transformation limits for {@link org.alfresco.repo.content.transform.ContentTransformer}
- * implementations.
- *
- * This class maintains the limits and provides methods that combine limits:
- * a) for the transformer as a whole
- * b) for specific combinations if source and target mimetypes
- * c) for the {@link TransformationOptions} provided for a specific transform.
- *
- * @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public abstract class AbstractContentTransformerLimits extends ContentTransformerHelper implements ContentTransformer
-{
- /** Indicates if 'page' limits are supported. */
- private boolean pageLimitsSupported;
-
- /** For debug **/
- protected TransformerDebug transformerDebug;
-
- /**
- * Indicates if 'page' limits are supported.
- * @return false by default.
- */
- protected boolean isPageLimitSupported(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return pageLimitsSupported;
- }
-
- /**
- * Indicates if 'page' limits are supported.
- */
- public void setPageLimitsSupported(boolean pageLimitsSupported)
- {
- this.pageLimitsSupported = pageLimitsSupported;
- }
-
- /**
- * Helper setter of the transformer debug.
- * @param transformerDebug TransformerDebug
- */
- public void setTransformerDebug(TransformerDebug transformerDebug)
- {
- this.transformerDebug = transformerDebug;
- }
-
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- throw new IllegalStateException("Method should no longer be called. Override isTransformableMimetype in subclass.");
- }
-
- /**
- * {@inheritDoc}
- *
- * Implementation calls the deprecated overloaded method without the sourceSize parameter
- * and then {@link #isTransformableSize(String, long, String, TransformationOptions)}.
- */
- @Override
- public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- // To make TransformerDebug output clearer, check the mimetypes and then the sizes.
- // If not done, 'unavailable' transformers due to size might be reported even
- // though they cannot transform the source to the target mimetype.
-
- return
- isSupportedTransformation(sourceMimetype, targetMimetype, options) &&
- isTransformableMimetype(sourceMimetype, targetMimetype, options) &&
- isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
- }
-
- /**
- * Indicates if this transformer is able to transform the given source mimetype
- * to the target mimetype. If overridden, consider also overriding
- * {@link ContentTransformerHelper#getComments(boolean)}.
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return isTransformable(sourceMimetype, targetMimetype, options);
- }
-
- /**
- * Indicates if this transformer is able to transform the given {@code sourceSize}.
- * The {@code maxSourceSizeKBytes} property may indicate that only small source files
- * may be transformed.
- * @param sourceSize size in bytes of the source. If negative, the source size is unknown.
- * @return {@code true} if the source is transformable.
- */
- @Override
- public boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- boolean sizeOkay = true;
- if (sourceSize >= 0)
- {
- // if maxSourceSizeKBytes == 0 this implies the transformation is disabled
- long maxSourceSizeKBytes = getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
- sizeOkay = maxSourceSizeKBytes < 0 || (maxSourceSizeKBytes > 0 && sourceSize <= maxSourceSizeKBytes*1024);
- if (!sizeOkay && transformerDebug.isEnabled())
- {
- ((LegacyTransformerDebug)transformerDebug).unavailableTransformer(this, sourceMimetype, targetMimetype, maxSourceSizeKBytes);
- }
- }
- return sizeOkay;
- }
-
- /**
- * Returns the maximum source size (in KBytes) allowed given the supplied values.
- * @return 0 if the the transformation is disabled, -1 if there is no limit, otherwise the size in KBytes.
- */
- @Override
- public long getMaxSourceSizeKBytes(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- long maxSourceSizeKBytes = -1;
-
- // The maxSourceSizeKbytes value is ignored if this transformer is able to use
- // page limits and the limits include a pageLimit. Normally used in the creation
- // of icons. Note the readLimitKBytes value is not checked as the combined limits
- // only have the max or limit KBytes value set (the smaller value is returned).
- TransformationOptionLimits limits = getLimits(sourceMimetype, targetMimetype, options);
- if (!isPageLimitSupported(sourceMimetype, targetMimetype, options) || limits.getPageLimit() <= 0)
- {
- maxSourceSizeKBytes = limits.getMaxSourceSizeKBytes();
- }
-
- return maxSourceSizeKBytes;
- }
-
- /**
- * @deprecated use {@link #getLimits(String, String, TransformationOptions) getTimeoutMs()}
- * which allows the limits to be selected based on mimetype and use.
- */
- protected long getTimeoutMs()
- {
- return getLimits().getTimeoutMs();
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setTimeoutMs(long timeoutMs)
- {
- deprecatedSetter(null, null, OPT_TIMEOUT_MS+'='+timeoutMs);
- }
-
- /**
- * @deprecated use {@link #getLimits(String, String, TransformationOptions) getReadLimitTimeMs()}
- * which allows the limits to be selected based on mimetype and use.
- */
- protected long getReadLimitTimeMs()
- {
- return getLimits().getReadLimitTimeMs();
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setReadLimitTimeMs(long readLimitTimeMs)
- {
- deprecatedSetter(null, null, OPT_READ_LIMIT_TIME_MS+'='+readLimitTimeMs);
- }
-
- /**
- * @deprecated use {@link #getLimits(String, String, TransformationOptions) getMaxSourceSizeKBytes()}
- * which allows the limits to be selected based on mimetype and use.
- */
- protected long getMaxSourceSizeKBytes()
- {
- return getLimits().getMaxSourceSizeKBytes();
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setMaxSourceSizeKBytes(long maxSourceSizeKBytes)
- {
- deprecatedSetter(null, null, OPT_MAX_SOURCE_SIZE_K_BYTES+'='+maxSourceSizeKBytes);
- }
-
- /**
- * @deprecated use {@link #getLimits(String, String, TransformationOptions) getReadLimitKBytes()}
- * which allows the limits to be selected based on mimetype and use.
- */
- protected long getReadLimitKBytes()
- {
- return getLimits().getReadLimitKBytes();
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setReadLimitKBytes(long readLimitKBytes)
- {
- deprecatedSetter(null, null, OPT_READ_LIMIT_K_BYTES+'='+readLimitKBytes);
- }
-
- /**
- * @deprecated use {@link #getLimits(String, String, TransformationOptions) getMaxPages()}
- * which allows the limits to be selected based on mimetype and use.
- */
- protected int getMaxPages()
- {
- return getLimits().getMaxPages();
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setMaxPages(int maxPages)
- {
- deprecatedSetter(null, null, OPT_MAX_PAGES+'='+maxPages);
- }
-
- /**
- * @deprecated use {@link #getLimits(String, String, TransformationOptions) getPageLimit()}
- * which allows the limits to be selected based on mimetype and use.
- */
- protected int getPageLimit()
- {
- return getLimits().getPageLimit();
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setPageLimit(int pageLimit)
- {
- deprecatedSetter(null, null, OPT_PAGE_LIMIT+'='+pageLimit);
- }
-
- /**
- * @deprecated use {@link #getLimits(String, String, TransformationOptions)} which allows the
- * limits to be selected based on mimetype and use.
- */
- protected TransformationOptionLimits getLimits()
- {
- return transformerConfig.getLimits(this, null, null, null);
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setLimits(TransformationOptionLimits limits)
- {
- deprecatedLimitsSetter(null, null, limits);
- }
-
- /**
- * @deprecated transformation limits are now set with global properties rather than spring configuration.
- */
- public void setMimetypeLimits(Map> mimetypeLimits)
- {
- for (Entry> source: mimetypeLimits.entrySet())
- {
- String sourceMimetype = source.getKey();
- for (Entry target: source.getValue().entrySet())
- {
- String targetMimetype = target.getKey();
- TransformationOptionLimits limits = target.getValue();
- deprecatedLimitsSetter(sourceMimetype, targetMimetype, limits);
- }
- }
- }
-
- private void deprecatedLimitsSetter(String sourceMimetype, String targetMimetype, TransformationOptionLimits limits)
- {
- if (limits.supported())
- {
- // Ignore limit pairs that are not specified
- for (String limit: new String[] {
- limits.getTimePair().toString(OPT_TIMEOUT_MS, OPT_READ_LIMIT_TIME_MS),
- limits.getKBytesPair().toString(OPT_MAX_SOURCE_SIZE_K_BYTES, OPT_READ_LIMIT_K_BYTES),
- limits.getPagesPair().toString(OPT_MAX_PAGES, OPT_PAGE_LIMIT)
- })
- {
- if (limit != null)
- {
- deprecatedSetter(sourceMimetype, targetMimetype, '.'+limit);
- }
- }
- }
- else
- {
- deprecatedSetter(sourceMimetype, targetMimetype, TransformerConfig.SUPPORTED+"=false");
- }
- }
-
- /**
- * Returns max and limit values for time, size and pages for a specified source and
- * target mimetypes, combined with this Transformer's general limits and optionally
- * the supplied transformation option's limits.
- */
- protected TransformationOptionLimits getLimits(ContentReader reader, ContentWriter writer,
- TransformationOptions options)
- {
- return (reader == null || writer == null)
- ? transformerConfig.getLimits(this, null, null, options.getUse()).combine(options.getLimits())
- : getLimits(reader.getMimetype(), writer.getMimetype(), options);
- }
-
- /**
- * Returns max and limit values for time, size and pages for a specified source and
- * target mimetypes, combined with this Transformer's general limits and optionally
- * the supplied transformation option's limits.
- */
- protected TransformationOptionLimits getLimits(String sourceMimetype, String targetMimetype,
- TransformationOptions options)
- {
- TransformationOptionLimits limits = transformerConfig.getLimits(this, sourceMimetype, targetMimetype, (options == null ? null : options.getUse()));
- return (options == null) ? limits : limits.combine(options.getLimits());
- }
-
- /**
- * Pass on any limits to the reader. Will only do so if the reader is an
- * {@link AbstractContentReader}.
- * @param reader passed to {@link #transform(ContentReader, ContentWriter, TransformationOptions)}.
- * @param writer passed to {@link #transform(ContentReader, ContentWriter, TransformationOptions)}.
- * @param options passed to {@link #transform(ContentReader, ContentWriter, TransformationOptions)}.
- */
- protected void setReaderLimits(ContentReader reader, ContentWriter writer,
- TransformationOptions options)
- {
- if (reader instanceof AbstractContentReader)
- {
- AbstractContentReader abstractContentReader = (AbstractContentReader)reader;
- TransformationOptionLimits limits = getLimits(reader, writer, options);
- abstractContentReader.setLimits(limits);
- abstractContentReader.setTransformerDebug(transformerDebug);
- }
- }
-}
\ No newline at end of file
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractRemoteContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/AbstractRemoteContentTransformer.java
deleted file mode 100644
index eb144c4554..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/AbstractRemoteContentTransformer.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.MimetypeService;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.Pair;
-import org.apache.commons.logging.Log;
-
-/**
- * Optionally sends transformations to a remote transformer if a {@link RemoteTransformerClient} is set and
- * the ".url" Alfresco global property is set.
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public abstract class AbstractRemoteContentTransformer extends AbstractContentTransformer2
-{
- private boolean enabled = true;
-
- private RemoteTransformerClient remoteTransformerClient;
-
- private boolean available = false;
-
- public void setEnabled(boolean enabled)
- {
- this.enabled = enabled;
- }
-
- /**
- * Sets the optional remote transformer client which will be used in preference to a local command if available.
- *
- * @param remoteTransformerClient may be null;
- */
- public void setRemoteTransformerClient(RemoteTransformerClient remoteTransformerClient)
- {
- this.remoteTransformerClient = remoteTransformerClient;
- }
-
- boolean remoteTransformerClientConfigured()
- {
- return remoteTransformerClient != null && remoteTransformerClient.getBaseUrl() != null;
- }
-
- protected abstract Log getLogger();
-
- /**
- * THIS IS A CUSTOM SPRING INIT METHOD
- */
- @Override
- public void register()
- {
- super.register();
- afterPropertiesSet();
- }
-
- public void afterPropertiesSet()
- {
- if (enabled)
- {
- // check availability
- if (remoteTransformerClientConfigured())
- {
- Log logger = getLogger();
- try
- {
- Pair result = remoteTransformerClient.check(logger);
- Boolean isAvailable = result.getFirst();
- String msg = result.getSecond() == null ? "" : result.getSecond();
- if (isAvailable != null && isAvailable)
- {
- String versionString = msg;
- setAvailable(true);
- logger.debug("Using legacy " + getName() + ": " + versionString);
- }
- else
- {
- setAvailable(false);
- String message = "Legacy " + getName() + " is not available for transformations. " + msg;
- if (isAvailable == null)
- {
- logger.debug(message);
- }
- else
- {
- logger.error(message);
- }
- }
- }
- catch (Throwable e)
- {
- setAvailable(false);
- logger.error("Remote " + getName() + " is not available: " + (e.getMessage() != null ? e.getMessage() : ""));
- // debug so that we can trace the issue if required
- logger.debug(e);
- }
- }
- else
- {
- available = true;
- }
- }
- }
-
- public boolean isAvailable()
- {
- if (remoteTransformerClientConfigured() && !remoteTransformerClient.isAvailable())
- {
- afterPropertiesSet();
- }
-
- return available;
- }
-
- protected void setAvailable(boolean available)
- {
- this.available = available;
- }
-
- @Override
- public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- if (!isAvailable())
- {
- return false;
- }
-
- return super.isTransformable(sourceMimetype, sourceSize, targetMimetype, options);
- }
-
- public void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws Exception
- {
- if (remoteTransformerClientConfigured())
- {
- String sourceMimetype = getMimetype(reader);
- String targetMimetype = writer.getMimetype();
- String targetEncoding = writer.getEncoding();
-
- MimetypeService mimetypeService = getMimetypeService();
- String sourceExtension = mimetypeService.getExtension(sourceMimetype);
- String targetExtension = mimetypeService.getExtension(targetMimetype);
- if (sourceExtension == null || targetExtension == null)
- {
- throw new AlfrescoRuntimeException("Unknown extensions for mimetypes: \n" +
- " source mimetype: " + sourceMimetype + "\n" +
- " source extension: " + sourceExtension + "\n" +
- " target mimetype: " + targetMimetype + "\n" +
- " target extension: " + targetExtension + "\n" +
- " target encoding: " + targetEncoding);
- }
-
- transformRemote(remoteTransformerClient, reader, writer, options, sourceMimetype, targetMimetype,
- sourceExtension, targetExtension, targetEncoding);
- }
- else
- {
- transformLocal(reader, writer, options);
- }
-
- Log logger = getLogger();
- if (logger.isDebugEnabled())
- {
- logger.debug("Transformation completed: \n" +
- " source: " + reader + "\n" +
- " target: " + writer + "\n" +
- " options: " + options);
- }
- }
-
- protected abstract void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws Exception;
-
- protected abstract void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options,
- String sourceMimetype, String targetMimetype,
- String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception;
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/AdminUiTransformerDebug.java b/repository/src/main/java/org/alfresco/repo/content/transform/AdminUiTransformerDebug.java
index 8e0ffe5e5f..655047b001 100644
--- a/repository/src/main/java/org/alfresco/repo/content/transform/AdminUiTransformerDebug.java
+++ b/repository/src/main/java/org/alfresco/repo/content/transform/AdminUiTransformerDebug.java
@@ -67,16 +67,16 @@ import java.util.regex.Pattern;
public class AdminUiTransformerDebug extends TransformerDebug implements ApplicationContextAware
{
protected TransformServiceRegistry remoteTransformServiceRegistry;
- protected LocalTransformServiceRegistry localTransformServiceRegistryImpl;
+ protected LocalTransformServiceRegistry localTransformServiceRegistry;
private ApplicationContext applicationContext;
private ContentService contentService;
private SynchronousTransformClient synchronousTransformClient;
private Repository repositoryHelper;
private TransactionService transactionService;
- public void setLocalTransformServiceRegistryImpl(LocalTransformServiceRegistry localTransformServiceRegistryImpl)
+ public void setLocalTransformServiceRegistry(LocalTransformServiceRegistry localTransformServiceRegistry)
{
- this.localTransformServiceRegistryImpl = localTransformServiceRegistryImpl;
+ this.localTransformServiceRegistry = localTransformServiceRegistry;
}
public void setRemoteTransformServiceRegistry(TransformServiceRegistry remoteTransformServiceRegistry)
@@ -108,7 +108,7 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
{
if (synchronousTransformClient == null)
{
- synchronousTransformClient = (SynchronousTransformClient) applicationContext.getBean("legacySynchronousTransformClient");
+ synchronousTransformClient = (SynchronousTransformClient) applicationContext.getBean("synchronousTransformClient");
}
return synchronousTransformClient;
}
@@ -150,7 +150,7 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
public void afterPropertiesSet() throws Exception
{
super.afterPropertiesSet();
- PropertyCheck.mandatory(this, "localTransformServiceRegistryImpl", localTransformServiceRegistryImpl);
+ PropertyCheck.mandatory(this, "localTransformServiceRegistry", localTransformServiceRegistry);
PropertyCheck.mandatory(this, "remoteTransformServiceRegistry", remoteTransformServiceRegistry);
}
@@ -160,12 +160,8 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
* @param sourceExtension restricts the list to one source extension. Unrestricted if null.
* @param targetExtension restricts the list to one target extension. Unrestricted if null.
* @param toString indicates that a String value should be returned in addition to any debug.
- * @param format42 ignored
- * @param onlyNonDeterministic ignored
- * @param renditionName ignored
*/
- public String transformationsByExtension(String sourceExtension, String targetExtension, boolean toString,
- boolean format42, boolean onlyNonDeterministic, String renditionName)
+ public String transformationsByExtension(String sourceExtension, String targetExtension, boolean toString)
{
// Do not generate this type of debug if already generating other debug to a StringBuilder
// (for example a test transform).
@@ -174,10 +170,10 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
return null;
}
- Collection sourceMimetypes = format42 || sourceExtension != null
+ Collection sourceMimetypes = sourceExtension != null
? getSourceMimetypes(sourceExtension)
: mimetypeService.getMimetypes();
- Collection targetMimetypes = format42 || targetExtension != null
+ Collection targetMimetypes = targetExtension != null
? getTargetMimetypes(sourceExtension, targetExtension, sourceMimetypes)
: mimetypeService.getMimetypes();
@@ -200,9 +196,9 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
? false
: remoteTransformServiceRegistry.isSupported(sourceMimetype,
-1, targetMimetype, Collections.emptyMap(), null);
- List localTransformers = localTransformServiceRegistryImpl == null
+ List localTransformers = localTransformServiceRegistry == null
? Collections.emptyList()
- : localTransformServiceRegistryImpl.findTransformers(sourceMimetype,
+ : localTransformServiceRegistry.findTransformers(sourceMimetype,
targetMimetype, Collections.emptyMap(), null);
if (!localTransformers.isEmpty() || supportedByTransformService)
{
@@ -327,9 +323,9 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
}
- public String testTransform(String sourceExtension, String targetExtension, String renditionName)
+ public String testTransform(String sourceExtension, String targetExtension)
{
- return new TestTransform().run(sourceExtension, targetExtension, renditionName);
+ return new TestTransform().run(sourceExtension, targetExtension);
}
public String[] getTestFileExtensionsAndMimetypes()
@@ -369,7 +365,7 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
{
protected LinkedList nodesToDeleteAfterTest = new LinkedList();
- String run(String sourceExtension, String targetExtension, String renditionName)
+ String run(String sourceExtension, String targetExtension)
{
RetryingTransactionHelper.RetryingTransactionCallback makeNodeCallback = new RetryingTransactionHelper.RetryingTransactionCallback()
{
@@ -403,7 +399,7 @@ public class AdminUiTransformerDebug extends TransformerDebug implements Applica
}
catch (Exception e)
{
- logger.debug("Unexpected test transform error", e);
+ sb.append(e.getMessage());
}
finally
{
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/AppleIWorksContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/AppleIWorksContentTransformer.java
deleted file mode 100644
index e68da54128..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/AppleIWorksContentTransformer.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2017 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Converts Apple iWorks files to JPEGs for thumbnailing & previewing.
- * The transformer will only work for iWorks 2013/14 files. Support for iWorks 2008/9 has been dropped as we cannot
- * support both, because the newer format does not contain a PDF. If we say this transformer supports PDF, Share will
- * assume incorrectly that we can convert to PDF and we would only get a preview for the older format and never the
- * newer one. Both formats have the same mimetype.
- *
- * @author Neil Mc Erlean
- * @since 4.0
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class AppleIWorksContentTransformer extends AbstractRemoteContentTransformer
-{
- private static final Log logger = LogFactory.getLog(AppleIWorksContentTransformer.class);
-
- // Apple's zip entry names for previews in iWorks have changed over time.
- private static final List PDF_PATHS = Arrays.asList(
- "QuickLook/Preview.pdf"); // iWorks 2008/9
- private static final List JPG_PATHS = Arrays.asList(
- "QuickLook/Thumbnail.jpg", // iWorks 2008/9
- "preview.jpg"); // iWorks 2013/14 (720 x 552) We use the best quality image. Others are:
- // (225 x 173) preview-web.jpg
- // (53 x 41) preview-micro.jpg
-
- private static final List IWORKS_MIMETYPES = Arrays.asList(MimetypeMap.MIMETYPE_IWORK_KEYNOTE,
- MimetypeMap.MIMETYPE_IWORK_NUMBERS,
- MimetypeMap.MIMETYPE_IWORK_PAGES);
- private static final List TARGET_MIMETYPES = Arrays.asList(MimetypeMap.MIMETYPE_IMAGE_JPEG
-// Commented out rather than removed, in case we can get SHARE to fall back to using JPEG when a PDF is not available
-// ,MimetypeMap.MIMETYPE_PDF
- );
-
- @Override
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- // only support [iWorks] -> JPEG but only if these are embedded in the file.
- // This is because iWorks 13+ files are zip files containing embedded jpeg previews.
- return TARGET_MIMETYPES.contains(targetMimetype) && IWORKS_MIMETYPES.contains(sourceMimetype);
- }
-
- @Override
- public String getComments(boolean available)
- {
- return getCommentsOnlySupports(IWORKS_MIMETYPES, TARGET_MIMETYPES, available);
- }
-
- @Override
- protected Log getLogger()
- {
- return logger;
- }
-
- @Override
- protected void transformLocal(ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception
- {
- final String sourceMimetype = reader.getMimetype();
- final String sourceExtension = getMimetypeService().getExtension(sourceMimetype);
- final String targetMimetype = writer.getMimetype();
- final String targetExtension = getMimetypeService().getExtension(targetMimetype);
-
- if (logger.isDebugEnabled())
- {
- StringBuilder msg = new StringBuilder();
- msg.append("Transforming from ").append(sourceMimetype)
- .append(" to ").append(targetMimetype);
- logger.debug(msg.toString());
- }
-
- ZipArchiveInputStream iWorksZip = null;
- try
- {
- // iWorks files are zip (or package) files.
- // If it's not a zip file, the resultant ZipException will be caught as an IOException below.
- iWorksZip = new ZipArchiveInputStream(reader.getContentInputStream());
-
- // Look through the zip file entries for the preview/thumbnail.
- List paths = MimetypeMap.MIMETYPE_IMAGE_JPEG.equals(targetMimetype) ? JPG_PATHS : PDF_PATHS;
- ZipArchiveEntry entry;
- boolean found = false;
- while ((entry=iWorksZip.getNextZipEntry()) != null)
- {
- String name = entry.getName();
- if (paths.contains(name))
- {
- writer.putContent( iWorksZip );
- found = true;
- break;
- }
- }
-
- if (! found)
- {
- throw new AlfrescoRuntimeException("The source " + sourceExtension + " file did not contain a " + targetExtension + " preview");
- }
- }
- catch (IOException e)
- {
- throw new AlfrescoRuntimeException("Unable to transform " + sourceExtension + " file. It should have been a zip format file.", e);
- }
- finally
- {
- if (iWorksZip != null)
- {
- iWorksZip.close();
- }
- }
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options, String sourceMimetype,
- String targetMimetype, String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- long timeoutMs = options.getTimeoutMs();
-
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "appleIWorks",
- "sourceMimetype", sourceMimetype,
- "sourceExtension", sourceExtension,
- "targetMimetype", targetMimetype);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ArchiveContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/ArchiveContentTransformer.java
deleted file mode 100644
index 0cfe65c193..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ArchiveContentTransformer.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.ArrayList;
-
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tika.config.TikaConfig;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AutoDetectParser;
-import org.apache.tika.parser.EmptyParser;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.parser.pkg.PackageParser;
-
-import static org.alfresco.repo.rendition2.RenditionDefinition2.TARGET_ENCODING;
-
-/**
- * This class transforms archive files (zip, tar etc) to text, which enables indexing
- * and searching of archives as well as webpreviewing.
- * The transformation can simply list the names of the entries within the archive, or
- * it can also include the textual content of the entries themselves.
- * The former is suggested for web preview, the latter for indexing.
- * This behaviour is controlled by the recurse flag.
- *
- * @author Neil McErlean
- * @author Nick Burch
- * @since 3.4
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class ArchiveContentTransformer extends TikaPoweredContentTransformer
-{
- /**
- * The logger
- */
- private static Log logger = LogFactory.getLog(ArchiveContentTransformer.class);
-
- private boolean includeContents = false;
- private TikaConfig tikaConfig;
-
- /**
- * We support all the archive mimetypes that the Tika
- * package parser can handle
- */
- public static ArrayList SUPPORTED_MIMETYPES;
- static {
- SUPPORTED_MIMETYPES = new ArrayList();
- Parser p = new PackageParser();
- for(MediaType mt : p.getSupportedTypes(null)) {
- // Tika can probably do some useful text
- SUPPORTED_MIMETYPES.add( mt.toString() );
- }
- }
-
- public ArchiveContentTransformer() {
- super(SUPPORTED_MIMETYPES);
- }
-
- /**
- * Injects the TikaConfig to use
- *
- * @param tikaConfig The Tika Config to use
- */
- public void setTikaConfig(TikaConfig tikaConfig)
- {
- this.tikaConfig = tikaConfig;
- }
-
- public void setIncludeContents(String includeContents)
- {
- // Spring really ought to be able to handle
- // setting a boolean that might still be
- // ${foo} (i.e. not overridden in a property).
- // As we can't do that with spring, we do it...
- this.includeContents = false;
- if(includeContents != null && includeContents.length() > 0)
- {
- this.includeContents = TransformationOptions.relaxedBooleanTypeConverter.convert(includeContents).booleanValue();
- }
- }
-
- @Override
- protected Parser getParser() {
- return new PackageParser();
- }
-
- @Override
- protected ParseContext buildParseContext(Metadata metadata,
- String targetMimeType, TransformationOptions options) {
- ParseContext context = super.buildParseContext(metadata, targetMimeType, options);
-
- boolean recurse = includeContents;
- if(options.getIncludeEmbedded() != null)
- {
- recurse = options.getIncludeEmbedded();
- }
-
- if(recurse)
- {
- // Use an auto detect parser to handle the contents
- if(tikaConfig == null)
- {
- tikaConfig = TikaConfig.getDefaultConfig();
- }
- context.set(Parser.class, new AutoDetectParser(tikaConfig));
- }
- else
- {
- // REPO-1066: an AutoDetectParser is the default in Tika after: https://issues.apache.org/jira/browse/TIKA-2096
- // so we need to specify an empty one if we don't want the recurse parsing to happen
- context.set(Parser.class, new EmptyParser());
- }
- return context;
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options,
- String sourceMimetype, String targetMimetype,
- String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- long timeoutMs = options.getTimeoutMs();
- boolean recurse = includeContents;
- if(options.getIncludeEmbedded() != null)
- {
- recurse = options.getIncludeEmbedded();
- }
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "Archive",
- "includeContents", Boolean.toString(recurse),
- "sourceMimetype", sourceMimetype,
- "sourceExtension", sourceExtension,
- "targetMimetype", targetMimetype,
- TARGET_ENCODING, targetEncoding);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/BinaryPassThroughContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/BinaryPassThroughContentTransformer.java
deleted file mode 100644
index bb33bcb7da..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/BinaryPassThroughContentTransformer.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Allows direct streaming from source to target when the respective mimetypes
- * are identical, except where the mimetype is text.
- *
- * Text has to be transformed based on the encoding even if the mimetypes don't
- * reflect it.
- *
- * @see org.alfresco.repo.content.transform.StringExtractingContentTransformer
- *
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class BinaryPassThroughContentTransformer extends AbstractContentTransformer2
-{
- @SuppressWarnings("unused")
- private static final Log logger = LogFactory.getLog(BinaryPassThroughContentTransformer.class);
-
- @Override
- protected void transformInternal(ContentReader reader,
- ContentWriter writer, TransformationOptions options)
- throws Exception
- {
- // just stream it
- writer.putContent(reader.getContentInputStream());
-
- }
-
- @Override
- public boolean isTransformableMimetype(String sourceMimetype,
- String targetMimetype, TransformationOptions options)
- {
- if (sourceMimetype.startsWith(StringExtractingContentTransformer.PREFIX_TEXT))
- {
- // we can only stream binary content through
- return false;
- }
- else if (!sourceMimetype.equals(targetMimetype))
- {
- // no transformation is possible so formats must be exact
- return false;
- }
- else
- {
- if (options == null || TransformationOptions.class.equals(options.getClass()) == true)
- {
- // formats are the same and are not text
- return true;
- }
- else
- {
- // If it has meaningful options then we assume there is another transformer better equiped
- // to deal with it
- return false;
- }
- }
- }
-
- @Override
- public String getComments(boolean available)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(super.getComments(available));
- sb.append("# Only supports streaming to the same type but excludes txt\n");
- return sb.toString();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ComplexContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/ComplexContentTransformer.java
deleted file mode 100644
index 189e8eb03c..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ComplexContentTransformer.java
+++ /dev/null
@@ -1,549 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.beans.PropertyDescriptor;
-import java.io.File;
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayDeque;
-import java.util.Collections;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.filestore.FileContentWriter;
-import org.alfresco.repo.rendition2.LegacySynchronousTransformClient;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.TransformationOptionLimits;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
-import org.alfresco.util.TempFileProvider;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.InitializingBean;
-
-/**
- * Transformer that passes a document through several nested transformations
- * in order to accomplish its goal.
- *
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public class ComplexContentTransformer extends AbstractContentTransformer2 implements InitializingBean
-{
- /**
- * The logger
- */
- private static Log logger = LogFactory.getLog(ComplexContentTransformer.class);
-
- /**
- * Complex transformers contain lower level transformers. In order to find dynamic
- * (defined as null) child transformers to use, they recursively check available
- * transformers. It makes no sense to have a transformer that is its own child.
- */
- static final ThreadLocal> parentTransformers = new ThreadLocal>() {
- @Override
- protected Deque initialValue() {
- return new ArrayDeque();
- }
- };
-
- private List transformers;
- private List intermediateMimetypes;
- private Map transformationOptionOverrides;
- private LegacySynchronousTransformClient legacySynchronousTransformClient;
-
- public ComplexContentTransformer()
- {
- }
-
- /**
- * The list of transformers to use. If any element is null
- * all possible transformers will be considered. If any element
- * is null, the legacySynchronousTransformClient property must be set.
- *
- * If a single transformer is supplied, then it will still be used.
- *
- * @param transformers list of at least one transformer
- */
- public void setTransformers(List transformers)
- {
- this.transformers = transformers;
- }
-
- /**
- * Set the intermediate mimetypes that the transformer must take the content
- * through. If the transformation A..B..C is performed in order to
- * simulate A..C, then B is the intermediate mimetype. There
- * must always be n-1 intermediate mimetypes, where n is the
- * number of {@link #setTransformers(List) transformers} taking part in the
- * transformation.
- *
- * @param intermediateMimetypes intermediate mimetypes to transition the content
- * through.
- */
- public void setIntermediateMimetypes(List intermediateMimetypes)
- {
- this.intermediateMimetypes = intermediateMimetypes;
- }
-
- /**
- * Sets any properties to be set on the TransformationOption as passed in.
- * This allows you to force certain properties to always be set on it,
- * to control the transformers in a different way to their default.
- * Note that only properties that are supported by the passed-in
- * {@link TransformationOptions} are changed, others are ignored.
- */
- public void setTransformationOptionOverrides(
- Map transformationOptionOverrides)
- {
- this.transformationOptionOverrides = transformationOptionOverrides;
- }
-
- public void setLegacySynchronousTransformClient(LegacySynchronousTransformClient legacySynchronousTransformClient)
- {
- this.legacySynchronousTransformClient = legacySynchronousTransformClient;
- }
-
- /**
- * Ensures that required properties have been set
- */
- public void afterPropertiesSet() throws Exception
- {
- if (transformers == null || transformers.size() == 0)
- {
- throw new AlfrescoRuntimeException("At least one inner transformer must be supplied: " + this);
- }
- if (intermediateMimetypes == null || intermediateMimetypes.size() != transformers.size() - 1)
- {
- throw new AlfrescoRuntimeException(
- "There must be n-1 intermediate mimetypes, where n is the number of transformers");
- }
- if (getMimetypeService() == null)
- {
- throw new AlfrescoRuntimeException("'mimetypeService' is a required property");
- }
- for (ContentTransformer transformer: transformers)
- {
- if (transformer == null)
- {
- if (legacySynchronousTransformClient == null)
- {
- throw new AlfrescoRuntimeException("'legacySynchronousTransformClient' is a required property if " +
- "there are any null (dynamic) transformers");
- }
- break;
- }
- }
- }
-
- @Override
- public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype,
- TransformationOptions options)
- {
- if (!isSupportedTransformation(sourceMimetype, targetMimetype, options))
- {
- return false;
- }
-
- // Don't allow transformer to be its own child.
- if (parentTransformers.get().contains(this))
- {
- return false;
- }
-
- overrideTransformationOptions(options);
-
- // Can use super isTransformableSize as it indirectly calls getLimits in this class
- // which combines the limits from the first transformer. Other transformer in the chain
- // are no checked as sizes are unknown.
- return
- isTransformableMimetype(sourceMimetype, targetMimetype, options) &&
- isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
- }
-
- /**
- * Sets any transformation option overrides it can.
- */
- private void overrideTransformationOptions(TransformationOptions options)
- {
- // Set any transformation options overrides if we can
- if(options != null && transformationOptionOverrides != null)
- {
- for(String key : transformationOptionOverrides.keySet())
- {
- if(PropertyUtils.isWriteable(options, key))
- {
- try
- {
- PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(options, key);
- Class> propertyClass = pd.getPropertyType();
-
- Object value = transformationOptionOverrides.get(key);
- if(value != null)
- {
- if(propertyClass.isInstance(value))
- {
- // Nothing to do
- }
- else if(value instanceof String && propertyClass.isInstance(Boolean.TRUE))
- {
- // Use relaxed converter
- value = TransformationOptions.relaxedBooleanTypeConverter.convert((String)value);
- }
- else
- {
- value = DefaultTypeConverter.INSTANCE.convert(propertyClass, value);
- }
- }
- PropertyUtils.setProperty(options, key, value);
- }
- catch(NoSuchMethodException nsme) {}
- catch(InvocationTargetException ite) {}
- catch(IllegalAccessException iae) {}
- }
- else
- {
- logger.warn("Unable to set override Transformation Option " + key + " on " + options);
- }
- }
- }
- }
-
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- boolean result = true;
- String currentSourceMimetype = sourceMimetype;
- Iterator transformerIterator = transformers.iterator();
-
- // When using a wild card (null) intermediate transformer, don't
- // say we support a transformation that one of the none null intermediate
- // transformers can do on its own, to avoid double transformations.
- // Not done when there are no wild card transformers, as there are cases
- // where it makes sense to go via an intermediate format (quality/speed).
- while (transformerIterator.hasNext())
- {
- ContentTransformer transformer = transformerIterator.next();
- if (transformer == null)
- {
- transformerIterator = transformers.iterator();
- while (transformerIterator.hasNext())
- {
- transformer = transformerIterator.next();
- if (transformer != null)
- {
- if (transformer.isTransformable(sourceMimetype, -1, targetMimetype, options))
- {
- return false;
- }
- }
- }
- break;
- }
- }
-
- transformerIterator = transformers.iterator();
- Iterator intermediateMimetypeIterator = intermediateMimetypes.iterator();
- while (transformerIterator.hasNext())
- {
- ContentTransformer transformer = transformerIterator.next();
-
- // determine the target mimetype. This is the final target if we are on the last transformation
- String currentTargetMimetype = transformerIterator.hasNext() ? intermediateMimetypeIterator.next() : targetMimetype;
- if (transformer == null)
- {
- try
- {
- parentTransformers.get().push(this);
- @SuppressWarnings("deprecation")
- List firstTansformers = legacySynchronousTransformClient.getActiveTransformers(
- currentSourceMimetype, -1, currentTargetMimetype, options);
- if (firstTansformers.isEmpty())
- {
- result = false;
- break;
- }
- }
- finally
- {
- parentTransformers.get().pop();
- }
- }
- else
- {
- if (transformer.isTransformable(currentSourceMimetype, -1, currentTargetMimetype, options) == false)
- {
- result = false;
- break;
- }
- }
-
- // move on
- currentSourceMimetype = currentTargetMimetype;
- }
-
- return result;
- }
-
- /**
- * Indicates if 'page' limits are supported by the first transformer in the chain.
- * If the first transformer is dynamic, all possible first transformers must support it.
- * @return true if the first transformer supports them.
- */
- @Override
- protected boolean isPageLimitSupported(String sourceMimetype, String targetMimetype,
- TransformationOptions options)
- {
- boolean pageLimitSupported;
- ContentTransformer firstTransformer = transformers.get(0);
- String firstTargetMimetype = intermediateMimetypes.get(0);
- if (firstTransformer == null)
- {
- try
- {
- parentTransformers.get().push(this);
- @SuppressWarnings("deprecation")
- List firstTansformers = legacySynchronousTransformClient.getActiveTransformers(
- sourceMimetype, -1, firstTargetMimetype, options);
- pageLimitSupported = !firstTansformers.isEmpty();
- if (pageLimitSupported)
- {
- for (ContentTransformer transformer: firstTansformers)
- {
- if (!isPageLimitSupported(transformer, sourceMimetype, targetMimetype, options))
- {
- pageLimitSupported = false;
- break;
- }
- }
- }
- }
- finally
- {
- parentTransformers.get().pop();
- }
- }
- else
- {
- pageLimitSupported = isPageLimitSupported(firstTransformer, sourceMimetype, targetMimetype, options);
- }
- return pageLimitSupported;
- }
-
- private boolean isPageLimitSupported(ContentTransformer transformer, String sourceMimetype,
- String targetMimetype, TransformationOptions options)
- {
- return (transformer instanceof AbstractContentTransformerLimits)
- ? ((AbstractContentTransformerLimits)transformer).isPageLimitSupported(sourceMimetype, targetMimetype, options)
- : false;
- }
-
- /**
- * Returns the limits from this transformer combined with those of the first transformer in the chain.
- * If the first transformer is dynamic, the lowest common denominator between all possible first transformers
- * are combined.
- */
- protected TransformationOptionLimits getLimits(String sourceMimetype, String targetMimetype,
- TransformationOptions options)
- {
- TransformationOptionLimits firstTransformerLimits = null;
- TransformationOptionLimits limits = super.getLimits(sourceMimetype, targetMimetype, options);
- ContentTransformer firstTransformer = transformers.get(0);
- String firstTargetMimetype = intermediateMimetypes.get(0);
- if (firstTransformer == null)
- {
- try
- {
- parentTransformers.get().push(this);
- @SuppressWarnings("deprecation")
- List firstTansformers = legacySynchronousTransformClient.getActiveTransformers(
- sourceMimetype, -1, firstTargetMimetype, options);
- if (!firstTansformers.isEmpty())
- {
- for (ContentTransformer transformer: firstTansformers)
- {
- if (transformer instanceof AbstractContentTransformerLimits)
- {
- TransformationOptionLimits transformerLimits = ((AbstractContentTransformerLimits)transformer).
- getLimits(sourceMimetype, firstTargetMimetype, options);
- firstTransformerLimits = (firstTransformerLimits == null)
- ? transformerLimits
- : firstTransformerLimits.combineUpper(transformerLimits);
- }
- }
- }
- }
- finally
- {
- parentTransformers.get().pop();
- }
- }
- else
- {
- if (firstTransformer instanceof AbstractContentTransformerLimits)
- {
- firstTransformerLimits = ((AbstractContentTransformerLimits)firstTransformer).
- getLimits(sourceMimetype, firstTargetMimetype, options);
- }
- }
-
- if (firstTransformerLimits != null)
- {
- limits = limits.combine(firstTransformerLimits);
- }
-
- return limits;
- }
-
- /**
- * @see org.alfresco.repo.content.transform.AbstractContentTransformer2#transformInternal(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- @Override
- public void transformInternal(
- ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception
- {
- NodeRef origSourceNodeRef = options.getSourceNodeRef();
- try
- {
- ContentReader currentReader = reader;
-
- Iterator transformerIterator = transformers.iterator();
- Iterator intermediateMimetypeIterator = intermediateMimetypes.iterator();
- while (transformerIterator.hasNext())
- {
- ContentTransformer transformer = transformerIterator.next();
- // determine the target mimetype. This is the final target if we are on the last transformation
- ContentWriter currentWriter = null;
- if (!transformerIterator.hasNext())
- {
- currentWriter = writer;
- }
- else
- {
- String nextMimetype = intermediateMimetypeIterator.next();
- // make a temp file writer with the correct extension
- String sourceExt = getMimetypeService().getExtension(currentReader.getMimetype());
- String targetExt = getMimetypeService().getExtension(nextMimetype);
- File tempFile = TempFileProvider.createTempFile(
- "ComplextTransformer_intermediate_" + sourceExt + "_",
- "." + targetExt);
- currentWriter = new FileContentWriter(tempFile);
- currentWriter.setMimetype(nextMimetype);
- }
-
- // transform
- if (transformer == null)
- {
- try
- {
- parentTransformers.get().push(this);
- legacySynchronousTransformClient.transform(currentReader, currentWriter, options);
- }
- finally
- {
- parentTransformers.get().pop();
- }
- }
- else
- {
- transformer.transform(currentReader, currentWriter, options);
- }
-
- // Must clear the sourceNodeRef after the first transformation to avoid later
- // transformers thinking the intermediate file is the original node. However as
- // we put the original sourceNodeRef back at the end of this try block (so that we are
- // not changing any data), we must setting the value to null just after the
- // transformation. Really only needs to be done after the first transformation
- // but doing it every time is simpler and faster.
- options.setSourceNodeRef(null);
-
- // move the source on
- currentReader = currentWriter.getReader();
- }
- // done
- }
- finally
- {
- options.setSourceNodeRef(origSourceNodeRef);
- }
- }
-
- public List getIntermediateMimetypes()
- {
- return Collections.unmodifiableList(intermediateMimetypes);
- }
-
- public List getIntermediateTransformers()
- {
- return Collections.unmodifiableList(transformers);
- }
-
- /**
- * Returns the transformer properties predefined (hard coded or implied) by this transformer.
- */
- @Override
- public String getComments(boolean available)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(super.getComments(available));
- sb.append("# ");
- sb.append(TransformerConfig.CONTENT);
- sb.append(getName());
- sb.append(TransformerConfig.PIPELINE);
- sb.append('=');
- Iterator iterator = intermediateMimetypes.iterator();
- for (ContentTransformer transformer: transformers)
- {
- sb.append(transformer != null ? getSimpleName(transformer) : TransformerConfig.ANY);
- if (iterator.hasNext())
- {
- sb.append(TransformerConfig.PIPE);
- String mimetype = iterator.next();
- if (mimetype != null && mimetype.length() != 0)
- {
- String extension = getMimetypeService().getExtension(mimetype);
- sb.append(extension);
- }
- sb.append(TransformerConfig.PIPE);
- }
- }
- sb.append('\n');
- return sb.toString();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformer.java
deleted file mode 100644
index ab9fc731b3..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformer.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.List;
-import java.util.Map;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.repo.content.ContentWorker;
-import org.alfresco.service.cmr.repository.ContentIOException;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-
-/**
- * Interface for class that allow content transformation from one mimetype to another.
- *
- * @author Derek Hulley
- *
- * @deprecated The RenditionService is being replace by the simpler async RenditionService2.
- */
-@Deprecated
-@AlfrescoPublicApi
-public interface ContentTransformer extends ContentWorker
-{
- /**
- * @deprecated use version with extra sourceSize parameter.
- */
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options);
-
- /**
- * Indicates whether the provided source mimetype can be transformed into the target mimetype with
- * the options specified by this content transformer.
- *
- * @param sourceMimetype the source mimetype
- * @param sourceSize the size (bytes) of the source. If negative it is unknown.
- * @param targetMimetype the target mimetype
- * @param options the transformation options
- * @return boolean true if this content transformer can satify the mimetypes and options specified, false otherwise
- */
- public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options);
-
- /**
- * Sub component of {@link #isTransformable(String, long, String, TransformationOptions)}
- * that checks just the mimetypes.
- * @param sourceMimetype the source mimetype
- * @param targetMimetype the target mimetype
- * @param options the transformation options
- * @return boolean true if this content transformer can satify the mimetypes, false otherwise
- */
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options);
-
- /**
- * Sub component of {@link #isTransformable(String, long, String, TransformationOptions)}
- * that checks just the size limits.
- * @param sourceMimetype the source mimetype
- * @param sourceSize the size (bytes) of the source. If negative it is unknown.
- * @param targetMimetype the target mimetype
- * @param options the transformation options
- * @return boolean true if this content transformer can satify the mimetypes, false otherwise
- */
- public boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options);
-
- /**
- * Overridden to supply a comment or String of commented out transformation properties
- * that specify any (hard coded or implied) supported transformations. Used
- * when providing a list of properties to an administrators who may be setting
- * other transformation properties, via JMX. Consider overriding if
- * {link {@link AbstractContentTransformerLimits#isTransformableMimetype(String, String, TransformationOptions)}
- * or {@link ContentTransformerWorker#isTransformable(String, String, TransformationOptions)}
- * have been overridden.
- * @param available indicates if the transformer has been registered and is available to be selected.
- * {@code false} indicates that the transformer is only available as a component of a
- * complex transformer.
- * @return one line per property. The simple transformer name is returned by default as a comment.
- */
- public String getComments(boolean available);
-
- /**
- * Returns the maximum source size (in KBytes) allowed given the supplied values.
- * @return 0 if the the transformation is disabled, -1 if there is no limit, otherwise the size in KBytes.
- */
- public long getMaxSourceSizeKBytes(String sourceMimetype, String targetMimetype, TransformationOptions options);
-
- /**
- * @deprecated Use transformer priority and unsupported transformer properties.
- *
- * Indicates whether given the provided transformation parameters this transformer can provide an explicit
- * transformation.
- *
- * An explicit transformation indicates that the transformation happens directly and not as a result of
- * another transformation process. Explicit transformation always take presidency over normal transformations.
- *
- * @param sourceMimetype the source mimetype
- * @param targetMimetype the target mimetype
- * @param options the transformation options
- * @return boolean true if it is an explicit transformation, false otherwise
- */
- public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options);
-
- /**
- * @deprecated use mimetype specific version.
- */
- public long getTransformationTime();
-
- /**
- * Provides an estimate, usually a worst case guess, of how long a transformation
- * will take. Null mimetype values provide the overall value for the transformer.
- *
- * This method is used to determine, up front, which of a set of
- * equally reliant transformers will be used for a specific transformation.
- *
- * @param sourceMimetype the source mimetype
- * @param targetMimetype the target mimetype
- *
- * @return Returns the approximate number of milliseconds per transformation
- */
- public long getTransformationTime(String sourceMimetype, String targetMimetype);
-
- /**
- * @see #transform(ContentReader, ContentWriter, TransformationOptions)
- *
- * @deprecated
- * Deprecated use {link {@link #transform(ContentReader, ContentWriter, TransformationOptions)}.
- */
- public void transform(ContentReader reader, ContentWriter writer) throws ContentIOException;
-
- /**
- * Transforms the content provided by the reader and source mimetype
- * to the writer and target mimetype.
- *
- * The source and target mimetypes must be available on the
- * {@link org.alfresco.service.cmr.repository.ContentAccessor#getMimetype()} methods of
- * both the reader and the writer.
- *
- * Both reader and writer will be closed after the transformation completes.
- *
- * @param reader the source of the content
- * @param writer the destination of the transformed content
- * @param options options to pass to the transformer. These are transformer dependent
- * and may be null.
- * @throws ContentIOException if an IO exception occurs
- *
- * @deprecated
- * Deprecated since 3.0. Options should now be provided as a TransformationOptions object.
- */
- @Deprecated
- public void transform(
- ContentReader reader,
- ContentWriter writer,
- Map options) throws ContentIOException;
-
- /**
- * Transforms the content provided by the reader and source mimetype
- * to the writer and target mimetype with the provided transformation options.
- *
- * The transformation viability can be determined by an up front call
- * to {@link #isTransformable(String, String, TransformationOptions)}.
- *
- * The source and target mimetypes must be available on the
- * {@link org.alfresco.service.cmr.repository.ContentAccessor#getMimetype()} methods of
- * both the reader and the writer.
- *
- * Both reader and writer will be closed after the transformation completes.
- *
- * The provided options can be null.
- *
- * @param reader the source of the content
- * @param contentWriter the destination of the transformed content
- * @param options transformation options, these can be null
- * @throws ContentIOException if an IO exception occurs
- */
- public void transform(ContentReader reader, ContentWriter contentWriter, TransformationOptions options)
- throws ContentIOException;
-
- /**
- * Returns transformer's name used in configuration.
- */
- public String getName();
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerHelper.java b/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerHelper.java
deleted file mode 100644
index e667d1018e..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerHelper.java
+++ /dev/null
@@ -1,454 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import static org.alfresco.repo.content.transform.TransformerConfig.ANY;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.service.cmr.repository.ContentAccessor;
-import org.alfresco.service.cmr.repository.MimetypeService;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.BeanNameAware;
-
-/**
- * A class providing basic functionality shared by both {@link ContentTransformer}s and {@link ContentTransformerWorker}s.
- *
- * @author dward
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public class ContentTransformerHelper implements BeanNameAware
-{
- private static final Log logger = LogFactory.getLog(ContentTransformerHelper.class);
-
- private MimetypeService mimetypeService;
- protected TransformerConfig transformerConfig;
-
- List deprecatedSetterMessages;
- private static boolean firstDeprecatedSetter = true;
-
- /** The bean name. */
- private String beanName;
-
- /**
- * Helper setter of the mimetype service. This is not always required.
- *
- * @param mimetypeService MimetypeService
- */
- public void setMimetypeService(MimetypeService mimetypeService)
- {
- this.mimetypeService = mimetypeService;
- }
-
- /**
- * @return Returns the mimetype helper
- */
- protected MimetypeService getMimetypeService()
- {
- return mimetypeService;
- }
-
- /**
- * @deprecated supported transformations are now set with global properties rather than spring configuration.
- */
- public void setExplicitTransformations(List explicitTransformations)
- {
- deprecatedSupportedTransformations(explicitTransformations, null);
- }
-
- /**
- * @deprecated supported transformations are now set with global properties rather than spring configuration.
- */
- public void setSupportedTransformations(List supportedTransformations)
- {
- deprecatedSupportedTransformations(supportedTransformations, "true");
- }
-
- /**
- * @deprecated supported transformations are now set with global properties rather than spring configuration.
- */
- public void setUnsupportedTransformations(List unsupportedTransformations)
- {
- deprecatedSupportedTransformations(unsupportedTransformations, "false");
- }
-
- public void setTransformerConfig(TransformerConfig transformerConfig)
- {
- this.transformerConfig = transformerConfig;
- }
-
- /**
- * Convenience to fetch and check the mimetype for the given content
- *
- * @param content
- * the reader/writer for the content
- * @return Returns the mimetype for the content
- * @throws AlfrescoRuntimeException
- * if the content doesn't have a mimetype
- */
- protected String getMimetype(ContentAccessor content)
- {
- String mimetype = content.getMimetype();
- if (mimetype == null)
- {
- throw new AlfrescoRuntimeException("Mimetype is mandatory for transformation: " + content);
- }
- // done
- return mimetype;
- }
-
- /**
- * @deprecated Should now use priority and unsupported transformer properties.
- *
- * @see org.alfresco.repo.content.transform.ContentTransformer#isExplicitTransformation(java.lang.String,
- * java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return transformerConfig.getPriority(((ContentTransformer)this), sourceMimetype, targetMimetype) == TransformerConfig.PRIORITY_EXPLICIT;
- }
-
- public boolean isSupportedTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return transformerConfig.isSupportedTransformation(((ContentTransformer)this), sourceMimetype, targetMimetype, options);
- }
-
- /**
- * Sets the Spring bean name.
- */
- @Override
- public void setBeanName(String beanName)
- {
- this.beanName = beanName;
- }
-
- /**
- * THIS IS A CUSTOM SPRING INIT METHOD
- */
- public void register()
- {
- logDeprecatedSetter(deprecatedSetterMessages);
- }
-
- /**
- * Returns the Spring bean name.
- */
- public String getBeanName()
- {
- return beanName;
- }
-
- /**
- * Returns transformer name. Uses the Spring bean name, but if null uses the class name.
- */
- public String getName()
- {
- return (beanName == null) ? getClass().getSimpleName() : beanName;
- }
-
- /**
- * Returns the simple form of the transformer name, which has had the normal
- * "transformer." prefix to the Spring bean name removed.
- */
- public static String getSimpleName(ContentTransformer transformer)
- {
- String transformerName = transformer.getName();
- return transformerName.startsWith(TransformerConfig.TRANSFORMER)
- ? transformerName.substring(TransformerConfig.TRANSFORMER.length())
- : transformerName;
- }
-
- /**
- * Called by deprecated property setter methods that should no longer be called
- * by Spring configuration as the values are now set using global properties.
- * @param sourceMimetype so that the source extension can be worked out once the mimetypeService
- * has been set.
- * @param targetMimetype so that the target extension can be worked out once the mimetypeService
- * has been set.
- * @param suffixAndValue that should be used.
- */
- protected void deprecatedSetter(String sourceMimetype, String targetMimetype, String suffixAndValue)
- {
- if (deprecatedSetterMessages == null)
- {
- deprecatedSetterMessages = new ArrayList();
- }
- deprecatedSetterMessages.add(new DeprecatedSetter(sourceMimetype, targetMimetype, suffixAndValue));
- }
-
- /**
- * Called when the bean name is set after all the deprecated setters to log
- * INFO messages with the Alfresco global properties that should now be set
- * (if not set) to replace Spring configuration.
- */
- void logDeprecatedSetter(List deprecatedSetterMessages)
- {
- if (deprecatedSetterMessages != null)
- {
- StringBuilder sb = new StringBuilder();
- for (DeprecatedSetter deprecatedSetter: deprecatedSetterMessages)
- {
- String propertyNameAndValue = deprecatedSetter.getPropertyNameAndValue(beanName);
- String propertyName = propertyNameAndValue.replaceAll("=.*", "");
- if (transformerConfig.getProperty(propertyName) == null)
- {
- if (firstDeprecatedSetter)
- {
- firstDeprecatedSetter = false;
- logger.error("In order to support dynamic setting of transformer options, Spring XML configuration");
- logger.error("is no longer used to initialise these options.");
- logger.error(" ");
- logger.error("Your system appears to contains custom Spring configuration which should be replace by");
- logger.error("the following Alfresco global properties. In the case of the Enterprise edition these");
- logger.error("values may then be dynamically changed via JMX.");
- logger.error(" ");
- // Note: Cannot set these automatically because, an MBean reset would clear them.
- }
- logger.error(propertyNameAndValue);
-
- sb.append(propertyNameAndValue);
- sb.append('\n');
- }
- else
- {
- logger.warn(propertyNameAndValue+" is set, but spring config still exists");
- }
- }
- deprecatedSetterMessages = null;
- if (sb.length() > 0)
- {
- // Add subsystem's properties anyway (even though an MBean reset would clear them),
- // so that existing unit tests work.
- transformerConfig.setProperties(sb.toString());
- }
- }
- }
-
- private void deprecatedSupportedTransformations(List extends SupportedTransformation> transformations, String value)
- {
- if (transformations != null)
- {
- for (SupportedTransformation transformation: transformations)
- {
- String sourceMimetype = transformation.getSourceMimetype();
- String targetMimetype = transformation.getTargetMimetype();
-
- if (value == null)
- {
- deprecatedSetter(sourceMimetype, targetMimetype, TransformerConfig.PRIORITY+"="+TransformerConfig.PRIORITY_EXPLICIT);
- deprecatedSetter(sourceMimetype, targetMimetype, TransformerConfig.SUPPORTED+"=true");
- }
- else
- {
- deprecatedSetter(sourceMimetype, targetMimetype, TransformerConfig.SUPPORTED+"="+value);
- }
- }
- }
- }
-
- protected String getExtensionOrAny(String mimetype)
- {
- return mimetype == null || ANY.equals(mimetype) ? ANY : mimetypeService.getExtension(mimetype);
- }
-
- public String toString()
- {
- return getName();
- }
-
- /**
- * Overridden to supply a comment or String of commented out transformation properties
- * that specify any (hard coded or implied) supported transformations. Used
- * when providing a list of properties to an administrators who may be setting
- * other transformation properties, via JMX. Consider overriding if
- * {link {@link AbstractContentTransformerLimits#isTransformableMimetype(String, String, TransformationOptions)}
- * or {@link ContentTransformerWorker#isTransformable(String, String, TransformationOptions)}
- * have been overridden.
- * See {@link #getCommentsOnlySupports(List, List, boolean)} which may be used to help construct a comment.
- * @param available indicates if the transformer has been registered and is available to be selected.
- * {@code false} indicates that the transformer is only available as a component of a
- * complex transformer.
- * @return one line per property. The simple transformer name is returned by default as a comment.
- */
- public String getComments(boolean available)
- {
- return getCommentNameAndAvailable(available);
- }
-
- /**
- * Helper method for {@link #getComments(boolean)} to
- * create a line that indicates which source and target mimetypes
- * it supports.
- * @param available TODO
- * @return a String of the form "# only supports xxx, yyy or zzz to aaa or bb\n".
- */
- protected String getCommentsOnlySupports(List sourceMimetypes, List targetMimetypes, boolean available)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(getCommentNameAndAvailable(available));
- sb.append("# Only supports ");
- sb.append(getExtensions(sourceMimetypes));
- sb.append(" to ");
- sb.append(getExtensions(targetMimetypes));
- sb.append("\n");
- return sb.toString();
- }
-
- /**
- * Returns the transformer's simple name and an indication if the transformer is not
- * available for selection.
- */
- String getCommentNameAndAvailable(boolean available)
- {
- String name = this instanceof ContentTransformer ? getSimpleName((ContentTransformer)this) : getName();
- StringBuilder sb = new StringBuilder();
- sb.append(getCommentName(name));
- if (!available)
- {
- sb.append("# ");
- sb.append(TransformerConfig.CONTENT);
- sb.append(getName());
- sb.append(TransformerConfig.AVAILABLE);
- sb.append("=false\n");
- }
- return sb.toString();
- }
-
- static String getCommentName(String name)
- {
- StringBuilder sb = new StringBuilder();
- sb.append("# ");
- sb.append(name);
- sb.append('\n');
- sb.append("# ");
- for (int i = name.length(); i > 0; i--)
- {
- sb.append('-');
- }
- sb.append('\n');
- return sb.toString();
- }
-
- /**
- * Helper method for {@link #getComments(boolean)} to
- * create a line that indicates which source and target mimetypes
- * it supports.
- * @param sourceMimetype String
- * @param targetMimetype String
- * @param available TODO
- * @return a String of the form "# only supports xxx to aaa\n".
- */
- protected String onlySupports(String sourceMimetype, String targetMimetype, boolean available)
- {
- return getCommentsOnlySupports(
- Arrays.asList(new String[] {sourceMimetype}),
- Arrays.asList(new String[] {targetMimetype}), available);
- }
-
- /**
- * Returns a comma separated String of mimetype file extensions.
- */
- private String getExtensions(List origMimetypes)
- {
- // Only use the mimetypes we have registered
- List mimetypes = new ArrayList(origMimetypes);
- mimetypes.retainAll(getMimetypeService().getMimetypes());
-
- StringBuilder sb = new StringBuilder();
- int j = mimetypes.size();
- int i=1;
- for (String mimetype: mimetypes)
- {
- sb.append(getMimetypeService().getExtension(mimetype));
- if (i < j)
- {
- sb.append(++i < j ? ", " : " or ");
- }
- }
- return sb.toString();
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((beanName == null) ? 0 : beanName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ContentTransformerHelper other = (ContentTransformerHelper) obj;
- if (beanName == null)
- {
- if (other.beanName != null)
- return false;
- }
- else if (!beanName.equals(other.beanName))
- return false;
- return true;
- }
-
- private class DeprecatedSetter
- {
- private final String sourceMimetype;
- private final String targetMimetype;
- private final String suffixAndValue;
-
- DeprecatedSetter(String sourceMimetype, String targetMimetype, String suffixAndValue)
- {
- this.sourceMimetype = sourceMimetype;
- this.targetMimetype = targetMimetype;
- this.suffixAndValue = suffixAndValue;
- }
-
- public String getPropertyNameAndValue(String beanName)
- {
- return TransformerConfig.CONTENT+beanName+
- (sourceMimetype != null
- ? TransformerConfig.EXTENSIONS+getExtensionOrAny(sourceMimetype)+'.'+getExtensionOrAny(targetMimetype)
- : ".")+
- suffixAndValue;
- }
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerRegistry.java b/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerRegistry.java
deleted file mode 100644
index aa8e3036a8..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerRegistry.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Holds and provides the most appropriate content transformer for
- * a particular source and target mimetype transformation request.
- *
- * The transformers themselves are used to determine the applicability
- * of a particular transformation.
- *
- * The actual selection of a transformer is done by the injected
- * {@link TransformerSelector}.
- *
- * @see org.alfresco.repo.content.transform.ContentTransformer
- *
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public class ContentTransformerRegistry
-{
- private static final Log logger = LogFactory.getLog(ContentTransformerRegistry.class);
-
- private final List transformers;
- private final List allTransformers;
-
- private final TransformerSelector transformerSelector;
- private boolean enabled = true;
- private boolean firstTime = true;
- private TransformerDebug transformerDebug;
-
- /**
- * @param transformerSelector Transformer selector
- */
- public ContentTransformerRegistry(TransformerSelector transformerSelector)
- {
- this.transformerSelector = transformerSelector;
- this.transformers = new ArrayList(70);
- this.allTransformers = new ArrayList(70);
- }
-
- public void setEnabled(boolean enabled)
- {
- this.enabled = enabled;
- firstTime = true;
- }
-
- public void setTransformerDebug(TransformerDebug transformerDebug)
- {
- this.transformerDebug = transformerDebug;
- }
-
- /**
- * Registers an individual transformer that can be queried to check for applicability.
- *
- * @param transformer a content transformer
- */
- public synchronized void addTransformer(ContentTransformer transformer)
- {
- transformers.add(transformer);
- allTransformers.add(transformer);
- // done
- if (logger.isDebugEnabled())
- {
- logger.debug("Registered general transformer: \n" +
- " transformer: " + transformer.getName() + " (" + transformer + ")");
- }
- }
-
- /**
- * Records a transformer that can NOT be queried for applicability, but may be
- * included as a component of complex transformers.
- * @param transformer a content transformer
- */
- public synchronized void addComponentTransformer(ContentTransformer transformer)
- {
- allTransformers.add(transformer);
- }
-
- /**
- * Removes a dynamically created transformer.
- * @param transformer to be removed.
- */
- public synchronized void removeTransformer(ContentTransformer transformer)
- {
- transformers.remove(transformer);
- allTransformers.remove(transformer);
- }
-
- /**
- * @return a list of transformers that may be queried to check for applicability.
- */
- public synchronized List getTransformers()
- {
- return Collections.unmodifiableList(transformers);
- }
-
- /**
- * @return a list of all transformers, including those that only exist as a
- * component of another transformer.
- */
- public synchronized List getAllTransformers()
- {
- return Collections.unmodifiableList(allTransformers);
- }
-
- /**
- * Returns a transformer identified by name.
- * @throws IllegalArgumentException if transformerName is not found.
- */
- public synchronized ContentTransformer getTransformer(String transformerName)
- {
- if (transformerName != null)
- {
- for (ContentTransformer transformer: allTransformers)
- {
- if (transformerName.equals(transformer.getName()))
- {
- return transformer;
- }
- }
- throw new IllegalArgumentException("Unknown transformer: "+
- (transformerName.startsWith(TransformerConfig.TRANSFORMER)
- ? transformerName.substring(TransformerConfig.TRANSFORMER.length())
- : transformerName));
- }
- return null;
- }
-
- /**
- * @deprecated use overloaded version with sourceSize parameter.
- */
- public ContentTransformer getTransformer(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return getTransformer(sourceMimetype, -1, targetMimetype, options);
- }
-
- /**
- * Gets the best transformer possible. This is a combination of the most reliable
- * and the most performant transformer.
- */
- public ContentTransformer getTransformer(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- // Get the sorted list of transformers
- List transformers = getActiveTransformers(sourceMimetype, sourceSize, targetMimetype, options);
-
- // select the most performant transformer
- ContentTransformer bestTransformer = null;
- if(transformers.size() > 0)
- {
- bestTransformer = transformers.get(0);
- }
- // done
- return bestTransformer;
- }
-
- /**
- * @since 3.5
- */
- public List getActiveTransformers(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- if (firstTime)
- {
- firstTime = false;
- transformerDebug.debug("Legacy transforms are " + (enabled ? "enabled" : "disabled"));
- }
-
- // Get the list of transformers
- List transformers;
- if (enabled)
- {
- transformers = transformerSelector.selectTransformers(sourceMimetype, sourceSize, targetMimetype, options);
-
- }
- else
- {
- transformers = Collections.EMPTY_LIST;
- }
- if (logger.isDebugEnabled())
- {
- logger.debug("Searched for transformer: \n" +
- " source mimetype: " + sourceMimetype + "\n" +
- " target mimetype: " + targetMimetype + "\n" +
- " transformers: " + transformers);
- }
- return transformers;
- }
-
- /**
- * Recursive method to build up a list of content transformers
- */
- @SuppressWarnings("unused")
- private void buildTransformer(List transformers,
- double reliability,
- List touchedMimetypes,
- String currentMimetype,
- String targetMimetype)
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * A key for a combination of a source and target mimetype
- *
- * Deprecated since 3.0
- */
- @Deprecated
- public static class TransformationKey
- {
- private final String sourceMimetype;
- private final String targetMimetype;
- private final String key;
-
- public TransformationKey(String sourceMimetype, String targetMimetype)
- {
- this.key = (sourceMimetype + "_" + targetMimetype);
- this.sourceMimetype = sourceMimetype;
- this.targetMimetype = targetMimetype;
- }
-
- public String getSourceMimetype()
- {
- return sourceMimetype;
- }
- public String getTargetMimetype()
- {
- return targetMimetype;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null)
- {
- return false;
- }
- else if (this == obj)
- {
- return true;
- }
- else if (!(obj instanceof TransformationKey))
- {
- return false;
- }
- TransformationKey that = (TransformationKey) obj;
- return this.key.equals(that.key);
- }
- @Override
- public int hashCode()
- {
- return key.hashCode();
- }
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerWorker.java b/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerWorker.java
deleted file mode 100644
index fe4c50e743..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ContentTransformerWorker.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-
-/**
- * An interface that allows separation between the content transformer registry and the various third party subsystems
- * performing the transformation.
- *
- * @author dward
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-// TODO Modify ContentTransformerWorker to understand transformer limits. At the moment no workers use them
-@Deprecated
-@AlfrescoPublicApi
-public interface ContentTransformerWorker
-{
- /**
- * Checks if this worker is available.
- *
- * @return true if it is available
- */
- public boolean isAvailable();
-
- /**
- * Gets a string returning product and version information.
- *
- * @return the version string
- */
- public String getVersionString();
-
- /**
- * Unlike {@link ContentTransformer#isTransformable(String, String, TransformationOptions)}
- * should not include the transformer name, as that is added by the ContentTransformer in
- * the parent context.
- */
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options);
-
- /**
- * @see ContentTransformer#getComments(boolean)
- */
- public String getComments(boolean available);
-
- /**
- * @see ContentTransformer#transform(ContentReader, ContentWriter, TransformationOptions)
- */
- public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception;
-
- /**
- * @return true if ther worker is using a remote server.
- */
- public default boolean remoteTransformerClientConfigured()
- {
- return false;
- }
-
- public default void setRemoteTransformerClient(RemoteTransformerClient remoteTransformerClient)
- {
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/DoubleMap.java b/repository/src/main/java/org/alfresco/repo/content/transform/DoubleMap.java
deleted file mode 100644
index 397d38bdbf..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/DoubleMap.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Provides simple get and put access to a Map like object with a double key that allows
- * either or both keys to be a wild card that matches any value. May not contain null
- * keys or values.
- *
- * Originally created for mapping source and target mimetypes to transformer configuration data.
- *
- * For example:
- *
- * DoubleMap foodLikes = new DoubleMap("*", "*");
- *
- * foodLikes.put("cat", "mouse", "likes");
- *
- * foodLikes.get("cat", "mouse"); // returns "likes"
- * foodLikes.get("cat", "meat"); // returns null
- *
- * foodLikes.put("dog", "meat", "likes");
- * foodLikes.put("dog", "stick", "unsure");
- * foodLikes.put("child", "olive", "dislikes");
- * foodLikes.put("bird", "*", "worms only");
- * foodLikes.put("*", "meat", "unknown");
- * foodLikes.put("*", "*", "no idea at all");
- *
- * foodLikes.get("cat", "mouse"); // returns "likes"
- * foodLikes.get("cat", "meat"); // returns "unknown"
- * foodLikes.get("cat", "tea"); // returns "unknown"
- * foodLikes.get("*", "mouse"); // returns "no idea at all"
- * foodLikes.get("dog", "*"); // returns "no idea at all"
- * foodLikes.get("bird","*"); // returns "worms only"
- * foodLikes.get("bird","tea"); // returns "worms only"
- *
- *
- * @author Alan Davis
- *
- */
-@Deprecated
-public class DoubleMap
-{
- private final Map> mapMap = new ConcurrentHashMap>();
- private final K1 anyKey1;
- private final K2 anyKey2;
-
- public DoubleMap(K1 anyKey1, K2 anyKey2)
- {
- this.anyKey1 = anyKey1;
- this.anyKey2 = anyKey2;
- }
-
- /**
- * Returns a value for the given keys.
- */
- public V get(K1 key1, K2 key2)
- {
- V value = null;
-
- Map map = mapMap.get(key1);
- boolean anySource = false;
- if (map == null)
- {
- map = mapMap.get(anyKey1);
- anySource = true;
- }
- if (map != null)
- {
- value = map.get(key2);
- if (value == null)
- {
- value = map.get(anyKey2);
-
- // Handle the case were there is no match using an non wildcarded key1 and
- // key2 but is a match if key1 is wildcarded.
- if (value == null && !anySource)
- {
- map = mapMap.get(anyKey1);
- if (map != null)
- {
- value = map.get(key2);
- if (value == null)
- {
- value = map.get(anyKey2);
- }
- }
- }
- }
- }
-
- return value;
- }
-
- /**
- * Returns a value for the given keys without using wildcards.
- */
- public V getNoWildcards(K1 key1, K2 key2)
- {
- V value = null;
-
- Map map = mapMap.get(key1);
- if (map != null)
- {
- value = map.get(key2);
- }
-
- return value;
- }
-
- /**
- * Adds a value for the given keys.
- */
- public void put(K1 key1, K2 key2, V t)
- {
- Map map = mapMap.get(key1);
- if (map == null)
- {
- map = new ConcurrentHashMap();
- mapMap.put(key1, map);
- }
-
- map.put(key2, t);
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- for (Entry> outerEntry: mapMap.entrySet())
- {
- for (Entry innerEntry: outerEntry.getValue().entrySet())
- {
- if (sb.length() > 0)
- {
- sb.append("\n");
- }
- sb.append(outerEntry.getKey()).
- append(", ").
- append(innerEntry.getKey()).
- append(" = ").
- append(innerEntry.getValue());
- }
- }
- return sb.toString();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/EMLTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/EMLTransformer.java
deleted file mode 100644
index 115ca646fc..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/EMLTransformer.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2020 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.repo.content.filestore.FileContentWriter;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.TempFileProvider;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.mail.MessagingException;
-import javax.mail.Multipart;
-import javax.mail.Part;
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import static org.alfresco.repo.rendition2.RenditionDefinition2.TARGET_ENCODING;
-
-
-/**
- * Uses javax.mail.MimeMessage to generate plain text versions of RFC822 email
- * messages. Searches for all text content parts, and returns them. Any
- * attachments are ignored. TIKA Note - could be replaced with the Tika email
- * parser. Would require a recursing parser to be specified, but not the full
- * Auto one (we don't want attachments), just one containing text and html
- * related parsers.
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class EMLTransformer extends AbstractRemoteContentTransformer
-{
- private static final Log logger = LogFactory.getLog(EMLTransformer.class);
- private static final String CHARSET = "charset";
- private static final String DEFAULT_ENCODING = "UTF-8";
-
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if (!MimetypeMap.MIMETYPE_RFC822.equals(sourceMimetype)
- || !MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(targetMimetype))
- {
- // only support RFC822 -> TEXT
- return false;
- }
- else
- {
- return true;
- }
- }
-
- @Override
- public String getComments(boolean available)
- {
- return onlySupports(MimetypeMap.MIMETYPE_RFC822, MimetypeMap.MIMETYPE_TEXT_PLAIN, available);
- }
-
- @Override
- protected Log getLogger()
- {
- return logger;
- }
-
- @Override
- protected void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception
- {
- InputStream contentInputStream = null;
- try{
- contentInputStream = reader.getContentInputStream();
- MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()), contentInputStream);
-
- final StringBuilder sb = new StringBuilder();
- Object content = mimeMessage.getContent();
- if (content instanceof Multipart)
- {
- processMultiPart((Multipart) content,sb);
- }
- else
- {
- sb.append(content.toString());
- }
- writer.putContent(sb.toString());
- }
- finally
- {
- if (contentInputStream != null)
- {
- try
- {
- contentInputStream.close();
- }
- catch ( IOException e)
- {
- //stop exception propagation
- }
- }
- }
- }
-
- /**
- * Find "text" parts of message recursively and appends it to sb StringBuilder
- *
- * @param multipart Multipart to process
- * @param sb StringBuilder
- * @throws MessagingException
- * @throws IOException
- */
- private void processMultiPart(Multipart multipart, StringBuilder sb) throws MessagingException, IOException
- {
- boolean isAlternativeMultipart = multipart.getContentType().contains(MimetypeMap.MIMETYPE_MULTIPART_ALTERNATIVE);
- if (isAlternativeMultipart)
- {
- processAlternativeMultipart(multipart, sb);
- }
- else
- {
- for (int i = 0, n = multipart.getCount(); i < n; i++)
- {
- Part part = multipart.getBodyPart(i);
- if (part.getContent() instanceof Multipart)
- {
- processMultiPart((Multipart) part.getContent(), sb);
- }
- else
- {
- processPart(part, sb);
- }
- }
- }
- }
-
-
- /**
- * Finds the suitable part from an multipart/alternative and appends it's text content to StringBuilder sb
- *
- * @param multipart
- * @param sb
- * @throws IOException
- * @throws MessagingException
- */
- private void processAlternativeMultipart(Multipart multipart, StringBuilder sb) throws IOException, MessagingException
- {
- Part partToUse = null;
- for (int i = 0, n = multipart.getCount(); i < n; i++)
- {
- Part part = multipart.getBodyPart(i);
- if (part.getContentType().contains(MimetypeMap.MIMETYPE_TEXT_PLAIN))
- {
- partToUse = part;
- break;
- }
- else if (part.getContentType().contains(MimetypeMap.MIMETYPE_HTML))
- {
- partToUse = part;
- }
- else if (part.getContentType().contains(MimetypeMap.MIMETYPE_MULTIPART_ALTERNATIVE))
- {
- if (part.getContent() instanceof Multipart)
- {
- processAlternativeMultipart((Multipart) part.getContent(), sb);
- }
- }
- }
- if (partToUse != null)
- {
- processPart(partToUse, sb);
- }
- }
-
- /**
- * Finds text on a given mail part. Accepted parts types are text/html and text/plain.
- * Attachments are ignored
- *
- * @param part
- * @param sb
- * @throws IOException
- * @throws MessagingException
- */
- private void processPart(Part part, StringBuilder sb) throws IOException, MessagingException
- {
- boolean isAttachment = Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition());
- if (isAttachment)
- {
- return;
- }
- if (part.getContentType().contains(MimetypeMap.MIMETYPE_TEXT_PLAIN))
- {
- sb.append(part.getContent().toString());
- }
- else if (part.getContentType().contains(MimetypeMap.MIMETYPE_HTML))
- {
- String mailPartContent = part.getContent().toString();
-
- //create a temporary html file with same mail part content and encoding
- File tempHtmlFile = TempFileProvider.createTempFile("EMLTransformer_", ".html");
- ContentWriter contentWriter = new FileContentWriter(tempHtmlFile);
- contentWriter.setEncoding(getMailPartContentEncoding(part));
- contentWriter.setMimetype(MimetypeMap.MIMETYPE_HTML);
- contentWriter.putContent(mailPartContent);
-
- //transform html file's content to plain text
- EncodingAwareStringBean extractor = new EncodingAwareStringBean();
- extractor.setCollapse(false);
- extractor.setLinks(false);
- extractor.setReplaceNonBreakingSpaces(false);
- extractor.setURL(tempHtmlFile, contentWriter.getEncoding());
- sb.append(extractor.getStrings());
-
- tempHtmlFile.delete();
- }
- }
-
- private String getMailPartContentEncoding(Part part) throws MessagingException
- {
- String encoding = DEFAULT_ENCODING;
- String contentType = part.getContentType();
- int startIndex = contentType.indexOf(CHARSET);
- if (startIndex > 0)
- {
- encoding = contentType.substring(startIndex + CHARSET.length() + 1).replaceAll("\"", "");
- }
- return encoding;
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options,
- String sourceMimetype, String targetMimetype,
- String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- long timeoutMs = options.getTimeoutMs();
-
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "rfc822",
- "sourceMimetype", sourceMimetype,
- "targetMimetype", targetMimetype,
- "targetExtension", targetExtension);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/EncodingAwareStringBean.java b/repository/src/main/java/org/alfresco/repo/content/transform/EncodingAwareStringBean.java
deleted file mode 100644
index a203d71ec3..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/EncodingAwareStringBean.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.File;
-import java.net.URLConnection;
-
-import org.htmlparser.Parser;
-import org.htmlparser.beans.StringBean;
-import org.htmlparser.util.ParserException;
-
-/**
- * A version of {@link StringBean} which allows control of the
- * encoding in the underlying HTML Parser.
- * Unfortunately, StringBean doesn't allow easy over-riding of
- * this, so we have to duplicate some code to control this.
- * This allows us to correctly handle HTML files where the encoding
- * is specified against the content property (rather than in the
- * HTML Head Meta), see ALF-10466 for details.
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-class EncodingAwareStringBean extends StringBean
-{
- private static final long serialVersionUID = -9033414360428669553L;
-
- /**
- * Sets the File to extract strings from, and the encoding
- * it's in (if known to Alfresco)
- *
- * @param file The File that text should be fetched from.
- * @param encoding The encoding of the input
- */
- public void setURL(File file, String encoding)
- {
- String previousURL = getURL();
- String newURL = file.getAbsolutePath();
-
- if ( (previousURL == null) || (!newURL.equals(previousURL)) )
- {
- try
- {
- URLConnection conn = getConnection();
-
- if (null == mParser)
- {
- mParser = new Parser(newURL);
- }
- else
- {
- mParser.setURL(newURL);
- }
-
- if (encoding != null)
- {
- mParser.setEncoding(encoding);
- }
-
- mPropertySupport.firePropertyChange(PROP_URL_PROPERTY, previousURL, getURL());
- mPropertySupport.firePropertyChange(PROP_CONNECTION_PROPERTY, conn, mParser.getConnection());
- setStrings();
- }
- catch (ParserException pe)
- {
- updateStrings(pe.toString());
- }
- }
- }
-
- public String getEncoding(){
- return mParser.getEncoding();
- }
-}
\ No newline at end of file
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ExplictTransformationDetails.java b/repository/src/main/java/org/alfresco/repo/content/transform/ExplictTransformationDetails.java
deleted file mode 100644
index dcad7d7a88..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ExplictTransformationDetails.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-/**
- * Specifies transformations that are considered to be 'exceptional' so
- * should be used in preference to other transformers that can perform
- * the same transformation.
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class ExplictTransformationDetails extends SupportedTransformation
-{
- public ExplictTransformationDetails()
- {
- super();
- }
-
- public ExplictTransformationDetails(String sourceMimetype, String targetMimetype)
- {
- super(sourceMimetype, targetMimetype);
- }
-}
\ No newline at end of file
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/FailoverContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/FailoverContentTransformer.java
deleted file mode 100644
index 1b2e96906c..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/FailoverContentTransformer.java
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.File;
-import java.util.List;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.filestore.FileContentWriter;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.TempFileProvider;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.InitializingBean;
-
-/**
- * This class is a transformer which contains a fixed sequence of delegate transformers.
- * Requests to transform a document will be passed to the first transformer in the sequence.
- * If that transformer successfully transforms the document then the process is complete. However
- * should it fail, the transformation will be passed on to the next transformer in the sequence and
- * so on.
- * Transformers are considered to have failed of they throw an exception.
- *
- * @author Neil McErlean
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public class FailoverContentTransformer extends AbstractContentTransformer2 implements InitializingBean
-{
- private static Log logger = LogFactory.getLog(FailoverContentTransformer.class);
- private List transformers;
-
- public FailoverContentTransformer()
- {
- // Intentionally empty
- }
-
- /**
- * The list of transformers to use. There must be at least one, but for failover behaviour to work
- * there should be at least two.
- *
- * @param transformers list of transformers.
- */
- public void setTransformers(List transformers)
- {
- this.transformers = transformers;
- }
-
- /**
- * Ensures that required properties have been set
- */
- public void afterPropertiesSet() throws Exception
- {
- if (transformers == null || transformers.size() == 0)
- {
- throw new AlfrescoRuntimeException("At least one inner transformer must be supplied: " + this);
- }
- if (getMimetypeService() == null)
- {
- throw new AlfrescoRuntimeException("'mimetypeService' is a required property");
- }
- }
-
- /**
- * Overrides super class method to avoid calling
- * {@link #isTransformableMimetype(String, String, TransformationOptions)}
- * twice on each transformer in the list, as
- * {@link #isTransformableSize(String, long, String, TransformationOptions)}
- * in this class must check the mimetype too.
- */
- @Override
- public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- return
- isSupportedTransformation(sourceMimetype, targetMimetype, options) &&
- // isTransformableSize must check the mimetype anyway
- (((sourceSize >= 0) && isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options)) ||
- ((sourceSize < 0) && isTransformableMimetype(sourceMimetype,targetMimetype, options)));
- }
-
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return isTransformableMimetypeAndSize(sourceMimetype, -1, targetMimetype, options);
- }
-
- @Override
- public boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- return (sourceSize < 0) ||
- super.isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options) &&
- isTransformableMimetypeAndSize(sourceMimetype, sourceSize, targetMimetype, options);
- }
-
- private boolean isTransformableMimetypeAndSize(String sourceMimetype, long sourceSize,
- String targetMimetype, TransformationOptions options)
- {
- boolean result = false;
- for (ContentTransformer ct : this.transformers)
- {
- if (ct.isTransformableMimetype(sourceMimetype, targetMimetype, options))
- {
- if (sourceSize < 0)
- {
- result = true;
- break;
- }
- else
- {
- try
- {
- ((LegacyTransformerDebug)transformerDebug).pushIsTransformableSize(this);
- if (ct.isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options))
- {
- result = true;
- break;
- }
- }
- finally
- {
- ((LegacyTransformerDebug)transformerDebug).popIsTransformableSize();
- }
- }
- }
- }
- return result;
- }
-
- @SuppressWarnings("deprecation")
- public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- boolean result = true;
- for (ContentTransformer ct : this.transformers)
- {
- if (ct.isExplicitTransformation(sourceMimetype, targetMimetype, options) == false)
- {
- result = false;
- }
- }
- return result;
- }
-
-
- /**
- * @see org.alfresco.repo.content.transform.AbstractContentTransformer2#transformInternal(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- @Override
- public void transformInternal(
- ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception
- {
- final String outputMimetype = writer.getMimetype();
- final String outputFileExt = getMimetypeService().getExtension(outputMimetype);
-
- // We need to keep a reference to thrown exceptions as we're going to catch them and
- // then move on to the next transformer. In the event that they all fail, we will throw
- // the final exception.
- Exception transformationException = null;
-
- for (int i = 0; i < transformers.size(); i++)
- {
- int oneBasedCount = i + 1;
- ContentTransformer transf = transformers.get(i);
- ContentWriter currentWriter = null;
- File tempFile = null;
- try
- {
- if (logger.isDebugEnabled())
- {
- logger.debug("Transformation attempt " + oneBasedCount + " of " + transformers.size() + ": " + transf);
- }
-
- if (!transf.isTransformable(reader.getMimetype(), reader.getSize(), outputMimetype, options))
- {
- throw new UnsupportedTransformationException("Unsupported transformation: " +reader.getMimetype()+" to "+outputMimetype);
- }
-
- // We can't know in advance which transformer in the sequence will work - if any.
- // Therefore we can't write into the ContentWriter stream.
- // So make a temporary file writer with the current transformer name.
- tempFile = TempFileProvider.createTempFile(
- "FailoverTransformer_intermediate_" + transf.getClass().getSimpleName() + "_",
- "." + outputFileExt);
- currentWriter = new FileContentWriter(tempFile);
- currentWriter.setMimetype(outputMimetype);
- currentWriter.setEncoding(writer.getEncoding());
-
- // attempt to transform
- transf.transform(reader, currentWriter, options);
-
- // TODO Could add a check for zero-length output and treat that as a failure
- // final long writtenSize = currentWriter.getSize();
- }
- catch (Exception are)
- {
- if (transformationException == null)
- {
- transformationException = are;
- }
-
- if (logger.isDebugEnabled())
- {
- logger.debug("Transformation " + oneBasedCount + " was unsuccessful.");
- if (i != transformers.size() - 1)
- {
- // We don't log the last exception as we're going to throw it.
- logger.debug("The below exception is provided for information purposes only.", are);
- }
- }
-
- // Set a new reader to refresh the input stream.
- reader = reader.getReader();
- // and move to the next transformer
- continue;
- }
- // No need to close input or output streams
-
- // At this point the current transformation was successful i.e. it did not throw an exception.
-
- // Now we must copy the content from the temporary file into the ContentWriter stream.
- if (tempFile != null)
- {
- writer.putContent(tempFile);
- }
-
- if (logger.isInfoEnabled())
- {
- logger.info("Transformation was successful");
- }
- return;
- }
- // At this point we have tried all transformers in the sequence without apparent success.
- if (transformationException != null)
- {
- transformerDebug.debug(" No more transformations to failover to");
- if (logger.isDebugEnabled())
- {
- logger.debug("All transformations were unsuccessful. Throwing first exception.", transformationException);
- }
- throw transformationException;
- }
- }
-
- /**
- * Returns the transformer properties predefined (hard coded or implied) by this transformer.
- */
- @Override
- public String getComments(boolean available)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(super.getComments(available));
- sb.append("# ");
- sb.append(TransformerConfig.CONTENT);
- sb.append(getName());
- sb.append(TransformerConfig.FAILOVER);
- sb.append('=');
- boolean first = true;
- for (ContentTransformer transformer: transformers)
- {
- if (!first)
- {
- sb.append(TransformerConfig.PIPE);
- }
- first = false;
- sb.append(transformer != null ? getSimpleName(transformer) : TransformerConfig.ANY);
- }
- sb.append('\n');
- return sb.toString();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/HtmlParserContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/HtmlParserContentTransformer.java
deleted file mode 100644
index 0ed160af62..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/HtmlParserContentTransformer.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.File;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.TempFileProvider;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
-
-
-/**
- * Content transformer which wraps the HTML Parser library for
- * parsing HTML content.
- *
- *
- * Since HTML Parser was updated from v1.6 to v2.1, META tags
- * defining an encoding for the content via http-equiv=Content-Type
- * will ONLY be respected if the encoding of the content item
- * itself is set to ISO-8859-1.
- *
- *
- *
- * Tika Note - could be converted to use the Tika HTML parser,
- * but we'd potentially need a custom text handler to replicate
- * the current settings around links and non-breaking spaces.
- *
- *
- * @see http://htmlparser.sourceforge.net
- * @see org.htmlparser.beans.StringBean
- * @see HTML Parser
- *
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class HtmlParserContentTransformer extends AbstractRemoteContentTransformer
-{
- @SuppressWarnings("unused")
- private static final Log logger = LogFactory.getLog(HtmlParserContentTransformer.class);
-
- /**
- * Only support HTML to TEXT.
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if (!MimetypeMap.MIMETYPE_HTML.equals(sourceMimetype) ||
- !MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(targetMimetype))
- {
- // only support HTML -> TEXT
- return false;
- }
- else
- {
- return true;
- }
- }
-
- @Override
- public String getComments(boolean available)
- {
- return onlySupports(MimetypeMap.MIMETYPE_HTML, MimetypeMap.MIMETYPE_TEXT_PLAIN, available);
- }
-
- @Override
- protected Log getLogger()
- {
- return logger;
- }
-
- @Override
- public void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws Exception
- {
-
- // We can only work from a file
- File htmlFile = TempFileProvider.createTempFile("HtmlParserContentTransformer_", ".html");
- reader.getContent(htmlFile);
-
- // Fetch the encoding of the HTML, as set in the ContentReader
- // This will default to 'UTF-8' if not specifically set
- String encoding = reader.getEncoding();
-
- // Create the extractor
- EncodingAwareStringBean extractor = new EncodingAwareStringBean();
- extractor.setCollapse(false);
- extractor.setLinks(false);
- extractor.setReplaceNonBreakingSpaces(false);
- extractor.setURL(htmlFile, encoding);
- // get the text
- String text = extractor.getStrings();
- // write it to the writer
- writer.putContent(text);
-
- // Tidy up
- htmlFile.delete();
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options, String sourceMimetype,
- String targetMimetype, String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- String sourceEncoding = reader.getEncoding();
- long timeoutMs = options.getTimeoutMs();
-
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "html",
- "sourceMimetype", sourceMimetype,
- "sourceExtension", sourceExtension,
- "targetMimetype", targetMimetype,
- SOURCE_ENCODING, sourceEncoding);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/JodContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/JodContentTransformer.java
deleted file mode 100644
index cc4ed52e77..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/JodContentTransformer.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2017 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.repo.content.JodConverter;
-import org.alfresco.util.Pair;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.artofsolving.jodconverter.OfficeDocumentConverter;
-import org.artofsolving.jodconverter.document.DocumentFormat;
-import org.springframework.beans.factory.InitializingBean;
-
-import java.io.File;
-
-/**
- * Makes use of the {@link http://code.google.com/p/jodconverter/} library and an installed
- * OpenOffice application to perform OpenOffice-driven conversions.
- *
- * @author Neil McErlean
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class JodContentTransformer extends OOoContentTransformerHelper implements ContentTransformerWorker, InitializingBean
-{
- private static Log logger = LogFactory.getLog(JodContentTransformer.class);
-
- private boolean enabled = true;
-
- private JodConverter jodconverter;
-
- public void setEnabled(boolean enabled)
- {
- this.enabled = enabled;
- }
-
- public void setJodConverter(JodConverter jodc)
- {
- this.jodconverter = jodc;
- }
-
- @Override
- protected Log getLogger()
- {
- return logger;
- }
-
- @Override
- protected String getTempFilePrefix()
- {
- return "JodContentTransformer";
- }
-
- @Override
- public boolean isAvailable()
- {
- if (remoteTransformerClientConfigured() && !remoteTransformerClient.isAvailable())
- {
- afterPropertiesSet();
- }
-
- return remoteTransformerClientConfigured()
- ? remoteTransformerClient.isAvailable()
- : jodconverter.isAvailable();
- }
-
- @Override
- public void afterPropertiesSet()
- {
- if (enabled)
- {
- super.afterPropertiesSet();
- if (remoteTransformerClientConfigured())
- {
- Pair result = remoteTransformerClient.check(logger);
- Boolean isAvailable = result.getFirst();
- if (isAvailable != null && isAvailable)
- {
- String versionString = result.getSecond().trim();
- logger.debug("Using legacy JodCoverter: " + versionString);
- }
- else
- {
- String message = "Legacy JodConverter is not available for transformations. " + result.getSecond();
- if (isAvailable == null)
- {
- logger.debug(message);
- }
- else
- {
- logger.error(message);
- }
- }
- }
- }
- }
-
- @Override
- protected void convert(File tempFromFile, DocumentFormat sourceFormat, File tempToFile,
- DocumentFormat targetFormat)
- {
- OfficeDocumentConverter converter = new OfficeDocumentConverter(jodconverter.getOfficeManager());
- converter.convert(tempFromFile, tempToFile);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/LegacyTransformerDebug.java b/repository/src/main/java/org/alfresco/repo/content/transform/LegacyTransformerDebug.java
deleted file mode 100644
index 7831333627..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/LegacyTransformerDebug.java
+++ /dev/null
@@ -1,647 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2019 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.repo.content.metadata.AsynchronousExtractor;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.transform.client.registry.SupportedTransform;
-import org.alfresco.util.PropertyCheck;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Deque;
-import java.util.List;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-/**
- * Debugs Legacy transformers selection and activity. Will be removed when Legacy transforms are removed.
- *
- * @author Alan Davis
- */
-@Deprecated
-public class LegacyTransformerDebug extends AdminUiTransformerDebug
-{
- private ContentTransformerRegistry transformerRegistry;
- private TransformerConfig transformerConfig;
-
- public void setTransformerRegistry(ContentTransformerRegistry transformerRegistry)
- {
- this.transformerRegistry = transformerRegistry;
- }
-
- public void setTransformerConfig(TransformerConfig transformerConfig)
- {
- this.transformerConfig = transformerConfig;
- }
-
- @Override
- public void afterPropertiesSet() throws Exception
- {
- super.afterPropertiesSet();
- PropertyCheck.mandatory(this, "transformerRegistry", transformerRegistry);
- PropertyCheck.mandatory(this, "transformerConfig", transformerConfig);
- }
-
- @Deprecated
- public void pushAvailable(String fromUrl, String sourceMimetype, String targetMimetype,
- TransformationOptions options)
- {
- String renditionName = options == null ? null : options.getUse();
- NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
- pushAvailable(fromUrl, sourceMimetype, targetMimetype, renditionName, sourceNodeRef);
- }
-
- /**
- * Called prior to working out what transformers are available.
- */
- @Deprecated
- public void pushAvailable(String fromUrl, String sourceMimetype, String targetMimetype,
- String renditionName, NodeRef sourceNodeRef)
- {
- if (isEnabled())
- {
- push(null, fromUrl, sourceMimetype, targetMimetype, -1,
- null, renditionName, sourceNodeRef, Call.AVAILABLE);
- }
- }
-
- /**
- * Called when a transformer has been ignored because of a blacklist entry.
- */
- @Deprecated
- public void blacklistTransform(ContentTransformer transformer, String sourceMimetype,
- String targetMimetype, TransformationOptions options)
- {
- log("Blacklist "+getName(transformer)+" "+ getSourceAndTargetExt(sourceMimetype, targetMimetype));
- }
-
- @Deprecated
- public void pushTransform(ContentTransformer transformer, String fromUrl, String sourceMimetype,
- String targetMimetype, long sourceSize, TransformationOptions options)
- {
- String renditionName = options == null ? null : options.getUse();
- NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
- pushTransform(transformer, fromUrl, sourceMimetype, targetMimetype, sourceSize, renditionName, sourceNodeRef);
- }
-
- /**
- * Called prior to performing a transform.
- */
- @Deprecated
- public void pushTransform(ContentTransformer transformer, String fromUrl, String sourceMimetype,
- String targetMimetype, long sourceSize, String renditionName, NodeRef sourceNodeRef)
- {
- if (isEnabled())
- {
- push(getName(transformer), fromUrl, sourceMimetype, targetMimetype, sourceSize,
- null, renditionName, sourceNodeRef, Call.TRANSFORM);
- }
- }
-
- /**
- * Called prior to calling a nested isTransformable.
- */
- @Deprecated
- public void pushIsTransformableSize(ContentTransformer transformer)
- {
- if (isEnabled())
- {
- ThreadInfo.getIsTransformableStack().push(getName(transformer));
- }
- }
-
- /**
- * Called to identify a transformer that cannot be used during working out
- * available transformers.
- */
- @Deprecated
- public void unavailableTransformer(ContentTransformer transformer, String sourceMimetype, String targetMimetype, long maxSourceSizeKBytes)
- {
- if (isEnabled())
- {
- Deque ourStack = ThreadInfo.getStack();
- Frame frame = ourStack.peek();
-
- if (frame != null)
- {
- Deque isTransformableStack = ThreadInfo.getIsTransformableStack();
- String name = (!isTransformableStack.isEmpty())
- ? isTransformableStack.getFirst()
- : getName(transformer);
- boolean debug = (maxSourceSizeKBytes != 0);
- if (frame.unavailableTransformers == null)
- {
- frame.unavailableTransformers = new TreeSet();
- }
- String priority = gePriority(transformer, sourceMimetype, targetMimetype);
- frame.unavailableTransformers.add(new UnavailableTransformer(name, priority, maxSourceSizeKBytes, debug));
- }
- }
- }
-
- @Deprecated
- public void availableTransformers(List transformers, long sourceSize,
- TransformationOptions options, String calledFrom)
- {
- String renditionName = options == null ? null : options.getUse();
- NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
- availableTransformers(transformers, sourceSize, renditionName, sourceNodeRef, calledFrom);
- }
-
- /**
- * Called once all available transformers have been identified.
- */
- @Deprecated
- public void availableTransformers(List transformers, long sourceSize,
- String renditionName, NodeRef sourceNodeRef, String calledFrom)
- {
- if (isEnabled())
- {
- Deque ourStack = ThreadInfo.getStack();
- Frame frame = ourStack.peek();
- boolean firstLevel = ourStack.size() == 1;
-
- // Override setDebugOutput(false) to allow debug when there are transformers but they are all unavailable
- // Note once turned on we don't turn it off again.
- if (transformers.size() == 0)
- {
- frame.setFailureReason(NO_TRANSFORMERS);
- if (frame.unavailableTransformers != null &&
- frame.unavailableTransformers.size() != 0)
- {
- ThreadInfo.setDebugOutput(true);
- }
- }
- frame.setSourceSize(sourceSize);
-
- // Log the basic info about this transformation
- logBasicDetails(frame, sourceSize, null, renditionName,
- calledFrom + ((transformers.size() == 0) ? " NO transformers" : ""), firstLevel);
-
- // Report available and unavailable transformers
- char c = 'a';
- int longestNameLength = getLongestTransformerNameLength(transformers, frame);
- for (ContentTransformer trans : transformers)
- {
- String name = getName(trans);
- int padName = longestNameLength - name.length() + 1;
- TransformationOptions options = new TransformationOptions();
- options.setUse(frame.renditionName);
- options.setSourceNodeRef(frame.sourceNodeRef);
- long maxSourceSizeKBytes = trans.getMaxSourceSizeKBytes(frame.sourceMimetype, frame.targetMimetype, options);
- String size = maxSourceSizeKBytes > 0 ? "< "+fileSize(maxSourceSizeKBytes*1024) : "";
- int padSize = 10 - size.length();
- String priority = gePriority(trans, frame.sourceMimetype, frame.targetMimetype);
- log((c == 'a' ? "**" : " ") + (c++) + ") " + priority + ' ' + name + spaces(padName) +
- size + spaces(padSize) + ms(trans.getTransformationTime(frame.sourceMimetype, frame.targetMimetype)));
- }
- if (frame.unavailableTransformers != null)
- {
- for (UnavailableTransformer unavailable: frame.unavailableTransformers)
- {
- int pad = longestNameLength - unavailable.name.length();
- String reason = "> "+fileSize(unavailable.maxSourceSizeKBytes*1024);
- if (unavailable.debug || logger.isTraceEnabled())
- {
- log("--" + (c++) + ") " + unavailable.priority + ' ' + unavailable.name + spaces(pad+1) + reason, unavailable.debug);
- }
- }
- }
- }
- }
-
- private String gePriority(ContentTransformer transformer, String sourceMimetype, String targetMimetype)
- {
- String priority =
- '[' + (isComponentTransformer(transformer)
- ? "---"
- : Integer.toString(transformerConfig.getPriority(transformer, sourceMimetype, targetMimetype))) +
- ']';
- priority = spaces(5-priority.length())+priority;
- return priority;
- }
-
- @Deprecated
- public void inactiveTransformer(ContentTransformer transformer)
- {
- log(getName(transformer)+' '+ms(transformer.getTransformationTime(null, null))+" INACTIVE");
- }
-
- @Deprecated
- public void activeTransformer(int mimetypePairCount, ContentTransformer transformer, String sourceMimetype,
- String targetMimetype, long maxSourceSizeKBytes, boolean firstMimetypePair)
- {
- if (firstMimetypePair)
- {
- log(getName(transformer)+' '+ms(transformer.getTransformationTime(sourceMimetype, targetMimetype)));
- }
- String i = Integer.toString(mimetypePairCount);
- String priority = gePriority(transformer, sourceMimetype, targetMimetype);
- String sourceExt = getMimetypeExt(sourceMimetype);
- String targetExt = getMimetypeExt(targetMimetype);
- targetExt = AsynchronousExtractor.getExtension(targetMimetype, sourceExt, targetExt);
- log(spaces(5-i.length())+mimetypePairCount+") "+ sourceExt + targetExt +
- priority +
- ' '+fileSize((maxSourceSizeKBytes > 0) ? maxSourceSizeKBytes*1024 : maxSourceSizeKBytes)+
- (maxSourceSizeKBytes == 0 ? " disabled" : ""));
- }
-
- @Deprecated
- public void activeTransformer(String sourceMimetype, String targetMimetype,
- int transformerCount, ContentTransformer transformer, long maxSourceSizeKBytes,
- boolean firstTransformer)
- {
- String priority = gePriority(transformer, sourceMimetype, targetMimetype);
- activeTransformer(sourceMimetype, targetMimetype, transformerCount, priority, getName(transformer),
- maxSourceSizeKBytes, firstTransformer);
- }
-
- private int getLongestTransformerNameLength(List transformers,
- Frame frame)
- {
- int longestNameLength = 0;
- for (ContentTransformer trans : transformers)
- {
- int length = getName(trans).length();
- if (longestNameLength < length)
- longestNameLength = length;
- }
- if (frame != null && frame.unavailableTransformers != null)
- {
- for (UnavailableTransformer unavailable: frame.unavailableTransformers)
- {
- int length = unavailable.name.length();
- if (longestNameLength < length)
- longestNameLength = length;
- }
- }
- return longestNameLength;
- }
-
- /**
- * Called after working out what transformers are available and any
- * resulting transform has been called.
- */
- public void popAvailable()
- {
- if (isEnabled())
- {
- pop(Call.AVAILABLE, false, false);
- }
- }
-
-
- /**
- * Called after returning from a nested isTransformable.
- */
- public void popIsTransformableSize()
- {
- if (isEnabled())
- {
- ThreadInfo.getIsTransformableStack().pop();
- }
- }
-
- /**
- * 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)
- {
- // Do not generate this type of debug if already generating other debug to a StringBuilder
- // (for example a test transform).
- if (getStringBuilder() != null)
- {
- return null;
- }
-
- Collection transformers = format42 || transformerName != null
- ? sortTransformersByName(transformerName)
- : transformerRegistry.getTransformers();
- Collection sourceMimetypes = format42
- ? getSourceMimetypes(null)
- : mimetypeService.getMimetypes();
- Collection 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);
- }
-
- /**
- * Returns a String and /or debug that provides a list of supported transformations
- * sorted by source and target mimetype extension.
- * @param sourceExtension restricts the list to one source extension. Unrestricted if null.
- * @param targetExtension restricts the list to one target extension. Unrestricted if null.
- * @param toString indicates that a String value should be returned in addition to any debug.
- * @param format42 indicates the new 4.2 rather than older 4.1.4 format should be used.
- * The 4.1.4 format did not order the transformers or mimetypes and only included top
- * level transformers.
- * @param onlyNonDeterministic if true only report transformations where there is more than
- * one transformer available with the same priority.
- * @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
- @Override
- public String transformationsByExtension(String sourceExtension, String targetExtension, boolean toString,
- boolean format42, boolean onlyNonDeterministic, String renditionName)
- {
- // Do not generate this type of debug if already generating other debug to a StringBuilder
- // (for example a test transform).
- if (getStringBuilder() != null)
- {
- return null;
- }
-
- Collection transformers = format42 && !onlyNonDeterministic
- ? sortTransformersByName(null)
- : transformerRegistry.getTransformers();
- Collection sourceMimetypes = format42 || sourceExtension != null
- ? getSourceMimetypes(sourceExtension)
- : mimetypeService.getMimetypes();
- Collection targetMimetypes = format42 || targetExtension != null
- ? getTargetMimetypes(sourceExtension, targetExtension, sourceMimetypes)
- : mimetypeService.getMimetypes();
-
- TransformationOptions options = new TransformationOptions();
- options.setUse(renditionName);
- StringBuilder sb = null;
- try
- {
- if (toString)
- {
- sb = new StringBuilder();
- setStringBuilder(sb);
- }
- pushMisc();
- for (String sourceMimetype: sourceMimetypes)
- {
- for (String targetMimetype: targetMimetypes)
- {
- // Find available transformers
- List availableTransformer = new ArrayList();
- for (ContentTransformer transformer: transformers)
- {
- if (transformer.isTransformable(sourceMimetype, -1, targetMimetype, options))
- {
- availableTransformer.add(transformer);
- }
- }
-
- // Sort by priority
- final String currSourceMimetype = sourceExtension;
- final String currTargetMimetype = targetExtension;
- Collections.sort(availableTransformer, new Comparator()
- {
- @Override
- public int compare(ContentTransformer transformer1, ContentTransformer transformer2)
- {
- return transformerConfig.getPriority(transformer1, currSourceMimetype, currTargetMimetype) -
- transformerConfig.getPriority(transformer2, currSourceMimetype, currTargetMimetype);
- }
- });
-
- // Do we need to produce any output?
- int size = availableTransformer.size();
- int priority = size >= 2
- ? transformerConfig.getPriority(availableTransformer.get(0), sourceMimetype, targetMimetype)
- : -1;
- if (!onlyNonDeterministic || (size >= 2 && priority ==
- transformerConfig.getPriority(availableTransformer.get(1), sourceMimetype, targetMimetype)))
- {
- // Log the transformers
- boolean supportedByTransformService = remoteTransformServiceRegistry == null ||
- remoteTransformServiceRegistry instanceof DummyTransformServiceRegistry
- ? false
- : remoteTransformServiceRegistry.isSupported(sourceMimetype,
- -1, targetMimetype, Collections.emptyMap(), null);
- List localTransformers = localTransformServiceRegistryImpl == null
- ? Collections.emptyList()
- : localTransformServiceRegistryImpl.findTransformers(sourceMimetype,
- targetMimetype, Collections.emptyMap(), null);
- if (!localTransformers.isEmpty() || supportedByTransformService || size >= 1)
- {
- try
- {
- pushMisc();
- int transformerCount = 0;
- if (supportedByTransformService)
- {
- long maxSourceSizeKBytes = remoteTransformServiceRegistry.findMaxSize(sourceMimetype,
- targetMimetype, Collections.emptyMap(), null);
- activeTransformer(sourceMimetype, targetMimetype, transformerCount, " ",
- TRANSFORM_SERVICE_NAME, maxSourceSizeKBytes, transformerCount++ == 0);
- }
- for (SupportedTransform localTransformer : localTransformers)
- {
- long maxSourceSizeKBytes = localTransformer.getMaxSourceSizeBytes();
- String transformName = "Local:" + localTransformer.getName();
- String transformerPriority = "[" + localTransformer.getPriority() + ']';
- transformerPriority = spaces(5-transformerPriority.length())+transformerPriority;
- activeTransformer(sourceMimetype, targetMimetype, transformerCount, transformerPriority,
- transformName, maxSourceSizeKBytes, transformerCount++ == 0);
- }
- for (ContentTransformer transformer: availableTransformer)
- {
- if (!onlyNonDeterministic || transformerCount < 2 ||
- priority == transformerConfig.getPriority(transformer, sourceMimetype, targetMimetype))
- {
- long maxSourceSizeKBytes = transformer.getMaxSourceSizeKBytes(
- sourceMimetype, targetMimetype, options);
- activeTransformer(sourceMimetype, targetMimetype, transformerCount,
- transformer, maxSourceSizeKBytes, transformerCount++ == 0);
- }
- }
- }
- finally
- {
- popMisc();
- }
- }
- }
- }
- }
- }
- finally
- {
- popMisc();
- setStringBuilder(null);
- }
- stripFinishedLine(sb);
- return stripLeadingNumber(sb);
- }
-
- private String getName(ContentTransformer transformer)
- {
- String name =
- transformer instanceof ContentTransformerHelper
- ? ContentTransformerHelper.getSimpleName(transformer)
- : transformer.getClass().getSimpleName();
-
- String type =
- ((transformer instanceof AbstractRemoteContentTransformer &&
- ((AbstractRemoteContentTransformer)transformer).remoteTransformerClientConfigured()) ||
- (transformer instanceof ProxyContentTransformer &&
- ((ProxyContentTransformer)transformer).remoteTransformerClientConfigured())
- ? "Remote" : "")+
- (transformer instanceof ComplexContentTransformer
- ? "Complex"
- : transformer instanceof FailoverContentTransformer
- ? "Failover"
- : transformer instanceof ProxyContentTransformer
- ? (((ProxyContentTransformer)transformer).getWorker() instanceof RuntimeExecutableContentTransformerWorker)
- ? "Runtime"
- : "Proxy"
- : "");
-
- boolean componentTransformer = isComponentTransformer(transformer);
-
- StringBuilder sb = new StringBuilder("Legacy:").append(name);
- if (componentTransformer || type.length() > 0)
- {
- sb.append("<<");
- sb.append(type);
- if (componentTransformer)
- {
- sb.append("Component");
- }
- sb.append(">>");
- }
-
- return sb.toString();
- }
-
-
- private boolean isComponentTransformer(ContentTransformer transformer)
- {
- return !transformerRegistry.getTransformers().contains(transformer);
- }
-
- @Deprecated
- public String getFileName(TransformationOptions options, boolean firstLevel, long sourceSize)
- {
- NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
- return getFileName(sourceNodeRef, firstLevel, sourceSize);
- }
-
- /**
- * Returns a sorted list of all transformers sorted by name.
- * @param transformerName to restrict the collection to one entry
- * @return a new Collection of sorted transformers
- * @throws IllegalArgumentException if transformerName is not found.
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
- @Deprecated
- public Collection sortTransformersByName(String transformerName)
- {
- Collection transformers = (transformerName != null)
- ? Collections.singleton(transformerRegistry.getTransformer(transformerName))
- : transformerRegistry.getAllTransformers();
-
- SortedMap map = new TreeMap();
- for (ContentTransformer transformer: transformers)
- {
- String name = transformer.getName();
- map.put(name, transformer);
- }
- Collection sorted = map.values();
- return sorted;
- }
-
- /**
- * @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 testTransform(final String transformerName, String sourceExtension,
- String targetExtension, String renditionName)
- {
- logger.error("The testTransform operation for a specific transformer is no longer supported. " +
- "Request redirected to the version of this method without a transformerName.");
- return testTransform(sourceExtension, targetExtension, renditionName);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformImpl.java b/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformImpl.java
index ef0ab8b3d5..c96b73fafe 100644
--- a/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformImpl.java
+++ b/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformImpl.java
@@ -180,7 +180,7 @@ public class LocalTransformImpl extends AbstractLocalTransform
}
// These 3 values are commonly needed and are always supplied in the TransformRequest (message to the T-Router).
- // The targetExtension is also supplied in the TransformRequest, but in the case of local and legacy transformers
+ // The targetExtension is also supplied in the TransformRequest, but in the case of local transforms
// is added by the remoteTransformerClient.request call for historic reasons, so does not need to be added here.
args[i++] = "sourceMimetype";
args[i++] = sourceMimetype;
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java b/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java
index d74c1a103e..a493328d5c 100644
--- a/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java
+++ b/repository/src/main/java/org/alfresco/repo/content/transform/LocalTransformServiceRegistry.java
@@ -484,9 +484,7 @@ public class LocalTransformServiceRegistry extends TransformServiceRegistryImpl
transformerDebug.debug("Local transforms "+getData()+" are " + (enabled ? "enabled" : "disabled"));
}
- return enabled
- ? super.findMaxSize(sourceMimetype, targetMimetype, options, renditionName)
- : 0;
+ return super.findMaxSize(sourceMimetype, targetMimetype, options, renditionName);
}
public LocalTransform getLocalTransform(String sourceMimetype, long sourceSizeInBytes, String targetMimetype, Map actualOptions, String renditionName)
@@ -495,9 +493,14 @@ public class LocalTransformServiceRegistry extends TransformServiceRegistryImpl
{
return null;
}
+ LocalTransform localTransform = null;
String name = findTransformerName(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
- LocalData data = getData();
- Map localTransforms = data.localTransforms;
- return localTransforms.get(name);
+ if (name != null)
+ {
+ LocalData data = getData();
+ Map localTransforms = data.localTransforms;
+ localTransform = localTransforms.get(name);
+ }
+ return localTransform;
}
}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/LogEntries.java b/repository/src/main/java/org/alfresco/repo/content/transform/LogEntries.java
index cefed5f35d..edddea498c 100644
--- a/repository/src/main/java/org/alfresco/repo/content/transform/LogEntries.java
+++ b/repository/src/main/java/org/alfresco/repo/content/transform/LogEntries.java
@@ -29,10 +29,7 @@ import org.apache.commons.logging.Log;
/**
* Interface that gives access to Log entries
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
-@Deprecated
interface LogEntries extends Log
{
/**
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/MailContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/MailContentTransformer.java
deleted file mode 100644
index f8f084aeef..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/MailContentTransformer.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.parser.microsoft.OfficeParser;
-
-/**
- * Uses Apache Tika and
- * Apache POI to transform
- * Outlook email msg files.
- *
- * @author Nick Burch
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class MailContentTransformer extends TikaPoweredContentTransformer
-{
- public MailContentTransformer() {
- super(new String[] {
- MimetypeMap.MIMETYPE_OUTLOOK_MSG
- });
- setTransformerName("OutlookMsg");
- }
-
- @Override
- protected Parser getParser() {
- return new OfficeParser();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/MediaWikiContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/MediaWikiContentTransformer.java
deleted file mode 100644
index 4b0d4b4445..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/MediaWikiContentTransformer.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import info.bliki.wiki.filter.Encoder;
-import info.bliki.wiki.model.WikiModel;
-import info.bliki.wiki.tags.ATag;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.model.FileFolderService;
-import org.alfresco.service.cmr.model.FileInfo;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.htmlcleaner.ContentToken;
-
-/**
- * MediaWiki content transformer. Converts mediawiki markup into HTML.
- *
- *
@see Java_Wikipedia_API
- *
- * Tika Note - Tika doesn't currently support mediawiki markup, so this
- * transformer cannot currently be converted to use Tika.
- *
- * @author Roy Wetherall
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class MediaWikiContentTransformer extends AbstractContentTransformer2
-{
- /** The file folder service */
- private FileFolderService fileFolderService;
-
- /** The node service */
- private NodeService nodeService;
-
- /**
- * Sets the file folder service
- *
- * @param fileFolderService the file folder service
- */
- public void setFileFolderService(FileFolderService fileFolderService)
- {
- this.fileFolderService = fileFolderService;
- }
-
- /**
- * Sets the node service
- *
- * @param nodeService the node service
- */
- public void setNodeService(NodeService nodeService)
- {
- this.nodeService = nodeService;
- }
-
- /**
- * Only transform from mediawiki to html
- *
- * @see org.alfresco.repo.content.transform.ContentTransformer#isTransformable(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if (!MimetypeMap.MIMETYPE_TEXT_MEDIAWIKI.equals(sourceMimetype) ||
- !MimetypeMap.MIMETYPE_HTML.equals(targetMimetype))
- {
- // only support MEDIAWIKI -> HTML
- return false;
- }
- else
- {
- return true;
- }
- }
-
- @Override
- public String getComments(boolean available)
- {
- return onlySupports(MimetypeMap.MIMETYPE_TEXT_MEDIAWIKI, MimetypeMap.MIMETYPE_HTML, available);
- }
-
- /**
- * @see org.alfresco.repo.content.transform.AbstractContentTransformer2#transformInternal(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)
- */
- public void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws Exception
- {
- String imageURL = "{$image}";
- String pageURL = "${title}";
-
- // If we have context about the destination of the transformation then use it
- if (options.getTargetNodeRef() != null)
- {
- NodeRef parentNodeRef = this.nodeService.getPrimaryParent(options.getTargetNodeRef()).getParentRef();
-
- StringBuffer folderPath = new StringBuffer(256);
- List fileInfos = this.fileFolderService.getNamePath(null, parentNodeRef);
- for (FileInfo fileInfo : fileInfos)
- {
- folderPath.append(fileInfo.getName()).append("/");
- }
-
- pageURL = "/alfresco/d/d?path=" + folderPath + "${title}.html";
- imageURL = "/alfresco/d/d?path=" + folderPath + "Images/${image}";
- }
-
- // Create the wikiModel and set the title and image link URL's
- AlfrescoWikiModel wikiModel = new AlfrescoWikiModel(imageURL, pageURL);
-
- // Render the wiki content as HTML
- writer.putContent(wikiModel.render(reader.getContentString()));
- }
-
- /**
- * Alfresco custom Wiki model used to generate links and image references
- *
- * @author Roy Wetherall
- */
- private class AlfrescoWikiModel extends WikiModel
- {
- public AlfrescoWikiModel(String imageBaseURL, String linkBaseURL)
- {
- super(imageBaseURL, linkBaseURL);
- }
-
- @Override
- public void appendInternalLink(String link, String hashSection, String linkText)
- {
- link = link.replaceAll(":", " - ");
- String encodedtopic = Encoder.encodeTitleUrl(link);
- encodedtopic = encodedtopic.replaceAll("_", " ");
-
- String hrefLink = fExternalWikiBaseURL.replace("${title}", encodedtopic);
-
- ATag aTagNode = new ATag();
- append(aTagNode);
- aTagNode.addAttribute("id", "w");
- String href = hrefLink;
- if (hashSection != null) {
- href = href + '#' + hashSection;
- }
- aTagNode.addAttribute("href", href);
- aTagNode.addObjectAttribute("wikilink", hrefLink);
-
- ContentToken text = new ContentToken(linkText);
- aTagNode.addChild(text);
- }
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/OOXMLThumbnailContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/OOXMLThumbnailContentTransformer.java
deleted file mode 100644
index 0410b72a33..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/OOXMLThumbnailContentTransformer.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.List;
-
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.TempFileProvider;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
-
-/**
- * Extracts out Thumbnail JPEGs from OOXML files for thumbnailing & previewing.
- * This transformer will only work for OOXML files where thumbnailing was enabled,
- * which isn't on by default on Windows, but is more common on Mac.
- *
- * @author Nick Burch
- * @since 4.0.1
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class OOXMLThumbnailContentTransformer extends AbstractContentTransformer2
-{
- public static final String NO_THUMBNAIL_PRESENT_IN_FILE = "No thumbnail present in file, unable to generate ";
-
- private static final Log log = LogFactory.getLog(OOXMLThumbnailContentTransformer.class);
-
- private static final List OOXML_MIMETYPES = Arrays.asList(new String[]{
- MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING,
- MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_WORD_TEMPLATE,
- MimetypeMap.MIMETYPE_OPENXML_WORD_TEMPLATE_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_SLIDESHOW,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_SLIDESHOW_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_TEMPLATE,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_TEMPLATE_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_ADDIN,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_SLIDE,
- MimetypeMap.MIMETYPE_OPENXML_PRESENTATION_SLIDE_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET,
- MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE,
- MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET_ADDIN_MACRO,
- MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET_BINARY_MACRO});
-
- private static final List TARGET_MIMETYPES = Arrays.asList(new String[]{MimetypeMap.MIMETYPE_IMAGE_JPEG});
-
- @Override
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- // only support [OOXML] -> JPEG
- return TARGET_MIMETYPES.contains(targetMimetype) && OOXML_MIMETYPES.contains(sourceMimetype);
- }
-
- @Override
- public String getComments(boolean available)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(super.getComments(available));
- sb.append("# Only supports extraction of embedded jpegs from OOXML formats\n");
- return sb.toString();
- }
-
- @Override
- protected void transformInternal(ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception
- {
- final String sourceMimetype = reader.getMimetype();
- final String sourceExtension = getMimetypeService().getExtension(sourceMimetype);
- final String targetMimetype = writer.getMimetype();
-
-
- if (log.isDebugEnabled())
- {
- StringBuilder msg = new StringBuilder();
- msg.append("Transforming from ").append(sourceMimetype)
- .append(" to ").append(targetMimetype);
- log.debug(msg.toString());
- }
-
-
- OPCPackage pkg = null;
- try
- {
- File ooxmlTempFile = TempFileProvider.createTempFile(this.getClass().getSimpleName() + "_ooxml", sourceExtension);
- reader.getContent(ooxmlTempFile);
-
- // Load the file
- pkg = OPCPackage.open(ooxmlTempFile.getPath());
-
- // Does it have a thumbnail?
- PackageRelationshipCollection rels =
- pkg.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL);
- if (rels.size() > 0)
- {
- // Get the thumbnail part
- PackageRelationship tRel = rels.getRelationship(0);
- PackagePart tPart = pkg.getPart(tRel);
-
- // Write it to the target
- InputStream tStream = tPart.getInputStream();
- writer.putContent( tStream );
- tStream.close();
- }
- else
- {
- log.debug("No thumbnail present in " + reader.toString());
- throw new UnimportantTransformException(NO_THUMBNAIL_PRESENT_IN_FILE + targetMimetype);
- }
- }
- catch (IOException e)
- {
- throw new AlfrescoRuntimeException("Unable to transform " + sourceExtension + " file.", e);
- }
- finally
- {
- if (pkg != null)
- {
- pkg.close();
- }
- }
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/OOoContentTransformerHelper.java b/repository/src/main/java/org/alfresco/repo/content/transform/OOoContentTransformerHelper.java
deleted file mode 100644
index d653e9c3e7..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/OOoContentTransformerHelper.java
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import com.sun.star.task.ErrorCodeIOException;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentIOException;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.MimetypeService;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.TempFileProvider;
-import org.apache.commons.logging.Log;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.PDPageContentStream;
-import org.artofsolving.jodconverter.document.*;
-import org.artofsolving.jodconverter.office.OfficeException;
-import org.json.JSONException;
-import org.springframework.core.io.DefaultResourceLoader;
-import org.springframework.util.FileCopyUtils;
-
-import java.io.*;
-
-/**
- * A class providing basic OOo-related functionality shared by both
- * {@link ContentTransformer}s and {@link ContentTransformerWorker}s.
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public abstract class OOoContentTransformerHelper extends ContentTransformerHelper
-{
- private String documentFormatsConfiguration;
- private DocumentFormatRegistry formatRegistry;
- protected LegacyTransformerDebug transformerDebug;
- private static final int JODCONVERTER_TRANSFORMATION_ERROR_CODE = 3088;
-
- protected RemoteTransformerClient remoteTransformerClient;
-
- /**
- * Set a non-default location from which to load the document format mappings.
- *
- * @param path
- * a resource location supporting the file: or classpath: prefixes
- */
- public void setDocumentFormatsConfiguration(String path)
- {
- this.documentFormatsConfiguration = path;
- }
-
- protected abstract Log getLogger();
-
- protected abstract String getTempFilePrefix();
-
- public abstract boolean isAvailable();
-
- protected abstract void convert(File tempFromFile, DocumentFormat sourceFormat, File tempToFile,
- DocumentFormat targetFormat);
-
- /**
- * Helper setter of the transformer debug.
- * @param transformerDebug TransformerDebug
- */
- public void setTransformerDebug(LegacyTransformerDebug transformerDebug)
- {
- this.transformerDebug = transformerDebug;
- }
-
- /**
- * Sets the optional remote transformer client which will be used in preference to a local command if available.
- *
- * @param remoteTransformerClient may be null;
- */
- public void setRemoteTransformerClient(RemoteTransformerClient remoteTransformerClient)
- {
- this.remoteTransformerClient = remoteTransformerClient;
- }
-
- public boolean remoteTransformerClientConfigured()
- {
- return remoteTransformerClient != null && remoteTransformerClient.getBaseUrl() != null;
- }
-
- public void afterPropertiesSet()
- {
- // load the document conversion configuration
- if (formatRegistry == null)
- {
- if (documentFormatsConfiguration != null)
- {
- DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
- try
- {
- InputStream is = resourceLoader.getResource(this.documentFormatsConfiguration).getInputStream();
- formatRegistry = new JsonDocumentFormatRegistry(is);
- // We do not need to explicitly close this InputStream as it is closed for us within the XmlDocumentFormatRegistry
- }
- catch (IOException e)
- {
- throw new AlfrescoRuntimeException(
- "Unable to load document formats configuration file: "
- + this.documentFormatsConfiguration);
- }
- catch (JSONException e)
- {
- throw new AlfrescoRuntimeException(
- "Unable to read document formats configuration file: "
- + this.documentFormatsConfiguration);
- }
- }
- else
- {
- formatRegistry = new DefaultDocumentFormatRegistry();
- }
- }
- }
-
- /**
- * There are some conversions that fail, despite the converter believing them possible.
- * This method can be used by subclasses to check if a targetMimetype or source/target
- * Mimetype pair are blocked.
- *
- * @param sourceMimetype String
- * @param targetMimetype String
- * @return true
if the mimetypes are blocked, else false
- */
- protected boolean isTransformationBlocked(String sourceMimetype, String targetMimetype)
- {
- if (targetMimetype.equals(MimetypeMap.MIMETYPE_XHTML))
- {
- return true;
- }
- else if (targetMimetype.equals(MimetypeMap.MIMETYPE_WORDPERFECT))
- {
- return true;
- }
- else if (targetMimetype.equals(MimetypeMap.MIMETYPE_FLASH))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /**
- * @see DocumentFormatRegistry
- */
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- // Use BinaryPassThroughContentTransformer if mimetypes are the same.
- if (sourceMimetype.equals(targetMimetype))
- {
- return false;
- }
-
- if (!isAvailable())
- {
- // The connection management is must take care of this
- return false;
- }
-
- if (isTransformationBlocked(sourceMimetype, targetMimetype))
- {
- if (getLogger().isDebugEnabled())
- {
- StringBuilder msg = new StringBuilder();
- msg.append("Transformation from ")
- .append(sourceMimetype).append(" to ")
- .append(targetMimetype)
- .append(" is blocked and therefore unavailable.");
- getLogger().debug(msg.toString());
- }
- return false;
- }
-
- MimetypeService mimetypeService = getMimetypeService();
- String sourceExtension = mimetypeService.getExtension(sourceMimetype);
- String targetExtension = mimetypeService.getExtension(targetMimetype);
- // query the registry for the source format
- DocumentFormat sourceFormat = formatRegistry.getFormatByExtension(sourceExtension);
- if (sourceFormat == null)
- {
- // no document format
- return false;
- }
- // query the registry for the target format
- DocumentFormat targetFormat = formatRegistry.getFormatByExtension(targetExtension);
- if (targetFormat == null)
- {
- // no document format
- return false;
- }
-
- // get the family of the target document
- DocumentFamily sourceFamily = sourceFormat.getInputFamily();
- // does the format support the conversion
- boolean transformable = formatRegistry.getOutputFormats(sourceFamily).contains(targetFormat); // same as: targetFormat.getStoreProperties(sourceFamily) != null
- return transformable;
- }
-
- @Override
- public String getComments(boolean available)
- {
- return "# Transformations supported by OpenOffice/LibreOffice\n";
- }
-
- /**
- * This method produces an empty PDF file at the specified File location.
- * Apache's PDFBox is used to create the PDF file.
- */
- private void produceEmptyPdfFile(File tempToFile)
- {
- // If improvement PDFBOX-914 is incorporated, we can do this with a straight call to
- // org.apache.pdfbox.TextToPdf.createPDFFromText(new StringReader(""));
- // https://issues.apache.org/jira/browse/PDFBOX-914
-
- PDDocument pdfDoc = null;
- PDPageContentStream contentStream = null;
- try
- {
- pdfDoc = new PDDocument();
- PDPage pdfPage = new PDPage();
- // Even though, we want an empty PDF, some libs (e.g. PDFRenderer) object to PDFs
- // that have literally nothing in them. So we'll put a content stream in it.
- contentStream = new PDPageContentStream(pdfDoc, pdfPage);
- pdfDoc.addPage(pdfPage);
-
- // Now write the in-memory PDF document into the temporary file.
- pdfDoc.save(tempToFile.getAbsolutePath());
-
- }
- catch (IOException iox)
- {
- throw new ContentIOException("Error creating empty PDF file", iox);
- }
- finally
- {
- if (contentStream != null)
- {
- try
- {
- contentStream.close();
- }
- catch (IOException ignored)
- {
- // Intentionally empty
- }
- }
- if (pdfDoc != null)
- {
- try
- {
- pdfDoc.close();
- }
- catch (IOException ignored)
- {
- // Intentionally empty.
- }
- }
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.alfresco.repo.content.transform.ContentTransformerWorker#getVersionString()
- */
- public String getVersionString()
- {
- return "";
- }
-
- public void transform(
- ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception
- {
- if (isAvailable() == false)
- {
- throw new ContentIOException("Content conversion failed (unavailable): \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer);
- }
-
- if (getLogger().isDebugEnabled())
- {
- StringBuilder msg = new StringBuilder();
- msg.append("transforming content from ")
- .append(reader.getMimetype())
- .append(" to ")
- .append(writer.getMimetype());
- getLogger().debug(msg.toString());
- }
-
- String sourceMimetype = getMimetype(reader);
- String targetMimetype = getMimetype(writer);
-
- MimetypeService mimetypeService = getMimetypeService();
- String sourceExtension = mimetypeService.getExtension(sourceMimetype);
- String targetExtension = mimetypeService.getExtension(targetMimetype);
- // query the registry for the source format
- DocumentFormat sourceFormat = formatRegistry.getFormatByExtension(sourceExtension);
- if (sourceFormat == null)
- {
- // source format is not recognised
- throw new ContentIOException("No OpenOffice document format for source extension: " + sourceExtension);
- }
- // query the registry for the target format
- DocumentFormat targetFormat = formatRegistry.getFormatByExtension(targetExtension);
- if (targetFormat == null)
- {
- // target format is not recognised
- throw new ContentIOException("No OpenOffice document format for target extension: " + targetExtension);
- }
- // get the family of the target document
- DocumentFamily sourceFamily = sourceFormat.getInputFamily();
- // does the format support the conversion
- if (!formatRegistry.getOutputFormats(sourceFamily).contains(targetFormat)) // same as: targetFormat.getStoreProperties(sourceFamily) == null
- {
- throw new ContentIOException(
- "OpenOffice conversion not supported: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer);
- }
-
- // There is a bug (reported in ALF-219) whereby JooConverter (the Alfresco Community Edition's 3rd party
- // OpenOffice connector library) struggles to handle zero-size files being transformed to pdf.
- // For zero-length .html files, it throws NullPointerExceptions.
- // For zero-length .txt files, it produces a pdf transformation, but it is not a conformant
- // pdf file and cannot be viewed (contains no pages).
- //
- // For these reasons, if the file is of zero length, we will not use JooConverter & OpenOffice
- // and will instead ask Apache PDFBox to produce an empty pdf file for us.
- final long documentSize = reader.getSize();
- if (documentSize == 0L || temporaryMsFile(options))
- {
- File tempToFile = TempFileProvider.createTempFile(
- getTempFilePrefix()+"-target-",
- "." + targetExtension);
- produceEmptyPdfFile(tempToFile);
- writer.putContent(tempToFile);
- }
- else
- {
- if (remoteTransformerClientConfigured())
- {
- transformRemote(reader, writer, options, sourceMimetype, sourceExtension, targetMimetype, targetExtension);
- }
- else
- {
- transformLocal(reader, writer, options, sourceMimetype,
- sourceExtension, targetExtension, sourceFormat, targetFormat);
- }
- }
-
- if (getLogger().isDebugEnabled())
- {
- getLogger().debug("transformation successful");
- }
- }
-
- protected void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options,
- String sourceMimetype, String sourceExtension, String targetExtension,
- DocumentFormat sourceFormat, DocumentFormat targetFormat)
- {
- // create temporary files to convert from and to
- File tempFromFile = TempFileProvider.createTempFile(
- getTempFilePrefix()+"-source-",
- "." + sourceExtension);
- File tempToFile = TempFileProvider.createTempFile(
- getTempFilePrefix()+"-target-",
- "." + targetExtension);
-
- // download the content from the source reader
- saveContentInFile(sourceMimetype, reader, tempFromFile);
-
- try
- {
- convert(tempFromFile, sourceFormat, tempToFile, targetFormat);
- writer.putContent(tempToFile);
- }
- catch (OfficeException e)
- {
- throw new ContentIOException("OpenOffice server conversion failed: \n" +
- " reader: " + reader + "\n" +
- " writer: " + writer + "\n" +
- " from file: " + tempFromFile + "\n" +
- " to file: " + tempToFile,
- e);
- }
- catch (Throwable throwable)
- {
- // Because of the known bug with empty Spreadsheets in JodConverter try to catch exception and produce empty pdf file
- if (throwable.getCause() instanceof ErrorCodeIOException &&
- ((ErrorCodeIOException) throwable.getCause()).ErrCode == JODCONVERTER_TRANSFORMATION_ERROR_CODE)
- {
- getLogger().warn("Transformation failed: \n" +
- "from file: " + tempFromFile + "\n" +
- "to file: " + tempToFile +
- "Source file " + tempFromFile + " has no content");
- produceEmptyPdfFile(tempToFile);
- }
- else
- {
- throw throwable;
- }
- }
- }
-
- protected void transformRemote(ContentReader reader, ContentWriter writer, TransformationOptions options,
- String sourceMimetype, String sourceExtension,
- String targetMimetype, String targetExtension) throws IllegalAccessException
- {
- long timeoutMs = options.getTimeoutMs();
- Log logger = getLogger();
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "libreoffice",
- "sourceMimetype", sourceMimetype,
- "sourceExtension", sourceExtension,
- "targetMimetype", targetMimetype);
- }
-
- private boolean temporaryMsFile(TransformationOptions options)
- {
- String fileName = transformerDebug == null ? null : transformerDebug.getFileName(options, true, -1);
- return fileName != null && fileName.startsWith("~$");
- }
-
- /**
- * Populates a file with the content in the reader.
- */
- public void saveContentInFile(String sourceMimetype, ContentReader reader, File file) throws ContentIOException
- {
- String encoding = reader.getEncoding();
- if (encodeAsUtf8(sourceMimetype, encoding))
- {
- saveContentInUtf8File(reader, file);
- }
- else
- {
- reader.getContent(file);
- }
- }
-
- /**
- * Returns {@code true} if the input file should be transformed to UTF8 encoding.
- *
- * OpenOffice/LibreOffice is unable to support the import of text files that are SHIFT JIS encoded
- * (and others: windows-1252...) so transformed to UTF-8.
- */
- protected boolean encodeAsUtf8(String sourceMimetype, String encoding)
- {
- return MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(sourceMimetype) && !"UTF-8".equals(encoding);
- }
-
- /**
- * Populates a file with the content in the reader, but also converts the encoding to UTF-8.
- */
- private void saveContentInUtf8File(ContentReader reader, File file)
- {
- String encoding = reader.getEncoding();
- try
- {
- Reader in = new InputStreamReader(reader.getContentInputStream(), encoding);
- Writer out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), "UTF-8");
-
- FileCopyUtils.copy(in, out); // both streams are closed
- }
- catch (IOException e)
- {
- throw new ContentIOException("Failed to copy content to file and convert "+encoding+" to UTF-8: \n" +
- " file: " + file,
- e);
- }
- }
-}
\ No newline at end of file
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/PdfBoxContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/PdfBoxContentTransformer.java
deleted file mode 100644
index 51ec70160a..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/PdfBoxContentTransformer.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.parser.pdf.PDFParser;
-import org.apache.tika.parser.pdf.PDFParserConfig;
-
-import static org.alfresco.repo.rendition2.RenditionDefinition2.TARGET_ENCODING;
-
-/**
- * Uses Apache Tika and
- * Apache PDFBox to perform
- * conversions from PDF documents.
- *
- * @author Nick Burch
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class PdfBoxContentTransformer extends TikaPoweredContentTransformer
-{
- /**
- * The logger
- */
- private static Log logger = LogFactory.getLog(PdfBoxContentTransformer.class);
- protected PDFParserConfig pdfParserConfig;
- private boolean extractBookmarksText = true;
-
- public PdfBoxContentTransformer() {
- super(new String[] {
- MimetypeMap.MIMETYPE_PDF
- });
- }
-
- @Override
- protected Parser getParser() {
- return new PDFParser();
- }
-
- /**
- * Sets the PDFParserConfig for inclusion in the ParseContext sent to the PDFBox parser,
- * useful for setting config like spacingTolerance.
- *
- * @param pdfParserConfig
- */
- public void setPdfParserConfig(PDFParserConfig pdfParserConfig)
- {
- this.pdfParserConfig = pdfParserConfig;
- }
-
- public void setExtractBookmarksText(boolean extractBookmarksText)
- {
- this.extractBookmarksText = extractBookmarksText;
- }
-
-
- @Override
- protected ParseContext buildParseContext(Metadata metadata, String targetMimeType, TransformationOptions options)
- {
- ParseContext context = super.buildParseContext(metadata, targetMimeType, options);
- if (pdfParserConfig != null)
- {
- pdfParserConfig.setExtractBookmarksText(extractBookmarksText);
- context.set(PDFParserConfig.class, pdfParserConfig);
- }
- // TODO: Possibly extend TransformationOptions to allow for per-transform PDFParserConfig?
- return context;
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options,
- String sourceMimetype, String targetMimetype,
- String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- long timeoutMs = options.getTimeoutMs();
- String notExtractBookmarksText = null;
-
- if (!extractBookmarksText)
- {
- notExtractBookmarksText = Boolean.TRUE.toString();
- }
-
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "PdfBox",
- "notExtractBookmarksText", notExtractBookmarksText,
- "sourceMimetype", sourceMimetype,
- "targetMimetype", targetMimetype,
- "targetExtension", targetExtension,
- TARGET_ENCODING, targetEncoding);
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/PoiContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/PoiContentTransformer.java
deleted file mode 100644
index a1970f5ca0..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/PoiContentTransformer.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.ArrayList;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.parser.microsoft.OfficeParser;
-
-/**
- * Uses Apache Tika and
- * Apache POI to perform
- * conversions from Office documents.
- *
- * {@link PoiHssfContentTransformer} handles the Excel
- * transformations (mostly for compatibility), while
- * this does all the other Office file formats.
- *
- * @author Nick Burch
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class PoiContentTransformer extends TikaPoweredContentTransformer
-{
- /**
- * We support all the office mimetypes that the Tika
- * office parser can handle, except for excel
- * (handled by {@link PoiHssfContentTransformer}
- */
- public static ArrayList SUPPORTED_MIMETYPES;
- static {
- SUPPORTED_MIMETYPES = new ArrayList();
- Parser p = new OfficeParser();
- for(MediaType mt : p.getSupportedTypes(null)) {
- if(mt.toString().equals(MimetypeMap.MIMETYPE_EXCEL))
- {
- // Skip, handled elsewhere
- continue;
- }
- // Tika can probably do some useful text
- SUPPORTED_MIMETYPES.add( mt.toString() );
- }
- }
-
- public PoiContentTransformer() {
- super(SUPPORTED_MIMETYPES);
- setTransformerName("Office");
- }
-
- @Override
- protected Parser getParser() {
- return new OfficeParser();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/PoiHssfContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/PoiHssfContentTransformer.java
deleted file mode 100644
index e2a2ba78cf..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/PoiHssfContentTransformer.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.Writer;
-import java.util.regex.Pattern;
-
-import javax.xml.transform.TransformerConfigurationException;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.repo.content.TikaOfficeDetectParser;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.sax.BodyContentHandler;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-/**
- * Uses Apache Tika and
- * Apache POI to perform
- * conversions from Excel spreadsheets.
- * Will transform from Excel spreadsheets into Html,
- * Xml or Text (space or comma separated)
- *
Handles all sheets in the file.
- *
- * @author Nick Burch
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class PoiHssfContentTransformer extends TikaPoweredContentTransformer
-{
- /**
- * Error message to delegate to NodeInfoBean
- */
- public static final String WRONG_FORMAT_MESSAGE_ID = "transform.err.format_or_password";
- private static Log logger = LogFactory.getLog(PoiHssfContentTransformer.class);
-
- public PoiHssfContentTransformer()
- {
- super(new String[] {
- MimetypeMap.MIMETYPE_EXCEL,
- MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET
- });
- setTransformerName("Poi");
- }
-
- @Override
- protected Parser getParser()
- {
- return new TikaOfficeDetectParser();
- }
-
- /**
- * Can we do the requested transformation via Tika?
- * We support transforming to HTML, XML, Text or CSV
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if(sourceMimeTypes.contains(sourceMimetype) &&
- MimetypeMap.MIMETYPE_TEXT_CSV.equals(targetMimetype))
- {
- // Special case for CSV
- return true;
- }
-
- // Otherwise fall back on the default Tika rules
- return super.isTransformableMimetype(sourceMimetype, targetMimetype, options);
- }
-
- /**
- * Make sure we win over openoffice when it comes to producing
- * HTML
- */
- @Override
- public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if(sourceMimeTypes.contains(sourceMimetype) &&
- (MimetypeMap.MIMETYPE_HTML.equals(targetMimetype) ||
- MimetypeMap.MIMETYPE_XHTML.equals(targetMimetype)) )
- {
- // Special case to win for HTML
- return true;
- }
-
- // Otherwise fall back on the default Tika rules
- return super.isTransformableMimetype(sourceMimetype, targetMimetype, options);
- }
-
- @Override
- protected ContentHandler getContentHandler(String targetMimeType, Writer output)
- throws TransformerConfigurationException
- {
- if(MimetypeMap.MIMETYPE_TEXT_CSV.equals(targetMimeType))
- {
- return new CsvContentHandler(output);
- }
-
- // Otherwise use the normal Tika rules
- return super.getContentHandler(targetMimeType, output);
- }
-
- /**
- * A wrapper around the normal Tika BodyContentHandler,
- * which causes things to be CSV encoded rather than
- * tab separated
- */
- protected static class CsvContentHandler extends BodyContentHandler {
- private static final char[] comma = new char[]{ ',' };
- private static final Pattern all_nums = Pattern.compile("[\\d\\.\\-\\+]+");
-
- private boolean inCell = false;
- private boolean needsComma = false;
-
- protected CsvContentHandler(Writer output) {
- super(output);
- }
-
- @Override
- public void ignorableWhitespace(char[] ch, int start, int length)
- throws SAXException {
- if(length == 1 && ch[0] == '\t') {
- // Ignore tabs, as they mess up the CSV output
- } else {
- super.ignorableWhitespace(ch, start, length);
- }
- }
-
- @Override
- public void characters(char[] ch, int start, int length)
- throws SAXException {
- if(inCell) {
- StringBuffer t = new StringBuffer(new String(ch,start,length));
-
- // Quote if not all numbers
- if(all_nums.matcher(t).matches())
- {
- super.characters(ch, start, length);
- }
- else
- {
- for(int i=t.length()-1; i>=0; i--) {
- if(t.charAt(i) == '\"') {
- // Double up double quotes
- t.insert(i, '\"');
- i--;
- }
- }
- t.insert(0, '\"');
- t.append('\"');
- char[] c = t.toString().toCharArray();
- super.characters(c, 0, c.length);
- }
- } else {
- super.characters(ch, start, length);
- }
- }
-
- @Override
- public void startElement(String uri, String localName, String name,
- Attributes atts) throws SAXException {
- if(localName.equals("td")) {
- inCell = true;
- if(needsComma) {
- super.characters(comma, 0, 1);
- needsComma = true;
- }
- } else {
- super.startElement(uri, localName, name, atts);
- }
- }
-
- @Override
- public void endElement(String uri, String localName, String name)
- throws SAXException {
- if(localName.equals("td")) {
- needsComma = true;
- inCell = false;
- } else {
- if(localName.equals("tr")) {
- needsComma = false;
- }
- super.endElement(uri, localName, name);
- }
- }
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/PoiOOXMLContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/PoiOOXMLContentTransformer.java
deleted file mode 100644
index 056239dae9..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/PoiOOXMLContentTransformer.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.ArrayList;
-
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.parser.microsoft.ooxml.OOXMLParser;
-
-/**
- * Uses Apache Tika and
- * Apache POI to perform
- * conversions from the newer OOXML Office documents.
- *
- * @author Nick Burch
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class PoiOOXMLContentTransformer extends TikaPoweredContentTransformer
-{
- /**
- * We support all the office mimetypes that the Tika
- * office parser can handle
- */
- public static ArrayList SUPPORTED_MIMETYPES;
- static {
- SUPPORTED_MIMETYPES = new ArrayList();
- Parser p = new OOXMLParser();
- for(MediaType mt : p.getSupportedTypes(null)) {
- SUPPORTED_MIMETYPES.add( mt.toString() );
- }
- }
-
- public PoiOOXMLContentTransformer() {
- super(SUPPORTED_MIMETYPES);
- setUseTimeoutThread(true);
- setTransformerName("OOXML");
- }
-
- @Override
- protected Parser getParser() {
- return new OOXMLParser();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/ProxyContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/ProxyContentTransformer.java
deleted file mode 100644
index 529c4fa0b7..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/ProxyContentTransformer.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.artofsolving.jodconverter.document.DocumentFormatRegistry;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptionLimits;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-
-/**
- * Makes use of a {@link ContentTransformerWorker} to perform conversions.
- *
- * @author dward
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public class ProxyContentTransformer extends AbstractContentTransformer2
-{
- private ContentTransformerWorker worker;
-
- public ProxyContentTransformer()
- {
- }
-
- /**
- * @param worker
- * the worker that the converter uses
- */
- public void setWorker(ContentTransformerWorker worker)
- {
- this.worker = worker;
- }
-
- /**
- * Returns the worker that the converter uses
- */
- public ContentTransformerWorker getWorker()
- {
- return this.worker;
- }
-
- /**
- * THIS IS A CUSTOM SPRING INIT METHOD
- */
- public void register()
- {
- if (worker instanceof ContentTransformerHelper)
- {
- logDeprecatedSetter(((ContentTransformerHelper)worker).deprecatedSetterMessages);
- }
- super.register();
- }
-
- /**
- * @see DocumentFormatRegistry
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return this.worker.isTransformable(sourceMimetype, targetMimetype, options);
- }
-
- @Override
- public String getComments(boolean available)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(super.getComments(available));
- sb.append(worker.getComments(false));
- return sb.toString();
- }
-
- protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws Exception
- {
- TransformationOptionLimits original = options.getLimits();
- try
- {
- // Combine the transformer's limit values into the options so they are available to the worker
- options.setLimits(getLimits(reader, writer, options));
-
- // Perform the transformation
- this.worker.transform(reader, writer, options);
- }
- finally
- {
- options.setLimits(original);
- }
- }
-
- boolean remoteTransformerClientConfigured()
- {
- return worker.remoteTransformerClientConfigured();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/RuntimeExecutableContentTransformerWorker.java b/repository/src/main/java/org/alfresco/repo/content/transform/RuntimeExecutableContentTransformerWorker.java
deleted file mode 100644
index bd6c6ecc89..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/RuntimeExecutableContentTransformerWorker.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.service.cmr.repository.ContentIOException;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.TempFileProvider;
-import org.alfresco.util.exec.RuntimeExec;
-import org.alfresco.util.exec.RuntimeExec.ExecutionResult;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.InitializingBean;
-
-/**
- * This configurable wrapper is able to execute any command line transformation that
- * accepts an input and an output file on the command line.
- *
- * The following parameters are use:
- *
- * - {@link #VAR_SOURCE target} - full path to the source file
- * - {@link #VAR_TARGET source} - full path to the target file
- *
- * Provided that the command executed ultimately transforms the source file
- * and leaves the result in the target file, the transformation should be
- * successful.
- *
- * NOTE: It is only the contents of the files that can be transformed.
- * Any attempt to modify the source or target file metadata will, at best, have
- * no effect, but may ultimately lead to the transformation failing. This is
- * because the files provided are both temporary files that reside in a location
- * outside the system's content store.
- *
- * This transformer requires the setting of the explicitTransformations
- * property.
- *
- * @see org.alfresco.util.exec.RuntimeExec
- *
- * @since 1.1
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public class RuntimeExecutableContentTransformerWorker extends ContentTransformerHelper implements ContentTransformerWorker, InitializingBean
-{
- public static final String VAR_SOURCE = "source";
- public static final String VAR_TARGET = "target";
- public static final String VAR_PAGE_RANGE = "pageRange";
-
- private static Log logger = LogFactory.getLog(RuntimeExecutableContentTransformerWorker.class);
-
- private boolean available;
- private RuntimeExec checkCommand;
- private RuntimeExec transformCommand;
-
- /** Stores the output from the check command */
- private String versionString;
-
- public RuntimeExecutableContentTransformerWorker()
- {
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- sb.append(this.getClass().getSimpleName())
- .append("[ transform=").append(transformCommand).append("\n")
- .append("]");
- return sb.toString();
- }
-
- /**
- * Set the runtime executer that will be called as part of the initialisation
- * to determine if the transformer is able to function. This is optional, but allows
- * the transformer registry to detect and avoid using this instance if it is not working.
- *
- * The command will be considered to have failed if the
- *
- * @param checkCommand the initialisation check command
- */
- public void setCheckCommand(RuntimeExec checkCommand)
- {
- this.checkCommand = checkCommand;
- }
-
- /**
- * Set the runtime executer that will called to perform the actual transformation.
- *
- * @param transformCommand the runtime transform command
- */
- public void setTransformCommand(RuntimeExec transformCommand)
- {
- this.transformCommand = transformCommand;
- }
-
- /**
- * A comma or space separated list of values that, if returned by the executed command,
- * indicate an error value. This defaults to "1, 2".
- *
- * @param errCodesStr String
- */
- public void setErrorCodes(String errCodesStr)
- {
- throw new AlfrescoRuntimeException("content.runtime_exec.property_moved");
- }
-
-
- /**
- * Executes the check command, if present. Any errors will result in this component
- * being rendered unusable within the transformer registry, but may still be called
- * directly.
- */
- public void afterPropertiesSet()
- {
- if (transformCommand == null)
- {
- throw new AlfrescoRuntimeException("Mandatory property 'transformCommand' not set");
- }
-
- // execute the command
- if (checkCommand != null)
- {
- ExecutionResult result = checkCommand.execute();
- // check the return code
- if (this.available = result.getSuccess())
- {
- this.versionString = result.getStdOut().trim();
- }
- else
- {
- logger.error("Failed to start a runtime executable content transformer: \n" + result);
- }
- }
- else
- {
- // no check - just assume it is available
- available = true;
- }
- }
-
- /**
- * If the initialization failed, then it returns 0.0.
- * Otherwise the explicit transformations are checked for the reliability.
- *
- * @return Returns 1.0 if initialization succeeded, otherwise 0.0.
- *
- * @see AbstractContentTransformer#setExplicitTransformations(List)
- */
- public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- return isAvailable();
- }
-
- @Override
- public String getComments(boolean available)
- {
- return "";
- }
-
- /**
- * Signals whether this transformer is available.
- *
- * @return true, if is available
- */
- public boolean isAvailable()
- {
- return this.available;
- }
-
- /**
- * Gets the version string captured from the check command.
- *
- * @return the version string
- */
- public String getVersionString()
- {
- return this.versionString;
- }
-
- /**
- * Converts the source and target content to temporary files with the
- * correct extensions for the mimetype that they map to.
- *
- */
- public final void transform(
- ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception
- {
- // get mimetypes
- String sourceMimetype = getMimetype(reader);
- String targetMimetype = getMimetype(writer);
-
- // get the extensions to use
- String sourceExtension = getMimetypeService().getExtension(sourceMimetype);
- String targetExtension = getMimetypeService().getExtension(targetMimetype);
- if (sourceExtension == null || targetExtension == null)
- {
- throw new AlfrescoRuntimeException("Unknown extensions for mimetypes: \n" +
- " source mimetype: " + sourceMimetype + "\n" +
- " source extension: " + sourceExtension + "\n" +
- " target mimetype: " + targetMimetype + "\n" +
- " target extension: " + targetExtension);
- }
-
- // create required temp files
- File sourceFile = TempFileProvider.createTempFile(
- getClass().getSimpleName() + "_source_",
- "." + sourceExtension);
- File targetFile = TempFileProvider.createTempFile(
- getClass().getSimpleName() + "_target_",
- "." + targetExtension);
-
- Map properties = new HashMap(5);
- // copy options over
- Map optionsMap = options.toMap();
- for (Map.Entry entry : optionsMap.entrySet())
- {
- String key = entry.getKey();
- Object value = entry.getValue();
- properties.put(key, (value == null ? null : value.toString()));
- }
- // add the source and target properties
- properties.put(VAR_SOURCE, sourceFile.getAbsolutePath());
- properties.put(VAR_TARGET, targetFile.getAbsolutePath());
- properties.put(VAR_PAGE_RANGE, "0-"+(options.getPageLimit() >=0 ? options.getPageLimit() : ""));
-
- // pull reader file into source temp file
- reader.getContent(sourceFile);
-
- // execute the transformation command
- long timeoutMs = options.getTimeoutMs();
- ExecutionResult result = null;
- try
- {
- result = transformCommand.execute(properties, timeoutMs);
- }
- catch (Throwable e)
- {
- throw new ContentIOException("Transformation failed during command execution: \n" + transformCommand, e);
- }
-
- // check
- if (!result.getSuccess())
- {
- throw new ContentIOException("Transformation failed - status indicates an error: \n" + result);
- }
-
- // check that the file was created
- if (!targetFile.exists())
- {
- throw new ContentIOException("Transformation failed - target file doesn't exist: \n" + result);
- }
- // copy the target file back into the repo
- writer.putContent(targetFile);
-
- // done
- if (logger.isDebugEnabled())
- {
- logger.debug("Transformation completed: \n" +
- " source: " + reader + "\n" +
- " target: " + writer + "\n" +
- " options: " + options + "\n" +
- " result: \n" + result);
- }
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/StringExtractingContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/StringExtractingContentTransformer.java
deleted file mode 100644
index 12a1fbbc46..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/StringExtractingContentTransformer.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
-import static org.alfresco.repo.rendition2.RenditionDefinition2.TARGET_ENCODING;
-
-/**
- * Converts any textual format to plain text.
- *
- * The transformation is sensitive to the source and target string encodings.
- *
- * @author Derek Hulley
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class StringExtractingContentTransformer extends AbstractRemoteContentTransformer
-{
- public static final String PREFIX_TEXT = "text/";
-
- private static final Log logger = LogFactory.getLog(StringExtractingContentTransformer.class);
-
- /**
- * Gives a high reliability for all translations from text/sometype to
- * text/plain. As the text formats are already text, the characters
- * are preserved and no actual conversion takes place.
- *
- * Extraction of text from binary data is wholly unreliable.
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if (!targetMimetype.equals(MimetypeMap.MIMETYPE_TEXT_PLAIN))
- {
- // can only convert to plain text
- return false;
- }
- else if (sourceMimetype.equals(MimetypeMap.MIMETYPE_TEXT_PLAIN) ||
- sourceMimetype.equals(MimetypeMap.MIMETYPE_JAVASCRIPT))
- {
- // conversions from any plain text format are very reliable
- return true;
- }
- else if (sourceMimetype.startsWith(PREFIX_TEXT) ||
- sourceMimetype.equals(MimetypeMap.MIMETYPE_DITA))
- {
- // the source is text, but probably with some kind of markup
- return true;
- }
- else
- {
- // extracting text from binary is not useful
- return false;
- }
- }
-
- @Override
- public String getComments(boolean available)
- {
- StringBuilder sb = new StringBuilder();
- sb.append(super.getComments(available));
- sb.append("# Only supports transformation of js, dita and mimetypes starting with \"");
- sb.append(PREFIX_TEXT);
- sb.append("\" to txt.\n");
- return sb.toString();
- }
-
- @Override
- protected Log getLogger()
- {
- return logger;
- }
-
- /**
- * Text to text conversions are done directly using the content reader and writer string
- * manipulation methods.
- *
- * Extraction of text from binary content attempts to take the possible character
- * encoding into account. The text produced from this will, if the encoding was correct,
- * be unformatted but valid.
- */
- @Override
- public void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws Exception
- {
- // is this a straight text-text transformation
- transformText(reader, writer, options);
- }
-
- /**
- * Transformation optimized for text-to-text conversion
- */
- private void transformText(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception
- {
- // get a char reader and writer
- Reader charReader = null;
- Writer charWriter = null;
- try
- {
- if (reader.getEncoding() == null)
- {
- charReader = new InputStreamReader(reader.getContentInputStream());
- }
- else
- {
- charReader = new InputStreamReader(reader.getContentInputStream(), reader.getEncoding());
- }
- if (writer.getEncoding() == null)
- {
- charWriter = new OutputStreamWriter(writer.getContentOutputStream());
- }
- else
- {
- charWriter = new OutputStreamWriter(writer.getContentOutputStream(), writer.getEncoding());
- }
- // copy from the one to the other
- char[] buffer = new char[8192];
- int readCount = 0;
- while (readCount > -1)
- {
- // write the last read count number of bytes
- charWriter.write(buffer, 0, readCount);
- // fill the buffer again
- readCount = charReader.read(buffer);
- }
- }
- finally
- {
- if (charReader != null)
- {
- try { charReader.close(); } catch (Throwable e) { logger.error(e); }
- }
- if (charWriter != null)
- {
- try { charWriter.close(); } catch (Throwable e) { logger.error(e); }
- }
- }
- // done
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options, String sourceMimetype,
- String targetMimetype, String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- String sourceEncoding = reader.getEncoding();
- long timeoutMs = options.getTimeoutMs();
-
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "string",
- "sourceMimetype", sourceMimetype,
- "targetMimetype", targetMimetype,
- "targetExtension", targetExtension,
- SOURCE_ENCODING, sourceEncoding,
- TARGET_ENCODING, targetEncoding);
-
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/SupportedTransformation.java b/repository/src/main/java/org/alfresco/repo/content/transform/SupportedTransformation.java
deleted file mode 100644
index b26bdf9d50..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/SupportedTransformation.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-/**
- * Represents a supported transformation. Normally used in a spring bean that limits
- * the number of supported configures.
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class SupportedTransformation
-{
- private String sourceMimetype;
- private String targetMimetype;
-
- public SupportedTransformation()
- {
- }
-
- public SupportedTransformation(String sourceMimetype, String targetMimetype)
- {
- this.sourceMimetype = sourceMimetype;
- this.targetMimetype = targetMimetype;
- }
-
- public void setSourceMimetype(String sourceMimetype)
- {
- this.sourceMimetype = sourceMimetype;
- }
-
- public String getSourceMimetype()
- {
- return sourceMimetype;
- }
-
- public void setTargetMimetype(String targetMimetype)
- {
- this.targetMimetype = targetMimetype;
- }
-
- public String getTargetMimetype()
- {
- return targetMimetype;
- }
-}
\ No newline at end of file
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/TextMiningContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/TextMiningContentTransformer.java
deleted file mode 100644
index a13fb007dd..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/TextMiningContentTransformer.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.parser.microsoft.OfficeParser;
-
-/**
- * This badly named transformer turns Microsoft Word documents
- * (Word 6, 95, 97, 2000, 2003) into plain text, using Apache Tika.
- *
- * @author Nick Burch
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class TextMiningContentTransformer extends TikaPoweredContentTransformer
-{
- public TextMiningContentTransformer()
- {
- super(new String[] {
- MimetypeMap.MIMETYPE_WORD
- });
- setTransformerName("TextMining");
- }
-
- @Override
- protected Parser getParser() {
- return new OfficeParser();
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/TextToPdfContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/TextToPdfContentTransformer.java
deleted file mode 100644
index 9c7ee37483..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/TextToPdfContentTransformer.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptionLimits;
-import org.alfresco.service.cmr.repository.TransformationOptionPair;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.PDPageContentStream;
-import org.apache.pdfbox.pdmodel.font.PDType1Font;
-import org.apache.pdfbox.tools.TextToPDF;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.alfresco.repo.rendition2.RenditionDefinition2.SOURCE_ENCODING;
-
-/**
- * Makes use of the PDFBox library's TextToPDF
utility.
- *
- * @author Derek Hulley
- * @since 2.1.0
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class TextToPdfContentTransformer extends AbstractRemoteContentTransformer
-{
- private static final Log logger = LogFactory.getLog(TextToPdfContentTransformer.class);
-
- private PagedTextToPDF transformer;
-
- public TextToPdfContentTransformer()
- {
- setPageLimitsSupported(true);
- transformer = new PagedTextToPDF();
- }
-
- public void setStandardFont(String fontName)
- {
- try
- {
- transformer.setFont(transformer.getStandardFont(fontName));
- }
- catch (Throwable e)
- {
- throw new AlfrescoRuntimeException("Unable to set Standard Font for PDF generation: " + fontName, e);
- }
- }
-
- public void setFontSize(int fontSize)
- {
- try
- {
- transformer.setFontSize(fontSize);
- }
- catch (Throwable e)
- {
- throw new AlfrescoRuntimeException("Unable to set Font Size for PDF generation: " + fontSize);
- }
- }
-
- /**
- * Only supports Text to PDF
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if ( (!MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(sourceMimetype) &&
- !MimetypeMap.MIMETYPE_TEXT_CSV.equals(sourceMimetype) &&
- !MimetypeMap.MIMETYPE_DITA.equals(sourceMimetype) &&
- !MimetypeMap.MIMETYPE_XML.equals(sourceMimetype) ) ||
- !MimetypeMap.MIMETYPE_PDF.equals(targetMimetype))
- {
- // only support (text/plain OR text/csv OR text/xml) to (application/pdf)
- return false;
- }
- else
- {
- return true;
- }
- }
-
- @Override
- public String getComments(boolean available)
- {
- return getCommentsOnlySupports(
- Arrays.asList(new String[] {MimetypeMap.MIMETYPE_TEXT_PLAIN, MimetypeMap.MIMETYPE_TEXT_CSV,
- MimetypeMap.MIMETYPE_DITA, MimetypeMap.MIMETYPE_XML}),
- Arrays.asList(new String[] {MimetypeMap.MIMETYPE_PDF}), available);
- }
-
- @Override
- protected Log getLogger()
- {
- return logger;
- }
-
- @Override
- protected void transformLocal(
- ContentReader reader,
- ContentWriter writer,
- TransformationOptions options) throws Exception
- {
- PDDocument pdf = null;
- InputStream is = null;
- InputStreamReader ir = null;
- OutputStream os = null;
- try
- {
- is = reader.getContentInputStream();
- ir = buildReader(is, reader.getEncoding(), reader.getContentUrl());
-
- TransformationOptionLimits limits = getLimits(reader, writer, options);
- TransformationOptionPair pageLimits = limits.getPagesPair();
- pdf = transformer.createPDFFromText(ir, pageLimits, reader.getContentUrl(), transformerDebug);
-
- // dump it all to the writer
- os = writer.getContentOutputStream();
- pdf.save(os);
- }
- finally
- {
- if (pdf != null)
- {
- try { pdf.close(); } catch (Throwable e) {e.printStackTrace(); }
- }
- if (ir != null)
- {
- try { ir.close(); } catch (Throwable e) {e.printStackTrace(); }
- }
- if (is != null)
- {
- try { is.close(); } catch (Throwable e) {e.printStackTrace(); }
- }
- if (os != null)
- {
- try { os.close(); } catch (Throwable e) {e.printStackTrace(); }
- }
- }
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options, String sourceMimetype,
- String targetMimetype, String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- String sourceEncoding = reader.getEncoding();
- long timeoutMs = options.getTimeoutMs();
-
- TransformationOptionLimits limits = getLimits(reader, writer, options);
- TransformationOptionPair pageLimits = limits.getPagesPair();
- int pageLimit = (int)pageLimits.getValue();
-
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", "textToPdf",
- "sourceMimetype", sourceMimetype,
- "targetMimetype", targetMimetype,
- "targetExtension", targetExtension,
- SOURCE_ENCODING, sourceEncoding,
- "pageLimit", String.valueOf(pageLimit));
- }
-
- protected InputStreamReader buildReader(InputStream is, String encoding, String node)
- {
- // If they gave an encoding, try to use it
- if(encoding != null)
- {
- Charset charset = null;
- try
- {
- charset = Charset.forName(encoding);
- } catch(Exception e)
- {
- logger.warn("JVM doesn't understand encoding '" + encoding +
- "' when transforming " + node);
- }
- if(charset != null)
- {
- logger.debug("Processing plain text in encoding " + charset.displayName());
- return new InputStreamReader(is, charset);
- }
- }
-
- // Fall back on the system default
- logger.debug("Processing plain text using system default encoding");
- return new InputStreamReader(is);
- }
-
- private static class PagedTextToPDF extends TextToPDF
- {
- // REPO-1066: duplicating the following lines from org.apache.pdfbox.tools.TextToPDF because they made them private
- // before the upgrade to pdfbox 2.0.8, in pdfbox 1.8, this piece of code was public in org.apache.pdfbox.pdmodel.font.PDType1Font
- static PDType1Font getStandardFont(String name) {
- return (PDType1Font)STANDARD_14.get(name);
- }
- private static final Map STANDARD_14 = new HashMap();
- static
- {
- STANDARD_14.put(PDType1Font.TIMES_ROMAN.getBaseFont(), PDType1Font.TIMES_ROMAN);
- STANDARD_14.put(PDType1Font.TIMES_BOLD.getBaseFont(), PDType1Font.TIMES_BOLD);
- STANDARD_14.put(PDType1Font.TIMES_ITALIC.getBaseFont(), PDType1Font.TIMES_ITALIC);
- STANDARD_14.put(PDType1Font.TIMES_BOLD_ITALIC.getBaseFont(), PDType1Font.TIMES_BOLD_ITALIC);
- STANDARD_14.put(PDType1Font.HELVETICA.getBaseFont(), PDType1Font.HELVETICA);
- STANDARD_14.put(PDType1Font.HELVETICA_BOLD.getBaseFont(), PDType1Font.HELVETICA_BOLD);
- STANDARD_14.put(PDType1Font.HELVETICA_OBLIQUE.getBaseFont(), PDType1Font.HELVETICA_OBLIQUE);
- STANDARD_14.put(PDType1Font.HELVETICA_BOLD_OBLIQUE.getBaseFont(), PDType1Font.HELVETICA_BOLD_OBLIQUE);
- STANDARD_14.put(PDType1Font.COURIER.getBaseFont(), PDType1Font.COURIER);
- STANDARD_14.put(PDType1Font.COURIER_BOLD.getBaseFont(), PDType1Font.COURIER_BOLD);
- STANDARD_14.put(PDType1Font.COURIER_OBLIQUE.getBaseFont(), PDType1Font.COURIER_OBLIQUE);
- STANDARD_14.put(PDType1Font.COURIER_BOLD_OBLIQUE.getBaseFont(), PDType1Font.COURIER_BOLD_OBLIQUE);
- STANDARD_14.put(PDType1Font.SYMBOL.getBaseFont(), PDType1Font.SYMBOL);
- STANDARD_14.put(PDType1Font.ZAPF_DINGBATS.getBaseFont(), PDType1Font.ZAPF_DINGBATS);
- }
- //duplicating until here
-
- // The following code is based on the code in TextToPDF with the addition of
- // checks for page limits.
- // The calling code must close the PDDocument once finished with it.
- public PDDocument createPDFFromText(Reader text, TransformationOptionPair pageLimits, String contentUrl, TransformerDebug transformerDebug)
- throws IOException
- {
- int pageLimit = (int)pageLimits.getValue();
- PDDocument doc = null;
- int pageCount = 0;
- try
- {
- final int margin = 40;
- float height = getFont().getFontDescriptor().getFontBoundingBox().getHeight()/1000;
-
- //calculate font height and increase by 5 percent.
- height = height*getFontSize()*1.05f;
- doc = new PDDocument();
- BufferedReader data = new BufferedReader( text );
- String nextLine = null;
- PDPage page = new PDPage();
- PDPageContentStream contentStream = null;
- float y = -1;
- float maxStringLength = page.getMediaBox().getWidth() - 2*margin;
-
- // There is a special case of creating a PDF document from an empty string.
- boolean textIsEmpty = true;
-
- outer:
- while( (nextLine = data.readLine()) != null )
- {
-
- // The input text is nonEmpty. New pages will be created and added
- // to the PDF document as they are needed, depending on the length of
- // the text.
- textIsEmpty = false;
-
- String[] lineWords = nextLine.trim().split( " " );
- int lineIndex = 0;
- while( lineIndex < lineWords.length )
- {
- StringBuffer nextLineToDraw = new StringBuffer();
- float lengthIfUsingNextWord = 0;
- do
- {
- nextLineToDraw.append( lineWords[lineIndex] );
- nextLineToDraw.append( " " );
- lineIndex++;
- if( lineIndex < lineWords.length )
- {
- String lineWithNextWord = nextLineToDraw.toString() + lineWords[lineIndex];
- lengthIfUsingNextWord =
- (getFont().getStringWidth( lineWithNextWord )/1000) * getFontSize();
- }
- }
- while( lineIndex < lineWords.length &&
- lengthIfUsingNextWord < maxStringLength );
- if( y < margin )
- {
- if (pageLimit > 0 && pageCount++ >= pageLimit)
- {
- pageLimits.getAction().throwIOExceptionIfRequired("Page limit ("+pageLimit+
- ") reached.", transformerDebug);
- break outer;
- }
-
- // We have crossed the end-of-page boundary and need to extend the
- // document by another page.
- page = new PDPage();
- doc.addPage( page );
- if( contentStream != null )
- {
- contentStream.endText();
- contentStream.close();
- }
- contentStream = new PDPageContentStream(doc, page);
- contentStream.setFont(getFont(), getFontSize());
- contentStream.beginText();
- y = page.getMediaBox().getHeight() - margin + height;
- contentStream.moveTextPositionByAmount(
- margin, y );
- }
- //System.out.println( "Drawing string at " + x + "," + y );
-
- if( contentStream == null )
- {
- throw new IOException( "Error:Expected non-null content stream." );
- }
- contentStream.moveTextPositionByAmount( 0, -height);
- y -= height;
- contentStream.drawString( nextLineToDraw.toString() );
- }
- }
-
- // If the input text was the empty string, then the above while loop will have short-circuited
- // and we will not have added any PDPages to the document.
- // So in order to make the resultant PDF document readable by Adobe Reader etc, we'll add an empty page.
- if (textIsEmpty)
- {
- doc.addPage(page);
- }
-
- if( contentStream != null )
- {
- contentStream.endText();
- contentStream.close();
- }
- }
- catch( IOException io )
- {
- if( doc != null )
- {
- doc.close();
- }
- throw io;
- }
- return doc;
- }
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/TikaAutoContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/TikaAutoContentTransformer.java
deleted file mode 100644
index 0e52b8f76e..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/TikaAutoContentTransformer.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.ArrayList;
-
-import org.apache.tika.config.TikaConfig;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AutoDetectParser;
-import org.apache.tika.parser.Parser;
-
-/**
- * A Content Extractor for XML, HTML and Text,
- * which makes use of the Apache Tika
- * auto-detection to select the best parser
- * to process your document.
- * This will be used for all files which Tika can
- * handle, but where no other more explicit
- * extractor is defined.
- *
- * @author Nick Burch
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class TikaAutoContentTransformer extends TikaPoweredContentTransformer
-{
- private static AutoDetectParser parser;
- private static TikaConfig config;
-
- /**
- * We support all the mimetypes that the Tika
- * auto-detect parser can handle, except for
- * Image, Audio and Video ones which don't
- * make much sense
- */
- public static ArrayList SUPPORTED_MIMETYPES;
- private static ArrayList buildMimeTypes(TikaConfig tikaConfig)
- {
- config = tikaConfig;
- parser = new AutoDetectParser(config);
-
- SUPPORTED_MIMETYPES = new ArrayList();
- for(MediaType baseType : parser.getParsers().keySet())
- {
- // Register both the canonical type, and any alias it may have
- // Alfresco sometimes uses the canonical type, and sometimes an alias
- ArrayList types = new ArrayList();
- types.add(baseType);
- types.addAll( config.getMediaTypeRegistry().getAliases(baseType) );
-
- for(MediaType mt : types)
- {
- if(mt.toString().startsWith("application/vnd.oasis.opendocument.formula")) {
- // TODO Tika support for quick.odf, mimetype=application/vnd.oasis.opendocument.formula
- // TODO Tika support for quick.otf, mimetype=application/vnd.oasis.opendocument.formula-template
- continue;
- }
- if(mt.toString().startsWith("application/vnd.oasis.opendocument.graphics")) {
- // TODO Tika support for quick.odg, mimetype=application/vnd.oasis.opendocument.graphics
- // TODO Tika support for quick.otg, mimetype=application/vnd.oasis.opendocument.graphics-template
- continue;
- }
-
- if(mt.getType().equals("image") ||
- mt.getType().equals("audio") ||
- mt.getType().equals("video"))
- {
- // Skip these, as Tika mostly just does
- // metadata rather than content
- }
- else if(mt.toString().equals("application/zip") ||
- mt.toString().equals("application/tar") ||
- mt.toString().equals("application/x-tar"))
- {
- // Skip these, as we handle container formats in a different
- // transformer to give the user control over recursion
- }
- else if(mt.toString().equals("message/rfc822") ||
- mt.toString().equals("application/vnd.ms-outlook"))
- {
- // Skip these, as we want our textual representations to include
- // parts of the metadata (eg people, subjects, dates) too
- }
- else
- {
- // Tika can probably do some useful text
- SUPPORTED_MIMETYPES.add( mt.toString() );
- }
- }
- }
- return SUPPORTED_MIMETYPES;
- }
-
- public TikaAutoContentTransformer(TikaConfig tikaConfig)
- {
- super( buildMimeTypes(tikaConfig) );
- setUseTimeoutThread(true);
- setTransformerName("TikaAuto");
- }
-
- /**
- * Returns the Tika Auto-Detection
- * parser, which will try to
- * process all documents that Tika
- * knows about
- */
- protected Parser getParser()
- {
- return parser;
- }
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/TikaPoweredContainerExtractor.java b/repository/src/main/java/org/alfresco/repo/content/transform/TikaPoweredContainerExtractor.java
deleted file mode 100644
index 4b1011800c..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/TikaPoweredContainerExtractor.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.model.ContentModel;
-import org.alfresco.repo.action.ParameterDefinitionImpl;
-import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
-import org.alfresco.service.cmr.action.Action;
-import org.alfresco.service.cmr.action.ParameterDefinition;
-import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentService;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.namespace.QName;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tika.config.TikaConfig;
-import org.apache.tika.detect.DefaultDetector;
-import org.apache.tika.detect.Detector;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.extractor.EmbeddedResourceHandler;
-import org.apache.tika.extractor.ParserContainerExtractor;
-import org.apache.tika.io.TikaInputStream;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AutoDetectParser;
-
-/**
- * Warning - this is a prototype service, and will likely change dramatically
- * in Alfresco 4.0!
- *
- * This proto-service provides a way to have Apache Tika extract out
- * certain kinds of embedded resources from within a container file.
- *
- * One use might be to extract all the images in a zip file, another might
- * be to fetch all the Word Documents embedded in an Excel Spreadsheet.
- *
- * Uses the Apache Tika ContainerExtractor framework, along with the
- * Apache Tika Auto-Parser.
- *
- * Not sprung-in by default, you will need to manually list this in
- * an extension context file.
- *
- * @author Nick Burch
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class TikaPoweredContainerExtractor
-{
- private static final Log logger = LogFactory.getLog(TikaPoweredContainerExtractor.class);
-
- private NodeService nodeService;
- private ContentService contentService;
-
- private TikaConfig config;
- private AutoDetectParser parser;
- private Detector detector;
-
- /**
- * Injects the nodeService bean.
- *
- * @param nodeService the nodeService.
- */
- public void setNodeService(NodeService nodeService)
- {
- this.nodeService = nodeService;
- }
-
- /**
- * Injects the contentService bean.
- *
- * @param contentService the contentService.
- */
- public void setContentService(ContentService contentService)
- {
- this.contentService = contentService;
- }
-
- /**
- * Injects the TikaConfig to use
- *
- * @param tikaConfig The Tika Config to use
- */
- public void setTikaConfig(TikaConfig tikaConfig)
- {
- this.config = tikaConfig;
-
- // Setup the detector and parser
- detector = new DefaultDetector(config.getMimeRepository());
- parser = new AutoDetectParser(detector);
- }
-
- /**
- * Extracts out all the entries from the container
- * that match the supplied list of mime types.
- * If no mime types are specified, extracts all
- * available embedded resources.
- */
- public List extract(NodeRef source, List mimetypes)
- {
- // Grab the directory to put the nodes into
- // Will be the parent folder of the source
- NodeRef folder = nodeService.getPrimaryParent(source).getParentRef();
-
- // Get the contents
- ContentReader reader = contentService.getReader(source, ContentModel.PROP_CONTENT);
- InputStream wrappedInputStream = null;
- TikaInputStream stream = null;
- Extractor handler = null;
- try {
- wrappedInputStream = reader.getContentInputStream();
- stream = TikaInputStream.get(wrappedInputStream);
- // Build the recursing parser
- handler = new Extractor(folder, mimetypes);
-
- // Have Tika look for things
- ParserContainerExtractor extractor = new ParserContainerExtractor(
- parser, detector
- );
- logger.info("Beginning extraction of " + source.toString());
- extractor.extract(stream, null, handler);
- logger.info("Completed extraction of " + source.toString());
- } catch(TikaException te) {
- throw new AlfrescoRuntimeException("Extraction Failed", te);
- } catch(IOException ie) {
- throw new AlfrescoRuntimeException("Extraction Failed", ie);
- }
- finally
- {
- // Tidy up
- if (stream != null)
- {
- try
- {
- stream.close();
- }
- catch (IOException error)
- {
- logger.debug("Error while closing stream.", error);
- }
- }
- if (wrappedInputStream != null)
- {
- try
- {
- wrappedInputStream.close();
- }
- catch (IOException error)
- {
- logger.debug("Error while closing stream.", error);
- }
- }
- }
-
- // All done
- return handler.extracted;
- }
-
- /**
- * This EmbeddedResourceHandler is called by Tika for each
- * embedded resource. It decides if the resource is to
- * be extracted or not, and if it is, saves it into the
- * specified folder.
- */
- private class Extractor implements EmbeddedResourceHandler
- {
- private List extracted;
- private Set acceptTypes;
- private NodeRef folder;
- private int anonymousCount = 0;
-
- private Extractor(NodeRef folder, List types)
- {
- this.folder = folder;
- this.extracted = new ArrayList();
-
- if(types != null && types.size() > 0)
- {
- acceptTypes = new HashSet();
- for(String type : types)
- {
- acceptTypes.add(MediaType.parse(type));
- }
- }
- }
-
- @Override
- public void handle(String filename, MediaType mediaType,
- InputStream stream) {
- // Do we want it?
- if(acceptTypes == null || acceptTypes.contains(mediaType))
- {
- // Ensure we have a filename
- if(filename == null)
- {
- anonymousCount++;
- filename = "embedded"+anonymousCount+"."+mediaType.getSubtype();
- }
-
- logger.info("Extracting embedded " + mediaType + " entry " + filename);
-
- // Save it
- Map properties = new HashMap();
- properties.put(ContentModel.PROP_NAME, filename);
- NodeRef node = nodeService.createNode(
- folder,
- ContentModel.ASSOC_CONTAINS,
- QName.createQName(filename),
- ContentModel.TYPE_CONTENT,
- properties
- ).getChildRef();
-
- ContentWriter writer = contentService.getWriter(
- node, ContentModel.PROP_CONTENT, true
- );
- writer.setMimetype(mediaType.toString());
- writer.putContent(stream);
- }
- else
- {
- logger.info("Skipping embedded " + mediaType + " entry " + filename);
- }
- }
- }
-
- /**
- * This action executor allows you to trigger extraction as an
- * action, perhaps from a rule.
- *
- * Not sprung-in by default, you will need to manually list this in
- * an extension context file. You will also need to add properties
- * files entries.
- */
- public static class ExtractorActionExecutor extends ActionExecuterAbstractBase
- {
- public static final String NAME = "extractEmbeddedResources";
- public static final String PARAM_MIME_TYPES = "mime-types";
-
- private TikaPoweredContainerExtractor extractor;
- public void setTikaPoweredContainerExtractor(TikaPoweredContainerExtractor extractor)
- {
- this.extractor = extractor;
- }
-
- @Override
- protected void addParameterDefinitions(List paramList) {
- paramList.add(new ParameterDefinitionImpl(
- PARAM_MIME_TYPES,
- DataTypeDefinition.TEXT,
- false,
- getParamDisplayLabel(PARAM_MIME_TYPES)
- ));
- }
-
- @Override
- protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
- List mimeTypes = null;
- String rawTypes = (String)action.getParameterValue(PARAM_MIME_TYPES);
- if(rawTypes != null && rawTypes.length() > 0)
- {
- mimeTypes = new ArrayList();
- StringTokenizer st = new StringTokenizer(rawTypes, ",");
- while(st.hasMoreTokens())
- {
- mimeTypes.add( st.nextToken().trim() );
- }
- }
-
- extractor.extract(actionedUponNodeRef, mimeTypes);
- }
- }
-/*
-
-
-
-
-
-
-
- */
-/*
-extractEmbeddedResources.title=Extract embedded resources
-extractEmbeddedResources.description=Extract resources from within container files, such as .zip or .docx
-extractEmbeddedResources.param_mime-types.display-label=Mime Types
- */
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/TikaPoweredContentTransformer.java b/repository/src/main/java/org/alfresco/repo/content/transform/TikaPoweredContentTransformer.java
deleted file mode 100644
index 65bf884c0d..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/TikaPoweredContentTransformer.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
-
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tika.extractor.DocumentSelector;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.parser.Parser;
-import org.apache.tika.sax.BodyContentHandler;
-import org.apache.tika.sax.ExpandedTitleContentHandler;
-import org.xml.sax.ContentHandler;
-
-import static org.alfresco.repo.rendition2.RenditionDefinition2.TARGET_ENCODING;
-
-/**
- * Provides helpful services for {@link org.alfresco.repo.content.transform.ContentTransformer}
- * implementations which are powered by Apache Tika.
- *
- * To use Tika to transform some content into Text, Html or XML, create an
- * implementation of this / use the Auto Detect transformer.
- *
- * For now, all transformers are registered as regular, rather than explicit
- * transformations. This should allow you to register your own explicit
- * transformers and have them nicely take priority.
- *
- * @author Nick Burch
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public abstract class TikaPoweredContentTransformer extends AbstractRemoteContentTransformer
-{
- private static final Log logger = LogFactory.getLog(TikaPoweredContentTransformer.class);
- private static final List TARGET_MIMETYPES = Arrays.asList(new String[] {
- MimetypeMap.MIMETYPE_TEXT_PLAIN,
- MimetypeMap.MIMETYPE_HTML,
- MimetypeMap.MIMETYPE_XHTML,
- MimetypeMap.MIMETYPE_XML});
-
- private static final double MEGABYTES = 1024.0 * 1024.0;
-
- private static final String USAGE_PATTERN = "Content transformation has completed:\n" +
- " Transformer: %s\n" +
- " Content Reader: %s\n" +
- " Memory (MB): Used/Total/Maximum - %f/%f/%f\n" +
- " Time Spent: %d ms";
-
- protected List sourceMimeTypes;
- private String transformerName;
- protected DocumentSelector documentSelector;
-
- /**
- * Windows carriage return line feed pair.
- */
- protected static final String LINE_BREAK = "\r\n";
- public static final String WRONG_FORMAT_MESSAGE_ID = "transform.err.format_or_password";
-
- protected TikaPoweredContentTransformer(List sourceMimeTypes)
- {
- this.sourceMimeTypes = sourceMimeTypes;
- }
-
- protected TikaPoweredContentTransformer(String[] sourceMimeTypes)
- {
- this(Arrays.asList(sourceMimeTypes));
- }
-
- public void setTransformerName(String transformerName)
- {
- this.transformerName = transformerName;
- }
-
- @Override
- protected Log getLogger()
- {
- return logger;
- }
-
- /**
- * Returns the correct Tika Parser to process
- * the document.
- * If you don't know which you want, use
- * {@link TikaAutoContentTransformer} which
- * makes use of the Tika auto-detection.
- */
- protected abstract Parser getParser();
-
- /**
- * Can we do the requested transformation via Tika?
- * We support transforming to HTML, XML or Text
- */
- @Override
- public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
- {
- if(! sourceMimeTypes.contains(sourceMimetype))
- {
- // The source isn't one of ours
- return false;
- }
-
- if (TARGET_MIMETYPES.contains(targetMimetype))
- {
- // We can output to this
- return true;
- }
- else
- {
- // We support the source, but not the target
- return false;
- }
- }
-
- @Override
- public String getComments(boolean available)
- {
- return getCommentsOnlySupports(sourceMimeTypes, TARGET_MIMETYPES, available);
- }
-
- /**
- * Returns an appropriate Tika ContentHandler for the
- * requested content type. Normally you'll let this
- * work as default, but if you need fine-grained
- * control of how the Tika events become text then
- * override and supply your own.
- */
- protected ContentHandler getContentHandler(String targetMimeType, Writer output)
- throws TransformerConfigurationException
- {
- if(MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(targetMimeType))
- {
- return new BodyContentHandler(output);
- }
-
- SAXTransformerFactory factory = (SAXTransformerFactory)
- SAXTransformerFactory.newInstance();
- TransformerHandler handler = factory.newTransformerHandler();
- handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
- handler.setResult(new StreamResult(output));
-
- if(MimetypeMap.MIMETYPE_HTML.equals(targetMimeType))
- {
- handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
- return new ExpandedTitleContentHandler(handler);
- }
- else if(MimetypeMap.MIMETYPE_XHTML.equals(targetMimeType) ||
- MimetypeMap.MIMETYPE_XML.equals(targetMimeType))
- {
- handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
- }
- else
- {
- throw new TransformerInfoException(
- WRONG_FORMAT_MESSAGE_ID,
- new IllegalArgumentException("Requested target type " + targetMimeType + " not supported")
- );
- }
- return handler;
- }
-
- /**
- * Sets the document selector, used for determining whether to parse embedded resources.
- *
- * @param documentSelector DocumentSelector
- */
- public void setDocumentSelector(DocumentSelector documentSelector)
- {
- this.documentSelector = documentSelector;
- }
- /**
- * Gets the document selector, used for determining whether to parse embedded resources,
- * null by default so parse all.
- *
- * @param metadata Metadata
- * @param targetMimeType String
- * @param options TransformationOptions
- * @return the document selector
- */
- protected DocumentSelector getDocumentSelector(Metadata metadata, String targetMimeType, TransformationOptions options)
- {
- return documentSelector;
- }
-
- /**
- * By default returns a ParseContent that does not recurse
- */
- protected ParseContext buildParseContext(Metadata metadata, String targetMimeType, TransformationOptions options)
- {
- ParseContext context = new ParseContext();
- DocumentSelector selector = getDocumentSelector(metadata, targetMimeType, options);
- if (selector != null)
- {
- context.set(DocumentSelector.class, selector);
- }
- return context;
- }
-
- @Override
- public void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options)
- throws Exception
- {
- OutputStream os = writer.getContentOutputStream();
- String encoding = writer.getEncoding();
- String targetMimeType = writer.getMimetype();
-
- Writer ow = new OutputStreamWriter(os, encoding);
-
- Parser parser = getParser();
- Metadata metadata = new Metadata();
-
- ParseContext context = buildParseContext(metadata, targetMimeType, options);
-
- ContentHandler handler = getContentHandler(targetMimeType, ow);
- if(handler == null)
- {
- throw new TransformerConfigurationException(
- "Unable to create Tika Handler for configured output " + targetMimeType
- );
- }
-
- InputStream is = null;
-
- long startTime = 0;
- try {
- is = reader.getContentInputStream();
- if (logger.isDebugEnabled())
- {
- startTime = System.currentTimeMillis();
- }
-
- parser.parse(is, handler, metadata, context);
- }
- finally
- {
- if(logger.isDebugEnabled())
- {
- logger.debug(calculateMemoryAndTimeUsage(reader, startTime));
- }
-
- if (is != null)
- {
- try { is.close(); } catch (Throwable e) {}
- }
- if (ow != null)
- {
- try { ow.close(); } catch (Throwable e) {}
- }
- if (os != null)
- {
- try { os.close(); } catch (Throwable e) {}
- }
- }
- }
-
- @Override
- protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
- ContentWriter writer, TransformationOptions options,
- String sourceMimetype, String targetMimetype,
- String sourceExtension, String targetExtension,
- String targetEncoding) throws Exception
- {
- long timeoutMs = options.getTimeoutMs();
-
- remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
- timeoutMs, logger,
- "transformName", transformerName,
- "sourceMimetype", sourceMimetype,
- "targetMimetype", targetMimetype,
- "targetExtension", targetExtension,
- TARGET_ENCODING, targetEncoding);
- }
-
- private String calculateMemoryAndTimeUsage(ContentReader reader, long startTime)
- {
- long endTime = System.currentTimeMillis();
- Runtime runtime = Runtime.getRuntime();
- long totalMemory = runtime.totalMemory();
- return String.format(USAGE_PATTERN, this.getClass().getName(), reader, (totalMemory - runtime.freeMemory()) / MEGABYTES, totalMemory / MEGABYTES, runtime.maxMemory()
- / MEGABYTES, (endTime - startTime));
- }
-
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/TransformerConfig.java b/repository/src/main/java/org/alfresco/repo/content/transform/TransformerConfig.java
deleted file mode 100644
index 5c1114ba9f..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/TransformerConfig.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.TransformationOptionLimits;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-
-/**
- * Provides access to transformer configuration and current performance data.
- *
- * @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-@AlfrescoPublicApi
-public interface TransformerConfig
-{
- /**
- * Wild card mimetype and mimetype extension.
- */
- public static final String ANY = "*";
-
- /**
- * Prefix before the transformer name of all property names that contain transformer
- * information
- */
- static final String CONTENT = "content.";
-
- /**
- * Prefix for all transformer names
- */
- static final String TRANSFORMER = "transformer.";
-
- /**
- * The combined content and transformer name prefix of for all property names that contain
- * transformer information
- */
- static final String PREFIX = CONTENT+TRANSFORMER;
-
- /**
- * The 'transformer name' for system wide defaults for all transformers
- */
- static final String DEFAULT_TRANSFORMER = TRANSFORMER+"default";
-
- /**
- * Name given to the 'SUMMARY' dummy (does not exist) transformer that gathers data
- * from all root level transformations
- */
- static final String SUMMARY_TRANSFORMER_NAME = "SUMMARY";
-
- /**
- * An optional separator appended after the normal suffix and following value that
- * identifies the 'use' or 'application' of the property. Example uses include 'index'
- * 'doclib' and 'preview'. The corresponding configuration value is only used in the
- * context of the specified usage.
- */
- static final String USE = ".use.";
-
- /**
- * The separator between the transformer name and two mimetype extensions in a property name.
- */
- static final String EXTENSIONS = ".extensions.";
-
- /**
- * The separator between the transformer name and wildcarded mimetypes rather than extensions in a property name.
- * Effectively equivalent to multiple properties using the {@link #EXTENSIONS}.
- */
- static final String MIMETYPES = ".mimetypes.";
-
- /**
- * Both extension and minetype separators.
- */
- public static String[] SEPARATORS = new String[] {EXTENSIONS , MIMETYPES};
-
- /**
- * The suffix to property names for creating dynamic complex transformers
- */
- public static final String PIPELINE = ".pipeline";
-
- /**
- * The suffix to property names for creating dynamic failover transformers
- */
- public static final String FAILOVER = ".failover";
-
- /**
- * The suffix to property names to indicate that a transformer is available.
- * If not specified, defaults to true, indicating it may be selected rather
- * only being available as a component of another transformer.
- */
- public static final String AVAILABLE = ".available";
-
- /**
- * Separator between transformers and mimetype extensions in a dynamic compound property value.
- */
- public static final char PIPE = '|';
-
- /**
- * The suffix to property names for supported and unsupported combinations.
- */
- static final String SUPPORTED = ".supported";
-
- /**
- * The suffix to property names for the priority.
- */
- static final String PRIORITY = ".priority";
-
- /**
- * The suffix to property names for the blacklist.
- */
- static final String BLACKLIST = ".blacklist";
-
- /**
- * The suffix to property names to indicate which Alfresco version the transformer is
- * available with. If not specified it is not restricted. So if set to "Enterprise" it
- * is not available to Community.
- * @see #AMP
- */
- static final String EDITION = ".edition";
-
- /**
- * The suffix to property names to indicate which Alfresco AMPs the transformer is
- * available with. The value should be the AMP's ID. If not specified it is not restricted.
- * @see #EDITION
- */
- static final String AMP = ".amp";
-
- /**
- * The suffix to property names for the threshold count.
- */
- static final String THRESHOLD_COUNT = ".thresholdCount";
-
- /**
- * The suffix to property names for the error time.
- */
- static final String ERROR_TIME = ".errorTime";
-
- /**
- * The suffix to property names for the the average time. Only used in the initial setup of
- * TransformerData. This is a historical property used by the 'Transformation Server' to set
- * an effective priority.
- */
- static final String INITIAL_TIME = ".time";
-
- /**
- * The suffix to property names for the the average count. Only used in the initial setup of
- * TransformerData. This is a historical property used by the 'Transformation Server' to set
- * an effective priority.
- */
- static final String INITIAL_COUNT = ".count";
-
- /**
- * Suffixes for limits.
- */
- static final String MAX_SOURCE_SIZE_K_BYTES = '.'+TransformationOptionLimits.OPT_MAX_SOURCE_SIZE_K_BYTES;
- static final String TIMEOUT_MS = '.'+TransformationOptionLimits.OPT_TIMEOUT_MS;
- static final String MAX_PAGES = '.'+TransformationOptionLimits.OPT_MAX_PAGES;
- static final String READ_LIMIT_K_BYTES = '.'+TransformationOptionLimits.OPT_READ_LIMIT_K_BYTES;
- static final String READ_LIMIT_TIME_MS = '.'+TransformationOptionLimits.OPT_READ_LIMIT_TIME_MS;
- static final String PAGE_LIMIT = '.'+TransformationOptionLimits.OPT_PAGE_LIMIT;
-
- /**
- * To support the historical concept of EXPLICIT transformers, all such transformers
- * are given a {@link #PRIORITY_EXPLICIT} (50). By default transformers have a default of 10.
- * A value of 5 allows better transformers to be added later.
- */
- public int PRIORITY_EXPLICIT = 50;
-
- /**
- * By default transformers have a priority of 100.
- */
- public int PRIORITY_DEFAULT = 100;
-
- /**
- * Suffixes to property names used to define transformation limits
- */
- static final Collection LIMIT_SUFFIXES = Arrays.asList(new String [] {
- MAX_SOURCE_SIZE_K_BYTES,
- TIMEOUT_MS,
- MAX_PAGES,
- READ_LIMIT_K_BYTES,
- READ_LIMIT_TIME_MS,
- PAGE_LIMIT
- });
-
- /**
- * Suffix pairs (max and limit values) to property names used to define transformation limits
- */
- public final String[][] LIMIT_PAIR_SUFFIXES = new String[][]
- {
- {MAX_SOURCE_SIZE_K_BYTES, READ_LIMIT_K_BYTES},
- {TIMEOUT_MS, READ_LIMIT_TIME_MS},
- {MAX_PAGES, PAGE_LIMIT}
- };
-
- /**
- * All suffixes to property names used to transformer configuration
- */
- static final Collection ALL_SUFFIXES = Arrays.asList(new String [] {
- MAX_SOURCE_SIZE_K_BYTES,
- TIMEOUT_MS,
- MAX_PAGES,
- READ_LIMIT_K_BYTES,
- READ_LIMIT_TIME_MS,
- PAGE_LIMIT,
- SUPPORTED,
- AVAILABLE,
- PRIORITY,
- BLACKLIST,
- ERROR_TIME,
- INITIAL_TIME,
- INITIAL_COUNT,
- THRESHOLD_COUNT,
- FAILOVER,
- PIPELINE
- });
-
- /**
- * No suffixes to property names used to define transformer settings.
- */
- public static final Collection NO_SUFFIXES = Collections.singletonList("");
-
- static final String ENTRIES = "entries";
-
- /**
- * The number of debug lines to keep. Turned off if <= 0.
- */
- public static final String DEBUG_ENTRIES = TRANSFORMER+"debug."+ENTRIES;
-
- /**
- * The number of log lines to keep. Turned off if <= 0.
- */
- public static final String LOG_ENTRIES = TRANSFORMER+"log."+ENTRIES;
-
- /**
- * A white list of declared and detected mimetypes, that don't match, but should still be transformed.
- */
- // Has ".mimetypes" on the end as we might one day wish to use extensions too (to simplify the entry).
- static final String STRICT_MIMETYPE_CHECK_WHITELIST_MIMETYPES = TRANSFORMER+"strict.mimetype.check.whitelist"+MIMETYPES.substring(0, MIMETYPES.length()-1);
-
- /**
- * Returns a transformer property value.
- * @param name of the property.
- * @return a transformer property or {@code null} if not set.
- */
- String getProperty(String name);
-
- /**
- * Returns a sorted set of all transformer properties, their values and includes
- * comments about the properties.
- * @param changesOnly only custom values will be included.
- * @return a multi-line String which is never {code null}.
- */
- String getProperties(boolean changesOnly);
-
- /**
- * Removes transformer properties.
- *
- * @param propertyNames new line separated names. Any values will be ignored.
- * @return the number of properties removed.
- * @throws IllegalArgumentException if the properties were not set or the
- * list contains errors.
- */
- int removeProperties(String propertyNames);
-
- /**
- * Sets a transformer property values. These will be stored in the database but on an MBean
- * reset is cleared.
- *
- * @param propertyNamesAndValues new line separated name and values
- * @return the number of properties set.
- * @throws IllegalArgumentException the list contains errors.
- */
- int setProperties(String propertyNamesAndValues);
-
- /**
- * Returns and creates if needed the {@link TransformerStatistics} object for the combination of
- * transformer, sourceMimetype and targetMimetype. When transformer is null this is the
- * system wide summary object for a combination of sourceMimetype and targetMimetype.
- * When both sourceMimetype and targetMimetype are null this is the transformer's summary
- * object. When all three parameters are null this is the system wide summary for all
- * transformers.
- * @param transformer the transformer for which data is being recorded.
- * @param sourceMimetype the source mimetype.
- * @param targetMimetype the source mimetype.
- * @param createNew indicates if a new object should be created if it does not exist.
- * @return the requested {@link TransformerStatistics}.
- */
- public TransformerStatistics getStatistics(ContentTransformer transformer, String sourceMimetype, String targetMimetype, boolean createNew);
-
- /**
- * Returns the limits defined for the combination of transformer, sourceMimetype and targetMimetype.
- * When the transformer is null, this is a default value. When both sourceMimetype and targetMimetype
- * are null this is a default for the specified transformer.
- * @param transformer
- * @param sourceMimetype
- * @param targetMimetype
- * @param use to which the limits will be put. For example "index", "webpreview", "doclib", "syncRule",
- * "aysncRule". {@code null} is the default.
- * @return the combined (takes into account defaults from higher levels) limits for the combination.
- */
- public TransformationOptionLimits getLimits(ContentTransformer transformer, String sourceMimetype, String targetMimetype, String use);
-
- /**
- * Returns true if the supplied mimetype transformation pair is allowed by the list of supported
- * and unsupported transformations.
- * @param transformer
- * @param sourceMimetype
- * @param targetMimetype
- * @param options not currently used
- */
- public boolean isSupportedTransformation(ContentTransformer transformer, String sourceMimetype,
- String targetMimetype, TransformationOptions options);
-
- /**
- * Returns the priority of the specified transformer for the the combination of source and target mimetype.
- * @param contentTransformerHelper
- * @param sourceMimetype
- * @param targetMimetype
- * @return the priority. To support the historical concept of EXPLICIT transformers, all such transformers
- * are given a {@link #PRIORITY_EXPLICIT} (50). By default transformers have a default of 100.
- */
- public int getPriority(ContentTransformer contentTransformerHelper,
- String sourceMimetype, String targetMimetype);
-
-
- /**
- * Returns a list of blacklisted NodeRefs of the specified transformer for the the combination of source and target mimetype.
- * @param transformer
- * @param sourceMimetype
- * @param targetMimetype
- * @return the blacklist or null is none.
- */
- List getBlacklist(ContentTransformer transformer, String sourceMimetype,
- String targetMimetype);
-
- /**
- * When strict mimetype checking is performed before a transformation, this method is called.
- * There are a few issues with the Tika mimetype detection. As a result we still allow some
- * transformations to take place even if there is a discrepancy between the detected and
- * declared mimetypes.
- * @param declaredMimetype the mimetype on the source node
- * @param detectedMimetype returned by Tika having looked at the content.
- * @return true if the transformation should take place. This includes the case where the
- * detectedMimetype is null (returned by Tika when the mimetypes are the same), or
- * the supplied pair of mimetypes have been added to the
- * {@code}transformer.strict.mimetype.check.whitelist{@code}.
- */
- boolean strictMimetypeCheck(String declaredMimetype, String detectedMimetype);
-
- /**
- * Returns the threshold of the transformer. It is only after this number of transformation attempts
- * that the average time is used.
- * @param contentTransformerHelper
- * @param sourceMimetype
- * @param targetMimetype
- * @return the threshold.
- */
-
- public int getThresholdCount(ContentTransformer contentTransformerHelper, String sourceMimetype,
- String targetMimetype);
-}
diff --git a/repository/src/main/java/org/alfresco/repo/content/transform/TransformerConfigDynamicTransformers.java b/repository/src/main/java/org/alfresco/repo/content/transform/TransformerConfigDynamicTransformers.java
deleted file mode 100644
index 5c3d1ffd5c..0000000000
--- a/repository/src/main/java/org/alfresco/repo/content/transform/TransformerConfigDynamicTransformers.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
- * %%
- * This file is part of the Alfresco software.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- * #L%
- */
-package org.alfresco.repo.content.transform;
-
-import static org.alfresco.repo.content.transform.TransformerConfig.AMP;
-import static org.alfresco.repo.content.transform.TransformerConfig.AVAILABLE;
-import static org.alfresco.repo.content.transform.TransformerConfig.EDITION;
-import static org.alfresco.repo.content.transform.TransformerConfig.FAILOVER;
-import static org.alfresco.repo.content.transform.TransformerConfig.PIPE;
-import static org.alfresco.repo.content.transform.TransformerConfig.PIPELINE;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.repo.rendition2.LegacySynchronousTransformClient;
-import org.alfresco.service.cmr.module.ModuleService;
-import org.alfresco.service.cmr.repository.ContentService;
-import org.alfresco.service.cmr.repository.MimetypeService;
-import org.alfresco.service.descriptor.DescriptorService;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Adds dynamic transformers defined in alfresco global properties to the ContentTransformerRegistry.
- *
- * @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
- */
-@Deprecated
-public class TransformerConfigDynamicTransformers extends TransformerPropertyNameExtractor
-{
- private static final Log logger = LogFactory.getLog(TransformerConfigDynamicTransformers.class);
- int errorCount = 0;
- private final List dynamicTransformers = new ArrayList();
-
- public TransformerConfigDynamicTransformers(TransformerConfig transformerConfig, TransformerProperties transformerProperties,
- MimetypeService mimetypeService, LegacySynchronousTransformClient legacySynchronousTransformClient, ContentTransformerRegistry transformerRegistry,
- TransformerDebug transformerDebug, ModuleService moduleService, DescriptorService descriptorService,
- Properties globalProperties)
- {
- createDynamicTransformers(transformerConfig, transformerProperties, mimetypeService, legacySynchronousTransformClient,
- transformerRegistry, transformerDebug, moduleService, descriptorService, globalProperties);
- }
-
- private void createDynamicTransformers(TransformerConfig transformerConfig, TransformerProperties transformerProperties,
- MimetypeService mimetypeService, LegacySynchronousTransformClient legacySynchronousTransformClient, ContentTransformerRegistry transformerRegistry,
- TransformerDebug transformerDebug, ModuleService moduleService, DescriptorService descriptorService,
- Properties globalProperties)
- {
- Collection SUFFIXES = Arrays.asList(new String [] {
- FAILOVER,
- PIPELINE,
- AVAILABLE,
- EDITION,
- AMP
- });
-
- Map
- transformerSourceTargetSuffixValues =
- getTransformerSourceTargetValuesMap(SUFFIXES, true, true, false, transformerProperties, mimetypeService);
- Collection properties =
- transformerSourceTargetSuffixValues.values();
-
- // Repeat until we cannot create any more transformers or all have been created
- Collection processed =
- new ArrayList();
- do
- {
- processed.clear();
- for (TransformerSourceTargetSuffixValue property: properties)
- {
- if (property.suffix.equals(PIPELINE) || property.suffix.equals(FAILOVER))
- {
- try
- {
- String edition = getProperty(property.transformerName, null, null, EDITION,
- null, transformerSourceTargetSuffixValues);
- String moduleId = getProperty(property.transformerName, null, null, AMP,
- null, transformerSourceTargetSuffixValues);
- if (!supportedEdition(descriptorService, edition))
- {
- processed.add(property);
- logger.debug(property.transformerName+" ignored. As it is an "+edition+" only transformer.");
- }
- else if (!supportedModule(moduleService, moduleId))
- {
- processed.add(property);
- logger.debug(property.transformerName+" ignored. As the AMP "+moduleId+" is not installed.");
- }
- else
- {
- String availableStr = getProperty(property.transformerName, null, null, AVAILABLE,
- null, transformerSourceTargetSuffixValues);
- boolean available = availableStr == null || "true".equalsIgnoreCase(availableStr);
-
- AbstractContentTransformer2 transformer = property.suffix.equals(PIPELINE)
- ? createComplexTransformer(property, transformerConfig, mimetypeService,
- legacySynchronousTransformClient, transformerRegistry, transformerDebug, available,
- globalProperties)
- : createFailoverTransformer(property, transformerConfig, mimetypeService,
- transformerRegistry, transformerDebug, available,
- globalProperties);
- transformer.register();
- processed.add(property);
- dynamicTransformers.add(transformer);
- logger.debug(property.transformerName+" added");
- }
- }
- catch (IllegalArgumentException e)
- {
- // Thrown if unknown sub transformer name - it might be dynamic
- }
- catch (AlfrescoRuntimeException e)
- {
- // Thrown if the mimetype is invalid or the transformer already exists
- processed.add(property);
- error(e.getMessage());
- }
- }
- }
- } while (properties.removeAll(processed) && properties.size() > 0);
-
- for (TransformerSourceTargetSuffixValue property: properties)
- {
- if (property.suffix.equals(PIPELINE) || property.suffix.equals(FAILOVER))
- {
- error("Cannot create dynamic transformer "+property.transformerName+
- " as sub transformers could not be found or created (\""+
- property.value+"\").");
- }
- }
- }
-
- private boolean supportedEdition(DescriptorService descriptorService, String edition)
- {
- return descriptorService == null || edition == null ||
- descriptorService.getServerDescriptor().getEdition().equals(edition);
- }
-
- private boolean supportedModule(ModuleService moduleService, String moduleId)
- {
- return moduleService == null || moduleId == null ||
- moduleService.getModule(moduleId) != null;
- }
-
- private AbstractContentTransformer2 createComplexTransformer(TransformerSourceTargetSuffixValue property,
- TransformerConfig transformerConfig,
- MimetypeService mimetypeService, LegacySynchronousTransformClient legacySynchronousTransformClient,
- ContentTransformerRegistry transformerRegistry, TransformerDebug transformerDebug,
- boolean available, Properties globalProperties)
- {
- List