Search in sources :

Example 6 with Attribute

use of org.sonar.plugins.html.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) {
                QuoteMatcher quoteMatcher = new QuoteMatcher((char) ch);
                quoteMatcher.match(codeReader.peek());
                codeReader.popTo(quoteMatcher, sbValue);
                attribute.setValue(unescapeQuotes(sbValue.toString(), (char) ch));
            }
            codeReader.pop();
            attribute.setQuoteChar((char) ch);
        } else {
            codeReader.popTo(endUnquotedAttributeMatcher, sbValue);
            attribute.setValue(sbValue.toString().trim());
        }
    }
}
Also used : Attribute(org.sonar.plugins.html.node.Attribute)

Example 7 with Attribute

use of org.sonar.plugins.html.node.Attribute in project sonar-web by SonarSource.

the class DeprecatedAttributesInHtml5Check method startElement.

@Override
public void startElement(TagNode element) {
    String nodeName = element.getNodeName();
    String elementName = nodeName.toLowerCase(Locale.ROOT);
    Set<String> deprecatedAttributes = DEPRECATED.get(elementName);
    if (deprecatedAttributes != null) {
        List<Attribute> attributes = element.getAttributes();
        for (Attribute attribute : attributes) {
            if (isDeprecated(element, deprecatedAttributes, getOriginalAttributeName(attribute.getName()), attribute.getValue().toLowerCase(Locale.ROOT))) {
                createViolation(element, "Remove this deprecated \"" + attribute.getName() + "\" attribute.");
            }
        }
    }
}
Also used : Attribute(org.sonar.plugins.html.node.Attribute)

Aggregations

Attribute (org.sonar.plugins.html.node.Attribute)7 StringReader (java.io.StringReader)3 Node (org.sonar.plugins.html.node.Node)3 TagNode (org.sonar.plugins.html.node.TagNode)3 Test (org.junit.Test)2 CommentNode (org.sonar.plugins.html.node.CommentNode)2 DirectiveNode (org.sonar.plugins.html.node.DirectiveNode)2 TextNode (org.sonar.plugins.html.node.TextNode)2 IOException (java.io.IOException)1 StreamTokenizer (java.io.StreamTokenizer)1