While creating import services I want some configuration mechanism for (not just) BatchProcessor. I like Alfresco’s *-config-custom.xml files (aka Spring framework XMLConfigService), so I did simple custom config service.

Anyone, who customized Alfresco, knows format of this file (web-client-config-custom.xml). I put that structure to new file – mis-config-custom.xml:

    <config evaluator="string-compare" condition="imports">

Please note those constants are just for ilustration purposes now, more on them in scripting series. My MisConfigService extends org.springframework.extensions.config.xml.XMLConfigService, but uses nothing from that class (except init method in bootstrap), I just added some statics inside to keep things together:

public class MisConfigService extends XMLConfigService {
    public MisConfigService(ConfigSource configSource) {

    public static String getChildValue(Config config, String elementId, String childName, String defaultValue) {
        ConfigElement myConfig = config.getConfigElement(elementId);
        String result = myConfig.getChildValue(childName);

        return (result==null ? defaultValue : result);

    public static Integer getChildValue(Config config, String elementId, String childName, Integer defaultValue) {
        Integer result = defaultValue;
        try {
            String number = getChildValue(config, elementId, childName, defaultValue.toString());
            result = Integer.parseInt(number);
        } finally { /* O:-) */ }
        return result;

        . . .

To instantiate this service just add bean definition with UrlConfigSource(-s), which defines path to custom xml configuration:

<bean id="misConfigService" class="cz.mis.service.MisConfigService" init-method="init">
        <bean class="org.springframework.extensions.config.source.UrlConfigSource">

Now it’s possible to access those properties in code like this:

org.springframework.extensions.config.Config config = configService.getConfig(imports");
Boolean splitTransactions = MisConfigService.getChildValue(config, "processor", "split-transactions", false);

It’s also possible to access attributes of nodes in that config:

ConfigElement myConfig = config.getConfigElement("config-element");
for(ConfigElement child : myConfig.getChildren()) {
    // child.getAttributes()
    // child.getName()
    // child.getValue()

That’s all! And now for something completely different! I also spent some time trying to get properties files working and putting those properties into Spring configurations. There’s nice solved thread in Alfresco forums. Prefix helps:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <property name="ignoreResourceNotFound" value="true" />
    <property name="placeholderPrefix" value="${mis:" />
    <property name="placeholderSuffix" value="}" />

<!-- and I can use stuff from properties file with prefix -->
<bean class="foo.bar.Example">
    <property name="fooAttribute">