User Agent Service

Purpose

A user agent is an application which is used to browse through the World Wide Web. Web user agents can be web browsers and search engine spiders as well as accessibility products like screen readers and braille browsers.

The user agent provides information about itself, when a web site is accessed. The information contains the brand and version of the browser and the operating system the browser is running on.

Example

User agent

Internet Explorer 5.5 running on MS Windows 2000

Provided information

Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0).

How to get the User Agent

Necessary SharingReference Entry in Deployment Descriptor

To use the user agent service you have to add a sharing reference entry to the deployment descriptor (file portalapp.xml ) in the section <application-config> .

The entry has following format:

< application-config>

< propertyname= "SharingReference"value= "com.sap.portal.useragent"/>

.

< /application-config>

Example

value= "htmlb,com.sap.portal.useragent"

Get the Useragent Service

The entry point of the user agent service is the interface IUserAgentService . You get this interface from the Portal Runtime (PRT) with following command:

IUserAgentServiceuserAgentService=(IUserAgentService)PortalRuntime.getRuntimeResources().getService( "com.sap.portal.useragent.useragent" );

Get the User Agent

To get the user agent , you have to get the user agent name first. With the user agent name and the user agent service you get the user agent from the HttpServletRequest object. You can use the following commands:

HttpServletRequestsRequest=request.getServletRequest();StringuserAgentName=sRequest.getHeader( "User-Agent" ); //UsingthisinformationyoucanusethemethodgetUserAgent()of//IUserAgentServicetogettheuseragentobjectoftypeIUserAgent: IUserAgentuserAgent=userAgentService.getUserAgent(sRequest.getHeader(userAgentName));

For more details about the usage of the userAgent methods refer to the PDK.

Get the User Agent Family

The user agent service also provides information about the user agent family with interface IUserAgentService. This interface provides the method getUserAgentFamily() that delivers the information. You get this interface with the following commands:

IUserAgentFamilyuserAgentFamily= userAgentService.getUserAgentFamily(); / * Fromthisobjectyougetanenumerationofalluseragentsetsof typeIUserAgentSetthatmatchestheIUserAgent:object:*/ Enumerationenum=userAgentFamily.findUserAgentSets(userAgent);