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:
Alan Davis
2013-02-21 00:27:55 +00:00
parent 66bd490bb6
commit 2b1d9fc813
5 changed files with 23 additions and 54 deletions

View File

@@ -298,7 +298,7 @@ public abstract class AbstractContentTransformerLimits extends ContentTransforme
{
String targetExt = getExtensionOrAny(target.getKey());
TransformationOptionLimits limits = target.getValue();
String mimetypeSuffix = TransformerConfig.EXTENSIONS_SEPARATOR.substring(1)+sourceExt+'.'+targetExt;
String mimetypeSuffix = TransformerConfig.EXTENSIONS.substring(1)+sourceExt+'.'+targetExt;
deprecatedLimitsSetter(mimetypeSuffix, limits);
}

View File

@@ -237,7 +237,7 @@ public class ContentTransformerHelper implements BeanNameAware
String targetMimetype = transformation.getTargetMimetype();
String sourceExt = getExtensionOrAny(sourceMimetype);
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
? TransformerConfig.PRIORITY+"="+TransformerConfig.PRIORITY_EXPLICIT
: TransformerConfig.SUPPORTED+"="+value));

View File

@@ -68,13 +68,13 @@ public interface TransformerConfig
/**
* 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.
* 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.

View File

@@ -19,20 +19,16 @@
package org.alfresco.repo.content.transform;
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.LIMIT_SUFFIXES;
import static org.alfresco.repo.content.transform.TransformerConfig.EXTENSIONS_SEPARATOR;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.TransformationOptionLimits;
import org.alfresco.util.Triple;
/**
* Provides access to transformer limits defined via properties.

View File

@@ -41,11 +41,9 @@ import org.alfresco.util.Triple;
*/
public abstract class TransformerPropertyNameExtractor
{
private static String[] SEPARATORS = new String[] {TransformerConfig.EXTENSIONS_SEPARATOR , TransformerConfig.MIMETYPES_SEPARATOR};
private static Pattern EXTENSIONS_SEPARATOR = Pattern.compile("[^].]\\.");
private static String[] SEPARATORS = new String[] {TransformerConfig.EXTENSIONS , TransformerConfig.MIMETYPES};
private static Pattern EXTENSIONS_SEPARATOR = Pattern.compile("[^]\\\\]\\.");
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
@@ -89,21 +87,21 @@ public abstract class TransformerPropertyNameExtractor
if (ext.length == 2)
{
name = name.substring(0, i);
if (separator == TransformerConfig.EXTENSIONS_SEPARATOR)
if (separator == TransformerConfig.EXTENSIONS)
{
addTransformerSourceTargetValue(TransformerSourceTargetValues,
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> targetMimetypes = getMatchingMimetypes(ext[1], mimetypeService);
for (String sourceMimetype : sourceMimetypes)
List<String> sourceExtensions = getMatchingExtensions(ext[0], mimetypeService);
List<String> targetExtensions = getMatchingExtensions(ext[1], mimetypeService);
for (String sourceExt : sourceExtensions)
{
for (String targetMimetype : targetMimetypes)
for (String targetExt : targetExtensions)
{
addTransformerSourceTargetValue(TransformerSourceTargetValues,
true, name, sourceMimetype, targetMimetype, value,
true, name, sourceExt, targetExt, value,
suffix, mimetypeService);
}
}
@@ -162,8 +160,8 @@ public abstract class TransformerPropertyNameExtractor
{
int i = matcher.start();
ext = new String[2];
ext[0] = extensions.substring(0, i);
ext[1] = extensions.substring(0, i);
ext[0] = extensions.substring(0, i+1).replaceAll("\\\\\\.", ".");
ext[1] = extensions.substring(i+2).replaceAll("\\\\\\.", ".");
}
return ext;
}
@@ -178,21 +176,14 @@ public abstract class TransformerPropertyNameExtractor
* If the given mimetype string has no wildcards a list with only the given
* mimetype's extension is returned.
*
* @param configMimetype
* @param mimetypeWildcardRegex
* @param mimetypeService
* @return the list of extensions of mimetypes which match
*/
private List<String> getMatchingMimetypes(
String configMimetype, MimetypeService mimetypeService)
private List<String> getMatchingExtensions(
String mimetypeWildcardRegex, MimetypeService mimetypeService)
{
if (configMimetype == null)
{
return null;
}
List<String> matchingMimetypes = new ArrayList<String>(1);
if (isMimetypeSubtypeWildcard(configMimetype))
{
String mimetypeWildcardRegex = configMimetype.replaceAll("\\" + ANY, ".*");
for (String mimetype : mimetypeService.getMimetypes())
{
if (mimetype.matches(mimetypeWildcardRegex))
@@ -201,26 +192,8 @@ public abstract class TransformerPropertyNameExtractor
matchingMimetypes.add(ext);
}
}
}
else
{
String ext = mimetypeService.getExtension(configMimetype);
matchingMimetypes.add(ext);
}
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