【转自官网】WURFL 浏览器版本识别API+末尾附WURFL工具包
来源:互联网 发布:阿里云节点选择 编辑:程序博客网 时间:2024/06/05 16:06
WURFL OnSite Java API: User Guide
Please note - there are breaking changes in API release v1.8. For documentation of releases before API v1.8 please refer to the README file included with that version. If you need aditional help for versions prior to 1.8 feel free to contact us at support@scientiamobile.com
Installation
To enable WURFL on your application you need to register for a free
account on scientiamobile.com and download the latest release from
your file manager. Once you have imported the included JAR files,
you are ready to begin configuring WURFL in your application. If you
are using Maven to handle external dependencies, you can import
WURFl by following this
tutorial.
*Note: The WURFL API is closely tied to the wurfl.xml
file. New versions
of the wurfl.xml
are compatible with old versions of the API by nature,
but the reverse is not true. Old versions of the wurfl.xml
are not
guaranteed to be compatible with new versions of the API.*
The WURFLEngine
is a high-level interface introduced to further
abstract and simplify management of the WURFL API.
In most cases, initializing the WURFLEngine
is enough to start
using the API and is the entry point to all WURFL functionalities.
The default implementation of WURFLEngine
is GeneralWURFLEngine
.
Please note that since version 1.8.0.0 the package names have changed to com.scientiamobile
: update your configuration accordingly. If by any chance you need to update with the old package name a legacy release package will be present. All new modules, like WurflUpdater
, will only be available with the new package names.
import com.scientiamobile.wurfl.core.Device;import com.scientiamobile.wurfl.core.EngineTarget;import com.scientiamobile.wurfl.core.GeneralWURFLEngine;public class Wurfl { public static void main(String[] args) { GeneralWURFLEngine wurfl = new GeneralWURFLEngine("wurfl.xml"); wurfl.setEngineTarget(EngineTarget.accuracy); String user_agent = "Mozilla/5.0 (Linux; Android 4.2.1; N9600 Build/JOP40D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.111 Mobile Safari/537.36"; Device device = wurfl.getDeviceForRequest(user_agent); System.out.println("Is Tablet: " + device.getCapability('is_tablet')); System.out.println("Can Assign Phone Number: " + device.getCapability('can_assign_phone_number')); }}
If you are configuring using a web.xml
file, you can:
<listener> <listener-class> com.scientiamobile.wurfl.core.web.WURFLServletContextListener </listener-class></listener><context-param> <param-name>wurfl</param-name> <param-value>/WEB-INF/wurfl.zip</param-value></context-param><context-param> <param-name>wurflPatch</param-name> <param-value>/WEB-INF/patch_1.xml,/WEB-INF/patch_2.xml</param-value></context-param><context-param> <param-name>wurflEngineTarget</param-name> <param-value>accuracy</param-value></context-param>
Capability Filtering
In order to reduce memory usage and increase performance, you can specify a
subset of the 500+ WURFL capabilities to load into memory. The list of the
selected capabilities can be set by calling the setCapabilityFilter
method
on a WURFLEngine
instance. The list can be passed as either a string array
(String[]
) or as a generic collection (Collection<String>
):
String[] capabilities = { "device_os", "brand_name", "model_name", "release_date", "has_qwerty_keyboard"};
If you are configuring using a web.xml
file, you can apply a filter by:
<context-param> <param-name>capability-filter</param-name> <param-value> device_os brand_name model_name release_date has_qwerty_keyboard </param-value></context-param>
Virtual Capabilities
Virtual capabilities are an important feature of the WURFL API that
obtain values related to the requesting agent out of the HTTP request
as a whole (as opposed to limiting itself to capabilities that are found
in WURFL).
In order to compute its final returned value, a virtual capability may
look at regular (non-virtual) capabilities as well as other parameters
that can be derived from the HTTP request at run-time. Virtual capabilities
are useful to model aspects of the HTTP Client that are not easily captured
through the finite number of profiles in WURFL.
Virtual capabilities depend on certain real capabilities, which may be
considered mandatory for this reason. These capabilities are:
device_os
device_os_version
is_tablet
is_wireless_device
pointing_method
preferred_markup
resolution_height
resolution_width
ux_full_desktop
xhtml_support_level
is_smarttv
can_assign_phone_number
brand_name
model_name
marketing_name
mobile_browser_version
To retrieve the value of a virtual capability, use the getVirtualCapability()
method from a Device
object:
device.getVirtualCapability("is_mobile");
Configuring with the Spring Framework
The WURFL API (starting with 1.4) is completely decoupled from the Spring
framework. This allows non-Spring users to import and use WURFL without having
to include the Spring library and everything involved with it.
Using Spring, does not mean that the web.xml
file is no longer involved.
You must tell your application that all the features of the API are
now supported through Spring.
In practice, this means that web.xml
will contain the following lines:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/wurfl-ctx.xml</param-value></context-param> :<listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class></listener>
In the wurfl-helloworld-spring-{version}.war
web application, you can find
an easy way to configure the WURFL API using Spring. The wurfl.ctx
context
file will contain:
<bean id="WurflHolder" class="com.scientiamobile.wurfl.core.GeneralWURFLEngine"> <constructor-arg index="0" value="classpath:/wurfl.zip" /> <!-- <constructor-arg index="1" value="<< patch here >>"/> --> <!-- <constructor-arg index="2" value="<< more patches here >>"/> --></bean><!-- DeviceCacheProvider --><bean id="deviceCacheProvider" class="com.scientiamobile.wurfl.core.cache.LRUMapCacheProvider" /><!-- <bean id="deviceCacheProvider" class="com.scientiamobile.wurfl.core.cache.DoubleLRUMapCacheProvider" /> --><!-- <bean id="deviceCacheProvider" class="com.scientiamobile.wurfl.core.cache.HashMapCacheProvider" /> --><!-- <bean id="deviceCacheProvider" class="com.scientiamobile.wurfl.core.cache.NullCacheProvider" /> --><!-- <bean id="deviceCacheProvider" class="com.scientiamobile.wurfl.core.cache.EhCacheProvider" /> -->
If you would like to set a capability filter, you will need to add the following
properties to your wurfl-ctx.xml
:
<property name="capabilityFilter"> <set> device_os brand_name model_name release_date has_qwerty_keyboard </set></property>
To configure the performance mode of the API, you can edit the /META-INF/wurfl-config.xml
file:
<wurfl-api-config engine-target="accuracy"><wurfl-api-config engine-target="performance">
Finally you can simply access the WURFLEngine
instance with the code here, taken from a common Servlet method:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); WURFLEngine engine = (WURFLEngine)wac.getBean(WURFLEngine.class.getName()); [...]}
Configuring WURFL updater
API version 1.8.0.0 introduces WURFL updater; a new set of classes which allow a client using WURFL to automatically update
In order to use the WurflUpdater
, you must have your personal WURFL Snapshot url in the following format:
https://data.scientiamobile.com/xxxxx/wurfl.zip where xxxxx is replaced with you personal access token. Also, do note that rootPath must be writable from the process/task that is executing the Java API since WurflUpdater
will update rootPath
file.
Suggested setting for WURFL updater is “periodic” mode; i.e. WurflUpdater
will periodically check to see if a new version of the wurfl.zip has been released,
and if so, download it and reload the engine with the new version; all while the standard WurflEngine
is running and serving requests.
Running “periodic” updates.
String rootPath = "wurfl.zip";WURFLEngine engine = new GeneralWURFLEngine(rootPath);// remember to modify the url below with your personal WURFL Snapshot urlWURFLUpdater updater = new WURFLUpdater(engine, rootPath, "https://data.scientiamobile.com/xxxxx/wurfl.zip");updater.setFrequency(Frequency.DAILY);updater.performperiodicUpdate();
Being a periodic task, the updater will run perpetually until updater.stopPeriodicUpdate()
is called. Periodic update does not return a result. Failed/successful results must be checked in log files/console messages.
If needed, WurflUpdater can also run in “on demand” mode i.e. check for a new version of the wurfl.zip once and then stop.
Running “on demand” update.
String rootPath = "wurfl.zip";WURFLEngine engine = new GeneralWURFLEngine(rootPath);// remember to substitute url below with your personal WURFL Snapshot urlWURFLUpdater updater = new WURFLUpdater(engine, rootPath, "https://data.scientiamobile.com/xxxxx/wurfl.zip");UpdateResult result = updater.performUpdate();
On demand update runs only once per call and returns a result that can be used to programmatically check if update has been successful or, in case of failure, get an error message.
License
2016 ScientiaMobile Incorporated
All Rights Reserved.
NOTICE: All information contained herein is, and remains the property of ScientiaMobile Incorporated
and its suppliers, if any. The intellectual and technical concepts contained herein are proprietary to
ScientiaMobile Incorporated and its suppliers and may be covered by U.S. and Foreign Patents, patents
in process, and are protected by trade secret or copyright law. Dissemination of this information or
reproduction of this material is strictly forbidden unless prior written permission is obtained from
ScientiaMobile Incorporated.
援引自:WurflAPI~:https://docs.scientiamobile.com/documentation/onsite/onsite-java-api
留着给自己mark一下,收藏夹不够用了。因为是英文的,所以哪里有问题可以留言,之后还会搜集一些资料传到上面来~
最后附上wurfl工具包:WURFL工具包
- 【转自官网】WURFL 浏览器版本识别API+末尾附WURFL工具包
- 探索WURFL(转自:developerworks)
- WURFL简介
- 使用 PHP、JavaScript 和 WURFL 的设备识别移动网站
- WURFL的使用
- WURFL:终端(手机设备)信息的文件
- 第一篇文章,介绍一下自己为什么叫wurfl
- 构建多服务的 Java 应用程序,第 1 部分: 探索 WURFL
- 构建多服务的 Java 应用程序,第 1 部分: 探索 WURFL
- 构建多服务的 Java 应用程序,第 1 部分: 探索 WURFL ( 3)
- 构建多服务的 Java 应用程序,第 1 部分: 探索 WURFL(4)
- ie浏览器版本识别
- 1025(附Windows API版本)
- 浏览器版本识别(备忘)
- 使用 jQuery 识别浏览器版本
- 如何识别 SQL Server 的版本【转自msdn】
- Android运行时识别API版本
- 获取操作系统版本字符串(转自MSDN) 附判断操作系统的代码
- kibana 访问IP分布图
- Hbase常用命令
- org.springframework.util.Assert
- 求最大公约数及最小公倍数
- 微信支付(微信支付的坑基本上都踩过一遍了)
- 【转自官网】WURFL 浏览器版本识别API+末尾附WURFL工具包
- 【Qt开发】Qt让线程休息一段时间
- NGUI 字体相关
- 自定义select
- linux中lnmp环境的搭建
- Android 事件分发onInterceptTouchEvent和onTouchEvent整理
- hashMap ,hashTable ,concurrentHashMap区别
- SimpleAdapter创建ListView
- centos7 开放端口