Author: akazakov
Date: 2012-01-18 20:33:40 -0500 (Wed, 18 Jan 2012)
New Revision: 37963
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/XHTMLDetector.java
Log:
https://issues.jboss.org/browse/JBIDE-10472 CLONE - XHTML Validator hangs eclipse
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/XHTMLDetector.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/XHTMLDetector.java 2012-01-19
00:53:49 UTC (rev 37962)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/XHTMLDetector.java 2012-01-19
01:33:40 UTC (rev 37963)
@@ -26,33 +26,22 @@
*
*/
class XHTMLDetector extends TextScanner {
-
- private static final String XML_DECLARATION_START = "<?";
- private static final String XML_DECLARATION_END = "?>";
- private static final String XML_DECLARATION = "xml";
-
+
private static final String DOCTYPE_DECLARATION = "DOCTYPE";
- private static final String DOCTYPE_DECLARATION_END = ">";
- private static final String VALID_DOCTYPE_ROOT = "html";
private static final String[] VALID_DOCTYPE_DTD_DECLARATION_REQUIRED_TOKENS = {
"W3C", "DTD", "XHTML"};
private static final String[] VALID_DOCTYPE_DTD_DECLARATION_ONE_OF_TOKENS = {
"Strict", "Transitional", "Frameset"};
- private static final String[] VALID_DOCTYPE_DTD_DECLARATION_REQUIRED_SYSTEM_IDS = {
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd",
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"
- };
private static final String VALID_ELEMENT_XMLNS_ATTRIBUTE = "xmlns";
private static final String VALID_ELEMENT_XMLNS_ATTRIBUTE_VALUE =
"http://www.w3.org/1999/xhtml";
-
+
private static final String TEXT_TOKEN = "___TEXT_TOKEN";
private static final String COMMENT_TOKEN = "___COMMENT_TOKEN";
private static final String XML_DECL_TOKEN = "___XML_DECL_TOKEN";
private static final String DECL_TOKEN = "___DECL_TOKEN";
private static final String ELEMENT_TOKEN = "___ELEMENT_TOKEN";
-
+
private static final String PUBLIC = "PUBLIC";
private static final String SYSTEM = "SYSTEM";
-
+
public XHTMLDetector(Reader reader) {
super(reader);
}
@@ -65,8 +54,7 @@
String docTypeRootName = null;
String docTypeIdKind = null;
String docTypePublicId = null;
- String docTypeSystemId = null;
-
+
for (IToken t = nextToken(); t != null && !t.isEOF() ; t = nextToken()) {
if (!(t instanceof TextToken))
continue;
@@ -77,8 +65,7 @@
docTypeRootName = rootName;
docTypeIdKind = idKind;
docTypePublicId = publicId;
- docTypeSystemId = systemId;
-
+
// if (!VALID_DOCTYPE_ROOT.equals(docTypeRootName))
// return false;
if (!PUBLIC.equals(docTypeIdKind))
@@ -102,12 +89,12 @@
return false;
String name = elementName.substring(elementName.indexOf(':') + 1); // Cut
the prefix off
-
- if (!docTypeRootName.equals(name))
+
+ if (!name.equals(docTypeRootName))
return false;
if (!elementAttributes.containsKey(VALID_ELEMENT_XMLNS_ATTRIBUTE))
return false;
-
+
String value = elementAttributes.get(VALID_ELEMENT_XMLNS_ATTRIBUTE);
if (value == null) return false;
if
(!VALID_ELEMENT_XMLNS_ATTRIBUTE_VALUE.equals(Utils.trimQuotes(value).toLowerCase()))
@@ -129,7 +116,7 @@
}
return false;
}
-
+
private boolean hasAllTokens(String publicId, String[] reqiured) {
if (publicId == null) return false;
for (String r : reqiured) {
@@ -143,6 +130,7 @@
}
return true;
}
+
private boolean hasOneOfTokens(String publicId, String[] oneOf) {
if (publicId == null) return false;
boolean found = false;
@@ -170,16 +158,16 @@
private static final int STATE_END = 5;
private int state;
-
+
private String declName;
private String rootName;
private String idKind;
private String publicId;
private String systemId;
-
+
private String elementName;
private Map<String, String> elementAttributes = new HashMap<String,
String>();
-
+
/* (non-Javadoc)
* @see org.jboss.tools.jsf.text.ext.util.TextScanner#nextToken()
*/
@@ -245,7 +233,7 @@
state = STATE_END;
return getToken(TEXT_TOKEN);
}
-
+
private IToken nextCommentToken() {
int count = skip(3); // Skip '<!--' chars
if (count < 3) {
@@ -276,7 +264,7 @@
state = STATE_END;
return getToken(COMMENT_TOKEN);
}
-
+
private IToken nextXmlDeclToken() {
int count = skip(2); // Skip '<?' chars
if (count < 2) {
@@ -290,7 +278,7 @@
ch = read();
continue;
}
-
+
if (ch == '?') {
ch = read();
if (ch == ICharacterScanner.EOF) {
@@ -307,15 +295,14 @@
state = STATE_END;
return getToken(XML_DECL_TOKEN);
}
-
-
+
private IToken nextDeclToken() {
int count = skip(2); // Skip '<' chars
if (count < 2) {
state = STATE_END;
return getToken(DECL_TOKEN);
}
-
+
// Read declaration name (we're very expecting to see 'DOCTYPE' here)
declName = readName();
if (declName == null || declName.length() == 0) {
@@ -323,7 +310,7 @@
return getToken(DECL_TOKEN);
}
count += declName.length();
-
+
// At least one WS-char is expected here
int wsCount = skipWhitespaceToken();
if (wsCount == 0) {
@@ -331,7 +318,7 @@
return getToken(DECL_TOKEN);
}
count += wsCount;
-
+
// Read root element name here (
http://www.w3.org/TR/xhtml1/#strict says that
'html' is strictly expected here)
rootName = readName();
if (declName == null || declName.length() == 0) {
@@ -339,7 +326,7 @@
return getToken(DECL_TOKEN);
}
count += declName.length();
-
+
// At least one WS-char is expected here
wsCount = skipWhitespaceToken();
if (wsCount == 0) {
@@ -347,7 +334,7 @@
return getToken(DECL_TOKEN);
}
count += wsCount;
-
+
// Read 'PUBLIC' or 'SYSTEM' word here
idKind = readName();
if (declName == null || declName.length() == 0) {
@@ -355,7 +342,7 @@
return getToken(DECL_TOKEN);
}
count += declName.length();
-
+
// At least one WS-char is expected here
wsCount = skipWhitespaceToken();
if (wsCount == 0) {
@@ -373,7 +360,7 @@
if (PUBLIC.equals(idKind)) {
publicId = readLiteralValue();
count += publicId.length();
-
+
// At least one WS-char is expected here
wsCount = skipWhitespaceToken();
if (wsCount == 0) {
@@ -382,11 +369,11 @@
}
count += wsCount;
}
-
+
// Read SYSTEM ID value
systemId = readLiteralValue();
count += systemId.length();
-
+
// Expecting end of declaration, so don't check count of WS-chars
count += skipWhitespaceToken();
count += wsCount;
@@ -416,17 +403,17 @@
} else {
count++;
}
-
+
// Read tag name (the tag that is interesting for us is 'html', but it could be
any tag)
elementName = readName();
elementAttributes.clear();
-
+
if (elementName == null || elementName.length() == 0) {
state = STATE_END;
return getToken(ELEMENT_TOKEN);
}
count += elementName.length();
-
+
ch = read(); // Check that the next char exists
while (ch != ICharacterScanner.EOF) {
@@ -435,7 +422,7 @@
return getToken(ELEMENT_TOKEN);
}
unread();
-
+
int wsCount = skipWhitespaceToken();
count += wsCount;
// Check for end of tag:
@@ -465,7 +452,7 @@
}
count += attrName.length();
count += skipWhitespaceToken();
-
+
// read eq sign
ch = read();
if (ch != '=') {
@@ -478,33 +465,32 @@
// read attr value
String attrValue = readLiteralValue();
count += attrValue.length();
-
+
elementAttributes.put(attrName, attrValue);
}
- //
ch = read();
}
-
+
state = STATE_END;
return getToken(ELEMENT_TOKEN);
}
-
+
int skip(int count) {
int skipped = 0;
for (;skipped < count && read() != -1;skipped++) ;
return skipped;
}
-
+
public int skipLiteralToken(int quote) {
int count = 0;
for (int ch = read(); ch != -1 && ch != quote; ch = read()) count++;
return count;
}
-
+
String readLiteralValue() {
StringBuffer sb = new StringBuffer();
-
+
int quote = read();
if (quote != '"' && quote != '\'') {
unread();
@@ -517,7 +503,7 @@
sb.append((char)ch);
return sb.toString();
}
-
+
String readName() {
StringBuffer sb = new StringBuffer();
@@ -530,7 +516,7 @@
return null;
}
sb.append((char)ch);
-
+
ch = read();
while (ch != ICharacterScanner.EOF) {
if (!NMTOKEN_DETECTOR.isWordPart((char)ch)) {
@@ -542,4 +528,4 @@
}
return sb.toString();
}
-}
+}
\ No newline at end of file