Content style  Sample navstyles.xml file

Chapter 10: Building Page Groups

UserAgentMapping

UserAgentMapping.xml, located in %SYBASE%\UnwiredAccelerator70\tomcat\webapps\onepage\fw\properties, maps the UserAgents to the navigation and content styles. Several UserAgent mappings are defined by default. For example:

<UserAgentMapping>  <UserAgent clientpattern="Mozilla">    <NavStyle name="Default"/>     <Content name="portal" type="text/html"/>   </UserAgent><UserAgent clientpattern="MSIE" platform="PPC"> <NavStyle name="PocketPC/PDA"/>  <Content name="portal" type="text/html"/>  <ResolutionHeader name="UA-pixels"/>   </UserAgent>

The clientpattern and platform attribute values are from the client’s User-Agent HTTP header. The User-Agent header usually contains the platform and browser information. In device detection, Unwired Accelerator matches the platform substring against the User-Agent header first.

The name attribute value in the NavStyle element is from navstyles.xml. This specifies the Navigation Style the UserAgent supports. The name attribute value in Content element is from oem.xml. This specifies the Content Style that application playback should use for the UserAgent.

StepsDefining a custom template for Content Style

  1. Implement the interface com.onepage.fw.uwp.interfaces.uwp.UWPMobileTemplate:

    String getTemplate
    

    This returns the template string name, or if there are any errors, NULL. The template string name should match one of the names listed in the Template Manager in Mobile Web Studio.

  2. Compile it. All the required JARs are in WEB-INF\lib.

    Check the XML data by going to:

    http://host.domain.com/onepage/servlet/UWPServlet?wid=<wid>&content=text/xml
    

    <wid> is the application ID you see in the application properties in Application Builder.

  3. Move the implementation in the WEB-INF\classes directory.

  4. Set “WAPCustomTemplate:<class package>” in the name attribute of the Content element. For example:

    <Content name=“WAPCustomTemplate:com.sybase.template.MyTemplate”
    

Defining a custom template example

In this example, the OpenWave Basic template is returned. The OpenWave Basic template is located in %SYBASE%\UnwiredAccelerator70\tomcat\webapps\onepage\portlets\templates\mobile\openwave.xsl.

package com.sybase.ep.utils;
 
import com.onepage.fw.uwp.interfaces.uwp.*;
import javax.servlet.http.*;
import java.io.*;
 
/**
 * Sample custom template for openwave browsers */
public class OpenWaveTemplate implements UWPMobileTemplate
{
    public String getTemplate (UWPRequest request) 
    {
        HttpServletRequest req =
(HttpServletRequest)request.GetServletRequest();
        String agent = req.getHeader("User-Agent");
        if (agent.indexOf ("UP.Browser") >= 0) {
            return "OpenWave Basic";
        }
        else {
            return null;
        }
}

For this example, the custom template is used on OpenWave browsers, so you must modify the content in UserAgentMapping.xml to say:

<UserAgent clientpattern="UP.Browser" platform="UP.Browser">
    <NavStyle name="Phone-WML"/>
    <Content name="WAPCustomTemplate:com.sybase.ep.utils.OpenWaveTemplate"
type="text/vnd.wap.wml"/>
</UserAgent>




Copyright © 2005. Sybase Inc. All rights reserved. Sample navstyles.xml file

View this book as PDF