The Surf based Alfresco Share web application provides a highly customizable framework that allows you to override and customize the user interface via the share-config-custom.xml file. In this file, an evaluator element <config evaluator=”” condition=””> is used to target the elements for customization. These evaluators are managed by the SpringSurf XmlConfigService. This service is extended by the Alfresco web client framework to include the following default evaluators:
- string-compare defined by StringEvaluator
- node-type defined by NodeTypeEvaluator
- task-type defined by TaskTypeEvaluator
- aspect defined by AspectEvaluator
- object-type defined by ObjectTypeEvaluator
In addition to these you can implement your own evaluators. For example a StringRegexEvaluator that uses a regex to match any pattern defined in your share-custom-config.xml to override an element in the Share application. The two items needed for registering a custom evaluator is an evaluator plugin registration, along with the Java class that defines the Evaluator. For example:
package org.alfresco.consulting.evaluators; import org.springframework.extensions.config.evaluator.Evaluator; /** * Regex based Evaluator * @author Alexander Mahabir * */ public class StringRegexEvaluator implements Evaluator { @Override public boolean applies(Object obj, String condition) { if (obj instanceof String && ((String) obj).matches(condition) ) return true; return false; } }
And in your share-custom-config.xml, register the evaluator in the plug-ins element, as follows
Once this is in place, you can continue to to define your customizations in the share-config-custom.xml file using the string-regex evaluator with a regular expression as the condition. For example:
<alfresco-config> <plug-ins> <evaluators> <evaluator id="string-regex" class="org.alfresco.consulting.evaluators.StringRegexEvaluator" /> </evaluators> </plug-ins> <config evaluator="string-regex" condition="activiti.*"> <forms> <form> <appearance> <field id="packageItems"> <control > <control-param name="allowUpload">true</control-param> </control> </field> </appearance> </form> </forms> </config> </alfresco-config>
And in your pom.xml, you will need the following dependency:
<dependency> <groupId>org.springframework.extensions.surf</groupId> <artifactId>spring-surf-api</artifactId> <version>${dependency.surf.version}</version> <scope>provided</scope> </dependency>
To see a working example of this configuration, review the Alfresco Workflow Form Upload project, which uses this evaluator to add the upload functionality to all the activiti forms.
Note: This evaluation filter is not a spring wired bean. It will be instantiated when used.