use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class ElementTokenizer method parseToken.
private void parseToken(Node node) {
TagNode element = (TagNode) node;
CodeReader codeReader = new CodeReader(node.getCode());
ParseMode mode = ParseMode.BEFORE_NODE_NAME;
for (int ch = codeReader.peek(); ch != -1; ch = codeReader.peek()) {
// handle white space
if (Character.isWhitespace(ch)) {
codeReader.pop();
continue;
}
// handle special characters
switch(ch) {
case '=':
mode = ParseMode.BEFORE_ATTRIBUTE_VALUE;
codeReader.pop();
continue;
case '<':
nestedTag(element, codeReader, mode);
continue;
case '>':
case '/':
case '%':
case '@':
codeReader.pop();
continue;
default:
break;
}
mode = parseToken(mode, codeReader, element);
}
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class TableHeaderHasIdOrScopeCheck method visitTrNode.
private void visitTrNode(TagNode node) {
List<TagNode> row = node.getChildren();
if (!tables.isEmpty() && !row.isEmpty()) {
TableElement currentTable = tables.peek();
for (TagNode element : row) {
if (isThTag(element)) {
currentTable.headers.add(element);
}
}
currentTable.firstCol.add(row.get(0));
if (currentTable.firstRow.isEmpty()) {
currentTable.firstRow = row;
}
} else {
// Sometimes rows are defined in separate files, and at this point we don't see them as part of a current table.
// In this case we treat them as belonging to "not simple tables".
raiseIssueOnTableHeadersWithoutScopeOrId(row);
}
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method testLexer.
@Test
public void testLexer() throws FileNotFoundException {
String fileName = "src/test/resources/src/main/webapp/create-salesorder.xhtml";
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(new FileReader(fileName));
assertThat(nodeList.size()).isGreaterThan(50);
// check tagnodes
for (Node node : nodeList) {
if (node instanceof TagNode) {
assertThat(node.getCode()).startsWith("<");
assertThat(node.getCode()).endsWith(">");
}
}
showHierarchy(nodeList);
// check hierarchy
for (Node node : nodeList) {
if (node instanceof TagNode) {
TagNode tagNode = (TagNode) node;
if (!tagNode.isEndElement()) {
if (tagNode.equalsElementName("define")) {
assertThat(tagNode.getChildren()).as("Tag should have children: " + tagNode.getCode()).isNotEmpty();
} else if (tagNode.equalsElementName("outputText")) {
assertThat(tagNode.getChildren()).isEmpty();
}
}
}
}
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method testNestedTagInValue.
@Test
public void testNestedTagInValue() {
String fragment = "<td label=\"Hello <c:if test='${param == true}'>World</c:if>\">Type</td>";
StringReader reader = new StringReader(fragment);
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(reader);
assertThat(nodeList).hasSize(3);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
assertThat(nodeList.get(1)).isInstanceOf(TextNode.class);
assertThat(nodeList.get(2)).isInstanceOf(TagNode.class);
TagNode tagNode = (TagNode) nodeList.get(0);
assertThat(tagNode.getAttributes()).hasSize(1);
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method showHierarchy.
private void showHierarchy(List<Node> nodeList) {
StringBuilder sb = new StringBuilder();
for (Node node : nodeList) {
if (node.getClass() == TagNode.class && ((TagNode) node).getParent() == null) {
TagNode root = (TagNode) node;
printTag(sb, root, 0);
// System.out.print(sb.toString());
}
}
}
Aggregations