Milyn-Tinak Version 0.6.1

org.milyn.servlet
Class ServletUAContext

java.lang.Object
  extended byorg.milyn.servlet.ServletUAContext
All Implemented Interfaces:
java.io.Serializable, UAContext

public final class ServletUAContext
extends java.lang.Object
implements UAContext

Servlet useragent context.

Requirements

Deployment

Deploying Tinak in a J2EE Servlet Container is very simple:
  1. Download and explode the Tinak distribution.
  2. Deploy the Tinak binaries into the Servlet container i.e. into /WEB-INF/lib. The binaries are located in the "build" folder in the distribution.
  3. Deploy the Tinak dependencies into the Servlet container i.e. into /WEB-INF/lib. The dependencies are located in the "lib" folder in the distribution.
    Note: Don't copy the servlet.jar file to the target container.
  4. Deploy the Tinak device recognition XML module in the container. It's default deployment location is /WEB-INF/device-ident.xml but this can be configured in the deployment descriptor. A sample device-ident.xml can be found in the root of the distribution
  5. Deploy the Tinak device profiling XML module in the container. It's default deployment location is /WEB-INF/device-profile.xml but this can be configured in the deployment descriptor. A sample device-profile.xml can be found in the root of the distribution

As stated at the start of this section, the Tinak device recognition XML module default deployment location can be overridden. This is done through the web application's deployment descriptor as follows:

 <servlet>
 	<servlet-name>aservlet</servlet-name>
 	<servlet-class>org.milyn.some.AServlet</servlet-class>
 	<init-param>
 		<param-name>DeviceIdentUrl</param-name>
 		<param-value>URL</param-value>
 	</init-param>
 </servlet>
 
or,
 <context-param>
 	<param-name>DeviceIdentUrl</param-name>
 	<param-value>URL</param-value>
 </context-param>
 
checked by Tinak in that order. URL can be a context relative URL or a URL to an external resource i.e. and absolute URL. The ability to define an external URL means that two or more web applications can share the same configuration. It also means that the device recognition data can be stored in a database (or some other format) and accessed as an XML stream via a HTTP request. See "Device Recognition" for more.

The default deployment location of the profiling XML module can also be overridden in exactly the same fashion. The name of the parameter in this case is "DeviceProfileUrl".

Adding Browser Recognition & Profiling to a J2EE Servlet

Adding browser recognition and profiling support to a Servlet implementation using Tinak is very simple - literally a one-liner.

It's done using this class as follows:

 try {
     UAContext uaContext = ServletUAContext.getInstance(HttpServletRequest, ServletConfig);
 } catch(UnknownDeviceException unknownDevice) {
     // Handle Exception...
 }
The UAContext instance can then be used to: See the online user docs for details on how to configure device recognition and profiling in a Servlet container.

Author:
Tom Fennelly
See Also:
Serialized Form

Field Summary
protected static java.lang.String CONTEXT_KEY
          ServletUAContext session key.
static java.lang.String PROFILES_KEY
          Profiles Servlet Context key.
 
Method Summary
 java.lang.String getCommonName()
          Get the useragent common name.
static UAContext getInstance(javax.servlet.http.HttpServletRequest request, javax.servlet.ServletConfig config)
          Get the Useragent Context for the Servlet request.
 ProfileSet getProfileSet()
          Get the ProfileSet for the device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_KEY

protected static final java.lang.String CONTEXT_KEY
ServletUAContext session key.


PROFILES_KEY

public static final java.lang.String PROFILES_KEY
Profiles Servlet Context key.

Method Detail

getInstance

public static UAContext getInstance(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.ServletConfig config)
                             throws UnknownDeviceException
Get the Useragent Context for the Servlet request.

Factory construction method.

Parameters:
request - The HttpServletRequest instance associated with the request.
config - The Servet Configuration.
Returns:
Useragent context.
Throws:
UnknownDeviceException - Device match failure.

getCommonName

public java.lang.String getCommonName()
Get the useragent common name.

Specified by:
getCommonName in interface UAContext
Returns:
The useragent common name.

getProfileSet

public ProfileSet getProfileSet()
Get the ProfileSet for the device.

Specified by:
getProfileSet in interface UAContext
Returns:
The ProfileSet

Milyn-Tinak Version 0.6.1