org.apache.turbine.services.pull.tools

## Class UITool

- java.lang.Object
- - org.apache.turbine.services.pull.tools.UITool

- All Implemented Interfaces:
    ApplicationTool

      public class UITool
      extends Object
      implements ApplicationTool

  Manages all UI elements for a Turbine Application. Any UI element can be accessed in any template using the $ui handle (assuming you use the default PullService configuration). So, for example, you could access the background color for your pages by using $ui.bgcolor

  This implementation provides a single level of inheritance in that if a property does not exist in a non-default skin, the value from the default skin will be used. By only requiring values different to those stored in the default skin to appear in the non-default skins the amount of memory consumed in cases where the UserManager instance is used at a non-global scope will potentially be reduced due to the fact that a shared instance of the default skin properties can be used. Note that this inheritance only applies to property values - it does not apply to any images or stylesheets that may form part of your skins.

  This is an application pull tool for the template system. You should not use it in a normal application! Within Java code you should use TurbineUI.

  This is an application pull tool for the template system. You should only use it in a normal application to set the skin attribute for a user (setSkin(User user, String skin)) and to initialize it for the user, otherwise use TurbineUI is probably the way to go.

  Version:
    $Id$
  Author:
    Jason van Zyl, James Coltman, Henning P. Schmiedehausen, Scott Eade
  See Also:
    `UIService`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `SKIN_ATTRIBUTE` Attribute name of skinName value in User's temp hashmap.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UITool()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `get(String key)` Retrieve a skin property.
    `String` | `getScript(String filename)` Retrieve the URL for a given script that is part of the skin.
    `String` | `getScript(String filename, RunData data)` Retrieve the URL for a given script that is part of the skin.
    `String` | `getScript(String filename, ServerData serverData)` Retrieve the URL for a given script that is part of the skin.
    `String` | `getSkin()` Retrieve the skin name.
    `String[]` | `getSkinNames()` Provide access to the list of available skin names.
    `String` | `getStylecss()` Retrieve the URL for the style sheet that is part of the skin.
    `String` | `getStylecss(RunData data)` Retrieve the URL for the style sheet that is part of the skin.
    `String` | `getStylecss(ServerData serverData)` Retrieve the URL for the style sheet that is part of the skin.
    `String` | `getWebappSkinName()` Get the name of the default skin name for the web application from the TurbineResources.properties file.
    `String` | `image(String imageId)` Retrieve the URL for an image that is part of the skin.
    `String` | `image(String imageId, RunData data)` Retrieve the URL for an image that is part of the skin.
    `String` | `image(String imageId, ServerData serverData)` Retrieve the URL for an image that is part of the skin.
    `void` | `init(Object data)` Initialize the UITool object.
    `void` | `refresh()` Refresh the tool.
    `void` | `setSkin()` Set the skin name to the skin from the TurbineResources.properties file.
    `protected void` | `setSkin(RunData data)` Set the skin name when the tool is configured to be loaded on a per-request basis.
    `void` | `setSkin(String skinName)` Set the skin name to the specified skin.
    `protected void` | `setSkin(User user)` Set the skin name when the tool is configured to be loaded on a per-session basis.
    `static void` | `setSkin(User user, String skin)` Set the skin name in the user's temp hashmap for the current session.

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

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

- - ### Field Detail

    - #### SKIN_ATTRIBUTE

          public static final String SKIN_ATTRIBUTE

      Attribute name of skinName value in User's temp hashmap.

  - ### Constructor Detail

    - #### UITool

          public UITool()

  - ### Method Detail

    - #### refresh

          public void refresh()

      Refresh the tool.
      Specified by:
        `refresh` in interface `ApplicationTool`

    - #### getSkinNames

          public String[] getSkinNames()

      Provide access to the list of available skin names.
      Returns:
        the available skin names.

    - #### getWebappSkinName

          public String getWebappSkinName()

      Get the name of the default skin name for the web application from the TurbineResources.properties file. If the property is not present the name of the default skin will be returned. Note that the web application skin name may be something other than default, in which case its properties will default to the skin with the name "default".
      Returns:
        the name of the default skin for the web application.

    - #### get

          public String get(String key)

      Retrieve a skin property. If the property is not defined in the current skin the value for the default skin will be provided. If the current skin does not exist then the skin configured for the webapp will be used. If the webapp skin does not exist the default skin will be used. If the default skin does not exist then `null` will be returned.
      Parameters:
        `key` - the key to retrieve from the skin.
      Returns:
        the value of the property for the named skin (defaulting to the default skin), the webapp skin, the default skin or `null`, depending on whether or not the property or skins exist.

    - #### getSkin

          public String getSkin()

      Retrieve the skin name.
      Returns:
        the selected skin name

    - #### setSkin

          public void setSkin()

      Set the skin name to the skin from the TurbineResources.properties file. If the property is not present use the "default" skin.

    - #### setSkin

          public void setSkin(String skinName)

      Set the skin name to the specified skin.
      Parameters:
        `skinName` - the skin name to use.

    - #### setSkin

          protected void setSkin(RunData data)

      Set the skin name when the tool is configured to be loaded on a per-request basis. By default it calls getSkin to return the skin specified in TurbineResources.properties. Developers can write a subclass of UITool that overrides this method to determine the skin to use based on information held in the request.
      Parameters:
        `data` - a RunData instance

    - #### setSkin

          protected void setSkin(User user)

      Set the skin name when the tool is configured to be loaded on a per-session basis. If the user's temp hashmap contains a value in the attribute specified by the String constant SKIN_ATTRIBUTE then that is returned. Otherwise it calls getSkin to return the skin specified in TurbineResources.properties.
      Parameters:
        `user` - a User instance

    - #### setSkin

          public static void setSkin(User user,
                     String skin)

      Set the skin name in the user's temp hashmap for the current session.
      Parameters:
        `user` - a User instance
        `skin` - the skin name for the session

    - #### image

          public String image(String imageId,
                     RunData data)

      Retrieve the URL for an image that is part of the skin. The images are stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.

      Use this if for some reason your server name, server scheme, or server port change on a per request basis. I'm not sure if this would happen in a load balanced situation. I think in most cases the image(String image) method would probably be enough, but I'm not absolutely positive.

      Parameters:
        `imageId` - the id of the image whose URL will be generated.
        `data` - the RunData to use as the source of the ServerData to use as the basis for the URL.
      Returns:
        the image URL

    - #### image

          public String image(String imageId,
                     ServerData serverData)

      Retrieve the URL for an image that is part of the skin. The images are stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.

      Use this if for some reason your server name, server scheme, or server port change on a per request basis. I'm not sure if this would happen in a load balanced situation. I think in most cases the image(String image) method would probably be enough, but I'm not absolutely positive.

      Parameters:
        `imageId` - the id of the image whose URL will be generated.
        `serverData` - the serverData to use as the basis for the URL.
      Returns:
        the image URL

    - #### image

          public String image(String imageId)

      Retrieve the URL for an image that is part of the skin. The images are stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
      Parameters:
        `imageId` - the id of the image whose URL will be generated.
      Returns:
        the image URL

    - #### getStylecss

          public String getStylecss(RunData data)

      Retrieve the URL for the style sheet that is part of the skin. The style is stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the filename skin.css

      Use this if for some reason your server name, server scheme, or server port change on a per request basis. I'm not sure if this would happen in a load balanced situation. I think in most cases the style() method would probably be enough, but I'm not absolutely positive.

      Parameters:
        `data` - the RunData to use as the source of the ServerData to use as the basis for the URL.
      Returns:
        the CSS URL

    - #### getStylecss

          public String getStylecss(ServerData serverData)

      Retrieve the URL for the style sheet that is part of the skin. The style is stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the filename skin.css

      Use this if for some reason your server name, server scheme, or server port change on a per request basis. I'm not sure if this would happen in a load balanced situation. I think in most cases the style() method would probably be enough, but I'm not absolutely positive.

      Parameters:
        `serverData` - the serverData to use as the basis for the URL.
      Returns:
        the CSS URL

    - #### getStylecss

          public String getStylecss()

      Retrieve the URL for the style sheet that is part of the skin. The style is stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the filename skin.css
      Returns:
        the CSS URL

    - #### getScript

          public String getScript(String filename,
                         RunData data)

      Retrieve the URL for a given script that is part of the skin. The script is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.

      Use this if for some reason your server name, server scheme, or server port change on a per request basis. I'm not sure if this would happen in a load balanced situation. I think in most cases the image(String image) method would probably be enough, but I'm not absolutely positive.

      Parameters:
        `filename` - the name of the script file whose URL will be generated.
        `data` - the RunDate to use as the source of the ServerData to use as the basis for the URL.
      Returns:
        the script URL

    - #### getScript

          public String getScript(String filename,
                         ServerData serverData)

      Retrieve the URL for a given script that is part of the skin. The script is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.

      Use this if for some reason your server name, server scheme, or server port change on a per request basis. I'm not sure if this would happen in a load balanced situation. I think in most cases the image(String image) method would probably be enough, but I'm not absolutely positive.

      Parameters:
        `filename` - the name of the script file whose URL will be generated.
        `serverData` - the serverData to use as the basis for the URL.
      Returns:
        the script URL

    - #### getScript

          public String getScript(String filename)

      Retrieve the URL for a given script that is part of the skin. The script is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
      Parameters:
        `filename` - the name of the script file whose URL will be generated.
      Returns:
        the script URL

    - #### init

          public void init(Object data)

      Initialize the UITool object.
      Specified by:
        `init` in interface `ApplicationTool`
      Parameters:
        `data` - This is null, RunData or User depending upon specified tool scope.

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