org.apache.turbine.util

## Class TurbineConfig

- java.lang.Object
- - org.apache.turbine.util.TurbineConfig

- All Implemented Interfaces:
    javax.servlet.ServletConfig, javax.servlet.ServletContext, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.activity.Initializable
  Direct Known Subclasses:
    TurbineXmlConfig

      public class TurbineConfig
      extends Object
      implements javax.servlet.ServletConfig, javax.servlet.ServletContext, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.activity.Disposable

  A class used for initialization of Turbine without a servlet container.

  If you need to use Turbine outside of a servlet container, you can use this class for initialization of the Turbine servlet.

       TurbineConfig config = new TurbineConfig(".", "conf/TurbineResources.properties");

  All paths referenced in TurbineResources.properties and the path to the properties file itself (the second argument) will be resolved relative to the directory given as the first argument of the constructor, here - the directory where application was started. Don't worry about discarding the references to objects created above. They are not needed, once everything is initialized.

  In order to initialize the Services Framework outside of the Turbine Servlet, you need to call the `init()` method. By default, this will initialize the Resource and Logging Services and any other services you have defined in your TurbineResources.properties file. TODO Make this class enforce the lifecycle contracts

  Version:
    $Id: TurbineConfig.java 1773378 2016-12-09 13:19:59Z tv $
  Author:
    Quinton McCombs, Rafal Krzewski, Jon S. Stevens, Daniel Rall, Henning P. Schmiedehausen, Eric Pugh

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<String,Object>` | `attributes` Servlet container (or emulator) attributes.
    `static String` | `CONFIGURATION_PATH_KEY` Servlet initialization parameter name for the path to TurbineConfiguration.xml file used by Turbine
    `protected Map<String,String>` | `initParams` Turbine servlet initialization parameters.
    `static String` | `PROPERTIES_PATH_DEFAULT` Default value of TurbineResources.properties file path (`/WEB-INF/conf/TurbineResources.properties`).
    `static String` | `PROPERTIES_PATH_KEY` Servlet initialization parameter name for the path to Turbine.properties file used by Turbine
    `protected File` | `root` Filenames are looked up in this directory.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TurbineConfig(String path, Map<String,Object> attributes, Map<String,String> initParams)` Constructs a new TurbineConfig.
    `TurbineConfig(String path, Map<String,String> initParams)` Constructs a new TurbineConfig.
    `TurbineConfig(String path, String properties)` Constructs a TurbineConfig.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `dispose()` Shutdown the Turbine System, lifecycle style
    `Object` | `getAttribute(String s)` Returns the servlet container attribute with the given name, or null if there is no attribute by that name.
    `Enumeration<String>` | `getAttributeNames()` Returns an Enumeration containing the attribute names available within this servlet context.
    `javax.servlet.ServletContext` | `getContext(String s)` Not implemented.
    `String` | `getContextPath()` Returns the context path.
    `String` | `getInitParameter(String name)` Retrieves an initialization parameter.
    `Enumeration<String>` | `getInitParameterNames()` Retrieves an Enumeration of initialization parameter names.
    `int` | `getMajorVersion()` Not implemented.
    `String` | `getMimeType(String s)` Not implemented.
    `int` | `getMinorVersion()` Not implemented.
    `javax.servlet.RequestDispatcher` | `getNamedDispatcher(String s)` Not implemented.
    `String` | `getRealPath(String path)` Translates a path relative to the web application root into an absolute path.
    `javax.servlet.RequestDispatcher` | `getRequestDispatcher(String s)` Not implemented.
    `URL` | `getResource(String s)` Returns a URL to the resource that is mapped to a specified path.
    `InputStream` | `getResourceAsStream(String s)` Returns the resource located at the named path as an `InputStream` object.
    `Set<String>` | `getResourcePaths(String s)` Not implemented.
    `String` | `getServerInfo()` Not implemented.
    `javax.servlet.Servlet` | `getServlet(String s)` Deprecated. As of Java Servlet API 2.1, with no direct replacement.
    `javax.servlet.ServletContext` | `getServletContext()` Returns a reference to the object cast onto ServletContext type.
    `String` | `getServletContextName()` Returns the context name.
    `String` | `getServletName()` Returns the servlet name.
    `Enumeration<String>` | `getServletNames()` Deprecated. As of Java Servlet API 2.1, with no replacement.
    `Enumeration<javax.servlet.Servlet>` | `getServlets()` Deprecated. As of Java Servlet API 2.0, with no replacement.
    `Turbine` | `getTurbine()` Returns a reference to the Turbine servlet that was initialized.
    `void` | `init(RunData data)` Initialization requiring a HTTP `GET` request.
    `void` | `initialize()` Causes this class to initialize itself which in turn initializes all of the Turbine Services that need to be initialized.
    `void` | `log(Exception e, String m)` Deprecated. use log(String,Throwable) instead
    `void` | `log(String m)` Logs a message.
    `void` | `log(String m, Throwable t)` Logs an error message.
    `void` | `removeAttribute(String s)` Not implemented.
    `void` | `setAttribute(String s, Object o)` Not implemented.

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

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

- - ### Field Detail

    - #### CONFIGURATION_PATH_KEY

          public static final String CONFIGURATION_PATH_KEY

      Servlet initialization parameter name for the path to TurbineConfiguration.xml file used by Turbine
      See Also:
        Constant Field Values

    - #### PROPERTIES_PATH_KEY

          public static final String PROPERTIES_PATH_KEY

      Servlet initialization parameter name for the path to Turbine.properties file used by Turbine
      See Also:
        Constant Field Values

    - #### PROPERTIES_PATH_DEFAULT

          public static final String PROPERTIES_PATH_DEFAULT

      Default value of TurbineResources.properties file path (`/WEB-INF/conf/TurbineResources.properties`).
      See Also:
        Constant Field Values

    - #### root

          protected File root

      Filenames are looked up in this directory.

    - #### attributes

          protected Map<String,Object> attributes

      Servlet container (or emulator) attributes.

    - #### initParams

          protected Map<String,String> initParams

      Turbine servlet initialization parameters.

  - ### Constructor Detail

    - #### TurbineConfig

          public TurbineConfig(String path,
                       Map<String,Object> attributes,
                       Map<String,String> initParams)

      Constructs a new TurbineConfig. This is the general form of the constructor. You can provide a path to search for files, and a name-value map of init parameters.

      For the list of recognized init parameters, see `Turbine` class.

      Parameters:
        `path` - The web application root (i.e. the path for file lookup).
        `attributes` - Servlet container (or emulator) attributes.
        `initParams` - initialization parameters.

    - #### TurbineConfig

          public TurbineConfig(String path,
                       Map<String,String> initParams)

      Constructs a new TurbineConfig. This is the general form of the constructor. You can provide a path to search for files, and a name-value map of init parameters.

      For the list of recognized init parameters, see `Turbine` class.

      Parameters:
        `path` - The web application root (i.e. the path for file lookup).
        `initParams` - initialization parameters.

    - #### TurbineConfig

          public TurbineConfig(String path,
                       String properties)

      Constructs a TurbineConfig. This is a specialized constructor that allows to configure Turbine easily in the common setups.
      Parameters:
        `path` - The web application root (i.e. the path for file lookup).
        `properties` - the relative path to TurbineResources.properties file

  - ### Method Detail

    - #### initialize

          public void initialize()

      Causes this class to initialize itself which in turn initializes all of the Turbine Services that need to be initialized.
      Specified by:
        `initialize` in interface `org.apache.avalon.framework.activity.Initializable`

    - #### init

          public void init(RunData data)

      Initialization requiring a HTTP `GET` request.
      Parameters:
        `data` - the Turbine request

    - #### dispose

          public void dispose()

      Shutdown the Turbine System, lifecycle style
      Specified by:
        `dispose` in interface `org.apache.avalon.framework.activity.Disposable`

    - #### getTurbine

          public Turbine getTurbine()

      Returns a reference to the Turbine servlet that was initialized.
      Returns:
        a ServletContext reference

    - #### getServletContext

          public javax.servlet.ServletContext getServletContext()

      Returns a reference to the object cast onto ServletContext type.
      Specified by:
        `getServletContext` in interface `javax.servlet.ServletConfig`
      Returns:
        a ServletContext reference

    - #### getRealPath

          public String getRealPath(String path)

      Translates a path relative to the web application root into an absolute path.
      Specified by:
        `getRealPath` in interface `javax.servlet.ServletContext`
      Parameters:
        `path` - A path relative to the web application root.
      Returns:
        An absolute version of the supplied path, or `null` if the translated path doesn't map to a file or directory.

    - #### getInitParameter

          public String getInitParameter(String name)

      Retrieves an initialization parameter.
      Specified by:
        `getInitParameter` in interface `javax.servlet.ServletConfig`
      Specified by:
        `getInitParameter` in interface `javax.servlet.ServletContext`
      Parameters:
        `name` - the name of the parameter.
      Returns:
        the value of the parameter.

    - #### getInitParameterNames

          public Enumeration<String> getInitParameterNames()

      Retrieves an Enumeration of initialization parameter names.
      Specified by:
        `getInitParameterNames` in interface `javax.servlet.ServletConfig`
      Specified by:
        `getInitParameterNames` in interface `javax.servlet.ServletContext`
      Returns:
        an Enumeration of initialization parameter names.

    - #### getServletName

          public String getServletName()

      Returns the servlet name. Fixed value "Turbine" is returned.
      Specified by:
        `getServletName` in interface `javax.servlet.ServletConfig`
      Returns:
        the servlet name.

    - #### getServletContextName

          public String getServletContextName()

      Returns the context name. Fixed value "Turbine" is returned
      Specified by:
        `getServletContextName` in interface `javax.servlet.ServletContext`
      Returns:
        the context name

    - #### getContextPath

          public String getContextPath()

      Returns the context path. Fixed value "/turbine" is returned
      Specified by:
        `getContextPath` in interface `javax.servlet.ServletContext`
      Returns:
        the context path

    - #### getResource

          public URL getResource(String s)
                          throws MalformedURLException

      Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.
      Specified by:
        `getResource` in interface `javax.servlet.ServletContext`
      Parameters:
        `s` - the path to the resource
      Returns:
        a URL pointing to the resource
      Throws:
        `MalformedURLException`

    - #### getResourceAsStream

          public InputStream getResourceAsStream(String s)

      Returns the resource located at the named path as an `InputStream` object.
      Specified by:
        `getResourceAsStream` in interface `javax.servlet.ServletContext`
      Parameters:
        `s` - the path to the resource
      Returns:
        an InputStream object from which the resource can be read

    - #### log

          @Deprecated
          public void log(Exception e,
                            String m)

      Deprecated. use log(String,Throwable) instead
      Logs an error message.
      Specified by:
        `log` in interface `javax.servlet.ServletContext`
      Parameters:
        `e` - an Exception.
        `m` - a message.

    - #### log

          public void log(String m)

      Logs a message.
      Specified by:
        `log` in interface `javax.servlet.ServletContext`
      Parameters:
        `m` - a message.

    - #### log

          public void log(String m,
                 Throwable t)

      Logs an error message.
      Specified by:
        `log` in interface `javax.servlet.ServletContext`
      Parameters:
        `t` - a Throwable object.
        `m` - a message.

    - #### getAttribute

          public Object getAttribute(String s)

      Returns the servlet container attribute with the given name, or null if there is no attribute by that name.
      Specified by:
        `getAttribute` in interface `javax.servlet.ServletContext`

    - #### getAttributeNames

          public Enumeration<String> getAttributeNames()

      Returns an Enumeration containing the attribute names available within this servlet context.
      Specified by:
        `getAttributeNames` in interface `javax.servlet.ServletContext`

    - #### getContext

          public javax.servlet.ServletContext getContext(String s)

      Not implemented. A method in ServletConfig or ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getContext` in interface `javax.servlet.ServletContext`

    - #### getMajorVersion

          public int getMajorVersion()

      Not implemented. A method in ServletConfig or ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getMajorVersion` in interface `javax.servlet.ServletContext`

    - #### getMimeType

          public String getMimeType(String s)

      Not implemented. A method in ServletConfig or ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getMimeType` in interface `javax.servlet.ServletContext`

    - #### getMinorVersion

          public int getMinorVersion()

      Not implemented. A method in ServletConfig or ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getMinorVersion` in interface `javax.servlet.ServletContext`

    - #### getNamedDispatcher

          public javax.servlet.RequestDispatcher getNamedDispatcher(String s)

      Not implemented. A method in ServletConfig or ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getNamedDispatcher` in interface `javax.servlet.ServletContext`

    - #### getRequestDispatcher

          public javax.servlet.RequestDispatcher getRequestDispatcher(String s)

      Not implemented. A method in ServletConfig or ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getRequestDispatcher` in interface `javax.servlet.ServletContext`

    - #### getResourcePaths

          public Set<String> getResourcePaths(String s)

      Not implemented. A method in ServletContext (2.3) interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getResourcePaths` in interface `javax.servlet.ServletContext`

    - #### getServerInfo

          public String getServerInfo()

      Not implemented. A method in ServletContext (2.3) interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getServerInfo` in interface `javax.servlet.ServletContext`

    - #### getServlet

          @Deprecated
          public javax.servlet.Servlet getServlet(String s)

      Deprecated. As of Java Servlet API 2.1, with no direct replacement.
      Not implemented. A method in ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getServlet` in interface `javax.servlet.ServletContext`

    - #### getServletNames

          @Deprecated
          public Enumeration<String> getServletNames()

      Deprecated. As of Java Servlet API 2.1, with no replacement.
      Not implemented. A method in ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getServletNames` in interface `javax.servlet.ServletContext`

    - #### getServlets

          @Deprecated
          public Enumeration<javax.servlet.Servlet> getServlets()

      Deprecated. As of Java Servlet API 2.0, with no replacement.
      Not implemented. A method in ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `getServlets` in interface `javax.servlet.ServletContext`

    - #### removeAttribute

          public void removeAttribute(String s)

      Not implemented. A method in ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `removeAttribute` in interface `javax.servlet.ServletContext`

    - #### setAttribute

          public void setAttribute(String s,
                          Object o)

      Not implemented. A method in ServletContext interface that is not implemented and will throw `UnsuportedOperationException` upon invocation
      Specified by:
        `setAttribute` in interface `javax.servlet.ServletContext`

Copyright © 2000–2018 The Apache Software Foundation. All rights reserved.