Class JavaScriptUtils
- java.lang.Object
-
- org.apache.wicket.core.util.string.JavaScriptUtils
-
public class JavaScriptUtils extends Object
Provide some helpers to write javascript related tags to the response object.- Author:
- Juergen Donnerstag
-
-
Field Summary
Fields Modifier and Type Field Description static String
ATTR_CROSS_ORIGIN
static String
ATTR_CSP_NONCE
static String
ATTR_ID
static String
ATTR_INTEGRITY
static String
ATTR_SCRIPT_ASYNC
static String
ATTR_SCRIPT_DEFER
static String
ATTR_SCRIPT_SRC
static String
ATTR_TYPE
static String
SCRIPT_CLOSE_TAG
Script close tag including content suffixstatic String
SCRIPT_CONTENT_PREFIX
Prefix for JavaScript CDATA content.static String
SCRIPT_CONTENT_SUFFIX
Suffix for JavaScript CDATA content.static String
SCRIPT_OPEN_TAG
Script open tag including content prefix
-
Constructor Summary
Constructors Constructor Description JavaScriptUtils(Response response)
Constructor without id for backward compatibilityJavaScriptUtils(Response response, String id)
Construct.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Write the inline script close tag to the response.static CharSequence
escapeQuotes(CharSequence input)
Escape single and double quotes so that they can be part of e.g.void
println(CharSequence script)
void
write(CharSequence script)
static void
writeCloseTag(Response response)
Write close script tag for inline script.static void
writeInlineScript(Response response, CharSequence text, AttributeMap attributes)
Write the simple text to the response object surrounded by a script tag.static void
writeJavaScript(Response response, CharSequence text)
Write the simple text to the response object surrounded by a script tag.static void
writeJavaScript(Response response, CharSequence text, String id)
Deprecated.please usewriteInlineScript(Response, CharSequence, AttributeMap)
insteadstatic void
writeJavaScriptUrl(Response response, CharSequence url)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadstatic void
writeJavaScriptUrl(Response response, CharSequence url, String id)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadstatic void
writeJavaScriptUrl(Response response, CharSequence url, String id, boolean defer, String charset)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadstatic void
writeJavaScriptUrl(Response response, CharSequence url, String id, boolean defer, String charset, boolean async)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadstatic void
writeOpenTag(Response response)
Deprecated.please usewriteOpenTag(Response, AttributeMap)
static void
writeOpenTag(Response response, String id)
Deprecated.please usewriteOpenTag(Response, AttributeMap)
static void
writeOpenTag(Response response, AttributeMap attributes)
Write open script tag for inline script.static void
writeScript(Response response, AttributeMap attributes)
Write a reference to a javascript file to the response object
-
-
-
Field Detail
-
SCRIPT_CONTENT_PREFIX
public static final 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 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 String SCRIPT_OPEN_TAG
Script open tag including content prefix- See Also:
- Constant Field Values
-
SCRIPT_CLOSE_TAG
public static final String SCRIPT_CLOSE_TAG
Script close tag including content suffix- See Also:
- Constant Field Values
-
ATTR_ID
public static final String ATTR_ID
- See Also:
- Constant Field Values
-
ATTR_TYPE
public static final String ATTR_TYPE
- See Also:
- Constant Field Values
-
ATTR_SCRIPT_SRC
public static final String ATTR_SCRIPT_SRC
- See Also:
- Constant Field Values
-
ATTR_SCRIPT_DEFER
public static final String ATTR_SCRIPT_DEFER
- See Also:
- Constant Field Values
-
ATTR_SCRIPT_ASYNC
public static final String ATTR_SCRIPT_ASYNC
- See Also:
- Constant Field Values
-
ATTR_CSP_NONCE
public static final String ATTR_CSP_NONCE
- See Also:
- Constant Field Values
-
ATTR_CROSS_ORIGIN
public static final String ATTR_CROSS_ORIGIN
- See Also:
- Constant Field Values
-
ATTR_INTEGRITY
public static final String ATTR_INTEGRITY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JavaScriptUtils
public JavaScriptUtils(Response response, String id)
Construct.- Parameters:
response
- The response objectid
-
-
JavaScriptUtils
public JavaScriptUtils(Response response)
Constructor without id for backward compatibility- Parameters:
response
- The response object
-
-
Method Detail
-
escapeQuotes
public static CharSequence escapeQuotes(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
@Deprecated public static void writeJavaScriptUrl(Response response, CharSequence url, String id)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadWrite a reference to a javascript file to the response object- Parameters:
response
- The HTTP responseurl
- The javascript file URLid
- Unique identifier of element
-
writeJavaScriptUrl
@Deprecated public static void writeJavaScriptUrl(Response response, CharSequence url, String id, boolean defer, String charset)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadWrite 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
@Deprecated public static void writeJavaScriptUrl(Response response, CharSequence url, String id, boolean defer, String charset, boolean async)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadWrite 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
-
writeScript
public static void writeScript(Response response, AttributeMap attributes)
Write a reference to a javascript file to the response object- Parameters:
response
- The HTTP responseattributes
- Extra tag attributes
-
writeJavaScriptUrl
@Deprecated public static void writeJavaScriptUrl(Response response, CharSequence url)
Deprecated.please usewriteScript(Response, AttributeMap)
insteadWrite a reference to a javascript file to the response object- Parameters:
response
- The HTTP responseurl
- The javascript file URL
-
writeJavaScript
public static void writeJavaScript(Response response, CharSequence text, String id)
Deprecated.please usewriteInlineScript(Response, CharSequence, AttributeMap)
insteadWrite 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
-
writeInlineScript
public static void writeInlineScript(Response response, CharSequence text, AttributeMap attributes)
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 tagsattributes
- Extra tag attributes
-
writeJavaScript
public static void writeJavaScript(Response response, 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
@Deprecated public static void writeOpenTag(Response response, String id)
Deprecated.please usewriteOpenTag(Response, AttributeMap)
- Parameters:
response
-id
-
-
writeOpenTag
public static void writeOpenTag(Response response, AttributeMap attributes)
Write open script tag for inline script. Content is prefixed withSCRIPT_CONTENT_PREFIX
.- Parameters:
response
- the response to write toattributes
- Tag attributes map
-
writeOpenTag
@Deprecated public static void writeOpenTag(Response response)
Deprecated.please usewriteOpenTag(Response, AttributeMap)
- Parameters:
response
-
-
writeCloseTag
public static void writeCloseTag(Response response)
Write close script tag for inline script. The close tag is prefixed withSCRIPT_CONTENT_SUFFIX
- Parameters:
response
- the response to write to
-
write
public void write(CharSequence script)
- Parameters:
script
-- See Also:
Response.write(java.lang.CharSequence)
-
println
public void println(CharSequence script)
- Parameters:
script
-- See Also:
Response.write(CharSequence)
-
close
public void close()
Write the inline script close tag to the response. The response output stream remains open. CallswriteCloseTag(Response)
internally. The close tag is prefixed withSCRIPT_CONTENT_SUFFIX
.
-
-