Commit 3f57bf21ffc0b1a5e5da1bb955f116a19a8d259f
1 parent
1929243e
Exists in
master
Mudanças na regra de negócio 2.2.1 e adicionada regra 2.2.6
Showing
2 changed files
with
426 additions
and
355 deletions
Show diff stats
src/main/java/br/com/checker/emag/AvaliadorContraste.java
... | ... | @@ -35,34 +35,33 @@ public class AvaliadorContraste { |
35 | 35 | private final double potenciaSrgb = 2.4; |
36 | 36 | |
37 | 37 | /** |
38 | - * Construtor padrão que seta as cores do avaliador como | |
39 | - * banca e branca para caso se chame o método avaliar não ocorra | |
40 | - * nenhuma Exception. | |
41 | - */ | |
38 | + * Construtor padrão que seta as cores do avaliador como banca e branca para caso se chame o | |
39 | + * método avaliar não ocorra nenhuma Exception. | |
40 | + */ | |
42 | 41 | public AvaliadorContraste() { |
43 | 42 | this.setCores(Color.WHITE, Color.WHITE); |
44 | 43 | } |
45 | 44 | |
46 | 45 | /** |
47 | - * Construtor para passar as cores que se deseja avaliar. | |
48 | - * @param cor1 Cor a ser avaliada | |
49 | - * @param cor2 Cor a ser avaliada | |
50 | - */ | |
46 | + * Construtor para passar as cores que se deseja avaliar. | |
47 | + * | |
48 | + * @param cor1 Cor a ser avaliada | |
49 | + * @param cor2 Cor a ser avaliada | |
50 | + */ | |
51 | 51 | public AvaliadorContraste(final Color cor1, final Color cor2) { |
52 | 52 | this.setCores(cor1, cor2); |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * Seta as cores que serão avaliadas. | |
57 | - * @param cor1 Cor a ser avaliada | |
58 | - * @param cor2 Cor a ser avaliada | |
59 | - */ | |
56 | + * Seta as cores que serão avaliadas. | |
57 | + * | |
58 | + * @param cor1 Cor a ser avaliada | |
59 | + * @param cor2 Cor a ser avaliada | |
60 | + */ | |
60 | 61 | public final void setCores(final Color cor1, final Color cor2) { |
61 | 62 | if (cor1 != null && cor2 != null) { |
62 | - int cor1Soma = cor1.getRed() + cor1.getGreen() | |
63 | - + cor1.getBlue(); | |
64 | - int cor2Soma = cor2.getRed() + cor2.getGreen() | |
65 | - + cor2.getBlue(); | |
63 | + int cor1Soma = cor1.getRed() + cor1.getGreen() + cor1.getBlue(); | |
64 | + int cor2Soma = cor2.getRed() + cor2.getGreen() + cor2.getBlue(); | |
66 | 65 | if (cor1Soma >= cor2Soma) { |
67 | 66 | this.corMaisClara = cor1; |
68 | 67 | this.corMaisEscura = cor2; |
... | ... | @@ -74,24 +73,24 @@ public class AvaliadorContraste { |
74 | 73 | } |
75 | 74 | |
76 | 75 | /** |
77 | - * Método que calcula e armazena o contraste das cores avaliadas | |
78 | - * no atributo 'constraste'. | |
79 | - */ | |
76 | + * Método que calcula e armazena o contraste das cores avaliadas no atributo 'constraste'. | |
77 | + */ | |
80 | 78 | public final void avaliar() { |
81 | 79 | double luminecencia1; |
82 | 80 | double luminecencia2; |
83 | 81 | |
84 | 82 | luminecencia1 = calcularLuminecencia(this.corMaisClara); |
85 | 83 | luminecencia2 = calcularLuminecencia(this.corMaisEscura); |
86 | - this.contraste = (luminecencia1 + this.fatorDeLuminosidade) | |
87 | - / (luminecencia2 + fatorDeLuminosidade); | |
84 | + this.contraste = | |
85 | + (luminecencia1 + this.fatorDeLuminosidade) / (luminecencia2 + fatorDeLuminosidade); | |
88 | 86 | } |
89 | 87 | |
90 | 88 | /** |
91 | - * Método para calcular a luminecência de uma cor. | |
92 | - * @param cor para ser calculado a luminecência. | |
93 | - * @return luminecencia da cor | |
94 | - */ | |
89 | + * Método para calcular a luminecência de uma cor. | |
90 | + * | |
91 | + * @param cor para ser calculado a luminecência. | |
92 | + * @return luminecencia da cor | |
93 | + */ | |
95 | 94 | private double calcularLuminecencia(final Color cor) { |
96 | 95 | double red; |
97 | 96 | double green; |
... | ... | @@ -107,45 +106,47 @@ public class AvaliadorContraste { |
107 | 106 | if (redsrgb <= this.limiteSrgb) { |
108 | 107 | red = redsrgb / this.divisoredsrgb; |
109 | 108 | } else { |
110 | - red = Math.pow(((redsrgb + this.fatorDeCorrecaoSrgb) | |
111 | - / this.divisorAlternativoSrgb), this.potenciaSrgb); | |
109 | + red = | |
110 | + Math.pow(((redsrgb + this.fatorDeCorrecaoSrgb) / this.divisorAlternativoSrgb), | |
111 | + this.potenciaSrgb); | |
112 | 112 | } |
113 | 113 | |
114 | 114 | if (greensrgb <= this.limiteSrgb) { |
115 | 115 | green = greensrgb / this.divisoredsrgb; |
116 | 116 | } else { |
117 | - green = Math.pow(((greensrgb + this.fatorDeCorrecaoSrgb) | |
118 | - / this.divisorAlternativoSrgb), this.potenciaSrgb); | |
117 | + green = | |
118 | + Math.pow(((greensrgb + this.fatorDeCorrecaoSrgb) / this.divisorAlternativoSrgb), | |
119 | + this.potenciaSrgb); | |
119 | 120 | } |
120 | 121 | |
121 | 122 | if (bluesrgb <= this.limiteSrgb) { |
122 | 123 | blue = bluesrgb / this.divisoredsrgb; |
123 | 124 | } else { |
124 | - blue = Math.pow(((bluesrgb + this.fatorDeCorrecaoSrgb) | |
125 | - / this.divisorAlternativoSrgb), this.potenciaSrgb); | |
125 | + blue = | |
126 | + Math.pow(((bluesrgb + this.fatorDeCorrecaoSrgb) / this.divisorAlternativoSrgb), | |
127 | + this.potenciaSrgb); | |
126 | 128 | } |
127 | 129 | |
128 | - return (red * this.multiplicadorDoVermelho) | |
129 | - + (green * this.multiplicadorDoVerde) | |
130 | + return (red * this.multiplicadorDoVermelho) + (green * this.multiplicadorDoVerde) | |
130 | 131 | + (blue * this.multiplicadorDoAzul); |
131 | 132 | } |
132 | 133 | |
133 | 134 | /** |
134 | - * Metodo que retorna o valor armazenado no atributo 'contraste'. | |
135 | - * @return contraste | |
136 | - */ | |
135 | + * Metodo que retorna o valor armazenado no atributo 'contraste'. | |
136 | + * | |
137 | + * @return contraste | |
138 | + */ | |
137 | 139 | public final double getContraste() { |
138 | 140 | return this.contraste; |
139 | 141 | } |
140 | 142 | |
141 | 143 | /** |
142 | - * Método que retorna o valor armazenado no atributo 'contraste' | |
143 | - * devidamente formatado. | |
144 | - * @return contrasteFormatado | |
145 | - */ | |
144 | + * Método que retorna o valor armazenado no atributo 'contraste' devidamente formatado. | |
145 | + * | |
146 | + * @return contrasteFormatado | |
147 | + */ | |
146 | 148 | public final String getContrasteFormatado() { |
147 | - String strContraste = String.valueOf(new DecimalFormat("#.##") | |
148 | - .format(this.contraste)); | |
149 | + String strContraste = String.valueOf(new DecimalFormat("#.##").format(this.contraste)); | |
149 | 150 | return strContraste.replace(".", ","); |
150 | 151 | } |
151 | 152 | } | ... | ... |
src/main/java/br/com/checker/emag/core/BehaviorEvaluation.java
... | ... | @@ -11,344 +11,414 @@ import br.com.checker.emag.Occurrence; |
11 | 11 | import br.com.checker.emag.OccurrenceClassification; |
12 | 12 | import br.com.checker.emag.core.SpecificRecommendation.BehaviorRecommendation; |
13 | 13 | |
14 | -public class BehaviorEvaluation extends Evaluation{ | |
15 | - | |
16 | - | |
17 | - private BehaviorEvaluation(Source document) { super(document); } | |
18 | - | |
19 | - public static class BehaviorEvaluationBuilder extends EvaluationBuilder { | |
20 | - | |
21 | - @Override | |
22 | - protected BehaviorEvaluation with(Source document) { return new BehaviorEvaluation(document); } | |
23 | - | |
24 | - @Override | |
25 | - protected BehaviorEvaluation with(Source document,String url) { return new BehaviorEvaluation(document); } | |
26 | - | |
27 | - public SpecificRecommendation recommendation10() { return new EvaluationRecommendation10();} | |
28 | - public SpecificRecommendation recommendation11() { return new EvaluationRecommendation11();} | |
29 | - public SpecificRecommendation recommendation12() { return new EvaluationRecommendation12();} | |
30 | - public SpecificRecommendation recommendation13() { return new EvaluationRecommendation13();} | |
31 | - public SpecificRecommendation recommendation14() { return new EvaluationRecommendation14();} | |
32 | - public SpecificRecommendation recommendation15() { return new EvaluationRecommendation15();} | |
33 | - public SpecificRecommendation recommendation16() { return new EvaluationRecommendation16();} | |
14 | +public class BehaviorEvaluation extends Evaluation { | |
15 | + | |
16 | + | |
17 | + private BehaviorEvaluation(Source document) { | |
18 | + super(document); | |
19 | + } | |
20 | + | |
21 | + public static class BehaviorEvaluationBuilder extends EvaluationBuilder { | |
22 | + | |
23 | + @Override | |
24 | + protected BehaviorEvaluation with(Source document) { | |
25 | + return new BehaviorEvaluation(document); | |
34 | 26 | } |
35 | - | |
36 | - protected static class EvaluationRecommendation10 extends BehaviorRecommendation{ | |
37 | - protected List<Occurrence> check() { return getEvaluation().checkRecommendation10();} | |
27 | + | |
28 | + @Override | |
29 | + protected BehaviorEvaluation with(Source document, String url) { | |
30 | + return new BehaviorEvaluation(document); | |
38 | 31 | } |
39 | - | |
40 | - protected static class EvaluationRecommendation11 extends BehaviorRecommendation{ | |
41 | - protected List<Occurrence> check() { return getEvaluation().checkRecommendation11();} | |
32 | + | |
33 | + public SpecificRecommendation recommendation10() { | |
34 | + return new EvaluationRecommendation10(); | |
42 | 35 | } |
43 | - | |
44 | - protected static class EvaluationRecommendation12 extends BehaviorRecommendation{ | |
45 | - protected List<Occurrence> check() { return getEvaluation().checkRecommendation12();} | |
36 | + | |
37 | + public SpecificRecommendation recommendation11() { | |
38 | + return new EvaluationRecommendation11(); | |
46 | 39 | } |
47 | - | |
48 | - protected static class EvaluationRecommendation13 extends BehaviorRecommendation{ | |
49 | - protected List<Occurrence> check() { return getEvaluation().checkRecommendation13();} | |
40 | + | |
41 | + public SpecificRecommendation recommendation12() { | |
42 | + return new EvaluationRecommendation12(); | |
50 | 43 | } |
51 | - | |
52 | - protected static class EvaluationRecommendation14 extends BehaviorRecommendation{ | |
53 | - protected List<Occurrence> check() { return getEvaluation().checkRecommendation14();} | |
44 | + | |
45 | + public SpecificRecommendation recommendation13() { | |
46 | + return new EvaluationRecommendation13(); | |
54 | 47 | } |
55 | - | |
56 | - protected static class EvaluationRecommendation15 extends BehaviorRecommendation{ | |
57 | - protected List<Occurrence> check() { return getEvaluation().checkRecommendation15();} | |
48 | + | |
49 | + public SpecificRecommendation recommendation14() { | |
50 | + return new EvaluationRecommendation14(); | |
58 | 51 | } |
59 | - | |
60 | - protected static class EvaluationRecommendation16 extends BehaviorRecommendation{ | |
61 | - protected List<Occurrence> check() { return getEvaluation().checkRecommendation16();} | |
52 | + | |
53 | + public SpecificRecommendation recommendation15() { | |
54 | + return new EvaluationRecommendation15(); | |
62 | 55 | } |
63 | - | |
64 | - public List<Occurrence> check() { | |
65 | - getOccurrences().clear(); | |
66 | - getOccurrences().addAll(checkRecommendation10()); | |
67 | - getOccurrences().addAll(checkRecommendation11()); | |
68 | - getOccurrences().addAll(checkRecommendation12()); | |
69 | - getOccurrences().addAll(checkRecommendation13()); | |
70 | - //getOccurrences().addAll(checkRecommendation14()); comentado por Gibran | |
71 | - getOccurrences().addAll(checkRecommendation15()); | |
72 | - //getOccurrences().addAll(checkRecommendation16()); comentado por Gibran | |
73 | - | |
74 | - return getOccurrences(); | |
56 | + | |
57 | + public SpecificRecommendation recommendation16() { | |
58 | + return new EvaluationRecommendation16(); | |
75 | 59 | } |
76 | - | |
77 | - | |
78 | - | |
79 | - private List<Occurrence> checkRecommendation10() { | |
80 | -List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
81 | - | |
82 | - for (Element element : getDocument().getAllElements()) { | |
83 | - | |
84 | - Attribute onmousedown = null,onkeydown = null, | |
85 | - onmouseup = null, onkeyup = null, | |
86 | - onclick = null, onkeypress = null, | |
87 | - onmouseover = null,onfocus = null, | |
88 | - onmouseout = null, onblur = null,dbclick = null, ondblclick = null; | |
89 | - | |
90 | - if (element.getAttributes() != null) { | |
91 | - onmousedown = element.getAttributes().get("onmousedown"); | |
92 | - onkeydown = element.getAttributes().get("onkeydown"); | |
93 | - | |
94 | - onmouseup = element.getAttributes().get("onmouseup"); | |
95 | - onkeyup = element.getAttributes().get("onkeyup"); | |
96 | - | |
97 | - onclick = element.getAttributes().get("onclick"); | |
98 | - onkeypress = element.getAttributes().get("onkeypress"); | |
99 | - | |
100 | - onmouseover = element.getAttributes().get("onmouseover"); | |
101 | - onfocus = element.getAttributes().get("onfocus"); | |
102 | - | |
103 | - onmouseout = element.getAttributes().get("onmouseout"); | |
104 | - onblur = element.getAttributes().get("onblur"); | |
105 | - | |
106 | - dbclick = element.getAttributes().get("dbclick"); | |
107 | - ondblclick = element.getAttributes().get("ondblclick"); | |
108 | - } | |
109 | - | |
110 | - if(dbclick!=null){ | |
111 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "6"));//"2")); | |
112 | - } | |
113 | - | |
114 | - if(ondblclick!=null){ | |
115 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "6"));//"2")); | |
116 | - } | |
117 | - | |
118 | - if (onmousedown != null && onkeydown == null) { | |
119 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "2"));//"1")); | |
120 | - } | |
121 | - | |
122 | - if (onmouseup != null && onkeyup == null) { | |
123 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "1"));//"1")); | |
124 | - } | |
125 | - /*if (onclick != null && onkeypress == null) { | |
126 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "1")); | |
127 | - }*/ | |
128 | - if (onmouseover != null && onfocus == null) { | |
129 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "2"));//"1")); | |
130 | - } | |
131 | - if (onmouseout != null && onblur == null) { | |
132 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "2"));//"1")); | |
133 | - } | |
134 | - } | |
135 | - | |
136 | - String attributes[] = {"onafterprint","onbeforeprint","onbeforeunload","onerror", "onhashchange", "onload", "onmessage", "onoffline","ononline", "onpagehide","onpageshow","onpopstate", | |
137 | - "onresize", "onstorage", "onunloadnblur", "onblur","onchange", "oncontextmenu", "onfocus", "oninput","oninvalid","onreset","onsearch","onselect","onsubmit","onkeydown","onkeypress", | |
138 | - "onkeyup", "onclick","ondblclick", "ondrag","ondragend","ondragenter", "ondragleave", "ondragover", "ondragstart","ondrop","onmousedown", "onmousemove","onmouseout","onmouseover","onmouseup", | |
139 | - "onmousewheel", "onscroll", "onwheel", "oncopy", "oncut","onpaste", "onabort", "oncanplay", "oncanplaythrough","oncuechange","ondurationchange","onemptied","onended","onerror", | |
140 | - "onloadeddata","onloadedmetadata","onloadstart","onpause","onplay","onplaying","onprogress","onratechange","onseeked","onseeking","onstalled","onsuspend","ontimeupdate", | |
141 | - "onvolumechange","onwaiting","onerror","onshow","ontoggle"}; | |
142 | - | |
143 | - for(Element element : getDocument().getAllElements()){ | |
144 | - | |
145 | - if(!isTagForm(element)) | |
146 | - if(element != null){ | |
147 | - for(String attribute : attributes){ | |
148 | - if (element.getAttributeValue(attribute) != null) { | |
149 | - occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "8"));//"3")); | |
150 | - } | |
151 | - } | |
152 | - } | |
153 | - } | |
154 | - | |
155 | - return occurrences; | |
60 | + } | |
61 | + | |
62 | + protected static class EvaluationRecommendation10 extends BehaviorRecommendation { | |
63 | + protected List<Occurrence> check() { | |
64 | + return getEvaluation().checkRecommendation10(); | |
65 | + } | |
66 | + } | |
67 | + | |
68 | + protected static class EvaluationRecommendation11 extends BehaviorRecommendation { | |
69 | + protected List<Occurrence> check() { | |
70 | + return getEvaluation().checkRecommendation11(); | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + protected static class EvaluationRecommendation12 extends BehaviorRecommendation { | |
75 | + protected List<Occurrence> check() { | |
76 | + return getEvaluation().checkRecommendation12(); | |
77 | + } | |
78 | + } | |
79 | + | |
80 | + protected static class EvaluationRecommendation13 extends BehaviorRecommendation { | |
81 | + protected List<Occurrence> check() { | |
82 | + return getEvaluation().checkRecommendation13(); | |
83 | + } | |
84 | + } | |
85 | + | |
86 | + protected static class EvaluationRecommendation14 extends BehaviorRecommendation { | |
87 | + protected List<Occurrence> check() { | |
88 | + return getEvaluation().checkRecommendation14(); | |
89 | + } | |
90 | + } | |
91 | + | |
92 | + protected static class EvaluationRecommendation15 extends BehaviorRecommendation { | |
93 | + protected List<Occurrence> check() { | |
94 | + return getEvaluation().checkRecommendation15(); | |
156 | 95 | } |
157 | - | |
158 | - | |
159 | - | |
160 | - private List<Occurrence> checkRecommendation11() { | |
161 | - List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
162 | - | |
163 | - //boolean script = false; | |
164 | - //boolean contAlter = false; | |
165 | - | |
166 | - /*if(!getDocument().getAllElements("script").isEmpty()) | |
167 | - script = true; | |
168 | - | |
169 | - if(script) | |
170 | - if(getDocument().getAllElements("noscript").isEmpty()) | |
171 | - occurrences.add(this.buildOccurrence("2.2", true, getDocument().getFirstElement("html").toString(), getDocument().getFirstElement("html"), "1"));*/ | |
172 | - | |
173 | - for(Element elementScript : getDocument().getAllElements("script")){ | |
174 | - if((!elementScript.isEmpty()) && (elementScript.getAttributeValue("noscript") == null)) | |
175 | - occurrences.add(this.buildOccurrence("2.2", true, elementScript.toString(), elementScript, "1")); | |
96 | + } | |
97 | + | |
98 | + protected static class EvaluationRecommendation16 extends BehaviorRecommendation { | |
99 | + protected List<Occurrence> check() { | |
100 | + return getEvaluation().checkRecommendation16(); | |
101 | + } | |
102 | + } | |
103 | + | |
104 | + public List<Occurrence> check() { | |
105 | + getOccurrences().clear(); | |
106 | + getOccurrences().addAll(checkRecommendation10()); | |
107 | + getOccurrences().addAll(checkRecommendation11()); | |
108 | + getOccurrences().addAll(checkRecommendation12()); | |
109 | + getOccurrences().addAll(checkRecommendation13()); | |
110 | + // getOccurrences().addAll(checkRecommendation14()); comentado por Gibran | |
111 | + getOccurrences().addAll(checkRecommendation15()); | |
112 | + // getOccurrences().addAll(checkRecommendation16()); comentado por Gibran | |
113 | + | |
114 | + return getOccurrences(); | |
115 | + } | |
116 | + | |
117 | + | |
118 | + | |
119 | + private List<Occurrence> checkRecommendation10() { | |
120 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
121 | + | |
122 | + for (Element element : getDocument().getAllElements()) { | |
123 | + | |
124 | + Attribute onmousedown = null, onkeydown = null, onmouseup = null, onkeyup = null, onclick = | |
125 | + null, onkeypress = null, onmouseover = null, onfocus = null, onmouseout = null, onblur = | |
126 | + null, dbclick = null, ondblclick = null; | |
127 | + | |
128 | + if (element.getAttributes() != null) { | |
129 | + onmousedown = element.getAttributes().get("onmousedown"); | |
130 | + onkeydown = element.getAttributes().get("onkeydown"); | |
131 | + | |
132 | + onmouseup = element.getAttributes().get("onmouseup"); | |
133 | + onkeyup = element.getAttributes().get("onkeyup"); | |
134 | + | |
135 | + onclick = element.getAttributes().get("onclick"); | |
136 | + onkeypress = element.getAttributes().get("onkeypress"); | |
137 | + | |
138 | + onmouseover = element.getAttributes().get("onmouseover"); | |
139 | + onfocus = element.getAttributes().get("onfocus"); | |
140 | + | |
141 | + onmouseout = element.getAttributes().get("onmouseout"); | |
142 | + onblur = element.getAttributes().get("onblur"); | |
143 | + | |
144 | + dbclick = element.getAttributes().get("dbclick"); | |
145 | + ondblclick = element.getAttributes().get("ondblclick"); | |
176 | 146 | } |
177 | - | |
178 | - | |
179 | - if(!getDocument().getAllElements("embed").isEmpty()){ | |
180 | - for(Element embed : getDocument().getAllElements("embed")) | |
181 | - occurrences.add(this.buildOccurrence("2.2", false, embed.toString(), embed, "3")); | |
182 | - } | |
183 | - | |
184 | - if(!getDocument().getAllElements("applet").isEmpty()){ | |
185 | - for(Element applet : getDocument().getAllElements("applet")) | |
186 | - occurrences.add(this.buildOccurrence("2.2", false, applet.toString(), applet, "4")); | |
147 | + | |
148 | + if (dbclick != null) { | |
149 | + occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "6"));// "2")); | |
187 | 150 | } |
188 | - | |
189 | - for (Element object : getDocument().getAllElements("object")) { | |
190 | - boolean isParam = false; | |
191 | - | |
192 | - for(Element element : object.getChildElements()){ | |
193 | - if(element.getName().equals("param")){ | |
194 | - isParam = true; | |
195 | - } | |
196 | - } | |
197 | - | |
198 | - if(!isParam) | |
199 | - occurrences.add(this.buildOccurrence("2.2", true, object.toString(), object, "2")); | |
151 | + | |
152 | + if (ondblclick != null) { | |
153 | + occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "6"));// "2")); | |
200 | 154 | } |
201 | - | |
202 | - | |
203 | - | |
204 | - /*for (Element object : getDocument().getAllElements("object")) { | |
205 | - | |
206 | - for(Element elemnet : object.getChildElements()){ | |
207 | - if(!elemnet.getName().equals("param")){ | |
208 | - contAlter = true; | |
209 | - } | |
210 | - } | |
211 | - | |
212 | - if(!contAlter){ | |
213 | - occurrences.add(this.buildOccurrence("2.2", true, object.toString(), object, "2")); | |
214 | - contAlter = false; | |
215 | - } | |
216 | - | |
217 | - }*/ | |
218 | - | |
219 | - return occurrences; | |
220 | - } | |
221 | - | |
222 | - private List<Occurrence> checkRecommendation12() { | |
223 | - List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
224 | - | |
225 | - boolean temMetaRefresh = false; | |
226 | - for (Element element : getDocument().getAllElements("meta")) { | |
227 | - Attribute httpEquiv = element.getAttributes().get("http-equiv"); | |
228 | - | |
229 | - if (httpEquiv != null && "refresh".equals(httpEquiv.getValue())) { | |
230 | - occurrences.add(this.buildOccurrence("2.3", false, element.toString(), element, "1")); | |
231 | - temMetaRefresh = true; | |
232 | - } | |
155 | + | |
156 | + if (onmousedown != null && onkeydown == null) { | |
157 | + occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "2"));// "1")); | |
233 | 158 | } |
234 | - | |
235 | - /*if(!temMetaRefresh) | |
236 | - occurrences.add(new Occurrence("2.3", false, this.getDocument().getFirstElement().toString(),OccurrenceClassification.BEHAVIOR));*/ | |
237 | - | |
238 | - return occurrences; | |
239 | - } | |
240 | - | |
241 | - private List<Occurrence> checkRecommendation13() { | |
242 | - List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
243 | - | |
244 | - for (Element element : getDocument().getAllElements("meta")) { | |
245 | - Attribute content = element.getAttributes().get("content"); | |
246 | - Attribute httpEquiv = element.getAttributes().get("http-equiv"); | |
247 | - | |
248 | - boolean url = false; | |
249 | - if(content != null) | |
250 | - url = content.toString().contains("url"); | |
251 | - | |
252 | - if (httpEquiv != null && "refresh".equals(httpEquiv.getValue()) && content != null && url == true) | |
253 | - occurrences.add(this.buildOccurrence("2.4", true, element.toString(), element, "1")); | |
159 | + | |
160 | + if (onmouseup != null && onkeyup == null) { | |
161 | + occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "1"));// "1")); | |
254 | 162 | } |
255 | - | |
256 | - return occurrences; | |
257 | - } | |
258 | - | |
259 | - private List<Occurrence> checkRecommendation14() { | |
260 | - List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
261 | - boolean hasBlink = false; | |
262 | - boolean hasMarquee = false; | |
263 | - for (Element blink : getDocument().getAllElements("blink")) { | |
264 | - occurrences.add(this.buildOccurrence("2.5", true, blink.toString(), blink)); | |
265 | - hasBlink = true; | |
163 | + /* | |
164 | + * if (onclick != null && onkeypress == null) { occurrences.add(this.buildOccurrence("2.1", | |
165 | + * true, element.toString(), element, "1")); } | |
166 | + */ | |
167 | + if (onmouseover != null && onfocus == null) { | |
168 | + occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "2"));// "1")); | |
266 | 169 | } |
267 | - | |
268 | - for(Element marquee : getDocument().getAllElements("marquee")) { | |
269 | - occurrences.add(this.buildOccurrence("2.5", true, marquee.toString(), marquee)); | |
270 | - hasMarquee = true; | |
170 | + if (onmouseout != null && onblur == null) { | |
171 | + occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "2"));// "1")); | |
271 | 172 | } |
272 | - | |
273 | - if (!hasBlink && !hasMarquee){ | |
274 | - occurrences.add(new Occurrence("2.5", false, getDocument().getFirstElement().toString(),OccurrenceClassification.BEHAVIOR,"1")); | |
173 | + } | |
174 | + | |
175 | + String attributes[] = | |
176 | + {"onafterprint", "onbeforeprint", "onbeforeunload", "onerror", "onhashchange", "onload", | |
177 | + "onmessage", "onoffline", "ononline", "onpagehide", "onpageshow", "onpopstate", | |
178 | + "onresize", "onstorage", "onunloadnblur", "onblur", "onchange", "oncontextmenu", | |
179 | + "onfocus", "oninput", "oninvalid", "onreset", "onsearch", "onselect", "onsubmit", | |
180 | + "onkeydown", "onkeypress", "onkeyup", "onclick", "ondblclick", "ondrag", "ondragend", | |
181 | + "ondragenter", "ondragleave", "ondragover", "ondragstart", "ondrop", "onmousedown", | |
182 | + "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onmousewheel", "onscroll", | |
183 | + "onwheel", "oncopy", "oncut", "onpaste", "onabort", "oncanplay", "oncanplaythrough", | |
184 | + "oncuechange", "ondurationchange", "onemptied", "onended", "onerror", "onloadeddata", | |
185 | + "onloadedmetadata", "onloadstart", "onpause", "onplay", "onplaying", "onprogress", | |
186 | + "onratechange", "onseeked", "onseeking", "onstalled", "onsuspend", "ontimeupdate", | |
187 | + "onvolumechange", "onwaiting", "onerror", "onshow", "ontoggle"}; | |
188 | + | |
189 | + for (Element element : getDocument().getAllElements()) { | |
190 | + | |
191 | + if (!isTagForm(element)) | |
192 | + if (element != null) { | |
193 | + for (String attribute : attributes) { | |
194 | + if (element.getAttributeValue(attribute) != null) { | |
195 | + occurrences.add(this.buildOccurrence("2.1", true, element.toString(), element, "8"));// "3")); | |
196 | + } | |
197 | + } | |
198 | + } | |
199 | + } | |
200 | + | |
201 | + return occurrences; | |
202 | + } | |
203 | + | |
204 | + | |
205 | + | |
206 | + private List<Occurrence> checkRecommendation11() { | |
207 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
208 | + | |
209 | + // boolean script = false; | |
210 | + // boolean contAlter = false; | |
211 | + | |
212 | + /* | |
213 | + * if(!getDocument().getAllElements("script").isEmpty()) script = true; | |
214 | + * | |
215 | + * if(script) if(getDocument().getAllElements("noscript").isEmpty()) | |
216 | + * occurrences.add(this.buildOccurrence("2.2", true, | |
217 | + * getDocument().getFirstElement("html").toString(), getDocument().getFirstElement("html"), | |
218 | + * "1")); | |
219 | + */ | |
220 | + | |
221 | + | |
222 | + | |
223 | + if (getDocument().getAllElements("script").size() > 0) { | |
224 | + if (getDocument().getAllElements("body").get(0).getAllElements("noscript") == null | |
225 | + || getDocument().getAllElements("body").get(0).getAllElements("noscript").size() <= 0) { | |
226 | + // occurrences.add(this.buildOccurrence("2.2", true, elementScript.toString(), | |
227 | + // elementScript, "1")); | |
228 | + | |
229 | + occurrences.add(this.buildOccurrence("2.2", true, | |
230 | + "Observação - Sem fonte (Não existe tag <noscript>)", | |
231 | + getDocument().getFirstElement(), "1"));// "1")); | |
275 | 232 | } |
276 | - | |
277 | - return occurrences; | |
278 | 233 | } |
279 | - | |
280 | - private List<Occurrence> checkRecommendation15() { | |
281 | - List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
282 | - | |
283 | - | |
284 | - for (Element blink : getDocument().getAllElements("blink")) { | |
285 | - occurrences.add(this.buildOccurrence("2.6", true, blink.toString(), blink, "1")); | |
234 | + | |
235 | + if (getDocument().getAllElements("script").size() != getDocument().getAllElements("body") | |
236 | + .get(0).getAllElements("noscript").size()) { | |
237 | + for (Element elementScript : getDocument().getAllElements("script")) { | |
238 | + if ((!elementScript.isEmpty()) && (elementScript.getAttributeValue("noscript") == null)) | |
239 | + occurrences.add(this.buildOccurrence("2.2", false, elementScript.toString(), | |
240 | + elementScript, "6")); | |
286 | 241 | } |
287 | - | |
288 | - for(Element marquee : getDocument().getAllElements("marquee")) { | |
289 | - | |
290 | - | |
291 | - /* for(Element img : marquee.getAllElements("img")) { | |
292 | - Attribute src = img.getAttributes().get("src"); | |
293 | - if(src != null) | |
294 | - if(img.getAttributeValue("src").contains(".gif")){ | |
295 | - occurrences.add(this.buildOccurrence("2.6", false,marquee.toString(), marquee, "3")); | |
296 | - } | |
297 | - }*/ | |
298 | - | |
299 | - occurrences.add(this.buildOccurrence("2.6", true, marquee.toString(), marquee, "2")); | |
242 | + | |
243 | + } | |
244 | + | |
245 | + | |
246 | + | |
247 | + if (!getDocument().getAllElements("embed").isEmpty()) { | |
248 | + for (Element embed : getDocument().getAllElements("embed")) | |
249 | + occurrences.add(this.buildOccurrence("2.2", false, embed.toString(), embed, "3")); | |
250 | + } | |
251 | + | |
252 | + if (!getDocument().getAllElements("applet").isEmpty()) { | |
253 | + for (Element applet : getDocument().getAllElements("applet")) | |
254 | + occurrences.add(this.buildOccurrence("2.2", false, applet.toString(), applet, "4")); | |
255 | + } | |
256 | + | |
257 | + for (Element object : getDocument().getAllElements("object")) { | |
258 | + boolean isParam = false; | |
259 | + | |
260 | + for (Element element : object.getChildElements()) { | |
261 | + if (element.getName().equals("param")) { | |
262 | + isParam = true; | |
263 | + } | |
300 | 264 | } |
301 | - | |
302 | - for(Element img : getDocument().getAllElements("img")) { | |
303 | - Attribute src = img.getAttributes().get("src"); | |
304 | - if(src != null) | |
305 | - if(img.getAttributeValue("src").contains(".gif")){ | |
306 | - occurrences.add(this.buildOccurrence("2.6", false, img.toString(), img, "3")); | |
307 | - } | |
265 | + | |
266 | + if (!isParam) | |
267 | + occurrences.add(this.buildOccurrence("2.2", true, object.toString(), object, "2")); | |
268 | + } | |
269 | + | |
270 | + | |
271 | + | |
272 | + /* | |
273 | + * for (Element object : getDocument().getAllElements("object")) { | |
274 | + * | |
275 | + * for(Element elemnet : object.getChildElements()){ if(!elemnet.getName().equals("param")){ | |
276 | + * contAlter = true; } } | |
277 | + * | |
278 | + * if(!contAlter){ occurrences.add(this.buildOccurrence("2.2", true, object.toString(), object, | |
279 | + * "2")); contAlter = false; } | |
280 | + * | |
281 | + * } | |
282 | + */ | |
283 | + | |
284 | + return occurrences; | |
285 | + } | |
286 | + | |
287 | + private List<Occurrence> checkRecommendation12() { | |
288 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
289 | + | |
290 | + boolean temMetaRefresh = false; | |
291 | + for (Element element : getDocument().getAllElements("meta")) { | |
292 | + Attribute httpEquiv = element.getAttributes().get("http-equiv"); | |
293 | + | |
294 | + if (httpEquiv != null && "refresh".equals(httpEquiv.getValue())) { | |
295 | + occurrences.add(this.buildOccurrence("2.3", false, element.toString(), element, "1")); | |
296 | + temMetaRefresh = true; | |
308 | 297 | } |
309 | - | |
310 | - return occurrences; | |
311 | 298 | } |
312 | - | |
313 | - private boolean isTagForm(Element element){ | |
314 | - | |
315 | - List<String> tagsForm = new ArrayList<String>(); | |
316 | - tagsForm.add("form"); | |
317 | - tagsForm.add("input"); | |
318 | - tagsForm.add("fieldset"); | |
319 | - tagsForm.add("legend"); | |
320 | - tagsForm.add("label"); | |
321 | - tagsForm.add("textarea"); | |
322 | - tagsForm.add("select"); | |
323 | - tagsForm.add("option"); | |
324 | - tagsForm.add("optgroup"); | |
325 | - tagsForm.add("button"); | |
326 | - tagsForm.add("a"); | |
327 | - | |
328 | - | |
329 | - if(element != null) | |
330 | - return tagsForm.contains(element.getName()); | |
331 | - | |
332 | - return false; | |
299 | + | |
300 | + /* | |
301 | + * if(!temMetaRefresh) occurrences.add(new Occurrence("2.3", false, | |
302 | + * this.getDocument().getFirstElement().toString(),OccurrenceClassification.BEHAVIOR)); | |
303 | + */ | |
304 | + | |
305 | + return occurrences; | |
306 | + } | |
307 | + | |
308 | + private List<Occurrence> checkRecommendation13() { | |
309 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
310 | + | |
311 | + for (Element element : getDocument().getAllElements("meta")) { | |
312 | + Attribute content = element.getAttributes().get("content"); | |
313 | + Attribute httpEquiv = element.getAttributes().get("http-equiv"); | |
314 | + | |
315 | + boolean url = false; | |
316 | + if (content != null) | |
317 | + url = content.toString().contains("url"); | |
318 | + | |
319 | + if (httpEquiv != null && "refresh".equals(httpEquiv.getValue()) && content != null | |
320 | + && url == true) | |
321 | + occurrences.add(this.buildOccurrence("2.4", true, element.toString(), element, "1")); | |
333 | 322 | } |
334 | - | |
335 | - | |
336 | - private List<Occurrence> checkRecommendation16() { | |
337 | - List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
338 | - occurrences.add(new Occurrence("2.7", false, getDocument().getFirstElement().toString(),OccurrenceClassification.BEHAVIOR)); | |
339 | - return occurrences; | |
323 | + | |
324 | + return occurrences; | |
325 | + } | |
326 | + | |
327 | + private List<Occurrence> checkRecommendation14() { | |
328 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
329 | + boolean hasBlink = false; | |
330 | + boolean hasMarquee = false; | |
331 | + for (Element blink : getDocument().getAllElements("blink")) { | |
332 | + occurrences.add(this.buildOccurrence("2.5", true, blink.toString(), blink)); | |
333 | + hasBlink = true; | |
334 | + } | |
335 | + | |
336 | + for (Element marquee : getDocument().getAllElements("marquee")) { | |
337 | + occurrences.add(this.buildOccurrence("2.5", true, marquee.toString(), marquee)); | |
338 | + hasMarquee = true; | |
340 | 339 | } |
341 | - | |
342 | - private Occurrence buildOccurrence(String code, boolean error, | |
343 | - String tag, Element element, | |
344 | - String criterio) { | |
345 | - return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.BEHAVIOR,criterio); | |
340 | + | |
341 | + if (!hasBlink && !hasMarquee) { | |
342 | + occurrences.add(new Occurrence("2.5", false, getDocument().getFirstElement().toString(), | |
343 | + OccurrenceClassification.BEHAVIOR, "1")); | |
346 | 344 | } |
347 | - | |
348 | - private Occurrence buildOccurrence(String code, boolean error, | |
349 | - String tag, Element element) { | |
350 | - return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.BEHAVIOR); | |
345 | + | |
346 | + return occurrences; | |
347 | + } | |
348 | + | |
349 | + private List<Occurrence> checkRecommendation15() { | |
350 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
351 | + | |
352 | + | |
353 | + for (Element blink : getDocument().getAllElements("blink")) { | |
354 | + occurrences.add(this.buildOccurrence("2.6", true, blink.toString(), blink, "1")); | |
351 | 355 | } |
352 | - | |
353 | - public OccurrenceClassification type () { return OccurrenceClassification.BEHAVIOR;} | |
356 | + | |
357 | + for (Element marquee : getDocument().getAllElements("marquee")) { | |
358 | + | |
359 | + | |
360 | + /* | |
361 | + * for(Element img : marquee.getAllElements("img")) { Attribute src = | |
362 | + * img.getAttributes().get("src"); if(src != null) | |
363 | + * if(img.getAttributeValue("src").contains(".gif")){ | |
364 | + * occurrences.add(this.buildOccurrence("2.6", false,marquee.toString(), marquee, "3")); } } | |
365 | + */ | |
366 | + | |
367 | + occurrences.add(this.buildOccurrence("2.6", true, marquee.toString(), marquee, "2")); | |
368 | + } | |
369 | + | |
370 | + for (Element img : getDocument().getAllElements("img")) { | |
371 | + Attribute src = img.getAttributes().get("src"); | |
372 | + if (src != null) | |
373 | + if (img.getAttributeValue("src").contains(".gif")) { | |
374 | + occurrences.add(this.buildOccurrence("2.6", false, img.toString(), img, "3")); | |
375 | + } | |
376 | + } | |
377 | + | |
378 | + return occurrences; | |
379 | + } | |
380 | + | |
381 | + private boolean isTagForm(Element element) { | |
382 | + | |
383 | + List<String> tagsForm = new ArrayList<String>(); | |
384 | + tagsForm.add("form"); | |
385 | + tagsForm.add("input"); | |
386 | + tagsForm.add("fieldset"); | |
387 | + tagsForm.add("legend"); | |
388 | + tagsForm.add("label"); | |
389 | + tagsForm.add("textarea"); | |
390 | + tagsForm.add("select"); | |
391 | + tagsForm.add("option"); | |
392 | + tagsForm.add("optgroup"); | |
393 | + tagsForm.add("button"); | |
394 | + tagsForm.add("a"); | |
395 | + | |
396 | + | |
397 | + if (element != null) | |
398 | + return tagsForm.contains(element.getName()); | |
399 | + | |
400 | + return false; | |
401 | + } | |
402 | + | |
403 | + | |
404 | + private List<Occurrence> checkRecommendation16() { | |
405 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
406 | + occurrences.add(new Occurrence("2.7", false, getDocument().getFirstElement().toString(), | |
407 | + OccurrenceClassification.BEHAVIOR)); | |
408 | + return occurrences; | |
409 | + } | |
410 | + | |
411 | + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element, | |
412 | + String criterio) { | |
413 | + return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.BEHAVIOR, | |
414 | + criterio); | |
415 | + } | |
416 | + | |
417 | + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element) { | |
418 | + return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.BEHAVIOR); | |
419 | + } | |
420 | + | |
421 | + public OccurrenceClassification type() { | |
422 | + return OccurrenceClassification.BEHAVIOR; | |
423 | + } | |
354 | 424 | } | ... | ... |