Interface Device

All Known Implementing Classes:
AjaxDevice, GenericDevice

public interface Device
Represents a client device. For example, the HTML browsers with Ajax are called AjaxDevice, the XML output called org.zkoss.zml.device.XmlDevice, and the MIL device called org.zkoss.mil.device.MilDevice.

Note: the same device is shared by all desktops of the same device type.

Since:
2.4.0
Author:
tomyeh
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds the content that shall be added to the output generated and sent to the client, when rending a desktop.
    Returns the default content type (never null).
    Returns the default doc type, or null if no doc type at all.
    Returns the content that shall be embedded to the output being generated to the client, or null if no embedded content.
    Returns the class that implements the server-push feature (ServerPush) for this device, or null if the default is used.
    Returns the device type.
    Returns the unavailable message that is shown to the client if the client doesn't support this device.
    void
    init(String deviceType, DeviceConfig config)
    Initializes the device.
    boolean
    Returns whether the output can be cached by the client.
    isCompatible(String userAgent)
    Returns whether this device supports the specified client.
    boolean
    isSupported(int func)
    Returns whether the specified function is supported.
    matches(String userAgent)
    Returns the name and version of the client if the given user agent matches this client, or null if not matched or it is a standard browser request.
    Converts a package to an absolute path that can be accessible by the class loader (classpath).
    void
    Reloads the client-side messages in the specified locale.
    void
    Notification that the desktop, which owns this device, has just been activated (a.k.a., deserialized) by the Web container.
    void
    Notification that the desktop, which owns this device, is about to be passivated (a.k.a., serialized) by the Web container.
    Sets the class that implements the server-push feature (ServerPush) for this device, or null to use the default.
    Sets the unavailable message that is shown to the client if the client doesn't support this device.
    Converts a relative path to an absolute path that can be accessible by the class loader (classpath).
  • Method Details

    • isSupported

      boolean isSupported(int func)
      Returns whether the specified function is supported.
      Parameters:
      func - the function.
      Since:
      3.0.3
    • getType

      String getType()
      Returns the device type.
    • isCacheable

      boolean isCacheable()
      Returns whether the output can be cached by the client.
    • getUnavailableMessage

      String getUnavailableMessage()
      Returns the unavailable message that is shown to the client if the client doesn't support this device.
      Returns:
      the unavailable message, or null if no such message
      Since:
      2.4.0
    • setUnavailableMessage

      String setUnavailableMessage(String unavailmsg)
      Sets the unavailable message that is shown to the client if the client doesn't support this device.
      Parameters:
      unavailmsg - the unavailable message.
      Returns:
      the previous unavailable message, or null if not such message
      Since:
      2.4.0
    • isCompatible

      Boolean isCompatible(String userAgent)
      Returns whether this device supports the specified client.
      Parameters:
      userAgent - represents a client. For HTTP clients, It is the user-agent header.
      Returns:
      Boolean.TRUE if this device supports the specified client, Boolean.FALSE if cannot, or null if unknown.
      Since:
      3.5.0
      See Also:
    • getServerPushClass

      Class getServerPushClass()
      Returns the class that implements the server-push feature (ServerPush) for this device, or null if the default is used.
      Since:
      3.0.0
    • setServerPushClass

      Class setServerPushClass(Class cls)
      Sets the class that implements the server-push feature (ServerPush) for this device, or null to use the default.

      Default: PollingServerPush.

      If ZK EE (with zkmax.jar) is loaded, the COMET-based server push (CometServerPush) is the default.

      Returns:
      the previous class, or null if not available.
      Since:
      3.0.0
    • getContentType

      String getContentType()
      Returns the default content type (never null).
      Since:
      3.0.0
    • getDocType

      String getDocType()
      Returns the default doc type, or null if no doc type at all.
      Since:
      3.0.0
    • addEmbedded

      void addEmbedded(String content)
      Adds the content that shall be added to the output generated and sent to the client, when rending a desktop. What content can be embedded depends on the device. For Ajax devices, it can be anything that can be placed inside HTML HEAD, such as JavaScript codes.

      As the method name suggests, the embedded contents are accumulated and all generated to the output.

      Since:
      3.0.6
    • getEmbedded

      String getEmbedded()
      Returns the content that shall be embedded to the output being generated to the client, or null if no embedded content.
      Since:
      3.0.6
    • init

      void init(String deviceType, DeviceConfig config)
      Initializes the device. A device is created for each desktop, and this method is called when it is associated to the desktop.
      Parameters:
      deviceType - the device type (never null)
      config - the configuration to initialize the device (never null)
      Since:
      3.0.0
    • sessionWillPassivate

      void sessionWillPassivate(Desktop desktop)
      Notification that the desktop, which owns this device, is about to be passivated (a.k.a., serialized) by the Web container.
      Since:
      2.4.0
    • sessionDidActivate

      void sessionDidActivate(Desktop desktop)
      Notification that the desktop, which owns this device, has just been activated (a.k.a., deserialized) by the Web container.
      Since:
      2.4.0
    • matches

      Object[] matches(String userAgent)
      Returns the name and version of the client if the given user agent matches this client, or null if not matched or it is a standard browser request.
      Parameters:
      userAgent - represents a client (i.e., HTTP's user-agent).
      Returns:
      a pair of objects or null. The first element of the pair is the name of the client (String), the second element is the version (Double, such as 3.5).
      Since:
      6.0.0
    • reloadMessages

      void reloadMessages(Locale locale) throws IOException
      Reloads the client-side messages in the specified locale.

      Notice that this method only reloads the standard messages. The application has to update the component's content (such as labels) manually if necessary.

      Limitation: it reloads only the messages of ZK Client Engine and ZUL components. It does not reload messages loaded by your own JavaScript codes.

      Parameters:
      locale - the locale. If null, Locales.getCurrent() is assumed.
      Throws:
      IOException
      Since:
      5.0.4
    • packageToPath

      String packageToPath(String pkg)
      Converts a package to an absolute path that can be accessible by the class loader (classpath).
      Since:
      5.0.4
    • toAbsolutePath

      String toAbsolutePath(String path)
      Converts a relative path to an absolute path that can be accessible by the class loader (classpath).
      Parameters:
      path - the path (never null). It is assumed to be a relative path if not starting with '/' or '~'.
      Since:
      5.0.4