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 5 import java.net.MalformedURLException;
6 6 import java.net.URL;
7 7 import java.util.ArrayList;
  8 +import java.util.Collections;
  9 +import java.util.Comparator;
8 10 import java.util.HashMap;
9 11 import java.util.List;
10 12 import java.util.Map;
... ... @@ -113,6 +115,22 @@ public class ContentEvaluation extends Evaluation{
113 115  
114 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 134 if ( lang == null && xmlLang == null){
117 135 occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
118 136 }
... ... @@ -170,7 +188,7 @@ public class ContentEvaluation extends Evaluation{
170 188 if(head != null) {
171 189 Element title = head.getFirstElement("title");
172 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 192 //occurrences.add(new Occurrence("3.3", true, "Sem fonte (n�o existe t�tulo na p�gina)",OccurrenceClassification.CONTENT_INFORMATION,"1"));
175 193 } else if (title.isEmpty()) {
176 194 occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1"));
... ... @@ -308,7 +326,20 @@ public class ContentEvaluation extends Evaluation{
308 326 String content = link.getContent().getTextExtractor().toString();
309 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 343 for(String leiaMais:this.leiaMais){
313 344 pattern = Pattern.compile("("+leiaMais+")");
314 345 if(title!=null)
... ... @@ -319,7 +350,7 @@ public class ContentEvaluation extends Evaluation{
319 350  
320 351 if(altImg!=null)
321 352 if(pattern.matcher(altImg.toLowerCase()).find()) return true;
322   - }
  353 + }*/
323 354  
324 355 return false;
325 356 }
... ... @@ -362,7 +393,8 @@ public class ContentEvaluation extends Evaluation{
362 393 }
363 394  
364 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 399 if(content != null)
368 400 content = content.replace("http://","").replaceFirst("(/$)", "");
... ... @@ -381,7 +413,8 @@ public class ContentEvaluation extends Evaluation{
381 413 for(Element otherLink : getDocument().getAllElements("a")){
382 414  
383 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 419 if(otherContent != null)
387 420 otherContent = otherContent.replace("http://","").replaceFirst("(/$)", "");
... ... @@ -392,11 +425,12 @@ public class ContentEvaluation extends Evaluation{
392 425 otherHref = otherHref.replace("http://","").replaceFirst("(/$)", "");
393 426  
394 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 430 linksVerificados.add(content);
398 431 return true;
399 432 }
  433 + }
400 434 }
401 435 return false;
402 436 }
... ... @@ -416,7 +450,7 @@ public class ContentEvaluation extends Evaluation{
416 450  
417 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 455 for (Element img : getDocument().getAllElements("img")) {
422 456 Attribute alt = img.getAttributes().get("alt");
... ... @@ -521,10 +555,10 @@ public class ContentEvaluation extends Evaluation{
521 555 Attribute summary = table.getAttributes().get("summary");
522 556  
523 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 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 564 return occurrences;
... ... @@ -540,7 +574,7 @@ public class ContentEvaluation extends Evaluation{
540 574 for (Element table : getDocument().getAllElements("table")) {
541 575 for(Element caption : table.getAllElements("caption")){
542 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 594  
561 595  
562 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 599 for (Element thead : table.getAllElements("thead")) {
566 600 if (thead != null)
... ... @@ -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 661 return occurrences;
622 662  
... ...