Commit d0c1989d5b6637dae5446bc8cfdb5aa1e4efdf26

Authored by lyandro.santana
1 parent 74b2e5ba

Pacote de atualização

git-svn-id: https://svn.bento.ifrs.edu.br/default/ASES/ASES%20-%20Web/ASES%20-%20Web/Fontes/avaliador-api@10339 c2178572-b5ca-4887-91d2-9e3a90c7d55b
src/main/java/br/com/checker/emag/core/MarkEvaluation.java
1 1 package br.com.checker.emag.core;
2 2  
  3 +import java.io.BufferedReader;
  4 +import java.io.InputStreamReader;
  5 +import java.net.URL;
  6 +import java.net.URLConnection;
3 7 import java.util.ArrayList;
4 8 import java.util.Arrays;
5 9 import java.util.Collections;
... ... @@ -133,23 +137,28 @@ public class MarkEvaluation extends Evaluation {
133 137 e.printStackTrace();
134 138 }
135 139  
  140 + String css = "";
  141 + for (Element element : getDocument().getAllElements("style"))
  142 + css+= element.getContent().toString();
136 143  
137 144 try {
138   - ValidationResponse response =
139   - new ValidatorBuilder().css().validate(getDocument().getSource().toString());
  145 + if(StringUtils.isNotBlank(css)){
  146 + ValidationResponse response =
  147 + new ValidatorBuilder().css().validate(css);
  148 +
140 149  
141   -
142   - for(Defect warn :response.warnings()) {
143   - //occurrences.add(buildOccurrence("1.1", false,warn.line(),warn.column(),OccurrenceClassification.MARK,"2"));
144   - occurrences.add(buildOccurrence(warn.line(), warn.column(), "1.1", false, warn.source().toString().isEmpty() ? warn.message() : "["+warn.message()+"] "+warn.source(), OccurrenceClassification.MARK,"2"));
145   - //occurrences.add(this.buildOccurrence("1.1", false, warn.source(), getDocument().getFirstElement(), "2"));
146   - }
147   -
148   - for(Defect error :response.errors()) {
149   - //occurrences.add(buildOccurrence("1.1", false,error.line(),error.column(),OccurrenceClassification.MARK,"2"));
150   - occurrences.add(buildOccurrence(error.line(), error.column(), "1.1", true, error.source().toString().isEmpty() ? error.message() : "["+error.message()+"] "+error.source(), OccurrenceClassification.MARK,"2"));
151   - ///occurrences.add(this.buildOccurrence("1.1", true, error.source().toString().isEmpty() ? error.message() : error.source(), getDocument().getFirstElement(), "2"));
152   - }
  150 + for(Defect warn :response.warnings()) {
  151 + //occurrences.add(buildOccurrence("1.1", false,warn.line(),warn.column(),OccurrenceClassification.MARK,"2"));
  152 + occurrences.add(buildOccurrence(warn.line(), warn.column(), "1.1", false, warn.source().toString().isEmpty() ? warn.message() : "["+warn.message()+"] "+warn.source(), OccurrenceClassification.MARK,"2"));
  153 + //occurrences.add(this.buildOccurrence("1.1", false, warn.source(), getDocument().getFirstElement(), "2"));
  154 + }
  155 +
  156 + for(Defect error :response.errors()) {
  157 + //occurrences.add(buildOccurrence("1.1", false,error.line(),error.column(),OccurrenceClassification.MARK,"2"));
  158 + occurrences.add(buildOccurrence(error.line(), error.column(), "1.1", true, error.source().toString().isEmpty() ? error.message() : "["+error.message()+"] "+error.source(), OccurrenceClassification.MARK,"2"));
  159 + ///occurrences.add(this.buildOccurrence("1.1", true, error.source().toString().isEmpty() ? error.message() : error.source(), getDocument().getFirstElement(), "2"));
  160 + }
  161 + }
153 162  
154 163 } catch (Exception e) {
155 164 e.printStackTrace();
... ... @@ -463,10 +472,21 @@ public class MarkEvaluation extends Evaluation {
463 472 private List<Occurrence> checkRecommendation5() {
464 473 List<Occurrence> occurrences = new ArrayList<Occurrence>();
465 474  
466   - Element firstLink = getDocument().getFirstElement("href", Pattern.compile(".*#.*"));
  475 + /*Element firstLink = getDocument().getFirstElement("href", Pattern.compile("#.*"));
467 476  
468 477 if(firstLink != null)
469   - occurrences.add(this.buildOccurrence("1.5", false, firstLink.toString(), firstLink, "4"));
  478 + occurrences.add(this.buildOccurrence("1.5", false, firstLink.toString(), firstLink, "4"));*/
  479 +
  480 + for (Element link : getDocument().getAllElements("a")) {
  481 + String contLink = link.getAttributeValue("href");
  482 + if(contLink != null && contLink.length() > 1 && contLink.substring(0,1).equals("#")){
  483 + occurrences.add(this.buildOccurrence("1.5", false, link.toString(), link, "4")); break;
  484 + }
  485 +
  486 + }
  487 +
  488 +
  489 +
470 490  
471 491 /*if(firstLink == null){
472 492 occurrences.add(this.buildOccurrence("1.5", false, getDocument().getFirstElement().toString(), getDocument().getFirstElement(), "4"));
... ... @@ -579,6 +599,14 @@ public class MarkEvaluation extends Evaluation {
579 599 occurrences.add(this.buildOccurrence("1.5", false, elemento.toString(), elemento,"5"));
580 600 }
581 601  
  602 +
  603 + //Sorting
  604 + Collections.sort(occurrences, new Comparator<Occurrence>() {
  605 + public int compare(Occurrence occurrence1, Occurrence occurrence2){
  606 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  607 + }
  608 + });
  609 +
582 610 return occurrences;
583 611 }
584 612  
... ... @@ -727,13 +755,13 @@ public class MarkEvaluation extends Evaluation {
727 755 }
728 756  
729 757 if(!hasBanner)
730   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe LANDMARKS na p&aacute;gina - banner)", getDocument().getFirstElement(),"2"));
  758 + occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe LANDMARKS na p&aacute;gina - <BANNER>)", getDocument().getFirstElement(),"2"));
731 759  
732 760 if(!hasNavigation)
733   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe LANDMARKS na p&aacute;gina - navigation)", getDocument().getFirstElement(),"2"));
  761 + occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe LANDMARKS na p&aacute;gina - <NAVIGATION>)", getDocument().getFirstElement(),"2"));
734 762  
735 763 if(!hasMain)
736   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe LANDMARKS na p&aacute;gina - main)", getDocument().getFirstElement(),"2"));
  764 + occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe LANDMARKS na p&aacute;gina - <MAIN>)", getDocument().getFirstElement(),"2"));
737 765 }
738 766  
739 767  
... ...