ALF-9981 Due to Spring 3.0 SPEL running on FTL entries like ${foo} before they are passed as properties to beans, support an escaped form of \$\{foo\} which is un-escaped before being passed to the FreeMarker engine. Updates the template code for scheduled actions to un-escape, and the example action definitions to be escaped

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30551 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-09-15 16:02:25 +00:00
parent 127ca27aa0
commit 3eed98f84a
2 changed files with 34 additions and 12 deletions

View File

@@ -33,7 +33,8 @@
<key>
<value>{http://www.alfresco.org/model/content/1.0}categories</value>
</key>
<value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/cm:generalclassifiable/cm:Languages/cm:English"' )}</value>
<!-- Note - FreeMarker ${..} entries must be escaped in Spring context files -->
<value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/cm:generalclassifiable/cm:Languages/cm:English"' )\}</value>
</entry>
</map>
</property>
@@ -95,19 +96,22 @@
<key>
<value>destination-folder</value>
</key>
<value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home"' )}</value>
<!-- Note - FreeMarker ${..} entries must be escaped in Spring context files -->
<value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home"' )\}</value>
</entry>
<entry>
<key>
<value>assoc-type</value>
</key>
<value>${node.primaryParentAssoc.typeQName}</value>
<!-- Note - FreeMarker ${..} entries must be escaped in Spring context files -->
<value>\$\{node.primaryParentAssoc.typeQName\}</value>
</entry>
<entry>
<key>
<value>assoc-name</value>
</key>
<value>${node.primaryParentAssoc.QName}</value>
<!-- Note - FreeMarker ${..} entries must be escaped in Spring context files -->
<value>\$\{node.primaryParentAssoc.QName\}</value>
</entry>
<entry>
<key>
@@ -150,7 +154,8 @@
<key>
<value>value</value>
</key>
<value>${today?string("yyyy-MM-dd'T'HH:mm:ss.sss'Z'")}</value>
<!-- Note - FreeMarker ${..} entries must be escaped in Spring context files -->
<value>\$\{today?string("yyyy-MM-dd'T'HH:mm:ss.sss'Z'")\}</value>
</entry>
</map>
</property>
@@ -402,7 +407,8 @@
</list>
</property>
<property name="queryTemplate">
<value>@cm\:created:${luceneDateRange(yesterday, "-P10Y")}</value>
<!-- Note - FreeMarker ${..} entries must be escaped in Spring context files -->
<value>@cm\:created:\$\{luceneDateRange(yesterday, "-P10Y")\}</value>
</property>
<property name="cronExpression">
<value>0 0/1 * * * ?</value>
@@ -439,4 +445,4 @@
</property>
</bean>
</beans>
</beans>

View File

@@ -36,6 +36,9 @@ import org.springframework.context.ApplicationContextAware;
/**
* This class defines the template used to build a single action.
*
* Because SPEL will eat ${foo} or #{foo} in the template when specified in the XML,
* this will also accept \$\{foo\} or \#\{foo\} as well.
*
* @author Andy Hind
*/
public class SimpleTemplateActionDefinition extends AbstractTemplateActionDefinition implements ApplicationContextAware
@@ -176,17 +179,30 @@ public class SimpleTemplateActionDefinition extends AbstractTemplateActionDefini
// Go through the template definitions and set the values.
for (String paramName : parameterTemplates.keySet())
{
// Transform the template
// Fetch the template. Need to de-escape things put in to work
// around it not being possible to disable SPEL for one bean
String template = parameterTemplates.get(paramName);
String stringValue = templateService.processTemplateString(getTemplateActionModelFactory()
.getTemplateEngine(), template, getTemplateActionModelFactory().getModel(nodeRef));
if(template.contains("\\$\\{") || template.contains("\\#\\{"))
{
template = template.replace("\\$\\{", "${");
template = template.replace("\\#\\{", "#{");
if(template.contains("\\}"))
{
template = template.replace("\\}", "}");
}
}
// Transform the template
String stringValue = templateService.processTemplateString(
getTemplateActionModelFactory().getTemplateEngine(),
template, getTemplateActionModelFactory().getModel(nodeRef));
// Find the data type from the action defintion
DataTypeDefinition dataTypeDef;
if (actionDefinition.getParameterDefintion(paramName) != null)
{
dataTypeDef = dictionaryService
.getDataType(actionDefinition.getParameterDefintion(paramName).getType());
dataTypeDef = dictionaryService.getDataType(
actionDefinition.getParameterDefintion(paramName).getType());
}
// Fall back to the DD using the property name of it is not defined
// This is sometimes used for setting a property to a value.