This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added lite-site-switcher-handler sample
- Loading branch information
1 parent
e5e124b
commit 20077c3
Showing
16 changed files
with
467 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Spring Mobile Lite Site Switcher Handler | ||
|
||
## Overview | ||
|
||
This sample app demonstrates many of the Site Switcher 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-switcher-handler | ||
|
||
_Note: Accessing this URL from your browser versus an Android emulator or iOS simulator will demonstrate the functionality_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.1-BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>lite-site-switcher-handler</artifactId> | ||
<packaging>war</packaging> | ||
<name>lite-site-switcher-handler</name> | ||
|
||
</project> |
37 changes: 37 additions & 0 deletions
37
...te-switcher-handler/src/main/java/org/springframework/showcases/lite/AboutController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
/** | ||
* Handles requests for the About page. | ||
* @author Roy Clarkson | ||
*/ | ||
@Controller | ||
public class AboutController { | ||
|
||
/** | ||
* Show the About page to the user. | ||
*/ | ||
@RequestMapping("/about") | ||
public String home(Model model) { | ||
return "about"; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ite-switcher-handler/src/main/java/org/springframework/showcases/lite/HomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
/** | ||
* Handles requests for the Home page. | ||
* @author Roy Clarkson | ||
*/ | ||
@Controller | ||
public class HomeController { | ||
|
||
/** | ||
* Show the home page to the user. | ||
*/ | ||
@RequestMapping("/") | ||
public String home(Model model) { | ||
return "home"; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...cher-handler/src/main/java/org/springframework/showcases/lite/config/ComponentConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...e-switcher-handler/src/main/java/org/springframework/showcases/lite/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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.DeviceHandlerMethodArgumentResolver; | ||
import org.springframework.mobile.device.DeviceResolverHandlerInterceptor; | ||
import org.springframework.mobile.device.switcher.SiteSwitcherHandlerInterceptor; | ||
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 DeviceResolverHandlerInterceptor()); | ||
registry.addInterceptor(SiteSwitcherHandlerInterceptor.mDot("testdomain.com")); | ||
} | ||
|
||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { | ||
argumentResolvers.add(new DeviceHandlerMethodArgumentResolver()); | ||
} | ||
|
||
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
3 changes: 3 additions & 0 deletions
3
lite-site-switcher-handler/src/main/webapp/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Class-Path: | ||
|
20 changes: 20 additions & 0 deletions
20
lite-site-switcher-handler/src/main/webapp/WEB-INF/views/about.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%@ page session="false" %> | ||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Spring Mobile | Lite Site Switcher Handler</title> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>About</h1> | ||
</header> | ||
<%@include file="includes/content.jsp" %> | ||
<footer> | ||
An Apache-licensed technology showcase by SpringSource. | ||
</footer> | ||
<aside> | ||
<p><a href="<c:url value="/" />">Home</a> | About</p> | ||
</aside> | ||
</body> | ||
</html> |
20 changes: 20 additions & 0 deletions
20
lite-site-switcher-handler/src/main/webapp/WEB-INF/views/home.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%@ page session="false" %> | ||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Spring Mobile | Lite Site Switcher Handler</title> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Home</h1> | ||
</header> | ||
<%@include file="includes/content.jsp" %> | ||
<footer> | ||
An Apache-licensed technology showcase by SpringSource. | ||
</footer> | ||
<aside> | ||
<p>Home | <a href="<c:url value="/about" />">About</a></p> | ||
</aside> | ||
</body> | ||
</html> |
21 changes: 21 additions & 0 deletions
21
lite-site-switcher-handler/src/main/webapp/WEB-INF/views/includes/content.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | ||
<p> | ||
<c:choose> | ||
<c:when test="${currentDevice.normal}"> | ||
You are currently viewing this page from a <strong>normal</strong> device. The site switcher has returned | ||
the normal site. | ||
</c:when> | ||
<c:when test="${currentDevice.mobile}"> | ||
You are currently viewing this page from a <strong>mobile</strong> device. Note the URL begins with "m.". | ||
This means the site switcher has redirected you to the mobile version of the site. | ||
</c:when> | ||
<c:when test="${currentDevice.tablet}"> | ||
You are currently viewing this page from a <strong>tablet</strong> device. Depending on how you have the | ||
site switcher configured tablets are either presented with the normal site, or the mobile site. | ||
</c:when> | ||
<c:otherwise> | ||
No device was detected. This usually means that the device resolver is not configured properly. | ||
In this case, the site switcher will return the normal site. | ||
</c:otherwise> | ||
</c:choose> | ||
</p> |
51 changes: 51 additions & 0 deletions
51
lite-site-switcher-handler/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.