diff --git a/src/main/java/br/com/checker/emag/core/MarkEvaluation.java b/src/main/java/br/com/checker/emag/core/MarkEvaluation.java index 0c7330d..48aec33 100644 --- a/src/main/java/br/com/checker/emag/core/MarkEvaluation.java +++ b/src/main/java/br/com/checker/emag/core/MarkEvaluation.java @@ -236,29 +236,70 @@ public class MarkEvaluation extends Evaluation { for (String tag : tags) { for (Element element : getDocument().getAllElements(tag)) { + /*if(element.getAttributes().getCount()==0) occurrences.add(this.buildOccurrence("1.2", true, element.toString(), element, "1")); else*/ + + if(element != null){ + Element img = element.getFirstElement("img"); + if(img != null){ + if(img.getAttributes().get("alt") != null && img.getAttributes().get("alt").getValue().isEmpty()){ + occurrences.add(this.buildOccurrence("1.2", true, element.getStartTag().toString(), element, "1")); + }else{ + if(element.getContent().toString().isEmpty() || element.getContent().toString().equals("")) + occurrences.add(this.buildOccurrence("1.2", true, element.getStartTag().toString(), element, "1")); + } + } + } + + /* + if(element.getTextExtractor().toString().isEmpty()) - occurrences.add(this.buildOccurrence("1.2", false, element.toString(), element, "1")); + occurrences.add(this.buildOccurrence("1.2", true, element.toString(), element, "1")); else{ Element img = element.getFirstElement("img"); if(img != null) - if(img.getAttributeValue("alt").equals("") || img.getAttributeValue("alt").isEmpty()) - occurrences.add(this.buildOccurrence("1.2", false, element.toString(), element, "1")); + if(img.getAttributes().get("alt").getValue().equals("") || img.getAttributeValue("alt").isEmpty()) + occurrences.add(this.buildOccurrence("1.2", true, element.toString(), element, "1")); - } + }*/ } } - - //Sorting - Collections.sort(occurrences, new Comparator() { - public int compare(Occurrence occurrence1, Occurrence occurrence2){ - return occurrence1.getLine().compareTo(occurrence2.getLine()); - } - }); + + + for (Element element : getDocument().getAllElements()) { + + if(element != null){ + Element img = element.getFirstElement("img"); + + if(img != null){ + + if(img.getAttributes().get("alt") != null && img.getAttributes().get("alt").getValue().isEmpty()) + occurrences.add(this.buildOccurrence("1.2", false, element.getStartTag().toString(), element, "1")); + + }else{ + if(element.getSource().toString().trim().equals("")){ + occurrences.add(this.buildOccurrence("1.2", false, element.getStartTag().toString(), element, "1")); + } + /*if(element.getTextExtractor().toString().isEmpty()) + occurrences.add(this.buildOccurrence("1.2", false, element.toString(), element, "1"));*/ + } + } + /* + if(element.getTextExtractor().toString().isEmpty()) + occurrences.add(this.buildOccurrence("1.2", false, element.toString(), element, "1")); + else{ + Element img = element.getFirstElement("img"); + if(img != null) + if(img.getAttributeValue("alt").equals("") || img.getAttributeValue("alt").isEmpty()) + occurrences.add(this.buildOccurrence("1.2", false, element.toString(), element, "1")); + }*/ + } + + this.oder(occurrences); /*boolean isError = false; @@ -330,20 +371,68 @@ public class MarkEvaluation extends Evaluation { //List tagsH = new ArrayList(); //List elementTag = new ArrayList(); + boolean achou = false; + int limhaMinima= 0; + for (Element htmlElement : elementsObj) { if (htmlElement.getName().matches("h[1-6]")) { int tagId = Integer.parseInt(htmlElement.getName().substring(1)); + //System.out.println("Tag verificada: "+htmlElement.getName()); + + if(tagId == 1) + limhaMinima = this.getRow(htmlElement); + + + List elementsObj2 = getDocument().getAllElements(); + + int verificar = tagId-1; + + if(tagId > 1){ + for (Element htmlElement2 : elementsObj2) { + if (htmlElement2.getName().matches("h[1-6]")) { + + if(this.getRow(htmlElement2) < this.getRow(htmlElement) && this.getRow(htmlElement2) >= limhaMinima){ + int tagId2 = Integer.parseInt(htmlElement2.getName().substring(1)); + if(verificar == tagId2) + achou = true; + //System.out.println("====> verificando: "+htmlElement2.getName()+" --- : "+verificar+" = "+ tagId2); + } + } + } + + if(!achou) + occurrences.add(this.buildOccurrence("1.3", true,htmlElement.toString(), htmlElement, "2")); + //System.out.println("Pegou: "+htmlElement.getName()); + achou = false; + } + + + + /*if(tagId==1) + tagsH.clear(); + */ + + /* if(tagId > 1) for (int i = tagId-1; i >= 1; i--) { + + Element h = getDocument().getFirstElement("h"+i); + + + if(h != null) if(this.getRow(getDocument().getFirstElement("h"+i)) > this.getRow(htmlElement)){ + + //System.out.println("====> verificando: "+h.toString()); occurrences.add(this.buildOccurrence("1.3", true,htmlElement.toString(), htmlElement, "2")); break; } - } + }*/ + + //System.out.println("------------------------------------------------------------------"); /* tagsH.add(htmlElement.getName()); @@ -465,15 +554,20 @@ public class MarkEvaluation extends Evaluation { }*/ - + List verificadsos = new ArrayList(); for(Element nav : this.getDocument().getAllElements("nav")){ if(nav !=null){ int firstNavRow = this.getRow(nav); for(Element section : this.getDocument().getAllElements("section")){ - if(firstNavRow < this.getRow(section)) - occurrences.add(this.buildOccurrence("1.4", false,section.getStartTag().toString(), section, "1")); + if(firstNavRow < this.getRow(section)){ + if(!verificadsos.contains(this.getRow(section))){ + occurrences.add(this.buildOccurrence("1.4", false,section.getStartTag().toString(), section, "1")); + verificadsos.add(this.getRow(section)); + } + + } } } } -- libgit2 0.21.2