org.springframework.osgi.web.deployer.support
Class DefaultContextPathStrategy

java.lang.Object
  extended by org.springframework.osgi.web.deployer.support.DefaultContextPathStrategy
All Implemented Interfaces:
ContextPathStrategy

public class DefaultContextPathStrategy
extends Object
implements ContextPathStrategy

ContextPathStrategy default implementation. This class takes into account the OSGi bundle properties for determining the war context path. by iterating through the following properties, considering the first one that is available in the following order:

  1. Web-ContextPath manifest header (identical to the one in SpringSource Application Platform). If present, the value of this header will be used as the context path.
  2. bundle location - if present, the implementation will try to determine if the location points to a file or a folder. In both cases, the name will be returned without the extension (if it's present):
     /root/bundle.jar -> /bundle /root/bundle/ -> /bundle /root/bundle.jar/ -> /bundle
     file:/path/bundle.jar -> /bundle jar:url:/root/bundle.jar -> /bundle 
  3. bundle name - if present, it is used as a fall back to the bundle location (ex: /myBundle)
  4. bundle symbolic name - if present, it used as a fall back to the bundle name (ex: /org.comp.osgi.some.bundle)
  5. bundle identity - if neither of the properties above is present, the bundle object identity will be used as context path (ex: /BundleImpl-15a0305)
Additionally, the returned context path will be HTML encoded (using 'UTF-8') to avoid problems with unsafe characters (such as whitespace).

Author:
Costin Leau
See Also:
Bundle.getLocation(), Constants.BUNDLE_NAME, Bundle.getSymbolicName(), System.identityHashCode(Object), URLEncoder.encode(String, String)

Constructor Summary
DefaultContextPathStrategy()
           
 
Method Summary
protected  String determineContextPath(Bundle bundle)
          Determines the context path associated with this bundle.
 String getContextPath(Bundle bundle)
          Obtains the context path for the given OSGi bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultContextPathStrategy

public DefaultContextPathStrategy()
Method Detail

getContextPath

public String getContextPath(Bundle bundle)
Description copied from interface: ContextPathStrategy
Obtains the context path for the given OSGi bundle. The returned String should be not null and should not contain any spaces.

Specified by:
getContextPath in interface ContextPathStrategy
Parameters:
bundle - OSGi bundle deployed as war
Returns:
the not-null context path (without any spaces) associated with the given bundle

determineContextPath

protected String determineContextPath(Bundle bundle)
Determines the context path associated with this bundle. This method can be overridden by possible subclasses that wish to decorate or modify the existing behaviour.

Parameters:
bundle - bundle for which the context path needs to be determined
Returns:
non-null context path determined for the given bundle


Copyright © 2006-2011 Spring Framework. All Rights Reserved.