- 浏览: 2561698 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Android Framework(III)Spring-mobile and wurfl with Groovy Controller
- 博客分类:
- Summary
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
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
发表评论
-
Stop Update Here
2020-04-28 09:00 323I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 484NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 374Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 376Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 345Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 436Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 445Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 382Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 464VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 394Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 488NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 432Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 342Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 256GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 456GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 332GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 318Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 325Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 302Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 315Serverless with NodeJS and Tenc ...
相关推荐
3. `wurfl-helloworld-spring-1.8.2.1.war` 和 `wurfl-helloworld-servlet-1.8.2.1.war`:这两个是Web应用程序档案(WAR)文件,可以直接部署到支持Java EE的服务器上。它们包含了前面提到的示例应用的编译后版本,...
Tera-WURFL的核心功能是利用Wireless Universal Resource File(WURFL),这是一个详尽的数据库,包含了各种移动设备的特性和能力信息。 WURFL是由 ScientiaMobile 公司创建和维护的,它是一个不断更新的设备特征...
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...
接着,你需要选择一个适合你的J2EE应用的WURFL实现库,如`wurfl-java`,将其添加到项目依赖中。 安装完成后,可以通过以下步骤在代码中使用WURFL: 1. **初始化WURFL API**:在应用程序启动时,加载`wurfl.xml`...
标题中的“wurfl-2.3.xml.zip”是一个压缩文件,其中包含了“wurfl-2.3.xml”这个核心文件。WURFL(Wireless Universal Resource File)是用于识别移动设备特性的数据库,主要用于优化网站内容以适应不同类型的移动...
《WURFL Core 1.8.0.0:浏览器检测技术详解》 ...通过使用`wurfl-1.8.0.0-javadoc.jar`和`wurfl-1.8.0.0.jar`,开发者可以轻松集成并利用WURFL Core的强大功能,构建更加智能和适应性强的数字产品。
2016-05-23 由官方scientiamobile更新的php api
**WURFL 浏览器版本识别API** WURFL(Wireless Universal Resource File)是一种强大的工具,专门用于识别和理解各种设备的特性和能力,尤其是移动设备的浏览器。这个API是Java开发者处理设备适配和浏览器兼容性...
- **Tera WURFL**:用于识别移动设备能力的工具。 - **MyMobileWeb**:一个帮助开发者构建移动友好的网站的框架。 - **Mobile Web Toolkit**:包含多种工具和组件的集合,用于加速移动网站开发。 - **GAIA Image ...
工具(C)将WURFL XML移动浏览器数据库拆分为带有符号链接(NTFS存根)的单个设备文件,以减少访问时间和服务器负载。 包括一个简单PHP库/ API作为如何访问数据的示例,以及一个示例phtml文件。
### Head First Mobile Web:关键技术与应用实践 #### 一、移动网络环境的演变与挑战 随着移动设备(如智能手机和平板电脑)的普及,越来越多的用户选择通过这些设备访问互联网。这种趋势使得移动网络的使用量正在...
移动Web的使用在呈爆炸式增长。很快,人们会更愿意在手机和平板电脑而不是PC机上浏览网页。...使用*的开发技术,包括响应式Web设计,以及利用WURFL完成服务器端设备检测;通过图片、谜题、故事和问答轻松学习。
标题“Mobile Device Information-开源”指的是一个基于Java Swing GUI(图形用户界面)的开源项目,其主要目的是为了帮助用户查看、搜索以及编辑WURFL(Wireless Universal Resource File)中的移动设备信息。WURFL...
标题中的"Soms"是该项目的简称,全称为“Simple .NET WURFL API”,这是一个专门为.NET平台,尤其是C#开发者设计的开源库。WURFL是"Wireless Universal Resource File"的缩写,是一个用于识别移动设备特性的数据库。...
“dinfo:对 WURFL 数据的 Web 访问,作为 Java servlet 实现。-开源” 这个标题表明我们讨论的是一个名为 "dinfo" 的项目,它是一个基于 Java servlet 技术实现的Web应用程序。这个项目的主要功能是提供对 WURFL...
【phpBB mobile addon-开源】 phpBB 是一个流行的开源论坛软件,它允许用户创建和管理在线社区。"phpBB mobile addon" 是针对该平台的一个重要扩展,旨在优化论坛的移动设备体验。这个插件的目的是确保在手机和平板...
Struts2是基于MVC(Model-View-Controller)架构的Web应用框架,用于控制应用流程。Spring框架则提供了依赖注入和面向切面编程等功能,简化了代码管理。Hibernate是一个对象关系映射工具,用于处理数据库操作,降低...
Apache Mobile Filter是检测移动设备的最简单,最快的方法。 AMF是一套工具,可以直接从Apache访问设备存储库(例如WURFL,DetectRight,51Degrees.mobi或免费的AMF服务):现在,无论您使用哪种语言,您都可以检测...
它是WURFL或DeviceAtlas的绝佳替代品。 在Maven上也可用。 1)下载zip并解压缩。 2)将位于“ dist”目录中的核心JAR添加到您的Java项目中。 3)导入以下软件包:import fiftyone.mobile.detection.Match; 导入五十...