com.osbcp.jjsw
Class JavaScript

java.lang.Object
  extended by com.osbcp.jjsw.JavaScript
All Implemented Interfaces:
java.io.Serializable

public class JavaScript
extends java.lang.Object
implements java.io.Serializable

JavaScript wrapper object.

Author:
@author Christoffer Pettersson
See Also:
Serialized Form

Nested Class Summary
static class JavaScript.TYPE
          Different output types.
 
Constructor Summary
JavaScript()
          Creates an empty JavaScript code instance.
JavaScript(java.lang.String code)
          Creates a new JavaScript instance based on a specific code.
JavaScript(java.lang.String javaScriptObjectName, java.lang.String code, java.lang.Object... parameters)
          Creates a new JavaScript instance based on a specific code.
 
Method Summary
 void append(JavaScript code)
          Appends a JavaScript code to the existing JavaScript code.
 void append(java.lang.String code)
          Appends a String to the JavaScript code.
 JavaScript call()
          Returns the JavaScript code to call the function.
 JavaScript call(boolean useSemicolon)
          Returns the JavaScript code to call the function.
static boolean isEmpty(JavaScript html)
          Checks if the JavaScript is empty.
 java.lang.String toScriptTag()
          Wraps the JavaScript in Script-tag, with character set UTF-8.
 java.lang.String toScriptTag(java.lang.String charset)
          Wraps the JavaScript in Script-tag.
static java.lang.String toScriptTagSource(java.lang.String source)
          Creates a Script-tag to a specific JavaScript source, with charset UTF-8.
static java.lang.String toScriptTagSource(java.lang.String charset, java.lang.String source)
          Creates a Script-tag to a specific JavaScript source.
 java.lang.String toString()
          Returns the JavaScript code as a String.
 java.lang.String toString(JavaScript.TYPE type)
          Outputs the JavaScript based on a specific output type.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JavaScript

public JavaScript()
Creates an empty JavaScript code instance.


JavaScript

public JavaScript(java.lang.String code)
Creates a new JavaScript instance based on a specific code.

Parameters:
code - The JavaScript code as String that should be appended

JavaScript

public JavaScript(java.lang.String javaScriptObjectName,
                  java.lang.String code,
                  java.lang.Object... parameters)
Creates a new JavaScript instance based on a specific code. Any additional parameters will be concatenated into the code via the %s annotation. For example: String name = "John"; JavaScriptFunction function = new JavaScriptFunction("alert(\"%s\");", name );

Parameters:
javaScriptObjectName - The JavaScript object name, for example "$test"
code - The JavaScript code
parameters - Any parameters that should be used in the JavaScript code. Each parameter should be declared as %s in the code. For example: alert('Hello %s %s!'); where the %s are parameters.
Method Detail

append

public void append(JavaScript code)
Appends a JavaScript code to the existing JavaScript code.

Parameters:
code - The JavaScript code to be appended

append

public void append(java.lang.String code)
Appends a String to the JavaScript code.

Parameters:
code - The code to be appended

toString

public java.lang.String toString()
Returns the JavaScript code as a String.

Overrides:
toString in class java.lang.Object
Returns:
The JavaScript code as a String.

toString

public java.lang.String toString(JavaScript.TYPE type)
Outputs the JavaScript based on a specific output type.

Parameters:
type - Type of output
Returns:
JavaScript as a String

toScriptTag

public java.lang.String toScriptTag()
Wraps the JavaScript in Script-tag, with character set UTF-8.

Returns:
The JavaScript wrapped in a Script-tag, with character set UTF-8
See Also:
http://www.w3schools.com/TAGS/tag_script.asp

toScriptTag

public java.lang.String toScriptTag(java.lang.String charset)
Wraps the JavaScript in Script-tag.

Parameters:
charset - The character set to be used.
Returns:
The JavaScript wrapped in a Script-tag
See Also:
http://www.w3schools.com/TAGS/tag_script.asp

toScriptTagSource

public static java.lang.String toScriptTagSource(java.lang.String source)
Creates a Script-tag to a specific JavaScript source, with charset UTF-8.

Parameters:
source - The source URI to the JavaScript code
Returns:
a Script-tag to a specific JavaScript source, with charset UTF-8
See Also:
http://www.w3schools.com/TAGS/tag_script.asp

toScriptTagSource

public static java.lang.String toScriptTagSource(java.lang.String charset,
                                                 java.lang.String source)
Creates a Script-tag to a specific JavaScript source.

Parameters:
charset - The character set to be used.
source - The source URI to the JavaScript code
Returns:
The JavaScript HTML tag
See Also:
http://www.w3schools.com/TAGS/tag_script.asp

isEmpty

public static boolean isEmpty(JavaScript html)
Checks if the JavaScript is empty.

Parameters:
html - The JavaScript to check
Returns:
if the JavaScript is empty

call

public final JavaScript call()
Returns the JavaScript code to call the function. JavaScriptFunction needs to be generated via the Generator class. By default a semicolon will be appended at the end.

Returns:
The JavaScript code that calls the function
See Also:
Generator

call

public final JavaScript call(boolean useSemicolon)
Returns the JavaScript code to call the function. JavaScriptFunction needs to be generated via the Generator class.

Parameters:
useSemicolon - If a semicolon should be appended at the end
Returns:
The JavaScript code that calls the function
See Also:
Generator