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(java.lang.Object value)
Creates a new script expression object wrapping the specified object.
|
java.lang.String |
encodeURIComponent(char c)
Is a Java implementation of the JavaScript
encodeURIComponent function
applied to a Java char . |
java.lang.String |
encodeURIComponent(java.lang.String text)
Is a Java implementation of the JavaScript
encodeURIComponent function. |
java.lang.String |
getCallMethodCode(java.lang.Object obj,
java.lang.String methodName,
java.lang.Object[] params)
Generates the appropriated code to call the specified object method at the client.
|
java.lang.String |
getCallMethodCode(java.lang.Object obj,
java.lang.String methodName,
java.lang.Object[] params,
boolean endSentence)
Generates the appropriated code to call the specified object method at the client.
|
java.lang.String |
getGetPropertyCode(java.lang.Object obj,
java.lang.String propName)
Generates the JavaScript code to get the value of the specified property.
|
java.lang.String |
getGetPropertyCode(java.lang.Object obj,
java.lang.String propName,
boolean endSentence)
Generates the JavaScript code to get the value of the specified property.
|
java.lang.String |
getNodeReference(org.w3c.dom.Node node)
Generates the appropriated code to locate the specified DOM node at the client.
|
java.lang.String |
getSetPropertyCode(java.lang.Object obj,
java.lang.String propName,
java.lang.Object value)
Generates the JavaScript code to set a value to the specified property.
|
java.lang.String |
getSetPropertyCode(java.lang.Object obj,
java.lang.String propName,
java.lang.Object value,
boolean endSentence)
Generates the JavaScript code to set a value to the specified property.
|
java.lang.String |
getTransportableCharLiteral(char c)
Converts the specified Java
String to a JavaScript string literal, this
string can be sent to the client. |
java.lang.String |
getTransportableStringLiteral(java.lang.String text)
Converts the specified Java
String to a JavaScript string literal, this
string can be sent to the client. |
java.lang.String |
toScript(java.lang.Object value)
Converts the specified object value to JavaScript code.
|
java.lang.String getNodeReference(org.w3c.dom.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(java.lang.Object value)
java.lang.String getCallMethodCode(java.lang.Object obj, java.lang.String methodName, java.lang.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.java.lang.String getCallMethodCode(java.lang.Object obj, java.lang.String methodName, java.lang.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)
.java.lang.String getSetPropertyCode(java.lang.Object obj, java.lang.String propName, java.lang.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.java.lang.String getSetPropertyCode(java.lang.Object obj, java.lang.String propName, java.lang.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)
.java.lang.String getGetPropertyCode(java.lang.Object obj, java.lang.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.java.lang.String getGetPropertyCode(java.lang.Object obj, java.lang.String propName)
obj
- the object reference, converted to JavaScript calling toScript(Object)
.propName
- property name.java.lang.String getTransportableStringLiteral(java.lang.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.java.lang.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.java.lang.String encodeURIComponent(java.lang.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.java.lang.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.java.lang.String toScript(java.lang.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 © 2007 Innowhere Software Services S.L. All Rights Reserved.