Class GenericDevice

java.lang.Object
org.zkoss.zk.device.GenericDevice
All Implemented Interfaces:
Device
Direct Known Subclasses:
AjaxDevice

public abstract class GenericDevice extends Object implements Device
A skeletal implementation of Device.
Since:
3.0.0
Author:
tomyeh
  • Constructor Details

    • GenericDevice

      public GenericDevice()
  • Method Details

    • isSupported

      public boolean isSupported(int func)
      Description copied from interface: Device
      Returns whether the specified function is supported.
      Specified by:
      isSupported in interface Device
      Parameters:
      func - the function.
    • getType

      public String getType()
      Description copied from interface: Device
      Returns the device type.
      Specified by:
      getType in interface Device
    • isCacheable

      public boolean isCacheable()
      Return true to indicate it is cacheable.
      Specified by:
      isCacheable in interface Device
    • isCompatible

      public Boolean isCompatible(String userAgent)
      Returns null to indicate unknown. Deriving should override it to provide more precise information.
      Specified by:
      isCompatible in interface Device
      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.
      See Also:
    • getUnavailableMessage

      public String getUnavailableMessage()
      Description copied from interface: Device
      Returns the unavailable message that is shown to the client if the client doesn't support this device.
      Specified by:
      getUnavailableMessage in interface Device
      Returns:
      the unavailable message, or null if no such message
    • setUnavailableMessage

      public String setUnavailableMessage(String msg)
      Description copied from interface: Device
      Sets the unavailable message that is shown to the client if the client doesn't support this device.
      Specified by:
      setUnavailableMessage in interface Device
      Parameters:
      msg - the unavailable message.
      Returns:
      the previous unavailable message, or null if not such message
    • setServerPushClass

      public Class setServerPushClass(Class cls)
      Description copied from interface: Device
      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.

      Specified by:
      setServerPushClass in interface Device
      Returns:
      the previous class, or null if not available.
    • getServerPushClass

      public Class getServerPushClass()
      Description copied from interface: Device
      Returns the class that implements the server-push feature (ServerPush) for this device, or null if the default is used.
      Specified by:
      getServerPushClass in interface Device
    • getDocType

      public String getDocType()
      Returns null to indicate not to generate <!DOCTYPE> at all.
      Specified by:
      getDocType in interface Device
    • addEmbedded

      public void addEmbedded(String content)
      Description copied from interface: Device
      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.

      Specified by:
      addEmbedded in interface Device
    • getEmbedded

      public String getEmbedded()
      Description copied from interface: Device
      Returns the content that shall be embedded to the output being generated to the client, or null if no embedded content.
      Specified by:
      getEmbedded in interface Device
    • matches

      public 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.

      This implementation always returns null. That is, it assumes the client is a standard browser.

      Specified by:
      matches in interface Device
      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

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

      Default: throw UnsupportedOperationException.

      Specified by:
      reloadMessages in interface Device
      Parameters:
      locale - the locale. If null, Locales.getCurrent() is assumed.
      Throws:
      IOException
      Since:
      5.0.4
    • packageToPath

      public String packageToPath(String pkg)
      Converts a package to an absolute path that can be accessible by the class loader (classpath).

      Default: throw UnsupportedOperationException.

      Specified by:
      packageToPath in interface Device
      Since:
      5.0.4
    • toAbsolutePath

      public String toAbsolutePath(String path)
      Converts a relative path to an absolute path that can be accessible by the class loader (classpath).

      Default: throw UnsupportedOperationException.

      Specified by:
      toAbsolutePath in interface Device
      Parameters:
      path - the path (never null). It is assumed to be a relative path if not starting with '/' or '~'.
      Since:
      5.0.4
    • init

      public void init(String type, DeviceConfig config)
      Description copied from interface: Device
      Initializes the device. A device is created for each desktop, and this method is called when it is associated to the desktop.
      Specified by:
      init in interface Device
      Parameters:
      type - the device type (never null)
      config - the configuration to initialize the device (never null)
    • sessionWillPassivate

      public void sessionWillPassivate(Desktop desktop)
      Description copied from interface: Device
      Notification that the desktop, which owns this device, is about to be passivated (a.k.a., serialized) by the Web container.
      Specified by:
      sessionWillPassivate in interface Device
    • sessionDidActivate

      public void sessionDidActivate(Desktop desktop)
      Description copied from interface: Device
      Notification that the desktop, which owns this device, has just been activated (a.k.a., deserialized) by the Web container.
      Specified by:
      sessionDidActivate in interface Device