Commit 0a93f9751dba09fe4d8d28d7541d228fc3e2b22e

Authored by lyandro.santana
1 parent 874c963d

Pacote de atualização4

git-svn-id: https://svn.bento.ifrs.edu.br/default/ASES/ASES%20-%20Web/ASES%20-%20Web/Fontes/avaliador-api@10334 c2178572-b5ca-4887-91d2-9e3a90c7d55b
src/main/java/br/com/checker/emag/core/ContentEvaluation.java
... ... @@ -171,6 +171,7 @@ public class ContentEvaluation extends Evaluation{
171 171 Element title = head.getFirstElement("title");
172 172 if (title == null) {
173 173 occurrences.add(this.buildOccurrence("3.3", true, "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"));
174 175 } else if (title.isEmpty()) {
175 176 occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1"));
176 177 }
... ... @@ -193,7 +194,7 @@ public class ContentEvaluation extends Evaluation{
193 194 String title = link.getAttributeValue("title");
194 195 String content = link.getContent().toString();
195 196  
196   - if(hasEqualsContentHref(link) &&isRegistroBr(content))
  197 + if(hasEqualsContentHref(link) && isRegistroBr(content))
197 198 occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "1"));
198 199  
199 200 if(!hasContent(link))
... ... @@ -236,7 +237,7 @@ public class ContentEvaluation extends Evaluation{
236 237  
237 238 private boolean isLinkUnavailable(Element link){
238 239  
239   - if(link.getAttributeValue("href") != null && !link.getAttributeValue("href").equals("#") && !link.getAttributeValue("href").contains("javascript")){
  240 + if(link.getAttributeValue("href") != null && !link.getAttributeValue("href").equals("#") && !link.getAttributeValue("href").equals("/") && !link.getAttributeValue("href").contains("javascript")){
240 241 int[] codErro ={400, 401,402, 403,404, 405, 406, 407, 408,409, 410, 411, 412, 414,415, 416, 417, 418,422, 423,424,425,426,450,499,500,501,502,503,504,505};
241 242 int codResponse = 0;
242 243  
... ... @@ -336,7 +337,12 @@ public class ContentEvaluation extends Evaluation{
336 337  
337 338 private boolean hasEqualsContentHref(Element link) {
338 339 String content = link.getContent().getTextExtractor().toString();
  340 + if(content != null && !content.isEmpty())
  341 + content = content.replace("http://","").replaceFirst("(/$)", "");
  342 +
339 343 String href = link.getAttributeValue("href");
  344 + if(href != null && !href.isEmpty())
  345 + href = href.replace("http://","").replaceFirst("(/$)", "");
340 346 return content.equals(href);
341 347 }
342 348  
... ... @@ -357,18 +363,34 @@ public class ContentEvaluation extends Evaluation{
357 363  
358 364 private boolean hasSameContentDiferentLink(Element link) {
359 365 String content = link.getContent().getTextExtractor().toString();
  366 +
  367 + if(content != null)
  368 + content = content.replace("http://","").replaceFirst("(/$)", "");
  369 +
360 370 String href = link.getAttributeValue("href");
  371 +
  372 + if(href != null)
  373 + href = href.replace("http://","").replaceFirst("(/$)", "");
  374 +
361 375 if(StringUtils.isBlank(href)) return false;
362 376 String otherContent;
363 377 String otherHref;
364 378  
365 379 List<String> linksVerificados = new ArrayList<String>();
366 380  
367   - for(Element otherLink:getDocument().getAllElements("a")){
  381 + for(Element otherLink : getDocument().getAllElements("a")){
368 382  
369 383 if(otherLink.getBegin() == link.getBegin()) continue;
370 384 otherContent = otherLink.getContent().getTextExtractor().toString();
  385 +
  386 + if(otherContent != null)
  387 + otherContent = otherContent.replace("http://","").replaceFirst("(/$)", "");
  388 +
371 389 otherHref = otherLink.getAttributeValue("href");
  390 +
  391 + if(otherHref != null)
  392 + otherHref = otherHref.replace("http://","").replaceFirst("(/$)", "");
  393 +
372 394 if(StringUtils.isBlank(otherHref))continue;
373 395 if(!linksVerificados.contains(content))
374 396 if(content.toLowerCase().equals(otherContent.toLowerCase()) && !href.equals(otherHref)){
... ... @@ -499,10 +521,10 @@ public class ContentEvaluation extends Evaluation{
499 521 Attribute summary = table.getAttributes().get("summary");
500 522  
501 523 if (summary == null || summary.getValue().equals(""))
502   - occurrences.add(buildOccurrence("3.9", false, table.toString(), table, "1"));
  524 + occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString()+"</table>", table, "1"));
503 525  
504 526 if(table.getAllElements("caption").isEmpty() || table.getAllElements("caption") == null)
505   - occurrences.add(buildOccurrence("3.9", false, table.toString(), table, "1"));
  527 + occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString()+"</table>", table, "1"));
506 528 }
507 529  
508 530 return occurrences;
... ... @@ -518,7 +540,7 @@ public class ContentEvaluation extends Evaluation{
518 540 for (Element table : getDocument().getAllElements("table")) {
519 541 for(Element caption : table.getAllElements("caption")){
520 542 if(caption == null || caption.isEmpty())
521   - occurrences.add(buildOccurrence("3.10", true, table.toString(), table, "1"));
  543 + occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString()+"</table>", table, "1"));
522 544 }
523 545 }
524 546  
... ... @@ -538,7 +560,7 @@ public class ContentEvaluation extends Evaluation{
538 560  
539 561  
540 562 if (summary == null || summary.getValue().equals(""))
541   - occurrences.add(buildOccurrence("3.10", true, table.toString(), table, "1"));
  563 + occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString()+"</table>", table, "1"));
542 564  
543 565 for (Element thead : table.getAllElements("thead")) {
544 566 if (thead != null)
... ...
src/main/java/br/com/checker/emag/core/MarkEvaluation.java
... ... @@ -177,8 +177,25 @@ public class MarkEvaluation extends Evaluation {
177 177  
178 178 List<String> tags = Arrays.asList("h1","h2","h3","h4","h5","h6","a","p");
179 179  
  180 + for (String tag : tags) {
  181 + for (Element element : getDocument().getAllElements(tag)) {
  182 + if(element.getAttributes().getCount()==0)
  183 + occurrences.add(this.buildOccurrence("1.2", true, element.toString(), element, "1"));
  184 + else if(element.getTextExtractor().toString().isEmpty())
  185 + occurrences.add(this.buildOccurrence("1.2", false, element.toString(), element, "1"));
  186 + }
  187 +
  188 + }
  189 +
  190 + //Sorting
  191 + Collections.sort(occurrences, new Comparator<Occurrence>() {
  192 + public int compare(Occurrence occurrence1, Occurrence occurrence2){
  193 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  194 + }
  195 + });
180 196  
181   - boolean isError = false;
  197 +
  198 + /*boolean isError = false;
182 199 for (Element element : getDocument().getAllElements()) {
183 200 Attributes attribute = element.getAttributes();
184 201  
... ... @@ -189,7 +206,7 @@ public class MarkEvaluation extends Evaluation {
189 206 occurrences.add(this.buildOccurrence("1.2", isError, element.toString(), element, "1"));
190 207 else if(attribute.getCount()==0)
191 208 occurrences.add(this.buildOccurrence("1.2", isError, element.toString(), element, "1"));
192   - }
  209 + }*/
193 210  
194 211  
195 212  
... ... @@ -242,7 +259,17 @@ public class MarkEvaluation extends Evaluation {
242 259 }
243 260  
244 261 if(!hasH())
245   - occurrences.add(this.buildOccurrence("1.3", true,"Sem fonte (os níveis de título não foram utilizados)", getDocument().getFirstElement(), "1"));
  262 + occurrences.add(this.buildOccurrence("1.3", true,"Sem fonte (os níveis de título não foram utilizados)", getDocument().getFirstElement(), "1"));
  263 +
  264 +
  265 +
  266 + //Sorting
  267 + Collections.sort(occurrences, new Comparator<Occurrence>() {
  268 + public int compare(Occurrence occurrence1, Occurrence occurrence2){
  269 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  270 + }
  271 + });
  272 +
246 273  
247 274 return occurrences;
248 275 }
... ... @@ -438,12 +465,12 @@ public class MarkEvaluation extends Evaluation {
438 465 List<Occurrence> occurrences = new ArrayList<Occurrence>();
439 466  
440 467 for (Element table : getDocument().getAllElements("table"))
441   - occurrences.add(this.buildOccurrence("1.6", false, table.toString(), table, "1"));
  468 + occurrences.add(this.buildOccurrence("1.6", false, table.getStartTag()+"</table>", table, "1"));
442 469  
443 470 for (Element table : getDocument().getAllElements("table")){
444 471 Element tagsForm = table.getFirstElement("form");
445 472 if(tagsForm != null)
446   - occurrences.add(this.buildOccurrence("1.6", true, table.toString(), table, "2"));
  473 + occurrences.add(this.buildOccurrence("1.6", true, table.getStartTag()+"</table>", table, "2"));
447 474 }
448 475  
449 476 return occurrences;
... ...