mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ALF-14306 Add priorities to transformers
- Fix problems with ".mimetypes." properties git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@46893 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -298,7 +298,7 @@ public abstract class AbstractContentTransformerLimits extends ContentTransforme
|
|||||||
{
|
{
|
||||||
String targetExt = getExtensionOrAny(target.getKey());
|
String targetExt = getExtensionOrAny(target.getKey());
|
||||||
TransformationOptionLimits limits = target.getValue();
|
TransformationOptionLimits limits = target.getValue();
|
||||||
String mimetypeSuffix = TransformerConfig.EXTENSIONS_SEPARATOR.substring(1)+sourceExt+'.'+targetExt;
|
String mimetypeSuffix = TransformerConfig.EXTENSIONS.substring(1)+sourceExt+'.'+targetExt;
|
||||||
|
|
||||||
deprecatedLimitsSetter(mimetypeSuffix, limits);
|
deprecatedLimitsSetter(mimetypeSuffix, limits);
|
||||||
}
|
}
|
||||||
|
@@ -237,7 +237,7 @@ public class ContentTransformerHelper implements BeanNameAware
|
|||||||
String targetMimetype = transformation.getTargetMimetype();
|
String targetMimetype = transformation.getTargetMimetype();
|
||||||
String sourceExt = getExtensionOrAny(sourceMimetype);
|
String sourceExt = getExtensionOrAny(sourceMimetype);
|
||||||
String targetExt = getExtensionOrAny(targetMimetype);
|
String targetExt = getExtensionOrAny(targetMimetype);
|
||||||
deprecatedSetter(TransformerConfig.EXTENSIONS_SEPARATOR.substring(1)+sourceExt+'.'+targetExt+
|
deprecatedSetter(TransformerConfig.EXTENSIONS.substring(1)+sourceExt+'.'+targetExt+
|
||||||
(value == null // same as: transformation instanceof ExplictTransformationDetails
|
(value == null // same as: transformation instanceof ExplictTransformationDetails
|
||||||
? TransformerConfig.PRIORITY+"="+TransformerConfig.PRIORITY_EXPLICIT
|
? TransformerConfig.PRIORITY+"="+TransformerConfig.PRIORITY_EXPLICIT
|
||||||
: TransformerConfig.SUPPORTED+"="+value));
|
: TransformerConfig.SUPPORTED+"="+value));
|
||||||
|
@@ -68,13 +68,13 @@ public interface TransformerConfig
|
|||||||
/**
|
/**
|
||||||
* The separator between the transformer name and two mimetype extensions in a property name.
|
* The separator between the transformer name and two mimetype extensions in a property name.
|
||||||
*/
|
*/
|
||||||
static final String EXTENSIONS_SEPARATOR = ".extensions.";
|
static final String EXTENSIONS = ".extensions.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The separator between the transformer name and wildcarded mimetypes rather than extensions in a property name.
|
* 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_SEPARATOR}.
|
* Effectively equivalent to multiple properties using the {@link #EXTENSIONS}.
|
||||||
*/
|
*/
|
||||||
static final String MIMETYPES_SEPARATOR = ".mimetypes.";
|
static final String MIMETYPES = ".mimetypes.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The suffix to property names for supported and unsupported combinations.
|
* The suffix to property names for supported and unsupported combinations.
|
||||||
|
@@ -19,20 +19,16 @@
|
|||||||
package org.alfresco.repo.content.transform;
|
package org.alfresco.repo.content.transform;
|
||||||
|
|
||||||
import static org.alfresco.repo.content.transform.TransformerConfig.ANY;
|
import static org.alfresco.repo.content.transform.TransformerConfig.ANY;
|
||||||
import static org.alfresco.repo.content.transform.TransformerConfig.CONTENT;
|
|
||||||
import static org.alfresco.repo.content.transform.TransformerConfig.DEFAULT_TRANSFORMER;
|
import static org.alfresco.repo.content.transform.TransformerConfig.DEFAULT_TRANSFORMER;
|
||||||
import static org.alfresco.repo.content.transform.TransformerConfig.LIMIT_SUFFIXES;
|
import static org.alfresco.repo.content.transform.TransformerConfig.LIMIT_SUFFIXES;
|
||||||
import static org.alfresco.repo.content.transform.TransformerConfig.EXTENSIONS_SEPARATOR;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
||||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||||
import org.alfresco.service.cmr.repository.TransformationOptionLimits;
|
import org.alfresco.service.cmr.repository.TransformationOptionLimits;
|
||||||
import org.alfresco.util.Triple;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to transformer limits defined via properties.
|
* Provides access to transformer limits defined via properties.
|
||||||
|
@@ -41,11 +41,9 @@ import org.alfresco.util.Triple;
|
|||||||
*/
|
*/
|
||||||
public abstract class TransformerPropertyNameExtractor
|
public abstract class TransformerPropertyNameExtractor
|
||||||
{
|
{
|
||||||
private static String[] SEPARATORS = new String[] {TransformerConfig.EXTENSIONS_SEPARATOR , TransformerConfig.MIMETYPES_SEPARATOR};
|
private static String[] SEPARATORS = new String[] {TransformerConfig.EXTENSIONS , TransformerConfig.MIMETYPES};
|
||||||
private static Pattern EXTENSIONS_SEPARATOR = Pattern.compile("[^].]\\.");
|
private static Pattern EXTENSIONS_SEPARATOR = Pattern.compile("[^]\\\\]\\.");
|
||||||
private static String[] NO_EXT_MATCH = new String[0];
|
private static String[] NO_EXT_MATCH = new String[0];
|
||||||
private static final String IS_MIMETYPE_SUBTYPE_WILDCARD_REGEX =
|
|
||||||
"(application|audio|image|message|model|multipart|text|video)/.*\\" + ANY + ".*";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a set of transformer name, source extension, target extension and value
|
* Returns a set of transformer name, source extension, target extension and value
|
||||||
@@ -89,21 +87,21 @@ public abstract class TransformerPropertyNameExtractor
|
|||||||
if (ext.length == 2)
|
if (ext.length == 2)
|
||||||
{
|
{
|
||||||
name = name.substring(0, i);
|
name = name.substring(0, i);
|
||||||
if (separator == TransformerConfig.EXTENSIONS_SEPARATOR)
|
if (separator == TransformerConfig.EXTENSIONS)
|
||||||
{
|
{
|
||||||
addTransformerSourceTargetValue(TransformerSourceTargetValues,
|
addTransformerSourceTargetValue(TransformerSourceTargetValues,
|
||||||
false, name, ext[0], ext[1], value, suffix, mimetypeService);
|
false, name, ext[0], ext[1], value, suffix, mimetypeService);
|
||||||
}
|
}
|
||||||
else // if (separator == TransformerConfig.MIMETYPES_SEPARATOR)
|
else if (separator == TransformerConfig.MIMETYPES)
|
||||||
{
|
{
|
||||||
List<String> sourceMimetypes = getMatchingMimetypes(ext[0], mimetypeService);
|
List<String> sourceExtensions = getMatchingExtensions(ext[0], mimetypeService);
|
||||||
List<String> targetMimetypes = getMatchingMimetypes(ext[1], mimetypeService);
|
List<String> targetExtensions = getMatchingExtensions(ext[1], mimetypeService);
|
||||||
for (String sourceMimetype : sourceMimetypes)
|
for (String sourceExt : sourceExtensions)
|
||||||
{
|
{
|
||||||
for (String targetMimetype : targetMimetypes)
|
for (String targetExt : targetExtensions)
|
||||||
{
|
{
|
||||||
addTransformerSourceTargetValue(TransformerSourceTargetValues,
|
addTransformerSourceTargetValue(TransformerSourceTargetValues,
|
||||||
true, name, sourceMimetype, targetMimetype, value,
|
true, name, sourceExt, targetExt, value,
|
||||||
suffix, mimetypeService);
|
suffix, mimetypeService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,8 +160,8 @@ public abstract class TransformerPropertyNameExtractor
|
|||||||
{
|
{
|
||||||
int i = matcher.start();
|
int i = matcher.start();
|
||||||
ext = new String[2];
|
ext = new String[2];
|
||||||
ext[0] = extensions.substring(0, i);
|
ext[0] = extensions.substring(0, i+1).replaceAll("\\\\\\.", ".");
|
||||||
ext[1] = extensions.substring(0, i);
|
ext[1] = extensions.substring(i+2).replaceAll("\\\\\\.", ".");
|
||||||
}
|
}
|
||||||
return ext;
|
return ext;
|
||||||
}
|
}
|
||||||
@@ -178,49 +176,24 @@ public abstract class TransformerPropertyNameExtractor
|
|||||||
* If the given mimetype string has no wildcards a list with only the given
|
* If the given mimetype string has no wildcards a list with only the given
|
||||||
* mimetype's extension is returned.
|
* mimetype's extension is returned.
|
||||||
*
|
*
|
||||||
* @param configMimetype
|
* @param mimetypeWildcardRegex
|
||||||
* @param mimetypeService
|
* @param mimetypeService
|
||||||
* @return the list of extensions of mimetypes which match
|
* @return the list of extensions of mimetypes which match
|
||||||
*/
|
*/
|
||||||
private List<String> getMatchingMimetypes(
|
private List<String> getMatchingExtensions(
|
||||||
String configMimetype, MimetypeService mimetypeService)
|
String mimetypeWildcardRegex, MimetypeService mimetypeService)
|
||||||
{
|
{
|
||||||
if (configMimetype == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<String> matchingMimetypes = new ArrayList<String>(1);
|
List<String> matchingMimetypes = new ArrayList<String>(1);
|
||||||
if (isMimetypeSubtypeWildcard(configMimetype))
|
for (String mimetype : mimetypeService.getMimetypes())
|
||||||
{
|
{
|
||||||
String mimetypeWildcardRegex = configMimetype.replaceAll("\\" + ANY, ".*");
|
if (mimetype.matches(mimetypeWildcardRegex))
|
||||||
for (String mimetype : mimetypeService.getMimetypes())
|
|
||||||
{
|
{
|
||||||
if (mimetype.matches(mimetypeWildcardRegex))
|
String ext = mimetypeService.getExtension(mimetype);
|
||||||
{
|
matchingMimetypes.add(ext);
|
||||||
String ext = mimetypeService.getExtension(mimetype);
|
|
||||||
matchingMimetypes.add(ext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
String ext = mimetypeService.getExtension(configMimetype);
|
|
||||||
matchingMimetypes.add(ext);
|
|
||||||
}
|
|
||||||
return matchingMimetypes;
|
return matchingMimetypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the given string is a mime type expression containing a wildcard
|
|
||||||
* in the subtype.
|
|
||||||
*
|
|
||||||
* @param mimetype
|
|
||||||
* @return whether or not the mime type contains a wildcard subtype
|
|
||||||
*/
|
|
||||||
private boolean isMimetypeSubtypeWildcard(String mimetype)
|
|
||||||
{
|
|
||||||
return (mimetype != null && mimetype.matches(IS_MIMETYPE_SUBTYPE_WILDCARD_REGEX));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TransformerSourceTargetValue
|
class TransformerSourceTargetValue
|
||||||
|
Reference in New Issue
Block a user