in wicket-core/src/main/java/org/apache/wicket/markup/parser/XmlPullParser.java [334:460]
protected void specialTagHandling(String tagText, final int openBracketIndex,
int closeBracketIndex) throws ParseException
{
// Handle comments
if (tagText.startsWith("!--"))
{
// downlevel-revealed conditional comments e.g.: <!--[if (gt IE9)|!(IE)]><!-->
if (tagText.contains("![endif]--"))
{
lastType = HttpTagType.CONDITIONAL_COMMENT_ENDIF;
// Move to position after the tag
input.setPosition(closeBracketIndex + 1);
return;
}
// Conditional comment? E.g.
// "<!--[if IE]><a href='test.html'>my link</a><![endif]-->"
if (tagText.startsWith("!--[if ") && tagText.endsWith("]"))
{
int pos = input.find("]-->", openBracketIndex + 1);
if (pos == -1)
{
throw new ParseException("Unclosed conditional comment beginning at" +
getLineAndColumnText(), openBracketIndex);
}
pos += 4;
lastText = input.getSubstring(openBracketIndex, pos);
// Actually it is no longer a comment. It is now
// up to the browser to select the section appropriate.
input.setPosition(closeBracketIndex + 1);
lastType = HttpTagType.CONDITIONAL_COMMENT;
}
else
{
// Normal comment section.
// Skip ahead to "-->". Note that you can not simply test for
// tagText.endsWith("--") as the comment might contain a '>'
// inside.
int pos = input.find("-->", openBracketIndex + 1);
if (pos == -1)
{
throw new ParseException("Unclosed comment beginning at" +
getLineAndColumnText(), openBracketIndex);
}
pos += 3;
lastText = input.getSubstring(openBracketIndex, pos);
lastType = HttpTagType.COMMENT;
input.setPosition(pos);
}
return;
}
// The closing tag of a conditional comment, e.g.
// "<!--[if IE]><a href='test.html'>my link</a><![endif]-->
// and also <!--<![endif]-->"
if (tagText.equals("![endif]--"))
{
lastType = HttpTagType.CONDITIONAL_COMMENT_ENDIF;
input.setPosition(closeBracketIndex + 1);
return;
}
// CDATA sections might contain "<" which is not part of an XML tag.
// Make sure escaped "<" are treated right
if (tagText.startsWith("!["))
{
final String startText = (tagText.length() <= 8 ? tagText : tagText.substring(0, 8));
if (startText.toUpperCase(Locale.ROOT).equals("![CDATA["))
{
int pos1 = openBracketIndex;
do
{
// Get index of closing tag and advance past the tag
closeBracketIndex = findChar('>', pos1);
if (closeBracketIndex == -1)
{
throw new ParseException("No matching close bracket at" +
getLineAndColumnText(), input.getPosition());
}
// Get the tagtext between open and close brackets
tagText = input.getSubstring(openBracketIndex + 1, closeBracketIndex)
.toString();
pos1 = closeBracketIndex + 1;
}
while (tagText.endsWith("]]") == false);
// Move to position after the tag
input.setPosition(closeBracketIndex + 1);
lastText = tagText;
lastType = HttpTagType.CDATA;
return;
}
}
if (tagText.charAt(0) == '?')
{
lastType = HttpTagType.PROCESSING_INSTRUCTION;
// Move to position after the tag
input.setPosition(closeBracketIndex + 1);
return;
}
if (tagText.startsWith("!DOCTYPE"))
{
lastType = HttpTagType.DOCTYPE;
// Get the tagtext between open and close brackets
doctype = input.getSubstring(openBracketIndex + 1, closeBracketIndex);
// Move to position after the tag
input.setPosition(closeBracketIndex + 1);
return;
}
// Move to position after the tag
lastType = HttpTagType.SPECIAL_TAG;
input.setPosition(closeBracketIndex + 1);
}