Package org.zkoss.zk.device
Class Devices
java.lang.Object
org.zkoss.zk.device.Devices
A manager of devices (
Device).- Since:
- 2.4.0
- Author:
- tomyeh
-
Method Summary
Modifier and TypeMethodDescriptionstatic final StringAdds a device type.static final StringAdds a device type.static final voidadd(org.zkoss.idom.Element config) Adds a device based on the XML declaration.static voidaddEmbedded(String deviceType, String content) Adds the content that shall be added to the output generated and sent to the client, when rending a desktop.static final booleanTests whether the device for the specified type exists.static final DeviceReturns the device for the specified desktop type.static final DevicegetDeviceByClient(String userAgent) Returns the device for the specified client.getEmbedded(String deviceType) Returns the content that shall be embedded to the output being generated to the client, or null if no embedded content.static final StringgetServerPushClass(String deviceType) Returns the class name that implements the server push feature.static final StringgetUnavailableMessage(String deviceType) Returns the unavailable message for the specified device type.static StringloadFileContentAsString(Execution exec, String path) Loads the content of a file as a String.static StringloadJavaScript(Execution exec, String path) Loads the content of a javascript file as a String.static final Object[]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.static final StringsetServerPushClass(String deviceType, Class cls) Sets the class that implements the server-push feature.static final StringsetServerPushClass(String deviceType, String clsnm) Sets the name of the class that implements the server-push feature.static final StringsetUnavailableMessage(String deviceType, String msg) Sets the unavailable message for the specified device type.
-
Method Details
-
getDevice
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
Returns the device for the specified client. It invokesDevice.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
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
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
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
-
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
-
addEmbedded
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
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()againstgetDevice(java.lang.String), but this method will not load the device if it is not loaded yet.- Since:
- 3.0.0
-
setServerPushClass
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
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
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
Loads the content of a javascript file as a String.- Throws:
IOException- Since:
- 5.0.11
-
loadFileContentAsString
Loads the content of a file as a String.- Throws:
IOException- Since:
- 8.5.1
-