spring-mobile-device

org.springframework.mobile.device.switcher
Class SiteSwitcherHandlerInterceptor

java.lang.Object
  extended by org.springframework.web.servlet.handler.HandlerInterceptorAdapter
      extended by org.springframework.mobile.device.switcher.SiteSwitcherHandlerInterceptor
All Implemented Interfaces:
org.springframework.web.servlet.HandlerInterceptor

public class SiteSwitcherHandlerInterceptor
extends org.springframework.web.servlet.handler.HandlerInterceptorAdapter

A Spring MVC interceptor that switches the user between the mobile and normal site by employing a specific switching algorithm. The switching algorithm is as follows:

Author:
Keith Donald, Scott Rossillo, Roy Clarkson

Constructor Summary
SiteSwitcherHandlerInterceptor(SiteUrlFactory normalSiteUrlFactory, SiteUrlFactory mobileSiteUrlFactory, SitePreferenceHandler sitePreferenceHandler)
          Creates a new site switcher.
 
Method Summary
static SiteSwitcherHandlerInterceptor dotMobi(java.lang.String serverName)
          Creates a site switcher that redirects to a .mobi domain for normal site requests that either originate from a mobile device or indicate a mobile site preference.
static SiteSwitcherHandlerInterceptor mDot(java.lang.String serverName)
          Creates a site switcher that redirects to a m. domain for normal site requests that either originate from a mobile device or indicate a mobile site preference.
 boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
           
static SiteSwitcherHandlerInterceptor urlPath(java.lang.String mobilePath)
          Creates a site switcher that redirects to a path on the current domain for normal site requests that either originate from a mobile device or indicate a mobile site preference.
static SiteSwitcherHandlerInterceptor urlPath(java.lang.String mobilePath, java.lang.String rootPath)
          Creates a site switcher that redirects to a path on the current domain for normal site requests that either originate from a mobile device or indicate a mobile site preference.
 
Methods inherited from class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
afterCompletion, postHandle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SiteSwitcherHandlerInterceptor

public SiteSwitcherHandlerInterceptor(SiteUrlFactory normalSiteUrlFactory,
                                      SiteUrlFactory mobileSiteUrlFactory,
                                      SitePreferenceHandler sitePreferenceHandler)
Creates a new site switcher.

Parameters:
normalSiteUrlFactory - the factory for a "normal" site URL e.g. http://app.com
mobileSiteUrlFactory - the factory for a "mobile" site URL e.g. http://m.app.com
sitePreferenceHandler - the handler for the user site preference
Method Detail

preHandle

public boolean preHandle(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response,
                         java.lang.Object handler)
                  throws java.lang.Exception
Specified by:
preHandle in interface org.springframework.web.servlet.HandlerInterceptor
Overrides:
preHandle in class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
Throws:
java.lang.Exception

mDot

public static SiteSwitcherHandlerInterceptor mDot(java.lang.String serverName)
Creates a site switcher that redirects to a m. domain for normal site requests that either originate from a mobile device or indicate a mobile site preference. Uses a CookieSitePreferenceRepository that saves a cookie that is shared between the two domains.


dotMobi

public static SiteSwitcherHandlerInterceptor dotMobi(java.lang.String serverName)
Creates a site switcher that redirects to a .mobi domain for normal site requests that either originate from a mobile device or indicate a mobile site preference. Will strip off the trailing domain name when building the mobile domain e.g. "app.com" will become "app.mobi" (the .com will be stripped). Uses a CookieSitePreferenceRepository that saves a cookie that is shared between the two domains.


urlPath

public static SiteSwitcherHandlerInterceptor urlPath(java.lang.String mobilePath)
Creates a site switcher that redirects to a path on the current domain for normal site requests that either originate from a mobile device or indicate a mobile site preference. Uses a CookieSitePreferenceRepository that saves a cookie that is stored on the root path.


urlPath

public static SiteSwitcherHandlerInterceptor urlPath(java.lang.String mobilePath,
                                                     java.lang.String rootPath)
Creates a site switcher that redirects to a path on the current domain for normal site requests that either originate from a mobile device or indicate a mobile site preference. Allows you to configure a root path for an application. For example, if your app is running at "http://www.app.com/demoapp", then the root path is "/demoapp". Uses a CookieSitePreferenceRepository that saves a cookie that is stored on the root path.


spring-mobile-device