public interface ScriptUtil
ItsNat provides two default implementations of this interface, these implementations
are got calling ItsNatDocument.getScriptUtil() or
ClientDocument.getScriptUtil()
If this utility object was got calling the method ItsNatDocument.getScriptUtil()
the generated JavaScript code must be sent to the client calling ItsNatDocument.addCodeToSend(Object),
this JavaScript code will be received by all clients (owner and attached) of this document.
If this utility object was got calling the method ClientDocument.getScriptUtil()
the generated JavaScript code must be sent to the client calling ClientDocument.addCodeToSend(Object)
this JavaScript code will be received by the specified client (use ever the same client for generating and sending code).
When a DOM node is used a parameter this node must be part of the document tree (server and client) otherwise an exception is thrown, and the generated code must be sent as soon as possible to the client/s calling the appropriated method as explained before. *
ItsNat generates JavaScript code referencing the specified node in client, when this
utility object was got calling ItsNatDocument.getScriptUtil()
this reference is valid for all clients of the document (in spite of internal node caching
ItsNat ensures the same internal caching id is used for all clients or no caching is used).
| Modifier and Type | Method and Description |
|---|---|
ScriptExpr |
createScriptExpr(Object value)
Creates a new script expression object wrapping the specified object.
|
String |
encodeURIComponent(char c)
Is a Java implementation of the JavaScript
encodeURIComponent function
applied to a Java char. |
String |
encodeURIComponent(String text)
Is a Java implementation of the JavaScript
encodeURIComponent function. |
String |
getCallMethodCode(Object obj,
String methodName,
Object[] params)
Generates the appropriated code to call the specified object method at the client.
|
String |
getCallMethodCode(Object obj,
String methodName,
Object[] params,
boolean endSentence)
Generates the appropriated code to call the specified object method at the client.
|
String |
getGetPropertyCode(Object obj,
String propName)
Generates the JavaScript code to get the value of the specified property.
|
String |
getGetPropertyCode(Object obj,
String propName,
boolean endSentence)
Generates the JavaScript code to get the value of the specified property.
|
String |
getNodeReference(Node node)
Generates the appropriated code to locate the specified DOM node at the client.
|
String |
getSetPropertyCode(Object obj,
String propName,
Object value)
Generates the JavaScript code to set a value to the specified property.
|
String |
getSetPropertyCode(Object obj,
String propName,
Object value,
boolean endSentence)
Generates the JavaScript code to set a value to the specified property.
|
String |
getTransportableCharLiteral(char c)
Converts the specified Java
String to a JavaScript string literal, this
string can be sent to the client. |
String |
getTransportableStringLiteral(String text)
Converts the specified Java
String to a JavaScript string literal, this
string can be sent to the client. |
String |
toScript(Object value)
Converts the specified object value to JavaScript code.
|
String getNodeReference(Node node)
Returned code may be considered as a JavaScript reference to the specified node.
The following example generates JavaScript to set 'City' to the "value" property of the specified DOM element aNode:
ItsNatDocument itsNatDoc = ...; Element aNode = ...; String code = itsNatDoc.getScriptUtil().getNodeReference(aNode) + ".value = 'City';"; itsNatDoc.addCodeToSend(code);
node - the node to generate a JavaScript reference.ScriptExpr createScriptExpr(Object value)
String getCallMethodCode(Object obj, String methodName, Object[] params, boolean endSentence)
obj - the object reference, converted to JavaScript calling toScript(Object).methodName - method name.params - the parameter list. Are converted to JavaScript calling toScript(Object).endSentence - if true adds a ; at the end.String getCallMethodCode(Object obj, String methodName, Object[] params)
obj - the object reference, converted to JavaScript calling toScript(Object).methodName - method name.params - the parameter list. Are converted to JavaScript calling toScript(Object).String getSetPropertyCode(Object obj, String propName, Object value, boolean endSentence)
obj - the object reference, converted to JavaScript calling toScript(Object).propName - property name.value - the value to set. Is converted to JavaScript calling toScript(Object).endSentence - if true adds a ; at the end.String getSetPropertyCode(Object obj, String propName, Object value)
obj - the object reference, converted to JavaScript calling toScript(Object).propName - property name.value - the value to set. Is converted to JavaScript calling toScript(Object).String getGetPropertyCode(Object obj, String propName, boolean endSentence)
obj - the object reference, converted to JavaScript calling toScript(Object).propName - property name.endSentence - if true adds a ; at the end.String getGetPropertyCode(Object obj, String propName)
obj - the object reference, converted to JavaScript calling toScript(Object).propName - property name.String getTransportableStringLiteral(String text)
String to a JavaScript string literal, this
string can be sent to the client.
Any special character like end of lines, tabs, " , ' , \ etc are escaped to sent to the client as a JavaScript string literal.
text - the String to convert.String getTransportableCharLiteral(char c)
String to a JavaScript string literal, this
string can be sent to the client.
Any special character like end of lines, tabs, " , ' , \ etc are escaped to sent to the client as a JavaScript string literal.
c - the Java char to convert.String encodeURIComponent(String text)
encodeURIComponent function.
The string encoded with this method can be unencoded using the JavaScript decodeURIComponent function.
This method is an alternative (slower and bigger) to getTransportableStringLiteral(String)
to transport texts to the client.
The encoded Java String is not a string literal. The following
example encloses the String as a literal:
String code = "\"" + encodeURIComponent(someText) + "\"";
text - the Java String to encode.String encodeURIComponent(char c)
encodeURIComponent function
applied to a Java char.
This method is an alternative (slower and bigger) to getTransportableCharLiteral(char)
to transport characters to the client.
The encoded Java char is not a char literal. The following
example encloses the char as a literal:
String code = "'" + encodeURIComponent(someChar) + "'";
c - the Java char to encode.String toScript(Object value)
Conversion rules if value is a:
getNodeReference(org.w3c.dom.Node).true and false.getTransportableCharLiteral(char).ScriptExpr.getCode().getTransportableStringLiteral(String).value - the object to convert to JavaScript.Copyright © Innowhere Software, Jose Maria Arranz Santamaria.