Class Devices

java.lang.Object
org.zkoss.zk.device.Devices

public class Devices extends Object
A manager of devices (Device).
Since:
2.4.0
Author:
tomyeh
  • Method Details

    • getDevice

      public static final Device getDevice(String deviceType) throws DeviceNotFoundException
      Returns the device for the specified desktop type.
      Parameters:
      deviceType - the device type, such as ajax, xml and mil.
      Throws:
      DeviceNotFoundException - if not found.
      Since:
      3.0.0
    • getDeviceByClient

      public static final Device getDeviceByClient(String userAgent) throws DeviceNotFoundException
      Returns the device for the specified client. It invokes Device.isCompatible(java.lang.String) to return the correct device. If all devices returns null (means unknown), one of the devices returning null is returned. If all devices returns Boolean.FALSE, DeviceNotFoundException is thrown.
      Parameters:
      userAgent - represents a client. It is the user-agent header for HTTP-base client.
      Throws:
      DeviceNotFoundException - if not found.
      Since:
      3.0.0
      See Also:
    • exists

      public static final boolean exists(String deviceType)
      Tests whether the device for the specified type exists.
      Parameters:
      deviceType - the device type, say, ajax.
      Since:
      2.4.0
    • add

      public static final void add(org.zkoss.idom.Element config)
      Adds a device based on the XML declaration.
      
              <device-config>
              <device-type>superajax</device-type>
              <device-class>my.MyDevice</device-class>
              <unavailable-message>error message</unavailable-message>
              <server-push-class>my.MyServerPush</server-push-class>
              </device-config>
       
      Parameters:
      config - the XML element called zscript-config
    • add

      public static final String add(String deviceType, String clsnm)
      Adds a device type.
      Parameters:
      deviceType - the device type (a.k.a., the device name).
      clsnm - the device class name
      Returns:
      the previous class of the device with the same type, if any, or null if no such device.
    • add

      public static final String add(String deviceType, Class cls)
      Adds a device type.
      Parameters:
      deviceType - the device type (a.k.a., the device name).
      cls - the device class
      Returns:
      the previous class of the device with the same type, if any, or null if no such device.
      Since:
      3.0.0
    • getUnavailableMessage

      public static final String getUnavailableMessage(String deviceType)
      Returns the unavailable message for the specified device type.

      The result is the same as the invocation of Device.getUnavailableMessage() against getDevice(java.lang.String), but this method will not load the device if it is not loaded yet.

      See Also:
    • setUnavailableMessage

      public static final String setUnavailableMessage(String deviceType, String msg)
      Sets the unavailable message for the specified device type.
      Returns:
      the previous unavailable message if any.
      See Also:
    • getEmbedded

      public String getEmbedded(String deviceType)
      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
    • addEmbedded

      public static void addEmbedded(String deviceType, 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
    • getServerPushClass

      public static final String getServerPushClass(String deviceType)
      Returns the class name that implements the server push feature.

      Default: null (the server-push feature is not available).

      The result is the same as the invocation of Device.getServerPushClass() against getDevice(java.lang.String), but this method will not load the device if it is not loaded yet.

      Since:
      3.0.0
    • setServerPushClass

      public static final String setServerPushClass(String deviceType, String clsnm)
      Sets the name of the class that implements the server-push feature.
      Parameters:
      clsnm - the class name that implements the server push. If null, it means no server push is available.
      Returns:
      the previous class name, or null if not available.
      Since:
      3.0.0
    • setServerPushClass

      public static final String setServerPushClass(String deviceType, Class cls)
      Sets the class that implements the server-push feature.
      Parameters:
      cls - the class that implements the server push. If null, it means no server push is available.
      Returns:
      the previous class name, or null if not available.
      Since:
      3.0.0
    • matches

      public static final Object[] matches(String userAgent)
      Returns the name and version of the client if the given user agent matches any of the devices, or null if not matched or it is a standard browser request.

      It iterates all devices and invokes Device.matches(java.lang.String) one-by-one, then returns the first non-null return, if any.

      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
    • loadJavaScript

      public static String loadJavaScript(Execution exec, String path) throws IOException
      Loads the content of a javascript file as a String.
      Throws:
      IOException
      Since:
      5.0.11
    • loadFileContentAsString

      public static String loadFileContentAsString(Execution exec, String path) throws IOException
      Loads the content of a file as a String.
      Throws:
      IOException
      Since:
      8.5.1