mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
MNT-7158: Investigating adding priorities to transformers
- addition of methods to support the admin ui such as list of test file extensions, property names for custom properties and 'uses' - NPE if on removeProperties(...) if no value is supplied - Allow * transformer name to be used in a pipeline property in a setProperties(...) call git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55771 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Debug and Log buffer sizes
|
||||
# ==========================
|
||||
transformer.debug.entries=0
|
||||
transformer.log.entries=50
|
||||
transformer.log.entries=0
|
||||
|
||||
|
||||
# Base setting for all transformers
|
||||
|
@@ -93,6 +93,21 @@ public interface TransformerConfigMBean
|
||||
*/
|
||||
public String testTransform(String transformerName, String sourceExtension, String targetExtension, String use);
|
||||
|
||||
/**
|
||||
* Lists the names of the contexts or uses.
|
||||
*/
|
||||
public String[] getContextNames();
|
||||
|
||||
/**
|
||||
* Lists custom (non default) property names.
|
||||
*/
|
||||
public String[] getCustomePropertyNames();
|
||||
|
||||
/**
|
||||
* Lists the extensions of available test files.
|
||||
*/
|
||||
public String[] getTestFileExtensionsAndMimetypes();
|
||||
|
||||
/**
|
||||
* Returns a description of each method and its parameters.
|
||||
*/
|
||||
|
@@ -288,8 +288,11 @@ public class TransformerConfigMBeanImpl implements TransformerConfigMBean
|
||||
{
|
||||
try
|
||||
{
|
||||
propertyNames = nullDefaultParam(propertyNames);
|
||||
return "Properties removed: "+
|
||||
transformerConfig.removeProperties(nullDefaultParam(propertyNames));
|
||||
(propertyNames == null
|
||||
? 0
|
||||
: transformerConfig.removeProperties(propertyNames));
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
@@ -315,6 +318,38 @@ public class TransformerConfigMBeanImpl implements TransformerConfigMBean
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getContextNames()
|
||||
{
|
||||
return new String[] {"", "doclib", "index", "webpreview", "syncRule", "asyncRule"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCustomePropertyNames()
|
||||
{
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
String[] lines = getProperties(false).split("\\n");
|
||||
for (String line: lines)
|
||||
{
|
||||
if (!line.isEmpty() && !line.startsWith("#") && line.indexOf(" # default=") == -1)
|
||||
{
|
||||
int i = line.indexOf('=');
|
||||
if (i != 0)
|
||||
{
|
||||
String propertyName = line.substring(0, i);
|
||||
propertyNames.add(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return propertyNames.toArray(new String[propertyNames.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTestFileExtensionsAndMimetypes()
|
||||
{
|
||||
return transformerDebug.getTestFileExtensionsAndMimetypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full transformer name given a simple transformer name parameter.
|
||||
* @param simpleTransformerName the name of the transformer without the
|
||||
@@ -427,6 +462,15 @@ public class TransformerConfigMBeanImpl implements TransformerConfigMBean
|
||||
" - transformerName to be checked. If blank all transformers are included\n" +
|
||||
" - use or context in which the transformation will be used (\"doclib\",\n" +
|
||||
" \"index\", \"webpreview\", \"syncRule\", \"asyncRule\"...) or blank for\n" +
|
||||
" the default.";
|
||||
" the default.\n"+
|
||||
"\n" +
|
||||
"getCustomePropertyNames()\n" +
|
||||
" Lists custom (non default) property names\n" +
|
||||
"\n" +
|
||||
"getContextNames()\n" +
|
||||
" Lists the names of the contexts or uses\n" +
|
||||
"\n" +
|
||||
"getTestFileExtensionsAndMimetypes()\n" +
|
||||
" Lists the extensions of available test files";
|
||||
}
|
||||
}
|
||||
|
@@ -1353,14 +1353,53 @@ public class TransformerDebug
|
||||
}.run(sourceExtension, targetExtension, use);
|
||||
}
|
||||
|
||||
public String[] getTestFileExtensionsAndMimetypes()
|
||||
{
|
||||
List<String> sourceExtensions = new ArrayList<String>();
|
||||
Collection<String> sourceMimetypes = mimetypeService.getMimetypes(null);
|
||||
for (String sourceMimetype: sourceMimetypes)
|
||||
{
|
||||
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
|
||||
if (loadQuickTestFile(sourceExtension) != null)
|
||||
{
|
||||
sourceExtensions.add(sourceExtension+" - "+sourceMimetype);
|
||||
}
|
||||
}
|
||||
|
||||
return sourceExtensions.toArray(new String[sourceExtensions.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one of the "The quick brown fox" files from the classpath.
|
||||
* @param extension required, eg <b>txt</b> for the file quick.txt
|
||||
* @return Returns a test resource loaded from the classpath or <tt>null</tt> if
|
||||
* no resource could be found.
|
||||
*/
|
||||
private File loadQuickTestFile(String extension)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = this.getClass().getClassLoader().getResource("quick/quick." + extension);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ResourceUtils.getFile(url);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class TestTransform
|
||||
{
|
||||
String run(String sourceExtension, String targetExtension, String use)
|
||||
{
|
||||
String debug;
|
||||
|
||||
String sourceMimetype = getMimetype(sourceExtension, true);
|
||||
String targetMimetype = getMimetype(targetExtension, false);
|
||||
String sourceMimetype = getMimetype(sourceExtension, true);
|
||||
File sourceFile = loadQuickTestFile(sourceExtension);
|
||||
if (sourceFile == null)
|
||||
{
|
||||
@@ -1424,28 +1463,5 @@ public class TransformerDebug
|
||||
}
|
||||
|
||||
protected abstract void transform(ContentReader reader, ContentWriter writer, TransformationOptions options);
|
||||
|
||||
/**
|
||||
* Load one of the "The quick brown fox" files from the classpath.
|
||||
* @param extension required, eg <b>txt</b> for the file quick.txt
|
||||
* @return Returns a test resource loaded from the classpath or <tt>null</tt> if
|
||||
* no resource could be found.
|
||||
*/
|
||||
private File loadQuickTestFile(String extension)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = this.getClass().getClassLoader().getResource("quick/quick." + extension);
|
||||
if (url == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ResourceUtils.getFile(url);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.content.transform;
|
||||
|
||||
import static org.alfresco.repo.content.transform.TransformerConfig.ANY;
|
||||
import static org.alfresco.repo.content.transform.TransformerConfig.AVAILABLE;
|
||||
import static org.alfresco.repo.content.transform.TransformerConfig.CONTENT;
|
||||
import static org.alfresco.repo.content.transform.TransformerConfig.ERROR_TIME;
|
||||
@@ -139,11 +140,14 @@ public class TransformerPropertySetter
|
||||
|
||||
for (String transformerSimpleName: transformerReferences.keySet())
|
||||
{
|
||||
String name = TRANSFORMER+transformerSimpleName;
|
||||
if (!allTransformerNames.contains(name))
|
||||
if (!ANY.equals(transformerSimpleName))
|
||||
{
|
||||
String line = transformerReferences.get(transformerSimpleName);
|
||||
throw unexpectedProperty("Transformer "+transformerSimpleName+" does not exist", line);
|
||||
String name = TRANSFORMER+transformerSimpleName;
|
||||
if (!allTransformerNames.contains(name))
|
||||
{
|
||||
String line = transformerReferences.get(transformerSimpleName);
|
||||
throw unexpectedProperty("Transformer "+transformerSimpleName+" does not exist", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user