Creating device-specific portlet content using Multi-Channel Server APIs

You can create device-specific content by retrieving device policy values.

Portlets may require information about device policies to render content dependent on device capabilities. To access this information, there are APIs that you may use, in either the portlet Java™ class, or portlet JSP, as illustrated in the examples that follow.

Java portlet

The following example illustrates how you can use the doView method of the Java Portlet implementation class to get the device name and the mfg (manufacturer) policy for the requesting device:
public void doView(PortletRequest request, PortletResponse response)
    throws PortletException, IOException
{
        
    try{
        com.ibm.mwp.util.mcs.MCSUtil.getMarinerServletApplication();
        com.volantis.mcs.devices.Device device = mcs.getDevice(request);
        String deviceName = device.getName();
        String mfg = device.getPolicyValue("mfg");

        System.out.println("device.getName() = "+deviceName);
        System.out.println("device.getPolicyValue(\"mfg\") = "+mfg);
    }catch(Exception ex){
        ex.printStackTrace();
    }
}

JSP portlet

If you are including a JSP and prefer to add code there, you can use this sample:
<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>
<portletAPI:init/>

<%
    try{
        com.ibm.mwp.util.mcs.MCSUtil.getMarinerServletApplication();
        com.volantis.mcs.devices.Device device = mcs.getDevice(portletRequest);
        String deviceName = device.getName();
        String mfg = device.getPolicyValue("mfg");
%>            
        Device name: <%=deviceName%>
        Manufacturer: <%=mfg%>
<%
        }catch(Exception ex){
                ex.printStackTrace();
        }
%>
The getPolicyValue() method takes a device policy attribute name as input and returns a string. To get the list of device policy names, use the Mobile Portal Toolkit Device Policy Browser. The policy names that can be used with the getPolicyValue() method are in the shortname column displayed by the device policy browser.



Terms of use
(C) Copyright IBM Corporation 2012. All Rights Reserved.