`
sillycat
  • 浏览: 2561698 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Android Framework(III)Spring-mobile and wurfl with Groovy Controller

阅读更多
Android Framework(III)Spring-mobile and wurfl with Groovy Controller

1. backgroup
Get the spring-mobile source codes
>git clone --recursive git://github.com/SpringSource/spring-mobile.git spring-mobile

Get the wurfl files
wurfl zip file: http://sourceforge.net/projects/wurfl/files/WURFL/

wurfl patch file:  http://wurfl.sourceforge.net/web_browsers_patch.xml

2. enable the jar files repository
add 3 more respositories to my ivysettings.xml:
<url name="office4">
<artifact pattern="http://maven.springframework.org/snapshot/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="office5">
<artifact pattern="http://maven.springframework.org/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="office6">
<artifact pattern="http://maven.springframework.org/milestone/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>

add some jar files configuration to ivy.xml:
<!-- spring device -->
<dependency org="org/springframework/mobile" name="spring-mobile-device" rev="1.0.0.M3" />
<!-- wurlf -->
<dependency org="net/sourceforge/wurfl" name="wurfl" rev="1.2.2" />
<!--  velocity -->
<dependency org="org/apache/velocity" name="velocity" rev="1.7" />
<dependency org="org/apache/velocity" name="velocity-tools" rev="2.0" />

3. Spring configuration changes
I changed my core-context.xml to add wurfl and spring mobile part.
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
            <list>
                <ref bean="deviceResolverHandlerInteceptor"/>
                <ref bean="sitePreferenceHandlerInterceptor" />
            </list>
        </property>
</bean>

<bean id="handlerAdapter" class="com.sillycat.easygroovyplugin.servlet.proxy.ProxyAwareAnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonConverter" />
</list>
</property>
<property name="customArgumentResolvers">
<list>
<ref bean="deviceWebArgumentResolver" />
                <ref bean="sitePreferenceWebArgumentResolver" />
</list>
</property>
</bean>

<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="${velocity.file.path}/template/" />
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
<prop key="contentType">text/html;charset=UTF-8</prop>
</props>
</property>
</bean>
<bean id="velocityViewResolver"
      class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
    <property name="layoutUrl" value="layout/layout.vm"/>
    <property name="cache" value="false" />
<property name="suffix" value=".vm" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="contentType" value="text/html;charset=UTF-8" />
</bean>

I deal with wurfl in my groovy controller, and I add the velocity resolver to my controller.
Here comes the wurfl-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:device="http://www.springframework.org/schema/mobile/device"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mobile/device
    http://www.springframework.org/schema/mobile/device/spring-mobile-device-1.0.xsd
">
<bean id="deviceWebArgumentResolver" class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
<bean id="sitePreferenceWebArgumentResolver" class="org.springframework.mobile.device.site.SitePreferenceWebArgumentResolver" />
<bean id="sitePreferenceHandlerInterceptor" class="org.springframework.mobile.device.site.SitePreferenceHandlerInterceptor" />
<bean id="deviceResolverHandlerInteceptor" class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor">
<constructor-arg>
<device:wurfl-device-resolver root-location="file:${wurfl.zip.file}"
                              patch-locations="file:${wurfl.patch.file}" />
</constructor-arg>
</bean>
</beans>

Some settings in spring configuration file is in properties, config.properties:
##########################################
# wurfl configuration
##########################################
wurfl.zip.file=/home/luohua/work/easymarket/conf/wurfl/wurfl-2.0.28.zip
wurfl.patch.file=/home/luohua/work/easymarket/conf/wurfl/web_browsers_patch.xml

################################################
# velocity path
################################################
velocity.file.path=file://home/luohua/work/easymarket

4. The Groovy Controller
package com.sillycat.easymarket.controller;
import org.springframework.stereotype.Controller;
import org.springframework.mobile.device.site.SitePreference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HomeController {

@RequestMapping("/home")
public ModelAndView home(SitePreference sitePreference) {
ModelAndView view = null;
if (sitePreference == SitePreference.MOBILE) {
println sitePreference.isMobile();
println "home-mobile";
view = new ModelAndView("home_mobile");
} else {
println sitePreference.isMobile();
println "home";
view = new ModelAndView("home");
}
return view;
}
}

And the view of page home.vm:
#set($layout = "layout/layout.vm")

<h3>Device Information</h3>
<p>Your browser:</p>
<ul>
<li>${currentDevice.userAgent}</li>
</ul>
<p>is capable of:</p>
<ul>
${currentDevice.capabilities}
</ul>

<p>and has a preferred markup grade of:</p>
<ul>
<li>${currentDevice.markUp}</li>
</ul>

references:
http://www.springsource.org/spring-mobile
http://static.springsource.org/spring-mobile/docs/1.0.x/reference/htmlsingle/
http://www.abdn.ac.uk/~csc228/teaching/CS5302/practicals/practical_spring_wurfl.shtml

http://hi.baidu.com/hn_why/blog/item/442a171ab3ee3ce41ad57696.html


分享到:
评论

相关推荐

    wurfl1.8.2.1_java

    3. `wurfl-helloworld-spring-1.8.2.1.war` 和 `wurfl-helloworld-servlet-1.8.2.1.war`:这两个是Web应用程序档案(WAR)文件,可以直接部署到支持Java EE的服务器上。它们包含了前面提到的示例应用的编译后版本,...

    Tera-WURFL Enhanced PHP WURFL Library-开源

    Tera-WURFL的核心功能是利用Wireless Universal Resource File(WURFL),这是一个详尽的数据库,包含了各种移动设备的特性和能力信息。 WURFL是由 ScientiaMobile 公司创建和维护的,它是一个不断更新的设备特征...

    wurfl-2.3.1

    WURFL is a set of proprietary application programming interfaces (APIs) and an XML configuration file which contains information about device capabilities and features for a variety of mobile devices...

    WURFL - J2EE获取客户端移动设备信息

    接着,你需要选择一个适合你的J2EE应用的WURFL实现库,如`wurfl-java`,将其添加到项目依赖中。 安装完成后,可以通过以下步骤在代码中使用WURFL: 1. **初始化WURFL API**:在应用程序启动时,加载`wurfl.xml`...

    wurfl-2.3.xml.zip

    标题中的“wurfl-2.3.xml.zip”是一个压缩文件,其中包含了“wurfl-2.3.xml”这个核心文件。WURFL(Wireless Universal Resource File)是用于识别移动设备特性的数据库,主要用于优化网站内容以适应不同类型的移动...

    com.scientiamobile wurfl-core1.8.0.0.zip

    《WURFL Core 1.8.0.0:浏览器检测技术详解》 ...通过使用`wurfl-1.8.0.0-javadoc.jar`和`wurfl-1.8.0.0.jar`,开发者可以轻松集成并利用WURFL Core的强大功能,构建更加智能和适应性强的数字产品。

    wurfl-php-1.7.1.2

    2016-05-23 由官方scientiamobile更新的php api

    WURFL 浏览器版本识别API

    **WURFL 浏览器版本识别API** WURFL(Wireless Universal Resource File)是一种强大的工具,专门用于识别和理解各种设备的特性和能力,尤其是移动设备的浏览器。这个API是Java开发者处理设备适配和浏览器兼容性...

    Mobile Web Development: Building mobile websites, SMS and MMS messaging, mobile payments, and automated voice call systems with XHTML MP, WCSS, and mobile AJAX

    - **Tera WURFL**:用于识别移动设备能力的工具。 - **MyMobileWeb**:一个帮助开发者构建移动友好的网站的框架。 - **Mobile Web Toolkit**:包含多种工具和组件的集合,用于加速移动网站开发。 - **GAIA Image ...

    WURFL Split-开源

    工具(C)将WURFL XML移动浏览器数据库拆分为带有符号链接(NTFS存根)的单个设备文件,以减少访问时间和服务器负载。 包括一个简单PHP库/ API作为如何访问数据的示例,以及一个示例phtml文件。

    Head First Mobile Web

    ### Head First Mobile Web:关键技术与应用实践 #### 一、移动网络环境的演变与挑战 随着移动设备(如智能手机和平板电脑)的普及,越来越多的用户选择通过这些设备访问互联网。这种趋势使得移动网络的使用量正在...

    Head First Mobile Web(中文版)

    移动Web的使用在呈爆炸式增长。很快,人们会更愿意在手机和平板电脑而不是PC机上浏览网页。...使用*的开发技术,包括响应式Web设计,以及利用WURFL完成服务器端设备检测;通过图片、谜题、故事和问答轻松学习。

    Mobile Device Information-开源

    标题“Mobile Device Information-开源”指的是一个基于Java Swing GUI(图形用户界面)的开源项目,其主要目的是为了帮助用户查看、搜索以及编辑WURFL(Wireless Universal Resource File)中的移动设备信息。WURFL...

    Soms:用于.NET(C#)的WURFL API-开源

    标题中的"Soms"是该项目的简称,全称为“Simple .NET WURFL API”,这是一个专门为.NET平台,尤其是C#开发者设计的开源库。WURFL是"Wireless Universal Resource File"的缩写,是一个用于识别移动设备特性的数据库。...

    dinfo:对 WURFL 数据的 Web 访问,作为 Java servlet 实现。-开源

    “dinfo:对 WURFL 数据的 Web 访问,作为 Java servlet 实现。-开源” 这个标题表明我们讨论的是一个名为 "dinfo" 的项目,它是一个基于 Java servlet 技术实现的Web应用程序。这个项目的主要功能是提供对 WURFL...

    phpBB mobile addon-开源

    【phpBB mobile addon-开源】 phpBB 是一个流行的开源论坛软件,它允许用户创建和管理在线社区。"phpBB mobile addon" 是针对该平台的一个重要扩展,旨在优化论坛的移动设备体验。这个插件的目的是确保在手机和平板...

    Green手机广告投放系统设计与实现参考.pdf

    Struts2是基于MVC(Model-View-Controller)架构的Web应用框架,用于控制应用流程。Spring框架则提供了依赖注入和面向切面编程等功能,简化了代码管理。Hibernate是一个对象关系映射工具,用于处理数据库操作,降低...

    Apache Mobile Filter:检测移动设备的最快,最简单的方法-开源

    Apache Mobile Filter是检测移动设备的最简单,最快的方法。 AMF是一套工具,可以直接从Apache访问设备存储库(例如WURFL,DetectRight,51Degrees.mobi或免费的AMF服务):现在,无论您使用哪种语言,您都可以检测...

    51Degrees-Java:Java移动设备检测-4步设置-3分钟-开源

    它是WURFL或DeviceAtlas的绝佳替代品。 在Maven上也可用。 1)下载zip并解压缩。 2)将位于“ dist”目录中的核心JAR添加到您的Java项目中。 3)导入以下软件包:import fiftyone.mobile.detection.Match; 导入五十...

Global site tag (gtag.js) - Google Analytics