| org.itsnat.core.script.ScriptUtil
All known Subclasses: org.itsnat.impl.core.js.JScriptUtilImpl,
ScriptUtil | public interface ScriptUtil (Code) | | Utility interface to generate JavaScript code mainly to bridge server DOM nodes
with client nodes.
When a DOM node is used a parameter this must be part of the document tree
(server and client) otherwise an exception is thrown, and the generated code
MUST be sent to the client normally calling
org.itsnat.core.ItsNatDocument.addCodeToSend(Object) because this node may have been automatically cached at the server, the generated code contains
the order and information to cache at the client too, otherwise the server and client
caches are unsynchronized (if localization cache is disabled this issue does not apply).
author: Jose Maria Arranz Santamaria |
Method Summary | |
public ScriptExpr | createScriptExpr(Object value) Creates a new script expression object wrapping the specified object. | public String | encodeURIComponent(String text) Is a Java implementation of the JavaScript encodeURIComponent function. | public String | encodeURIComponent(char c) Is a Java implementation of the JavaScript encodeURIComponent function
applied to a Java char . | public String | getCallMethodCode(Object obj, String methodName, Object[] params, boolean endSentence) Generates the appropriated code to call the specified object method at the client.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: methodName - method name. Parameters: params - the parameter list. | public String | getCallMethodCode(Object obj, String methodName, Object[] params) Generates the appropriated code to call the specified object method at the client.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: methodName - method name. Parameters: params - the parameter list. | public String | getGetPropertyCode(Object obj, String propName, boolean endSentence) Generates the JavaScript code to get the value of the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). | public String | getGetPropertyCode(Object obj, String propName) Generates the JavaScript code to get the value of the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). | public String | getNodeReference(Node node) Generates the appropriated code to locate the specified DOM node at the client.
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 node:
String code = itsNatDoc.getScriptUtil().getNodeReference(aNode) + ".value = 'City';";
itsNatDoc.addCodeToSend(code);
Parameters: node - the node to generate a JavaScript reference. | public String | getSetPropertyCode(Object obj, String propName, Object value, boolean endSentence) Generates the JavaScript code to set a value to the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). | public String | getSetPropertyCode(Object obj, String propName, Object value) Generates the JavaScript code to set a value to the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). | public String | getTransportableCharLiteral(char c) Converts the specified Java String to a JavaScript string literal, this
string can be send to the client.
Any special character like end of lines, tabs, " , ' , \ etc are escaped to sent
to the client as a JavaScript string literal.
Parameters: c - the Java char to convert. | public String | getTransportableStringLiteral(String text) Converts the specified Java String to a JavaScript string literal, this
string can be send to the client.
Any special character like end of lines, tabs, " , ' , \ etc are escaped to sent
to the client as a JavaScript string literal.
Parameters: text - the String to convert. | public String | toScript(Object value) Converts the specified object value to JavaScript code.
Conversion rules if value is a:
Parameters: value - the object to convert to JavaScript. |
createScriptExpr | public ScriptExpr createScriptExpr(Object value)(Code) | | Creates a new script expression object wrapping the specified object.
a new script expression object. |
encodeURIComponent | public String encodeURIComponent(String text)(Code) | | Is a Java implementation of the JavaScript 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
ScriptUtil.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) + "\"";
Parameters: text - the Java String to encode. the encoded text. |
encodeURIComponent | public String encodeURIComponent(char c)(Code) | | Is a Java implementation of the JavaScript encodeURIComponent function
applied to a Java char .
This method is an alternative (slower and bigger) to
ScriptUtil.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) + "'";
Parameters: c - the Java char to encode. the encoded char. |
getCallMethodCode | public String getCallMethodCode(Object obj, String methodName, Object[] params, boolean endSentence)(Code) | | Generates the appropriated code to call the specified object method at the client.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: methodName - method name. Parameters: params - the parameter list. Are converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: endSentence - if true adds a ; at the end. the JavaScript code. |
getCallMethodCode | public String getCallMethodCode(Object obj, String methodName, Object[] params)(Code) | | Generates the appropriated code to call the specified object method at the client.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: methodName - method name. Parameters: params - the parameter list. Are converted to JavaScript calling ScriptUtil.toScript(Object). the JavaScript code. |
getGetPropertyCode | public String getGetPropertyCode(Object obj, String propName, boolean endSentence)(Code) | | Generates the JavaScript code to get the value of the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: propName - property name. Parameters: endSentence - if true adds a ; at the end. the JavaScript code. |
getGetPropertyCode | public String getGetPropertyCode(Object obj, String propName)(Code) | | Generates the JavaScript code to get the value of the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: propName - property name. the JavaScript code. |
getNodeReference | public String getNodeReference(Node node)(Code) | | Generates the appropriated code to locate the specified DOM node at the client.
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 node:
String code = itsNatDoc.getScriptUtil().getNodeReference(aNode) + ".value = 'City';";
itsNatDoc.addCodeToSend(code);
Parameters: node - the node to generate a JavaScript reference. the JavaScript reference to send to the client. |
getSetPropertyCode | public String getSetPropertyCode(Object obj, String propName, Object value, boolean endSentence)(Code) | | Generates the JavaScript code to set a value to the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: propName - property name. Parameters: value - the value to set. Is converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: endSentence - if true adds a ; at the end. the JavaScript code. |
getSetPropertyCode | public String getSetPropertyCode(Object obj, String propName, Object value)(Code) | | Generates the JavaScript code to set a value to the specified property.
Parameters: obj - the object reference, converted to JavaScript calling ScriptUtil.toScript(Object). Parameters: propName - property name. Parameters: value - the value to set. Is converted to JavaScript calling ScriptUtil.toScript(Object). the JavaScript code. |
getTransportableCharLiteral | public String getTransportableCharLiteral(char c)(Code) | | Converts the specified Java String to a JavaScript string literal, this
string can be send to the client.
Any special character like end of lines, tabs, " , ' , \ etc are escaped to sent
to the client as a JavaScript string literal.
Parameters: c - the Java char to convert. the resulting JavaScript string literal. |
getTransportableStringLiteral | public String getTransportableStringLiteral(String text)(Code) | | Converts the specified Java String to a JavaScript string literal, this
string can be send to the client.
Any special character like end of lines, tabs, " , ' , \ etc are escaped to sent
to the client as a JavaScript string literal.
Parameters: text - the String to convert. the resulting JavaScript string literal. |
toScript | public String toScript(Object value)(Code) | | Converts the specified object value to JavaScript code.
Conversion rules if value is a:
Parameters: value - the object to convert to JavaScript. the JavaScript code. |
|
|