Class JavaScriptUtils
- java.lang.Object
-
- org.apache.wicket.core.util.string.JavaScriptUtils
-
public class JavaScriptUtils extends java.lang.ObjectProvide some helpers to write javascript related tags to the response object.- Author:
- Juergen Donnerstag
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSCRIPT_CLOSE_TAGScript close tag including content suffixstatic java.lang.StringSCRIPT_CONTENT_PREFIXPrefix for JavaScript CDATA content.static java.lang.StringSCRIPT_CONTENT_SUFFIXSuffix for JavaScript CDATA content.static java.lang.StringSCRIPT_OPEN_TAGScript open tag including content prefix
-
Constructor Summary
Constructors Constructor Description JavaScriptUtils(org.apache.wicket.request.Response response)Constructor without id for backward compatibilityJavaScriptUtils(org.apache.wicket.request.Response response, java.lang.String id)Construct.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Write the script close tag to the response.static java.lang.CharSequenceescapeQuotes(java.lang.CharSequence input)Escape single and double quotes so that they can be part of e.g.voidprintln(java.lang.CharSequence script)voidwrite(java.lang.CharSequence script)static voidwriteCloseTag(org.apache.wicket.request.Response response)static voidwriteJavaScript(org.apache.wicket.request.Response response, java.lang.CharSequence text)Write the simple text to the response object surrounded by a script tag.static voidwriteJavaScript(org.apache.wicket.request.Response response, java.lang.CharSequence text, java.lang.String id)Write the simple text to the response object surrounded by a script tag.static voidwriteJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url)Write a reference to a javascript file to the response objectstatic voidwriteJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url, java.lang.String id)Write a reference to a javascript file to the response objectstatic voidwriteJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url, java.lang.String id, boolean defer, java.lang.String charset)Write a reference to a javascript file to the response objectstatic voidwriteJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url, java.lang.String id, boolean defer, java.lang.String charset, boolean async)Write a reference to a javascript file to the response objectstatic voidwriteOpenTag(org.apache.wicket.request.Response response)static voidwriteOpenTag(org.apache.wicket.request.Response response, java.lang.String id)
-
-
-
Field Detail
-
SCRIPT_CONTENT_PREFIX
public static final java.lang.String SCRIPT_CONTENT_PREFIX
Prefix for JavaScript CDATA content. If this is changed, also update Wicket.Head.Contributor.processScript() function from wicket-ajax-jquery.js- See Also:
- Constant Field Values
-
SCRIPT_CONTENT_SUFFIX
public static final java.lang.String SCRIPT_CONTENT_SUFFIX
Suffix for JavaScript CDATA content. If this is changed, also update Wicket.Head.Contributor.processScript() function from wicket-ajax-jquery.js- See Also:
- Constant Field Values
-
SCRIPT_OPEN_TAG
public static final java.lang.String SCRIPT_OPEN_TAG
Script open tag including content prefix- See Also:
- Constant Field Values
-
SCRIPT_CLOSE_TAG
public static final java.lang.String SCRIPT_CLOSE_TAG
Script close tag including content suffix- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JavaScriptUtils
public JavaScriptUtils(org.apache.wicket.request.Response response, java.lang.String id)Construct.- Parameters:
response- The response objectid-
-
JavaScriptUtils
public JavaScriptUtils(org.apache.wicket.request.Response response)
Constructor without id for backward compatibility- Parameters:
response- The response object
-
-
Method Detail
-
escapeQuotes
public static java.lang.CharSequence escapeQuotes(java.lang.CharSequence input)
Escape single and double quotes so that they can be part of e.g. an alert call. Note: JSON values need to escape only the double quote, so this method wont help.- Parameters:
input- the JavaScript which needs to be escaped- Returns:
- Escaped version of the input
-
writeJavaScriptUrl
public static void writeJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url, java.lang.String id)Write a reference to a javascript file to the response object- Parameters:
response- The HTTP responseurl- The javascript file URLid- Unique identifier of element
-
writeJavaScriptUrl
public static void writeJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url, java.lang.String id, boolean defer, java.lang.String charset)Write a reference to a javascript file to the response object- Parameters:
response- The HTTP responseurl- The javascript file URLid- Unique identifier of elementdefer- specifies that the execution of a script should be deferred (delayed) until after the page has been loaded.charset- a non null value specifies the charset attribute of the script tag
-
writeJavaScriptUrl
public static void writeJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url, java.lang.String id, boolean defer, java.lang.String charset, boolean async)Write a reference to a javascript file to the response object- Parameters:
response- The HTTP responseurl- The javascript file URLid- Unique identifier of elementdefer- specifies that the execution of a script should be deferred (delayed) until after the page has been loaded.charset- a non null value specifies the charset attribute of the script tagasync- specifies that the script can be loaded asynchronously by the browser
-
writeJavaScriptUrl
public static void writeJavaScriptUrl(org.apache.wicket.request.Response response, java.lang.CharSequence url)Write a reference to a javascript file to the response object- Parameters:
response- The HTTP responseurl- The javascript file URL
-
writeJavaScript
public static void writeJavaScript(org.apache.wicket.request.Response response, java.lang.CharSequence text, java.lang.String id)Write the simple text to the response object surrounded by a script tag.- Parameters:
response- The HTTP: responsetext- The text to added in between the script tagsid- Unique identifier of element
-
writeJavaScript
public static void writeJavaScript(org.apache.wicket.request.Response response, java.lang.CharSequence text)Write the simple text to the response object surrounded by a script tag.- Parameters:
response- The HTTP: responsetext- The text to added in between the script tags
-
writeOpenTag
public static void writeOpenTag(org.apache.wicket.request.Response response, java.lang.String id)- Parameters:
response-id-
-
writeOpenTag
public static void writeOpenTag(org.apache.wicket.request.Response response)
- Parameters:
response-
-
writeCloseTag
public static void writeCloseTag(org.apache.wicket.request.Response response)
- Parameters:
response-
-
write
public void write(java.lang.CharSequence script)
- Parameters:
script-- See Also:
Response.write(java.lang.CharSequence)
-
println
public void println(java.lang.CharSequence script)
- Parameters:
script-- See Also:
Response.write(CharSequence)
-
close
public void close()
Write the script close tag to the response. The response output stream remains open.
-
-