use of org.sonar.plugins.web.node.Attribute in project sonar-web by SonarSource.
the class DeprecatedAttributesInHtml5Check method startElement.
@Override
public void startElement(TagNode element) {
String elementName = element.getNodeName().toLowerCase();
Set<String> deprecatedAttributes = DEPRECATED.get(elementName);
if (deprecatedAttributes != null) {
List<Attribute> attributes = element.getAttributes();
for (Attribute attribute : attributes) {
if (isDeprecated(element, deprecatedAttributes, attribute.getName().toLowerCase(), attribute.getValue().toLowerCase())) {
createViolation(element.getStartLinePosition(), "Remove this deprecated \"" + attribute.getName() + "\" attribute.");
}
}
}
}
use of org.sonar.plugins.web.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.web.node.Attribute in project sonar-web by SonarSource.
the class ElementTokenizer method handleBeforeAttributeValue.
private static void handleBeforeAttributeValue(CodeReader codeReader, TagNode element) {
Attribute attribute;
if (!element.getAttributes().isEmpty()) {
attribute = element.getAttributes().get(element.getAttributes().size() - 1);
StringBuilder sbValue = new StringBuilder();
int ch = codeReader.peek();
if (isQuote((char) ch)) {
codeReader.pop();
if (codeReader.peek() != ch) {
codeReader.popTo(new QuoteMatcher((char) ch), sbValue);
attribute.setValue(unescapeQuotes(sbValue.toString(), (char) ch));
}
codeReader.pop();
attribute.setQuoteChar((char) ch);
} else {
codeReader.popTo(endUnquotedAttributeMatcher, sbValue);
attribute.setValue(sbValue.toString().trim());
}
}
}
use of org.sonar.plugins.web.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.web.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);
assertEquals(1, nodeList.size());
assertTrue(nodeList.get(0) instanceof TagNode);
final TagNode node = (TagNode) nodeList.get(0);
assertEquals(4, node.getAttributes().size());
final Attribute attribute = node.getAttributes().get(0);
assertEquals("src", attribute.getName());
assertEquals("http://foo/sfds?sjg", attribute.getValue());
final Attribute attributeA = node.getAttributes().get(1);
assertEquals("a", attributeA.getName());
assertEquals("1", attributeA.getValue());
final Attribute attributeB = node.getAttributes().get(2);
assertEquals("b", attributeB.getName());
assertEquals("2", attributeB.getValue());
final Attribute attributeC = node.getAttributes().get(3);
assertEquals("c", attributeC.getName());
assertEquals("3", attributeC.getValue());
}
Aggregations