In Liferay 6.1, one of the new built in features are the Mobile Device Rules. To add a custom rule handler, it’s fairly simple. You need to create a hook with the following liferay-hook.xml:

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN"
 "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">
<hook>
     <portal-properties>portal.properties</portal-properties>
</hook>
In the portal properties, set a application startup hook.
application.startup.events=com.xtivia.CustomRuleHandlerStartupAction
Then, in the test startup action:
package com.xtivia;
 
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.kernel.mobile.device.rulegroup.RuleGroupProcessorUtil;
 
public class CustomRuleHandlerStartupAction extends SimpleAction {
 
    private static CustomRuleHandler _customRuleHandler = new CustomRuleHandler();
 
    public void run(String[] ids) throws ActionException {
        RuleGroupProcessorUtil.registerRuleHandler(_customRuleHandler);
    }
 
}
The CustomRuleHandler class needs to implement the com.liferay.portal.kernel.mobile.device.rulegroup.rule.RuleHandler interface, and the default implementation is contained within the com.liferay.portal.mobile.device.rulegroup.rule.impl.SimpleRuleHandler class.
Share This