mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V4.0-BUG-FIX to HEAD
33836: Fix for ALF-10651 Fix patches that trigger reindexing and ALF-10656 SOLR: Patches execute search during bootstrap causing deadlock 33842: Fixes ALF-12797: i18n strings in activiti-admin login-screen escaped properly 33844: Fix for ALF-10651 Fix patches that trigger reindexing and ALF-10656 SOLR: Patches execute search during bootstrap causing deadlock - batch touch to limit the in clause size generated 33845: Manually added extra core Share extensions needed for the V4.0 Records Management module from the development branch. - Refactored JSON property decorators for the Document Library data webscripts - Document List banners (e.g. working copy) moved into metadata template config - Ability to override default document/folder title within Document Library (<title> element in metadata template - unused in core code) - Additional extension point in surf-doclist to override remote data URL - Better handling for missing content property 33852: ALF-12725: Merged V3.4-BUG-FIX (3.4.9) to V4.0-BUG-FIX (4.0.1) 33849: Merged V3 (3.4.8) to V3.4-BUG-FIX (3.4.9) 33848: ALF-10976 (relates to ALF-10412) Fixed bug to do with preview being stuck as always being 'Content cannot be previewed. Do you wish to download?' or a 'blank preview after a transformer is not found' for all content with the same mimetype. Cache in ThumbnailRegistory.getThumbnailDefinitions() now understands that transformers may have an upper content size limit. The choice between the two options was based on the size of the first file previewed of each mimetype. Needed to add getMaxSourceSizeBytes() to support this (see below). - refactored (previous refactor was incomplete) ContentTransformer so that the two halfs of isTransformable is now split into sub methods isTransformableMimetypes and isTransformableSize. This is why there are so many files changed. - Moved getMaxSourceSizeBytes() from AbstractContentTransformerLimits to ContentTransformer as there were becomming too many places in the code that needed needed to check if the ContentTransformer was an instanceof AbstractContentTransformerLimits before calling this method. - TransformerDebug now uses KB MB GB values in output to make it simpler to read. - TransformerDebug now uses thousand separaters in millisecond values to make it simpler to read. - TransformerDebug now reports the 'parent' transformer name rather than the sub-transformer name when an unavailable transformer is found. Makes it simpler to tie up with the 'available transformer' list with the new pushIsTransformableSize() calls. - TransformerDebug now uses trace logging for calls from ThumbnailRegistory.isThumbnailDefinitionAvailable() as it is normally followed by a ContentService.transform() which is logged at debug level anyway. - TransformerDebug now turns logging level to trace if the file size is 0 bytes. Request from Jan. Not sure how one uploads such a file! - Modified ComplexContentTransformer.isTransformable() so that it checks the mimetypes before the sizes so that TransformerDebug does not report 'unavailable transformers' that don't support the mimetype conversion. - Modified ComplexContentTransformer.getLimits and ComplexContentTransformer.isPageLimitSupported() to include the limits from the first sub transformer. Was not an issue until ContentTransformer.getMaxSourceSizeBytes() was introduced. - Added logger to RhinoScriptProcessor to debug requests run javascript on the server. - Dropped the sourceUrl parameter from ThumbnailRegistry.getThumbnailDefinitions() which was introduced with limits as it is logicall not needed. 33853: DiskInterface.renameFile() can now throw PermissionDeniedException to return a different status to the client. Part of ALF-12717. 33856: Merged V3.4-BUG-FIX to V4.0-BUG-FIX 33835: ALF-12546: Remove references to retired RegPaths.exe from installed apply_amps.bat script 33843: Fix for ALF-12775 33855: Merged V3.4 to V3.4-BUG-FIX 33851: ALF-12588: Documents Intermittently Do Not Appear in Share - Fix by Alex Busel for regression I accidentally caused in 3.4.6 - Simple typo in mergeDeletions() caused path deletions to sometimes not get applied or get processed twice - Yikes! git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33857 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -33,6 +33,7 @@ import org.alfresco.repo.content.ContentServicePolicies.OnContentReadPolicy;
|
||||
import org.alfresco.repo.content.ContentServicePolicies.OnContentUpdatePolicy;
|
||||
import org.alfresco.repo.content.cleanup.EagerContentStoreCleaner;
|
||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||
import org.alfresco.repo.content.transform.AbstractContentTransformerLimits;
|
||||
import org.alfresco.repo.content.transform.ContentTransformer;
|
||||
import org.alfresco.repo.content.transform.ContentTransformerRegistry;
|
||||
import org.alfresco.repo.content.transform.TransformerDebug;
|
||||
@@ -40,6 +41,7 @@ import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.ClassPolicyDelegate;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
@@ -628,6 +630,45 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public long getMaxSourceSizeBytes(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
try
|
||||
{
|
||||
long maxSourceSize = 0;
|
||||
transformerDebug.pushAvailable(null, sourceMimetype, targetMimetype);
|
||||
List<ContentTransformer> transformers = getActiveTransformers(sourceMimetype, 0, targetMimetype, options);
|
||||
for (ContentTransformer transformer: transformers)
|
||||
{
|
||||
long maxSourceSizeKBytes = transformer.getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
|
||||
if (maxSourceSize >= 0)
|
||||
{
|
||||
if (maxSourceSizeKBytes < 0)
|
||||
{
|
||||
maxSourceSize = -1;
|
||||
}
|
||||
else if (maxSourceSizeKBytes > 0 && maxSourceSize < maxSourceSizeKBytes)
|
||||
{
|
||||
maxSourceSize = maxSourceSizeKBytes;
|
||||
}
|
||||
}
|
||||
// if maxSourceSizeKBytes == 0 this implies the transformation is disabled
|
||||
}
|
||||
if (transformerDebug.isEnabled())
|
||||
{
|
||||
transformerDebug.availableTransformers(transformers, -1,
|
||||
"ContentService.getMaxSourceSizeBytes() = "+transformerDebug.fileSize(maxSourceSize*1024));
|
||||
}
|
||||
return (maxSourceSize > 0) ? maxSourceSize * 1024 : maxSourceSize;
|
||||
}
|
||||
finally
|
||||
{
|
||||
transformerDebug.popAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ContentTransformer> getActiveTransformers(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
return getActiveTransformers(sourceMimetype, -1, targetMimetype, options);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -208,7 +208,9 @@ public abstract class AbstractContentTransformer implements ContentTransformer
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
return isTransformable(sourceMimetype, targetMimetype, options);
|
||||
return
|
||||
isTransformableMimetype(sourceMimetype, targetMimetype, options) &&
|
||||
isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,6 +230,36 @@ public abstract class AbstractContentTransformer implements ContentTransformer
|
||||
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)
|
||||
*/
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -84,6 +84,11 @@ public abstract class AbstractContentTransformerLimits extends ContentTransforme
|
||||
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}<p>
|
||||
*
|
||||
@@ -91,14 +96,24 @@ public abstract class AbstractContentTransformerLimits extends ContentTransforme
|
||||
* and then {@link #isTransformableSize(String, long, String, TransformationOptions)}.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
return
|
||||
isTransformable(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.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
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
|
||||
@@ -106,31 +121,45 @@ public abstract class AbstractContentTransformerLimits extends ContentTransforme
|
||||
* @param sourceSize size in bytes of the source. If negative, the source size is unknown.
|
||||
* @return {@code true} if the source is transformable.
|
||||
*/
|
||||
protected boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableSize(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
boolean sizeOkay = true;
|
||||
if (sourceSize >= 0)
|
||||
{
|
||||
TransformationOptionLimits limits = getLimits(sourceMimetype, targetMimetype, options);
|
||||
|
||||
// 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).
|
||||
if (!isPageLimitSupported() || limits.getPageLimit() <= 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())
|
||||
{
|
||||
// if maxSourceSizeKBytes == 0 this implies the transformation is disabled
|
||||
long maxSourceSizeKBytes = limits.getMaxSourceSizeKBytes();
|
||||
sizeOkay = maxSourceSizeKBytes < 0 || (maxSourceSizeKBytes > 0 && sourceSize <= maxSourceSizeKBytes*1024);
|
||||
if (!sizeOkay && transformerDebug.isEnabled())
|
||||
{
|
||||
transformerDebug.unavailableTransformer(this, maxSourceSizeKBytes);
|
||||
}
|
||||
transformerDebug.unavailableTransformer(this, 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() || limits.getPageLimit() <= 0)
|
||||
{
|
||||
maxSourceSizeKBytes = limits.getMaxSourceSizeKBytes();
|
||||
}
|
||||
|
||||
return maxSourceSizeKBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the timeout (ms) on the InputStream after which an IOExecption is thrown
|
||||
* to terminate very slow transformations or a subprocess is terminated (killed).
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -63,7 +63,7 @@ public class AbstractContentTransformerLimitsTest
|
||||
transformer = new AbstractContentTransformer2()
|
||||
{
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype,
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
{
|
||||
return false;
|
||||
@@ -214,6 +214,70 @@ public class AbstractContentTransformerLimitsTest
|
||||
assertEquals("Getter did not return set value", value, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMaxSourceSizeKBytes() throws Exception
|
||||
{
|
||||
long kValue = 12;
|
||||
long byteValue = kValue*1024;
|
||||
|
||||
// Not set mimetype limits yet
|
||||
assertTrue("No limits so should have been ok",
|
||||
transformer.isTransformableSize(A, byteValue+1, B, options));
|
||||
|
||||
// Set limit for A to B mimetypes and test
|
||||
limits.setMaxSourceSizeKBytes(kValue);
|
||||
addMimetypeLimits(A, B, limits);
|
||||
transformer.setMimetypeLimits(mimetypeLimits);
|
||||
|
||||
assertEquals("Expected to have set value returned", kValue,
|
||||
transformer.getMaxSourceSizeKBytes(A, B, options));
|
||||
|
||||
// With a mimetype that does not have any specific limits
|
||||
assertEquals("Expected to have -1 (unlimited) returned", -1,
|
||||
transformer.getMaxSourceSizeKBytes(C, B, options));
|
||||
|
||||
|
||||
// Clear the mimetype limits and double check
|
||||
limits.setMaxSourceSizeKBytes(-1);
|
||||
|
||||
assertEquals("Expected to have -1 (unlimited) returned", -1,
|
||||
transformer.getMaxSourceSizeKBytes(A, B, options));
|
||||
|
||||
// Check for combinations with transformer limits
|
||||
|
||||
// a) Using just transformer limit to start with
|
||||
transformer.setMaxSourceSizeKBytes(kValue);
|
||||
assertEquals("Expected to have transformer set value returned", kValue,
|
||||
transformer.getMaxSourceSizeKBytes(A, B, options));
|
||||
|
||||
// b) combination where transformer limit is used
|
||||
transformer.setMaxSourceSizeKBytes(kValue);
|
||||
limits.setMaxSourceSizeKBytes(kValue+1);
|
||||
assertEquals("Expected to have transformer set value returned", kValue,
|
||||
transformer.getMaxSourceSizeKBytes(A, B, options));
|
||||
|
||||
// c) combination where mimetype limit is used
|
||||
transformer.setMaxSourceSizeKBytes(kValue+1);
|
||||
limits.setMaxSourceSizeKBytes(kValue);
|
||||
assertEquals("Expected to have transformer set value returned", kValue,
|
||||
transformer.getMaxSourceSizeKBytes(A, B, options));
|
||||
|
||||
// Check no limit when page limit set on a transformer that does not support page limit
|
||||
transformer.setMaxSourceSizeKBytes(kValue);
|
||||
limits.setMaxSourceSizeKBytes(kValue+1);
|
||||
limits.setPageLimit(1);
|
||||
assertEquals("Expected to ignore the page limit as the transformer does not support it", kValue,
|
||||
transformer.getMaxSourceSizeKBytes(A, B, options));
|
||||
|
||||
// Check no limit when page limit set on a transformer that does support page limit
|
||||
transformer.setMaxSourceSizeKBytes(kValue);
|
||||
limits.setMaxSourceSizeKBytes(kValue+1);
|
||||
transformer.setPageLimitsSuported(true);
|
||||
limits.setPageLimit(1);
|
||||
assertEquals("Expected to have -1 (unlimited) returned when there are page limits", -1,
|
||||
transformer.getMaxSourceSizeKBytes(A, B, options));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsTransformableSize() throws Exception
|
||||
{
|
||||
@@ -260,16 +324,16 @@ public class AbstractContentTransformerLimitsTest
|
||||
transformer.isTransformableSize(A, byteValue+1, B, options));
|
||||
|
||||
// b) combination where transformer limit is used
|
||||
transformer.setMaxSourceSizeKBytes(kValue+1);
|
||||
limits.setMaxSourceSizeKBytes(kValue);
|
||||
transformer.setMaxSourceSizeKBytes(kValue);
|
||||
limits.setMaxSourceSizeKBytes(kValue+1);
|
||||
assertTrue("Size is equal to limit so should have been ok",
|
||||
transformer.isTransformableSize(A, byteValue, B, options));
|
||||
assertFalse("Size is greater than limit so should not have failed",
|
||||
transformer.isTransformableSize(A, byteValue+1, B, options));
|
||||
|
||||
// c) combination where mimetype limit is used
|
||||
transformer.setMaxSourceSizeKBytes(kValue);
|
||||
limits.setMaxSourceSizeKBytes(kValue+1);
|
||||
transformer.setMaxSourceSizeKBytes(kValue+1);
|
||||
limits.setMaxSourceSizeKBytes(kValue);
|
||||
assertTrue("Size is equal to limit so should have been ok",
|
||||
transformer.isTransformableSize(A, byteValue, B, options));
|
||||
assertFalse("Size is greater than limit so should not have failed",
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -50,7 +50,8 @@ public class BinaryPassThroughContentTransformer extends AbstractContentTransfor
|
||||
|
||||
}
|
||||
|
||||
public boolean isTransformable(String sourceMimetype,
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype,
|
||||
String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if (sourceMimetype.startsWith(StringExtractingContentTransformer.PREFIX_TEXT))
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -33,6 +33,7 @@ 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.TransformationOptionLimits;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
@@ -126,15 +127,32 @@ public class ComplexContentTransformer extends AbstractContentTransformer2 imple
|
||||
}
|
||||
|
||||
/**
|
||||
* Check we can transform all the way along the chain of mimetypes
|
||||
*
|
||||
* @see org.alfresco.repo.content.transform.ContentTransformer#isTransformable(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
|
||||
* Overrides this 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.
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
{
|
||||
boolean result = true;
|
||||
String currentSourceMimetype = sourceMimetype;
|
||||
overrideTransformationOptions(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
|
||||
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)
|
||||
{
|
||||
@@ -177,8 +195,28 @@ public class ComplexContentTransformer extends AbstractContentTransformer2 imple
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 = true;
|
||||
String currentSourceMimetype = sourceMimetype;
|
||||
|
||||
boolean first = true;
|
||||
Iterator<ContentTransformer> transformerIterator = transformers.iterator();
|
||||
Iterator<String> intermediateMimetypeIterator = intermediateMimetypes.iterator();
|
||||
while (transformerIterator.hasNext())
|
||||
@@ -195,28 +233,78 @@ public class ComplexContentTransformer extends AbstractContentTransformer2 imple
|
||||
// use an intermediate transformation mimetype
|
||||
currentTargetMimetype = intermediateMimetypeIterator.next();
|
||||
}
|
||||
|
||||
// check we can tranform the current stage (using -1 if not the first stage as we can't know the size)
|
||||
long size = first ? sourceSize : -1;
|
||||
if (transformer.isTransformable(currentSourceMimetype, size, currentTargetMimetype, options) == false)
|
||||
|
||||
if (sourceSize < 0)
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
// check we can transform the current stage's mimetypes
|
||||
if (transformer.isTransformableMimetype(currentSourceMimetype, currentTargetMimetype, options) == false)
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// check we can transform the current stage's sizes
|
||||
try
|
||||
{
|
||||
transformerDebug.pushIsTransformableSize(this);
|
||||
// (using -1 if not the first stage as we can't know the size)
|
||||
if (transformer.isTransformableSize(currentSourceMimetype, sourceSize, currentTargetMimetype, options) == false)
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// As the size is unknown for the next stages stop.
|
||||
// In future we might guess sizes such as excl to pdf
|
||||
// is about 110% of the original size, in which case
|
||||
// we would continue.
|
||||
break;
|
||||
// sourceSize += sourceSize * 10 / 100;
|
||||
}
|
||||
finally
|
||||
{
|
||||
transformerDebug.popIsTransformableSize();
|
||||
}
|
||||
}
|
||||
|
||||
// move on
|
||||
currentSourceMimetype = currentTargetMimetype;
|
||||
first = false;
|
||||
}
|
||||
|
||||
if (result && !isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if 'page' limits are supported by the first transformer in the chain.
|
||||
* @return true if the first transformer supports them.
|
||||
*/
|
||||
protected boolean isPageLimitSupported()
|
||||
{
|
||||
ContentTransformer firstTransformer = transformers.iterator().next();
|
||||
return (firstTransformer instanceof AbstractContentTransformerLimits)
|
||||
? ((AbstractContentTransformerLimits)firstTransformer).isPageLimitSupported()
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the limits from this transformer combined with those of the first transformer in the chain.
|
||||
*/
|
||||
protected TransformationOptionLimits getLimits(String sourceMimetype, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
{
|
||||
TransformationOptionLimits limits = super.getLimits(sourceMimetype, targetMimetype, options);
|
||||
ContentTransformer firstTransformer = transformers.get(0);
|
||||
if (firstTransformer instanceof AbstractContentTransformerLimits)
|
||||
{
|
||||
String firstTargetMimetype = intermediateMimetypes.get(0);
|
||||
limits = limits.combine(((AbstractContentTransformerLimits) firstTransformer).
|
||||
getLimits(sourceMimetype, firstTargetMimetype, options));
|
||||
}
|
||||
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)
|
||||
*/
|
||||
@@ -263,15 +351,4 @@ public class ComplexContentTransformer extends AbstractContentTransformer2 imple
|
||||
{
|
||||
return Collections.unmodifiableList(intermediateMimetypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should no longer be called as the overloaded method
|
||||
* that calls it has the overridden.
|
||||
*/
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -44,12 +44,39 @@ public interface ContentTransformer extends ContentWorker
|
||||
*
|
||||
* @param sourceMimetype the source mimetype
|
||||
* @param sourceSize the size (bytes) of the source. If negative it is unknown.
|
||||
* @param targetMimetype the target mimetype
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Indicates whether given the provided transformation parmaters this transformer can prvide an explict
|
||||
* transformation.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -111,6 +111,7 @@ public class ContentTransformerRegistry
|
||||
for (ContentTransformer transformer : transformers)
|
||||
{
|
||||
// Transformability can be dynamic, i.e. it may have become unusable
|
||||
// Don't know why we do this test as it has already been done by findTransformers(...)
|
||||
if (transformer.isTransformable(sourceMimetype, sourceSize, targetMimetype, options) == false)
|
||||
{
|
||||
// It is unreliable now.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -236,7 +236,7 @@ public class ContentTransformerRegistryTest extends AbstractContentTransformerTe
|
||||
disable = true;
|
||||
}
|
||||
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if (disable) {
|
||||
return false;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -28,6 +28,7 @@ import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
// TODO Modify ContentTransformerWorker to understand transformer limits. At the moment no workers use them
|
||||
public interface ContentTransformerWorker
|
||||
{
|
||||
/**
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -46,7 +46,8 @@ import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
*/
|
||||
public class EMLTransformer extends AbstractContentTransformer2
|
||||
{
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if (!MimetypeMap.MIMETYPE_RFC822.equals(sourceMimetype) || !MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(targetMimetype))
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -79,37 +79,65 @@ public class FailoverContentTransformer extends AbstractContentTransformer2 impl
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see org.alfresco.repo.content.transform.ContentTransformer#isTransformable(java.lang.String, long sourceSize, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
// For this transformer to be considered operational, there must be at least one transformer
|
||||
// in the chain that can perform for us.
|
||||
boolean result = false;
|
||||
|
||||
for (ContentTransformer ct : this.transformers)
|
||||
{
|
||||
if (ct.isTransformable(sourceMimetype, sourceSize, targetMimetype, options))
|
||||
{
|
||||
// There may be size limits on this transformer as well as those it contains.
|
||||
result = isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should no longer be called as the overloaded method
|
||||
* that calls it has the overridden.
|
||||
* 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, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
return false;
|
||||
return isTransformableSize(sourceMimetype, sourceSize, 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) || isTransformableMimetypeAndSize(sourceMimetype, sourceSize, targetMimetype, options);
|
||||
}
|
||||
|
||||
private boolean isTransformableMimetypeAndSize(String sourceMimetype, long sourceSize,
|
||||
String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
boolean result = false;
|
||||
if (super.isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options))
|
||||
{
|
||||
for (ContentTransformer ct : this.transformers)
|
||||
{
|
||||
transformerDebug.pushIsTransformableSize(this);
|
||||
if (ct.isTransformableMimetype(sourceMimetype, targetMimetype, options))
|
||||
{
|
||||
if (sourceSize == -1)
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ct.isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options))
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
transformerDebug.popIsTransformableSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isExplicitTransformation(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -118,7 +118,8 @@ class DummyTestContentTransformer extends AbstractContentTransformer2 implements
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTransformable(String sourceMimetype,
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype,
|
||||
String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
// We'll arbitrarily claim to be able to transform PDF to PNG
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -50,7 +50,8 @@ public class HtmlParserContentTransformer extends AbstractContentTransformer2
|
||||
/**
|
||||
* Only support HTML to TEXT.
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if (!MimetypeMap.MIMETYPE_HTML.equals(sourceMimetype) ||
|
||||
!MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(targetMimetype))
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -76,7 +76,9 @@ public class MediaWikiContentTransformer extends AbstractContentTransformer2
|
||||
* 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)
|
||||
*/public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
*/
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if (!MimetypeMap.MIMETYPE_TEXT_MEDIAWIKI.equals(sourceMimetype) ||
|
||||
!MimetypeMap.MIMETYPE_HTML.equals(targetMimetype))
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -53,7 +53,8 @@ public class PdfBoxPdfToImageContentTransformer extends AbstractContentTransform
|
||||
private static final String PDF_DEFAULT_PASSWORD = "";
|
||||
private static Log logger = LogFactory.getLog(PdfBoxPdfToImageContentTransformer.class);
|
||||
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
// only support PDF -> PNG OR Adobe Illustrator -> PNG.
|
||||
// Recent .ai file format is a .pdf file.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -53,7 +53,8 @@ public class PdfToImageContentTransformer extends AbstractContentTransformer2
|
||||
/**
|
||||
* Currently the only transformation performed is that of text extraction from PDF documents.
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
// only support PDF -> PNG OR Adobe Illustrator -> PNG.
|
||||
// .ai is really just a .pdf file anyway
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -72,28 +72,17 @@ public class PoiHssfContentTransformer extends TikaPoweredContentTransformer
|
||||
* We support transforming to HTML, XML, Text or CSV
|
||||
*/
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if(sourceMimeTypes.contains(sourceMimetype) &&
|
||||
MimetypeMap.MIMETYPE_TEXT_CSV.equals(targetMimetype))
|
||||
{
|
||||
// Special case for CSV
|
||||
return isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
|
||||
// Special case for CSV
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise fall back on the default Tika rules
|
||||
return super.isTransformable(sourceMimetype, sourceSize, targetMimetype, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should no longer be called as the overloaded method
|
||||
* that calls it has been overridden.
|
||||
*/
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
{
|
||||
return isTransformable(sourceMimetype, -1, targetMimetype, options);
|
||||
return super.isTransformableMimetype(sourceMimetype, targetMimetype, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +101,7 @@ public class PoiHssfContentTransformer extends TikaPoweredContentTransformer
|
||||
}
|
||||
|
||||
// Otherwise fall back on the default Tika rules
|
||||
return super.isTransformable(sourceMimetype, targetMimetype, options);
|
||||
return super.isTransformableMimetype(sourceMimetype, targetMimetype, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -58,7 +58,8 @@ public class ProxyContentTransformer extends AbstractContentTransformer2
|
||||
/**
|
||||
* @see DocumentFormatRegistry
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
return this.worker.isTransformable(sourceMimetype, targetMimetype, options);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -50,7 +50,8 @@ public class StringExtractingContentTransformer extends AbstractContentTransform
|
||||
* <p>
|
||||
* Extraction of text from binary data is wholly unreliable.
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if (!targetMimetype.equals(MimetypeMap.MIMETYPE_TEXT_PLAIN))
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -100,7 +100,8 @@ public class TextToPdfContentTransformer extends AbstractContentTransformer2
|
||||
/**
|
||||
* Only supports Text to PDF
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if ( (!MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(sourceMimetype) &&
|
||||
!MimetypeMap.MIMETYPE_TEXT_CSV.equals(sourceMimetype) &&
|
||||
@@ -112,21 +113,10 @@ public class TextToPdfContentTransformer extends AbstractContentTransformer2
|
||||
}
|
||||
else
|
||||
{
|
||||
return isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should no longer be called as the overloaded method
|
||||
* that calls it has the overridden.
|
||||
*/
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transformInternal(
|
||||
ContentReader reader,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -87,7 +87,8 @@ public abstract class TikaPoweredContentTransformer extends AbstractContentTrans
|
||||
* Can we do the requested transformation via Tika?
|
||||
* We support transforming to HTML, XML or Text
|
||||
*/
|
||||
public boolean isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
|
||||
@Override
|
||||
public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options)
|
||||
{
|
||||
if(! sourceMimeTypes.contains(sourceMimetype))
|
||||
{
|
||||
@@ -101,8 +102,7 @@ public abstract class TikaPoweredContentTransformer extends AbstractContentTrans
|
||||
MimetypeMap.MIMETYPE_XML.equals(targetMimetype))
|
||||
{
|
||||
// We can output to this
|
||||
// But there may be size limits on this transformer.
|
||||
return isTransformableSize(sourceMimetype, sourceSize, targetMimetype, options);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,17 +110,6 @@ public abstract class TikaPoweredContentTransformer extends AbstractContentTrans
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method should no longer be called as the overloaded method
|
||||
* that calls it has been overridden.
|
||||
*/
|
||||
@Override
|
||||
public boolean isTransformable(String sourceMimetype, String targetMimetype,
|
||||
TransformationOptions options)
|
||||
{
|
||||
return isTransformable(sourceMimetype, -1, targetMimetype, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an appropriate Tika ContentHandler for the
|
||||
|
@@ -18,10 +18,9 @@
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Formatter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -74,6 +73,7 @@ public class TransformerDebug
|
||||
};
|
||||
|
||||
private final Deque<Frame> stack = new ArrayDeque<Frame>();
|
||||
private final Deque<String> isTransformableStack = new ArrayDeque<String>();
|
||||
private boolean debugOutput = true;
|
||||
|
||||
public static Deque<Frame> getStack()
|
||||
@@ -85,6 +85,11 @@ public class TransformerDebug
|
||||
{
|
||||
return threadInfo.get().debugOutput;
|
||||
}
|
||||
|
||||
public static Deque<String> getIsTransformableStack()
|
||||
{
|
||||
return threadInfo.get().isTransformableStack;
|
||||
}
|
||||
|
||||
public static boolean setDebugOutput(boolean debugOutput)
|
||||
{
|
||||
@@ -103,6 +108,7 @@ public class TransformerDebug
|
||||
private final String fromUrl;
|
||||
private final String sourceMimetype;
|
||||
private final String targetMimetype;
|
||||
private final boolean origDebugOutput;
|
||||
private final long start;
|
||||
|
||||
private Call callType;
|
||||
@@ -111,13 +117,14 @@ public class TransformerDebug
|
||||
// See debug(String, Throwable) as to why this is commented out
|
||||
// private Throwable lastThrowable;
|
||||
|
||||
private Frame(Frame parent, String fromUrl, String sourceMimetype, String targetMimetype, Call pushCall)
|
||||
private Frame(Frame parent, String fromUrl, String sourceMimetype, String targetMimetype, Call pushCall, boolean origDebugOutput)
|
||||
{
|
||||
this.id = parent == null ? uniqueId.getAndIncrement() : ++parent.childId;
|
||||
this.fromUrl = fromUrl;
|
||||
this.sourceMimetype = sourceMimetype;
|
||||
this.targetMimetype = targetMimetype;
|
||||
this.callType = pushCall;
|
||||
this.origDebugOutput = origDebugOutput;
|
||||
start = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -196,6 +203,17 @@ public class TransformerDebug
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called prior to calling a nested isTransformable.
|
||||
*/
|
||||
public void pushIsTransformableSize(ContentTransformer transformer)
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
ThreadInfo.getIsTransformableStack().push(getName(transformer));
|
||||
}
|
||||
}
|
||||
|
||||
private void push(String name, String fromUrl, String sourceMimetype, String targetMimetype, long sourceSize, Call callType)
|
||||
{
|
||||
Deque<Frame> ourStack = ThreadInfo.getStack();
|
||||
@@ -207,7 +225,9 @@ public class TransformerDebug
|
||||
}
|
||||
else
|
||||
{
|
||||
frame = new Frame(frame, fromUrl, sourceMimetype, targetMimetype, callType);
|
||||
// Create a new frame. Logging level is set to trace if the file size is 0
|
||||
boolean origDebugOutput = ThreadInfo.setDebugOutput(ThreadInfo.getDebug() && sourceSize != 0);
|
||||
frame = new Frame(frame, fromUrl, sourceMimetype, targetMimetype, callType, origDebugOutput);
|
||||
ourStack.push(frame);
|
||||
|
||||
if (callType == Call.TRANSFORM)
|
||||
@@ -231,8 +251,11 @@ public class TransformerDebug
|
||||
|
||||
if (frame != null)
|
||||
{
|
||||
String name = getName(transformer);
|
||||
String reason = String.format("> %,dK", maxSourceSizeKBytes);
|
||||
Deque<String> isTransformableStack = ThreadInfo.getIsTransformableStack();
|
||||
String name = (!isTransformableStack.isEmpty())
|
||||
? isTransformableStack.getFirst()
|
||||
: getName(transformer);
|
||||
String reason = "> "+fileSize(maxSourceSizeKBytes*1024);
|
||||
boolean debug = (maxSourceSizeKBytes != 0);
|
||||
if (ourStack.size() == 1)
|
||||
{
|
||||
@@ -273,7 +296,7 @@ public class TransformerDebug
|
||||
String name = getName(trans);
|
||||
int pad = longestNameLength - name.length();
|
||||
log((c == 'a' ? "**" : " ") + (c++) + ") " +
|
||||
name + spaces(pad+1) + trans.getTransformationTime() + " ms");
|
||||
name + spaces(pad+1) + ms(trans.getTransformationTime()));
|
||||
}
|
||||
if (frame.unavailableTransformers != null)
|
||||
{
|
||||
@@ -317,7 +340,8 @@ public class TransformerDebug
|
||||
log(frame.fromUrl, firstLevel);
|
||||
}
|
||||
|
||||
log(getMimetypeExt(frame.sourceMimetype)+getMimetypeExt(frame.targetMimetype) + String.format("%,dK ", (sourceSize/1024)) + message);
|
||||
log(getMimetypeExt(frame.sourceMimetype)+getMimetypeExt(frame.targetMimetype) +
|
||||
((sourceSize >= 0) ? fileSize(sourceSize)+' ' : "") + message);
|
||||
|
||||
log(frame.sourceMimetype+' '+frame.targetMimetype, false);
|
||||
}
|
||||
@@ -345,6 +369,17 @@ public class TransformerDebug
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after returning from a nested isTransformable.
|
||||
*/
|
||||
public void popIsTransformableSize()
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
ThreadInfo.getIsTransformableStack().pop();
|
||||
}
|
||||
}
|
||||
|
||||
private void pop(Call callType)
|
||||
{
|
||||
Deque<Frame> ourStack = ThreadInfo.getStack();
|
||||
@@ -358,12 +393,13 @@ public class TransformerDebug
|
||||
{
|
||||
boolean topFrame = ourStack.size() == 1;
|
||||
log("Finished in " +
|
||||
(System.currentTimeMillis() - frame.start) + " ms" +
|
||||
ms(System.currentTimeMillis() - frame.start) +
|
||||
(frame.callType == Call.AVAILABLE ? " Transformer NOT called" : "") +
|
||||
(topFrame ? "\n" : ""),
|
||||
topFrame);
|
||||
}
|
||||
|
||||
setDebugOutput(frame.origDebugOutput);
|
||||
ourStack.pop();
|
||||
|
||||
// See debug(String, Throwable) as to why this is commented out
|
||||
@@ -523,7 +559,7 @@ public class TransformerDebug
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getName(ContentTransformer transformer)
|
||||
public String getName(ContentTransformer transformer)
|
||||
{
|
||||
return
|
||||
(transformer instanceof AbstractContentTransformer2
|
||||
@@ -567,4 +603,51 @@ public class TransformerDebug
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String ms(long time)
|
||||
{
|
||||
return String.format("%,d ms", time);
|
||||
}
|
||||
|
||||
public String fileSize(long size)
|
||||
{
|
||||
if (size < 0)
|
||||
{
|
||||
return "unlimited";
|
||||
}
|
||||
if (size == 1)
|
||||
{
|
||||
return "1 byte";
|
||||
}
|
||||
final String[] units = new String[] { "bytes", "KB", "MB", "GB", "TB" };
|
||||
long divider = 1;
|
||||
for(int i = 0; i < units.length-1; i++)
|
||||
{
|
||||
long nextDivider = divider * 1024;
|
||||
if(size < nextDivider)
|
||||
{
|
||||
return fileSizeFormat(size, divider, units[i]);
|
||||
}
|
||||
divider = nextDivider;
|
||||
}
|
||||
return fileSizeFormat(size, divider, units[units.length-1]);
|
||||
}
|
||||
|
||||
private String fileSizeFormat(long size, long divider, String unit)
|
||||
{
|
||||
size = size * 10 / divider;
|
||||
int decimalPoint = (int) size % 10;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(size/10);
|
||||
if (decimalPoint != 0)
|
||||
{
|
||||
sb.append(".");
|
||||
sb.append(decimalPoint);
|
||||
}
|
||||
sb.append(' ');
|
||||
sb.append(unit);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user