use of org.sonar.plugins.html.node.Attribute in project sonar-web by SonarSource.
the class PageLexerTest method testAttributeWithoutQuotes.
@Test
public void testAttributeWithoutQuotes() {
final StringReader reader = new StringReader("<img src=http://foo/sfds?sjg a=1\tb=2\r\nc=3 />");
final PageLexer lexer = new PageLexer();
final List<Node> nodeList = lexer.parse(reader);
assertThat(nodeList).hasSize(1);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
final TagNode node = (TagNode) nodeList.get(0);
assertThat(node.getAttributes()).hasSize(4);
final Attribute attribute = node.getAttributes().get(0);
assertThat(attribute.getName()).isEqualTo("src");
assertThat(attribute.getValue()).isEqualTo("http://foo/sfds?sjg");
final Attribute attributeA = node.getAttributes().get(1);
assertThat(attributeA.getName()).isEqualTo("a");
assertThat(attributeA.getValue()).isEqualTo("1");
final Attribute attributeB = node.getAttributes().get(2);
assertThat(attributeB.getName()).isEqualTo("b");
assertThat(attributeB.getValue()).isEqualTo("2");
final Attribute attributeC = node.getAttributes().get(3);
assertThat(attributeC.getName()).isEqualTo("c");
assertThat(attributeC.getValue()).isEqualTo("3");
}
use of org.sonar.plugins.html.node.Attribute in project sonar-web by SonarSource.
the class PageLexerTest method attribute_value_starting_with_quote.
@Test
public void attribute_value_starting_with_quote() {
StringReader reader = new StringReader("<img src=\"'a'\"/>");
List<Node> nodeList = new PageLexer().parse(reader);
assertThat(nodeList).hasSize(1);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
TagNode node = (TagNode) nodeList.get(0);
Attribute attribute = node.getAttributes().get(0);
assertThat(attribute.getName()).isEqualTo("src");
assertThat(attribute.getValue()).isEqualTo("'a'");
}
use of org.sonar.plugins.html.node.Attribute in project sonar-web by SonarSource.
the class ElementTokenizer method parseNestedTag.
/**
* Parse a nested tag with PageLexer.
* The nested tag is added as an attribute to its parent element.
*/
private static void parseNestedTag(CodeReader codeReader, TagNode element) {
PageLexer nestedPageLexer = new PageLexer();
List<Node> nodeList = nestedPageLexer.nestedParse(codeReader);
// add the nested tags as attribute.
for (Node node : nodeList) {
element.getAttributes().add(new Attribute(node.getCode()));
}
}
use of org.sonar.plugins.html.node.Attribute in project sonar-web by SonarSource.
the class DoctypeTokenizer method parseToken.
private static void parseToken(DirectiveNode node) {
String code = node.getCode();
StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(code));
tokenizer.quoteChar('"');
try {
while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
if (tokenizer.sval != null) {
if (node.getNodeName() == null) {
node.setNodeName(tokenizer.sval);
} else {
node.getAttributes().add(new Attribute(tokenizer.sval));
}
}
}
} catch (IOException e) {
// ignore
}
}
use of org.sonar.plugins.html.node.Attribute in project sonar-web by SonarSource.
the class ElementTokenizer method handleBeforeAttributeName.
private static void handleBeforeAttributeName(CodeReader codeReader, TagNode element) {
Attribute attribute;
StringBuilder sbQName = new StringBuilder();
codeReader.popTo(endQNameMatcher, sbQName);
attribute = new Attribute(sbQName.toString().trim());
attribute.setLine(codeReader.getLinePosition() + element.getStartLinePosition() - 1);
element.getAttributes().add(attribute);
}
Aggregations