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
- Added TransformerConfigSupported isMimetype and isMimetypeSubtypeWildcard methods which check a given string - Added TransformerConfigSupported getMatchingMimetypes which gets all matching mime types from the mimetypeService if wildcards are present, otherwise passes the given mimetype on - Modified TransformerConfigSupported setSupported to check for mimetypes and call getMatchingMimetypes in addition to existing support for extensions git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@46807 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,8 +23,10 @@ import static org.alfresco.repo.content.transform.TransformerConfig.CONTENT;
|
||||
import static org.alfresco.repo.content.transform.TransformerConfig.MIMETYPES_SEPARATOR;
|
||||
import static org.alfresco.repo.content.transform.TransformerConfig.SUPPORTED;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -41,6 +43,11 @@ import org.alfresco.util.Triple;
|
||||
*/
|
||||
public class TransformerConfigSupported extends TransformerPropertyNameExtractor
|
||||
{
|
||||
private static final String IS_MIMETYPE_REGEX =
|
||||
"(application|audio|image|message|model|multipart|text|video)/.+";
|
||||
private static final String IS_MIMETYPE_SUBTYPE_WILDCARD_REGEX =
|
||||
"(application|audio|image|message|model|multipart|text|video)/.*\\" + ANY + ".*";
|
||||
|
||||
// Holds configured (entries only exist if configured rather than for all possible combinations)
|
||||
// of supported and unsupported mimetypes transformations for a transformer.
|
||||
// SourceMimetype and targetMimetype may be 'ANY' values to act as wild cards.
|
||||
@@ -50,6 +57,69 @@ public class TransformerConfigSupported extends TransformerPropertyNameExtractor
|
||||
{
|
||||
setSupported(subsystem, mimetypeService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given string is a mime type expression.
|
||||
*
|
||||
* @param extension
|
||||
* @return whether or not the string is a mime type
|
||||
*/
|
||||
private boolean isMimetype(String extension)
|
||||
{
|
||||
return (extension != null && extension.matches(IS_MIMETYPE_REGEX));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mimetypes which match the given <code>configMimetype</code> from the given
|
||||
* <code>mimetypeService</code>.
|
||||
* <p>
|
||||
* If the given mime type string contains one or more wildcards (*) in the subtype, the string
|
||||
* is converted to a regular expression and any mimetypes which match are returned.
|
||||
* <p>
|
||||
* If the given mime type string has no wildcards a list with only the given
|
||||
* mime type is returned.
|
||||
*
|
||||
* @param configMimetype
|
||||
* @param mimetypeService
|
||||
* @return the list of mime types which match the wildcard, or a list with just the given mimetype
|
||||
*/
|
||||
private List<String> getMatchingMimetypes(
|
||||
String configMimetype, 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))
|
||||
{
|
||||
matchingMimetypes.add(mimetype);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
matchingMimetypes.add(configMimetype);
|
||||
}
|
||||
return matchingMimetypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the supported/unsupported mimetype transformations created from system properties.
|
||||
@@ -62,17 +132,12 @@ public class TransformerConfigSupported extends TransformerPropertyNameExtractor
|
||||
Set<Triple<String, String, String>> transformerNamesAndMimetypes =
|
||||
getTransformerNamesAndExt(MIMETYPES_SEPARATOR, Collections.singletonList(SUPPORTED), false, subsystem, mimetypeService);
|
||||
|
||||
|
||||
|
||||
|
||||
// Populate the transformer values
|
||||
for (Triple<String, String, String> triple: transformerNamesAndMimetypes)
|
||||
{
|
||||
String transformerName = triple.getFirst();
|
||||
String sourceExt = triple.getSecond();
|
||||
String targetExt = triple.getThird();
|
||||
String sourceMimetype = ANY.equals(sourceExt) ? ANY : mimetypeService.getMimetype(sourceExt);
|
||||
String targetMimetype = ANY.equals(targetExt) ? ANY : mimetypeService.getMimetype(targetExt);
|
||||
|
||||
SupportedAndUnsupportedTransformations supportedBytransformer = this.supported.get(transformerName);
|
||||
|
||||
@@ -82,7 +147,32 @@ public class TransformerConfigSupported extends TransformerPropertyNameExtractor
|
||||
this.supported.put(transformerName, supportedBytransformer);
|
||||
}
|
||||
boolean supported = getValueFromProperties(transformerName, sourceExt, targetExt, subsystem, SUPPORTED);
|
||||
supportedBytransformer.put(sourceMimetype, targetMimetype, supported);
|
||||
|
||||
List<String> sourceMimetypes = new ArrayList<String>(1);
|
||||
List<String> targetMimetypes = new ArrayList<String>(1);
|
||||
if (isMimetype(sourceExt))
|
||||
{
|
||||
sourceMimetypes.addAll(getMatchingMimetypes(sourceExt, mimetypeService));
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceMimetypes.add(ANY.equals(sourceExt) ? ANY : mimetypeService.getMimetype(sourceExt));
|
||||
}
|
||||
if (isMimetype(targetExt))
|
||||
{
|
||||
targetMimetypes.addAll(getMatchingMimetypes(targetExt, mimetypeService));
|
||||
}
|
||||
else
|
||||
{
|
||||
targetMimetypes.add(ANY.equals(targetExt) ? ANY : mimetypeService.getMimetype(targetExt));
|
||||
}
|
||||
for (String sourceMimetype : sourceMimetypes)
|
||||
{
|
||||
for (String targetMimetype : targetMimetypes)
|
||||
{
|
||||
supportedBytransformer.put(sourceMimetype, targetMimetype, supported);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user