public final boolean isValidEndContextForContentKind ( SanitizedContentKind contentKind ) { if ( templateNestDepth != 0 ) { return false ; } switch ( contentKind ) { case CSS : return state == HtmlContext . CSS && elType == ElementType . NONE ; case HTML : return state == HtmlContext . HTML_PCDATA && elType == ElementType . NONE ; case ATTRIBUTES : // Allow any html attribute context or html tag this. HTML_TAG is needed for constructs // like "checked" that don't require an attribute value. Explicitly disallow // HTML_NORMAL_ATTR_VALUE (e.g. foo={$x} without quotes) to help catch cases where // attributes aren't safely composable (e.g. foo={$x}checked would end up with one long // attribute value, whereas foo="{$x}"checked would be parsed as intended). return state == HtmlContext . HTML_ATTRIBUTE_NAME || state == HtmlContext . HTML_TAG ; case JS : // Just ensure the state is JS -- don't worry about whether a regex is coming or not. return state == HtmlContext . JS && elType == ElementType . NONE ; case URI : // Ensure that the URI content is non-empty and the URI type remains normal (which is // the assumed type of the URI content kind). return state == HtmlContext . URI && uriType == UriType . NORMAL && uriPart != UriPart . START ; case TEXT : return state == HtmlContext . TEXT ; case TRUSTED_RESOURCE_URI : // Ensure that the URI content is non-empty and the URI type remains normal (which is // the assumed type of the URI content kind). return state == HtmlContext . URI && uriType == UriType . TRUSTED_RESOURCE && uriPart != UriPart . START ; } throw new IllegalArgumentException ( "Specified content kind " + contentKind + " has no associated end context." ) ; }
Determines whether a particular context is valid for the end of a block of a particular content kind .