Class DefaultContextPathStrategy

  extended by
All Implemented Interfaces:

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).

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

Constructor Summary
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


public DefaultContextPathStrategy()
Method Detail


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
bundle - OSGi bundle deployed as war
the not-null context path (without any spaces) associated with the given bundle


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.

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

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