User Agent Viewtool - Documentation topics on: browser,dotcms 3.3,operating system,rendering engine,user agent,viewtools that extend velocity,.

User Agent Viewtool

The User Agent Tool is a viewtool for getting user agent information from within Velocity code. It provides methods to get information about the user agent, device type, browser, browser version, operating system, manufacturer and rendering engine.  These can be used to display different versions of content depending on the user's platform.

Credit

This viewtool calls libraries from the user-agent-utils project by Harold Walker.

Usage

viewtool: com.dotmarketing.viewtools.UserAgentTool@322e87f7

Agent: $useragent.agent
Device type: $useragent.type
Browser: $useragent.browser
Browser version: $useragent.version
Operating System: $useragent.os
Manufacturer: $useragent.manufacturer
Rendering engine: $useragent.engine

Examples:

These examples demonstrate two of the most common uses of the User Agent Viewtool.

1. Display platform information

The following velocity code displays all platform information available from the User Agent Tool.

<pre>
Agent:        $useragent.agent
Type:         $useragent.type
Browser:      $useragent.browser
Version:      $useragent.version
OS:           $useragent.os
Manufacturer: $useragent.manufacturer
Engine:       $useragent.engine
</pre>

Which displays the following on a sample test system:

Agent:        WINDOWS_7-CHROME45
Type:         COMPUTER
Browser:      CHROME45
Version:      45.0.2454.99
OS:           WINDOWS_7
Manufacturer: MICROSOFT
Engine:       WEBKIT

2. Change how images are displayed on different platforms

The following velocity code resizes the displayed image to a width appropriate for the platform where the page is viewed.

#if(UNKNOWN == "MOBILE")
    #set($image_width = "250")
#elseif(UNKNOWN == "TABLET")
    #set($image_width = "400")
#else
    #set($image_width = "600")
#end
<img src="/contentAsset/image/c3d0ab93-cee9-4ed3-849d-2132701e6b0c/fileAsset/filter/Resize/resize_w/$!{image_width}" />

Return Values

All values are returned by the User Agent Viewtool as strings based on version 1.16 of the user-agent-utils project. See the following sections for specific values returned for each method.


Agent

$useragent.agent returns the user agent string provided by the web browser.


Device Type

$useragent.type returns one of the following Strings to identify the device type:

COMPUTER
MOBILE
TABLET
GAME_CONSOLE
WEARABLE
DMR- Digital Media Receiver like the Google TV
UNKNOWN

Browser

$useragent.browser returns one of the following Strings to identify the browser:

Apple

APPLE_ITUNES
APPLE_MAIL- Deprecated
APPLE_WEB_KIT
BLACKBERRY10
BOT
BOT_MOBILE
CAMINO
CAMINO2
CFNETWORK

Google Chrome

CHROME
CHROME_MOBILE
CHROME10
CHROME11
CHROME12
CHROME13
CHROME14
CHROME15
CHROME16
CHROME17
CHROME18
CHROME19
CHROME20
CHROME21
CHROME22
CHROME23
CHROME24
CHROME25
CHROME26
CHROME27
CHROME28
CHROME29
CHROME30
CHROME31
CHROME32
CHROME33
CHROME8
CHROME9

Firefox

FIREFOX
FIREFOX_MOBILE
FIREFOX_MOBILE23
FIREFOX1_5
FIREFOX10
FIREFOX11
FIREFOX12
FIREFOX13
FIREFOX14
FIREFOX15
FIREFOX16
FIREFOX17
FIREFOX18
FIREFOX19
FIREFOX2
FIREFOX20
FIREFOX21
FIREFOX22
FIREFOX23
FIREFOX24
FIREFOX25
FIREFOX26
FIREFOX27
FIREFOX28
FIREFOX29
FIREFOX3
FIREFOX30
FIREFOX3MOBILE
FIREFOX4
FIREFOX5
FIREFOX6
FIREFOX7
FIREFOX8
FIREFOX9
FLOCK

Internet Explorer

IE
IE10
IE11
IE5
IE5_5
IE6
IE7
IE8
IE9
IEMOBILE10
IEMOBILE11- Since 2007 the mobile edition of Internet Explorer identifies itself as IEMobile in the user-agent.
IEMOBILE6
IEMOBILE7
IEMOBILE9

Other

DOLFIN2
DOWNLOAD
EUDORA
EVOLUTION
KONQUEROR
LOTUS_NOTES
LYNX
MOBILE_SAFARI
MOZILLA
NETFRONT
OMNIWEB
OPERA
OPERA_MINI
OPERA10
OPERA11
OPERA12
OPERA15
OPERA16
OPERA17
OPERA18
OPERA19
OPERA20
OPERA9
UNKNOWN

Email client

OUTLOOK
OUTLOOK_EXPRESS7- Since version 7, Outlook Express identifies as itself.
OUTLOOK2007- Microsoft Outlook 2007 identifies itself as MSIE7 but uses the Microsoft Word 2007 html rendering engine.
OUTLOOK2010- Microsoft Outlook 2010 still uses the Microsoft Word rendering engine.
OUTLOOK2013
POCOMAIL
SAFARI
SAFARI4
SAFARI5
SAFARI6
SEAMONKEY
SILK
THEBAT
THUNDERBIRD
THUNDERBIRD10
THUNDERBIRD11
THUNDERBIRD12
THUNDERBIRD2
THUNDERBIRD3
THUNDERBIRD6
THUNDERBIRD7
THUNDERBIRD8

Operating System

$useragent.os returns one of the following Strings to identify the operating system:

Apple

IOS- iOS4; with the release of the iPhone 4, Apple renamed the OS to iOS.
iOS4_IPHONE
iOS5_IPHONE
iOS6_IPAD
iOS6_IPHONE
iOS7_IPAD
iOS7_IPHONE
iOS8_1_IPAD
iOS8_1_IPHONE
iOS8_2_IPAD
iOS8_2_IPHONE
iOS8_3_IPAD
iOS8_3_IPHONE
iOS8_4_IPAD
iOS8_4_IPHONE
iOS8_IPAD
iOS8_IPHONE
iOS9_IPAD
iOS9_IPHONE
MAC_OS- Older Mac OS systems before Mac OS X.
MAC_OS_X
MAC_OS_X_IPAD
MAC_OS_X_IPHONE
MAC_OS_X_IPOD

Google

ANDROID
ANDROID_MOBILE- Generic Android mobile device without OS version number information.
ANDROID_TABLET- Generic Android tablet device without OS version number information.
ANDROID1
ANDROID2
ANDROID2_TABLET
ANDROID3_TABLET
ANDROID4
ANDROID4_TABLET
ANDROID4_WEARABLE
ANDROID5
ANDROID5_TABLET
CHROME_OS- Chrome OS by Google, mostly used on Chromebooks and Chromeboxes.
GOOGLE_TV- Google TV uses Android 2.x or 3.x but doesn't identify itself as Android.

Microsoft

WINDOWS- Windows Mobile / Windows CE.
WINDOWS_10
WINDOWS_2000
WINDOWS_7
WINDOWS_8
WINDOWS_81
WINDOWS_98
WINDOWS_MOBILE
WINDOWS_MOBILE7
WINDOWS_PHONE8
WINDOWS_PHONE8_1
WINDOWS_VISTA
WINDOWS_XP
XBOX_OS

Other

BADA- A mobile operating system being developed by Samsung Electronics.
BLACKBERRY- BlackBerryOS.
BLACKBERRY_TABLET
BLACKBERRY6
BLACKBERRY7
KINDLE- Various Linux based operating systems.
KINDLE2
KINDLE3
LINUX
MAEMO- Linux based Maemo software platform by Nokia.
MEEGO
PALM
PROXY- Proxy server that hides the original user-agent.
PSP
ROKU
SERIES40- Nokia's Series 40 operating system.
SONY_ERICSSON- Proprietary operating system used for many Sony Ericsson phones.
SUN_OS
SYMBIAN- Other Symbian OS versions.
SYMBIAN6- Symbian OS 6.x versions.
SYMBIAN7- Symbian OS 7.x versions.
SYMBIAN8- Symbian OS 8.x versions.
SYMBIAN9- Symbian OS 9.x versions.
UNKNOWN
UNKNOWN_MOBILE
UNKNOWN_TABLET
WEBOS- PalmOS, exact version unknown.
WII- Nintendo Wii game console.

Manufacturer

$useragent.manufacturer returns one of the following Strings to identify the manufacturer of the device or operating system:

ADOBE- Adobe Systems Inc.
AMAZON- Amazon.com, Inc.
AOL- AOL LLC
APPLE- Apple Inc.
BLACKBERRY- Research In Motion Limited
COMPUSERVE- CompuServe Interactive Services, Inc.
CONONICAL- Canonical Ltd.
GOOGLE- Google Inc.
HP- Hewlett-Packard Company (previously Palm)
MICROSOFT- Microsoft Corporation
MMC- Mail.com Media Corporation
MOZILLA- Mozilla Foundation
NINTENDO- Nintendo
NOKIA- Nokia Corporation
OPERA- Opera Software ASA
ROKU- Roku sells home digital media products
SAMSUNG- Samsung Electronics
SONY- Sony Computer Entertainment, Inc.
SONY_ERICSSON- Sony Ericsson Mobile Communications AB
SUN- Sun Microsystems, Inc. (now Oracle)
SYMBIAN- Symbian Ltd.
YAHOO- Yahoo Inc.
OTHER- Unknow or rare manufacturer

Rendering Engine

$useragent.engine returns one of the following Strings to identify the HTML rendering engine:

BLINK- Layout engine developed as part of the Chromium project.
GECKO- Open source and cross platform layout engine, used by Firefox and many other browsers.
KHTML- Layout engine of the KDE project.
MOZILLA- Original layout engine of the Mozilla browser and related products.
OTHER- Other or unknown layout engine.
PRESTO- Proprietary layout engine by Opera Software ASA.
TRIDENT- Microsoft layout engine, mainly used by Internet Explorer.
WEBKIT- Layout engine based on KHTML, used by Safari, Chrome and some other browsers.
WORD- HTML parsing and rendering engine of Microsoft Office Word and some other Microsoft products.

For more detailed documentation on each of these values, see the documentation on the user-agent-utils project home page.