Commit 0a93f9751dba09fe4d8d28d7541d228fc3e2b22e
1 parent
874c963d
Exists in
master
and in
1 other branch
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
Showing
2 changed files
with
61 additions
and
12 deletions
Show diff stats
src/main/java/br/com/checker/emag/core/ContentEvaluation.java
@@ -171,6 +171,7 @@ public class ContentEvaluation extends Evaluation{ | @@ -171,6 +171,7 @@ public class ContentEvaluation extends Evaluation{ | ||
171 | Element title = head.getFirstElement("title"); | 171 | Element title = head.getFirstElement("title"); |
172 | if (title == null) { | 172 | if (title == null) { |
173 | occurrences.add(this.buildOccurrence("3.3", true, "Sem fonte (não existe título na página)", head, "1")); | 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 | } else if (title.isEmpty()) { | 175 | } else if (title.isEmpty()) { |
175 | occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1")); | 176 | occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1")); |
176 | } | 177 | } |
@@ -193,7 +194,7 @@ public class ContentEvaluation extends Evaluation{ | @@ -193,7 +194,7 @@ public class ContentEvaluation extends Evaluation{ | ||
193 | String title = link.getAttributeValue("title"); | 194 | String title = link.getAttributeValue("title"); |
194 | String content = link.getContent().toString(); | 195 | String content = link.getContent().toString(); |
195 | 196 | ||
196 | - if(hasEqualsContentHref(link) &&isRegistroBr(content)) | 197 | + if(hasEqualsContentHref(link) && isRegistroBr(content)) |
197 | occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "1")); | 198 | occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "1")); |
198 | 199 | ||
199 | if(!hasContent(link)) | 200 | if(!hasContent(link)) |
@@ -236,7 +237,7 @@ public class ContentEvaluation extends Evaluation{ | @@ -236,7 +237,7 @@ public class ContentEvaluation extends Evaluation{ | ||
236 | 237 | ||
237 | private boolean isLinkUnavailable(Element link){ | 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 | 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 | 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 | int codResponse = 0; | 242 | int codResponse = 0; |
242 | 243 | ||
@@ -336,7 +337,12 @@ public class ContentEvaluation extends Evaluation{ | @@ -336,7 +337,12 @@ public class ContentEvaluation extends Evaluation{ | ||
336 | 337 | ||
337 | private boolean hasEqualsContentHref(Element link) { | 338 | private boolean hasEqualsContentHref(Element link) { |
338 | String content = link.getContent().getTextExtractor().toString(); | 339 | String content = link.getContent().getTextExtractor().toString(); |
340 | + if(content != null && !content.isEmpty()) | ||
341 | + content = content.replace("http://","").replaceFirst("(/$)", ""); | ||
342 | + | ||
339 | String href = link.getAttributeValue("href"); | 343 | String href = link.getAttributeValue("href"); |
344 | + if(href != null && !href.isEmpty()) | ||
345 | + href = href.replace("http://","").replaceFirst("(/$)", ""); | ||
340 | return content.equals(href); | 346 | return content.equals(href); |
341 | } | 347 | } |
342 | 348 | ||
@@ -357,18 +363,34 @@ public class ContentEvaluation extends Evaluation{ | @@ -357,18 +363,34 @@ public class ContentEvaluation extends Evaluation{ | ||
357 | 363 | ||
358 | private boolean hasSameContentDiferentLink(Element link) { | 364 | private boolean hasSameContentDiferentLink(Element link) { |
359 | String content = link.getContent().getTextExtractor().toString(); | 365 | String content = link.getContent().getTextExtractor().toString(); |
366 | + | ||
367 | + if(content != null) | ||
368 | + content = content.replace("http://","").replaceFirst("(/$)", ""); | ||
369 | + | ||
360 | String href = link.getAttributeValue("href"); | 370 | String href = link.getAttributeValue("href"); |
371 | + | ||
372 | + if(href != null) | ||
373 | + href = href.replace("http://","").replaceFirst("(/$)", ""); | ||
374 | + | ||
361 | if(StringUtils.isBlank(href)) return false; | 375 | if(StringUtils.isBlank(href)) return false; |
362 | String otherContent; | 376 | String otherContent; |
363 | String otherHref; | 377 | String otherHref; |
364 | 378 | ||
365 | List<String> linksVerificados = new ArrayList<String>(); | 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 | if(otherLink.getBegin() == link.getBegin()) continue; | 383 | if(otherLink.getBegin() == link.getBegin()) continue; |
370 | otherContent = otherLink.getContent().getTextExtractor().toString(); | 384 | otherContent = otherLink.getContent().getTextExtractor().toString(); |
385 | + | ||
386 | + if(otherContent != null) | ||
387 | + otherContent = otherContent.replace("http://","").replaceFirst("(/$)", ""); | ||
388 | + | ||
371 | otherHref = otherLink.getAttributeValue("href"); | 389 | otherHref = otherLink.getAttributeValue("href"); |
390 | + | ||
391 | + if(otherHref != null) | ||
392 | + otherHref = otherHref.replace("http://","").replaceFirst("(/$)", ""); | ||
393 | + | ||
372 | if(StringUtils.isBlank(otherHref))continue; | 394 | if(StringUtils.isBlank(otherHref))continue; |
373 | if(!linksVerificados.contains(content)) | 395 | if(!linksVerificados.contains(content)) |
374 | if(content.toLowerCase().equals(otherContent.toLowerCase()) && !href.equals(otherHref)){ | 396 | if(content.toLowerCase().equals(otherContent.toLowerCase()) && !href.equals(otherHref)){ |
@@ -499,10 +521,10 @@ public class ContentEvaluation extends Evaluation{ | @@ -499,10 +521,10 @@ public class ContentEvaluation extends Evaluation{ | ||
499 | Attribute summary = table.getAttributes().get("summary"); | 521 | Attribute summary = table.getAttributes().get("summary"); |
500 | 522 | ||
501 | if (summary == null || summary.getValue().equals("")) | 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 | if(table.getAllElements("caption").isEmpty() || table.getAllElements("caption") == null) | 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 | return occurrences; | 530 | return occurrences; |
@@ -518,7 +540,7 @@ public class ContentEvaluation extends Evaluation{ | @@ -518,7 +540,7 @@ public class ContentEvaluation extends Evaluation{ | ||
518 | for (Element table : getDocument().getAllElements("table")) { | 540 | for (Element table : getDocument().getAllElements("table")) { |
519 | for(Element caption : table.getAllElements("caption")){ | 541 | for(Element caption : table.getAllElements("caption")){ |
520 | if(caption == null || caption.isEmpty()) | 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,7 +560,7 @@ public class ContentEvaluation extends Evaluation{ | ||
538 | 560 | ||
539 | 561 | ||
540 | if (summary == null || summary.getValue().equals("")) | 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 | for (Element thead : table.getAllElements("thead")) { | 565 | for (Element thead : table.getAllElements("thead")) { |
544 | if (thead != null) | 566 | if (thead != null) |
src/main/java/br/com/checker/emag/core/MarkEvaluation.java
@@ -177,8 +177,25 @@ public class MarkEvaluation extends Evaluation { | @@ -177,8 +177,25 @@ public class MarkEvaluation extends Evaluation { | ||
177 | 177 | ||
178 | List<String> tags = Arrays.asList("h1","h2","h3","h4","h5","h6","a","p"); | 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 | for (Element element : getDocument().getAllElements()) { | 199 | for (Element element : getDocument().getAllElements()) { |
183 | Attributes attribute = element.getAttributes(); | 200 | Attributes attribute = element.getAttributes(); |
184 | 201 | ||
@@ -189,7 +206,7 @@ public class MarkEvaluation extends Evaluation { | @@ -189,7 +206,7 @@ public class MarkEvaluation extends Evaluation { | ||
189 | occurrences.add(this.buildOccurrence("1.2", isError, element.toString(), element, "1")); | 206 | occurrences.add(this.buildOccurrence("1.2", isError, element.toString(), element, "1")); |
190 | else if(attribute.getCount()==0) | 207 | else if(attribute.getCount()==0) |
191 | occurrences.add(this.buildOccurrence("1.2", isError, element.toString(), element, "1")); | 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,7 +259,17 @@ public class MarkEvaluation extends Evaluation { | ||
242 | } | 259 | } |
243 | 260 | ||
244 | if(!hasH()) | 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 | return occurrences; | 274 | return occurrences; |
248 | } | 275 | } |
@@ -438,12 +465,12 @@ public class MarkEvaluation extends Evaluation { | @@ -438,12 +465,12 @@ public class MarkEvaluation extends Evaluation { | ||
438 | List<Occurrence> occurrences = new ArrayList<Occurrence>(); | 465 | List<Occurrence> occurrences = new ArrayList<Occurrence>(); |
439 | 466 | ||
440 | for (Element table : getDocument().getAllElements("table")) | 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 | for (Element table : getDocument().getAllElements("table")){ | 470 | for (Element table : getDocument().getAllElements("table")){ |
444 | Element tagsForm = table.getFirstElement("form"); | 471 | Element tagsForm = table.getFirstElement("form"); |
445 | if(tagsForm != null) | 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 | return occurrences; | 476 | return occurrences; |