Commit 888cec6daff793e6a4ada7d0268b373349ffac3e

Authored by Carlos Vieira
1 parent 1d42ee73
Exists in master

Nova versão do avaliador-api

.classpath
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<classpath>
3   - <classpathentry kind="src" output="target/classes" path="src/main/java">
4   - <attributes>
5   - <attribute name="optional" value="true"/>
6   - <attribute name="maven.pomderived" value="true"/>
7   - </attributes>
8   - </classpathentry>
9   - <classpathentry kind="src" output="target/test-classes" path="src/test/java">
10   - <attributes>
11   - <attribute name="optional" value="true"/>
12   - <attribute name="maven.pomderived" value="true"/>
13   - </attributes>
14   - </classpathentry>
15   - <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
16   - <attributes>
17   - <attribute name="maven.pomderived" value="true"/>
18   - <attribute name="org.eclipse.jst.component.nondependency" value=""/>
19   - </attributes>
20   - </classpathentry>
21   - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
22   - <attributes>
23   - <attribute name="owner.project.facets" value="java"/>
24   - </attributes>
25   - </classpathentry>
26   - <classpathentry kind="output" path="target/classes"/>
27   -</classpath>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<classpath>
  3 + <classpathentry kind="src" output="target/classes" path="src/main/java">
  4 + <attributes>
  5 + <attribute name="optional" value="true"/>
  6 + <attribute name="maven.pomderived" value="true"/>
  7 + </attributes>
  8 + </classpathentry>
  9 + <classpathentry kind="src" output="target/test-classes" path="src/test/java">
  10 + <attributes>
  11 + <attribute name="optional" value="true"/>
  12 + <attribute name="maven.pomderived" value="true"/>
  13 + </attributes>
  14 + </classpathentry>
  15 + <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
  16 + <attributes>
  17 + <attribute name="maven.pomderived" value="true"/>
  18 + <attribute name="org.eclipse.jst.component.nondependency" value=""/>
  19 + </attributes>
  20 + </classpathentry>
  21 + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
  22 + <attributes>
  23 + <attribute name="maven.pomderived" value="true"/>
  24 + </attributes>
  25 + </classpathentry>
  26 + <classpathentry kind="output" path="target/classes"/>
  27 +</classpath>
... ...
.gitignore
... ... @@ -0,0 +1 @@
  1 +target/**
... ...
.settings/org.eclipse.jdt.core.prefs
1 1 eclipse.preferences.version=1
2 2 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3   -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4   -org.eclipse.jdt.core.compiler.compliance=1.8
  3 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
  4 +org.eclipse.jdt.core.compiler.compliance=1.5
5 5 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6 6 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7   -org.eclipse.jdt.core.compiler.source=1.8
  7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
  8 +org.eclipse.jdt.core.compiler.source=1.5
... ...
.settings/org.eclipse.wst.common.project.facet.core.xml
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<faceted-project>
3   - <installed facet="jst.utility" version="1.0"/>
4   - <installed facet="java" version="1.8"/>
5   -</faceted-project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<faceted-project>
  3 + <installed facet="jst.utility" version="1.0"/>
  4 + <installed facet="java" version="1.5"/>
  5 +</faceted-project>
... ...
lombok.jar
No preview for this file type
pom.xml
... ... @@ -31,11 +31,11 @@
31 31 <version>3.0</version>
32 32 </dependency>
33 33  
34   - <dependency>
35   - <groupId>org.projectlombok</groupId>
36   - <artifactId>lombok</artifactId>
37   - <version>1.16.12</version>
38   - <scope>provided</scope>
  34 + <dependency>
  35 + <groupId>org.projectlombok</groupId>
  36 + <artifactId>lombok</artifactId>
  37 + <version>0.12.0</version>
  38 + <scope>provided</scope>
39 39 </dependency>
40 40  
41 41 <dependency>
... ...
src/main/java/br/com/checker/emag/core/BehaviorEvaluation.java
... ... @@ -117,7 +117,10 @@ public class BehaviorEvaluation extends Evaluation {
117 117  
118 118  
119 119 private List<Occurrence> checkRecommendation10() {
120   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
  120 +
  121 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  122 +
  123 + try {
121 124  
122 125 for (Element element : getDocument().getAllElements()) {
123 126  
... ... @@ -197,7 +200,9 @@ public class BehaviorEvaluation extends Evaluation {
197 200 }
198 201 }
199 202 }
200   -
  203 + } catch (Exception e) {
  204 + e.printStackTrace();
  205 + }
201 206 return occurrences;
202 207 }
203 208  
... ... @@ -205,7 +210,7 @@ public class BehaviorEvaluation extends Evaluation {
205 210  
206 211 private List<Occurrence> checkRecommendation11() {
207 212 List<Occurrence> occurrences = new ArrayList<Occurrence>();
208   -
  213 +try {
209 214 // boolean script = false;
210 215 // boolean contAlter = false;
211 216  
... ... @@ -283,13 +288,16 @@ public class BehaviorEvaluation extends Evaluation {
283 288 *
284 289 * }
285 290 */
286   -
  291 +} catch (Exception e) {
  292 + e.printStackTrace();
  293 +}
287 294 return occurrences;
288 295 }
289 296  
290 297 private List<Occurrence> checkRecommendation12() {
291 298 List<Occurrence> occurrences = new ArrayList<Occurrence>();
292 299  
  300 + try {
293 301 boolean temMetaRefresh = false;
294 302 for (Element element : getDocument().getAllElements("meta")) {
295 303 Attribute httpEquiv = element.getAttributes().get("http-equiv");
... ... @@ -304,13 +312,16 @@ public class BehaviorEvaluation extends Evaluation {
304 312 * if(!temMetaRefresh) occurrences.add(new Occurrence("2.3", false,
305 313 * this.getDocument().getFirstElement().toString(),OccurrenceClassification.BEHAVIOR));
306 314 */
307   -
  315 + } catch (Exception e) {
  316 + e.printStackTrace();
  317 + }
308 318 return occurrences;
309 319 }
310 320  
311 321 private List<Occurrence> checkRecommendation13() {
312 322 List<Occurrence> occurrences = new ArrayList<Occurrence>();
313 323  
  324 + try {
314 325 for (Element element : getDocument().getAllElements("meta")) {
315 326 Attribute content = element.getAttributes().get("content");
316 327 Attribute httpEquiv = element.getAttributes().get("http-equiv");
... ... @@ -323,12 +334,18 @@ public class BehaviorEvaluation extends Evaluation {
323 334 && url == true)
324 335 occurrences.add(this.buildOccurrence("2.4", true, element.toString(), element, "1"));
325 336 }
326   -
  337 + } catch (Exception e) {
  338 + e.printStackTrace();
  339 + }
327 340 return occurrences;
328 341 }
329 342  
330 343 private List<Occurrence> checkRecommendation14() {
331 344 List<Occurrence> occurrences = new ArrayList<Occurrence>();
  345 +
  346 + try {
  347 +
  348 +
332 349 boolean hasBlink = false;
333 350 boolean hasMarquee = false;
334 351 for (Element blink : getDocument().getAllElements("blink")) {
... ... @@ -345,14 +362,17 @@ public class BehaviorEvaluation extends Evaluation {
345 362 occurrences.add(new Occurrence("2.5", false, getDocument().getFirstElement().toString(),
346 363 OccurrenceClassification.BEHAVIOR, "1"));
347 364 }
348   -
  365 +
  366 + } catch (Exception e) {
  367 + e.printStackTrace();
  368 + }
349 369 return occurrences;
350 370 }
351 371  
352 372 private List<Occurrence> checkRecommendation15() {
353 373 List<Occurrence> occurrences = new ArrayList<Occurrence>();
354 374  
355   -
  375 +try {
356 376 for (Element blink : getDocument().getAllElements("blink")) {
357 377 occurrences.add(this.buildOccurrence("2.6", true, blink.toString(), blink, "1"));
358 378 }
... ... @@ -377,12 +397,14 @@ public class BehaviorEvaluation extends Evaluation {
377 397 occurrences.add(this.buildOccurrence("2.6", false, img.toString(), img, "3"));
378 398 }
379 399 }
380   -
  400 +} catch (Exception e) {
  401 + e.printStackTrace();
  402 +}
381 403 return occurrences;
382 404 }
383 405  
384 406 private boolean isTagForm(Element element) {
385   -
  407 +try {
386 408 List<String> tagsForm = new ArrayList<String>();
387 409 tagsForm.add("form");
388 410 tagsForm.add("input");
... ... @@ -399,15 +421,24 @@ public class BehaviorEvaluation extends Evaluation {
399 421  
400 422 if (element != null)
401 423 return tagsForm.contains(element.getName());
402   -
  424 +
  425 +} catch (Exception e) {
  426 + e.printStackTrace();
  427 +}
403 428 return false;
404 429 }
405 430  
406 431  
407 432 private List<Occurrence> checkRecommendation16() {
408 433 List<Occurrence> occurrences = new ArrayList<Occurrence>();
  434 +
  435 + try {
  436 +
409 437 occurrences.add(new Occurrence("2.7", false, getDocument().getFirstElement().toString(),
410 438 OccurrenceClassification.BEHAVIOR));
  439 + } catch (Exception e) {
  440 + e.printStackTrace();
  441 + }
411 442 return occurrences;
412 443 }
413 444  
... ...
src/main/java/br/com/checker/emag/core/ContentEvaluation.java
... ... @@ -11,9 +11,14 @@ import java.util.Comparator;
11 11 import java.util.HashMap;
12 12 import java.util.List;
13 13 import java.util.Map;
  14 +import java.util.concurrent.ExecutorService;
  15 +import java.util.concurrent.Executors;
  16 +import java.util.concurrent.TimeUnit;
14 17 import java.util.regex.Matcher;
15 18 import java.util.regex.Pattern;
16 19  
  20 +import javax.validation.constraints.Max;
  21 +
17 22 import net.htmlparser.jericho.Attribute;
18 23 import net.htmlparser.jericho.Element;
19 24 import net.htmlparser.jericho.Source;
... ... @@ -34,6 +39,9 @@ import br.com.checker.emag.util.UrlSemArquiNoFinal;
34 39  
35 40 public class ContentEvaluation extends Evaluation {
36 41  
  42 + private List<Occurrence> occurrencesLinks;
  43 + private Element linkThread;
  44 +
37 45 public ContentEvaluation(Source document) {
38 46 super(document);
39 47 }
... ... @@ -198,6 +206,7 @@ public class ContentEvaluation extends Evaluation {
198 206 private List<Occurrence> checkRecommendation17() {
199 207 List<Occurrence> occurrences = new ArrayList<Occurrence>();
200 208  
  209 + try {
201 210 Element html = getDocument().getFirstElement("html");
202 211  
203 212 if (html != null) {
... ... @@ -224,7 +233,7 @@ public class ContentEvaluation extends Evaluation {
224 233 // Caso seja diferente de html5
225 234 if (!doctype.equalsIgnoreCase("<!DOCTYPEhtml>")) {
226 235  
227   - if (xmlLang == null || lang == null) {
  236 + if (xmlLang == null && lang == null) {
228 237 occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
229 238 }
230 239 } else {
... ... @@ -251,13 +260,17 @@ public class ContentEvaluation extends Evaluation {
251 260 * false, html.toString(), html, "2")); }
252 261 */
253 262 }
254   -
  263 + } catch (Exception e) {
  264 + e.printStackTrace();
  265 + }
255 266 return occurrences;
256 267 }
257 268  
258 269 private List<Occurrence> checkRecommendation18() {
259 270 List<Occurrence> occurrences = new ArrayList<Occurrence>();
260 271  
  272 + try {
  273 +
261 274 for (Element element : getDocument().getAllElements()) {
262 275 if (!element.getName().equals("html")) {
263 276  
... ... @@ -269,7 +282,9 @@ public class ContentEvaluation extends Evaluation {
269 282 occurrences.add(this.buildOccurrence("3.2", false, element.toString(), element, "1"));
270 283 }
271 284 }
272   -
  285 + } catch (Exception e) {
  286 + e.printStackTrace();
  287 + }
273 288 return occurrences;
274 289 }
275 290  
... ... @@ -277,19 +292,24 @@ public class ContentEvaluation extends Evaluation {
277 292  
278 293 Element titulo = getDocument().getFirstElement("title");
279 294  
  295 +
280 296 String titulo_site = "";
281   -
  297 +try {
282 298 if (titulo != null) {
283 299  
284 300 titulo_site = titulo.getContent().getTextExtractor().toString();
285 301 }
286   -
  302 + } catch (Exception e) {
  303 + e.printStackTrace();
  304 + }
287 305 return titulo_site;
288 306 }
289 307  
290 308 private List<Occurrence> checkRecommendation19() {
291 309 List<Occurrence> occurrences = new ArrayList<Occurrence>();
292 310  
  311 + try {
  312 +
293 313 // Element head = getDocument().getFirstElement("head");
294 314  
295 315 // if(head == null) {
... ... @@ -312,6 +332,10 @@ public class ContentEvaluation extends Evaluation {
312 332 occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1"));
313 333 }
314 334 // }
  335 +
  336 + } catch (Exception e) {
  337 + e.printStackTrace();
  338 + }
315 339  
316 340 return occurrences;
317 341 }
... ... @@ -323,83 +347,130 @@ public class ContentEvaluation extends Evaluation {
323 347 return occurrences;
324 348 }
325 349  
326   - private List<Occurrence> checkRecommendation21() {
327   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
328   - UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal();
329   -
330   - String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal.urlSemArquivoNoFinal(getUrl());
331   -
332   - Element LinkComImg;
333   -
  350 +
  351 +
  352 +
  353 + private List<Occurrence> checkRecommendation21() {
  354 + occurrencesLinks = new ArrayList<Occurrence>();
  355 +
  356 + try {
  357 + ExecutorService executor = Executors.newFixedThreadPool(30);
334 358  
335 359 for (Element link : getDocument().getAllElements("a")) {
336   - String href = link.getAttributeValue("href");
337   - String title = link.getAttributeValue("title");
338   - String content = link.getContent().toString();
339   -
340   - if (hasEqualsContentHref(link) && isRegistroBr(content))
341   - occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "2"));
  360 +
  361 + try {
  362 + if(link.getAttributeValue("href").startsWith("http") || link.getAttributeValue("href").startsWith("www"))
  363 + {
  364 + try {
  365 +
  366 +
  367 + Runnable worker = new WorkerThread(link);
  368 + executor.execute(worker);
  369 + } catch (Exception e) {
  370 + e.printStackTrace();
  371 + }
342 372  
343   - LinkComImg = link.getFirstElement("img");
344   -
345   - if (LinkComImg == null) {
346   - if (!hasContent(link)) {
347   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "3"));// "2"));
348 373 }
349   - } else {
350   - if (hasLinkComImgWithoutAlt(link)) {
351   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "3"));// "2"));
352   - }
353   - }
354   -
355   - if (LinkComImg == null) {
356   - // if(hasTitle(link) && isNotAlt(link))
357   - if (hasTitle(link) && !hasContent(link))
358   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "4"));// "3"));
359   - } else {
360   - // if(hasTitle(link) && isNotAlt(link))
361   - if (hasTitle(link) && !hasContent(link) && hasLinkComImgWithoutAlt(link))
362   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "4"));// "3"));
363   - }
364   -
365   - /*
366   - * if(!hasTitle(link) && !hasContent(link) && hasImgWithoutAlt(link))
367   - * occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"4"));
368   - */
369   -
370   - if (hasImgWithoutAlt(link))
371   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "5"));// "4"));
372   -
373   - if (hasLeiaMaisDescription(link))
374   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "6"));// "5"));
375   -
376   - if (hasDiferenteContentSameLink(link))
377   - occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "10"));// "6"));
378   -
379   - if (isTitleEqualsContent(link))
380   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "12"));// "8"));
381   -
382   - if (hasSameContentDiferentLink(link))
383   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "11"));// "7"));
384   -
385   - if (link != null && hasLongContent(link))
386   - occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "13"));// "9"));
387   -
388   - String retorno = "";
389   - if (link != null)
390   - retorno = isLinkUnavailable(link, urlSemArquiNoFinal);
391   - if (retorno.equalsIgnoreCase("erro")) {
392   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link, "14"));// "10"));
393   - } else if (retorno.equalsIgnoreCase("aviso")) {
394   - occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "15"));// "10"));
395   - }
396   -
  374 + } catch (Exception e) {
  375 + e.printStackTrace();
  376 + }
  377 +
  378 +
  379 + executor.shutdown();
  380 +
  381 + executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
397 382 }
398   - return occurrences;
399   - }
400   -
  383 + } catch (InterruptedException e) {
  384 + e.printStackTrace();
  385 + }
  386 + //while (!executor.isTerminated()) {
  387 + // }
  388 + return occurrencesLinks;
  389 + }
  390 +
  391 + private void checkRecomendationComThread(Element link)
  392 + {
  393 + try {
  394 +
  395 +
  396 + UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal();
  397 +
  398 + String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal.urlSemArquivoNoFinal(getUrl());
  399 +
  400 +
  401 +
  402 + Element LinkComImg;
  403 + String href = link.getAttributeValue("href");
  404 + String title = link.getAttributeValue("title");
  405 + String content = link.getContent().toString();
  406 +
  407 +
  408 +
  409 +
  410 + if (hasEqualsContentHref(link) && isRegistroBr(content))
  411 + occurrencesLinks.add(this.buildOccurrence("3.5", false, link.toString(), link, "2"));
  412 +
  413 + LinkComImg = link.getFirstElement("img");
  414 +
  415 + if (LinkComImg == null) {
  416 + if (!hasContent(link)) {
  417 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "3"));// "2"));
  418 + }
  419 + } else {
  420 + if (hasLinkComImgWithoutAlt(link)) {
  421 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "3"));// "2"));
  422 + }
  423 + }
  424 +
  425 + if (LinkComImg == null) {
  426 + // if(hasTitle(link) && isNotAlt(link))
  427 + if (hasTitle(link) && !hasContent(link))
  428 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "4"));// "3"));
  429 + } else {
  430 + // if(hasTitle(link) && isNotAlt(link))
  431 + if (hasTitle(link) && !hasContent(link) && hasLinkComImgWithoutAlt(link))
  432 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "4"));// "3"));
  433 + }
  434 +
  435 + /*
  436 + * if(!hasTitle(link) && !hasContent(link) && hasImgWithoutAlt(link))
  437 + * occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link,"4"));
  438 + */
  439 +
  440 + if (hasImgWithoutAlt(link))
  441 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "5"));// "4"));
  442 +
  443 + if (hasLeiaMaisDescription(link))
  444 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "6"));// "5"));
  445 +
  446 + if (hasDiferenteContentSameLink(link))
  447 + occurrencesLinks.add(this.buildOccurrence("3.5", false, link.toString(), link, "10"));// "6"));
  448 +
  449 + if (isTitleEqualsContent(link))
  450 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "12"));// "8"));
  451 +
  452 + if (hasSameContentDiferentLink(link))
  453 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "11"));// "7"));
  454 +
  455 + if (link != null && hasLongContent(link))
  456 + occurrencesLinks.add(this.buildOccurrence("3.5", false, link.toString(), link, "13"));// "9"));
  457 +
  458 + String retorno = "";
  459 + if (link != null)
  460 + retorno = isLinkUnavailable(link, urlSemArquiNoFinal);
  461 + if (retorno.equalsIgnoreCase("erro")) {
  462 + occurrencesLinks.add(this.buildOccurrence("3.5", true, link.toString(), link, "14"));// "10"));
  463 + } else if (retorno.equalsIgnoreCase("aviso")) {
  464 + occurrencesLinks.add(this.buildOccurrence("3.5", false, link.toString(), link, "15"));// "10"));
  465 + }
  466 +
  467 + } catch (Exception e) {
  468 + e.printStackTrace();
  469 + }
  470 + }
  471 +
401 472 private String isLinkUnavailable(Element link, String url) {
402   -
  473 +try {
403 474 String href = link.getAttributeValue("href");
404 475  
405 476 if (href != null && href.startsWith("www")) {
... ... @@ -434,7 +505,6 @@ public class ContentEvaluation extends Evaluation {
434 505 HttpMethod metodoRequisicaoGET = null;
435 506 HttpClient clienteHTTPJakartaCommons;
436 507 URL UrlConvertida;
437   -
438 508  
439 509 codResponse = verificarConexao(href, "http.agent", "Jakarta Commons-HttpClient/3.1");
440 510 if (codResponse != 200) {
... ... @@ -454,6 +524,9 @@ public class ContentEvaluation extends Evaluation {
454 524  
455 525 }
456 526 }
  527 +} catch (Exception e) {
  528 + e.printStackTrace();
  529 +}
457 530 return "false";
458 531 }
459 532  
... ... @@ -484,8 +557,7 @@ public class ContentEvaluation extends Evaluation {
484 557 new DefaultHttpMethodRetryHandler(3, false));
485 558 clienteHTTPJakartaCommons.getParams().setParameter("http.protocol.allow-circular-redirects",
486 559 true);
487   - clienteHTTPJakartaCommons.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT,
488   - new Integer(2000));
  560 + clienteHTTPJakartaCommons.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, new Integer(2000));
489 561  
490 562  
491 563 metodoRequisicao = new HeadMethod(UrlConvertida.toExternalForm());// GetMethod(UrlConvertida.toExternalForm());// URLEncoder.encode(UrlConvertida.toExternalForm(),
... ... @@ -550,6 +622,7 @@ public class ContentEvaluation extends Evaluation {
550 622  
551 623 temConteudo = StringUtils.isNotBlank(link.getContent().getTextExtractor().toString());
552 624  
  625 + try {
553 626 if (!temConteudo) {
554 627 for (Element elemento : link.getAllElements()) {
555 628 temConteudo = StringUtils.isNotBlank(elemento.getContent().getTextExtractor().toString());
... ... @@ -559,6 +632,11 @@ public class ContentEvaluation extends Evaluation {
559 632 }
560 633 }
561 634 }
  635 +
  636 + } catch (Exception e) {
  637 + e.printStackTrace();
  638 + }
  639 +
562 640 return temConteudo;
563 641  
564 642 /*
... ... @@ -581,6 +659,8 @@ public class ContentEvaluation extends Evaluation {
581 659 boolean temImgSemAlt = false;
582 660  
583 661 String alt;
  662 +
  663 + try {
584 664  
585 665 for (Element elementoImagem : link.getAllElements("img")) {
586 666  
... ... @@ -590,7 +670,9 @@ public class ContentEvaluation extends Evaluation {
590 670 break;
591 671 }
592 672 }
593   -
  673 + } catch (Exception e) {
  674 + e.printStackTrace();
  675 + }
594 676 return temImgSemAlt;
595 677 }
596 678  
... ... @@ -609,6 +691,7 @@ public class ContentEvaluation extends Evaluation {
609 691 link.getFirstElement("img") != null ? link.getFirstElement("img").getAttributeValue("alt")
610 692 : "";
611 693  
  694 + try {
612 695 for (String leiaMais : this.leiaMais) {
613 696  
614 697 if (title != null)
... ... @@ -633,7 +716,9 @@ public class ContentEvaluation extends Evaluation {
633 716 *
634 717 * if(altImg!=null) if(pattern.matcher(altImg.toLowerCase()).find()) return true; }
635 718 */
636   -
  719 + } catch (Exception e) {
  720 + e.printStackTrace();
  721 + }
637 722 return false;
638 723 }
639 724  
... ... @@ -738,6 +823,9 @@ public class ContentEvaluation extends Evaluation {
738 823 }
739 824  
740 825 private List<Occurrence> checkRecommendation22() {
  826 +
  827 + occurrencesLinks = null;
  828 +
741 829 List<Occurrence> occurrences = new ArrayList<Occurrence>();
742 830  
743 831 String[] parts = null;
... ... @@ -1047,4 +1135,33 @@ public class ContentEvaluation extends Evaluation {
1047 1135 return occurrences;
1048 1136 }
1049 1137  
  1138 +
  1139 + public class WorkerThread implements Runnable {
  1140 +
  1141 + private Element linkThead;
  1142 +
  1143 + public WorkerThread(Element link){
  1144 + this.linkThead= link;
  1145 + }
  1146 +
  1147 + public void run() {
  1148 + processCommand();
  1149 + }
  1150 +
  1151 + private void processCommand() {
  1152 + try {
  1153 + Thread.sleep(1000);
  1154 +
  1155 + checkRecomendationComThread(this.linkThead);
  1156 +
  1157 + } catch (InterruptedException e) {
  1158 + e.printStackTrace();
  1159 + }
  1160 + }
  1161 +
  1162 +
  1163 + }
1050 1164 }
  1165 +
  1166 +
  1167 +
... ...
src/main/java/br/com/checker/emag/core/FormEvaluation.java
... ... @@ -93,6 +93,7 @@ public class FormEvaluation extends Evaluation{
93 93 private List<Occurrence> checkRecommendation38() {
94 94 List<Occurrence> occurrences = new ArrayList<Occurrence>();
95 95  
  96 + try {
96 97 for (Element input : this.getDocument().getAllElements("input")) {
97 98 Attribute type = input.getAttributes().get("type");
98 99 if (type != null) {
... ... @@ -126,12 +127,17 @@ public class FormEvaluation extends Evaluation{
126 127 }
127 128 }
128 129 }
  130 + } catch (Exception e) {
  131 + e.printStackTrace();
  132 + }
129 133 return occurrences;
130 134 }
131 135  
132 136 private List<Occurrence> checkRecommendation39() {
133 137 List<Occurrence> occurrences = new ArrayList<Occurrence>();
134 138  
  139 +try {
  140 +
135 141 for (Element form : this.getDocument().getAllElements("form")) {
136 142 /*for (Element label : form.getAllElements("label")) {
137 143 Attribute attrFor = label.getAttributes().get("for");
... ... @@ -228,6 +234,9 @@ public class FormEvaluation extends Evaluation{
228 234  
229 235 }
230 236  
  237 +} catch (Exception e) {
  238 + e.printStackTrace();
  239 +}
231 240 return occurrences;
232 241 }
233 242  
... ... @@ -245,6 +254,9 @@ public class FormEvaluation extends Evaluation{
245 254  
246 255 private List<Occurrence> checkRecommendation41() {
247 256 List<Occurrence> occurrences = new ArrayList<Occurrence>();
  257 +
  258 + try {
  259 +
248 260 String[] eventos1 = {"onchange", "onblur","onfocus", "onformchange",
249 261 "onforminput","oninput","oninvalid","onreset",
250 262 "onselect","onsubmit","onkeydown","onkeypress",
... ... @@ -294,7 +306,9 @@ public class FormEvaluation extends Evaluation{
294 306 }
295 307  
296 308 this.oder(occurrences);
297   -
  309 + } catch (Exception e) {
  310 + e.printStackTrace();
  311 + }
298 312 return occurrences;
299 313 }
300 314  
... ... @@ -331,6 +345,8 @@ public class FormEvaluation extends Evaluation{
331 345 private List<Occurrence> checkRecommendation44() {
332 346 List<Occurrence> occurrences = new ArrayList<Occurrence>();
333 347  
  348 + try {
  349 +
334 350 for (Element form : this.getDocument().getAllElements("form")) {
335 351  
336 352 //String tagForm = form.getStartTag()+"</form>";
... ... @@ -362,6 +378,10 @@ public class FormEvaluation extends Evaluation{
362 378 }
363 379 }
364 380  
  381 + } catch (Exception e) {
  382 + e.printStackTrace();
  383 + }
  384 +
365 385 return occurrences;
366 386 }
367 387  
... ... @@ -377,7 +397,14 @@ public class FormEvaluation extends Evaluation{
377 397  
378 398 private List<Occurrence> checkRecommendation45() {
379 399 List<Occurrence> occurrences = new ArrayList<Occurrence>();
  400 +
  401 + try {
  402 +
  403 +
380 404 occurrences.add(new Occurrence("6.8", false, getDocument().getFirstElement().toString(),OccurrenceClassification.FORM));
  405 + } catch (Exception e) {
  406 + e.printStackTrace();
  407 + }
381 408 return occurrences;
382 409 }
383 410  
... ...
src/main/java/br/com/checker/emag/core/MarkEvaluation.java
1 1 package br.com.checker.emag.core;
2 2  
3   -
4 3 import java.net.URL;
5 4 import java.net.URLEncoder;
6 5 import java.util.ArrayList;
... ... @@ -27,1141 +26,1127 @@ import com.google.gson.GsonBuilder;
27 26  
28 27 public class MarkEvaluation extends Evaluation {
29 28  
30   - // private static String CSS_VALIDATOR_URL =
31   - // "http://www.css-validator.org/validator?uri=#{url}&warning=0&output=soap12";
32   - private static String CSS_VALIDATOR_URL = "http://jigsaw.w3.org/css-validator/validator?uri=#{url}&warning=0&output=soap12";
33   - private static String HTML_VALIDATOR_URL = "https://validator.w3.org/check?uri=#{url}&output=json";
34   -
35   - private MarkEvaluation(Source document) {
36   - super(document);
37   - }
38   -
39   - private MarkEvaluation(Source document, String url) {
40   -
41   - super(document, url);
42   - }
43   -
44   - public static class MarkEvaluationBuilder extends EvaluationBuilder {
45   -
46   - @Override
47   - protected MarkEvaluation with(Source document) {
48   - return new MarkEvaluation(document);
49   - }
50   -
51   - @Override
52   - protected MarkEvaluation with(Source document, String url) {
53   - return new MarkEvaluation(document, url);
54   - }
55   -
56   - public SpecificRecommendation recommendation1() {
57   - return new EvaluationRecommendation1();
58   - }
59   -
60   - public SpecificRecommendation recommendation2() {
61   - return new EvaluationRecommendation2();
62   - }
63   -
64   - public SpecificRecommendation recommendation3() {
65   - return new EvaluationRecommendation3();
66   - }
67   -
68   - public SpecificRecommendation recommendation4() {
69   - return new EvaluationRecommendation4();
70   - }
71   -
72   - public SpecificRecommendation recommendation5() {
73   - return new EvaluationRecommendation5();
74   - }
75   -
76   - public SpecificRecommendation recommendation6() {
77   - return new EvaluationRecommendation6();
78   - }
79   -
80   - public SpecificRecommendation recommendation7() {
81   - return new EvaluationRecommendation7();
82   - }
83   -
84   - public SpecificRecommendation recommendation8() {
85   - return new EvaluationRecommendation8();
86   - }
87   -
88   - public SpecificRecommendation recommendation9() {
89   - return new EvaluationRecommendation9();
90   - }
91   - }
92   -
93   - protected static class EvaluationRecommendation1 extends MarkRecommendation {
94   - protected List<Occurrence> check() {
95   - return getEvaluation().checkRecommendation1();
96   - }
97   - }
98   -
99   - protected static class EvaluationRecommendation2 extends MarkRecommendation {
100   - protected List<Occurrence> check() {
101   - return getEvaluation().checkRecommendation2();
102   - }
103   - }
104   -
105   - protected static class EvaluationRecommendation3 extends MarkRecommendation {
106   - protected List<Occurrence> check() {
107   - return getEvaluation().checkRecommendation3();
108   - }
109   - }
110   -
111   - protected static class EvaluationRecommendation4 extends MarkRecommendation {
112   - protected List<Occurrence> check() {
113   - return getEvaluation().checkRecommendation4();
114   - }
115   - }
116   -
117   - protected static class EvaluationRecommendation5 extends MarkRecommendation {
118   - protected List<Occurrence> check() {
119   - return getEvaluation().checkRecommendation5();
120   - }
121   - }
122   -
123   - protected static class EvaluationRecommendation6 extends MarkRecommendation {
124   - protected List<Occurrence> check() {
125   - return getEvaluation().checkRecommendation6();
126   - }
127   - }
128   -
129   - protected static class EvaluationRecommendation7 extends MarkRecommendation {
130   - protected List<Occurrence> check() {
131   - return getEvaluation().checkRecommendation7();
132   - }
133   - }
134   -
135   - protected static class EvaluationRecommendation8 extends MarkRecommendation {
136   - protected List<Occurrence> check() {
137   - return getEvaluation().checkRecommendation8();
138   - }
139   - }
140   -
141   - protected static class EvaluationRecommendation9 extends MarkRecommendation {
142   - protected List<Occurrence> check() {
143   - return getEvaluation().checkRecommendation9();
144   - }
145   - }
146   -
147   - public List<Occurrence> check() {
148   - getOccurrences().addAll(checkRecommendation1());
149   - getOccurrences().addAll(checkRecommendation2());
150   - getOccurrences().addAll(checkRecommendation3());
151   - getOccurrences().addAll(checkRecommendation4());
152   - getOccurrences().addAll(checkRecommendation5());
153   - getOccurrences().addAll(checkRecommendation6());
154   - getOccurrences().addAll(checkRecommendation7());
155   - getOccurrences().addAll(checkRecommendation8());
156   - getOccurrences().addAll(checkRecommendation9());
157   -
158   - return getOccurrences();
159   - }
160   -
161   - private List<Occurrence> checkRecommendation1() {
162   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
163   -
164   - String url = getUrl();
165   - if (url != null) {
166   -
167   - int[] errosWarningsCss = getErrorCount(true, url);
168   - int[] errosWarningsHtml = getErrorCount(false, url);
169   - int avisoHtml = 0;
170   - int errosHtml = 0;
171   - int avisoCss = 0;
172   - int errosCss = 0;
173   -
174   -
175   - avisoHtml = errosWarningsHtml[1];
176   -
177   - if (avisoHtml > 0)
178   - {
179   - for(;avisoHtml > 0; avisoHtml--)
180   - {
181   - occurrences.add(buildOccurrence("1.1", false, url,
182   - getDocument().getFirstElement(), "7"));//"1"));
183   - }
184   - }
185   -
186   - /*if (errosWarningsHtml[1] > 0)
187   - System.out.println(errosWarningsHtml[1]);
188   -
189   - occurrences.add(buildOccurrence("1.1", false, url,
190   - getDocument().getFirstElement(), "1"));*/
191   -
192   - avisoCss = errosWarningsCss[1];
193   -
194   - if (avisoCss > 0)
195   - {
196   - for(;avisoCss > 0; avisoCss--)
197   - {
198   - occurrences.add(buildOccurrence("1.1", false, url,
199   - getDocument().getFirstElement().getFirstElement(), "8"));//"2"));
200   - }
201   - }
202   - /*if (errosWarningsCss[1] > 0)
203   - System.out.println(errosWarningsCss[1]);
204   - occurrences
205   - .add(buildOccurrence("1.1", false, url, getDocument()
206   - .getFirstElement().getFirstElement(), "2"));*/
207   -
208   - errosHtml = errosWarningsHtml[0];
209   -
210   - if (errosHtml > 0)
211   - {
212   - for(;errosHtml > 0; errosHtml--)
213   - {
214   - occurrences.add(buildOccurrence("1.1", true, url, getDocument()
215   - .getFirstElement(), "1"));
216   - }
217   - }
218   - /*if (errosWarningsHtml[0] > 0)
219   - System.out.println(errosWarningsHtml[0]);
220   - occurrences.add(buildOccurrence("1.1", true, url, getDocument()
221   - .getFirstElement(), "1"));*/
222   -
223   - errosCss = errosWarningsCss[0];
224   -
225   - if (errosCss > 0)
226   - {
227   - for(;errosCss > 0; errosCss--)
228   - {
229   - occurrences.add(buildOccurrence("1.1", true, url, getDocument()
230   - .getFirstElement().getFirstElement(), "2"));
231   - }
232   - }
233   - /*if (errosWarningsCss[0] > 0)
234   - System.out.println(errosWarningsCss[0]);
235   - occurrences.add(buildOccurrence("1.1", true, url, getDocument()
236   - .getFirstElement().getFirstElement(), "2"));*/
237   - }
238   -
239   - for (Element element : getDocument().getAllElements()) {
240   - String value = element.getAttributeValue("style");
241   -
242   - if (value != null)
243   - occurrences.add(this.buildOccurrence("1.1", false,
244   - element.toString(), element, "3"));
245   - }
246   -
247   - for (Element element : getDocument().getAllElements("style")) {
248   -
249   - if (element != null)
250   - occurrences.add(this.buildOccurrence("1.1", false,
251   - element.toString(), element, "4"));
252   - }
253   -
254   - List<String> eventos = new ArrayList<String>(Arrays.asList("onclick",
255   - "ondblclick"));
256   -
257   - for (Element element : getDocument().getAllElements()) {
258   - if (element.getAttributes() != null) {
259   - // String script =
260   - // element.getAttributes().getTextExtractor().toString();
261   - for (Attribute attribute : element.getAttributes()) {
262   - if (eventos.contains(attribute.getName()))
263   - occurrences.add(this.buildOccurrence("1.1", false,
264   - element.toString(), element, "5"));
265   - }
266   -
267   - /*
268   - * if(script.contains("javascript")){
269   - * occurrences.add(this.buildOccurrence("1.1", false,
270   - * element.toString(), element, "5")); }
271   - */
272   - }
273   - }
274   -
275   - for (Element element : getDocument().getAllElements("script")) {
276   -
277   - if (element != null) {
278   -
279   - if (!element.getContent().getTextExtractor().toString().trim()
280   - .equalsIgnoreCase("")) {
281   - occurrences.add(this.buildOccurrence("1.1", false,
282   - element.toString(), element, "6"));
283   -
284   - }
285   -
286   - }
287   - }
288   -
289   - this.oder(occurrences);
290   -
291   - return occurrences;
292   - }
293   -
294   - private boolean hasContent(Element elementoHTML) {
295   -
296   - boolean temConteudo;
297   -
298   -
299   - temConteudo = StringUtils.isNotBlank(elementoHTML.getContent().getTextExtractor().toString());
300   -
301   - if(!temConteudo)
302   - {
303   - for (Element elemento : elementoHTML.getAllElements()) {
304   - temConteudo = StringUtils.isNotBlank(elemento.getContent().getTextExtractor().toString());
305   -
306   - if(temConteudo)
307   - {
308   - break;
309   - }
310   - }
311   - }
312   - return temConteudo;
313   -
314   - }
315   -
316   - private List<Occurrence> checkRecommendation2() {
317   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
318   -
319   - List<String> tags = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6",
320   - "a", "p","label");
321   - List<Integer> linhasImg = new ArrayList<Integer>();
322   -
323   - for (String tag : tags) {
324   - for (Element element : getDocument().getAllElements(tag)) {
325   -
326   - /*
327   - * if(element.getAttributes().getCount()==0)
328   - * occurrences.add(this.buildOccurrence("1.2", true,
329   - * element.toString(), element, "1")); else
330   - */
331   -
332   - if (element != null) {
333   - String endTag = element.getEndTag() == null ? "" : element
334   - .getEndTag().toString();
335   -
336   - Element img = element.getFirstElement("img");
337   -
338   - if (img != null) {
339   - if (img.getAttributes().get("alt") != null
340   - && img.getAttributes().get("alt").getValue()
341   - .isEmpty()) {
342   -
343   - if (!linhasImg.contains(this.getRow(img))) {
344   - occurrences.add(this.buildOccurrence("1.2",
345   - true, img.getStartTag().toString(),
346   - img, "3"));//"1"));
347   - }
348   - linhasImg.add(this.getRow(img));
349   - }
350   - } else {
351   -
352   - if (!hasContent(element)) {
353   - occurrences.add(this.buildOccurrence("1.2", true,
354   - element.toString(),
355   - element, "3"));//"1"));
356   - //element.getStartTag().toString() + endTag,
357   - //element, "3"));//"1"));
358   - }
359   - }
360   - }
361   - }
362   - }
363   -
364   - linhasImg = new ArrayList<Integer>();
365   -
366   - tags = Arrays.asList("!doctype", "script", "meta", "style", "head",
367   - "link", "h1", "h2", "h3", "h4", "h5", "h6", "a", "p", "input");
368   -
369   - for (Element element : getDocument().getAllElements()) {
370   - if (!tags.contains(element.getName())) {
371   -
372   - if (element != null && !(element.getName().equals("!--"))) {
373   -
374   - String endTag = element.getEndTag() == null ? "" : element
375   - .getEndTag().toString();
376   -
377   - Element img = element.getFirstElement("img");
378   -
379   - if (img != null) {
380   - if (img.getAttributes().get("alt") != null
381   - && img.getAttributes().get("alt").getValue()
382   - .isEmpty()) {
383   -
384   - if (!linhasImg.contains(this.getRow(img))) {
385   - occurrences.add(this.buildOccurrence("1.2",
386   - false, img.toString(), img, "2")); //"1"));
387   - }
388   -
389   - linhasImg.add(this.getRow(img));
390   - }
391   -
392   - } else {
393   - if (!element.getStartTag().toString().replace(" ", "").equalsIgnoreCase("<br>") && !element.getStartTag().toString().replace(" ", "").equalsIgnoreCase("</br>")) {
394   -
395   - if (!hasContent(element)) {
396   - occurrences.add(this.buildOccurrence("1.2",
397   - false, element.toString(), element, "2"));
398   - //+ endTag, element, "2"));//"1"));
399   - //element.getStartTag().toString()
400   - //+ endTag, element, "2"));//"1"));
401   - }
402   - }
403   - }
404   - }
405   - }
406   - }
407   -
408   - this.oder(occurrences);
409   -
410   - /*
411   - * boolean isError = false; for (Element element :
412   - * getDocument().getAllElements()) { Attributes attribute =
413   - * element.getAttributes();
414   - *
415   - * isError = tags.contains(element.getName());
416   - *
417   - *
418   - * if(element.isEmpty()) occurrences.add(this.buildOccurrence("1.2",
419   - * isError, element.toString(), element, "1")); else
420   - * if(attribute.getCount()==0)
421   - * occurrences.add(this.buildOccurrence("1.2", isError,
422   - * element.toString(), element, "1")); }
423   - */
424   -
425   - return occurrences;
426   - }
427   -
428   - private List<Occurrence> checkRecommendation3() {
429   -
430   - // CRITERIO 4
431   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
432   -
433   - int count = getDocument().getAllElements("h1").size();
434   -
435   - if (count > 1) {
436   - for (Element element : getDocument().getAllElements("h1")) {
437   -
438   - occurrences.add(this.buildOccurrence("1.3", true,
439   - element.toString(), element, "6"));//"4"));
440   - }
441   - }
442   -
443   - /*
444   - * if(count>0) occurrences.add(this.buildOccurrence("1.3",
445   - * true,getDocument().getFirstElement("h1").toString(),
446   - * getDocument().getFirstElement("h1"), "4"));
447   - */
448   -
449   - // CRITERIO 3
450   - boolean hasOtherH = false;
451   - for (Element element : getDocument().getAllElements()) {
452   - if (element.getName().matches("h[2-6]")) {
453   - hasOtherH = true;
454   - break;
455   - }
456   - }
457   -
458   - if (count > 0 && !hasOtherH)
459   - occurrences.add(this.buildOccurrence("1.3", false, getDocument()
460   - .getFirstElement("h1").toString(), getDocument()
461   - .getFirstElement("h1"), "4"));//"3"));
462   -
463   - // CRITERIO 2
464   -
465   - /*
466   - * String[] tags = {"h6","h5","h4","h3","h2","h1"}; //String[] tags =
467   - * {"h1","h2","h3","h4","h5","h6"};
468   - *
469   - *
470   - * for(int index = 0 ; index< tags.length ; index++){
471   - *
472   - * for(Element h : getDocument().getAllElements(tags[index])) {
473   - * if(!hasCorrectHierarchy(index, tags))
474   - * occurrences.add(this.buildOccurrence("1.3", true,h.toString(), h,
475   - * "2")); } }
476   - */
477   -
478   - List<Element> elementsObj = getDocument().getAllElements();
479   -
480   - int anterior = 0;
481   - for (Element htmlElement : elementsObj) {
482   - if (htmlElement.getName().matches("h[1-6]")) {
483   - int tagId = Integer.parseInt(htmlElement.getName().substring(1));
484   - if (!(tagId <= anterior)) {
485   - if (!(tagId -1 == anterior))
486   - {
487   - occurrences.add(this.buildOccurrence("1.3", true,
488   - htmlElement.toString(), htmlElement, "2"));
489   - }
490   -
491   - }
492   - anterior = tagId;
493   -
494   -
495   - }
496   - }
497   -
498   -
499   -
500   - if (!hasH())
501   - occurrences.add(this.buildOccurrence("1.3", true, "Observa&ccedil;&atilde;o - Sem fonte (os n&iacute;veis de t&iacute;tulo n&atilde;o foram utilizados)",
502   - getDocument().getFirstElement(), "1"));
503   -
504   - // Sorting
505   - Collections.sort(occurrences, new Comparator<Occurrence>() {
506   - public int compare(Occurrence occurrence1, Occurrence occurrence2) {
507   - return occurrence1.getLine().compareTo(occurrence2.getLine());
508   - }
509   - });
510   -
511   - return occurrences;
512   - }
513   -
514   - private int verificarNiveis(Integer posicao, List<String> tags) {
515   - for (int i = 0; i < posicao; i++) {
516   - if (Integer.parseInt(tags.get(i).substring(1)) == Integer
517   - .parseInt(tags.get(posicao).substring(1)) - 1) {
518   - return Integer.parseInt(tags.get(i).substring(1));
519   - }
520   - }
521   - return -1;
522   - }
523   -
524   - private boolean hasCorrectHierarchy(int index, String[] tags) {
525   -
526   - for (int i = index + 1; i < tags.length; i++) {
527   - if (getDocument().getFirstElement(tags[i]) == null)
528   - return false;
529   - }
530   - return true;
531   - }
532   -
533   - private boolean hasH() {
534   -
535   - String[] tags = { "h6", "h5", "h4", "h3", "h2", "h1" };
536   - for (String h : tags) {
537   - if (getDocument().getFirstElement(h) != null)
538   - return true;
539   - }
540   -
541   - return false;
542   - }
543   -
544   - /* No documento NÃO PERMITE VERIFICAÇÃO AUTOMATIZADA */
545   - private List<Occurrence> checkRecommendation4() {
546   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
547   -
548   - for (Element link : this.getDocument().getAllElements("a")) {
549   - Attribute tabIndex = link.getAttributes().get("tabindex");
550   - if (tabIndex != null) {
551   - occurrences.add(this.buildOccurrence("1.4", false,
552   - link.toString(), link, "3"));//"2"));
553   -
554   - if (rangeIncorretoTabeIndex(tabIndex))
555   - occurrences.add(this.buildOccurrence("1.4", false,
556   - link.toString(), link, "6"));//"3"));
557   - }
558   - }
559   -
560   - for (Element input : this.getDocument().getAllElements("input")) {
561   -
562   - Attribute tabIndex = input.getAttributes().get("tabindex");
563   - if (tabIndex != null)
564   - occurrences.add(this.buildOccurrence("1.4", false,
565   - input.toString(), input, "3"));//"2"));
566   -
567   - if (rangeIncorretoTabeIndex(tabIndex))
568   - occurrences.add(this.buildOccurrence("1.4", false,
569   - input.toString(), input, "6"));//"3"));
570   - }
571   -
572   - for (Element select : this.getDocument().getAllElements("select")) {
573   -
574   - Attribute tabIndex = select.getAttributes().get("tabindex");
575   - if (tabIndex != null)
576   - occurrences.add(this.buildOccurrence("1.4", false,
577   - select.toString(), select, "3"));//"2"));
578   -
579   - if (rangeIncorretoTabeIndex(tabIndex))
580   - occurrences.add(this.buildOccurrence("1.4", false,
581   - select.toString(), select, "6"));//"3"));
582   - }
583   -
584   - for (Element textarea : this.getDocument().getAllElements("textarea")) {
585   -
586   - Attribute tabIndex = textarea.getAttributes().get("tabindex");
587   - if (tabIndex != null)
588   - occurrences.add(this.buildOccurrence("1.4", false,
589   - textarea.toString(), textarea, "3"));//"2"));
590   -
591   - if (rangeIncorretoTabeIndex(tabIndex))
592   - occurrences.add(this.buildOccurrence("1.4", false,
593   - textarea.toString(), textarea, "6"));//"3"));
594   - }
595   -
596   - /*
597   - * Element section = this.getDocument().getFirstElement("section");
598   - *
599   - * if(section !=null){
600   - *
601   - * int firstSectionRow = this.getRow(section); for(Element nav :
602   - * this.getDocument().getAllElements("nav")){ if(this.getRow(nav) <
603   - * firstSectionRow) occurrences.add(this.buildOccurrence("1.4",
604   - * false,nav.toString(), nav, "1")); } }
605   - */
606   -
607   - List<Integer> verificadsos = new ArrayList<Integer>();
608   - for (Element nav : this.getDocument().getAllElements("nav")) {
609   - if (nav != null) {
610   - int firstNavRow = this.getRow(nav);
611   -
612   - for (Element section : this.getDocument().getAllElements(
613   - "section")) {
614   -
615   - if (firstNavRow < this.getRow(section)) {
616   - if (!verificadsos.contains(this.getRow(section))) {
617   - occurrences.add(this.buildOccurrence("1.4", false,
618   - section.getStartTag().toString(), section,
619   - "1"));
620   - verificadsos.add(this.getRow(section));
621   - }
622   -
623   - }
624   - }
625   - }
626   - }
627   -
628   - return occurrences;
629   - }
630   -
631   - private boolean rangeIncorretoTabeIndex(Attribute tabIndex) {
632   - try {
633   - Integer value = Integer.valueOf(tabIndex.getValue());
634   - if (value < 0 || value > 32767)
635   - return true;
636   - } catch (Exception e) {
637   - return false;
638   - }
639   - return false;
640   - }
641   -
642   - private List<Occurrence> checkRecommendation5() {
643   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
644   -
645   - /*
646   - * Element firstLink = getDocument().getFirstElement("href",
647   - * Pattern.compile("#.*"));
648   - *
649   - * if(firstLink != null) occurrences.add(this.buildOccurrence("1.5",
650   - * false, firstLink.toString(), firstLink, "4"));
651   - */
652   -
653   - for (Element link : getDocument().getAllElements("a")) {
654   - String contLink = link.getAttributeValue("href");
655   - if (contLink != null && contLink.length() > 1
656   - && !contLink.substring(0, 1).equals("#")) {
657   - occurrences.add(this.buildOccurrence("1.5", true,
658   - link.toString(), link, "9"));//"4"));
659   - }
660   -
661   - break;
662   - }
663   -
664   - /*
665   - * if(firstLink == null){ occurrences.add(this.buildOccurrence("1.5",
666   - * false, getDocument().getFirstElement().toString(),
667   - * getDocument().getFirstElement(), "4")); } else
668   - * if(firstLink.getAttributeValue("href") == null ||
669   - * !firstLink.getAttributeValue("href").contains("#")){
670   - * occurrences.add(this.buildOccurrence("1.5", false,
671   - * firstLink.toString(), firstLink, "4")); }
672   - */
673   -
674   - boolean existAcessKey = false;
675   -
676   - for (Element area : getDocument().getAllElements("area")) {
677   - if (hasAcessKey(area))
678   - existAcessKey = true;
679   - /*
680   - * if(!hasAcessKey(area))
681   - * occurrences.add(this.buildOccurrence("1.5", true,
682   - * area.toString(), area, "3"));
683   - */
684   - }
685   -
686   - if (!existAcessKey)
687   - for (Element button : getDocument().getAllElements("button")) {
688   - if (hasAcessKey(button))
689   - existAcessKey = true;
690   - /*
691   - * if(!hasAcessKey(button))
692   - * occurrences.add(this.buildOccurrence("1.5", true,
693   - * button.toString(), button, "3"));
694   - */
695   - }
696   -
697   - if (!existAcessKey)
698   - for (Element input : getDocument().getAllElements("input")) {
699   - if (hasAcessKey(input))
700   - existAcessKey = true;
701   - /*
702   - * if(!hasAcessKey(input))
703   - * occurrences.add(this.buildOccurrence("1.5", true,
704   - * input.toString(), input, "3"));
705   - */
706   - }
707   -
708   - if (!existAcessKey)
709   - for (Element label : getDocument().getAllElements("label")) {
710   - if (hasAcessKey(label))
711   - existAcessKey = true;
712   - /*
713   - * if(!hasAcessKey(label))
714   - * occurrences.add(this.buildOccurrence("1.5", true,
715   - * label.toString(), label, "3"));
716   - */
717   - }
718   -
719   - if (!existAcessKey)
720   - for (Element legend : getDocument().getAllElements("legend")) {
721   - if (hasAcessKey(legend))
722   - existAcessKey = true;
723   - /*
724   - * if(!hasAcessKey(legend))
725   - * occurrences.add(this.buildOccurrence("1.5", true,
726   - * legend.toString(), legend, "3"));
727   - */
728   - }
729   -
730   - if (!existAcessKey)
731   - for (Element textarea : getDocument().getAllElements("textarea")) {
732   - if (hasAcessKey(textarea))
733   - existAcessKey = true;
734   - /*
735   - * if(!hasAcessKey(textarea))
736   - * occurrences.add(this.buildOccurrence("1.5", true,
737   - * textarea.toString(), textarea, "3"));
738   - */
739   - }
740   -
741   - String href;
742   - boolean existAnchor = false;
743   -
744   - for (Element link : getDocument().getAllElements("a")) {
745   - href = link.getAttributeValue("href");
746   -
747   - /*
748   - * if(href != null && (href.length() > 1 &&
749   - * !href.substring(0,2).equals("?#"))){
750   - * ///occurrences.add(this.buildOccurrence("1.5", true,
751   - * link.toString(), link, "2")); if(!(href.length()==1 &&
752   - * href.substring(1).equals("#"))) if(href.substring(1).equals("#")
753   - * && !this.hasLinkSemAncora(href))
754   - * occurrences.add(this.buildOccurrence("1.5", true,
755   - * link.toString(), link, "2")); }
756   - */
757   -
758   - if (href != null && href.length() > 1
759   - && !href.substring(0, 2).equals("?#")) {
760   - if (href.substring(0, 1).equals("#"))
761   - if (!this.hasLinkRefAncora(link))
762   - occurrences.add(this.buildOccurrence("1.5", true,
763   - link.toString(), link, "2"));
764   - }
765   -
766   - /*
767   - * if(href != null && href.contains("#"))
768   - * if(!hasAnchor(href.substring(1)))
769   - * occurrences.add(this.buildOccurrence("1.5", true,
770   - * link.toString(), link, "2"));
771   - */
772   - /*
773   - * }else{ occurrences.add(this.buildOccurrence("1.5", true,
774   - * link.toString(), link, "1")); }
775   - */
776   -
777   - // if(href != null && href.contains("#"))
778   -
779   - /*
780   - * if(href != null && href.length() == 1 &&
781   - * href.toString().equals("#")) existAnchor = true;
782   - */
783   - if (href != null && href.contains("#"))
784   - existAnchor = true;
785   -
786   - if (hasAcessKey(link))
787   - existAcessKey = true;
788   -
789   - /*
790   - * if(!hasAcessKey(link))
791   - * occurrences.add(this.buildOccurrence("1.5", true,
792   - * link.toString(), link, "3"));
793   - */
794   - }
795   -
796   - if (!existAnchor)
797   - occurrences
798   - .add(this
799   - .buildOccurrence(
800   - "1.5",
801   - true,
802   - "Observa&ccedil;&atilde;o - Sem fonte (n&atilde;o foram encontrados &acirc;ncoras que permitam saltar pelas diferentes se&ccedil;&otilde;es da p&aacute;gina)",
803   - getDocument().getFirstElement(), "1"));
804   -
805   - if (!existAcessKey)
806   - occurrences
807   - .add(this
808   - .buildOccurrence(
809   - "1.5",
810   - true,
811   - "Observa&ccedil;&atilde;o - Sem fonte ( n&atilde;o existe(m) accesskey(s) na página)",
812   - getDocument().getFirstElement(), "4"));//"3"));
813   -
814   - for (Element elemento : getDocument().getAllElements("accesskey",
815   - Pattern.compile(".*"))) {
816   - if (duplicatedAcessKey(elemento))
817   - occurrences.add(this.buildOccurrence("1.5", false,
818   - elemento.toString(), elemento, "11"));//"5"));
819   - }
820   -
821   - this.oder(occurrences);
822   -
823   - return occurrences;
824   - }
825   -
826   - private boolean hasLinkRefAncora(Element link) {
827   - boolean existeAncora = false;
828   - String href = link.getAttributeValue("href");
829   - String ancora = href.substring(1, href.length());
830   -
831   - for (Element a : getDocument().getAllElements()) {
832   - if (a.getAttributeValue("id") != null
833   - && a.getAttributeValue("id").equals(ancora)) {
834   - existeAncora = true;
835   - }
836   - if (a.getAttributeValue("name") != null
837   - && a.getAttributeValue("name").equals(ancora)) {
838   - existeAncora = true;
839   - }
840   - }
841   -
842   - return existeAncora;
843   - }
844   -
845   - private boolean hasAcessKey(Element element) {
846   - String acessKey = element.getAttributeValue("accesskey");
847   -
848   - return StringUtils.isNotBlank(acessKey);
849   - }
850   -
851   - private boolean hasAnchor(String href) {
852   -
853   - String id, name;
854   -
855   - for (Element element : getDocument().getAllElements()) {
856   - id = element.getAttributeValue("id");
857   - name = element.getAttributeValue("name");
858   -
859   - if (href.equals(id) || href.equals(name))
860   - return true;
861   - }
862   -
863   - return false;
864   - }
865   -
866   - private boolean duplicatedAcessKey(Element element) {
867   - String value = element.getAttributeValue("accesskey");
868   -
869   - for (Element elementToCompare : getDocument().getAllElements(
870   - "accesskey", Pattern.compile(".*"))) {
871   - String acessKey = elementToCompare.getAttributeValue("accesskey");
872   - if (acessKey.equals(value)
873   - && elementToCompare.getBegin() != element.getBegin())
874   - return true;
875   -
876   - }
877   -
878   - return false;
879   - }
880   -
881   - public List<Occurrence> checkRecommendation6() {
882   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
883   -
884   - for (Element table : getDocument().getAllElements("table"))
885   - occurrences.add(this.buildOccurrence("1.6", false, table
886   - .getStartTag().toString(), table, "1"));
887   -
888   - int firstFormRow = 0;
889   -
890   - List<Integer> linhasOcorrForm = new ArrayList<Integer>();
891   -
892   - for (Element table : getDocument().getAllElements("table")) {
893   - // Element tagsForm = table.getFirstElement("form");
894   -
895   - Element form = table.getContent().getFirstElement("form");
896   -
897   - if (form != null) {
898   - firstFormRow = this.getRow(form);
899   - if (!linhasOcorrForm.contains(firstFormRow)) {
900   - occurrences.add(this.buildOccurrence("1.6", true, form
901   - .getStartTag().toString(), form, "2"));
902   - linhasOcorrForm.add(firstFormRow);
903   - }
904   - }
905   -
906   - }
907   -
908   - return occurrences;
909   - }
910   -
911   - public List<Occurrence> checkRecommendation7() {
912   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
913   - List<Element> element = getDocument().getAllElements();
914   -
915   - int pos = 1;
916   - int end = 0;
917   - int begin = 0;
918   - Element firstElement = null;
919   - Element secondElement = null;
920   - for (int i = 0; i < element.size() - 1; i++) {
921   - firstElement = element.get(i);
922   - secondElement = element.get(pos);
923   - if (firstElement.getEndTag() != null
924   - && firstElement.getName().equals("a"))
925   - end = firstElement.getEndTag().getEnd();
926   - begin = secondElement.getStartTag().getBegin();
927   - if (element.get(i).getName().equals(element.get(pos).getName())
928   - && (end == begin)) {
929   - occurrences.add(this.buildOccurrence("1.7", true, element
930   - .get(i).toString() + " " + element.get(pos).toString(),
931   - element.get(i), "1"));
932   - }
933   - pos++;
934   - }
935   -
936   - return occurrences;
937   - }
938   -
939   -
940   - public List<Occurrence> checkRecommendation8() {
941   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
942   - Element firstElement = this.getDocument().getFirstElement();
943   -
944   - if (firstElement.toString().replace(" ", "").equalsIgnoreCase("<!DOCTYPEhtml>")) {
945   -
946   - Element header = getDocument().getFirstElement("header");
947   - Element nav = getDocument().getFirstElement("nav");
948   - Element section = getDocument().getFirstElement("section");
949   - Element footer = getDocument().getFirstElement("footer");
950   -
951   - if (header == null)
952   - occurrences.add(this.buildOccurrence("1.8",false,"Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <HEADER>)",
953   - getDocument().getFirstElement(), "3"));//"1"));
954   -
955   - if (nav == null)
956   - occurrences.add(this.buildOccurrence("1.8",false,"Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <NAV>)",
957   - getDocument().getFirstElement(), "3"));//"1"));
958   -
959   - if (section == null)
960   - occurrences.add(this.buildOccurrence("1.8",false,"Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <SECTION>)",
961   - getDocument().getFirstElement(), "3"));//"1"));
962   -
963   - if (footer == null)
964   - occurrences.add(this.buildOccurrence("1.8",false,"Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <FOOTER>)",
965   - getDocument().getFirstElement(), "3"));
966   -
967   - } else {
968   -
969   - boolean hasBanner = false;
970   - boolean hasNavigation = false;
971   - boolean hasMain = false;
972   - for (Element element : getDocument().getAllElements()) {
973   - String role = element.getAttributeValue("role");
974   -
975   - if (role != null && "banner".equals(role.toLowerCase()))
976   - hasBanner = true;
977   -
978   - if (role != null && "navigation".equals(role.toLowerCase()))
979   - hasNavigation = true;
980   -
981   - if (role != null && "main".equals(role.toLowerCase()))
982   - hasMain = true;
983   -
984   - if (hasBanner && hasNavigation && hasMain)
985   - break;
986   - }
987   -/*//comentado por Gibran
988   - *
989   - if (!hasBanner)
990   - occurrences
991   - .add(this
992   - .buildOccurrence(
993   - "1.8",
994   - false,
995   - "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do BANNER)",
996   - getDocument().getFirstElement(), "2"));
997   -
998   - if (!hasNavigation)
999   - occurrences
1000   - .add(this
1001   - .buildOccurrence(
1002   - "1.8",
1003   - false,
1004   - "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do NAVIGATION)",
1005   - getDocument().getFirstElement(), "2"));
1006   -
1007   - if (!hasMain)
1008   - occurrences
1009   - .add(this
1010   - .buildOccurrence(
1011   - "1.8",
1012   - false,
1013   - "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do MAIN)",
1014   - getDocument().getFirstElement(), "2"));*/ //comentado por Gibran
1015   -
1016   - }
1017   -
1018   - return occurrences;
1019   - }
1020   -
1021   - public List<Occurrence> checkRecommendation9() {
1022   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
1023   - boolean hasBlankLink = false;
1024   -
1025   - for (Element link : getDocument().getAllElements("a")) {
1026   -
1027   - if (link.toString().contains("_blank")) {
1028   - hasBlankLink = true;
1029   - occurrences.add(this.buildOccurrence("1.9", false,
1030   - link.toString(), link, "1"));
1031   - }
1032   - }
1033   -
1034   - /*
1035   - * if(!hasBlankLink) occurrences.add(new Occurrence("1.9",
1036   - * false,this.getDocument
1037   - * ().getFirstElement().toString(),OccurrenceClassification.MARK));
1038   - */
1039   -
1040   - return occurrences;
1041   - }
1042   -
1043   - private List<Occurrence> oder(List<Occurrence> occurrences) {
1044   - // Sorting
1045   - Collections.sort(occurrences, new Comparator<Occurrence>() {
1046   - public int compare(Occurrence occurrence1, Occurrence occurrence2) {
1047   - return occurrence1.getLine().compareTo(occurrence2.getLine());
1048   - }
1049   - });
1050   - return occurrences;
1051   - }
1052   -
1053   - private Occurrence buildOccurrence(String code, boolean error, String tag,
1054   - Element element, String criterio) {
1055   - return super.buildOccurrence(code, error, tag, element,
1056   - OccurrenceClassification.MARK, criterio);
1057   - }
1058   -
1059   -
1060   -
1061   - public int[] getErrorCount(boolean isCss, String url) {
1062   - int errors = 0;
1063   - int warnings = 0;
1064   - URL UrlConvertida;
1065   -
1066   -
1067   - try {
1068   - UrlConvertida = new URL(url);
1069   -
1070   -
1071   - if (isCss) {
1072   -
1073   - String content = WebAgent.from(CSS_VALIDATOR_URL.replace("#{url}", URLEncoder.encode(UrlConvertida.toExternalForm(), "UTF-8"))).withGetRequest().execute().getContent();
1074   -
1075   - Matcher m = Pattern.compile("<m:errorcount>(\\d)*</m:errorcount>",Pattern.MULTILINE).matcher(content);
1076   - if (m.find())
1077   - errors = Integer.valueOf(m.group(0).replace("<m:errorcount>", "").replace("</m:errorcount>", ""));
1078   -
1079   - m = Pattern.compile("<m:warningcount>(\\d)*</m:warningcount>", Pattern.MULTILINE).matcher(content);
1080   -
1081   - if (m.find())
1082   - warnings = Integer.valueOf(m.group(0).replace("<m:warningcount>", "").replace("</m:warningcount>", ""));
1083   -
1084   - } else {
1085   -
1086   - String content = WebAgent.from(HTML_VALIDATOR_URL.replace("#{url}", URLEncoder.encode(UrlConvertida.toExternalForm(), "UTF-8"))).withGetRequest().execute().getContent();
1087   - Gson g = new GsonBuilder().create();
1088   - HtmlValidation a = g.fromJson(content, HtmlValidation.class);
1089   - int[] errorsWarnings = a.getQtdWarningsErros();
1090   - errors = errorsWarnings[1];
1091   - warnings = errorsWarnings[0];
1092   -
1093   - }
1094   - } catch (Exception e) {
1095   -
1096   - e.printStackTrace();
1097   - }
1098   -
1099   - return new int[] { errors, warnings };
1100   - }
1101   -
1102   - public OccurrenceClassification type() {
1103   - return OccurrenceClassification.MARK;
1104   - }
1105   -
1106   - public class HtmlValidation {
1107   -
1108   - List<Message> messages = new ArrayList<HtmlValidation.Message>();
1109   -
1110   - public List<Message> getMessages() {
1111   - return messages;
1112   - }
1113   -
1114   - public void setMessages(List<Message> messages) {
1115   - this.messages = messages;
1116   - }
1117   -
1118   - public int[] getQtdWarningsErros() {
1119   - int warnings = 0;
1120   - int erros = 0;
1121   - for (Message message : this.messages) {
1122   - if (message.isError())
1123   - erros++;
1124   - else if (message.isWarning())
1125   - warnings++;
1126   - }
1127   -
1128   - return new int[] { warnings, erros };
1129   - }
1130   -
1131   - public HtmlValidation() {
1132   - }
1133   -
1134   - public class Message {
1135   -
1136   - private String type;
1137   -
1138   - private String subType;
1139   -
1140   - public String getType() {
1141   - return type;
1142   - }
1143   -
1144   - public void setType(String type) {
1145   - this.type = type;
1146   - }
1147   -
1148   - public String getSubType() {
1149   - return subType;
1150   - }
1151   -
1152   - public void setSubType(String subType) {
1153   - this.subType = subType;
1154   - }
1155   -
1156   - public boolean isWarning() {
1157   - return "info".equals(type) && "warning".equals(this.subType);
1158   - }
1159   -
1160   - public boolean isError() {
1161   - return "error".equals(this.type);
1162   - }
  29 + // private static String CSS_VALIDATOR_URL =
  30 + // "http://www.css-validator.org/validator?uri=#{url}&warning=0&output=soap12";
  31 + private static String CSS_VALIDATOR_URL = "http://jigsaw.w3.org/css-validator/validator?uri=#{url}&profile=css3svg&warning=0&output=soap12";
  32 + // private static String CSS_VALIDATOR_URL =
  33 + // "http://189.9.137.162:8080/css-validator/validator?uri=#{url}&warning=0&output=soap12";
  34 + //private static String CSS_VALIDATOR_URL ="http://css.ases.nuvem.gov.br:8080/validator?uri=#{url}&warning=0&output=soap12";
  35 +
  36 + // private static String CSS_VALIDATOR_URL =
  37 + // "http://189.9.137.162:8080/cssvalidator/css-validator/validator?uri=#{url}&warning=0&output=soap12";
  38 + private static String HTML_VALIDATOR_URL = "https://validator.w3.org/check?uri=#{url}&output=json";
  39 + //private static String HTML_VALIDATOR_URL = "http://html.ases.nuvem.gov.br:8080/w3c-validator/check?uri=#{url}&output=json";
  40 +
  41 + private MarkEvaluation(Source document) {
  42 + super(document);
  43 + }
  44 +
  45 + private MarkEvaluation(Source document, String url) {
  46 +
  47 + super(document, url);
  48 + }
  49 +
  50 + public static class MarkEvaluationBuilder extends EvaluationBuilder {
  51 +
  52 + @Override
  53 + protected MarkEvaluation with(Source document) {
  54 + return new MarkEvaluation(document);
  55 + }
  56 +
  57 + @Override
  58 + protected MarkEvaluation with(Source document, String url) {
  59 + return new MarkEvaluation(document, url);
  60 + }
  61 +
  62 + public SpecificRecommendation recommendation1() {
  63 + return new EvaluationRecommendation1();
  64 + }
  65 +
  66 + public SpecificRecommendation recommendation2() {
  67 + return new EvaluationRecommendation2();
  68 + }
  69 +
  70 + public SpecificRecommendation recommendation3() {
  71 + return new EvaluationRecommendation3();
  72 + }
  73 +
  74 + public SpecificRecommendation recommendation4() {
  75 + return new EvaluationRecommendation4();
  76 + }
  77 +
  78 + public SpecificRecommendation recommendation5() {
  79 + return new EvaluationRecommendation5();
  80 + }
  81 +
  82 + public SpecificRecommendation recommendation6() {
  83 + return new EvaluationRecommendation6();
  84 + }
  85 +
  86 + public SpecificRecommendation recommendation7() {
  87 + return new EvaluationRecommendation7();
  88 + }
  89 +
  90 + public SpecificRecommendation recommendation8() {
  91 + return new EvaluationRecommendation8();
  92 + }
  93 +
  94 + public SpecificRecommendation recommendation9() {
  95 + return new EvaluationRecommendation9();
  96 + }
  97 + }
  98 +
  99 + protected static class EvaluationRecommendation1 extends MarkRecommendation {
  100 + protected List<Occurrence> check() {
  101 + return getEvaluation().checkRecommendation1();
  102 + }
  103 + }
  104 +
  105 + protected static class EvaluationRecommendation2 extends MarkRecommendation {
  106 + protected List<Occurrence> check() {
  107 + return getEvaluation().checkRecommendation2();
  108 + }
  109 + }
  110 +
  111 + protected static class EvaluationRecommendation3 extends MarkRecommendation {
  112 + protected List<Occurrence> check() {
  113 + return getEvaluation().checkRecommendation3();
  114 + }
  115 + }
  116 +
  117 + protected static class EvaluationRecommendation4 extends MarkRecommendation {
  118 + protected List<Occurrence> check() {
  119 + return getEvaluation().checkRecommendation4();
  120 + }
  121 + }
  122 +
  123 + protected static class EvaluationRecommendation5 extends MarkRecommendation {
  124 + protected List<Occurrence> check() {
  125 + return getEvaluation().checkRecommendation5();
  126 + }
  127 + }
  128 +
  129 + protected static class EvaluationRecommendation6 extends MarkRecommendation {
  130 + protected List<Occurrence> check() {
  131 + return getEvaluation().checkRecommendation6();
  132 + }
  133 + }
  134 +
  135 + protected static class EvaluationRecommendation7 extends MarkRecommendation {
  136 + protected List<Occurrence> check() {
  137 + return getEvaluation().checkRecommendation7();
  138 + }
  139 + }
  140 +
  141 + protected static class EvaluationRecommendation8 extends MarkRecommendation {
  142 + protected List<Occurrence> check() {
  143 + return getEvaluation().checkRecommendation8();
  144 + }
  145 + }
  146 +
  147 + protected static class EvaluationRecommendation9 extends MarkRecommendation {
  148 + protected List<Occurrence> check() {
  149 + return getEvaluation().checkRecommendation9();
  150 + }
  151 + }
  152 +
  153 + public List<Occurrence> check() {
  154 + getOccurrences().addAll(checkRecommendation1());
  155 + getOccurrences().addAll(checkRecommendation2());
  156 + getOccurrences().addAll(checkRecommendation3());
  157 + getOccurrences().addAll(checkRecommendation4());
  158 + getOccurrences().addAll(checkRecommendation5());
  159 + getOccurrences().addAll(checkRecommendation6());
  160 + getOccurrences().addAll(checkRecommendation7());
  161 + getOccurrences().addAll(checkRecommendation8());
  162 + getOccurrences().addAll(checkRecommendation9());
  163 +
  164 + return getOccurrences();
  165 + }
  166 +
  167 + private List<Occurrence> checkRecommendation1() {
  168 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  169 +
  170 + try {
  171 +
  172 + String url = getUrl();
  173 + if (url != null) {
  174 +
  175 + int[] errosWarningsCss = getErrorCount(true, url);
  176 + int[] errosWarningsHtml = getErrorCount(false, url);
  177 + int avisoHtml = 0;
  178 + int errosHtml = 0;
  179 + int avisoCss = 0;
  180 + int errosCss = 0;
  181 +
  182 + avisoHtml = errosWarningsHtml[1];
  183 +
  184 + if (avisoHtml > 0) {
  185 + for (; avisoHtml > 0; avisoHtml--) {
  186 + occurrences.add(buildOccurrence("1.1", false, url, getDocument().getFirstElement(), "7"));// "1"));
  187 + }
  188 + }
  189 +
  190 + /*
  191 + * if (errosWarningsHtml[1] > 0) System.out.println(errosWarningsHtml[1]);
  192 + *
  193 + * occurrences.add(buildOccurrence("1.1", false, url,
  194 + * getDocument().getFirstElement(), "1"));
  195 + */
  196 +
  197 + avisoCss = errosWarningsCss[1];
  198 +
  199 + if (avisoCss > 0) {
  200 + for (; avisoCss > 0; avisoCss--) {
  201 + occurrences.add(buildOccurrence("1.1", false, url,
  202 + getDocument().getFirstElement().getFirstElement(), "8"));// "2"));
  203 + }
  204 + }
  205 + /*
  206 + * if (errosWarningsCss[1] > 0) System.out.println(errosWarningsCss[1]);
  207 + * occurrences .add(buildOccurrence("1.1", false, url, getDocument()
  208 + * .getFirstElement().getFirstElement(), "2"));
  209 + */
  210 +
  211 + errosHtml = errosWarningsHtml[0];
  212 +
  213 + if (errosHtml > 0) {
  214 + for (; errosHtml > 0; errosHtml--) {
  215 + occurrences.add(buildOccurrence("1.1", true, url, getDocument().getFirstElement(), "1"));
  216 + }
  217 + }
  218 + /*
  219 + * if (errosWarningsHtml[0] > 0) System.out.println(errosWarningsHtml[0]);
  220 + * occurrences.add(buildOccurrence("1.1", true, url, getDocument()
  221 + * .getFirstElement(), "1"));
  222 + */
  223 +
  224 + errosCss = errosWarningsCss[0];
  225 +
  226 + if (errosCss > 0) {
  227 + for (; errosCss > 0; errosCss--) {
  228 + occurrences.add(buildOccurrence("1.1", true, url,
  229 + getDocument().getFirstElement().getFirstElement(), "2"));
  230 + }
  231 + }
  232 + /*
  233 + * if (errosWarningsCss[0] > 0) System.out.println(errosWarningsCss[0]);
  234 + * occurrences.add(buildOccurrence("1.1", true, url, getDocument()
  235 + * .getFirstElement().getFirstElement(), "2"));
  236 + */
  237 + }
  238 +
  239 + for (Element element : getDocument().getAllElements()) {
  240 + String value = element.getAttributeValue("style");
  241 +
  242 + if (value != null)
  243 + occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "3"));
  244 + }
  245 +
  246 + for (Element element : getDocument().getAllElements("style")) {
  247 +
  248 + if (element != null)
  249 + occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "4"));
  250 + }
  251 +
  252 + List<String> eventos = new ArrayList<String>(Arrays.asList("onclick", "ondblclick"));
  253 +
  254 + for (Element element : getDocument().getAllElements()) {
  255 + if (element.getAttributes() != null) {
  256 + // String script =
  257 + // element.getAttributes().getTextExtractor().toString();
  258 + for (Attribute attribute : element.getAttributes()) {
  259 + if (eventos.contains(attribute.getName()))
  260 + occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "5"));
  261 + }
  262 +
  263 + /*
  264 + * if(script.contains("javascript")){
  265 + * occurrences.add(this.buildOccurrence("1.1", false, element.toString(),
  266 + * element, "5")); }
  267 + */
  268 + }
  269 + }
  270 +
  271 + for (Element element : getDocument().getAllElements("script")) {
  272 +
  273 + if (element != null) {
  274 +
  275 + if (!element.getContent().getTextExtractor().toString().trim().equalsIgnoreCase("")) {
  276 + occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "6"));
  277 +
  278 + }
  279 +
  280 + }
  281 + }
  282 +
  283 + this.oder(occurrences);
  284 +
  285 + } catch (Exception e) {
  286 + e.printStackTrace();
  287 + }
  288 + return occurrences;
  289 + }
  290 +
  291 + private boolean hasContent(Element elementoHTML) {
  292 +
  293 + boolean temConteudo;
  294 +
  295 + temConteudo = StringUtils.isNotBlank(elementoHTML.getContent().getTextExtractor().toString());
  296 +
  297 + try {
  298 +
  299 + if (!temConteudo) {
  300 + for (Element elemento : elementoHTML.getAllElements()) {
  301 + temConteudo = StringUtils.isNotBlank(elemento.getContent().getTextExtractor().toString());
  302 +
  303 + if (temConteudo) {
  304 + break;
  305 + }
  306 + }
  307 + }
  308 +
  309 + } catch (Exception e) {
  310 + e.printStackTrace();
  311 + }
  312 +
  313 + return temConteudo;
  314 +
  315 + }
  316 +
  317 + private List<Occurrence> checkRecommendation2() {
  318 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  319 +
  320 + try {
  321 +
  322 + List<String> tags = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "a", "p", "label");
  323 + List<Integer> linhasImg = new ArrayList<Integer>();
  324 +
  325 + for (String tag : tags) {
  326 + for (Element element : getDocument().getAllElements(tag)) {
  327 +
  328 + /*
  329 + * if(element.getAttributes().getCount()==0)
  330 + * occurrences.add(this.buildOccurrence("1.2", true, element.toString(),
  331 + * element, "1")); else
  332 + */
  333 +
  334 + if (element != null) {
  335 + String endTag = element.getEndTag() == null ? "" : element.getEndTag().toString();
  336 +
  337 + Element img = element.getFirstElement("img");
  338 +
  339 + if (img != null) {
  340 + if (img.getAttributes().get("alt") != null
  341 + && img.getAttributes().get("alt").getValue().isEmpty()) {
  342 +
  343 + if (!linhasImg.contains(this.getRow(img))) {
  344 + occurrences.add(
  345 + this.buildOccurrence("1.2", true, img.getStartTag().toString(), img, "3"));// "1"));
  346 + }
  347 + linhasImg.add(this.getRow(img));
  348 + }
  349 + } else {
  350 +
  351 + if (!hasContent(element)) {
  352 + occurrences.add(this.buildOccurrence("1.2", true, element.toString(), element, "3"));// "1"));
  353 + // element.getStartTag().toString() + endTag,
  354 + // element, "3"));//"1"));
  355 + }
  356 + }
  357 + }
  358 + }
  359 + }
  360 +
  361 + linhasImg = new ArrayList<Integer>();
  362 +
  363 + tags = Arrays.asList("!doctype", "script", "meta", "style", "head", "link", "h1", "h2", "h3", "h4", "h5",
  364 + "h6", "a", "p", "input");
  365 +
  366 + for (Element element : getDocument().getAllElements()) {
  367 + if (!tags.contains(element.getName())) {
  368 +
  369 + if (element != null && !(element.getName().equals("!--"))) {
  370 +
  371 + String endTag = element.getEndTag() == null ? "" : element.getEndTag().toString();
  372 +
  373 + Element img = element.getFirstElement("img");
  374 +
  375 + if (img != null) {
  376 + if (img.getAttributes().get("alt") != null
  377 + && img.getAttributes().get("alt").getValue().isEmpty()) {
  378 +
  379 + if (!linhasImg.contains(this.getRow(img))) {
  380 + occurrences.add(this.buildOccurrence("1.2", false, img.toString(), img, "2")); // "1"));
  381 + }
  382 +
  383 + linhasImg.add(this.getRow(img));
  384 + }
  385 +
  386 + } else {
  387 + if (!element.getStartTag().toString().replace(" ", "").equalsIgnoreCase("<br>")
  388 + && !element.getStartTag().toString().replace(" ", "").equalsIgnoreCase("</br>")) {
  389 +
  390 + if (!hasContent(element)) {
  391 + occurrences
  392 + .add(this.buildOccurrence("1.2", false, element.toString(), element, "2"));
  393 + // + endTag, element, "2"));//"1"));
  394 + // element.getStartTag().toString()
  395 + // + endTag, element, "2"));//"1"));
  396 + }
  397 + }
  398 + }
  399 + }
  400 + }
  401 + }
  402 +
  403 + this.oder(occurrences);
  404 +
  405 + /*
  406 + * boolean isError = false; for (Element element :
  407 + * getDocument().getAllElements()) { Attributes attribute =
  408 + * element.getAttributes();
  409 + *
  410 + * isError = tags.contains(element.getName());
  411 + *
  412 + *
  413 + * if(element.isEmpty()) occurrences.add(this.buildOccurrence("1.2", isError,
  414 + * element.toString(), element, "1")); else if(attribute.getCount()==0)
  415 + * occurrences.add(this.buildOccurrence("1.2", isError, element.toString(),
  416 + * element, "1")); }
  417 + */
  418 +
  419 + } catch (Exception e) {
  420 + e.printStackTrace();
  421 + }
  422 + return occurrences;
  423 + }
  424 +
  425 + private List<Occurrence> checkRecommendation3() {
  426 +
  427 + // CRITERIO 4
  428 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  429 +
  430 + try {
  431 +
  432 + int count = getDocument().getAllElements("h1").size();
  433 +
  434 + if (count > 1) {
  435 + for (Element element : getDocument().getAllElements("h1")) {
  436 +
  437 + occurrences.add(this.buildOccurrence("1.3", true, element.toString(), element, "6"));// "4"));
  438 + }
  439 + }
  440 +
  441 + /*
  442 + * if(count>0) occurrences.add(this.buildOccurrence("1.3",
  443 + * true,getDocument().getFirstElement("h1").toString(),
  444 + * getDocument().getFirstElement("h1"), "4"));
  445 + */
  446 +
  447 + // CRITERIO 3
  448 + boolean hasOtherH = false;
  449 + for (Element element : getDocument().getAllElements()) {
  450 + if (element.getName().matches("h[2-6]")) {
  451 + hasOtherH = true;
  452 + break;
  453 + }
  454 + }
  455 +
  456 + if (count > 0 && !hasOtherH)
  457 + occurrences.add(this.buildOccurrence("1.3", false, getDocument().getFirstElement("h1").toString(),
  458 + getDocument().getFirstElement("h1"), "4"));// "3"));
  459 +
  460 + // CRITERIO 2
  461 +
  462 + /*
  463 + * String[] tags = {"h6","h5","h4","h3","h2","h1"}; //String[] tags =
  464 + * {"h1","h2","h3","h4","h5","h6"};
  465 + *
  466 + *
  467 + * for(int index = 0 ; index< tags.length ; index++){
  468 + *
  469 + * for(Element h : getDocument().getAllElements(tags[index])) {
  470 + * if(!hasCorrectHierarchy(index, tags))
  471 + * occurrences.add(this.buildOccurrence("1.3", true,h.toString(), h, "2")); } }
  472 + */
  473 +
  474 + List<Element> elementsObj = getDocument().getAllElements();
  475 +
  476 + int anterior = 0;
  477 + for (Element htmlElement : elementsObj) {
  478 + if (htmlElement.getName().matches("h[1-6]")) {
  479 + int tagId = Integer.parseInt(htmlElement.getName().substring(1));
  480 + if (!(tagId <= anterior)) {
  481 + if (!(tagId - 1 == anterior)) {
  482 + occurrences
  483 + .add(this.buildOccurrence("1.3", true, htmlElement.toString(), htmlElement, "2"));
  484 + }
  485 +
  486 + }
  487 + anterior = tagId;
  488 +
  489 + }
  490 + }
  491 +
  492 + if (!hasH())
  493 + occurrences.add(this.buildOccurrence("1.3", true,
  494 + "Observa&ccedil;&atilde;o - Sem fonte (os n&iacute;veis de t&iacute;tulo n&atilde;o foram utilizados)",
  495 + getDocument().getFirstElement(), "1"));
  496 +
  497 + // Sorting
  498 + Collections.sort(occurrences, new Comparator<Occurrence>() {
  499 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  500 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  501 + }
  502 + });
  503 +
  504 + } catch (Exception e) {
  505 + e.printStackTrace();
  506 + }
  507 +
  508 + return occurrences;
  509 + }
  510 +
  511 + private int verificarNiveis(Integer posicao, List<String> tags) {
  512 +
  513 + try {
  514 + for (int i = 0; i < posicao; i++) {
  515 + if (Integer.parseInt(tags.get(i).substring(1)) == Integer.parseInt(tags.get(posicao).substring(1))
  516 + - 1) {
  517 + return Integer.parseInt(tags.get(i).substring(1));
  518 + }
  519 + }
  520 + } catch (Exception e) {
  521 + e.printStackTrace();
  522 + }
  523 + return -1;
  524 + }
  525 +
  526 + private boolean hasCorrectHierarchy(int index, String[] tags) {
  527 +
  528 + try {
  529 + for (int i = index + 1; i < tags.length; i++) {
  530 + if (getDocument().getFirstElement(tags[i]) == null)
  531 + return false;
  532 + }
  533 + } catch (Exception e) {
  534 + e.printStackTrace();
  535 + }
  536 + return true;
  537 + }
  538 +
  539 + private boolean hasH() {
  540 +
  541 + String[] tags = { "h6", "h5", "h4", "h3", "h2", "h1" };
  542 + for (String h : tags) {
  543 + if (getDocument().getFirstElement(h) != null)
  544 + return true;
  545 + }
  546 +
  547 + return false;
  548 + }
  549 +
  550 + /* No documento NÃO PERMITE VERIFICAÇÃO AUTOMATIZADA */
  551 + private List<Occurrence> checkRecommendation4() {
  552 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  553 +
  554 + try {
  555 + for (Element link : this.getDocument().getAllElements("a")) {
  556 + Attribute tabIndex = link.getAttributes().get("tabindex");
  557 + if (tabIndex != null) {
  558 + occurrences.add(this.buildOccurrence("1.4", false, link.toString(), link, "3"));// "2"));
  559 +
  560 + if (rangeIncorretoTabeIndex(tabIndex))
  561 + occurrences.add(this.buildOccurrence("1.4", false, link.toString(), link, "6"));// "3"));
  562 + }
  563 + }
  564 +
  565 + for (Element input : this.getDocument().getAllElements("input")) {
  566 +
  567 + Attribute tabIndex = input.getAttributes().get("tabindex");
  568 + if (tabIndex != null)
  569 + occurrences.add(this.buildOccurrence("1.4", false, input.toString(), input, "3"));// "2"));
  570 +
  571 + if (rangeIncorretoTabeIndex(tabIndex))
  572 + occurrences.add(this.buildOccurrence("1.4", false, input.toString(), input, "6"));// "3"));
  573 + }
  574 +
  575 + for (Element select : this.getDocument().getAllElements("select")) {
  576 +
  577 + Attribute tabIndex = select.getAttributes().get("tabindex");
  578 + if (tabIndex != null)
  579 + occurrences.add(this.buildOccurrence("1.4", false, select.toString(), select, "3"));// "2"));
  580 +
  581 + if (rangeIncorretoTabeIndex(tabIndex))
  582 + occurrences.add(this.buildOccurrence("1.4", false, select.toString(), select, "6"));// "3"));
  583 + }
  584 +
  585 + for (Element textarea : this.getDocument().getAllElements("textarea")) {
  586 +
  587 + Attribute tabIndex = textarea.getAttributes().get("tabindex");
  588 + if (tabIndex != null)
  589 + occurrences.add(this.buildOccurrence("1.4", false, textarea.toString(), textarea, "3"));// "2"));
  590 +
  591 + if (rangeIncorretoTabeIndex(tabIndex))
  592 + occurrences.add(this.buildOccurrence("1.4", false, textarea.toString(), textarea, "6"));// "3"));
  593 + }
  594 +
  595 + /*
  596 + * Element section = this.getDocument().getFirstElement("section");
  597 + *
  598 + * if(section !=null){
  599 + *
  600 + * int firstSectionRow = this.getRow(section); for(Element nav :
  601 + * this.getDocument().getAllElements("nav")){ if(this.getRow(nav) <
  602 + * firstSectionRow) occurrences.add(this.buildOccurrence("1.4",
  603 + * false,nav.toString(), nav, "1")); } }
  604 + */
  605 +
  606 + List<Integer> verificadsos = new ArrayList<Integer>();
  607 + for (Element nav : this.getDocument().getAllElements("nav")) {
  608 + if (nav != null) {
  609 + int firstNavRow = this.getRow(nav);
  610 +
  611 + for (Element section : this.getDocument().getAllElements("section")) {
  612 +
  613 + if (firstNavRow < this.getRow(section)) {
  614 + if (!verificadsos.contains(this.getRow(section))) {
  615 + occurrences.add(this.buildOccurrence("1.4", false, section.getStartTag().toString(),
  616 + section, "1"));
  617 + verificadsos.add(this.getRow(section));
  618 + }
  619 +
  620 + }
  621 + }
  622 + }
  623 + }
  624 +
  625 + } catch (Exception e) {
  626 + e.printStackTrace();
  627 + }
  628 +
  629 + return occurrences;
  630 + }
  631 +
  632 + private boolean rangeIncorretoTabeIndex(Attribute tabIndex) {
  633 + try {
  634 + Integer value = Integer.valueOf(tabIndex.getValue());
  635 + if (value < 0 || value > 32767)
  636 + return true;
  637 + } catch (Exception e) {
  638 + return false;
  639 + }
  640 + return false;
  641 + }
  642 +
  643 + private List<Occurrence> checkRecommendation5() {
  644 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  645 +
  646 + try {
  647 + /*
  648 + * Element firstLink = getDocument().getFirstElement("href",
  649 + * Pattern.compile("#.*"));
  650 + *
  651 + * if(firstLink != null) occurrences.add(this.buildOccurrence("1.5", false,
  652 + * firstLink.toString(), firstLink, "4"));
  653 + */
  654 +
  655 + for (Element link : getDocument().getAllElements("a")) {
  656 + String contLink = link.getAttributeValue("href");
  657 + if (contLink != null && contLink.length() > 1 && !contLink.substring(0, 1).equals("#")) {
  658 + occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "9"));// "4"));
  659 + }
  660 +
  661 + break;
  662 + }
  663 +
  664 + /*
  665 + * if(firstLink == null){ occurrences.add(this.buildOccurrence("1.5", false,
  666 + * getDocument().getFirstElement().toString(), getDocument().getFirstElement(),
  667 + * "4")); } else if(firstLink.getAttributeValue("href") == null ||
  668 + * !firstLink.getAttributeValue("href").contains("#")){
  669 + * occurrences.add(this.buildOccurrence("1.5", false, firstLink.toString(),
  670 + * firstLink, "4")); }
  671 + */
  672 +
  673 + boolean existAcessKey = false;
  674 +
  675 + for (Element area : getDocument().getAllElements("area")) {
  676 + if (hasAcessKey(area))
  677 + existAcessKey = true;
  678 + /*
  679 + * if(!hasAcessKey(area)) occurrences.add(this.buildOccurrence("1.5", true,
  680 + * area.toString(), area, "3"));
  681 + */
  682 + }
  683 +
  684 + if (!existAcessKey)
  685 + for (Element button : getDocument().getAllElements("button")) {
  686 + if (hasAcessKey(button))
  687 + existAcessKey = true;
  688 + /*
  689 + * if(!hasAcessKey(button)) occurrences.add(this.buildOccurrence("1.5", true,
  690 + * button.toString(), button, "3"));
  691 + */
  692 + }
  693 +
  694 + if (!existAcessKey)
  695 + for (Element input : getDocument().getAllElements("input")) {
  696 + if (hasAcessKey(input))
  697 + existAcessKey = true;
  698 + /*
  699 + * if(!hasAcessKey(input)) occurrences.add(this.buildOccurrence("1.5", true,
  700 + * input.toString(), input, "3"));
  701 + */
  702 + }
  703 +
  704 + if (!existAcessKey)
  705 + for (Element label : getDocument().getAllElements("label")) {
  706 + if (hasAcessKey(label))
  707 + existAcessKey = true;
  708 + /*
  709 + * if(!hasAcessKey(label)) occurrences.add(this.buildOccurrence("1.5", true,
  710 + * label.toString(), label, "3"));
  711 + */
  712 + }
  713 +
  714 + if (!existAcessKey)
  715 + for (Element legend : getDocument().getAllElements("legend")) {
  716 + if (hasAcessKey(legend))
  717 + existAcessKey = true;
  718 + /*
  719 + * if(!hasAcessKey(legend)) occurrences.add(this.buildOccurrence("1.5", true,
  720 + * legend.toString(), legend, "3"));
  721 + */
  722 + }
  723 +
  724 + if (!existAcessKey)
  725 + for (Element textarea : getDocument().getAllElements("textarea")) {
  726 + if (hasAcessKey(textarea))
  727 + existAcessKey = true;
  728 + /*
  729 + * if(!hasAcessKey(textarea)) occurrences.add(this.buildOccurrence("1.5", true,
  730 + * textarea.toString(), textarea, "3"));
  731 + */
  732 + }
  733 +
  734 + String href;
  735 + boolean existAnchor = false;
  736 +
  737 + for (Element link : getDocument().getAllElements("a")) {
  738 + href = link.getAttributeValue("href");
  739 +
  740 + /*
  741 + * if(href != null && (href.length() > 1 && !href.substring(0,2).equals("?#"))){
  742 + * ///occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link,
  743 + * "2")); if(!(href.length()==1 && href.substring(1).equals("#")))
  744 + * if(href.substring(1).equals("#") && !this.hasLinkSemAncora(href))
  745 + * occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link,
  746 + * "2")); }
  747 + */
  748 +
  749 + if (href != null && href.length() > 1 && !href.substring(0, 2).equals("?#")) {
  750 + if (href.substring(0, 1).equals("#"))
  751 + if (!this.hasLinkRefAncora(link))
  752 + occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "2"));
  753 + }
  754 +
  755 + /*
  756 + * if(href != null && href.contains("#")) if(!hasAnchor(href.substring(1)))
  757 + * occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link,
  758 + * "2"));
  759 + */
  760 + /*
  761 + * }else{ occurrences.add(this.buildOccurrence("1.5", true, link.toString(),
  762 + * link, "1")); }
  763 + */
  764 +
  765 + // if(href != null && href.contains("#"))
  766 +
  767 + /*
  768 + * if(href != null && href.length() == 1 && href.toString().equals("#"))
  769 + * existAnchor = true;
  770 + */
  771 + if (href != null && href.contains("#"))
  772 + existAnchor = true;
  773 +
  774 + if (hasAcessKey(link))
  775 + existAcessKey = true;
  776 +
  777 + /*
  778 + * if(!hasAcessKey(link)) occurrences.add(this.buildOccurrence("1.5", true,
  779 + * link.toString(), link, "3"));
  780 + */
  781 + }
  782 +
  783 + if (!existAnchor)
  784 + occurrences.add(this.buildOccurrence("1.5", true,
  785 + "Observa&ccedil;&atilde;o - Sem fonte (n&atilde;o foram encontrados &acirc;ncoras que permitam saltar pelas diferentes se&ccedil;&otilde;es da p&aacute;gina)",
  786 + getDocument().getFirstElement(), "1"));
  787 +
  788 + if (!existAcessKey)
  789 + occurrences.add(this.buildOccurrence("1.5", true,
  790 + "Observa&ccedil;&atilde;o - Sem fonte ( n&atilde;o existe(m) accesskey(s) na página)",
  791 + getDocument().getFirstElement(), "4"));// "3"));
  792 +
  793 + for (Element elemento : getDocument().getAllElements("accesskey", Pattern.compile(".*"))) {
  794 + if (duplicatedAcessKey(elemento))
  795 + occurrences.add(this.buildOccurrence("1.5", false, elemento.toString(), elemento, "11"));// "5"));
  796 + }
  797 +
  798 + this.oder(occurrences);
  799 +
  800 + } catch (Exception e) {
  801 + e.printStackTrace();
  802 + }
  803 +
  804 + return occurrences;
  805 + }
  806 +
  807 + private boolean hasLinkRefAncora(Element link) {
  808 + boolean existeAncora = false;
  809 + String href = link.getAttributeValue("href");
  810 + String ancora = href.substring(1, href.length());
  811 +
  812 + try {
  813 + for (Element a : getDocument().getAllElements()) {
  814 + if (a.getAttributeValue("id") != null && a.getAttributeValue("id").equals(ancora)) {
  815 + existeAncora = true;
  816 + }
  817 + if (a.getAttributeValue("name") != null && a.getAttributeValue("name").equals(ancora)) {
  818 + existeAncora = true;
  819 + }
  820 + }
  821 + } catch (Exception e) {
  822 + e.printStackTrace();
  823 + }
  824 + return existeAncora;
  825 + }
  826 +
  827 + private boolean hasAcessKey(Element element) {
  828 + String acessKey = element.getAttributeValue("accesskey");
  829 +
  830 + return StringUtils.isNotBlank(acessKey);
  831 + }
  832 +
  833 + private boolean hasAnchor(String href) {
  834 +
  835 + String id, name;
  836 + try {
  837 + for (Element element : getDocument().getAllElements()) {
  838 + id = element.getAttributeValue("id");
  839 + name = element.getAttributeValue("name");
  840 +
  841 + if (href.equals(id) || href.equals(name))
  842 + return true;
  843 + }
  844 + } catch (Exception e) {
  845 + e.printStackTrace();
  846 + }
  847 + return false;
  848 + }
  849 +
  850 + private boolean duplicatedAcessKey(Element element) {
  851 + String value = element.getAttributeValue("accesskey");
  852 + try {
  853 + for (Element elementToCompare : getDocument().getAllElements("accesskey", Pattern.compile(".*"))) {
  854 + String acessKey = elementToCompare.getAttributeValue("accesskey");
  855 + if (acessKey.equals(value) && elementToCompare.getBegin() != element.getBegin())
  856 + return true;
  857 +
  858 + }
  859 + } catch (Exception e) {
  860 + e.printStackTrace();
  861 + }
  862 + return false;
  863 + }
  864 +
  865 + public List<Occurrence> checkRecommendation6() {
  866 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  867 +
  868 + try {
  869 +
  870 + for (Element table : getDocument().getAllElements("table"))
  871 + occurrences.add(this.buildOccurrence("1.6", false, table.getStartTag().toString(), table, "1"));
  872 +
  873 + int firstFormRow = 0;
  874 +
  875 + List<Integer> linhasOcorrForm = new ArrayList<Integer>();
  876 +
  877 + for (Element table : getDocument().getAllElements("table")) {
  878 + // Element tagsForm = table.getFirstElement("form");
  879 +
  880 + Element form = table.getContent().getFirstElement("form");
  881 +
  882 + if (form != null) {
  883 + firstFormRow = this.getRow(form);
  884 + if (!linhasOcorrForm.contains(firstFormRow)) {
  885 + occurrences.add(this.buildOccurrence("1.6", true, form.getStartTag().toString(), form, "2"));
  886 + linhasOcorrForm.add(firstFormRow);
  887 + }
  888 + }
  889 +
  890 + }
  891 +
  892 + } catch (Exception e) {
  893 + e.printStackTrace();
  894 + }
  895 +
  896 + return occurrences;
  897 + }
  898 +
  899 + public List<Occurrence> checkRecommendation7() {
  900 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  901 + List<Element> element = getDocument().getAllElements();
  902 +
  903 + int pos = 1;
  904 + int end = 0;
  905 + int begin = 0;
  906 + Element firstElement = null;
  907 + Element secondElement = null;
  908 +
  909 + try {
  910 + for (int i = 0; i < element.size() - 1; i++) {
  911 + firstElement = element.get(i);
  912 + secondElement = element.get(pos);
  913 + if (firstElement.getEndTag() != null && firstElement.getName().equals("a"))
  914 + end = firstElement.getEndTag().getEnd();
  915 + begin = secondElement.getStartTag().getBegin();
  916 + if (element.get(i).getName().equals(element.get(pos).getName()) && (end == begin)) {
  917 + occurrences.add(this.buildOccurrence("1.7", true,
  918 + element.get(i).toString() + " " + element.get(pos).toString(), element.get(i), "1"));
  919 + }
  920 + pos++;
  921 + }
  922 + } catch (Exception e) {
  923 + e.printStackTrace();
  924 + }
  925 + return occurrences;
  926 + }
  927 +
  928 + public List<Occurrence> checkRecommendation8() {
  929 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  930 + Element firstElement = this.getDocument().getFirstElement();
  931 +
  932 + try {
  933 + if (firstElement.toString().replace(" ", "").equalsIgnoreCase("<!DOCTYPEhtml>")) {
  934 +
  935 + Element header = getDocument().getFirstElement("header");
  936 + Element nav = getDocument().getFirstElement("nav");
  937 + Element section = getDocument().getFirstElement("section");
  938 + Element footer = getDocument().getFirstElement("footer");
  939 +
  940 + if (header == null)
  941 + occurrences.add(this.buildOccurrence("1.8", false,
  942 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <HEADER>)",
  943 + getDocument().getFirstElement(), "3"));// "1"));
  944 +
  945 + if (nav == null)
  946 + occurrences.add(this.buildOccurrence("1.8", false,
  947 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <NAV>)",
  948 + getDocument().getFirstElement(), "3"));// "1"));
  949 +
  950 + if (section == null)
  951 + occurrences.add(this.buildOccurrence("1.8", false,
  952 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <SECTION>)",
  953 + getDocument().getFirstElement(), "3"));// "1"));
  954 +
  955 + if (footer == null)
  956 + occurrences.add(this.buildOccurrence("1.8", false,
  957 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <FOOTER>)",
  958 + getDocument().getFirstElement(), "3"));
  959 +
  960 + } else {
  961 +
  962 + boolean hasBanner = false;
  963 + boolean hasNavigation = false;
  964 + boolean hasMain = false;
  965 + for (Element element : getDocument().getAllElements()) {
  966 + String role = element.getAttributeValue("role");
  967 +
  968 + if (role != null && "banner".equals(role.toLowerCase()))
  969 + hasBanner = true;
  970 +
  971 + if (role != null && "navigation".equals(role.toLowerCase()))
  972 + hasNavigation = true;
  973 +
  974 + if (role != null && "main".equals(role.toLowerCase()))
  975 + hasMain = true;
  976 +
  977 + if (hasBanner && hasNavigation && hasMain)
  978 + break;
  979 + }
  980 + /*
  981 + * //comentado por Gibran
  982 + *
  983 + * if (!hasBanner) occurrences .add(this .buildOccurrence( "1.8", false,
  984 + * "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do BANNER)"
  985 + * , getDocument().getFirstElement(), "2"));
  986 + *
  987 + * if (!hasNavigation) occurrences .add(this .buildOccurrence( "1.8", false,
  988 + * "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do NAVIGATION)"
  989 + * , getDocument().getFirstElement(), "2"));
  990 + *
  991 + * if (!hasMain) occurrences .add(this .buildOccurrence( "1.8", false,
  992 + * "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do MAIN)"
  993 + * , getDocument().getFirstElement(), "2"));
  994 + */ // comentado por Gibran
  995 +
  996 + }
  997 + } catch (Exception e) {
  998 + e.printStackTrace();
  999 + }
  1000 + return occurrences;
  1001 + }
  1002 +
  1003 + public List<Occurrence> checkRecommendation9() {
  1004 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  1005 + boolean hasBlankLink = false;
  1006 +
  1007 + try {
  1008 + for (Element link : getDocument().getAllElements("a")) {
  1009 +
  1010 + if (link.toString().contains("_blank")) {
  1011 + hasBlankLink = true;
  1012 + occurrences.add(this.buildOccurrence("1.9", false, link.toString(), link, "1"));
  1013 + }
  1014 + }
  1015 +
  1016 + /*
  1017 + * if(!hasBlankLink) occurrences.add(new Occurrence("1.9",
  1018 + * false,this.getDocument
  1019 + * ().getFirstElement().toString(),OccurrenceClassification.MARK));
  1020 + */
  1021 + } catch (Exception e) {
  1022 + e.printStackTrace();
  1023 + }
  1024 + return occurrences;
  1025 + }
  1026 +
  1027 + private List<Occurrence> oder(List<Occurrence> occurrences) {
  1028 + // Sorting
  1029 + Collections.sort(occurrences, new Comparator<Occurrence>() {
  1030 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  1031 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  1032 + }
  1033 + });
  1034 + return occurrences;
  1035 + }
  1036 +
  1037 + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element, String criterio) {
  1038 + return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.MARK, criterio);
  1039 + }
  1040 +
  1041 + public int[] getErrorCount(boolean isCss, String url) {
  1042 + int errors = 0;
  1043 + int warnings = 0;
  1044 + URL UrlConvertida;
  1045 +
  1046 + try {
  1047 + UrlConvertida = new URL(url);
  1048 +
  1049 + if (isCss) {
  1050 +
  1051 + String content = WebAgent
  1052 + .from(CSS_VALIDATOR_URL.replace("#{url}",
  1053 + URLEncoder.encode(UrlConvertida.toExternalForm(), "UTF-8")))
  1054 + .withGetRequest().execute().getContent();
  1055 +
  1056 + Matcher m = Pattern.compile("<m:errorcount>(\\d)*</m:errorcount>", Pattern.MULTILINE).matcher(content);
  1057 + if (m.find())
  1058 + errors = Integer.valueOf(m.group(0).replace("<m:errorcount>", "").replace("</m:errorcount>", ""));
  1059 +
  1060 + m = Pattern.compile("<m:warningcount>(\\d)*</m:warningcount>", Pattern.MULTILINE).matcher(content);
  1061 +
  1062 + if (m.find())
  1063 + warnings = Integer
  1064 + .valueOf(m.group(0).replace("<m:warningcount>", "").replace("</m:warningcount>", ""));
  1065 +
  1066 + } else {
  1067 +
  1068 + String content = WebAgent
  1069 + .from(HTML_VALIDATOR_URL.replace("#{url}",
  1070 + URLEncoder.encode(UrlConvertida.toExternalForm(), "UTF-8")))
  1071 + .withGetRequest().execute().getContent();
  1072 + Gson g = new GsonBuilder().create();
  1073 + HtmlValidation a = g.fromJson(content, HtmlValidation.class);
  1074 + int[] errorsWarnings = a.getQtdWarningsErros();
  1075 + errors = errorsWarnings[1];
  1076 + warnings = errorsWarnings[0];
  1077 +
  1078 + }
  1079 + } catch (Exception e) {
  1080 +
  1081 + e.printStackTrace();
  1082 + }
  1083 +
  1084 + return new int[] { errors, warnings };
  1085 + }
  1086 +
  1087 + public OccurrenceClassification type() {
  1088 + return OccurrenceClassification.MARK;
  1089 + }
  1090 +
  1091 + public class HtmlValidation {
  1092 +
  1093 + List<Message> messages = new ArrayList<HtmlValidation.Message>();
  1094 +
  1095 + public List<Message> getMessages() {
  1096 + return messages;
  1097 + }
  1098 +
  1099 + public void setMessages(List<Message> messages) {
  1100 + this.messages = messages;
  1101 + }
  1102 +
  1103 + public int[] getQtdWarningsErros() {
  1104 + int warnings = 0;
  1105 + int erros = 0;
  1106 + for (Message message : this.messages) {
  1107 + if (message.isError())
  1108 + erros++;
  1109 + else if (message.isWarning())
  1110 + warnings++;
  1111 + }
  1112 +
  1113 + return new int[] { warnings, erros };
  1114 + }
  1115 +
  1116 + public HtmlValidation() {
  1117 + }
  1118 +
  1119 + public class Message {
  1120 +
  1121 + private String type;
  1122 +
  1123 + private String subType;
  1124 +
  1125 + public String getType() {
  1126 + return type;
  1127 + }
  1128 +
  1129 + public void setType(String type) {
  1130 + this.type = type;
  1131 + }
  1132 +
  1133 + public String getSubType() {
  1134 + return subType;
  1135 + }
  1136 +
  1137 + public void setSubType(String subType) {
  1138 + this.subType = subType;
  1139 + }
  1140 +
  1141 + public boolean isWarning() {
  1142 + return "info".equals(type) && "warning".equals(this.subType);
  1143 + }
  1144 +
  1145 + public boolean isError() {
  1146 + return "error".equals(this.type);
  1147 + }
1163 1148  
1164   - }
1165   - }
  1149 + }
  1150 + }
1166 1151  
1167 1152 }
... ...
src/main/java/br/com/checker/emag/core/MultimediaEvaluation.java
... ... @@ -10,296 +10,331 @@ import br.com.checker.emag.Occurrence;
10 10 import br.com.checker.emag.OccurrenceClassification;
11 11 import br.com.checker.emag.core.SpecificRecommendation.MultimediaRecommendation;
12 12  
13   -public class MultimediaEvaluation extends Evaluation{
14   -
15   - private MultimediaEvaluation(Source document) { super(document); }
16   -
17   - public static class MultimediaEvaluationBuilder extends EvaluationBuilder {
18   -
19   - @Override
20   - protected MultimediaEvaluation with(Source document) { return new MultimediaEvaluation(document); }
21   -
22   - @Override
23   - protected MultimediaEvaluation with(Source document,String url) { return new MultimediaEvaluation(document); }
24   -
25   - public SpecificRecommendation recommendation33() { return new EvaluationRecommendation33();}
26   - public SpecificRecommendation recommendation34() { return new EvaluationRecommendation34();}
27   - public SpecificRecommendation recommendation35() { return new EvaluationRecommendation35();}
28   - public SpecificRecommendation recommendation36() { return new EvaluationRecommendation36();}
29   - public SpecificRecommendation recommendation37() { return new EvaluationRecommendation37();}
30   -
31   - }
32   -
33   - protected static class EvaluationRecommendation33 extends MultimediaRecommendation{
34   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation33();}
35   - }
36   -
37   - protected static class EvaluationRecommendation34 extends MultimediaRecommendation{
38   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation34();}
39   - }
40   -
41   - protected static class EvaluationRecommendation35 extends MultimediaRecommendation{
42   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation35();}
43   - }
44   -
45   - protected static class EvaluationRecommendation36 extends MultimediaRecommendation{
46   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation36();}
47   - }
48   -
49   - protected static class EvaluationRecommendation37 extends MultimediaRecommendation{
50   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation37();}
51   - }
52   -
53   -
54   - public List<Occurrence> check() {
55   - getOccurrences().clear();
56   - getOccurrences().addAll(checkRecommendation33());
57   - getOccurrences().addAll(checkRecommendation34());
58   - getOccurrences().addAll(checkRecommendation35());
59   - getOccurrences().addAll(checkRecommendation36());
60   -
61   - //getOccurrences().addAll(checkRecommendation37());
62   -
63   - return getOccurrences();
64   - }
65   -
66   -
67   -
68   - private List<Occurrence> checkRecommendation33() {
69   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
70   -
71   -
72   - for (Element video : getDocument().getAllElements("embed")){
73   -
74   - Attribute value = video.getAttributes().get("src");
75   - if (value != null){
76   - /*if (value.getValue().contains(".mp4")
77   - || value.getValue().contains(".avi")
78   - || value.getValue().contains(".flv")
79   - || value.getValue().contains(".rmvb")
80   - || value.getValue().contains(".WebM")
81   - || value.getValue().contains(".Ogg")) {*/
82   - occurrences.add(this.buildOccurrence("5.1", false, video.toString(), video, "1"));
83   - //}
84   -
85   - }
86   - }
87   -
88   - for (Element video : this.getDocument().getAllElements("object")) {
89   - Attribute src = video.getAttributes().get("src");
90   -
91   - if (src != null)
92   - /* if (value.getValue().contains(".mp4")
93   - || value.getValue().contains(".avi")
94   - || value.getValue().contains(".flv")
95   - || value.getValue().contains(".rmvb")
96   - || value.getValue().contains(".WebM")
97   - || value.getValue().contains(".Ogg")) {*/
98   - occurrences.add(this.buildOccurrence("5.1", false, video.toString(), video, "1"));
99   - //}
100   -
101   - }
102   -
103   - for (Element video : this.getDocument().getAllElements("video")) {
104   - if(video.getTextExtractor().toString().isEmpty())
105   - occurrences.add(this.buildOccurrence("5.1", false, video.toString(), video, "1"));
106   - }
107   -
108   - return occurrences;
109   - }
110   -
111   - private List<Occurrence> checkRecommendation34() {
112   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
113   -
114   - for (Element audio : getDocument().getAllElements("embed")){
115   -
116   - Attribute value = audio.getAttributes().get("src");
117   - if (value != null)
118   - occurrences.add(this.buildOccurrence("5.2", false, audio.toString(), audio, "1"));
119   - }
120   -
121   - for (Element audio : this.getDocument().getAllElements("object")) {
122   - Attribute src = audio.getAttributes().get("src");
123   -
124   - if (src != null)
125   - occurrences.add(this.buildOccurrence("5.2", false, audio.toString(), audio, "1"));
126   - }
127   -
128   - for (Element audio : getDocument().getAllElements("audio")) {
129   - if(audio.getTextExtractor().toString().isEmpty())
130   - occurrences.add(this.buildOccurrence("5.2", false, audio.toString(), audio, "1"));
131   - }
132   -
133   -
134   - return occurrences;
135   - }
136   -
137   - private List<Occurrence> checkRecommendation35() {
138   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
139   -
140   - for (Element video : getDocument().getAllElements("embed")){
141   -
142   - Attribute src = video.getAttributes().get("src");
143   - if (src != null)
144   - occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
145   -
146   - Attribute data = video.getAttributes().get("data");
147   - if (data != null)
148   - occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
149   - }
150   -
151   - for (Element video : getDocument().getAllElements("object")){
152   -
153   - Attribute src = video.getAttributes().get("src");
154   - if (src != null)
155   - occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
156   -
157   - Attribute data = video.getAttributes().get("data");
158   - if (data != null)
159   - occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
160   -
161   - }
162   -
163   - for (Element video : this.getDocument().getAllElements("video")) {
164   - if(video.getTextExtractor().toString().isEmpty())
165   - occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
166   - }
167   -
168   - /* for (Element video : getDocument().getAllElements("embed"))
169   - occurrences.add(this.buildOccurrence("5.3", true, video.toString(), video, "1"));*/
170   -
171   - return occurrences;
172   - }
173   -
174   - private List<Occurrence> checkRecommendation36() {
175   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
176   -
177   - /*for (Element musica : getDocument().getAllElements("embed")){
178   -
179   -
180   - Attribute type = musica.getAttributes().get("type");
181   - if (type != null)
182   - if (type.getValue().contains("audio/x-mpeg")
183   - || type.getValue().contains("audio/basic")
184   - || type.getValue().contains("audio/wav")
185   - || type.getValue().contains("audio/x-wav")
186   - || type.getValue().contains("audio/x-pn-realaudio")
187   - || type.getValue().contains("audio/x-ms-wma")
188   - || type.getValue().contains("audio/ogg")
189   - || type.getValue().contains("audio/mpeg")) {
190   -
191   - String autostart = musica.getAttributes().get("autoplay").getValue();
192   - String hidden = musica.getAttributes().get("hidden").getValue();
193   -
194   - if(autostart != null && hidden != null){
195   - if(autostart.equals("true") && hidden.equals("true"))
196   - occurrences.add(this.buildOccurrence("5.4", false, musica.toString(), musica, "1"));
197   - }
198   - }
199   - }
200   -
201   - for (Element musica : getDocument().getAllElements("object")){
202   -
203   - Attribute type = musica.getAttributes().get("type");
204   - if (type != null)
205   - if (type.getValue().contains("audio/x-mpeg")
206   - || type.getValue().contains("audio/basic")
207   - || type.getValue().contains("audio/wav")
208   - || type.getValue().contains("audio/x-wav")
209   - || type.getValue().contains("audio/x-pn-realaudio")
210   - || type.getValue().contains("audio/x-ms-wma")
211   - || type.getValue().contains("audio/ogg")
212   - || type.getValue().contains("audio/mpeg")) {
213   -
214   - for (Element param : musica.getAllElements("param")){
215   -
216   - String name = param.getAttributes().getValue("name");
217   - String value = param.getAttributes().getValue("value");
218   - if(name != null && value != null){
219   - if(name.equals("autoplay") && value.equals("false"))
220   - occurrences.add(this.buildOccurrence("5.4", false, musica.toString(), musica, "1"));
221   -
222   - if(name.equals("autostart") && value.equals("0"))
223   - occurrences.add(this.buildOccurrence("5.4", false, musica.toString(), musica, "1"));
224   - }
225   - }
226   - }
227   - }*/
228   -
229   -
230   -
231   - for (Element video : getDocument().getAllElements("embed")){
232   -
233   - Attribute value = video.getAttributes().get("src");
234   - Attribute data = video.getAttributes().get("data");
235   -
236   - if (value != null || data != null){
237   - /*if (value.getValue().contains(".mp4")
238   - || value.getValue().contains(".avi")
239   - || value.getValue().contains(".flv")
240   - || value.getValue().contains(".rmvb")
241   - || value.getValue().contains(".WebM")
242   - || value.getValue().contains(".Ogg")) {*/
243   - occurrences.add(this.buildOccurrence("5.4", false, video.toString(), video, "1"));
244   - //}
245   -
246   - }
247   - }
248   -
249   - for (Element video : this.getDocument().getAllElements("object")) {
250   - Attribute src = video.getAttributes().get("src");
251   - Attribute data = video.getAttributes().get("data");
252   -
253   - if (src != null || data != null)
254   - /* if (value.getValue().contains(".mp4")
255   - || value.getValue().contains(".avi")
256   - || value.getValue().contains(".flv")
257   - || value.getValue().contains(".rmvb")
258   - || value.getValue().contains(".WebM")
259   - || value.getValue().contains(".Ogg")) {*/
260   - occurrences.add(this.buildOccurrence("5.4", false, video.toString(), video, "1"));
261   - //}
262   -
263   - }
264   -
265   - /*for (Element audio : this.getDocument().getAllElements("audio")) {
266   - if(audio.getTextExtractor().toString().isEmpty())
267   - occurrences.add(this.buildOccurrence("5.4", false, audio.toString(), audio, "1"));
268   - }*/
269   -
270   - for (Element audio : getDocument().getAllElements("audio")) {
271   - Attribute value = audio.getAttributes().get("controls");
272   - if (value == null)
273   - occurrences.add(this.buildOccurrence("5.4", false, audio.toString(), audio, "1"));
274   - }
275   -
276   - return occurrences;
277   - }
278   -
279   - private List<Occurrence> checkRecommendation37() {
280   - List<Occurrence> occurrences = new ArrayList<Occurrence>();
281   - /*for (Element video : getDocument().getAllElements("object")) {
282   -
283   - if (video.toString().contains("swf"))
284   - occurrences.add(this.buildOccurrence("5.5", false, video.toString(), video, "1"));
285   - }*/
286   -
287   - occurrences.add(new Occurrence("5.5", false, getDocument().getFirstElement().toString(),OccurrenceClassification.MULTIMEDIA,"1"));
288   -
289   -
290   - return occurrences;
291   - }
292   -
293   - private Occurrence buildOccurrence(String code, boolean error,
294   - String tag, Element element,
295   - String criterio) {
296   - return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.MULTIMEDIA,criterio);
297   - }
298   -
299   - private Occurrence buildOccurrence(String code, boolean error,
300   - String tag, Element element) {
301   - return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.MULTIMEDIA);
302   - }
303   -
304   - public OccurrenceClassification type () { return OccurrenceClassification.MULTIMEDIA;}
  13 +public class MultimediaEvaluation extends Evaluation {
  14 +
  15 + private MultimediaEvaluation(Source document) {
  16 + super(document);
  17 + }
  18 +
  19 + public static class MultimediaEvaluationBuilder extends EvaluationBuilder {
  20 +
  21 + @Override
  22 + protected MultimediaEvaluation with(Source document) {
  23 + return new MultimediaEvaluation(document);
  24 + }
  25 +
  26 + @Override
  27 + protected MultimediaEvaluation with(Source document, String url) {
  28 + return new MultimediaEvaluation(document);
  29 + }
  30 +
  31 + public SpecificRecommendation recommendation33() {
  32 + return new EvaluationRecommendation33();
  33 + }
  34 +
  35 + public SpecificRecommendation recommendation34() {
  36 + return new EvaluationRecommendation34();
  37 + }
  38 +
  39 + public SpecificRecommendation recommendation35() {
  40 + return new EvaluationRecommendation35();
  41 + }
  42 +
  43 + public SpecificRecommendation recommendation36() {
  44 + return new EvaluationRecommendation36();
  45 + }
  46 +
  47 + public SpecificRecommendation recommendation37() {
  48 + return new EvaluationRecommendation37();
  49 + }
  50 +
  51 + }
  52 +
  53 + protected static class EvaluationRecommendation33 extends MultimediaRecommendation {
  54 + protected List<Occurrence> check() {
  55 + return getEvaluation().checkRecommendation33();
  56 + }
  57 + }
  58 +
  59 + protected static class EvaluationRecommendation34 extends MultimediaRecommendation {
  60 + protected List<Occurrence> check() {
  61 + return getEvaluation().checkRecommendation34();
  62 + }
  63 + }
  64 +
  65 + protected static class EvaluationRecommendation35 extends MultimediaRecommendation {
  66 + protected List<Occurrence> check() {
  67 + return getEvaluation().checkRecommendation35();
  68 + }
  69 + }
  70 +
  71 + protected static class EvaluationRecommendation36 extends MultimediaRecommendation {
  72 + protected List<Occurrence> check() {
  73 + return getEvaluation().checkRecommendation36();
  74 + }
  75 + }
  76 +
  77 + protected static class EvaluationRecommendation37 extends MultimediaRecommendation {
  78 + protected List<Occurrence> check() {
  79 + return getEvaluation().checkRecommendation37();
  80 + }
  81 + }
  82 +
  83 + public List<Occurrence> check() {
  84 + getOccurrences().clear();
  85 + getOccurrences().addAll(checkRecommendation33());
  86 + getOccurrences().addAll(checkRecommendation34());
  87 + getOccurrences().addAll(checkRecommendation35());
  88 + getOccurrences().addAll(checkRecommendation36());
  89 +
  90 + // getOccurrences().addAll(checkRecommendation37());
  91 +
  92 + return getOccurrences();
  93 + }
  94 +
  95 + private List<Occurrence> checkRecommendation33() {
  96 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  97 +
  98 + try {
  99 +
  100 + for (Element video : getDocument().getAllElements("embed")) {
  101 +
  102 + Attribute value = video.getAttributes().get("src");
  103 + if (value != null) {
  104 + /*
  105 + * if (value.getValue().contains(".mp4") || value.getValue().contains(".avi") ||
  106 + * value.getValue().contains(".flv") || value.getValue().contains(".rmvb") ||
  107 + * value.getValue().contains(".WebM") || value.getValue().contains(".Ogg")) {
  108 + */
  109 + occurrences.add(this.buildOccurrence("5.1", false, video.toString(), video, "1"));
  110 + // }
  111 +
  112 + }
  113 + }
  114 +
  115 + for (Element video : this.getDocument().getAllElements("object")) {
  116 + Attribute src = video.getAttributes().get("src");
  117 +
  118 + if (src != null)
  119 + /*
  120 + * if (value.getValue().contains(".mp4") || value.getValue().contains(".avi") ||
  121 + * value.getValue().contains(".flv") || value.getValue().contains(".rmvb") ||
  122 + * value.getValue().contains(".WebM") || value.getValue().contains(".Ogg")) {
  123 + */
  124 + occurrences.add(this.buildOccurrence("5.1", false, video.toString(), video, "1"));
  125 + // }
  126 +
  127 + }
  128 +
  129 + for (Element video : this.getDocument().getAllElements("video")) {
  130 + if (video.getTextExtractor().toString().isEmpty())
  131 + occurrences.add(this.buildOccurrence("5.1", false, video.toString(), video, "1"));
  132 + }
  133 + } catch (Exception e) {
  134 + e.printStackTrace();
  135 + }
  136 + return occurrences;
  137 + }
  138 +
  139 + private List<Occurrence> checkRecommendation34() {
  140 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  141 + try {
  142 +
  143 + for (Element audio : getDocument().getAllElements("embed")) {
  144 +
  145 + Attribute value = audio.getAttributes().get("src");
  146 + if (value != null)
  147 + occurrences.add(this.buildOccurrence("5.2", false, audio.toString(), audio, "1"));
  148 + }
  149 +
  150 + for (Element audio : this.getDocument().getAllElements("object")) {
  151 + Attribute src = audio.getAttributes().get("src");
  152 +
  153 + if (src != null)
  154 + occurrences.add(this.buildOccurrence("5.2", false, audio.toString(), audio, "1"));
  155 + }
  156 +
  157 + for (Element audio : getDocument().getAllElements("audio")) {
  158 + if (audio.getTextExtractor().toString().isEmpty())
  159 + occurrences.add(this.buildOccurrence("5.2", false, audio.toString(), audio, "1"));
  160 + }
  161 +
  162 + } catch (Exception e) {
  163 + e.printStackTrace();
  164 + }
  165 + return occurrences;
  166 + }
  167 +
  168 + private List<Occurrence> checkRecommendation35() {
  169 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  170 +
  171 + try {
  172 +
  173 + for (Element video : getDocument().getAllElements("embed")) {
  174 +
  175 + Attribute src = video.getAttributes().get("src");
  176 + if (src != null)
  177 + occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
  178 +
  179 + Attribute data = video.getAttributes().get("data");
  180 + if (data != null)
  181 + occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
  182 + }
  183 +
  184 + for (Element video : getDocument().getAllElements("object")) {
  185 +
  186 + Attribute src = video.getAttributes().get("src");
  187 + if (src != null)
  188 + occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
  189 +
  190 + Attribute data = video.getAttributes().get("data");
  191 + if (data != null)
  192 + occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
  193 +
  194 + }
  195 +
  196 + for (Element video : this.getDocument().getAllElements("video")) {
  197 + if (video.getTextExtractor().toString().isEmpty())
  198 + occurrences.add(this.buildOccurrence("5.3", false, video.toString(), video, "1"));
  199 + }
  200 +
  201 + /*
  202 + * for (Element video : getDocument().getAllElements("embed"))
  203 + * occurrences.add(this.buildOccurrence("5.3", true, video.toString(), video,
  204 + * "1"));
  205 + */
  206 + } catch (Exception e) {
  207 + e.printStackTrace();
  208 + }
  209 +
  210 + return occurrences;
  211 + }
  212 +
  213 + private List<Occurrence> checkRecommendation36() {
  214 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  215 +
  216 + try {
  217 + /*
  218 + * for (Element musica : getDocument().getAllElements("embed")){
  219 + *
  220 + *
  221 + * Attribute type = musica.getAttributes().get("type"); if (type != null) if
  222 + * (type.getValue().contains("audio/x-mpeg") ||
  223 + * type.getValue().contains("audio/basic") ||
  224 + * type.getValue().contains("audio/wav") ||
  225 + * type.getValue().contains("audio/x-wav") ||
  226 + * type.getValue().contains("audio/x-pn-realaudio") ||
  227 + * type.getValue().contains("audio/x-ms-wma") ||
  228 + * type.getValue().contains("audio/ogg") ||
  229 + * type.getValue().contains("audio/mpeg")) {
  230 + *
  231 + * String autostart = musica.getAttributes().get("autoplay").getValue(); String
  232 + * hidden = musica.getAttributes().get("hidden").getValue();
  233 + *
  234 + * if(autostart != null && hidden != null){ if(autostart.equals("true") &&
  235 + * hidden.equals("true")) occurrences.add(this.buildOccurrence("5.4", false,
  236 + * musica.toString(), musica, "1")); } } }
  237 + *
  238 + * for (Element musica : getDocument().getAllElements("object")){
  239 + *
  240 + * Attribute type = musica.getAttributes().get("type"); if (type != null) if
  241 + * (type.getValue().contains("audio/x-mpeg") ||
  242 + * type.getValue().contains("audio/basic") ||
  243 + * type.getValue().contains("audio/wav") ||
  244 + * type.getValue().contains("audio/x-wav") ||
  245 + * type.getValue().contains("audio/x-pn-realaudio") ||
  246 + * type.getValue().contains("audio/x-ms-wma") ||
  247 + * type.getValue().contains("audio/ogg") ||
  248 + * type.getValue().contains("audio/mpeg")) {
  249 + *
  250 + * for (Element param : musica.getAllElements("param")){
  251 + *
  252 + * String name = param.getAttributes().getValue("name"); String value =
  253 + * param.getAttributes().getValue("value"); if(name != null && value != null){
  254 + * if(name.equals("autoplay") && value.equals("false"))
  255 + * occurrences.add(this.buildOccurrence("5.4", false, musica.toString(), musica,
  256 + * "1"));
  257 + *
  258 + * if(name.equals("autostart") && value.equals("0"))
  259 + * occurrences.add(this.buildOccurrence("5.4", false, musica.toString(), musica,
  260 + * "1")); } } } }
  261 + */
  262 +
  263 + for (Element video : getDocument().getAllElements("embed")) {
  264 +
  265 + Attribute value = video.getAttributes().get("src");
  266 + Attribute data = video.getAttributes().get("data");
  267 +
  268 + if (value != null || data != null) {
  269 + /*
  270 + * if (value.getValue().contains(".mp4") || value.getValue().contains(".avi") ||
  271 + * value.getValue().contains(".flv") || value.getValue().contains(".rmvb") ||
  272 + * value.getValue().contains(".WebM") || value.getValue().contains(".Ogg")) {
  273 + */
  274 + occurrences.add(this.buildOccurrence("5.4", false, video.toString(), video, "1"));
  275 + // }
  276 +
  277 + }
  278 + }
  279 +
  280 + for (Element video : this.getDocument().getAllElements("object")) {
  281 + Attribute src = video.getAttributes().get("src");
  282 + Attribute data = video.getAttributes().get("data");
  283 +
  284 + if (src != null || data != null)
  285 + /*
  286 + * if (value.getValue().contains(".mp4") || value.getValue().contains(".avi") ||
  287 + * value.getValue().contains(".flv") || value.getValue().contains(".rmvb") ||
  288 + * value.getValue().contains(".WebM") || value.getValue().contains(".Ogg")) {
  289 + */
  290 + occurrences.add(this.buildOccurrence("5.4", false, video.toString(), video, "1"));
  291 + // }
  292 +
  293 + }
  294 +
  295 + /*
  296 + * for (Element audio : this.getDocument().getAllElements("audio")) {
  297 + * if(audio.getTextExtractor().toString().isEmpty())
  298 + * occurrences.add(this.buildOccurrence("5.4", false, audio.toString(), audio,
  299 + * "1")); }
  300 + */
  301 +
  302 + for (Element audio : getDocument().getAllElements("audio")) {
  303 + Attribute value = audio.getAttributes().get("controls");
  304 + if (value == null)
  305 + occurrences.add(this.buildOccurrence("5.4", false, audio.toString(), audio, "1"));
  306 + }
  307 + } catch (Exception e) {
  308 + e.printStackTrace();
  309 + }
  310 + return occurrences;
  311 + }
  312 +
  313 + private List<Occurrence> checkRecommendation37() {
  314 + List<Occurrence> occurrences = new ArrayList<Occurrence>();
  315 + /*
  316 + * for (Element video : getDocument().getAllElements("object")) {
  317 + *
  318 + * if (video.toString().contains("swf"))
  319 + * occurrences.add(this.buildOccurrence("5.5", false, video.toString(), video,
  320 + * "1")); }
  321 + */
  322 +
  323 + occurrences.add(new Occurrence("5.5", false, getDocument().getFirstElement().toString(),
  324 + OccurrenceClassification.MULTIMEDIA, "1"));
  325 +
  326 + return occurrences;
  327 + }
  328 +
  329 + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element, String criterio) {
  330 + return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.MULTIMEDIA, criterio);
  331 + }
  332 +
  333 + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element) {
  334 + return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.MULTIMEDIA);
  335 + }
  336 +
  337 + public OccurrenceClassification type() {
  338 + return OccurrenceClassification.MULTIMEDIA;
  339 + }
305 340 }
... ...
src/main/java/br/com/checker/emag/core/PresentationEvaluation.java
... ... @@ -65,29 +65,25 @@ public class PresentationEvaluation extends Evaluation {
65 65 }
66 66 }
67 67  
68   - protected static class EvaluationRecommendation29 extends
69   - PresentationRecommendation {
  68 + protected static class EvaluationRecommendation29 extends PresentationRecommendation {
70 69 protected List<Occurrence> check() {
71 70 return getEvaluation().checkRecommendation29();
72 71 }
73 72 }
74 73  
75   - protected static class EvaluationRecommendation30 extends
76   - PresentationRecommendation {
  74 + protected static class EvaluationRecommendation30 extends PresentationRecommendation {
77 75 protected List<Occurrence> check() {
78 76 return getEvaluation().checkRecommendation30();
79 77 }
80 78 }
81 79  
82   - protected static class EvaluationRecommendation31 extends
83   - PresentationRecommendation {
  80 + protected static class EvaluationRecommendation31 extends PresentationRecommendation {
84 81 protected List<Occurrence> check() {
85 82 return getEvaluation().checkRecommendation31();
86 83 }
87 84 }
88 85  
89   - protected static class EvaluationRecommendation32 extends
90   - PresentationRecommendation {
  86 + protected static class EvaluationRecommendation32 extends PresentationRecommendation {
91 87 protected List<Occurrence> check() {
92 88 return getEvaluation().checkRecommendation32();
93 89 }
... ... @@ -109,451 +105,409 @@ public class PresentationEvaluation extends Evaluation {
109 105 private List<Occurrence> checkRecommendation29() {
110 106 List<Occurrence> occurrences = new ArrayList<Occurrence>();
111 107  
112   - UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal();
  108 + try {
113 109  
114   - String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal
115   - .urlSemArquivoNoFinal(getUrl());
116   - // verificar css externo
117   - String href = null;
118   - boolean avalia = false;
  110 + UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal();
119 111  
120   - // Adiciona todo css externo em uma lista
121   - List<String> lsCssExterno = new ArrayList<String>();
  112 + String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal.urlSemArquivoNoFinal(getUrl());
  113 + // verificar css externo
  114 + String href = null;
  115 + boolean avalia = false;
122 116  
123   - for (Element link2 : getDocument().getAllElements("link")) {
124   - href = link2.getAttributeValue("href");
125   - if (href != null) {
126   - if (href.startsWith("www"))
127   - href = "http://" + href;
  117 + // Adiciona todo css externo em uma lista
  118 + List<String> lsCssExterno = new ArrayList<String>();
128 119  
129   - if (href.equalsIgnoreCase("http://s.glbimg.com/jo/g1/static/live/COMPR/css/f0/2c8c3d2881f0.css")) {
130   - System.out.println(href);
131   - }
132   - avalia = getUrl() != null || href.startsWith("http");
  120 + for (Element link2 : getDocument().getAllElements("link")) {
133 121  
134   - if (href.contains(".css") && avalia) {
  122 + if (link2.getAttributeValue("href").startsWith("http") || link2.getAttributeValue("href").startsWith("www")) {
  123 + href = link2.getAttributeValue("href");
  124 + if (href != null) {
  125 + if (href.startsWith("www"))
  126 + href = "http://" + href;
135 127  
136   - if (!href.startsWith("http"))
137   - href = urlSemArquiNoFinal + "/" + href;
  128 + if (href.equalsIgnoreCase(
  129 + "http://s.glbimg.com/jo/g1/static/live/COMPR/css/f0/2c8c3d2881f0.css")) {
  130 + System.out.println(href);
  131 + }
  132 + avalia = getUrl() != null || href.startsWith("http");
138 133  
139   - lsCssExterno.add(WebAgent.from(href.replace(" ", "%20"))
140   - .withGetRequest().execute().getContent());
  134 + if (href.contains(".css") && avalia) {
141 135  
142   - }
143   - }
144   - }
145   - // Fim Adiciona todo css externo em uma lista
  136 + if (!href.startsWith("http"))
  137 + href = urlSemArquiNoFinal + "/" + href;
146 138  
147   - AvaliadorContraste avaliadorContraste = new AvaliadorContraste();
  139 + lsCssExterno.add(
  140 + WebAgent.from(href.replace(" ", "%20")).withGetRequest().execute().getContent());
148 141  
149   - Color corAvaliar = null;
150   - Color foreground = null;
151   - Color background = null;
152   - Color backgroundDoBody = null;
153   - boolean achou_foreground = false;
154   - boolean achou_background = false;
155   - String styleInline = "";
156   - String procurarPorId = "";
157   - String procurarPorClasse = "";
158   - String cssParaBuscarCor = "";
159   -
160   - List<Element> lsCssInterno = new ArrayList<Element>();
161   -
162   - // pega css interno caso tenha
163   - for (Element head : getDocument().getAllElements("head")) {
164   - for (Element estilo : head.getAllElements("style")) {
165   - lsCssInterno.add(estilo);
166   - }
167   - }
168   -
169   - // Pega todos elementos do "body"
170   - for (Element body : getDocument().getAllElements("body")) {
171   - for (Element element : body.getAllElements()) {
172   -
173   - // verificar se o "body" possui o atributo "bgcolor"
174   - if (element.getStartTag().getName().equalsIgnoreCase("body")) {
175   - if (element.toString().contains("bgcolor")) {
176   - try {
177   - corAvaliar = new Color(Integer.parseInt(element
178   - .getStartTag().getAttributeValue("bgcolor")
179   - .trim().replaceFirst("#", ""), 16));
180   - if (corAvaliar != null) {
181   - background = corAvaliar;
182   - }
183   - } catch (Exception e) {
184   - e.printStackTrace();
185 142 }
186 143 }
187 144 }
  145 + }
  146 + // Fim Adiciona todo css externo em uma lista
  147 +
  148 + AvaliadorContraste avaliadorContraste = new AvaliadorContraste();
  149 +
  150 + Color corAvaliar = null;
  151 + Color foreground = null;
  152 + Color background = null;
  153 + Color backgroundDoBody = null;
  154 + boolean achou_foreground = false;
  155 + boolean achou_background = false;
  156 + String styleInline = "";
  157 + String procurarPorId = "";
  158 + String procurarPorClasse = "";
  159 + String cssParaBuscarCor = "";
  160 +
  161 + List<Element> lsCssInterno = new ArrayList<Element>();
  162 +
  163 + // pega css interno caso tenha
  164 + for (Element head : getDocument().getAllElements("head")) {
  165 + for (Element estilo : head.getAllElements("style")) {
  166 + lsCssInterno.add(estilo);
  167 + }
  168 + }
188 169  
189   - // Primeiro verificar se tem css in-line
190   - styleInline = element.getStartTag().getAttributeValue("style");
191   - if (styleInline != null) {
192   -
193   - // pega o valor da cor, mesmo que no final não seja
194   - // atribuido o ";"
195   - corAvaliar = getColor(styleInline, "color:(.*?)\\Z");
196   - if (corAvaliar != null) {
197   - foreground = corAvaliar;
198   - }
199   -
200   - corAvaliar = getColor(styleInline, "color:(.*?)\\;");
201   - if (corAvaliar != null) {
202   - foreground = corAvaliar;
203   - }
204   -
205   - // pega o valor da cor, mesmo que no final não seja
206   - // atribuido o ";"
207   - corAvaliar = getColor(styleInline, "background:(.*?)\\Z");
208   - if (corAvaliar != null) {
209   - background = corAvaliar;
210   - }
211   -
212   - corAvaliar = getColor(styleInline, "background:(.*?)\\;");
213   - if (corAvaliar != null) {
214   - background = corAvaliar;
215   - }
216   - // pega o valor da cor, mesmo que no final não seja
217   - // atribuido o ";"
218   - corAvaliar = getColor(styleInline,
219   - "background-color:(.*?)\\Z");
220   - if (corAvaliar != null) {
221   - background = corAvaliar;
222   - }
223   -
224   - corAvaliar = getColor(styleInline,
225   - "background-color:(.*?)\\;");
226   - if (corAvaliar != null) {
227   - background = corAvaliar;
228   - }
229   -
230   - if (foreground != null) {
231   - achou_foreground = true;
  170 + // Pega todos elementos do "body"
  171 + for (Element body : getDocument().getAllElements("body")) {
  172 + for (Element element : body.getAllElements()) {
  173 +
  174 + // verificar se o "body" possui o atributo "bgcolor"
  175 + if (element.getStartTag().getName().equalsIgnoreCase("body")) {
  176 + if (element.toString().contains("bgcolor")) {
  177 + try {
  178 + corAvaliar = new Color(Integer.parseInt(
  179 + element.getStartTag().getAttributeValue("bgcolor").trim().replaceFirst("#", ""),
  180 + 16));
  181 + if (corAvaliar != null) {
  182 + background = corAvaliar;
  183 + }
  184 + } catch (Exception e) {
  185 + e.printStackTrace();
  186 + }
  187 + }
232 188 }
233 189  
234   - if (background != null) {
235   - achou_background = true;
  190 + // Primeiro verificar se tem css in-line
  191 + styleInline = element.getStartTag().getAttributeValue("style");
  192 + if (styleInline != null) {
236 193  
237   - if (element.getStartTag().getName()
238   - .equalsIgnoreCase("body")) {
239   - backgroundDoBody = background;
  194 + // pega o valor da cor, mesmo que no final não seja
  195 + // atribuido o ";"
  196 + corAvaliar = getColor(styleInline, "color:(.*?)\\Z");
  197 + if (corAvaliar != null) {
  198 + foreground = corAvaliar;
240 199 }
241   - }
242 200  
243   - } else {
244   - procurarPorId = "#"
245   - + element.getStartTag().getAttributeValue("id");
246   - procurarPorClasse = "."
247   - + element.getStartTag().getAttributeValue("class");
248   -
249   - // verifica css interno
250   -
251   - // Verifica se tem #id
252   - for (Element style : lsCssInterno) {
253   -
254   - // String pattern = "";
255   -
256   - // Coloca todo css em apenas uma linha, depois separa
257   - // por blocos
258   - String texto = style.toString().replace("\n", "");
259   - texto = texto.replace(">", ">\n").replace("*/", "\n")
260   - .replace(" {", "{").replace("}", " }\n")
261   - .replace(" :", ":");
262   - cssParaBuscarCor = "";
263   -
264   - // vevifica 1º pelo "id"
265   - if (!procurarPorId.equalsIgnoreCase("#null")) {
266   - cssParaBuscarCor = getElementoCss(texto,
267   - procurarPorId);
  201 + corAvaliar = getColor(styleInline, "color:(.*?)\\;");
  202 + if (corAvaliar != null) {
  203 + foreground = corAvaliar;
268 204 }
269 205  
270   - // Se não encontrar pelo "id" verifica pela classe e
271   - // elemento
272   - if (cssParaBuscarCor.isEmpty()
273   - && !procurarPorClasse.equalsIgnoreCase(".null")) {
274   - cssParaBuscarCor = getElementoCss(texto,
275   - procurarPorClasse
276   - + element.getStartTag().getName());
  206 + // pega o valor da cor, mesmo que no final não seja
  207 + // atribuido o ";"
  208 + corAvaliar = getColor(styleInline, "background:(.*?)\\Z");
  209 + if (corAvaliar != null) {
  210 + background = corAvaliar;
277 211 }
278 212  
279   - // Se não encontrar pela classe e elemento, verifica
280   - // pela classe
281   - if (cssParaBuscarCor.isEmpty()
282   - && !procurarPorClasse.equalsIgnoreCase(".null")) {
283   - cssParaBuscarCor = getElementoCss(texto,
284   - procurarPorClasse);
  213 + corAvaliar = getColor(styleInline, "background:(.*?)\\;");
  214 + if (corAvaliar != null) {
  215 + background = corAvaliar;
285 216 }
286   - // Se não encontrar pela classe, verifica pelo elemento
287   - if (cssParaBuscarCor.isEmpty()) {
288   - cssParaBuscarCor = getElementoCss(texto, element
289   - .getStartTag().getName());
  217 + // pega o valor da cor, mesmo que no final não seja
  218 + // atribuido o ";"
  219 + corAvaliar = getColor(styleInline, "background-color:(.*?)\\Z");
  220 + if (corAvaliar != null) {
  221 + background = corAvaliar;
290 222 }
291 223  
292   - if (!cssParaBuscarCor.isEmpty()) {
293   - if (cssParaBuscarCor.contains("color:")) {
294   - corAvaliar = getColor(cssParaBuscarCor,
295   - "color:(.*?)\\Z");
296   - if (corAvaliar != null) {
297   - foreground = corAvaliar;
  224 + corAvaliar = getColor(styleInline, "background-color:(.*?)\\;");
  225 + if (corAvaliar != null) {
  226 + background = corAvaliar;
  227 + }
298 228  
299   - }
  229 + if (foreground != null) {
  230 + achou_foreground = true;
  231 + }
300 232  
301   - corAvaliar = getColor(cssParaBuscarCor,
302   - "color:(.*?)\\;");
303   - if (corAvaliar != null) {
304   - foreground = corAvaliar;
305   - }
  233 + if (background != null) {
  234 + achou_background = true;
  235 +
  236 + if (element.getStartTag().getName().equalsIgnoreCase("body")) {
  237 + backgroundDoBody = background;
306 238 }
  239 + }
307 240  
308   - if (cssParaBuscarCor.contains("background:")
309   - || cssParaBuscarCor
310   - .contains("background-color:")) {
311   - // pega o valor da cor, mesmo que no final não
312   - // seja atribuido o ";"
313   - corAvaliar = getColor(cssParaBuscarCor,
314   - "background:(.*?)\\Z");
315   - if (corAvaliar != null) {
316   - background = corAvaliar;
317   - }
  241 + } else {
  242 + procurarPorId = "#" + element.getStartTag().getAttributeValue("id");
  243 + procurarPorClasse = "." + element.getStartTag().getAttributeValue("class");
318 244  
319   - corAvaliar = getColor(cssParaBuscarCor,
320   - "background:(.*?)\\;");
321   - if (corAvaliar != null) {
322   - background = corAvaliar;
323   - }
324   - // pega o valor da cor, mesmo que no final não
325   - // seja atribuido o ";"
326   - corAvaliar = getColor(cssParaBuscarCor,
327   - "background-color:(.*?)\\Z");
328   - if (corAvaliar != null) {
329   - background = corAvaliar;
330   - }
  245 + // verifica css interno
331 246  
332   - corAvaliar = getColor(cssParaBuscarCor,
333   - "background-color:(.*?)\\;");
334   - if (corAvaliar != null) {
335   - background = corAvaliar;
336   - }
337   - }
  247 + // Verifica se tem #id
  248 + for (Element style : lsCssInterno) {
338 249  
339   - if (foreground != null) {
340   - achou_foreground = true;
341   - }
  250 + // String pattern = "";
342 251  
343   - if (background != null) {
344   - achou_background = true;
  252 + // Coloca todo css em apenas uma linha, depois separa
  253 + // por blocos
  254 + String texto = style.toString().replace("\n", "");
  255 + texto = texto.replace(">", ">\n").replace("*/", "\n").replace(" {", "{")
  256 + .replace("}", " }\n").replace(" :", ":");
  257 + cssParaBuscarCor = "";
345 258  
346   - if (element.getStartTag().getName()
347   - .equalsIgnoreCase("body")) {
348   - backgroundDoBody = background;
349   - }
  259 + // vevifica 1º pelo "id"
  260 + if (!procurarPorId.equalsIgnoreCase("#null")) {
  261 + cssParaBuscarCor = getElementoCss(texto, procurarPorId);
350 262 }
351 263  
352   - if (achou_foreground || achou_background) {
353   - break;
  264 + // Se não encontrar pelo "id" verifica pela classe e
  265 + // elemento
  266 + if (cssParaBuscarCor.isEmpty() && !procurarPorClasse.equalsIgnoreCase(".null")) {
  267 + cssParaBuscarCor = getElementoCss(texto,
  268 + procurarPorClasse + element.getStartTag().getName());
354 269 }
355 270  
356   - }
  271 + // Se não encontrar pela classe e elemento, verifica
  272 + // pela classe
  273 + if (cssParaBuscarCor.isEmpty() && !procurarPorClasse.equalsIgnoreCase(".null")) {
  274 + cssParaBuscarCor = getElementoCss(texto, procurarPorClasse);
  275 + }
  276 + // Se não encontrar pela classe, verifica pelo elemento
  277 + if (cssParaBuscarCor.isEmpty()) {
  278 + cssParaBuscarCor = getElementoCss(texto, element.getStartTag().getName());
  279 + }
357 280  
358   - corAvaliar = null;
359   - foreground = null;
360   - background = null;
361   - cssParaBuscarCor = "";
  281 + if (!cssParaBuscarCor.isEmpty()) {
  282 + if (cssParaBuscarCor.contains("color:")) {
  283 + corAvaliar = getColor(cssParaBuscarCor, "color:(.*?)\\Z");
  284 + if (corAvaliar != null) {
  285 + foreground = corAvaliar;
362 286  
363   - }
  287 + }
364 288  
365   - if (!achou_foreground && !achou_background) {
366   - // verifica css externo
  289 + corAvaliar = getColor(cssParaBuscarCor, "color:(.*?)\\;");
  290 + if (corAvaliar != null) {
  291 + foreground = corAvaliar;
  292 + }
  293 + }
367 294  
368   - // Verifica se tem #id
369   - for (String style : lsCssExterno) {
370   -
371   - if (style != null) {
372   - if (element.getStartTag().getAttributeValue(
373   - "id") != null
374   - || element.getStartTag()
375   - .getAttributeValue("class") != null) {
376   - // Coloca todo css em apenas uma linha,
377   - // depois separa por blocos
378   - String texto = style.toString().replace(
379   - "\n", "");
380   - texto = texto.replace(">", ">\n")
381   - .replace("*/", "\n")
382   - .replace(" {", "{")
383   - .replace("}", " }\n")
384   - .replace(" :", ":");
385   - cssParaBuscarCor = "";
386   -
387   - // vevifica 1º pelo "id"
388   - if (!procurarPorId
389   - .equalsIgnoreCase("#null")) {
390   - cssParaBuscarCor = getElementoCss(
391   - texto, procurarPorId);
  295 + if (cssParaBuscarCor.contains("background:")
  296 + || cssParaBuscarCor.contains("background-color:")) {
  297 + // pega o valor da cor, mesmo que no final não
  298 + // seja atribuido o ";"
  299 + corAvaliar = getColor(cssParaBuscarCor, "background:(.*?)\\Z");
  300 + if (corAvaliar != null) {
  301 + background = corAvaliar;
392 302 }
393 303  
394   - // Se não encontrar pelo "id" verifica pela
395   - // classe e elemento
396   - if (cssParaBuscarCor.isEmpty()
397   - && !procurarPorClasse
398   - .equalsIgnoreCase(".null")) {
399   - cssParaBuscarCor = getElementoCss(
400   - texto, procurarPorClasse
401   - + element.getStartTag()
402   - .getName());
  304 + corAvaliar = getColor(cssParaBuscarCor, "background:(.*?)\\;");
  305 + if (corAvaliar != null) {
  306 + background = corAvaliar;
  307 + }
  308 + // pega o valor da cor, mesmo que no final não
  309 + // seja atribuido o ";"
  310 + corAvaliar = getColor(cssParaBuscarCor, "background-color:(.*?)\\Z");
  311 + if (corAvaliar != null) {
  312 + background = corAvaliar;
403 313 }
404 314  
405   - // Se não encontrar pela classe e elemento,
406   - // verifica pela classe
407   - if (cssParaBuscarCor.isEmpty()
408   - && !procurarPorClasse
409   - .equalsIgnoreCase(".null")) {
410   - cssParaBuscarCor = getElementoCss(
411   - texto, procurarPorClasse);
  315 + corAvaliar = getColor(cssParaBuscarCor, "background-color:(.*?)\\;");
  316 + if (corAvaliar != null) {
  317 + background = corAvaliar;
412 318 }
413   - // Se não encontrar pela classe, verifica
414   - // pelo elemento
415   - if (cssParaBuscarCor.isEmpty()) {
416   - cssParaBuscarCor = getElementoCss(
417   - texto, element.getStartTag()
418   - .getName());
  319 + }
  320 +
  321 + if (foreground != null) {
  322 + achou_foreground = true;
  323 + }
  324 +
  325 + if (background != null) {
  326 + achou_background = true;
  327 +
  328 + if (element.getStartTag().getName().equalsIgnoreCase("body")) {
  329 + backgroundDoBody = background;
419 330 }
  331 + }
420 332  
421   - if (!cssParaBuscarCor.isEmpty()) {
422   - if (cssParaBuscarCor.contains("color:")) {
423   - corAvaliar = getColor(
424   - cssParaBuscarCor,
425   - "color:(.*?)\\Z");
426   - if (corAvaliar != null) {
427   - foreground = corAvaliar;
  333 + if (achou_foreground || achou_background) {
  334 + break;
  335 + }
428 336  
429   - }
  337 + }
430 338  
431   - corAvaliar = getColor(
432   - cssParaBuscarCor,
433   - "color:(.*?)\\;");
434   - if (corAvaliar != null) {
435   - foreground = corAvaliar;
436   - }
  339 + corAvaliar = null;
  340 + foreground = null;
  341 + background = null;
  342 + cssParaBuscarCor = "";
437 343  
  344 + }
  345 +
  346 + if (!achou_foreground && !achou_background) {
  347 + // verifica css externo
  348 +
  349 + // Verifica se tem #id
  350 + for (String style : lsCssExterno) {
  351 +
  352 + if (style != null) {
  353 + if (element.getStartTag().getAttributeValue("id") != null
  354 + || element.getStartTag().getAttributeValue("class") != null) {
  355 + // Coloca todo css em apenas uma linha,
  356 + // depois separa por blocos
  357 + String texto = style.toString().replace("\n", "");
  358 + texto = texto.replace(">", ">\n").replace("*/", "\n").replace(" {", "{")
  359 + .replace("}", " }\n").replace(" :", ":");
  360 + cssParaBuscarCor = "";
  361 +
  362 + // vevifica 1º pelo "id"
  363 + if (!procurarPorId.equalsIgnoreCase("#null")) {
  364 + cssParaBuscarCor = getElementoCss(texto, procurarPorId);
438 365 }
439 366  
440   - if (cssParaBuscarCor
441   - .contains("background:")
442   - || cssParaBuscarCor
443   - .contains("background-color:")) {
444   - // pega o valor da cor, mesmo que no
445   - // final não seja atribuido o ";"
446   - corAvaliar = getColor(
447   - cssParaBuscarCor,
448   - "background:(.*?)\\Z");
449   - if (corAvaliar != null) {
450   - background = corAvaliar;
451   - }
  367 + // Se não encontrar pelo "id" verifica pela
  368 + // classe e elemento
  369 + if (cssParaBuscarCor.isEmpty()
  370 + && !procurarPorClasse.equalsIgnoreCase(".null")) {
  371 + cssParaBuscarCor = getElementoCss(texto,
  372 + procurarPorClasse + element.getStartTag().getName());
  373 + }
  374 +
  375 + // Se não encontrar pela classe e elemento,
  376 + // verifica pela classe
  377 + if (cssParaBuscarCor.isEmpty()
  378 + && !procurarPorClasse.equalsIgnoreCase(".null")) {
  379 + cssParaBuscarCor = getElementoCss(texto, procurarPorClasse);
  380 + }
  381 + // Se não encontrar pela classe, verifica
  382 + // pelo elemento
  383 + if (cssParaBuscarCor.isEmpty()) {
  384 + cssParaBuscarCor = getElementoCss(texto, element.getStartTag().getName());
  385 + }
  386 +
  387 + if (!cssParaBuscarCor.isEmpty()) {
  388 + if (cssParaBuscarCor.contains("color:")) {
  389 + corAvaliar = getColor(cssParaBuscarCor, "color:(.*?)\\Z");
  390 + if (corAvaliar != null) {
  391 + foreground = corAvaliar;
  392 +
  393 + }
  394 +
  395 + corAvaliar = getColor(cssParaBuscarCor, "color:(.*?)\\;");
  396 + if (corAvaliar != null) {
  397 + foreground = corAvaliar;
  398 + }
452 399  
453   - corAvaliar = getColor(
454   - cssParaBuscarCor,
455   - "background:(.*?)\\;");
456   - if (corAvaliar != null) {
457   - background = corAvaliar;
458 400 }
459   - // pega o valor da cor, mesmo que no
460   - // final não seja atribuido o ";"
461   - corAvaliar = getColor(
462   - cssParaBuscarCor,
463   - "background-color:(.*?)\\Z");
464   - if (corAvaliar != null) {
465   - background = corAvaliar;
  401 +
  402 + if (cssParaBuscarCor.contains("background:")
  403 + || cssParaBuscarCor.contains("background-color:")) {
  404 + // pega o valor da cor, mesmo que no
  405 + // final não seja atribuido o ";"
  406 + corAvaliar = getColor(cssParaBuscarCor, "background:(.*?)\\Z");
  407 + if (corAvaliar != null) {
  408 + background = corAvaliar;
  409 + }
  410 +
  411 + corAvaliar = getColor(cssParaBuscarCor, "background:(.*?)\\;");
  412 + if (corAvaliar != null) {
  413 + background = corAvaliar;
  414 + }
  415 + // pega o valor da cor, mesmo que no
  416 + // final não seja atribuido o ";"
  417 + corAvaliar = getColor(cssParaBuscarCor, "background-color:(.*?)\\Z");
  418 + if (corAvaliar != null) {
  419 + background = corAvaliar;
  420 + }
  421 +
  422 + corAvaliar = getColor(cssParaBuscarCor, "background-color:(.*?)\\;");
  423 + if (corAvaliar != null) {
  424 + background = corAvaliar;
  425 + }
466 426 }
467 427  
468   - corAvaliar = getColor(
469   - cssParaBuscarCor,
470   - "background-color:(.*?)\\;");
471   - if (corAvaliar != null) {
472   - background = corAvaliar;
  428 + if (foreground != null) {
  429 + achou_foreground = true;
473 430 }
474   - }
475 431  
476   - if (foreground != null) {
477   - achou_foreground = true;
478   - }
  432 + if (background != null) {
  433 + achou_background = true;
479 434  
480   - if (background != null) {
481   - achou_background = true;
  435 + if (element.getStartTag().getName().equalsIgnoreCase("body")) {
  436 + backgroundDoBody = background;
  437 + }
  438 + }
482 439  
483   - if (element.getStartTag().getName()
484   - .equalsIgnoreCase("body")) {
485   - backgroundDoBody = background;
  440 + if (achou_foreground || achou_background) {
  441 + break;
486 442 }
487   - }
488 443  
489   - if (achou_foreground
490   - || achou_background) {
491   - break;
492 444 }
493 445  
494 446 }
495   -
496 447 }
497   - }
498 448  
499   - corAvaliar = null;
500   - foreground = null;
501   - background = null;
502   - cssParaBuscarCor = "";
  449 + corAvaliar = null;
  450 + foreground = null;
  451 + background = null;
  452 + cssParaBuscarCor = "";
503 453  
  454 + }
504 455 }
505   - }
506 456  
507   - }
508   - procurarPorId = "";
509   - procurarPorClasse = "";
  457 + }
  458 + procurarPorId = "";
  459 + procurarPorClasse = "";
510 460  
511   - if (achou_foreground == true && achou_background == true) {
  461 + if (achou_foreground == true && achou_background == true) {
512 462  
513   - avaliadorContraste.setCores(foreground, background);
514   - avaliadorContraste.avaliar();
  463 + avaliadorContraste.setCores(foreground, background);
  464 + avaliadorContraste.avaliar();
515 465  
516   - if (avaliadorContraste.getContraste() < new Double("4.5")) {
517   - occurrences.add(buildOccurrence("4.1", false, element
518   - .getStartTag().toString(), element, "2"));
  466 + if (avaliadorContraste.getContraste() < new Double("4.5")) {
  467 + occurrences
  468 + .add(buildOccurrence("4.1", false, element.getStartTag().toString(), element, "2"));
519 469  
520   - }
521   - achou_foreground = false;
522   - achou_background = false;
  470 + }
  471 + achou_foreground = false;
  472 + achou_background = false;
523 473  
524   - }// Caso não ache o background, usará o padrão encontrado no
525   - // body
526   - else if (achou_foreground == true && achou_background == false
527   - && backgroundDoBody != null) {
528   - avaliadorContraste.setCores(foreground, backgroundDoBody);
529   - avaliadorContraste.avaliar();
  474 + } // Caso não ache o background, usará o padrão encontrado no
  475 + // body
  476 + else if (achou_foreground == true && achou_background == false && backgroundDoBody != null) {
  477 + avaliadorContraste.setCores(foreground, backgroundDoBody);
  478 + avaliadorContraste.avaliar();
530 479  
531   - if (avaliadorContraste.getContraste() < new Double("4.5")) {
532   - occurrences.add(buildOccurrence("4.1", false, element
533   - .getStartTag().toString(), element, "2"));
  480 + if (avaliadorContraste.getContraste() < new Double("4.5")) {
  481 + occurrences
  482 + .add(buildOccurrence("4.1", false, element.getStartTag().toString(), element, "2"));
534 483  
535   - }
536   - achou_foreground = false;
537   - achou_background = false;
538   - }// Caso não ache o foreground, usará o padrão encontrado no
539   - // body
540   -
541   - // Caso seja encontrado um "foreground" e não "background" e
542   - // vice-versa, será adicionado um aviso para que seja avaliado
543   - // manualmente
544   - /*
545   - * if((achou_foreground== true && achou_background == false) ||
546   - * (achou_foreground== false && achou_background == true)){
547   - *
548   - * occurrences.add(buildOccurrence("4.1", false,
549   - * element.toString(), element,"2"));
550   - *
551   - * achou_foreground = false; achou_background = false;
552   - *
553   - * }
554   - */
  484 + }
  485 + achou_foreground = false;
  486 + achou_background = false;
  487 + } // Caso não ache o foreground, usará o padrão encontrado no
  488 + // body
  489 +
  490 + // Caso seja encontrado um "foreground" e não "background" e
  491 + // vice-versa, será adicionado um aviso para que seja avaliado
  492 + // manualmente
  493 + /*
  494 + * if((achou_foreground== true && achou_background == false) ||
  495 + * (achou_foreground== false && achou_background == true)){
  496 + *
  497 + * occurrences.add(buildOccurrence("4.1", false, element.toString(),
  498 + * element,"2"));
  499 + *
  500 + * achou_foreground = false; achou_background = false;
  501 + *
  502 + * }
  503 + */
  504 + }
555 505 }
  506 +
  507 + } catch (Exception e) {
  508 + e.printStackTrace();
556 509 }
  510 +
557 511 return occurrences;
558 512 }
559 513  
... ... @@ -594,8 +548,7 @@ public class PresentationEvaluation extends Evaluation {
594 548 Color color = null;
595 549  
596 550 Pattern value = Pattern.compile("\\s" + pattern);
597   - String cssModificado = css.replace(";", ";\n").replace("}", "")
598   - .replace("!important", "");
  551 + String cssModificado = css.replace(";", ";\n").replace("}", "").replace("!important", "");
599 552 Matcher match = value.matcher(cssModificado);
600 553 while (match.find()) {
601 554 String cor = match.group(1);
... ... @@ -607,16 +560,13 @@ public class PresentationEvaluation extends Evaluation {
607 560 // System.out.println("RGB: "+match.group(1));
608 561  
609 562 String str = cor.replaceAll("[^-?0-9]+", " ");
610   - color = new Color(Integer.parseInt(str.trim()
611   - .split(" ")[0]), Integer.parseInt(str.trim()
612   - .split(" ")[1]), Integer.parseInt(str.trim()
613   - .split(" ")[2]));
  563 + color = new Color(Integer.parseInt(str.trim().split(" ")[0]),
  564 + Integer.parseInt(str.trim().split(" ")[1]), Integer.parseInt(str.trim().split(" ")[2]));
614 565 break;
615 566 } else {
616 567 // System.out.println("EXADECIMAL: "+match.group(1));
617 568 if (css.replaceAll(" ", "").contains(":#")) {
618   - color = new Color(Integer.parseInt(match.group(1)
619   - .trim().replaceFirst("#", ""), 16));
  569 + color = new Color(Integer.parseInt(match.group(1).trim().replaceFirst("#", ""), 16));
620 570 break;
621 571 }
622 572 }
... ... @@ -644,124 +594,115 @@ public class PresentationEvaluation extends Evaluation {
644 594 */
645 595 boolean isProces = true;
646 596  
647   - Color foregroundColor = new Color(Integer.parseInt("000000", 16));
648   - Color backgroundColor = new Color(Integer.parseInt("ffffff", 16));
649   -
650   - // foreground
651   - Pattern colorValue = Pattern.compile("color:(.*?)\\;");
  597 + try {
652 598  
653   - Matcher match = colorValue.matcher(style);
  599 + Color foregroundColor = new Color(Integer.parseInt("000000", 16));
  600 + Color backgroundColor = new Color(Integer.parseInt("ffffff", 16));
654 601  
655   - if (match.find()) {
  602 + // foreground
  603 + Pattern colorValue = Pattern.compile("color:(.*?)\\;");
656 604  
657   - String cor = match.group(1);
  605 + Matcher match = colorValue.matcher(style);
658 606  
659   - // System.out.println("foreground: "+cor);
660   - if (!isTextCor(match.group(1)) && !cor.contains("url")) {
  607 + if (match.find()) {
661 608  
662   - if (cor.contains("rgb")) {
663   - String str = cor.replaceAll("[^-?0-9]+", " ");
  609 + String cor = match.group(1);
664 610  
665   - foregroundColor = new Color(Integer.parseInt(str.trim()
666   - .split(" ")[0]), Integer.parseInt(str.trim().split(
667   - " ")[1]),
668   - Integer.parseInt(str.trim().split(" ")[2]));
  611 + // System.out.println("foreground: "+cor);
  612 + if (!isTextCor(match.group(1)) && !cor.contains("url")) {
669 613  
670   - } else if (isTextCor(cor.trim().replaceFirst("^#", "")))
671   - foregroundColor = new Color(Integer.parseInt(cor.trim()
672   - .replaceFirst("^#", ""), 16));
  614 + if (cor.contains("rgb")) {
  615 + String str = cor.replaceAll("[^-?0-9]+", " ");
673 616  
674   - } else
675   - isProces = false;
676   - }
  617 + foregroundColor = new Color(Integer.parseInt(str.trim().split(" ")[0]),
  618 + Integer.parseInt(str.trim().split(" ")[1]), Integer.parseInt(str.trim().split(" ")[2]));
677 619  
678   - // background
679   - Pattern backgroundValue = Pattern.compile("background:(.*?)\\;");
680   - match = backgroundValue.matcher(style);
681   - if (match.find()) {
682   - String cor = match.group(1);
  620 + } else if (isTextCor(cor.trim().replaceFirst("^#", "")))
  621 + foregroundColor = new Color(Integer.parseInt(cor.trim().replaceFirst("^#", ""), 16));
683 622  
684   - // System.out.println("background: "+cor);
685   - if (!isTextCor(cor) && !cor.contains("url")) {
  623 + } else
  624 + isProces = false;
  625 + }
686 626  
687   - if (cor.contains("rgb")) {
688   - String str = cor.replaceAll("[^-?0-9]+", " ");
  627 + // background
  628 + Pattern backgroundValue = Pattern.compile("background:(.*?)\\;");
  629 + match = backgroundValue.matcher(style);
  630 + if (match.find()) {
  631 + String cor = match.group(1);
689 632  
690   - backgroundColor = new Color(Integer.parseInt(str.trim()
691   - .split(" ")[0]), Integer.parseInt(str.trim().split(
692   - " ")[1]),
693   - Integer.parseInt(str.trim().split(" ")[2]));
694   - } else if (isTextCor(cor.trim().replaceFirst("^#", "")))
695   - backgroundColor = new Color(Integer.parseInt(cor.trim()
696   - .replaceFirst("^#", ""), 16));
  633 + // System.out.println("background: "+cor);
  634 + if (!isTextCor(cor) && !cor.contains("url")) {
697 635  
698   - } else
699   - isProces = false;
  636 + if (cor.contains("rgb")) {
  637 + String str = cor.replaceAll("[^-?0-9]+", " ");
700 638  
701   - }
  639 + backgroundColor = new Color(Integer.parseInt(str.trim().split(" ")[0]),
  640 + Integer.parseInt(str.trim().split(" ")[1]), Integer.parseInt(str.trim().split(" ")[2]));
  641 + } else if (isTextCor(cor.trim().replaceFirst("^#", "")))
  642 + backgroundColor = new Color(Integer.parseInt(cor.trim().replaceFirst("^#", ""), 16));
702 643  
703   - // background
704   - Pattern backgroundColorValue = Pattern
705   - .compile("background-color:(.*?)\\;");
706   - match = backgroundColorValue.matcher(style);
  644 + } else
  645 + isProces = false;
707 646  
708   - if (match.find()) {
709   - String cor = match.group(1);
  647 + }
710 648  
711   - // System.out.println(cor);
712   - if (!isTextCor(cor)) {
  649 + // background
  650 + Pattern backgroundColorValue = Pattern.compile("background-color:(.*?)\\;");
  651 + match = backgroundColorValue.matcher(style);
713 652  
714   - if (cor.contains("rgb") && !cor.contains("url")) {
715   - String str = cor.replaceAll("[^-?0-9]+", " ");
  653 + if (match.find()) {
  654 + String cor = match.group(1);
716 655  
717   - backgroundColor = new Color(Integer.parseInt(str.trim()
718   - .split(" ")[0]), Integer.parseInt(str.trim().split(
719   - " ")[1]),
720   - Integer.parseInt(str.trim().split(" ")[2]));
721   - } else if (isTextCor(cor.trim().replaceFirst("^#", "")))
722   - backgroundColor = new Color(Integer.parseInt(cor.trim()
723   - .replaceFirst("^#", ""), 16));
  656 + // System.out.println(cor);
  657 + if (!isTextCor(cor)) {
724 658  
725   - } else
726   - isProces = false;
727   - }
  659 + if (cor.contains("rgb") && !cor.contains("url")) {
  660 + String str = cor.replaceAll("[^-?0-9]+", " ");
728 661  
729   - if (isProces) {
730   - avaliadorContraste.setCores(foregroundColor, backgroundColor);
731   - avaliadorContraste.avaliar();
  662 + backgroundColor = new Color(Integer.parseInt(str.trim().split(" ")[0]),
  663 + Integer.parseInt(str.trim().split(" ")[1]), Integer.parseInt(str.trim().split(" ")[2]));
  664 + } else if (isTextCor(cor.trim().replaceFirst("^#", "")))
  665 + backgroundColor = new Color(Integer.parseInt(cor.trim().replaceFirst("^#", ""), 16));
732 666  
733   - if (avaliadorContraste.getContraste() < new Double("4.5")) {
734   - System.out.println("foreground: " + foregroundColor.getRGB()
735   - + " -- " + "background" + backgroundColor.getRGB()
736   - + " Resultado: " + avaliadorContraste.getContraste());
737   - return true;
  667 + } else
  668 + isProces = false;
738 669 }
739 670  
740   - }
  671 + if (isProces) {
  672 + avaliadorContraste.setCores(foregroundColor, backgroundColor);
  673 + avaliadorContraste.avaliar();
741 674  
  675 + if (avaliadorContraste.getContraste() < new Double("4.5")) {
  676 + System.out.println("foreground: " + foregroundColor.getRGB() + " -- " + "background"
  677 + + backgroundColor.getRGB() + " Resultado: " + avaliadorContraste.getContraste());
  678 + return true;
  679 + }
  680 +
  681 + }
  682 + } catch (Exception e) {
  683 + e.printStackTrace();
  684 + }
742 685 return false;
743 686 }
744 687  
745 688 private List<Occurrence> checkRecommendation30() {
746 689 List<Occurrence> occurrences = new ArrayList<Occurrence>();
747   - occurrences.add(new Occurrence("4.2", false, getDocument()
748   - .getFirstElement().toString(),
  690 + occurrences.add(new Occurrence("4.2", false, getDocument().getFirstElement().toString(),
749 691 OccurrenceClassification.PRESENTATION_DESIGN));
750 692 return occurrences;
751 693 }
752 694  
753 695 private List<Occurrence> checkRecommendation31() {
754 696 List<Occurrence> occurrences = new ArrayList<Occurrence>();
755   - occurrences.add(new Occurrence("4.3", false, getDocument()
756   - .getFirstElement().toString(),
  697 + occurrences.add(new Occurrence("4.3", false, getDocument().getFirstElement().toString(),
757 698 OccurrenceClassification.PRESENTATION_DESIGN));
758 699  
759 700 return occurrences;
760 701 }
761 702  
762 703 /*
763   - * private String urlSemArquivoNoFinal(String url) { if(url != null) {
764   - * String urlSemArquivo = ""; boolean encontrouPonto = false;
  704 + * private String urlSemArquivoNoFinal(String url) { if(url != null) { String
  705 + * urlSemArquivo = ""; boolean encontrouPonto = false;
765 706 *
766 707 *
767 708 * for(int i = url.length()-1; i >= 0; i-- ) {
... ... @@ -777,103 +718,98 @@ public class PresentationEvaluation extends Evaluation {
777 718 private List<Occurrence> checkRecommendation32() {
778 719 List<Occurrence> occurrences = new ArrayList<Occurrence>();
779 720  
780   - UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal();
  721 + try {
781 722  
782   - String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal
783   - .urlSemArquivoNoFinal(getUrl());
  723 + UrlSemArquiNoFinal objetoUrlSemArquiNoFinal = new UrlSemArquiNoFinal();
784 724  
785   - // Caso seja encontrado o "a:focus" e "a:hover" n�o continua a
786   - // verifica��o nos demais for's, bem como, n�o
787   - // adiciona a ocorr�ncia
788   - boolean focoEncontrado = false;
789   - boolean passivelDeAvaliacao = false;
  725 + String urlSemArquiNoFinal = objetoUrlSemArquiNoFinal.urlSemArquivoNoFinal(getUrl());
790 726  
791   - for (Element style : getDocument().getAllElements("style")) {
792   - if (style.toString().contains("a:focus")
793   - && style.toString().contains("a:hover")) {
794   - // occurrences.add(buildOccurrence("4.4", true,
795   - // style.toString(), style, "1"));
796   - focoEncontrado = true;
797   - break;
798   - }
799   - }
800   - if (!focoEncontrado) {
801   - for (Element style : getDocument().getAllElements("a")) {
802   - Attribute attribute = style.getAttributes().get("style");
803   - if (attribute != null)
804   - if (attribute.toString().contains("a:focus")
805   - && attribute.toString().contains("a:hover")) {
806   - // occurrences.add(buildOccurrence("4.4", true,
807   - // style.toString(), style, "1"));
808   - focoEncontrado = true;
809   - break;
810   - }
811   - }
  727 + // Caso seja encontrado o "a:focus" e "a:hover" n�o continua a
  728 + // verifica��o nos demais for's, bem como, n�o
  729 + // adiciona a ocorr�ncia
  730 + boolean focoEncontrado = false;
  731 + boolean passivelDeAvaliacao = false;
812 732  
813   - }
814   - if (!focoEncontrado) {
815   - String href = null;
816   - WebAgent webAgent;
817   - String content = "";
  733 + for (Element style : getDocument().getAllElements("style")) {
  734 + if (style.toString().contains("a:focus") && style.toString().contains("a:hover")) {
  735 + // occurrences.add(buildOccurrence("4.4", true,
  736 + // style.toString(), style, "1"));
  737 + focoEncontrado = true;
  738 + break;
  739 + }
  740 + }
  741 + if (!focoEncontrado) {
  742 + for (Element style : getDocument().getAllElements("a")) {
  743 + Attribute attribute = style.getAttributes().get("style");
  744 + if (attribute != null)
  745 + if (attribute.toString().contains("a:focus") && attribute.toString().contains("a:hover")) {
  746 + // occurrences.add(buildOccurrence("4.4", true,
  747 + // style.toString(), style, "1"));
  748 + focoEncontrado = true;
  749 + break;
  750 + }
  751 + }
818 752  
819   - boolean avalia = false;
  753 + }
  754 + if (!focoEncontrado) {
  755 + String href = null;
  756 + WebAgent webAgent;
  757 + String content = "";
  758 +
  759 + boolean avalia = false;
  760 +
  761 + for (Element link : getDocument().getAllElements("link")) {
  762 + href = link.getAttributeValue("href");
  763 + if (href != null) {
  764 + if (href.startsWith("www")) {
  765 + href = "http://" + href;
  766 + }
820 767  
821   - for (Element link : getDocument().getAllElements("link")) {
822   - href = link.getAttributeValue("href");
823   - if (href != null) {
824   - if (href.startsWith("www")) {
825   - href = "http://" + href;
826   - }
  768 + avalia = getUrl() != null || href.startsWith("http");
827 769  
828   - avalia = getUrl() != null || href.startsWith("http");
  770 + if (href.contains(".css") && avalia) {
829 771  
830   - if (href.contains(".css") && avalia) {
  772 + if (!href.startsWith("http"))
  773 + href = urlSemArquiNoFinal + href;
  774 + href = href.replace(" ", "%20").replace("//", "/").replace(":/", "://");
  775 + webAgent = WebAgent.from(href).withGetRequest().execute();
831 776  
832   - if (!href.startsWith("http"))
833   - href = urlSemArquiNoFinal + href;
834   - href = href.replace(" ", "%20").replace("//", "/")
835   - .replace(":/", "://");
836   - webAgent = WebAgent.from(href).withGetRequest()
837   - .execute();
  777 + if (webAgent.getStatusCode() != 404) {
  778 + content = webAgent.getContent();
  779 + passivelDeAvaliacao = true;
  780 + if (content != null && content.contains("a:hover") && content.contains("a:focus")) {
838 781  
839   - if (webAgent.getStatusCode() != 404) {
840   - content = webAgent.getContent();
841   - passivelDeAvaliacao = true;
842   - if (content != null && content.contains("a:hover")
843   - && content.contains("a:focus")) {
  782 + focoEncontrado = true;
  783 + break;
844 784  
845   - focoEncontrado = true;
846   - break;
  785 + }
847 786  
848 787 }
849 788  
850 789 }
851   -
852 790 }
853 791 }
854 792 }
855   - }
856 793  
857   - if (!focoEncontrado && passivelDeAvaliacao) {
858   - occurrences.add(buildOccurrence("4.4", true, getDocument()
859   - .getFirstStartTag().toString(), getDocument()
860   - .getFirstElement(), "1"));
  794 + if (!focoEncontrado && passivelDeAvaliacao) {
  795 + occurrences.add(buildOccurrence("4.4", true, getDocument().getFirstStartTag().toString(),
  796 + getDocument().getFirstElement(), "1"));
  797 + }
  798 + Collections.sort(occurrences);
  799 +
  800 + } catch (Exception e) {
  801 + e.printStackTrace();
861 802 }
862   - Collections.sort(occurrences);
863 803  
864 804 return occurrences;
865 805 }
866 806  
867   - private Occurrence buildOccurrence(String code, boolean error, String tag,
868   - Element element, String criterio) {
869   - return super.buildOccurrence(code, error, tag, element,
870   - OccurrenceClassification.PRESENTATION_DESIGN, criterio);
  807 + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element, String criterio) {
  808 + return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.PRESENTATION_DESIGN, criterio);
871 809 }
872 810  
873   - private Occurrence buildOccurrence(String code, boolean error, String tag,
874   - Element element) {
875   - return super.buildOccurrence(code, error, tag, element,
876   - OccurrenceClassification.PRESENTATION_DESIGN);
  811 + private Occurrence buildOccurrence(String code, boolean error, String tag, Element element) {
  812 + return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.PRESENTATION_DESIGN);
877 813 }
878 814  
879 815 public OccurrenceClassification type() {
... ...