GWT 2.7.0

com.google.gwt.safehtml.shared
Class SafeHtmlHostedModeUtils

java.lang.Object
  extended by com.google.gwt.safehtml.shared.SafeHtmlHostedModeUtils

public class SafeHtmlHostedModeUtils
extends java.lang.Object

SafeHtml utilities whose implementation differs between Development and Production Mode.

This class has a super-source peer that provides the Production Mode implementation.


Field Summary
static java.lang.String FORCE_CHECK_COMPLETE_HTML
          Name of system property that if set, enables checks in server-side code (even if assertions are disabled).
 
Constructor Summary
SafeHtmlHostedModeUtils()
           
 
Method Summary
static boolean isCompleteHtml(java.lang.String html)
          Returns whether the provided HTML string is complete (ends in "inner HTML" context).
static void maybeCheckCompleteHtml(java.lang.String html)
          Conditionally checks if the provided HTML string is complete (ends in "inner HTML" context).
static void setForceCheckCompleteHtml(boolean check)
          Sets a global flag that controls whether or not maybeCheckCompleteHtml(String) should perform its check in a server-side environment.
static void setForceCheckCompleteHtmlFromProperty()
          Sets a global flag that controls whether or not maybeCheckCompleteHtml(String) should perform its check in a server-side environment from the value of the "com.google.gwt.safehtml.ForceCheckCompleteHtml" property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORCE_CHECK_COMPLETE_HTML

public static final java.lang.String FORCE_CHECK_COMPLETE_HTML
Name of system property that if set, enables checks in server-side code (even if assertions are disabled).

See Also:
Constant Field Values
Constructor Detail

SafeHtmlHostedModeUtils

public SafeHtmlHostedModeUtils()
Method Detail

isCompleteHtml

public static boolean isCompleteHtml(java.lang.String html)
Returns whether the provided HTML string is complete (ends in "inner HTML" context).

This method parses the provided string as HTML and determines the HTML context at the end of the string. This method returns true if and only if the context is "inner HTML text".

For example, this method returns true for the following strings:

<foo>blah
   baz<em>foo</em> <x a="b">hello
 

This method returns false for the following strings:

baz<em>foo</em> <x
   baz<em>foo</em> <x a="b
   baz<em>foo</em> <x a="b"
 

Note that the parser is lenient and this method will return true for HTML that is not well-formed, or contains invalid tags, as long as the parser can determine the HTML context at the end of the string.

Parameters:
html - the HTML to check.
Returns:
true if the provided HTML string is complete.

maybeCheckCompleteHtml

public static void maybeCheckCompleteHtml(java.lang.String html)
Conditionally checks if the provided HTML string is complete (ends in "inner HTML" context).

This check is intended to assert a convention-of-use constraint of SafeHtmlBuilder.appendHtmlConstant(String) and SafeHtmlUtils.fromSafeConstant(String). Since the check is somewhat expensive, it is intended to run only in the context of unit-tests or test environments, and not in production environments. Hence this check will only execute under the following conditions, and will be short-circuited otherwise:

Parameters:
html - the HTML to check
See Also:
isCompleteHtml(String)

setForceCheckCompleteHtml

public static void setForceCheckCompleteHtml(boolean check)
Sets a global flag that controls whether or not maybeCheckCompleteHtml(String) should perform its check in a server-side environment.

Parameters:
check - if true, perform server-side checks.

setForceCheckCompleteHtmlFromProperty

public static void setForceCheckCompleteHtmlFromProperty()
Sets a global flag that controls whether or not maybeCheckCompleteHtml(String) should perform its check in a server-side environment from the value of the "com.google.gwt.safehtml.ForceCheckCompleteHtml" property.


GWT 2.7.0