|
1 |
| package net.sourceforge.pmd.jsp.rules; |
|
2 |
| |
|
3 |
| import java.util.Set; |
|
4 |
| |
|
5 |
| import net.sourceforge.pmd.jsp.ast.ASTAttribute; |
|
6 |
| import net.sourceforge.pmd.jsp.ast.ASTElement; |
|
7 |
| import net.sourceforge.pmd.util.CollectionUtil; |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| public class NoInlineStyleInformation extends AbstractJspRule { |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| private static final Set STYLE_ELEMENT_NAMES = CollectionUtil.asSet( |
|
23 |
| new String[]{"B", "I", "FONT", "BASEFONT", "U", "CENTER"} |
|
24 |
| ); |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| private static final Set ELEMENT_NAMES_THAT_CAN_HAVE_STYLE_ATTRIBUTES = CollectionUtil.asSet( |
|
30 |
| new String[]{"P", "TABLE", "THEAD", "TBODY", "TFOOT", "TR", "TD", "COL", "COLGROUP"} |
|
31 |
| ); |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| private static final Set STYLE_ATTRIBUTES = CollectionUtil.asSet( |
|
38 |
| new String[]{"STYLE", "FONT", "SIZE", "COLOR", "FACE", "ALIGN", "VALIGN", "BGCOLOR"} |
|
39 |
| ); |
|
40 |
| |
|
41 |
3
| public Object visit(ASTAttribute node, Object data) {
|
|
42 |
3
| if (isStyleAttribute(node)) {
|
|
43 |
2
| addViolation(data, node);
|
|
44 |
| } |
|
45 |
| |
|
46 |
3
| return super.visit(node, data);
|
|
47 |
| } |
|
48 |
| |
|
49 |
9
| public Object visit(ASTElement node, Object data) {
|
|
50 |
9
| if (isStyleElement(node)) {
|
|
51 |
1
| addViolation(data, node);
|
|
52 |
| } |
|
53 |
| |
|
54 |
9
| return super.visit(node, data);
|
|
55 |
| } |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
9
| private boolean isStyleElement(ASTElement elementNode) {
|
|
64 |
9
| return STYLE_ELEMENT_NAMES.contains(elementNode.getName().toUpperCase());
|
|
65 |
| } |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
3
| private boolean isStyleAttribute(ASTAttribute attributeNode) {
|
|
75 |
3
| if (STYLE_ATTRIBUTES.contains(attributeNode.getName().toUpperCase())) {
|
|
76 |
2
| if (attributeNode.jjtGetParent() instanceof ASTElement) {
|
|
77 |
2
| ASTElement parent = (ASTElement) attributeNode.jjtGetParent();
|
|
78 |
2
| if (ELEMENT_NAMES_THAT_CAN_HAVE_STYLE_ATTRIBUTES.contains(parent
|
|
79 |
| .getName().toUpperCase())) { |
|
80 |
2
| return true;
|
|
81 |
| } |
|
82 |
| } |
|
83 |
| } |
|
84 |
| |
|
85 |
1
| return false;
|
|
86 |
| } |
|
87 |
| } |