Class Sling


  • public class Sling
    extends Object
    The Sling serves as the starting point for Sling.

    Launch Configuration

    The Apache Felix framework requires configuration parameters to be specified for startup. This servlet builds the list of parameters from three locations:

    1. The sling.properties file is read from the servlet class path. This properties file contains default settings.
    2. Extensions of this servlet may provide additional properties to be loaded overwriting the loadPropertiesOverride(Map) method.
    3. Finally, web application init parameters are added to the properties and may overwrite existing properties of the same name(s).

    After loading all properties, variable substitution takes place on the property values. A variable is indicated as ${<prop-name>} where <prop-name> is the name of a system or configuration property (configuration properties override system properties). Variables may be nested and are resolved from inner-most to outer-most. For example, the property value ${outer-${inner}} is resolved by first resolving ${inner} and then resolving the property whose name is the catenation of outer- and the result of resolving ${inner}.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String CONFIG_PROPERTIES
      The name of the default launcher properties file to setup the environment for the Felix framework (value is "sling.properties").
      static String JCR_REPO_CONFIG_FILE_URL
      The name of the configuration property defining the URL of an existing repository config file (repository.xml).
      static String JCR_REPO_HOME
      The name of the configuration property defining the JCR home directory (value is "sling.repository.home").
      protected org.apache.felix.framework.Logger logger
      The simple logger to log messages during startup and shutdown to
      static String OSGI_FRAMEWORK_BUNDLES
      The name of the configuration property defining a properties file defining a list of bundles, which are installed into the framework when it has been launched (value is "org.apache.osgi.bundles").
      static String PROP_EXTRA_CAPS  
      static String PROP_SYSTEM_PACKAGES  
      static String SLING_HOME_URL
      The name of the configuration property defining the Sling home directory as an URL (value is "sling.home.url").
      static String SLING_IGNORE_SYSTEM_PROPERTIES
      The property to be set to ignore the system properties when building the Felix framework properties (value is "sling.ignoreSystemProperties").
    • Constructor Summary

      Constructors 
      Constructor Description
      Sling​(Notifiable notifiable, org.apache.felix.framework.Logger logger, org.apache.sling.launchpad.api.LaunchpadContentProvider resourceProvider, Map<String,​String> propOverwrite)
      Initializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and the Felix instance as servlet context attributes.
    • Field Detail

      • SLING_HOME_URL

        public static final String SLING_HOME_URL
        The name of the configuration property defining the Sling home directory as an URL (value is "sling.home.url").

        The value of this property is assigned the value of new File(${sling.home}).toURI().toString() before resolving the property variables.

        See Also:
        SharedConstants.SLING_HOME, Constant Field Values
      • JCR_REPO_HOME

        public static final String JCR_REPO_HOME
        The name of the configuration property defining the JCR home directory (value is "sling.repository.home").

        The value of this property could be set as a system property, init-param in web.xml or property in sling.properties.

        Default value to #SLING_HOME/repository_name

        See Also:
        Constant Field Values
      • JCR_REPO_CONFIG_FILE_URL

        public static final String JCR_REPO_CONFIG_FILE_URL
        The name of the configuration property defining the URL of an existing repository config file (repository.xml).

        The value of this property could be set as a system property, init-param in web.xml or property in sling.properties.

        Default value to #SLING_HOME/repository_name/repository.xml

        See Also:
        Constant Field Values
      • OSGI_FRAMEWORK_BUNDLES

        public static final String OSGI_FRAMEWORK_BUNDLES
        The name of the configuration property defining a properties file defining a list of bundles, which are installed into the framework when it has been launched (value is "org.apache.osgi.bundles").

        This configuration property is generally set in the web application configuration and may be referenced in all property files (default, user supplied and web application parameters) used to build the framework configuration.

        See Also:
        Constant Field Values
      • SLING_IGNORE_SYSTEM_PROPERTIES

        public static final String SLING_IGNORE_SYSTEM_PROPERTIES
        The property to be set to ignore the system properties when building the Felix framework properties (value is "sling.ignoreSystemProperties"). If this is property is set to true (case does not matter), the system properties will not be used by loadConfigProperties(Map).
        See Also:
        Constant Field Values
      • CONFIG_PROPERTIES

        public static final String CONFIG_PROPERTIES
        The name of the default launcher properties file to setup the environment for the Felix framework (value is "sling.properties").

        Extensions of this class may overwrite some or all properties in this file through Web Application parameters or other properties files.

        See Also:
        Constant Field Values
      • logger

        protected final org.apache.felix.framework.Logger logger
        The simple logger to log messages during startup and shutdown to
    • Constructor Detail

      • Sling

        public Sling​(Notifiable notifiable,
                     org.apache.felix.framework.Logger logger,
                     org.apache.sling.launchpad.api.LaunchpadContentProvider resourceProvider,
                     Map<String,​String> propOverwrite)
              throws org.osgi.framework.BundleException
        Initializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and the Felix instance as servlet context attributes.
        Parameters:
        notifiable - The notifiable
        logger - The logger
        resourceProvider - The resource provider
        propOverwrite - The properties to overwrite
        Throws:
        org.osgi.framework.BundleException - if the framework cannot be initialized.
    • Method Detail

      • destroy

        public final void destroy()
        Destroys this servlet by shutting down the OSGi framework and hence the delegatee servlet if one is set at all.
      • loadPropertiesOverride

        protected void loadPropertiesOverride​(Map<String,​String> properties)
        Loads additional properties into the properties object.

        This implementation does nothing and may be overwritten by extensions requiring additional properties to be set.

        This method is called when the servlet is initialized to prepare the configuration for Felix. Implementations may add properties from implementation specific sources. Properties added here overwrite properties loaded from the default properties file and may be overwritten by parameters set in the web application.

        The properties object has not undergone variable substition and properties added by this method may also contain values refererring to other properties.

        The properties added in this method will not be persisted in the sling.properties file in the sling.home directory.

        Parameters:
        properties - The Properties object to which custom properties may be added.
      • getBundleContext

        public final org.osgi.framework.BundleContext getBundleContext()
        Returns the BundleContext of the system bundle of the OSGi framework launched by this servlet. This method only returns a non-null object after the system bundle of the framework has been started and before it is being stopped.
        Returns:
        The BundleContext of the system bundle