org.apache.struts2.osgi.host

## Class BaseOsgiHost

- java.lang.Object
- - org.apache.struts2.osgi.host.BaseOsgiHost

- All Implemented Interfaces:
    OsgiHost
  Direct Known Subclasses:
    FelixOsgiHost, GlassfishOSGiHost

      public abstract class BaseOsgiHost
      extends Object
      implements OsgiHost

  A base OsgiHost implementation
  Servlet config params:

  struts.osgi.searchForPropertiesFilesInRelativePath: Defaults to "false". Set to "true" for fallback search for properties files in relative path (e.g. for unit testing).

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `DETECT_JAVA_VERSION`
    `protected static String` | `JRE_JAVA_SPECIFICATION_VERSION`
    `protected static String` | `SCANNING_PACKAGE_INCLUDES`
    `protected javax.servlet.ServletContext` | `servletContext`
    `protected static Pattern` | `VERSION_PATTERN`
    `protected static Pattern` | `versionPattern` Deprecated. use `VERSION_PATTERN` instead

    - ### Fields inherited from interface org.apache.struts2.osgi.host.OsgiHost

      `OSGI_BUNDLE_CONTEXT, OSGI_HEADER_STRUTS_ENABLED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BaseOsgiHost()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addAutoStartBundles(Properties configProps)`
    `protected void` | `addExportedPackages(Properties strutsConfigProps, Properties configProps)` Find sub-packages of the packages defined in the property file and export them
    `protected abstract void` | `addSpringOSGiSupport()`
    `abstract void` | `destroy()`
    `protected Properties` | `findPropertiesFileInRelativePath(String fileName)` Attempt to read a properties file from the relative path of the current classloader.
    `abstract Map<String,org.osgi.framework.Bundle>` | `getActiveBundles()`
    `abstract org.osgi.framework.BundleContext` | `getBundleContext()`
    `abstract Map<String,org.osgi.framework.Bundle>` | `getBundles()` This bundle map will not change, but the status of the bundles can change over time.
    `protected List<String>` | `getBundlesInDir(String dir)`
    `protected String` | `getJarUrl(Class clazz)`
    `protected Properties` | `getProperties(String fileName)`
    `protected Map<String,String>` | `getRunLevelDirs(String dir)`
    `protected String` | `getServletContextParam(String paramName, String defaultValue)` Gets a param from the ServletContext, returning the default value if the param is not set
    `protected String` | `getVersion(URL url)`
    `protected String` | `getVersionFromString(String str)`
    `abstract void` | `init(javax.servlet.ServletContext servletContext)`
    `protected void` | `replaceSystemPackages(Properties properties)` Replace all instances of `JRE_JAVA_SPECIFICATION_VERSION`, within the `Constants.FRAMEWORK_SYSTEMPACKAGES` property of the provided properties.
    `protected boolean` | `searchForPropertiesFilesInRelativePath()` Check ServletContext initialization parameter "struts.osgi.searchForPropertiesFilesInRelativePath".

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### VERSION_PATTERN

          protected static final Pattern VERSION_PATTERN

    - #### SCANNING_PACKAGE_INCLUDES

          protected static final String SCANNING_PACKAGE_INCLUDES

      See Also:
        Constant Field Values

    - #### JRE_JAVA_SPECIFICATION_VERSION

          protected static final String JRE_JAVA_SPECIFICATION_VERSION

      See Also:
        Constant Field Values

    - #### DETECT_JAVA_VERSION

          protected static final String DETECT_JAVA_VERSION

      See Also:
        Constant Field Values

    - #### versionPattern

          @Deprecated
          protected static final Pattern versionPattern

      Deprecated. use `VERSION_PATTERN` instead

    - #### servletContext

          protected javax.servlet.ServletContext servletContext

  - ### Constructor Detail

    - #### BaseOsgiHost

          public BaseOsgiHost()

  - ### Method Detail

    - #### init

          public abstract void init(javax.servlet.ServletContext servletContext)

      Specified by:
        `init` in interface `OsgiHost`

    - #### destroy

          public abstract void destroy()
                                throws Exception

      Specified by:
        `destroy` in interface `OsgiHost`
      Throws:
        `Exception`

    - #### getBundles

          public abstract Map<String,org.osgi.framework.Bundle> getBundles()

      This bundle map will not change, but the status of the bundles can change over time. Use getActiveBundles() for active bundles
      Specified by:
        `getBundles` in interface `OsgiHost`
      Returns:
        map with bundles

    - #### getActiveBundles

          public abstract Map<String,org.osgi.framework.Bundle> getActiveBundles()

      Specified by:
        `getActiveBundles` in interface `OsgiHost`

    - #### getBundleContext

          public abstract org.osgi.framework.BundleContext getBundleContext()

      Specified by:
        `getBundleContext` in interface `OsgiHost`

    - #### addSpringOSGiSupport

          protected abstract void addSpringOSGiSupport()

    - #### getServletContextParam

          protected String getServletContextParam(String paramName,
                                                  String defaultValue)

      Gets a param from the ServletContext, returning the default value if the param is not set
      Parameters:
        `paramName` - the name of the param to get from the ServletContext
        `defaultValue` - value to return if the param is not set
      Returns:
        param from the ServletContext, returning the default value if the param is not set

    - #### addAutoStartBundles

          protected void addAutoStartBundles(Properties configProps)

    - #### getRunLevelDirs

          protected Map<String,String> getRunLevelDirs(String dir)

      Parameters:
        `dir` - directory
      Returns:
        a list of directories under a directory whose name is a number

    - #### getBundlesInDir

          protected List<String> getBundlesInDir(String dir)

    - #### getJarUrl

          protected String getJarUrl(Class clazz)

    - #### replaceSystemPackages

          protected void replaceSystemPackages(Properties properties)

      Replace all instances of `JRE_JAVA_SPECIFICATION_VERSION`, within the `Constants.FRAMEWORK_SYSTEMPACKAGES` property of the provided properties. The replacement will be the value for the key "jre-x.y" in the properties parameter (where x.y is the JRE version after transforming the System "java.version" property. For example: "jre-x.y" is "jre-1.8" for Java 8, "jre-9.0" for Java 9, and "jre-11.0" for Java 11. While performing the replacement, the elements within jre-x.y will also undergo a replacement of the substring `DETECT_JAVA_VERSION` into something like "0.0.0.JavaSE_001_008" for Java 8 and earlier, "0.0.0.JavaSE_009" for Java 9 and newer. If you prefer manual control, use literal strings rather than `DETECT_JAVA_VERSION` in your properties file.
      Parameters:
        `properties` - OSGi properties for which the `Constants.FRAMEWORK_SYSTEMPACKAGES` property's values substrings `JRE_JAVA_SPECIFICATION_VERSION` will be replaced by the value for the key "jre-xxx" (where xxx is the JRE version). If no `Constants.FRAMEWORK_SYSTEMPACKAGES` property exists, this is a no-op.

    - #### addExportedPackages

          protected void addExportedPackages(Properties strutsConfigProps,
                                             Properties configProps)

      Find sub-packages of the packages defined in the property file and export them
      Parameters:
        `strutsConfigProps` - Struts-OSGi configuration properties containing the `SCANNING_PACKAGE_INCLUDES` property containing comma-separated top-level package values.
        `configProps` - OSGi configuration properties for which the `Constants.FRAMEWORK_SYSTEMPACKAGES` property's value will have the sub-packages of strutsConfigProps appended to it. If no `Constants.FRAMEWORK_SYSTEMPACKAGES` property exists, and the exported packages is non-empty, then one is created that will contain the sub-packages of strutsConfigProps.

    - #### getVersion

          protected String getVersion(URL url)

      Parameters:
        `url` - URL for package
      Returns:
        the version used to export the packages. it tries to get it from MANIFEST.MF, or the file name

    - #### getVersionFromString

          protected String getVersionFromString(String str)

      Parameters:
        `str` - string for extract version
      Returns:
        Extracts numbers followed by "." or "-" from the string and joins them with "."

    - #### getProperties

          protected Properties getProperties(String fileName)

    - #### searchForPropertiesFilesInRelativePath

          protected boolean searchForPropertiesFilesInRelativePath()

      Check ServletContext initialization parameter "struts.osgi.searchForPropertiesFilesInRelativePath".
      Returns:
        true if "struts.osgi.searchForPropertiesFilesInRelativePath" is "true" in ServletContext initialization parameters, false otherwise.

    - #### findPropertiesFileInRelativePath

          protected Properties findPropertiesFileInRelativePath(String fileName)
                                                         throws IOException

      Attempt to read a properties file from the relative path of the current classloader. Intended as an alternate configuration fallback for special scenarios where the default lookup is not functional (such as for unit tests).
      Parameters:
        `fileName` - the filename (relative path) of the properties file.
      Returns:
        a Properties bundle loaded from the provided fileName.
      Throws:
        `IOException` - if the properties file does not exist or cannot be loaded.

Copyright © 2000–2023 Apache Software Foundation. All rights reserved.