Class PropertyReader


  • public final class PropertyReader
    extends java.lang.Object
    Property Reader for the WikiEngine. Reads the properties for the WikiEngine and implements the feature of cascading properties and variable substitution, which come in handy in a multi wiki installation environment: It reduces the need for (shell) scripting in order to generate different jspwiki.properties to a minimum.
    Since:
    2.5.x
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CUSTOM_JSPWIKI_CONFIG  
      static java.lang.String DEFAULT_JSPWIKI_CONFIG
      Path to the base property file, usually overridden by values provided in a jspwiki-custom.properties file "/ini/jspwiki.properties"
      static java.lang.String PARAM_CUSTOMCONFIG
      The servlet context parameter (from web.xml) that defines where the config file is to be found.
      static java.lang.String PARAM_CUSTOMCONFIG_CASCADEPREFIX
      The prefix when you are cascading properties.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void expandVars​(java.util.Properties properties)
      You define a property variable by using the prefix "var.x" as a property.
      static java.util.Properties getCombinedProperties​(java.lang.String fileName)
      Returns a property set consisting of the default Property Set overlaid with a custom property set
      static java.util.Properties getDefaultProperties()
      Returns the property set as a Properties object.
      static java.util.Properties loadWebAppProps​(javax.servlet.ServletContext context)
      Loads the webapp properties based on servlet context information, or (if absent) based on the Java System Property "jspwiki.custom.config".
      static java.io.InputStream locateClassPathResource​(javax.servlet.ServletContext context, java.lang.String resourceName)
      Locate a resource stored in the class path.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • loadWebAppProps

        public static java.util.Properties loadWebAppProps​(javax.servlet.ServletContext context)
        Loads the webapp properties based on servlet context information, or (if absent) based on the Java System Property "jspwiki.custom.config". Returns a Properties object containing the settings, or null if unable to load it. (The default file is ini/jspwiki.properties, and can be customized by setting "jspwiki.custom.config" in the server or webapp configuration.)

        Properties sources

        The following properties sources are taken into account:
        1. JSPWiki default properties
        2. System environment
        3. JSPWiki custom property files
        4. JSPWiki cascading properties
        5. System properties
        With later sources taking precedence over the previous ones. To avoid leaking system information, only System environment and properties beginning with jspwiki (case unsensitive) are taken into account. Also, to ease docker integration, System env properties containing "_" are turned into ".". Thus, ENV jspwiki_fileSystemProvider_pageDir is loaded as jspwiki.fileSystemProvider.pageDir.

        Cascading Properties

        You can define additional property files and merge them into the default properties file in a similar process to how you define cascading style sheets; hence we call this cascading property files. This way you can overwrite the default values and only specify the properties you need to change in a multiple wiki environment.

        You define a cascade in the context mapping of your servlet container.

          jspwiki.custom.cascade.1
          jspwiki.custom.cascade.2
          jspwiki.custom.cascade.3
          
        and so on. You have to number your cascade in a descending way starting with "1". This means you cannot leave out numbers in your cascade. This method is based on an idea by Olaf Kaus, see [JSPWiki:MultipleWikis].
        Parameters:
        context - A Servlet Context which is used to find the properties
        Returns:
        A filled Properties object with all the cascaded properties in place
      • getDefaultProperties

        public static java.util.Properties getDefaultProperties()
        Returns the property set as a Properties object.
        Returns:
        A property set.
      • getCombinedProperties

        public static java.util.Properties getCombinedProperties​(java.lang.String fileName)
        Returns a property set consisting of the default Property Set overlaid with a custom property set
        Parameters:
        fileName - Reference to the custom override file
        Returns:
        A property set consisting of the default property set and custom property set, with the latter's properties replacing the former for any common values
      • expandVars

        public static void expandVars​(java.util.Properties properties)
        You define a property variable by using the prefix "var.x" as a property. In property values you can then use the "$x" identifier to use this variable. For example, you could declare a base directory for all your files like this and use it in all your other property definitions with a "$basedir". Note that it does not matter if you define the variable before its usage.
          var.basedir = /p/mywiki;
          jspwiki.fileSystemProvider.pageDir =         $basedir/www/
          jspwiki.basicAttachmentProvider.storageDir = $basedir/www/
          jspwiki.workDir =                            $basedir/wrk/
          
        Parameters:
        properties - - properties to expand;
      • locateClassPathResource

        public static java.io.InputStream locateClassPathResource​(javax.servlet.ServletContext context,
                                                                  java.lang.String resourceName)
        Locate a resource stored in the class path. Try first with "WEB-INF/classes" from the web app and fallback to "resourceName".
        Parameters:
        context - the servlet context
        resourceName - the name of the resource
        Returns:
        the input stream of the resource or null if the resource was not found