org.springframework.richclient.jnlp
Class JnlpPropertyPlaceholderConfigurer

java.lang.Object
  extended by org.springframework.core.io.support.PropertiesLoaderSupport
      extended by org.springframework.beans.factory.config.PropertyResourceConfigurer
          extended by org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
              extended by org.springframework.richclient.jnlp.JnlpPropertyPlaceholderConfigurer
All Implemented Interfaces:
BeanFactoryAware, BeanNameAware, BeanFactoryPostProcessor, Ordered, PriorityOrdered

public class JnlpPropertyPlaceholderConfigurer
extends PropertyPlaceholderConfigurer

Subclass of PropertyPlaceholderConfigurer that resolves the following properties as placeholders:

Can be combined with "locations" and/or "properties" values.

If a placeholder could not be resolved against the provided local properties within the application, this configurer will fall back to the JNLP properties. Can also be configured to let jnlp properties override local properties (contextOverride=true).

If not running within a JNLP context (or any other context that is able to satisfy the BasicService.lookup call), this class will use the fallBackWebAppContextUrl. This allows for keeping JnlpPropertyPlaceholderConfigurer definitions in test suites.

A typical usage would be:

 <bean id="jnlpPropertyPlaceholderConfigurer"
      class="be.kahosl.thot.swingui.util.JnlpPropertyPlaceholderConfigurer">
      <property name="fallBackWebAppContextUrl" value="http://localhost:8080/mywebapp/"/>
      <property name="jnlpRelativeDirectoryPathFromWebAppContext" value="/jnlp/"/>
  </bean>
  

Use this in combination with Sun's JnlpDownloadServlet to not have to hardcode your server URL: http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/downloadservletguide.html

Author:
Geoffrey De Smet
See Also:
PropertiesLoaderSupport.setLocations(org.springframework.core.io.Resource[]), PropertiesLoaderSupport.setProperties(java.util.Properties), PropertyPlaceholderConfigurer.setSystemPropertiesModeName(java.lang.String), setContextOverride(boolean), BasicService.getCodeBase()

Field Summary
static String WEB_APP_CONTEXT_URL_PLACEHOLDER
          The placeholder for getWebAppContextUrl()
 
Fields inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, SYSTEM_PROPERTIES_MODE_FALLBACK, SYSTEM_PROPERTIES_MODE_NEVER, SYSTEM_PROPERTIES_MODE_OVERRIDE
 
Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
logger, XML_FILE_EXTENSION
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
JnlpPropertyPlaceholderConfigurer()
           
 
Method Summary
 String getWebAppContextUrl()
          Uses the jnlp API to determine the webapp context.
protected  String resolvePlaceholder(String placeholder)
          Resolves the given placeholder using the jnlp properties.
protected  String resolvePlaceholder(String placeholder, Properties props)
           
 void setContextOverride(boolean contextOverride)
          Set whether the JNLP properties should override local properties within the application.
 void setFallBackWebAppContextUrl(String fallBackWebAppContextUrl)
          Set the webAppContextUrl to use when no javax.jnlp.BasicService is available.
 void setJnlpRelativeDirectoryPathFromWebAppContext(String jnlpRelativeDirectoryPathFromWebAppContext)
          Sets the relative directory path of the JNLP file relative to the WebAppContext.
 
Methods inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
parseStringValue, processProperties, resolvePlaceholder, resolveSystemProperty, setBeanFactory, setBeanName, setIgnoreUnresolvablePlaceholders, setPlaceholderPrefix, setPlaceholderSuffix, setSearchSystemEnvironment, setSystemPropertiesMode, setSystemPropertiesModeName
 
Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer
convertProperties, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
 
Methods inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEB_APP_CONTEXT_URL_PLACEHOLDER

public static final String WEB_APP_CONTEXT_URL_PLACEHOLDER
The placeholder for getWebAppContextUrl()

See Also:
Constant Field Values
Constructor Detail

JnlpPropertyPlaceholderConfigurer

public JnlpPropertyPlaceholderConfigurer()
Method Detail

setContextOverride

public void setContextOverride(boolean contextOverride)
Set whether the JNLP properties should override local properties within the application. Default is "false": JNLP properties settings serve as fallback.

Note that system properties will still override JNLP properties, if the system properties mode is set to "SYSTEM_PROPERTIES_MODE_OVERRIDE".

See Also:
PropertyPlaceholderConfigurer.setSystemPropertiesModeName(java.lang.String), PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE

setFallBackWebAppContextUrl

public void setFallBackWebAppContextUrl(String fallBackWebAppContextUrl)
Set the webAppContextUrl to use when no javax.jnlp.BasicService is available. This is usefull for testing outside JNLP (Java webstart). This defaults to http://localhost:8080/. Ussually you 'll want to set this to http://localhost:8080/mywebapp/.

Parameters:
fallBackWebAppContextUrl - the webAppContextUrl to fall back on ending with a slash

setJnlpRelativeDirectoryPathFromWebAppContext

public void setJnlpRelativeDirectoryPathFromWebAppContext(String jnlpRelativeDirectoryPathFromWebAppContext)
Sets the relative directory path of the JNLP file relative to the WebAppContext. Default this is /, which means that the JNLP file is in the root of your webapp. If your JNLP file isn't in the root of you webapp, change it. For example for http://localhost:8080/mywebapp/dist/jnlp/myswingapp.jnlp you would set this to /dist/jnlp/.

Parameters:
jnlpRelativeDirectoryPathFromWebAppContext - the relative directory path starting and ending with a slash

resolvePlaceholder

protected String resolvePlaceholder(String placeholder,
                                    Properties props)
Overrides:
resolvePlaceholder in class PropertyPlaceholderConfigurer

resolvePlaceholder

protected String resolvePlaceholder(String placeholder)
Resolves the given placeholder using the jnlp properties.

Parameters:
placeholder - the placeholder to resolve
Returns:
the resolved value, of null if none

getWebAppContextUrl

public String getWebAppContextUrl()
Uses the jnlp API to determine the webapp context. If used outside of webstart, fallBackWebAppContextUrl is returned. For example this could return http://localhost:8080/mywebapp/.

Returns:
the url to the webapp ending with a slash


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.