Commit 2c1cf7d90c01fce7473785277b0de213959f343c
1 parent
0529a9ad
Exists in
master
and in
1 other branch
Correção do método para verificação do foco na página.
Showing
1 changed file
with
473 additions
and
58 deletions
Show diff stats
src/main/java/br/com/checker/emag/core/PresentationEvaluation.java
... | ... | @@ -2,10 +2,20 @@ package br.com.checker.emag.core; |
2 | 2 | |
3 | 3 | import java.awt.Color; |
4 | 4 | import java.util.ArrayList; |
5 | +import java.util.Arrays; | |
5 | 6 | import java.util.Collections; |
6 | 7 | import java.util.List; |
7 | 8 | import java.util.regex.Matcher; |
8 | 9 | import java.util.regex.Pattern; |
10 | + | |
11 | +import javax.script.Invocable; | |
12 | +import javax.script.ScriptEngine; | |
13 | +import javax.script.ScriptEngineManager; | |
14 | +import javax.script.ScriptException; | |
15 | +import javax.swing.text.html.HTML; | |
16 | + | |
17 | +import com.oracle.webservices.internal.api.EnvelopeStyle.Style; | |
18 | + | |
9 | 19 | import net.htmlparser.jericho.Attribute; |
10 | 20 | import net.htmlparser.jericho.Element; |
11 | 21 | import net.htmlparser.jericho.Source; |
... | ... | @@ -14,10 +24,12 @@ import br.com.checker.emag.Occurrence; |
14 | 24 | import br.com.checker.emag.OccurrenceClassification; |
15 | 25 | import br.com.checker.emag.core.SpecificRecommendation.PresentationRecommendation; |
16 | 26 | import br.com.checker.emag.util.WebAgent; |
27 | +import br.com.checker.emag.util.UrlSemArquiNoFinal; | |
28 | + | |
29 | + | |
17 | 30 | |
18 | 31 | public class PresentationEvaluation extends Evaluation{ |
19 | 32 | |
20 | - | |
21 | 33 | private PresentationEvaluation(Source document) { super(document); } |
22 | 34 | |
23 | 35 | private PresentationEvaluation(Source document,String url) { |
... | ... | @@ -55,7 +67,7 @@ public class PresentationEvaluation extends Evaluation{ |
55 | 67 | |
56 | 68 | public List<Occurrence> check() { |
57 | 69 | getOccurrences().clear(); |
58 | - //getOccurrences().addAll(checkRecommendation29()); comentado por Gibran | |
70 | + //getOccurrences().addAll(checkRecommendation29()); //comentado por Gibran | |
59 | 71 | //getOccurrences().addAll(checkRecommendation30()); comentado por Gibran |
60 | 72 | //getOccurrences().addAll(checkRecommendation31()); comentado por Gibran |
61 | 73 | getOccurrences().addAll(checkRecommendation32()); |
... | ... | @@ -64,18 +76,233 @@ public class PresentationEvaluation extends Evaluation{ |
64 | 76 | } |
65 | 77 | |
66 | 78 | |
67 | - | |
68 | 79 | private List<Occurrence> checkRecommendation29() { |
69 | 80 | List<Occurrence> occurrences = new ArrayList<Occurrence>(); |
70 | 81 | |
82 | + UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal(); | |
83 | + | |
84 | + String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal.urlSemArquivoNoFinal(getUrl()); | |
85 | + //verificar css externo | |
86 | + String href = null; | |
87 | + boolean avalia = false; | |
88 | + | |
89 | + List<String> lsContent = new ArrayList<String>(); | |
90 | + | |
91 | + for(Element link2 : getDocument().getAllElements("link")) { | |
92 | + href = link2.getAttributeValue("href"); | |
93 | + if(href.startsWith("www"))href= "http://"+ href; | |
94 | + | |
95 | + avalia = getUrl() != null || href.startsWith("http"); | |
96 | + | |
97 | + if(href.contains(".css") && avalia) { | |
98 | + | |
99 | + | |
100 | + if(!href.startsWith("http")) href = urlSemArquiNoFinal + "/" + href; | |
101 | + | |
102 | + | |
103 | + lsContent.add(WebAgent.from(href.replace(" ", "%20")).withGetRequest().execute().getContent()); | |
104 | + } | |
105 | + } | |
106 | + AvaliadorContraste avaliadorContraste = new AvaliadorContraste(); | |
107 | + | |
108 | + Color corAvaliar = null; | |
109 | + Color foreground = null; | |
110 | + Color background = null; | |
111 | + boolean achou_foreground = false; | |
112 | + boolean achou_background = false; | |
113 | + String styleInline = ""; | |
114 | + String valor_id = ""; | |
115 | + String valor_class = ""; | |
116 | + List<Attribute> lsAttribute = new ArrayList<Attribute>(); | |
117 | + | |
118 | + //pega css interno caso tenha | |
119 | + for (Element head : getDocument().getAllElements("head")) { | |
120 | + for (Element estilo : head.getAllElements("style")) { | |
121 | + for (Attribute atribute : estilo.getAttributes()) { | |
122 | + lsAttribute.add(atribute); | |
123 | + } | |
124 | + } | |
125 | + } | |
126 | + | |
127 | + | |
128 | + //Pega todos elementos do "body" | |
129 | + for (Element body : getDocument().getAllElements("body")) { | |
130 | + for (Element element : body.getAllElements()) { | |
131 | + | |
132 | + //Primeiro verificar se tem css in-line | |
133 | + styleInline = element.getAttributeValue("style"); | |
134 | + if(styleInline != null){ | |
135 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
136 | + corAvaliar = getColor(styleInline, "color:(.*?)\\Z"); | |
137 | + if(corAvaliar != null) | |
138 | + { | |
139 | + foreground = corAvaliar; | |
140 | + } | |
141 | + | |
142 | + corAvaliar = getColor(styleInline, "color:(.*?)\\;"); | |
143 | + if(corAvaliar != null) | |
144 | + { | |
145 | + foreground = corAvaliar; | |
146 | + } | |
147 | + | |
148 | + | |
149 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
150 | + corAvaliar = getColor(styleInline, "background:(.*?)\\Z"); | |
151 | + if(corAvaliar != null) | |
152 | + { | |
153 | + background = corAvaliar; | |
154 | + } | |
155 | + | |
156 | + corAvaliar = getColor(styleInline, "background:(.*?)\\;"); | |
157 | + if(corAvaliar != null) | |
158 | + { | |
159 | + background = corAvaliar; | |
160 | + } | |
161 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
162 | + corAvaliar = getColor(styleInline, "background-color:(.*?)\\Z"); | |
163 | + if(corAvaliar != null) | |
164 | + { | |
165 | + background = corAvaliar; | |
166 | + } | |
167 | + | |
168 | + corAvaliar = getColor(styleInline, "background-color:(.*?)\\;"); | |
169 | + if(corAvaliar != null) | |
170 | + { | |
171 | + background = corAvaliar; | |
172 | + } | |
173 | + | |
174 | + if(foreground != null) achou_foreground = true; | |
175 | + if(background != null) achou_background = true; | |
176 | + | |
177 | + }else | |
178 | + { | |
179 | + | |
180 | + //verifica css interno ou externo | |
181 | + | |
182 | + //Verifica se tem #id | |
183 | + valor_id = element.getAttributeValue("id"); | |
184 | + if(valor_id != null) | |
185 | + { | |
186 | + for (Attribute style : lsAttribute){ | |
187 | + | |
188 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
189 | + System.out.println("#"+ style); | |
190 | + if(style.toString().equalsIgnoreCase("#"+ element.toString())) | |
191 | + { | |
192 | + corAvaliar = getColor(style.toString(), "color:(.*?)\\Z"); | |
193 | + if(corAvaliar != null) | |
194 | + { | |
195 | + foreground = corAvaliar; | |
196 | + } | |
197 | + | |
198 | + corAvaliar = getColor(style.toString(), "color:(.*?)\\;"); | |
199 | + if(corAvaliar != null) | |
200 | + { | |
201 | + foreground = corAvaliar; | |
202 | + } | |
203 | + | |
204 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
205 | + corAvaliar = getColor(style.toString(), "background:(.*?)\\Z"); | |
206 | + if(corAvaliar != null) | |
207 | + { | |
208 | + background = corAvaliar; | |
209 | + } | |
210 | + | |
211 | + corAvaliar = getColor(style.toString(), "background:(.*?)\\;"); | |
212 | + if(corAvaliar != null) | |
213 | + { | |
214 | + background = corAvaliar; | |
215 | + } | |
216 | + | |
217 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
218 | + corAvaliar = getColor(style.toString(), "background-color:(.*?)\\Z"); | |
219 | + if(corAvaliar != null) | |
220 | + { | |
221 | + background = corAvaliar; | |
222 | + } | |
223 | + | |
224 | + corAvaliar = getColor(style.toString(), "background-color:(.*?)\\;"); | |
225 | + if(corAvaliar != null) | |
226 | + { | |
227 | + background = corAvaliar; | |
228 | + } | |
229 | + | |
230 | + if(foreground != null) achou_foreground = true; | |
231 | + if(background != null) achou_background = true; | |
232 | + } | |
233 | + | |
234 | + | |
235 | + } | |
236 | + | |
237 | + | |
238 | + }else | |
239 | + { | |
240 | + valor_class = element.getAttributeValue("class"); | |
241 | + | |
242 | + } | |
243 | + | |
244 | + | |
245 | + corAvaliar = null; | |
246 | + foreground = null; | |
247 | + background = null; | |
248 | + achou_foreground = false; | |
249 | + achou_background = false; | |
250 | + | |
251 | + | |
252 | + } | |
253 | + } | |
254 | + } | |
255 | + return occurrences; | |
256 | + } | |
257 | + | |
258 | + | |
259 | + | |
260 | + | |
261 | + private List<Occurrence> checkRecommendation292() { | |
262 | + List<Occurrence> occurrences = new ArrayList<Occurrence>(); | |
263 | + | |
264 | + UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal(); | |
265 | + | |
266 | + String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal.urlSemArquivoNoFinal(getUrl()); | |
267 | + //verificar css externo | |
268 | + String href = null; | |
269 | + boolean avalia = false; | |
270 | + | |
271 | + List<String> lsContent = new ArrayList<String>(); | |
272 | + | |
273 | + for(Element link2 : getDocument().getAllElements("link")) { | |
274 | + href = link2.getAttributeValue("href"); | |
275 | + if(href.startsWith("www"))href= "http://"+ href; | |
276 | + | |
277 | + avalia = getUrl() != null || href.startsWith("http"); | |
278 | + | |
279 | + if(href.contains(".css") && avalia) { | |
280 | + | |
281 | + | |
282 | + if(!href.startsWith("http")) href = urlSemArquiNoFinal + "/" + href; | |
283 | + | |
284 | + | |
285 | + lsContent.add(WebAgent.from(href.replace(" ", "%20")).withGetRequest().execute().getContent()); | |
286 | + } | |
287 | + } | |
288 | + | |
289 | + //List<String> tags = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6","a", "p","select", "option", "textarea", "button", "datalist", "keygen", | |
290 | + // "output", "input","label", "select","optgroup", "form","fieldset","legend"); | |
291 | + | |
292 | + | |
71 | 293 | // Implementação comentada, em virtude de comprometimento da performance do avaliador. Lyandro Santana - 12/11/2015 |
72 | - /*String[] attributes = {"class","id", "bgcolor"}; | |
294 | + String[] attributes = {"bgcolor","h1", "h2", "h3", "h4", "h5", "h6","a", "p","select", "option", "textarea", "button", "datalist", "keygen", | |
295 | + "output", "input","label", "select","optgroup", "form","fieldset","legend"}; | |
296 | + | |
73 | 297 | AvaliadorContraste avaliadorContraste = new AvaliadorContraste(); |
74 | 298 | |
75 | 299 | System.out.println("Processando verificação de cor..."); |
76 | - for (Element body : getDocument().getAllElements("body")) { | |
77 | - for (Element element : body.getAllElements()) { | |
300 | + for (Element body : getDocument().getAllElements("body")) { | |
301 | + for (String atributo : attributes) { | |
302 | + | |
303 | + for (Element element : body.getAllElements(atributo)) { | |
78 | 304 | |
305 | + Color corAvaliar = null; | |
79 | 306 | Color foreground = null; |
80 | 307 | Color background = null; |
81 | 308 | boolean achou_foreground = false; |
... | ... | @@ -83,17 +310,51 @@ public class PresentationEvaluation extends Evaluation{ |
83 | 310 | |
84 | 311 | if(element != null ){ |
85 | 312 | |
86 | - for (String attribute : attributes) { | |
313 | + | |
314 | + //for (String attribute : attributes) { | |
87 | 315 | //System.out.println("Verificando: "+attribute); |
88 | 316 | |
89 | 317 | //Verificar IN-LINE |
90 | 318 | String styleInline = element.getAttributeValue("style"); |
91 | 319 | if(styleInline != null){ |
320 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
321 | + corAvaliar = getColor(styleInline, "color:(.*?)\\Z"); | |
322 | + if(corAvaliar != null) | |
323 | + { | |
324 | + foreground = corAvaliar; | |
325 | + } | |
326 | + | |
327 | + corAvaliar = getColor(styleInline, "color:(.*?)\\;"); | |
328 | + if(corAvaliar != null) | |
329 | + { | |
330 | + foreground = corAvaliar; | |
331 | + } | |
92 | 332 | |
93 | - foreground = getColor(styleInline, "color:(.*?)\\;"); | |
94 | - background = getColor(styleInline, "background:(.*?)\\;"); | |
95 | - background = getColor(styleInline, "background-color:(.*?)\\;"); | |
96 | 333 | |
334 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
335 | + corAvaliar = getColor(styleInline, "background:(.*?)\\Z"); | |
336 | + if(corAvaliar != null) | |
337 | + { | |
338 | + background = corAvaliar; | |
339 | + } | |
340 | + | |
341 | + corAvaliar = getColor(styleInline, "background:(.*?)\\;"); | |
342 | + if(corAvaliar != null) | |
343 | + { | |
344 | + background = corAvaliar; | |
345 | + } | |
346 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
347 | + corAvaliar = getColor(styleInline, "background-color:(.*?)\\Z"); | |
348 | + if(corAvaliar != null) | |
349 | + { | |
350 | + background = corAvaliar; | |
351 | + } | |
352 | + | |
353 | + corAvaliar = getColor(styleInline, "background-color:(.*?)\\;"); | |
354 | + if(corAvaliar != null) | |
355 | + { | |
356 | + background = corAvaliar; | |
357 | + } | |
97 | 358 | |
98 | 359 | if(foreground != null) achou_foreground = true; |
99 | 360 | if(background != null) achou_background = true; |
... | ... | @@ -109,11 +370,50 @@ public class PresentationEvaluation extends Evaluation{ |
109 | 370 | |
110 | 371 | //Verificar css interno |
111 | 372 | for (Element style : getDocument().getAllElements("style")){ |
112 | - foreground = getColor(style.toString(), "color:(.*?)\\;"); | |
113 | - background = getColor(style.toString(), "background:(.*?)\\;"); | |
114 | - background = getColor(style.toString(), "background-color:(.*?)\\;"); | |
115 | 373 | |
374 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
375 | + corAvaliar = getColor(style.toString(), "color:(.*?)\\Z"); | |
376 | + if(corAvaliar != null) | |
377 | + { | |
378 | + foreground = corAvaliar; | |
379 | + } | |
380 | + | |
381 | + corAvaliar = getColor(style.toString(), "color:(.*?)\\;"); | |
382 | + if(corAvaliar != null) | |
383 | + { | |
384 | + foreground = corAvaliar; | |
385 | + } | |
386 | + | |
387 | + //foreground = getColor(style.toString(), "color:(.*?)\\;"); | |
388 | + //background = getColor(style.toString(), "background:(.*?)\\;"); | |
389 | + //background = getColor(style.toString(), "background-color:(.*?)\\;"); | |
390 | + | |
391 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
392 | + corAvaliar = getColor(style.toString(), "background:(.*?)\\Z"); | |
393 | + if(corAvaliar != null) | |
394 | + { | |
395 | + background = corAvaliar; | |
396 | + } | |
397 | + | |
398 | + corAvaliar = getColor(style.toString(), "background:(.*?)\\;"); | |
399 | + if(corAvaliar != null) | |
400 | + { | |
401 | + background = corAvaliar; | |
402 | + } | |
403 | + | |
404 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
405 | + corAvaliar = getColor(style.toString(), "background-color:(.*?)\\Z"); | |
406 | + if(corAvaliar != null) | |
407 | + { | |
408 | + background = corAvaliar; | |
409 | + } | |
116 | 410 | |
411 | + corAvaliar = getColor(style.toString(), "background-color:(.*?)\\;"); | |
412 | + if(corAvaliar != null) | |
413 | + { | |
414 | + background = corAvaliar; | |
415 | + } | |
416 | + | |
117 | 417 | if(foreground != null) achou_foreground = true; |
118 | 418 | if(background != null) achou_background = true; |
119 | 419 | } |
... | ... | @@ -121,7 +421,9 @@ public class PresentationEvaluation extends Evaluation{ |
121 | 421 | if(achou_foreground== false || achou_background == false){ |
122 | 422 | |
123 | 423 | //verificar css externo |
124 | - String href = null; | |
424 | + | |
425 | + | |
426 | + /*String href = null; | |
125 | 427 | boolean avalia = false; |
126 | 428 | for(Element link : getDocument().getAllElements("link")) { |
127 | 429 | href = link.getAttributeValue("href"); |
... | ... | @@ -136,10 +438,53 @@ public class PresentationEvaluation extends Evaluation{ |
136 | 438 | |
137 | 439 | |
138 | 440 | String content = WebAgent.from(href.replace(" ", "%20")).withGetRequest().execute().getContent(); |
139 | - foreground = getColor(content, "color:(.*?)\\;"); | |
140 | - background = getColor(content, "background:(.*?)\\;"); | |
141 | - background = getColor(content, "background-color:(.*?)\\;"); | |
441 | + */ | |
442 | + for (String content : lsContent) { | |
443 | + | |
444 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
445 | + corAvaliar = getColor(content.toString(), "color:(.*?)\\Z"); | |
446 | + if(corAvaliar != null) | |
447 | + { | |
448 | + foreground = corAvaliar; | |
449 | + } | |
450 | + | |
451 | + corAvaliar = getColor(content.toString(), "color:(.*?)\\;"); | |
452 | + if(corAvaliar != null) | |
453 | + { | |
454 | + foreground = corAvaliar; | |
455 | + } | |
456 | + | |
457 | + //foreground = getColor(content, "color:(.*?)\\;"); | |
458 | + //background = getColor(content, "background:(.*?)\\;"); | |
459 | + //background = getColor(content, "background-color:(.*?)\\;"); | |
460 | + | |
461 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
462 | + corAvaliar = getColor(content, "background:(.*?)\\Z"); | |
463 | + if(corAvaliar != null) | |
464 | + { | |
465 | + background = corAvaliar; | |
466 | + } | |
467 | + | |
468 | + corAvaliar = getColor(content, "background:(.*?)\\;"); | |
469 | + if(corAvaliar != null) | |
470 | + { | |
471 | + background = corAvaliar; | |
472 | + } | |
142 | 473 | |
474 | + //pega o valor da cor, mesmo que no final não seja atribuido o ";" | |
475 | + corAvaliar = getColor(content, "background-color:(.*?)\\Z"); | |
476 | + if(corAvaliar != null) | |
477 | + { | |
478 | + | |
479 | + background = corAvaliar; | |
480 | + } | |
481 | + | |
482 | + corAvaliar = getColor(content, "background-color:(.*?)\\;"); | |
483 | + if(corAvaliar != null) | |
484 | + { | |
485 | + | |
486 | + background = corAvaliar; | |
487 | + } | |
143 | 488 | |
144 | 489 | if(foreground != null) achou_foreground = true; |
145 | 490 | if(background != null) achou_background = true; |
... | ... | @@ -158,40 +503,43 @@ public class PresentationEvaluation extends Evaluation{ |
158 | 503 | avaliadorContraste.avaliar(); |
159 | 504 | |
160 | 505 | if(avaliadorContraste.getContraste() < new Double("4.5")){ |
161 | - occurrences.add(buildOccurrence("4.1", true, element.toString(), element,"1")); | |
506 | + occurrences.add(buildOccurrence("4.1", true, element.toString(), element,"2")); | |
162 | 507 | break; |
163 | 508 | } |
164 | 509 | |
165 | 510 | |
166 | - }else if(achou_foreground== true && achou_background == false){ | |
511 | + }else if(achou_foreground == false && achou_background == true){ | |
167 | 512 | |
168 | - avaliadorContraste.setCores(foreground, new Color(Integer.parseInt("ffffff", 16))); | |
169 | - avaliadorContraste.avaliar(); | |
513 | + //avaliadorContraste.setCores(foreground, new Color(Integer.parseInt("ffffff", 16))); | |
514 | + //avaliadorContraste.avaliar(); | |
170 | 515 | |
171 | - if(avaliadorContraste.getContraste() < new Double("4.5")){ | |
172 | - occurrences.add(buildOccurrence("4.1", true, element.toString(), element,"1")); | |
516 | + //if(avaliadorContraste.getContraste() < new Double("4.5")){ | |
517 | + occurrences.add(buildOccurrence("4.1", false, element.toString(), element,"3")); | |
173 | 518 | break; |
174 | - } | |
519 | + //} | |
175 | 520 | |
176 | 521 | |
177 | - }else if(achou_foreground== false && achou_background == true){ | |
522 | + }else if(achou_foreground== true && achou_background == false){ | |
178 | 523 | |
179 | - avaliadorContraste.setCores(new Color(Integer.parseInt("000000", 16)), background); | |
180 | - avaliadorContraste.avaliar(); | |
524 | + //avaliadorContraste.setCores(foreground, new Color(Integer.parseInt("ffffff", 16))); | |
525 | + //avaliadorContraste.avaliar(); | |
181 | 526 | |
182 | - if(avaliadorContraste.getContraste() < new Double("4.5")){ | |
183 | - occurrences.add(buildOccurrence("4.1", true, element.toString(), element,"1")); | |
527 | + //if(avaliadorContraste.getContraste() < new Double("4.5")){ | |
528 | + occurrences.add(buildOccurrence("4.1", false, element.toString(), element,"3")); | |
184 | 529 | break; |
185 | - } | |
530 | + //} | |
186 | 531 | |
187 | 532 | } |
188 | 533 | |
189 | 534 | } |
190 | 535 | } |
191 | 536 | } |
537 | + System.out.println("Verificação terminada."); | |
538 | + return occurrences; | |
192 | 539 | } |
540 | + //} | |
541 | + | |
193 | 542 | |
194 | - System.out.println("Verificação terminada."); */ | |
195 | 543 | |
196 | 544 | |
197 | 545 | |
... | ... | @@ -204,10 +552,10 @@ public class PresentationEvaluation extends Evaluation{ |
204 | 552 | |
205 | 553 | //Término da rotina de Avaliação de contraste |
206 | 554 | |
207 | - occurrences.add(new Occurrence("4.1", false, getDocument().getFirstElement().toString(),OccurrenceClassification.PRESENTATION_DESIGN)); | |
208 | - return occurrences; | |
555 | + // occurrences.add(new Occurrence("4.1", false, getDocument().getFirstElement().toString(),OccurrenceClassification.PRESENTATION_DESIGN)); | |
556 | + | |
209 | 557 | |
210 | - } | |
558 | + //} | |
211 | 559 | |
212 | 560 | |
213 | 561 | private Color getColor(String css, String pattern){ |
... | ... | @@ -231,12 +579,15 @@ public class PresentationEvaluation extends Evaluation{ |
231 | 579 | Integer.parseInt(str.trim().split(" ")[0]), |
232 | 580 | Integer.parseInt(str.trim().split(" ")[1]), |
233 | 581 | Integer.parseInt(str.trim().split(" ")[2])); |
582 | + break; | |
234 | 583 | }else{ |
235 | 584 | //System.out.println("EXADECIMAL: "+match.group(1)); |
236 | - color = new Color(Integer.parseInt(match.group(1).trim().replaceFirst("^#",""), 16)); | |
585 | + color = new Color(Integer.parseInt(match.group(1).trim().replaceFirst("#",""), 16)); | |
586 | + break; | |
237 | 587 | } |
238 | 588 | } |
239 | 589 | } catch (Exception e) { |
590 | + e.printStackTrace(); | |
240 | 591 | return null; |
241 | 592 | } |
242 | 593 | } |
... | ... | @@ -357,61 +708,125 @@ public class PresentationEvaluation extends Evaluation{ |
357 | 708 | return occurrences; |
358 | 709 | } |
359 | 710 | |
711 | + /*private String urlSemArquivoNoFinal(String url) | |
712 | + { | |
713 | + if(url != null) | |
714 | + { | |
715 | + String urlSemArquivo = ""; | |
716 | + boolean encontrouPonto = false; | |
717 | + | |
718 | + | |
719 | + for(int i = url.length()-1; i >= 0; i-- ) | |
720 | + { | |
721 | + | |
722 | + urlSemArquivo = url.substring(i-1,i); | |
723 | + | |
724 | + if(urlSemArquivo.equalsIgnoreCase(".")) | |
725 | + { | |
726 | + encontrouPonto = true; | |
727 | + | |
728 | + }else if(encontrouPonto && urlSemArquivo.equalsIgnoreCase("/")) | |
729 | + { | |
730 | + url = url.substring(0,i); | |
731 | + break; | |
732 | + } | |
733 | + else if(!encontrouPonto && urlSemArquivo.equalsIgnoreCase("/")) | |
734 | + { | |
735 | + break; | |
736 | + } | |
737 | + } | |
738 | + } | |
739 | + return url; | |
740 | + }*/ | |
360 | 741 | private List<Occurrence> checkRecommendation32() { |
361 | 742 | List<Occurrence> occurrences = new ArrayList<Occurrence>(); |
362 | 743 | |
744 | + UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal(); | |
745 | + | |
746 | + String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal.urlSemArquivoNoFinal(getUrl()); | |
747 | + | |
748 | + | |
749 | + //Caso seja encontrado o "a:focus" e "a:hover" n�o continua a verifica��o nos demais for's, bem como, n�o | |
750 | + //adiciona a ocorr�ncia | |
751 | + boolean focoEncontrado = false; | |
752 | + boolean passivelDeAvaliacao = false; | |
753 | + | |
363 | 754 | for (Element style : getDocument().getAllElements("style")) { |
364 | - if(!style.toString().contains("a:focus") && !style.toString().contains("a:hover")){ | |
365 | - occurrences.add(buildOccurrence("4.4", true, style.toString(), style, "1")); | |
755 | + if(style.toString().contains("a:focus") && style.toString().contains("a:hover")){ | |
756 | + //occurrences.add(buildOccurrence("4.4", true, style.toString(), style, "1")); | |
757 | + focoEncontrado = true; | |
366 | 758 | break; |
367 | 759 | } |
368 | 760 | } |
761 | + if(!focoEncontrado) | |
762 | + { | |
763 | + for (Element style : getDocument().getAllElements("a")) { | |
764 | + Attribute attribute = style.getAttributes().get("style"); | |
765 | + if(attribute != null) | |
766 | + if(attribute.toString().contains("a:focus") && attribute.toString().contains("a:hover")){ | |
767 | + //occurrences.add(buildOccurrence("4.4", true, style.toString(), style, "1")); | |
768 | + focoEncontrado = true; | |
769 | + break; | |
770 | + } | |
771 | + } | |
369 | 772 | |
370 | - for (Element style : getDocument().getAllElements("a")) { | |
371 | - Attribute attribute = style.getAttributes().get("style"); | |
372 | - if(attribute != null) | |
373 | - if(!attribute.toString().contains("a:focus") && !attribute.toString().contains("a:hover")){ | |
374 | - occurrences.add(buildOccurrence("4.4", true, style.toString(), style, "1")); | |
375 | - break; | |
376 | - } | |
377 | 773 | } |
378 | - | |
379 | - | |
774 | + if(!focoEncontrado) | |
775 | + { | |
380 | 776 | String href = null; |
381 | - boolean avalia = false; | |
777 | + WebAgent webAgent; | |
778 | + String content = ""; | |
779 | + | |
780 | + boolean avalia = false; | |
781 | + | |
382 | 782 | for(Element link : getDocument().getAllElements("link")) { |
383 | 783 | href = link.getAttributeValue("href"); |
384 | - if(href.startsWith("www"))href= "http://"+href; | |
784 | + if(href.startsWith("www")) | |
785 | + { | |
786 | + href= "http://" + href; | |
787 | + } | |
385 | 788 | |
386 | 789 | avalia = getUrl()!=null || href.startsWith("http"); |
387 | 790 | |
388 | 791 | if(href.contains(".css") && avalia) { |
389 | 792 | |
390 | - if(!href.startsWith("http")) href = getUrl()+"/"+href; | |
793 | + if(!href.startsWith("http")) href = urlSemArquiNoFinal + href; | |
794 | + href = href.replace(" ", "%20").replace("//", "/").replace(":/", "://"); | |
795 | + webAgent = WebAgent.from(href).withGetRequest().execute(); | |
391 | 796 | |
392 | - String content = WebAgent.from(href.replace(" ", "%20")).withGetRequest().execute().getContent(); | |
393 | - | |
394 | - if (content!=null && !content.contains("a:hover") && !content.contains("a:focus")){ | |
395 | - occurrences.add(buildOccurrence("4.4", true, link.toString(), link, "1")); | |
797 | + if(webAgent.getStatusCode() != 404) | |
798 | + { | |
799 | + content = webAgent.getContent(); | |
800 | + passivelDeAvaliacao = true; | |
801 | + if (content!=null && content.contains("a:hover") && content.contains("a:focus")){ | |
802 | + | |
803 | + focoEncontrado = true; | |
396 | 804 | break; |
805 | + | |
397 | 806 | } |
807 | + | |
808 | + } | |
809 | + | |
398 | 810 | } |
399 | 811 | |
400 | 812 | } |
813 | + } | |
814 | + | |
815 | + if(!focoEncontrado && passivelDeAvaliacao) | |
816 | + { | |
817 | + occurrences.add(buildOccurrence("4.4", true, getDocument().getFirstStartTag().toString(), getDocument().getFirstElement(), "1")); | |
818 | + } | |
401 | 819 | Collections.sort(occurrences); |
402 | 820 | |
403 | 821 | return occurrences; |
404 | 822 | } |
405 | 823 | |
406 | - private Occurrence buildOccurrence(String code, boolean error, | |
407 | - String tag, Element element, | |
408 | - String criterio) { | |
824 | + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element, String criterio) { | |
409 | 825 | return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.PRESENTATION_DESIGN,criterio); |
410 | 826 | } |
411 | 827 | |
412 | 828 | |
413 | - private Occurrence buildOccurrence(String code, boolean error, | |
414 | - String tag, Element element) { | |
829 | + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element) { | |
415 | 830 | return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.PRESENTATION_DESIGN); |
416 | 831 | } |
417 | 832 | ... | ... |