How can I use Java WURFL API in a standalone manner?

ermanno
Posts: 11
Joined: Fri Jul 08, 2011 12:19 pm

How can I use Java WURFL API in a standalone manner?

Postby ermanno » Wed Oct 12, 2011 11:15 am

Is it possible to use WURFL Java API in a standalone environment, outside a Server or a Servlet Container?

ermanno
Posts: 11
Joined: Fri Jul 08, 2011 12:19 pm

Re: How can I use Java WURFL API in a standalone manner?

Postby ermanno » Wed Oct 12, 2011 11:20 am

The simplest way is a Spring3 - Maven project.

You can instantiate an Application Context by hand,
and lookup for a 'wurflManager'.
E.g.:

Code: Select all

public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/spring/wurfl-standard-import-ctx.xml");
WURFLManager wurflManager = (WURFLManager) ctx.getBean("wurflManager");
String ua="Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17";
Device device = wurflManager.getDeviceForRequest(ua);
System.out.println(device.getCapabilities());
}
The context file may be (API 1.3.5-SNAPSHOT):

Code: Select all

<beans xmlns=(usual Spring 3 prologue...) >

<import resource="classpath:/META-INF/wurfl-api-service.xml"/>

<bean id="wurflModel" class="net.sourceforge.wurfl.spring.SpringWURFLModel">

<!-- default value is "/WEB-INF/wurfl.zip" -->
<property name="wurfl" value="classpath:/wurfl-2.2.zip"/>

<!--if you have only one patchfile , you can write this way-->
<property name="wurflPatch" value="classpath:/web_browsers_patch.xml"/>

</bean>

<bean id="wurflManager"
class="net.sourceforge.wurfl.spring.SpringWurflManager">
<property name="wurflModel" ref="wurflModel"/>
</bean>

</beans>
You can run it using Maven exec plugin.

A minimal but running example can be downloaded at
http://dl.dropbox.com/u/3009836/wurfl/wurfl-cli.zip


Who is online

Users browsing this forum: No registered users and 21 guests