Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:SpringSource/spring-mobile-samples

  • Loading branch information...
commit 1306a68e609dde3d9a0dcf158306bc4d95034bcd 2 parents 0e35f95 + 5e991e4
Craig Walls authored
Showing with 420 additions and 15 deletions.
  1. +3 −14 lite-device-resolver/README.md
  2. +1 −1  lite-device-resolver/src/main/java/org/springframework/showcases/lite/config/ComponentConfig.java
  3. +21 −0 lite-site-preference-handler/README.md
  4. +16 −0 lite-site-preference-handler/pom.xml
  5. +48 −0 lite-site-preference-handler/src/main/java/org/springframework/showcases/lite/HomeController.java
  6. +28 −0 lite-site-preference-handler/src/main/java/org/springframework/showcases/lite/config/ComponentConfig.java
  7. +64 −0 lite-site-preference-handler/src/main/java/org/springframework/showcases/lite/config/WebConfig.java
  8. +41 −0 lite-site-preference-handler/src/main/resources/log4j.xml
  9. +2 −0  lite-site-preference-handler/src/main/webapp/META-INF/MANIFEST.MF
  10. +24 −0 lite-site-preference-handler/src/main/webapp/WEB-INF/views/home-mobile.jsp
  11. +24 −0 lite-site-preference-handler/src/main/webapp/WEB-INF/views/home-tablet.jsp
  12. +24 −0 lite-site-preference-handler/src/main/webapp/WEB-INF/views/home.jsp
  13. +51 −0 lite-site-preference-handler/src/main/webapp/WEB-INF/web.xml
  14. +32 −0 lite-site-preference-handler/src/test/java/org/springframework/showcases/lite/HomeControllerTest.java
  15. +41 −0 lite-site-preference-handler/src/test/resources/log4j.xml
View
17 lite-device-resolver/README.md
@@ -1,12 +1,8 @@
-# Spring Mobile Lite Showcase
+# Spring Mobile Lite Device Resolver
## Overview
-This sample app demonstrates many of the capabilities of the Spring Mobile Device module, including:
-
-* "Lite" device resolution through the use of DeviceResolverHandlerInterceptor
-* Site preference management
-* Site switching configured for the mDot strategy
+This sample app demonstrates the Device Resolver capabilities of the Spring Mobile Device module, including:
## Build and Run the Sample Application
@@ -22,13 +18,6 @@ This sample app demonstrates many of the capabilities of the Spring Mobile Devic
3. Access the project at the following URL:
- http://localhost:8080/lite-interceptor-mdot
+ http://localhost:8080/lite-device-resolver
_Note: Accessing this URL from your browser versus an Android emulator or iOS simulator will demonstrate the functionality_
-
-## Configure your Hosts file
-
-In order for the site switcher demonstration to work in a local test environment, you will need to add the following to your hosts file; for example, /etc/hosts on Unix and OS X systems:
-
- 127.0.0.1 testdomain.com
- 127.0.0.1 m.testdomain.com
View
2  lite-device-resolver/src/main/java/org/springframework/showcases/lite/config/ComponentConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2011 the original author or authors.
+ * Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
21 lite-site-preference-handler/README.md
@@ -0,0 +1,21 @@
+# Spring Mobile Lite Showcase
+
+## Overview
+
+This sample app demonstrates the Site Preference capabilities of the Spring Mobile Device module.
+
+## Build and Run the Sample Application
+
+1. Build the app:
+
+ $ mvn clean install
+
+2. Deploy the .war to a Servlet 2.5 or > ServletContainer. This can be done via Maven on the command-line by running:
+
+ $ mvn tomcat:run
+
+ _Note: Alternatively, you may import the project into your IDE and deploy to a Servlet 2.5 or > container such as Tomcat 6 or 7._
+
+3. Access the project at the following URL:
+
+ http://localhost:8080/lite-site-preference-handler
View
16 lite-site-preference-handler/pom.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.springframework.mobile</groupId>
+ <artifactId>spring-mobile-samples</artifactId>
+ <version>1.0.0-BUILD-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>lite-site-preference-handler</artifactId>
+ <packaging>war</packaging>
+ <name>lite-site-preference-handler</name>
+
+</project>
View
48 lite-site-preference-handler/src/main/java/org/springframework/showcases/lite/HomeController.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.showcases.lite;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.mobile.device.site.SitePreference;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * Handles requests for the showcase application.
+ * @author Roy Clarkson
+ */
+@Controller
+public class HomeController {
+
+ private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
+
+ @RequestMapping("/")
+ public String home(SitePreference sitePreference, Model model) {
+ if (sitePreference == SitePreference.MOBILE) {
+ logger.info("Site preference is mobile");
+ return "home-mobile";
+ } else if (sitePreference == SitePreference.TABLET) {
+ logger.info("Site preference is tablet");
+ return "home-tablet";
+ } else {
+ logger.info("Site preference is normal, or no site preference selected");
+ return "home";
+ }
+ }
+
+}
View
28 lite-site-preference-handler/src/main/java/org/springframework/showcases/lite/config/ComponentConfig.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.showcases.lite.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author Roy Clarkson
+ */
+@Configuration
+@ComponentScan(basePackages="org.springframework.showcases.lite")
+public class ComponentConfig {
+
+}
View
64 lite-site-preference-handler/src/main/java/org/springframework/showcases/lite/config/WebConfig.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.showcases.lite.config;
+
+import java.util.List;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.mobile.device.site.SitePreferenceHandlerInterceptor;
+import org.springframework.mobile.device.site.SitePreferenceHandlerMethodArgumentResolver;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
+
+/**
+ * @author Roy Clarkson
+ * @see WebMvcConfigurer
+ */
+@Configuration
+@EnableWebMvc
+public class WebConfig extends WebMvcConfigurerAdapter {
+
+ // implementing WebMvcConfigurer
+
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new SitePreferenceHandlerInterceptor());
+ }
+
+ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
+ argumentResolvers.add(new SitePreferenceHandlerMethodArgumentResolver());
+ }
+
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
+ }
+
+ // additional webmvc-related beans
+
+ @Bean
+ public InternalResourceViewResolver internalResourceViewResolver() {
+ InternalResourceViewResolver resolver = new InternalResourceViewResolver();
+ resolver.setPrefix("/WEB-INF/views/");
+ resolver.setSuffix(".jsp");
+ return resolver;
+ }
+
+}
View
41 lite-site-preference-handler/src/main/resources/log4j.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <!-- Appenders -->
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p: %c - %m%n" />
+ </layout>
+ </appender>
+
+ <!-- Application Loggers -->
+ <logger name="org.springframework.showcases.lite">
+ <level value="info" />
+ </logger>
+
+ <!-- 3rdparty Loggers -->
+ <logger name="org.springframework.core">
+ <level value="info" />
+ </logger>
+
+ <logger name="org.springframework.beans">
+ <level value="info" />
+ </logger>
+
+ <logger name="org.springframework.context">
+ <level value="info" />
+ </logger>
+
+ <logger name="org.springframework.web">
+ <level value="info" />
+ </logger>
+
+ <!-- Root Logger -->
+ <root>
+ <priority value="info" />
+ <appender-ref ref="console" />
+ </root>
+
+</log4j:configuration>
View
2  lite-site-preference-handler/src/main/webapp/META-INF/MANIFEST.MF
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Class-Path:
View
24 lite-site-preference-handler/src/main/webapp/WEB-INF/views/home-mobile.jsp
@@ -0,0 +1,24 @@
+<%@ page session="false" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Spring Mobile | Lite Showcase</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+ </head>
+ <body>
+ <header>
+ <h1>Mobile Site</h1>
+ </header>
+ <footer>
+ An Apache-licensed technology showcase by SpringSource.
+ </footer>
+ <aside id="site-preference">
+ <p>Site:
+ <c:if test="${currentSitePreference.mobile}"><a href="?site_preference=normal">Normal</a> | Mobile | <a href="?site_preference=tablet">Tablet</a></c:if>
+ <c:if test="${currentSitePreference.tablet}"><a href="?site_preference=normal">Normal</a> | <a href="?site_preference=mobile">Mobile</a> | Tablet</c:if>
+ <c:if test="${currentSitePreference.normal}">Normal | <a href="?site_preference=mobile">Mobile</a> | <a href="?site_preference=tablet">Tablet</a></c:if>
+ </p>
+ </aside>
+ </body>
+</html>
View
24 lite-site-preference-handler/src/main/webapp/WEB-INF/views/home-tablet.jsp
@@ -0,0 +1,24 @@
+<%@ page session="false" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Spring Mobile | Lite Showcase</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+ </head>
+ <body>
+ <header>
+ <h1>Tablet Site</h1>
+ </header>
+ <footer>
+ An Apache-licensed technology showcase by SpringSource.
+ </footer>
+ <aside id="site-preference">
+ <p>Site:
+ <c:if test="${currentSitePreference.mobile}"><a href="?site_preference=normal">Normal</a> | Mobile | <a href="?site_preference=tablet">Tablet</a></c:if>
+ <c:if test="${currentSitePreference.tablet}"><a href="?site_preference=normal">Normal</a> | <a href="?site_preference=mobile">Mobile</a> | Tablet</c:if>
+ <c:if test="${currentSitePreference.normal}">Normal | <a href="?site_preference=mobile">Mobile</a> | <a href="?site_preference=tablet">Tablet</a></c:if>
+ </p>
+ </aside>
+ </body>
+</html>
View
24 lite-site-preference-handler/src/main/webapp/WEB-INF/views/home.jsp
@@ -0,0 +1,24 @@
+<%@ page session="false" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Spring Mobile | Lite Showcase</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+ </head>
+ <body>
+ <header>
+ <h1>Normal Site</h1>
+ </header>
+ <footer>
+ An Apache-licensed technology showcase by SpringSource.
+ </footer>
+ <aside id="site-preference">
+ <p>Site:
+ <c:if test="${currentSitePreference.mobile}"><a href="?site_preference=normal">Normal</a> | Mobile | <a href="?site_preference=tablet">Tablet</a></c:if>
+ <c:if test="${currentSitePreference.tablet}"><a href="?site_preference=normal">Normal</a> | <a href="?site_preference=mobile">Mobile</a> | Tablet</c:if>
+ <c:if test="${currentSitePreference.normal}">Normal | <a href="?site_preference=mobile">Mobile</a> | <a href="?site_preference=tablet">Tablet</a></c:if>
+ </p>
+ </aside>
+ </body>
+</html>
View
51 lite-site-preference-handler/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5">
+
+ <!-- Java-based Spring container definition -->
+ <context-param>
+ <param-name>contextClass</param-name>
+ <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
+ </context-param>
+
+ <!-- Location of Java @Configuration classes that configure the components
+ that makeup this application -->
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>org.springframework.showcases.lite.config</param-value>
+ </context-param>
+
+ <!-- Use the simplified configuration by default. -->
+ <context-param>
+ <param-name>spring.profiles.default</param-name>
+ <param-value>simple</param-value>
+ </context-param>
+
+ <!-- Creates the Spring Container shared by all Servlets and Filters -->
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+ <!-- Processes application requests -->
+ <servlet>
+ <servlet-name>appServlet</servlet-name>
+ <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+ <init-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value></param-value>
+ </init-param>
+ <init-param>
+ <param-name>spring.profiles.default</param-name>
+ <param-value>simple</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>appServlet</servlet-name>
+ <url-pattern>/</url-pattern>
+ </servlet-mapping>
+
+</web-app>
View
32 lite-site-preference-handler/src/test/java/org/springframework/showcases/lite/HomeControllerTest.java
@@ -0,0 +1,32 @@
+package org.springframework.showcases.lite;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.springframework.mobile.device.site.SitePreference;
+import org.springframework.ui.ExtendedModelMap;
+import org.springframework.ui.Model;
+
+public class HomeControllerTest {
+
+ private HomeController controller = new HomeController();
+
+ @Test
+ public void homePageNormalDevice() {
+ Model model = new ExtendedModelMap();
+ assertEquals("home", controller.home(SitePreference.NORMAL, model));
+ }
+
+ @Test
+ public void homePageMobileDevice() {
+ Model model = new ExtendedModelMap();
+ assertEquals("home-mobile", controller.home(SitePreference.MOBILE, model));
+ }
+
+ @Test
+ public void homePageTabletDevice() {
+ Model model = new ExtendedModelMap();
+ assertEquals("home-tablet", controller.home(SitePreference.TABLET, model));
+ }
+
+}
View
41 lite-site-preference-handler/src/test/resources/log4j.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <!-- Appenders -->
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p: %c - %m%n" />
+ </layout>
+ </appender>
+
+ <!-- Application Loggers -->
+ <logger name="org.springframework.showcases.lite">
+ <level value="debug" />
+ </logger>
+
+ <!-- 3rdparty Loggers -->
+ <logger name="org.springframework.core">
+ <level value="info" />
+ </logger>
+
+ <logger name="org.springframework.beans">
+ <level value="info" />
+ </logger>
+
+ <logger name="org.springframework.context">
+ <level value="info" />
+ </logger>
+
+ <logger name="org.springframework.web">
+ <level value="info" />
+ </logger>
+
+ <!-- Root Logger -->
+ <root>
+ <priority value="warn" />
+ <appender-ref ref="console" />
+ </root>
+
+</log4j:configuration>
Please sign in to comment.
Something went wrong with that request. Please try again.