Commit 3f5909dd7fc9858d623b354262699b4e4dfcbd5d

Authored by lyandro.santana
1 parent d0c1989d

Pacote de atualização

git-svn-id: https://svn.bento.ifrs.edu.br/default/ASES/ASES%20-%20Web/ASES%20-%20Web/Fontes/avaliador-api@10340 c2178572-b5ca-4887-91d2-9e3a90c7d55b
src/main/java/br/com/checker/emag/core/ContentEvaluation.java
@@ -5,6 +5,8 @@ import java.net.HttpURLConnection; @@ -5,6 +5,8 @@ import java.net.HttpURLConnection;
5 import java.net.MalformedURLException; 5 import java.net.MalformedURLException;
6 import java.net.URL; 6 import java.net.URL;
7 import java.util.ArrayList; 7 import java.util.ArrayList;
  8 +import java.util.Collections;
  9 +import java.util.Comparator;
8 import java.util.HashMap; 10 import java.util.HashMap;
9 import java.util.List; 11 import java.util.List;
10 import java.util.Map; 12 import java.util.Map;
@@ -113,6 +115,22 @@ public class ContentEvaluation extends Evaluation{ @@ -113,6 +115,22 @@ public class ContentEvaluation extends Evaluation{
113 115
114 String tagHtml = getDocument().getFirstStartTag("html").toString(); 116 String tagHtml = getDocument().getFirstStartTag("html").toString();
115 117
  118 +
  119 + /*if ( lang == null && xmlLang == null){
  120 + occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
  121 + }
  122 +
  123 + if(xmlLang != null && !(lang == null || xmlLang == null)){
  124 + occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
  125 + }else if (lang != null && lang.getValue().isEmpty()) {
  126 + occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
  127 + } else if (xmlLang != null && xmlLang.getValue().isEmpty()) {
  128 + occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
  129 + }else if (xmlns != null && xmlns.getValue().isEmpty()) {
  130 + occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
  131 + }*/
  132 +
  133 +
116 if ( lang == null && xmlLang == null){ 134 if ( lang == null && xmlLang == null){
117 occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1")); 135 occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
118 } 136 }
@@ -170,7 +188,7 @@ public class ContentEvaluation extends Evaluation{ @@ -170,7 +188,7 @@ public class ContentEvaluation extends Evaluation{
170 if(head != null) { 188 if(head != null) {
171 Element title = head.getFirstElement("title"); 189 Element title = head.getFirstElement("title");
172 if (title == null) { 190 if (title == null) {
173 - occurrences.add(this.buildOccurrence("3.3", true, "Sem fonte (nãoo existe título na página)", head, "1")); 191 + occurrences.add(this.buildOccurrence("3.3", true, " Observação – Sem Fonte (Não existe título na página)", head, "1"));
174 //occurrences.add(new Occurrence("3.3", true, "Sem fonte (n�o existe t�tulo na p�gina)",OccurrenceClassification.CONTENT_INFORMATION,"1")); 192 //occurrences.add(new Occurrence("3.3", true, "Sem fonte (n�o existe t�tulo na p�gina)",OccurrenceClassification.CONTENT_INFORMATION,"1"));
175 } else if (title.isEmpty()) { 193 } else if (title.isEmpty()) {
176 occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1")); 194 occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1"));
@@ -308,7 +326,20 @@ public class ContentEvaluation extends Evaluation{ @@ -308,7 +326,20 @@ public class ContentEvaluation extends Evaluation{
308 String content = link.getContent().getTextExtractor().toString(); 326 String content = link.getContent().getTextExtractor().toString();
309 String altImg = link.getFirstElement("img")!=null ? link.getFirstElement("img").getAttributeValue("alt") : "" ; 327 String altImg = link.getFirstElement("img")!=null ? link.getFirstElement("img").getAttributeValue("alt") : "" ;
310 328
311 - Pattern pattern; 329 + for(String leiaMais:this.leiaMais){
  330 +
  331 + if(title!=null)
  332 + if(title.toLowerCase().equals(leiaMais)) return true;
  333 +
  334 + if(content!=null)
  335 + if(content.toLowerCase().equals(leiaMais)) return true;
  336 +
  337 + if(altImg!=null)
  338 + if(altImg.toLowerCase().equals(leiaMais)) return true;
  339 + }
  340 +
  341 +
  342 + /* Pattern pattern;
312 for(String leiaMais:this.leiaMais){ 343 for(String leiaMais:this.leiaMais){
313 pattern = Pattern.compile("("+leiaMais+")"); 344 pattern = Pattern.compile("("+leiaMais+")");
314 if(title!=null) 345 if(title!=null)
@@ -319,7 +350,7 @@ public class ContentEvaluation extends Evaluation{ @@ -319,7 +350,7 @@ public class ContentEvaluation extends Evaluation{
319 350
320 if(altImg!=null) 351 if(altImg!=null)
321 if(pattern.matcher(altImg.toLowerCase()).find()) return true; 352 if(pattern.matcher(altImg.toLowerCase()).find()) return true;
322 - } 353 + }*/
323 354
324 return false; 355 return false;
325 } 356 }
@@ -362,7 +393,8 @@ public class ContentEvaluation extends Evaluation{ @@ -362,7 +393,8 @@ public class ContentEvaluation extends Evaluation{
362 } 393 }
363 394
364 private boolean hasSameContentDiferentLink(Element link) { 395 private boolean hasSameContentDiferentLink(Element link) {
365 - String content = link.getContent().getTextExtractor().toString(); 396 + //String content = link.getContent().getTextExtractor().toString();
  397 + String content = link.getContent().toString();
366 398
367 if(content != null) 399 if(content != null)
368 content = content.replace("http://","").replaceFirst("(/$)", ""); 400 content = content.replace("http://","").replaceFirst("(/$)", "");
@@ -381,7 +413,8 @@ public class ContentEvaluation extends Evaluation{ @@ -381,7 +413,8 @@ public class ContentEvaluation extends Evaluation{
381 for(Element otherLink : getDocument().getAllElements("a")){ 413 for(Element otherLink : getDocument().getAllElements("a")){
382 414
383 if(otherLink.getBegin() == link.getBegin()) continue; 415 if(otherLink.getBegin() == link.getBegin()) continue;
384 - otherContent = otherLink.getContent().getTextExtractor().toString(); 416 + otherContent = otherLink.getContent().toString();
  417 + //otherContent = otherLink.getContent().getTextExtractor().toString();
385 418
386 if(otherContent != null) 419 if(otherContent != null)
387 otherContent = otherContent.replace("http://","").replaceFirst("(/$)", ""); 420 otherContent = otherContent.replace("http://","").replaceFirst("(/$)", "");
@@ -392,11 +425,12 @@ public class ContentEvaluation extends Evaluation{ @@ -392,11 +425,12 @@ public class ContentEvaluation extends Evaluation{
392 otherHref = otherHref.replace("http://","").replaceFirst("(/$)", ""); 425 otherHref = otherHref.replace("http://","").replaceFirst("(/$)", "");
393 426
394 if(StringUtils.isBlank(otherHref))continue; 427 if(StringUtils.isBlank(otherHref))continue;
395 - if(!linksVerificados.contains(content))  
396 - if(content.toLowerCase().equals(otherContent.toLowerCase()) && !href.equals(otherHref)){ 428 + if(!linksVerificados.contains(content)){
  429 + if(content.toLowerCase().equals(otherContent.toLowerCase()) && !href.equals(otherHref)){
397 linksVerificados.add(content); 430 linksVerificados.add(content);
398 return true; 431 return true;
399 } 432 }
  433 + }
400 } 434 }
401 return false; 435 return false;
402 } 436 }
@@ -416,7 +450,7 @@ public class ContentEvaluation extends Evaluation{ @@ -416,7 +450,7 @@ public class ContentEvaluation extends Evaluation{
416 450
417 String[] parts = null; 451 String[] parts = null;
418 452
419 - String[] descricoes = {"figura", "imagem", "alt", "descri��o", "foto"}; 453 + String[] descricoes = {"figura", "imagem", "alt", "descrição", "foto"};
420 454
421 for (Element img : getDocument().getAllElements("img")) { 455 for (Element img : getDocument().getAllElements("img")) {
422 Attribute alt = img.getAttributes().get("alt"); 456 Attribute alt = img.getAttributes().get("alt");
@@ -521,10 +555,10 @@ public class ContentEvaluation extends Evaluation{ @@ -521,10 +555,10 @@ public class ContentEvaluation extends Evaluation{
521 Attribute summary = table.getAttributes().get("summary"); 555 Attribute summary = table.getAttributes().get("summary");
522 556
523 if (summary == null || summary.getValue().equals("")) 557 if (summary == null || summary.getValue().equals(""))
524 - occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString()+"</table>", table, "1")); 558 + occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString(), table, "1"));
525 559
526 if(table.getAllElements("caption").isEmpty() || table.getAllElements("caption") == null) 560 if(table.getAllElements("caption").isEmpty() || table.getAllElements("caption") == null)
527 - occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString()+"</table>", table, "1")); 561 + occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString(), table, "1"));
528 } 562 }
529 563
530 return occurrences; 564 return occurrences;
@@ -540,7 +574,7 @@ public class ContentEvaluation extends Evaluation{ @@ -540,7 +574,7 @@ public class ContentEvaluation extends Evaluation{
540 for (Element table : getDocument().getAllElements("table")) { 574 for (Element table : getDocument().getAllElements("table")) {
541 for(Element caption : table.getAllElements("caption")){ 575 for(Element caption : table.getAllElements("caption")){
542 if(caption == null || caption.isEmpty()) 576 if(caption == null || caption.isEmpty())
543 - occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString()+"</table>", table, "1")); 577 + occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString(), table, "1"));
544 } 578 }
545 } 579 }
546 580
@@ -560,7 +594,7 @@ public class ContentEvaluation extends Evaluation{ @@ -560,7 +594,7 @@ public class ContentEvaluation extends Evaluation{
560 594
561 595
562 if (summary == null || summary.getValue().equals("")) 596 if (summary == null || summary.getValue().equals(""))
563 - occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString()+"</table>", table, "1")); 597 + occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString(), table, "1"));
564 598
565 for (Element thead : table.getAllElements("thead")) { 599 for (Element thead : table.getAllElements("thead")) {
566 if (thead != null) 600 if (thead != null)
@@ -617,6 +651,12 @@ public class ContentEvaluation extends Evaluation{ @@ -617,6 +651,12 @@ public class ContentEvaluation extends Evaluation{
617 651
618 }*/ 652 }*/
619 } 653 }
  654 + //Sorting
  655 + Collections.sort(occurrences, new Comparator<Occurrence>() {
  656 + public int compare(Occurrence occurrence1, Occurrence occurrence2){
  657 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  658 + }
  659 + });
620 660
621 return occurrences; 661 return occurrences;
622 662