Commit 6af6311f1efd3ac71ee397d8328fd6d2336508e3

Authored by higo.gomes
1 parent ece5f89a

git-svn-id: https://svn.bento.ifrs.edu.br/default/ASES/ASES%20-%20Web/ASES%20-%2…

…0Web/Fontes/avaliador-api@10688 c2178572-b5ca-4887-91d2-9e3a90c7d55b
Showing 83 changed files with 1587 additions and 1174 deletions   Show diff stats
src/main/java/br/com/checker/emag/core/ContentEvaluation.java
... ... @@ -24,74 +24,162 @@ import br.com.checker.emag.Occurrence;
24 24 import br.com.checker.emag.OccurrenceClassification;
25 25 import br.com.checker.emag.core.SpecificRecommendation.ContentRecommendation;
26 26  
27   -public class ContentEvaluation extends Evaluation{
  27 +public class ContentEvaluation extends Evaluation {
28 28  
29   - private ContentEvaluation(Source document) { super(document); }
30   -
31   - private ContentEvaluation(Source document,String url) {
32   - super(document,url);
  29 + private ContentEvaluation(Source document) {
  30 + super(document);
33 31 }
34   -
  32 +
  33 + private ContentEvaluation(Source document, String url) {
  34 + super(document, url);
  35 + }
  36 +
35 37 public static class ContentEvaluationBuilder extends EvaluationBuilder {
36   -
  38 +
37 39 @Override
38   - protected ContentEvaluation with(Source document) { return new ContentEvaluation(document); }
39   -
  40 + protected ContentEvaluation with(Source document) {
  41 + return new ContentEvaluation(document);
  42 + }
  43 +
40 44 @Override
41   - protected ContentEvaluation with(Source document,String url) { return new ContentEvaluation(document,url); }
42   -
43   - public SpecificRecommendation recommendation17() { return new EvaluationRecommendation17();}
44   - public SpecificRecommendation recommendation18() { return new EvaluationRecommendation18();}
45   - public SpecificRecommendation recommendation19() { return new EvaluationRecommendation19();}
46   - public SpecificRecommendation recommendation20() { return new EvaluationRecommendation20();}
47   - public SpecificRecommendation recommendation21() { return new EvaluationRecommendation21();}
48   - public SpecificRecommendation recommendation22() { return new EvaluationRecommendation22();}
49   - public SpecificRecommendation recommendation23() { return new EvaluationRecommendation23();}
50   - public SpecificRecommendation recommendation24() { return new EvaluationRecommendation24();}
51   - public SpecificRecommendation recommendation25() { return new EvaluationRecommendation25();}
52   - public SpecificRecommendation recommendation26() { return new EvaluationRecommendation26();}
53   - public SpecificRecommendation recommendation27() { return new EvaluationRecommendation27();}
54   - public SpecificRecommendation recommendation28() { return new EvaluationRecommendation28();}
55   -
  45 + protected ContentEvaluation with(Source document, String url) {
  46 + return new ContentEvaluation(document, url);
  47 + }
  48 +
  49 + public SpecificRecommendation recommendation17() {
  50 + return new EvaluationRecommendation17();
  51 + }
  52 +
  53 + public SpecificRecommendation recommendation18() {
  54 + return new EvaluationRecommendation18();
  55 + }
  56 +
  57 + public SpecificRecommendation recommendation19() {
  58 + return new EvaluationRecommendation19();
  59 + }
  60 +
  61 + public SpecificRecommendation recommendation20() {
  62 + return new EvaluationRecommendation20();
  63 + }
  64 +
  65 + public SpecificRecommendation recommendation21() {
  66 + return new EvaluationRecommendation21();
  67 + }
  68 +
  69 + public SpecificRecommendation recommendation22() {
  70 + return new EvaluationRecommendation22();
  71 + }
  72 +
  73 + public SpecificRecommendation recommendation23() {
  74 + return new EvaluationRecommendation23();
  75 + }
  76 +
  77 + public SpecificRecommendation recommendation24() {
  78 + return new EvaluationRecommendation24();
  79 + }
  80 +
  81 + public SpecificRecommendation recommendation25() {
  82 + return new EvaluationRecommendation25();
  83 + }
  84 +
  85 + public SpecificRecommendation recommendation26() {
  86 + return new EvaluationRecommendation26();
  87 + }
  88 +
  89 + public SpecificRecommendation recommendation27() {
  90 + return new EvaluationRecommendation27();
  91 + }
  92 +
  93 + public SpecificRecommendation recommendation28() {
  94 + return new EvaluationRecommendation28();
  95 + }
  96 +
56 97 }
57   -
58   - protected static class EvaluationRecommendation17 extends ContentRecommendation{
59   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation17();}
  98 +
  99 + protected static class EvaluationRecommendation17 extends
  100 + ContentRecommendation {
  101 + protected List<Occurrence> check() {
  102 + return getEvaluation().checkRecommendation17();
  103 + }
60 104 }
61   - protected static class EvaluationRecommendation18 extends ContentRecommendation{
62   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation18();}
  105 +
  106 + protected static class EvaluationRecommendation18 extends
  107 + ContentRecommendation {
  108 + protected List<Occurrence> check() {
  109 + return getEvaluation().checkRecommendation18();
  110 + }
63 111 }
64   - protected static class EvaluationRecommendation19 extends ContentRecommendation{
65   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation19();}
  112 +
  113 + protected static class EvaluationRecommendation19 extends
  114 + ContentRecommendation {
  115 + protected List<Occurrence> check() {
  116 + return getEvaluation().checkRecommendation19();
  117 + }
66 118 }
67   - protected static class EvaluationRecommendation20 extends ContentRecommendation{
68   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation20();}
  119 +
  120 + protected static class EvaluationRecommendation20 extends
  121 + ContentRecommendation {
  122 + protected List<Occurrence> check() {
  123 + return getEvaluation().checkRecommendation20();
  124 + }
69 125 }
70   - protected static class EvaluationRecommendation21 extends ContentRecommendation{
71   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation21();}
  126 +
  127 + protected static class EvaluationRecommendation21 extends
  128 + ContentRecommendation {
  129 + protected List<Occurrence> check() {
  130 + return getEvaluation().checkRecommendation21();
  131 + }
72 132 }
73   - protected static class EvaluationRecommendation22 extends ContentRecommendation{
74   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation22();}
  133 +
  134 + protected static class EvaluationRecommendation22 extends
  135 + ContentRecommendation {
  136 + protected List<Occurrence> check() {
  137 + return getEvaluation().checkRecommendation22();
  138 + }
75 139 }
76   - protected static class EvaluationRecommendation23 extends ContentRecommendation{
77   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation23();}
  140 +
  141 + protected static class EvaluationRecommendation23 extends
  142 + ContentRecommendation {
  143 + protected List<Occurrence> check() {
  144 + return getEvaluation().checkRecommendation23();
  145 + }
78 146 }
79   - protected static class EvaluationRecommendation24 extends ContentRecommendation{
80   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation24();}
  147 +
  148 + protected static class EvaluationRecommendation24 extends
  149 + ContentRecommendation {
  150 + protected List<Occurrence> check() {
  151 + return getEvaluation().checkRecommendation24();
  152 + }
81 153 }
82   - protected static class EvaluationRecommendation25 extends ContentRecommendation{
83   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation25();}
  154 +
  155 + protected static class EvaluationRecommendation25 extends
  156 + ContentRecommendation {
  157 + protected List<Occurrence> check() {
  158 + return getEvaluation().checkRecommendation25();
  159 + }
84 160 }
85   - protected static class EvaluationRecommendation26 extends ContentRecommendation{
86   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation26();}
  161 +
  162 + protected static class EvaluationRecommendation26 extends
  163 + ContentRecommendation {
  164 + protected List<Occurrence> check() {
  165 + return getEvaluation().checkRecommendation26();
  166 + }
87 167 }
88   - protected static class EvaluationRecommendation27 extends ContentRecommendation{
89   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation27();}
  168 +
  169 + protected static class EvaluationRecommendation27 extends
  170 + ContentRecommendation {
  171 + protected List<Occurrence> check() {
  172 + return getEvaluation().checkRecommendation27();
  173 + }
90 174 }
91   - protected static class EvaluationRecommendation28 extends ContentRecommendation{
92   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation28();}
  175 +
  176 + protected static class EvaluationRecommendation28 extends
  177 + ContentRecommendation {
  178 + protected List<Occurrence> check() {
  179 + return getEvaluation().checkRecommendation28();
  180 + }
93 181 }
94   -
  182 +
95 183 public List<Occurrence> check() {
96 184 getOccurrences().clear();
97 185 getOccurrences().addAll(checkRecommendation17());
... ... @@ -106,198 +194,244 @@ public class ContentEvaluation extends Evaluation{
106 194 getOccurrences().addAll(checkRecommendation26());
107 195 getOccurrences().addAll(checkRecommendation27());
108 196 getOccurrences().addAll(checkRecommendation28());
109   -
  197 +
110 198 return getOccurrences();
111 199 }
112   -
113   -
  200 +
114 201 private List<Occurrence> checkRecommendation17() {
115 202 List<Occurrence> occurrences = new ArrayList<Occurrence>();
116   -
  203 +
117 204 Element html = getDocument().getFirstElement("html");
118   -
  205 +
119 206 if (html != null) {
120 207 Attribute lang = html.getAttributes().get("lang");
121 208 Attribute xmlLang = html.getAttributes().get("xml:lang");
122 209 Attribute xmlns = html.getAttributes().get("xmlns");
123   -
  210 +
124 211 String tagHtml = getDocument().getFirstStartTag("html").toString();
125   -
126   -
127   - /*if ( lang == null && xmlLang == null){
128   - occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
129   - }
130   -
131   - if(xmlLang != null && !(lang == null || xmlLang == null)){
132   - occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
133   - }else if (lang != null && lang.getValue().isEmpty()) {
134   - occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
135   - } else if (xmlLang != null && xmlLang.getValue().isEmpty()) {
136   - occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
137   - }else if (xmlns != null && xmlns.getValue().isEmpty()) {
138   - occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
139   - }*/
140   -
141   -
142   - if (lang == null){
143   - occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
  212 + String doctype = getDocument().getFirstStartTag().toString()
  213 + .replace(" ", "");
  214 +
  215 + /*
  216 + * if ( lang == null && xmlLang == null){
  217 + * occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html,
  218 + * "1")); }
  219 + *
  220 + * if(xmlLang != null && !(lang == null || xmlLang == null)){
  221 + * occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html,
  222 + * "1")); }else if (lang != null && lang.getValue().isEmpty()) {
  223 + * occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html,
  224 + * "2")); } else if (xmlLang != null &&
  225 + * xmlLang.getValue().isEmpty()) {
  226 + * occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html,
  227 + * "2")); }else if (xmlns != null && xmlns.getValue().isEmpty()) {
  228 + * occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html,
  229 + * "2")); }
  230 + */
  231 +
  232 + if (lang == null) {
  233 + occurrences.add(this.buildOccurrence("3.1", true, tagHtml,
  234 + html, "1"));
144 235 }
145   -
146   - if (xmlLang == null){
147   - occurrences.add(this.buildOccurrence("3.1", true, tagHtml, html, "1"));
  236 +
  237 + // Caso seja diferente de html5
  238 + if (!doctype.equals("<!DOCTYPEhtml>")) {
  239 +
  240 + if (xmlLang == null) {
  241 + occurrences.add(this.buildOccurrence("3.1", true, tagHtml,
  242 + html, "1"));
  243 + }
148 244 }
149   -
  245 +
150 246 if (lang == null && (xmlLang != null || xmlns != null)) {
151   - occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
  247 + occurrences.add(this.buildOccurrence("3.1", false, tagHtml,
  248 + html, "2"));
152 249 } else if (lang != null && lang.getValue().isEmpty()) {
153   - occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
154   - } else if (xmlLang != null && xmlLang.getValue().isEmpty()) {
155   - occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
156   - }else if (xmlns != null && xmlns.getValue().isEmpty()) {
157   - occurrences.add(this.buildOccurrence("3.1", false, tagHtml, html, "2"));
158   - }
159   -
160   - /*if (lang == null && xmlns != null) {
161   - occurrences.add(this.buildOccurrence("3.1", false, html.toString(), html, "2"));
162   - } else if (xmlns != null && xmlLang.getValue().isEmpty()) {
163   - occurrences.add(this.buildOccurrence("3.1", false, html.toString(), html, "2"));
164   - } else if (xmlns != null && xmlns.getValue().isEmpty()) {
165   - occurrences.add(this.buildOccurrence("3.1", false, html.toString(), html, "2"));
  250 + occurrences.add(this.buildOccurrence("3.1", false, tagHtml,
  251 + html, "2"));
  252 + } else if (xmlLang != null && xmlLang.getValue().isEmpty()) {
  253 + occurrences.add(this.buildOccurrence("3.1", false, tagHtml,
  254 + html, "2"));
  255 + } else if (xmlns != null && xmlns.getValue().isEmpty()) {
  256 + occurrences.add(this.buildOccurrence("3.1", false, tagHtml,
  257 + html, "2"));
166 258 }
167   -*/
  259 +
  260 + /*
  261 + * if (lang == null && xmlns != null) {
  262 + * occurrences.add(this.buildOccurrence("3.1", false,
  263 + * html.toString(), html, "2")); } else if (xmlns != null &&
  264 + * xmlLang.getValue().isEmpty()) {
  265 + * occurrences.add(this.buildOccurrence("3.1", false,
  266 + * html.toString(), html, "2")); } else if (xmlns != null &&
  267 + * xmlns.getValue().isEmpty()) {
  268 + * occurrences.add(this.buildOccurrence("3.1", false,
  269 + * html.toString(), html, "2")); }
  270 + */
168 271 }
169   -
  272 +
170 273 return occurrences;
171 274 }
172   -
173   -
  275 +
174 276 private List<Occurrence> checkRecommendation18() {
175 277 List<Occurrence> occurrences = new ArrayList<Occurrence>();
176   -
  278 +
177 279 for (Element element : getDocument().getAllElements()) {
178   - if(!element.getName().equals("html")){
179   -
180   - if(element.getName().equals("a") && element.getAttributeValue("href") != null){
181   - if(element.getAttributeValue("href").contains("/?lang=")){
182   - occurrences.add(this.buildOccurrence("3.2", false, element.toString(), element, "1"));
183   - }
184   - }else if(element.getAttributeValue("lang") != null)
185   - occurrences.add(this.buildOccurrence("3.2", false, element.toString(), element, "1"));
  280 + if (!element.getName().equals("html")) {
  281 +
  282 + if (element.getName().equals("a")
  283 + && element.getAttributeValue("href") != null) {
  284 + if (element.getAttributeValue("href").contains("/?lang=")) {
  285 + occurrences.add(this.buildOccurrence("3.2", false,
  286 + element.toString(), element, "1"));
  287 + }
  288 + } else if (element.getAttributeValue("lang") != null)
  289 + occurrences.add(this.buildOccurrence("3.2", false,
  290 + element.toString(), element, "1"));
186 291 }
187 292 }
188   -
  293 +
189 294 return occurrences;
190 295 }
191   -
  296 +
192 297 private List<Occurrence> checkRecommendation19() {
193 298 List<Occurrence> occurrences = new ArrayList<Occurrence>();
194   -
195   - //Element head = getDocument().getFirstElement("head");
196   -
197   - //if(head == null) {
198   - //occurrences.add(new Occurrence("3.3", true, getDocument().getFirstElement().toString(),OccurrenceClassification.CONTENT_INFORMATION,"1"));
199   - //}else {
200   - //if(head != null) {
201   - Element title = getDocument().getFirstElement("title");
202   - if (title == null) {
203   - occurrences.add(this.buildOccurrence("3.3", true, " Observa&ccedil;&atilde;o – Sem Fonte (N&atilde;o existe t&iacute;tulo na p&aacute;gina)", getDocument().getFirstElement(), "1"));
204   - //occurrences.add(new Occurrence("3.3", true, "Sem fonte (n�o existe t�tulo na p�gina)",OccurrenceClassification.CONTENT_INFORMATION,"1"));
205   - } else if (title.isEmpty()) {
206   - occurrences.add(buildOccurrence("3.3", true, title.toString(), title, "1"));
207   - }
208   - //}
209   -
  299 +
  300 + // Element head = getDocument().getFirstElement("head");
  301 +
  302 + // if(head == null) {
  303 + // occurrences.add(new Occurrence("3.3", true,
  304 + // getDocument().getFirstElement().toString(),OccurrenceClassification.CONTENT_INFORMATION,"1"));
  305 + // }else {
  306 + // if(head != null) {
  307 + Element title = getDocument().getFirstElement("title");
  308 + if (title == null) {
  309 + occurrences
  310 + .add(this
  311 + .buildOccurrence(
  312 + "3.3",
  313 + true,
  314 + " Observa&ccedil;&atilde;o – Sem Fonte (N&atilde;o existe t&iacute;tulo na p&aacute;gina)",
  315 + getDocument().getFirstElement(), "1"));
  316 + // occurrences.add(new Occurrence("3.3", true,
  317 + // "Sem fonte (n�o existe t�tulo na p�gina)",OccurrenceClassification.CONTENT_INFORMATION,"1"));
  318 + } else if (title.isEmpty()) {
  319 + occurrences.add(buildOccurrence("3.3", true, title.toString(),
  320 + title, "1"));
  321 + }
  322 + // }
  323 +
210 324 return occurrences;
211 325 }
212   -
  326 +
213 327 private List<Occurrence> checkRecommendation20() {
214 328 List<Occurrence> occurrences = new ArrayList<Occurrence>();
215   - occurrences.add(new Occurrence("3.4", false, getDocument().getFirstElement().toString(),OccurrenceClassification.CONTENT_INFORMATION));
  329 + occurrences.add(new Occurrence("3.4", false, getDocument()
  330 + .getFirstElement().toString(),
  331 + OccurrenceClassification.CONTENT_INFORMATION));
216 332 return occurrences;
217 333 }
218   -
  334 +
219 335 private List<Occurrence> checkRecommendation21() {
220 336 List<Occurrence> occurrences = new ArrayList<Occurrence>();
221   -
222   - for(Element link : getDocument().getAllElements("a")){
  337 +
  338 + for (Element link : getDocument().getAllElements("a")) {
223 339 String href = link.getAttributeValue("href");
224 340 String title = link.getAttributeValue("title");
225 341 String content = link.getContent().toString();
226   -
227   - if(hasEqualsContentHref(link) && isRegistroBr(content))
228   - occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link, "1"));
229   -
230   - if(!hasContent(link))
231   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"2"));
232   - else if(hasImgWithoutAlt(link))
233   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"2"));
234   -
235   - //if(hasTitle(link) && isNotAlt(link))
236   - if(hasTitle(link) && !hasContent(link))
237   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"3"));
238   -
239   - /*if(!hasTitle(link) && !hasContent(link) && hasImgWithoutAlt(link))
240   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"4"));*/
241   -
242   - if(hasImgWithoutAlt(link))
243   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"4"));
244   -
245   - if(hasLeiaMaisDescription(link))
246   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"5"));
247   -
248   - if(hasDiferenteContentSameLink(link))
249   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"6"));
250   -
251   - if(isTitleEqualsContent(link))
252   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"8"));
253   -
254   - if(hasSameContentDiferentLink(link))
255   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"7"));
256   -
257   - if(link != null && hasLongContent(link))
258   - occurrences.add(this.buildOccurrence("3.5", false, link.toString(), link,"9"));
259   -
260   - if(link != null && isLinkUnavailable(link,getUrl()))
261   - occurrences.add(this.buildOccurrence("3.5", true, link.toString(), link,"10"));
262   -
  342 +
  343 + if (hasEqualsContentHref(link) && isRegistroBr(content))
  344 + occurrences.add(this.buildOccurrence("3.5", false,
  345 + link.toString(), link, "1"));
  346 +
  347 + if (!hasContent(link))
  348 + occurrences.add(this.buildOccurrence("3.5", true,
  349 + link.toString(), link, "2"));
  350 + else if (hasImgWithoutAlt(link))
  351 + occurrences.add(this.buildOccurrence("3.5", true,
  352 + link.toString(), link, "2"));
  353 +
  354 + // if(hasTitle(link) && isNotAlt(link))
  355 + if (hasTitle(link) && !hasContent(link))
  356 + occurrences.add(this.buildOccurrence("3.5", true,
  357 + link.toString(), link, "3"));
  358 +
  359 + /*
  360 + * if(!hasTitle(link) && !hasContent(link) &&
  361 + * hasImgWithoutAlt(link))
  362 + * occurrences.add(this.buildOccurrence("3.5", true,
  363 + * link.toString(), link,"4"));
  364 + */
  365 +
  366 + if (hasImgWithoutAlt(link))
  367 + occurrences.add(this.buildOccurrence("3.5", true,
  368 + link.toString(), link, "4"));
  369 +
  370 + if (hasLeiaMaisDescription(link))
  371 + occurrences.add(this.buildOccurrence("3.5", true,
  372 + link.toString(), link, "5"));
  373 +
  374 + if (hasDiferenteContentSameLink(link))
  375 + occurrences.add(this.buildOccurrence("3.5", true,
  376 + link.toString(), link, "6"));
  377 +
  378 + if (isTitleEqualsContent(link))
  379 + occurrences.add(this.buildOccurrence("3.5", true,
  380 + link.toString(), link, "8"));
  381 +
  382 + if (hasSameContentDiferentLink(link))
  383 + occurrences.add(this.buildOccurrence("3.5", true,
  384 + link.toString(), link, "7"));
  385 +
  386 + if (link != null && hasLongContent(link))
  387 + occurrences.add(this.buildOccurrence("3.5", false,
  388 + link.toString(), link, "9"));
  389 +
  390 + if (link != null && isLinkUnavailable(link, getUrl()))
  391 + occurrences.add(this.buildOccurrence("3.5", true,
  392 + link.toString(), link, "10"));
  393 +
263 394 }
264   -
265 395 return occurrences;
266 396 }
267   -
268   -
269   - private boolean isLinkUnavailable(Element link,String url){
270   -
  397 +
  398 + private boolean isLinkUnavailable(Element link, String url) {
  399 +
271 400 String href = link.getAttributeValue("href");
272   -
273   - if(href!=null && href.startsWith("www"))
274   - href = "http://"+href;
275   -
276   - if(href!=null && !href.startsWith("http") && url !=null)
277   - href = url+"/"+link.getAttributeValue("href");
278   -
279   - if(link.getAttributeValue("href") != null && !link.getAttributeValue("href").equals("#") && !link.getAttributeValue("href").equals("/") && !link.getAttributeValue("href").contains("javascript")){
280   -
281   - 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};
  401 +
  402 + if (href != null && href.startsWith("www"))
  403 + href = "http://" + href;
  404 +
  405 + if (href != null && !href.startsWith("http") && url != null)
  406 + href = url + "/" + link.getAttributeValue("href");
  407 +
  408 + if (link.getAttributeValue("href") != null
  409 + && !link.getAttributeValue("href").substring(0, 1).equals("#")
  410 + && !link.getAttributeValue("href").substring(0, 1).equals("/")
  411 + && !link.getAttributeValue("href").contains("javascript")) {
  412 +
  413 + int[] codErro = { 400, 401, 402, 403, 404, 405, 406, 407, 408, 409,
  414 + 410, 411, 412, 414, 415, 416, 417, 418, 422, 423, 424, 425,
  415 + 426, 450, 499, 500, 501, 502, 503, 504, 505 };
282 416 int codResponse = 0;
283   -
  417 +
284 418 String regex = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]+$";
285   -
286   - //if(!IsMatch(href,regex))
287   - //return true;
288   -
  419 +
  420 + // if(!IsMatch(href,regex))
  421 + // return true;
  422 +
289 423 try {
290 424 String[] test = href.split("\\../");
291   - String newurl="";
292   - for(String tes : test)
293   - newurl=newurl+tes.trim();
294   -
  425 + String newurl = "";
  426 + for (String tes : test)
  427 + newurl = newurl + tes.trim();
  428 +
295 429 newurl = newurl.replace(" ", "%20");
296   -
297   - URL u = new URL(newurl);
298   - HttpURLConnection huc = (HttpURLConnection) u.openConnection();
299   - huc.setRequestMethod("GET");
300   - //huc.setRequestMethod("HEAD");
  430 +
  431 + URL u = new URL(newurl);
  432 + HttpURLConnection huc = (HttpURLConnection) u.openConnection();
  433 + huc.setRequestMethod("GET");
  434 + // huc.setRequestMethod("HEAD");
301 435 huc.connect();
302 436 codResponse = huc.getResponseCode();
303 437 huc.disconnect();
... ... @@ -305,532 +439,584 @@ public class ContentEvaluation extends Evaluation{
305 439 return true;
306 440 } catch (IOException e) {
307 441 return true;
308   - }
309   -
310   - /*if(huc.getResponseCode() != HttpURLConnection.HTTP_OK)
311   - System.out.println(link.toString());*/
312   - for(int cod : codErro)
313   - if(codResponse == cod) return true;
314   -
315   - }
316   -
317   - return false;
318   - }
319   -
320   - private static boolean IsMatch(String s, String pattern) {
321   - try {
322   - Pattern patt = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
323   - Matcher matcher = patt.matcher(s);
324   - return matcher.matches();
325   - } catch (RuntimeException e) {
326   - return false;
327   - }
328   - }
329   -
  442 + }
  443 +
  444 + /*
  445 + * if(huc.getResponseCode() != HttpURLConnection.HTTP_OK)
  446 + * System.out.println(link.toString());
  447 + */
  448 + for (int cod : codErro)
  449 + if (codResponse == cod) {
  450 + return true;
  451 + }
  452 +
  453 + }
  454 +
  455 + return false;
  456 + }
  457 +
  458 + private static boolean IsMatch(String s, String pattern) {
  459 + try {
  460 + Pattern patt = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
  461 + Matcher matcher = patt.matcher(s);
  462 + return matcher.matches();
  463 + } catch (RuntimeException e) {
  464 + return false;
  465 + }
  466 + }
  467 +
330 468 private boolean isNotAlt(Element link) {
331 469 String alt = link.getAttributeValue("alt");
332 470 return alt == null || StringUtils.isBlank(alt);
333 471 }
334   -
  472 +
335 473 private boolean hasLongContent(Element link) {
336   - return link.getContent().getTextExtractor().toString().length() > 500 ? true : false;
  474 + return link.getContent().getTextExtractor().toString().length() > 500 ? true
  475 + : false;
337 476 }
338   -
  477 +
339 478 private boolean hasContent(Element link) {
340   - return StringUtils.isNotBlank(link.getContent().getTextExtractor().toString());
  479 + return StringUtils.isNotBlank(link.getContent().getTextExtractor()
  480 + .toString());
341 481 }
342   - private boolean hasTitle(Element link){
  482 +
  483 + private boolean hasTitle(Element link) {
343 484 String title = link.getAttributeValue("title");
344 485 return title != null && StringUtils.isNotBlank(title);
345 486 }
  487 +
346 488 private boolean hasImgWithoutAlt(Element link) {
347 489 Element img = link.getFirstElement("img");
348   - if(img == null) return false;
  490 + if (img == null)
  491 + return false;
349 492 String alt = img.getAttributeValue("alt");
350 493 return alt == null || StringUtils.isBlank(alt);
351 494 }
352   -
353   - private boolean hasLeiaMaisDescription(Element link){
  495 +
  496 + private boolean hasLeiaMaisDescription(Element link) {
354 497 String title = link.getAttributeValue("title");
355 498 String content = link.getContent().getTextExtractor().toString();
356   - String altImg = link.getFirstElement("img")!=null ? link.getFirstElement("img").getAttributeValue("alt") : "" ;
357   -
358   - for(String leiaMais:this.leiaMais){
359   -
360   - if(title!=null)
361   - if(title.toLowerCase().equals(leiaMais)) return true;
362   -
363   - if(content!=null)
364   - if(content.toLowerCase().equals(leiaMais)) return true;
365   -
366   - if(altImg!=null)
367   - if(altImg.toLowerCase().equals(leiaMais)) return true;
368   - }
369   -
370   -
371   - /* Pattern pattern;
372   - for(String leiaMais:this.leiaMais){
373   - pattern = Pattern.compile("("+leiaMais+")");
374   - if(title!=null)
375   - if(pattern.matcher(title.toLowerCase()).find()) return true;
376   -
377   - if(content!=null)
378   - if(pattern.matcher(content.toLowerCase()).find()) return true;
379   -
380   - if(altImg!=null)
381   - if(pattern.matcher(altImg.toLowerCase()).find()) return true;
382   - }*/
383   -
  499 + String altImg = link.getFirstElement("img") != null ? link
  500 + .getFirstElement("img").getAttributeValue("alt") : "";
  501 +
  502 + for (String leiaMais : this.leiaMais) {
  503 +
  504 + if (title != null)
  505 + if (title.toLowerCase().equals(leiaMais))
  506 + return true;
  507 +
  508 + if (content != null)
  509 + if (content.toLowerCase().equals(leiaMais))
  510 + return true;
  511 +
  512 + if (altImg != null)
  513 + if (altImg.toLowerCase().equals(leiaMais))
  514 + return true;
  515 + }
  516 +
  517 + /*
  518 + * Pattern pattern; for(String leiaMais:this.leiaMais){ pattern =
  519 + * Pattern.compile("("+leiaMais+")"); if(title!=null)
  520 + * if(pattern.matcher(title.toLowerCase()).find()) return true;
  521 + *
  522 + * if(content!=null) if(pattern.matcher(content.toLowerCase()).find())
  523 + * return true;
  524 + *
  525 + * if(altImg!=null) if(pattern.matcher(altImg.toLowerCase()).find())
  526 + * return true; }
  527 + */
  528 +
384 529 return false;
385 530 }
386   - private boolean isRegistroBr(String href){
387   - if(StringUtils.isBlank(href)) return false;
  531 +
  532 + private boolean isRegistroBr(String href) {
  533 + if (StringUtils.isBlank(href))
  534 + return false;
388 535 Pattern pattern;
389   - for(String registro:hrefRegistroBr){
390   - pattern = Pattern.compile("(.*)("+registro+").*$");
391   - if(pattern.matcher(href.toUpperCase()).find()) return true;
  536 + for (String registro : hrefRegistroBr) {
  537 + pattern = Pattern.compile("(.*)(" + registro + ").*$");
  538 + if (pattern.matcher(href.toUpperCase()).find())
  539 + return true;
392 540 }
393   -
  541 +
394 542 return false;
395 543 }
396   -
397   -
  544 +
398 545 private boolean hasEqualsContentHref(Element link) {
399 546 String content = link.getContent().getTextExtractor().toString();
400   - if(content != null && !content.isEmpty())
401   - content = content.replace("http://","").replaceFirst("(/$)", "");
402   -
  547 + if (content != null && !content.isEmpty())
  548 + content = content.replace("http://", "").replaceFirst("(/$)", "");
  549 +
403 550 String href = link.getAttributeValue("href");
404   - if(href != null && !href.isEmpty())
405   - href = href.replace("http://","").replaceFirst("(/$)", "");
  551 + if (href != null && !href.isEmpty())
  552 + href = href.replace("http://", "").replaceFirst("(/$)", "");
406 553 return content.equals(href);
407 554 }
408   -
  555 +
409 556 private boolean hasDiferenteContentSameLink(Element link) {
410 557 String content = link.getContent().getTextExtractor().toString();
411 558 String href = link.getAttributeValue("href");
412   - if(StringUtils.isBlank(href)) return false;
  559 + if (StringUtils.isBlank(href))
  560 + return false;
413 561 String otherContent;
414 562 String otherHref;
415   - for(Element otherLink:getDocument().getAllElements("a")){
  563 + for (Element otherLink : getDocument().getAllElements("a")) {
416 564 otherContent = otherLink.getContent().getTextExtractor().toString();
417 565 otherHref = otherLink.getAttributeValue("href");
418   - if(StringUtils.isBlank(otherHref))continue;
419   - if(!content.toLowerCase().equals(otherContent.toLowerCase()) && href.equals(otherHref)) return true;
  566 + if (StringUtils.isBlank(otherHref))
  567 + continue;
  568 + if (!content.toLowerCase().equals(otherContent.toLowerCase())
  569 + && href.equals(otherHref))
  570 + return true;
420 571 }
421 572 return false;
422 573 }
423   -
  574 +
424 575 private boolean hasSameContentDiferentLink(Element link) {
425   - //String content = link.getContent().getTextExtractor().toString();
  576 + // String content = link.getContent().getTextExtractor().toString();
426 577 String content = link.getContent().toString();
427   -
428   - if(content != null)
429   - content = content.replace("http://","").replaceFirst("(/$)", "");
430   -
  578 +
  579 + if (content != null)
  580 + content = content.replace("http://", "").replaceFirst("(/$)", "");
  581 +
431 582 String href = link.getAttributeValue("href");
432   -
433   - if(href != null)
434   - href = href.replace("http://","").replaceFirst("(/$)", "");
435   -
436   - if(StringUtils.isBlank(href)) return false;
  583 +
  584 + if (href != null)
  585 + href = href.replace("http://", "").replaceFirst("(/$)", "");
  586 +
  587 + if (StringUtils.isBlank(href))
  588 + return false;
437 589 String otherContent;
438 590 String otherHref;
439   -
  591 +
440 592 List<String> linksVerificados = new ArrayList<String>();
441   -
442   - for(Element otherLink : getDocument().getAllElements("a")){
443   -
444   - if(otherLink.getBegin() == link.getBegin()) continue;
  593 +
  594 + for (Element otherLink : getDocument().getAllElements("a")) {
  595 +
  596 + if (otherLink.getBegin() == link.getBegin())
  597 + continue;
445 598 otherContent = otherLink.getContent().toString();
446   - //otherContent = otherLink.getContent().getTextExtractor().toString();
447   -
448   - if(otherContent != null)
449   - otherContent = otherContent.replace("http://","").replaceFirst("(/$)", "");
450   -
  599 + // otherContent =
  600 + // otherLink.getContent().getTextExtractor().toString();
  601 +
  602 + if (otherContent != null)
  603 + otherContent = otherContent.replace("http://", "")
  604 + .replaceFirst("(/$)", "");
  605 +
451 606 otherHref = otherLink.getAttributeValue("href");
452   -
453   - if(otherHref != null)
454   - otherHref = otherHref.replace("http://","").replaceFirst("(/$)", "");
455   -
456   - if(StringUtils.isBlank(otherHref))continue;
457   - if(!linksVerificados.contains(content)){
458   - if(content.toLowerCase().equals(otherContent.toLowerCase()) && !href.equals(otherHref)){
459   - linksVerificados.add(content);
460   - return true;
  607 +
  608 + if (otherHref != null)
  609 + otherHref = otherHref.replace("http://", "").replaceFirst(
  610 + "(/$)", "");
  611 +
  612 + if (StringUtils.isBlank(otherHref))
  613 + continue;
  614 + if (!linksVerificados.contains(content)) {
  615 + if (content.toLowerCase().equals(otherContent.toLowerCase())
  616 + && !href.equals(otherHref)) {
  617 + linksVerificados.add(content);
  618 + return true;
  619 + }
461 620 }
462   - }
463 621 }
464 622 return false;
465 623 }
466   -
  624 +
467 625 private boolean isTitleEqualsContent(Element element) {
468   -
469   - String content = element.getContent().getTextExtractor().toString() ;
  626 +
  627 + String content = element.getContent().getTextExtractor().toString();
470 628 String title = element.getAttributeValue("title");
471   -
472   - if(StringUtils.isBlank(title)) return false;
473   -
  629 +
  630 + if (StringUtils.isBlank(title))
  631 + return false;
  632 +
474 633 return title.toLowerCase().equals(content.toLowerCase());
475 634 }
476   -
  635 +
477 636 private List<Occurrence> checkRecommendation22() {
478 637 List<Occurrence> occurrences = new ArrayList<Occurrence>();
479   -
  638 +
480 639 String[] parts = null;
481   -
482   - String[] descricoes = {"figura", "imagem", "alt", "descrição", "foto"};
483   -
  640 +
  641 + String[] descricoes = { "figura", "imagem", "alt", "descrição",
  642 + "foto" };
  643 +
484 644 for (Element img : getDocument().getAllElements("img")) {
485 645 Attribute alt = img.getAttributes().get("alt");
486 646 if (alt == null) {
487   - occurrences.add(buildOccurrence("3.6", true, img.toString(), img, "1"));
488   - }else if(alt.getValueSegment().toString().trim().isEmpty()){
489   - occurrences.add(buildOccurrence("3.6", true, img.toString(), img, "2"));
490   - }
491   -
  647 + occurrences.add(buildOccurrence("3.6", true, img.toString(),
  648 + img, "1"));
  649 + } else if (alt.getValueSegment().toString().trim().isEmpty()) {
  650 + occurrences.add(buildOccurrence("3.6", true, img.toString(),
  651 + img, "2"));
  652 + }
  653 +
492 654 Attribute src = img.getAttributes().get("src");
493 655 String contAlt = null;
494   -
495   - if(src != null && alt != null){
  656 +
  657 + if (src != null && alt != null) {
496 658 String value = src.getValue();
497 659 parts = value.toString().split("/");
498   - contAlt = alt.getValue();
499   -
500   - if(parts.length > 0)
501   - if(parts[parts.length-1].toString().equals(contAlt))
502   - occurrences.add(buildOccurrence("3.6", true, img.toString(), img, "3"));
  660 + contAlt = alt.getValue();
  661 +
  662 + if (parts.length > 0)
  663 + if (parts[parts.length - 1].toString().equals(contAlt))
  664 + occurrences.add(buildOccurrence("3.6", true,
  665 + img.toString(), img, "3"));
503 666 }
504   -
505   - for(String descricao : descricoes){
506   - if(descricao.equalsIgnoreCase(contAlt))
507   - occurrences.add(buildOccurrence("3.6", true, img.toString(), img, "4"));
508   -
  667 +
  668 + for (String descricao : descricoes) {
  669 + if (descricao.equalsIgnoreCase(contAlt))
  670 + occurrences.add(buildOccurrence("3.6", true,
  671 + img.toString(), img, "4"));
  672 +
509 673 }
510   -
511   -
  674 +
512 675 }
513   -
514   -
  676 +
515 677 Map<String, Element> aMap = new HashMap<String, Element>();
516   -
517   -
518   -
  678 +
519 679 for (Element img : getDocument().getAllElements("img")) {
520   -
  680 +
521 681 Attribute src = img.getAttributes().get("src");
522 682 Attribute alt = img.getAttributes().get("alt");
523   -
  683 +
524 684 boolean isVerificado = false;
525   -
  685 +
526 686 if (alt != null && !alt.getValue().isEmpty()) {
527   -
528   - if(src != null)
529   - if(!aMap.containsKey(src.getValue())){
530   -
531   - int rowImgVerificado = this.getRow(img);
532   -
533   - for (Element imgA : getDocument().getAllElements("img")) {
534   - int rowImgA = this.getRow(imgA);
535   -
536   - if(rowImgA > rowImgVerificado){
537   -
538   - Attribute srcAtt = imgA.getAttributes().get("src");
539   - Attribute altAtt = imgA.getAttributes().get("alt");
540   -
541   - if (altAtt != null && !altAtt.getValue().isEmpty()) {
542   - if(alt.getValue().equals(altAtt.getValue())){
543   - if(srcAtt != null){
544   - if(!src.getValue().equals(srcAtt.getValue())){
545   - occurrences.add(buildOccurrence("3.6", false, imgA.toString(), imgA, "5"));
546   - aMap.put(srcAtt.getValue(), img);
547   - isVerificado = true;
  687 +
  688 + if (src != null)
  689 + if (!aMap.containsKey(src.getValue())) {
  690 +
  691 + int rowImgVerificado = this.getRow(img);
  692 +
  693 + for (Element imgA : getDocument().getAllElements("img")) {
  694 + int rowImgA = this.getRow(imgA);
  695 +
  696 + if (rowImgA > rowImgVerificado) {
  697 +
  698 + Attribute srcAtt = imgA.getAttributes().get(
  699 + "src");
  700 + Attribute altAtt = imgA.getAttributes().get(
  701 + "alt");
  702 +
  703 + if (altAtt != null
  704 + && !altAtt.getValue().isEmpty()) {
  705 + if (alt.getValue()
  706 + .equals(altAtt.getValue())) {
  707 + if (srcAtt != null) {
  708 + if (!src.getValue().equals(
  709 + srcAtt.getValue())) {
  710 + occurrences
  711 + .add(buildOccurrence(
  712 + "3.6",
  713 + false,
  714 + imgA.toString(),
  715 + imgA, "5"));
  716 + aMap.put(srcAtt.getValue(), img);
  717 + isVerificado = true;
  718 + }
548 719 }
549 720 }
550 721 }
551 722 }
552 723 }
553 724 }
554   - }
555   -
556   - if(src != null)
557   - aMap.put(src.getValue(), img);
558   -
559   - if(isVerificado)
560   - occurrences.add(buildOccurrence("3.6", false, img.toString(), img, "5"));
  725 +
  726 + if (src != null)
  727 + aMap.put(src.getValue(), img);
  728 +
  729 + if (isVerificado)
  730 + occurrences.add(buildOccurrence("3.6", false,
  731 + img.toString(), img, "5"));
561 732 }
562 733 }
563   -
564   -
565   - /*Map<String, String> aMap = new HashMap<String, String>();
566   -
567   - for (Element img : getDocument().getAllElements("img")) {
568   -
569   - Attribute src = img.getAttributes().get("src");
570   - Attribute altAtt = img.getAttributes().get("alt");
571   - if (altAtt != null && !altAtt.getValue().isEmpty()) {
572   - if(aMap.containsKey(altAtt.getValue())){
573   - Attribute srcAtt = img.getAttributes().get("src");
574   - if(srcAtt != null){
575   - if(!aMap.get(altAtt.getValue()).contains("src=\""+srcAtt.getValue()+"\""))
576   - occurrences.add(buildOccurrence("3.6", false, img.toString(), img, "5"));
577   - }
578   - }else{
579   - aMap.put(altAtt.getValue(), img.toString());
580   - }
581   - }
582   - }*/
583   -
  734 +
  735 + /*
  736 + * Map<String, String> aMap = new HashMap<String, String>();
  737 + *
  738 + * for (Element img : getDocument().getAllElements("img")) {
  739 + *
  740 + * Attribute src = img.getAttributes().get("src"); Attribute altAtt =
  741 + * img.getAttributes().get("alt"); if (altAtt != null &&
  742 + * !altAtt.getValue().isEmpty()) {
  743 + * if(aMap.containsKey(altAtt.getValue())){ Attribute srcAtt =
  744 + * img.getAttributes().get("src"); if(srcAtt != null){
  745 + * if(!aMap.get(altAtt
  746 + * .getValue()).contains("src=\""+srcAtt.getValue()+"\""))
  747 + * occurrences.add(buildOccurrence("3.6", false, img.toString(), img,
  748 + * "5")); } }else{ aMap.put(altAtt.getValue(), img.toString()); } } }
  749 + */
  750 +
584 751 for (Element img : getDocument().getAllElements("img")) {
585 752 Attribute alt = img.getAttributes().get("alt");
586 753 Attribute title = img.getAttributes().get("title");
587 754 if (alt != null && title != null) {
588   - if(title.getValue().equals(alt.getValue()))
589   - occurrences.add(buildOccurrence("3.6", true, img.toString(), img, "6"));
  755 + if (title.getValue().equals(alt.getValue()))
  756 + occurrences.add(buildOccurrence("3.6", true,
  757 + img.toString(), img, "6"));
590 758 }
591 759 }
592   -
  760 +
593 761 this.oder(occurrences);
594   -
  762 +
595 763 return occurrences;
596 764 }
597   -
  765 +
598 766 private List<Occurrence> checkRecommendation23() {
599 767 List<Occurrence> occurrences = new ArrayList<Occurrence>();
600   -
  768 +
601 769 boolean isMap = false;
602   -
  770 +
603 771 for (Element table : getDocument().getAllElements("img")) {
604   -
  772 +
605 773 Attribute usemap = table.getAttributes().get("usemap");
606 774 Attribute alt = table.getAttributes().get("alt");
607   -
608   - if (usemap != null && (alt == null || alt.getValue().isEmpty())){
609   - occurrences.add(this.buildOccurrence("3.7", true, table.toString(), table, "1"));
  775 +
  776 + if (usemap != null && (alt == null || alt.getValue().isEmpty())) {
  777 + occurrences.add(this.buildOccurrence("3.7", true,
  778 + table.toString(), table, "1"));
610 779 isMap = true;
611 780 }
612   -
  781 +
613 782 }
614   -
615   - if(isMap)
  783 +
  784 + if (isMap)
616 785 for (Element map : getDocument().getAllElements("map")) {
617   - for (Element area :map.getAllElements("area")) {
  786 + for (Element area : map.getAllElements("area")) {
618 787 Attribute alt = area.getAttributes().get("alt");
619   - if(alt == null || alt.getValue().isEmpty())
620   - occurrences.add(this.buildOccurrence("3.7", true, map.toString(), map, "1"));
  788 + if (alt == null || alt.getValue().isEmpty())
  789 + occurrences.add(this.buildOccurrence("3.7", true,
  790 + map.toString(), map, "1"));
621 791 }
622 792 }
623   -
624   -
  793 +
625 794 return occurrences;
626 795 }
627   -
  796 +
628 797 private List<Occurrence> checkRecommendation24() {
629 798 List<Occurrence> occurrences = new ArrayList<Occurrence>();
630   - occurrences.add(new Occurrence("3.8", false, getDocument().getFirstElement().toString(),OccurrenceClassification.CONTENT_INFORMATION));
  799 + occurrences.add(new Occurrence("3.8", false, getDocument()
  800 + .getFirstElement().toString(),
  801 + OccurrenceClassification.CONTENT_INFORMATION));
631 802 return occurrences;
632 803 }
633   -
  804 +
634 805 private List<Occurrence> checkRecommendation25() {
635 806 List<Occurrence> occurrences = new ArrayList<Occurrence>();
636   -
  807 +
  808 + String doctype = getDocument().getFirstStartTag().toString()
  809 + .replace(" ", "");
  810 +
637 811 for (Element table : getDocument().getAllElements("table")) {
638 812 Attribute summary = table.getAttributes().get("summary");
  813 +
  814 + if (!doctype.equals("<!DOCTYPEhtml>")) {
  815 + if (summary == null || summary.getValue().equals(""))
  816 + occurrences.add(buildOccurrence("3.9", false, table
  817 + .getStartTag().toString(), table, "1"));
  818 + }
639 819  
640   - if (summary == null || summary.getValue().equals(""))
641   - occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString(), table, "1"));
642   -
643   - if(table.getAllElements("caption").isEmpty() || table.getAllElements("caption") == null)
644   - occurrences.add(buildOccurrence("3.9", false, table.getStartTag().toString(), table, "1"));
  820 + if (table.getAllElements("caption").isEmpty()
  821 + || table.getAllElements("caption") == null)
  822 + occurrences.add(buildOccurrence("3.9", false, table
  823 + .getStartTag().toString(), table, "1"));
645 824 }
646   -
  825 +
647 826 return occurrences;
648 827 }
649   -
  828 +
650 829 private List<Occurrence> checkRecommendation26() {
651 830 List<Occurrence> occurrences = new ArrayList<Occurrence>();
652   -
653   - /*for (Element table : getDocument().getAllElements("table")) {
654   - occurrences.add(buildOccurrence("3.10", false, table.toString(), table, "1"));
655   - }*/
656   -
  831 +
  832 + /*
  833 + * for (Element table : getDocument().getAllElements("table")) {
  834 + * occurrences.add(buildOccurrence("3.10", false, table.toString(),
  835 + * table, "1")); }
  836 + */
  837 +
657 838 for (Element table : getDocument().getAllElements("table")) {
658   - for(Element caption : table.getAllElements("caption")){
659   - if(caption == null || caption.isEmpty())
660   - occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString(), table, "1"));
  839 + for (Element caption : table.getAllElements("caption")) {
  840 + if (caption == null || caption.isEmpty())
  841 + occurrences.add(buildOccurrence("3.10", true, table
  842 + .getStartTag().toString(), table, "1"));
661 843 }
662 844 }
663   -
664   -
  845 +
665 846 for (Element table : getDocument().getAllElements("table")) {
666 847 Attribute summary = table.getAttributes().get("summary");
667   -
  848 +
668 849 boolean THusaScope = false;
669 850 boolean THusaId = false;
670 851 boolean THusaHeaders = false;
671 852 boolean TDusaScope = false;
672   - boolean TDusaId= false;
  853 + boolean TDusaId = false;
673 854 boolean TDusaHeaders = false;
674 855 boolean usaThead = false;
675 856 boolean usaTfoot = false;
676 857 boolean usaTbody = false;
677   -
678   -
679   - if (summary == null || summary.getValue().equals(""))
680   - occurrences.add(buildOccurrence("3.10", true, table.getStartTag().toString(), table, "1"));
681   -
  858 +
  859 + if (summary == null || summary.getValue().equals(""))
  860 + occurrences.add(buildOccurrence("3.10", true, table
  861 + .getStartTag().toString(), table, "1"));
  862 +
682 863 for (Element thead : table.getAllElements("thead")) {
683 864 if (thead != null)
684 865 usaThead = true;
685 866 }
686   -
  867 +
687 868 for (Element tfoot : table.getAllElements("tfoot")) {
688 869 if (tfoot != null)
689 870 usaTfoot = true;
690 871 }
691   -
  872 +
692 873 for (Element tbody : table.getAllElements("tbody")) {
693 874 if (tbody != null)
694 875 usaTbody = true;
695 876 }
696   -
697   - /*if(!usaThead && !usaTbody && !usaTfoot){
698   -
699   - //occurrences.add(this.buildOccurrence("3.10", true, table.getAllStartTags("table").get(0).toString(), table, "1"));
700   -
701   - for (Element th : table.getAllElements("th")) {
702   - Attribute scope = th.getAttributes().get("scope");
703   - Attribute headers = th.getAttributes().get("headers");
704   - Attribute id = th.getAttributes().get("id");
705   - if (scope != null && !scope.getValue().equals("")) {
706   - THusaScope = true;
707   - } else if (headers != null && !headers.getValue().equals("")) {
708   - THusaHeaders = true;
709   - } else if (id != null && !id.getValue().equals("")) {
710   - THusaId = true;
711   - }
712   -
713   - if(!THusaScope && !THusaHeaders && !THusaId){
714   - occurrences.add(this.buildOccurrence("3.10", true, th.toString(), th, "1"));
715   - }
716   - }
717   -
718   - for (Element td : table.getAllElements("td")) {
719   - Attribute tdscope = td.getAttributes().get("scope");
720   - Attribute tdheaders = td.getAttributes().get("headers");
721   - Attribute tdid = td.getAttributes().get("id");
722   - if (tdscope != null && !tdscope.getValue().equals("")) {
723   - TDusaScope = true;
724   - } else if (tdheaders != null && !tdheaders.getValue().equals("")) {
725   - TDusaHeaders = true;
726   - } else if (tdid != null && !tdid.getValue().equals("")) {
727   - TDusaId = true;
728   - }
729   -
730   - if(!TDusaScope && !TDusaHeaders && !TDusaId){
731   - occurrences.add(this.buildOccurrence("3.10", true, td.toString(), td, "1"));
732   - }
733   - }
734   -
735   - }*/
736   - }
737   - //Sorting
  877 +
  878 + /*
  879 + * if(!usaThead && !usaTbody && !usaTfoot){
  880 + *
  881 + * //occurrences.add(this.buildOccurrence("3.10", true,
  882 + * table.getAllStartTags("table").get(0).toString(), table, "1"));
  883 + *
  884 + * for (Element th : table.getAllElements("th")) { Attribute scope =
  885 + * th.getAttributes().get("scope"); Attribute headers =
  886 + * th.getAttributes().get("headers"); Attribute id =
  887 + * th.getAttributes().get("id"); if (scope != null &&
  888 + * !scope.getValue().equals("")) { THusaScope = true; } else if
  889 + * (headers != null && !headers.getValue().equals("")) {
  890 + * THusaHeaders = true; } else if (id != null &&
  891 + * !id.getValue().equals("")) { THusaId = true; }
  892 + *
  893 + * if(!THusaScope && !THusaHeaders && !THusaId){
  894 + * occurrences.add(this.buildOccurrence("3.10", true, th.toString(),
  895 + * th, "1")); } }
  896 + *
  897 + * for (Element td : table.getAllElements("td")) { Attribute tdscope
  898 + * = td.getAttributes().get("scope"); Attribute tdheaders =
  899 + * td.getAttributes().get("headers"); Attribute tdid =
  900 + * td.getAttributes().get("id"); if (tdscope != null &&
  901 + * !tdscope.getValue().equals("")) { TDusaScope = true; } else if
  902 + * (tdheaders != null && !tdheaders.getValue().equals("")) {
  903 + * TDusaHeaders = true; } else if (tdid != null &&
  904 + * !tdid.getValue().equals("")) { TDusaId = true; }
  905 + *
  906 + * if(!TDusaScope && !TDusaHeaders && !TDusaId){
  907 + * occurrences.add(this.buildOccurrence("3.10", true, td.toString(),
  908 + * td, "1")); } }
  909 + *
  910 + * }
  911 + */
  912 + }
  913 + // Sorting
738 914 Collections.sort(occurrences, new Comparator<Occurrence>() {
739   - public int compare(Occurrence occurrence1, Occurrence occurrence2){
740   - return occurrence1.getLine().compareTo(occurrence2.getLine());
741   - }
742   - });
743   -
  915 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  916 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  917 + }
  918 + });
  919 +
744 920 return occurrences;
745 921  
746 922 }
747   -
  923 +
748 924 private List<Occurrence> checkRecommendation27() {
749 925 List<Occurrence> occurrences = new ArrayList<Occurrence>();
750   -
751   - //String reg = "<p.*?>(.*)<\\/p.*?>";
752   -
  926 +
  927 + // String reg = "<p.*?>(.*)<\\/p.*?>";
  928 +
753 929 for (Element paragrafo : getDocument().getAllElements("p")) {
754   -
755   - /* Pattern p = Pattern.compile(reg,Pattern.CASE_INSENSITIVE);
756   - Matcher m = p.matcher(paragrafo);
757   -
758   - while(m.find()){
759   - String conteudoParagrafo = m.group(1);
760   -
761   - if(conteudoParagrafo.length() > 1000)
762   - occurrences.add(this.buildOccurrence("3.11", false, paragrafo.toString(), paragrafo, "1"));
763   - }*/
764   -
765   -
766   - if(paragrafo.getContent().length() > 1000)
767   - occurrences.add(this.buildOccurrence("3.11", false, paragrafo.toString(), paragrafo, "1"));
768   -
769   - String align = paragrafo.getAttributeValue("align");
770   - if("justify".equals(align))
771   - occurrences.add(this.buildOccurrence("3.11", true, paragrafo.toString(), paragrafo, "2"));
772   -
773   - String style = paragrafo.getAttributeValue("style");
774   - if(style != null && style.contains("text-align:justify"))
775   - occurrences.add(this.buildOccurrence("3.11", true, paragrafo.toString(), paragrafo, "2"));
776   - }
777   -
778   -
  930 +
  931 + /*
  932 + * Pattern p = Pattern.compile(reg,Pattern.CASE_INSENSITIVE);
  933 + * Matcher m = p.matcher(paragrafo);
  934 + *
  935 + * while(m.find()){ String conteudoParagrafo = m.group(1);
  936 + *
  937 + * if(conteudoParagrafo.length() > 1000)
  938 + * occurrences.add(this.buildOccurrence("3.11", false,
  939 + * paragrafo.toString(), paragrafo, "1")); }
  940 + */
  941 +
  942 + if (paragrafo.getContent().length() > 1000)
  943 + occurrences.add(this.buildOccurrence("3.11", false,
  944 + paragrafo.toString(), paragrafo, "1"));
  945 +
  946 + String align = paragrafo.getAttributeValue("align");
  947 + if ("justify".equals(align))
  948 + occurrences.add(this.buildOccurrence("3.11", true,
  949 + paragrafo.toString(), paragrafo, "2"));
  950 +
  951 + String style = paragrafo.getAttributeValue("style");
  952 + if (style != null && style.contains("text-align:justify"))
  953 + occurrences.add(this.buildOccurrence("3.11", true,
  954 + paragrafo.toString(), paragrafo, "2"));
  955 + }
  956 +
779 957 for (Element tags : getDocument().getAllElements()) {
780   - if(!tags.getName().equals("p")){
781   - String style = tags.getAttributeValue("style");
782   - if(style != null && style.contains("text-align:justify"))
783   - occurrences.add(this.buildOccurrence("3.11", true, tags.toString(), tags, "3"));
784   - }
785   -
  958 + if (!tags.getName().equals("p")) {
  959 + String style = tags.getAttributeValue("style");
  960 + if (style != null && style.contains("text-align:justify"))
  961 + occurrences.add(this.buildOccurrence("3.11", true,
  962 + tags.toString(), tags, "3"));
  963 + }
  964 +
786 965 }
787 966 return occurrences;
788 967 }
789   -
  968 +
790 969 private List<Occurrence> checkRecommendation28() {
791 970 List<Occurrence> occurrences = new ArrayList<Occurrence>();
792   -
  971 +
793 972 for (Element abbr : getDocument().getAllElements("abbr")) {
794 973 Attribute title = abbr.getAttributes().get("title");
795   - if(title == null || title.getValue().equals(""))
796   - occurrences.add(buildOccurrence("3.12", true, abbr.toString(), abbr, "1"));
797   -
798   -
799   - if(abbr.getContent() == null)
800   - occurrences.add(buildOccurrence("3.12", true, abbr.toString(), abbr, "1"));
  974 + if (title == null || title.getValue().equals(""))
  975 + occurrences.add(buildOccurrence("3.12", true, abbr.toString(),
  976 + abbr, "1"));
  977 +
  978 + if (abbr.getContent() == null)
  979 + occurrences.add(buildOccurrence("3.12", true, abbr.toString(),
  980 + abbr, "1"));
801 981 }
802   -
  982 +
803 983 return occurrences;
804 984 }
805   -
806   - private Occurrence buildOccurrence(String code, boolean error,
807   - String tag, Element element,
808   - String criterio) {
809   - return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.CONTENT_INFORMATION,criterio);
810   - }
811   -
812   - public OccurrenceClassification type () { return OccurrenceClassification.CONTENT_INFORMATION;}
813   -
814   - private String[] hrefRegistroBr = {"COM","COM.BR","ECO.BR","EMP.BR","NET.BR","EDU.BR",
815   - "ADM.BR","ADV.BR","ARQ.BR","ATO.BR","BIO.BR","BMD.BR","CIM.BR","CNG.BR",
816   - "CNT.BR","ECN.BR","ENG.BR","ETI.B","FND.BR","FOT.BR","FST.BR","GGF.BR","JOR.BR",
817   - "LEL.BR","MAT.BR","MED.BR","MUS.BR","NOT.BR","NTR.BR","ODO.BR","PPG.BR","PRO.BR",
818   - "PSC.BR","QSL.BR","SLG.BR","TAXI.BR","TEO.BR","TRD.BR","VET.BR","ZLG.BR","BLOG.BR",
819   - "FLOG.BR","NOM.BR","VLOG.BR","WIKI.BR","AGR.BR","ART.BR","ESP.BR","ETC.BR","FAR.BR",
820   - "IMB.BR","IND.BR","INF.BR","RADIO.BR","REC.BR","SRV.BR","TMP.BR","TUR.BR","TV.BR",
821   - "AM.BR","COOP.BR","FM.BR","G12.BR","GOV.BR","MIL.BR","ORG.BR","PSI.BR","B.BR",
822   - "JUS.BR","LEG.BR","MP.BR"};
823   -
824   - private String[] leiaMais = {"clique aqui","leia mais","saiba mais","veja mais","acesse a lista", "mais"};
825   -
826   - private List<Occurrence> oder(List occurrences){
827   - //Sorting
  985 +
  986 + private Occurrence buildOccurrence(String code, boolean error, String tag,
  987 + Element element, String criterio) {
  988 + return super.buildOccurrence(code, error, tag, element,
  989 + OccurrenceClassification.CONTENT_INFORMATION, criterio);
  990 + }
  991 +
  992 + public OccurrenceClassification type() {
  993 + return OccurrenceClassification.CONTENT_INFORMATION;
  994 + }
  995 +
  996 + private String[] hrefRegistroBr = { "COM", "COM.BR", "ECO.BR", "EMP.BR",
  997 + "NET.BR", "EDU.BR", "ADM.BR", "ADV.BR", "ARQ.BR", "ATO.BR",
  998 + "BIO.BR", "BMD.BR", "CIM.BR", "CNG.BR", "CNT.BR", "ECN.BR",
  999 + "ENG.BR", "ETI.B", "FND.BR", "FOT.BR", "FST.BR", "GGF.BR",
  1000 + "JOR.BR", "LEL.BR", "MAT.BR", "MED.BR", "MUS.BR", "NOT.BR",
  1001 + "NTR.BR", "ODO.BR", "PPG.BR", "PRO.BR", "PSC.BR", "QSL.BR",
  1002 + "SLG.BR", "TAXI.BR", "TEO.BR", "TRD.BR", "VET.BR", "ZLG.BR",
  1003 + "BLOG.BR", "FLOG.BR", "NOM.BR", "VLOG.BR", "WIKI.BR", "AGR.BR",
  1004 + "ART.BR", "ESP.BR", "ETC.BR", "FAR.BR", "IMB.BR", "IND.BR",
  1005 + "INF.BR", "RADIO.BR", "REC.BR", "SRV.BR", "TMP.BR", "TUR.BR",
  1006 + "TV.BR", "AM.BR", "COOP.BR", "FM.BR", "G12.BR", "GOV.BR", "MIL.BR",
  1007 + "ORG.BR", "PSI.BR", "B.BR", "JUS.BR", "LEG.BR", "MP.BR" };
  1008 +
  1009 + private String[] leiaMais = { "clique aqui", "leia mais", "saiba mais",
  1010 + "veja mais", "acesse a lista", "mais" };
  1011 +
  1012 + private List<Occurrence> oder(List occurrences) {
  1013 + // Sorting
828 1014 Collections.sort(occurrences, new Comparator<Occurrence>() {
829   - public int compare(Occurrence occurrence1, Occurrence occurrence2){
830   - return occurrence1.getLine().compareTo(occurrence2.getLine());
831   - }
832   - });
  1015 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  1016 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  1017 + }
  1018 + });
833 1019 return occurrences;
834 1020 }
835   -
  1021 +
836 1022 }
... ...
src/main/java/br/com/checker/emag/core/MarkEvaluation.java
... ... @@ -23,74 +23,123 @@ import com.google.gson.Gson;
23 23 import com.google.gson.GsonBuilder;
24 24  
25 25 public class MarkEvaluation extends Evaluation {
26   -
27   - //private static String CSS_VALIDATOR_URL = "http://www.css-validator.org/validator?uri=#{url}&warning=0&output=soap12";
  26 +
  27 + // private static String CSS_VALIDATOR_URL =
  28 + // "http://www.css-validator.org/validator?uri=#{url}&warning=0&output=soap12";
28 29 private static String CSS_VALIDATOR_URL = "http://jigsaw.w3.org/css-validator/validator?uri=#{url}&warning=0&output=soap12";
29 30 private static String HTML_VALIDATOR_URL = "https://validator.w3.org/nu/?doc=#{url}&out=json";
30   -
31   - private MarkEvaluation(Source document) { super(document); }
32   -
33   - private MarkEvaluation(Source document,String url) {
34   - super(document,url);
  31 +
  32 + private MarkEvaluation(Source document) {
  33 + super(document);
  34 + }
  35 +
  36 + private MarkEvaluation(Source document, String url) {
  37 + super(document, url);
35 38 }
36   -
  39 +
37 40 public static class MarkEvaluationBuilder extends EvaluationBuilder {
38   -
  41 +
39 42 @Override
40   - protected MarkEvaluation with(Source document) { return new MarkEvaluation(document); }
41   -
42   -
  43 + protected MarkEvaluation with(Source document) {
  44 + return new MarkEvaluation(document);
  45 + }
  46 +
43 47 @Override
44   - protected MarkEvaluation with(Source document,String url) { return new MarkEvaluation(document,url); }
45   -
46   - public SpecificRecommendation recommendation1() { return new EvaluationRecommendation1();}
47   - public SpecificRecommendation recommendation2() { return new EvaluationRecommendation2();}
48   - public SpecificRecommendation recommendation3() { return new EvaluationRecommendation3();}
49   - public SpecificRecommendation recommendation4() { return new EvaluationRecommendation4();}
50   - public SpecificRecommendation recommendation5() { return new EvaluationRecommendation5();}
51   - public SpecificRecommendation recommendation6() { return new EvaluationRecommendation6();}
52   - public SpecificRecommendation recommendation7() { return new EvaluationRecommendation7();}
53   - public SpecificRecommendation recommendation8() { return new EvaluationRecommendation8();}
54   - public SpecificRecommendation recommendation9() { return new EvaluationRecommendation9();}
55   - }
56   -
57   - protected static class EvaluationRecommendation1 extends MarkRecommendation{
58   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation1();}
59   - }
60   -
61   - protected static class EvaluationRecommendation2 extends MarkRecommendation{
62   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation2();}
63   - }
64   -
65   - protected static class EvaluationRecommendation3 extends MarkRecommendation{
66   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation3();}
67   - }
68   -
69   - protected static class EvaluationRecommendation4 extends MarkRecommendation{
70   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation4();}
71   - }
72   -
73   - protected static class EvaluationRecommendation5 extends MarkRecommendation{
74   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation5();}
75   - }
76   -
77   - protected static class EvaluationRecommendation6 extends MarkRecommendation{
78   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation6();}
79   - }
80   -
81   - protected static class EvaluationRecommendation7 extends MarkRecommendation{
82   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation7();}
83   - }
84   -
85   - protected static class EvaluationRecommendation8 extends MarkRecommendation{
86   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation8();}
87   - }
88   -
89   - protected static class EvaluationRecommendation9 extends MarkRecommendation{
90   - protected List<Occurrence> check() { return getEvaluation().checkRecommendation9();}
91   - }
92   -
93   -
  48 + protected MarkEvaluation with(Source document, String url) {
  49 + return new MarkEvaluation(document, url);
  50 + }
  51 +
  52 + public SpecificRecommendation recommendation1() {
  53 + return new EvaluationRecommendation1();
  54 + }
  55 +
  56 + public SpecificRecommendation recommendation2() {
  57 + return new EvaluationRecommendation2();
  58 + }
  59 +
  60 + public SpecificRecommendation recommendation3() {
  61 + return new EvaluationRecommendation3();
  62 + }
  63 +
  64 + public SpecificRecommendation recommendation4() {
  65 + return new EvaluationRecommendation4();
  66 + }
  67 +
  68 + public SpecificRecommendation recommendation5() {
  69 + return new EvaluationRecommendation5();
  70 + }
  71 +
  72 + public SpecificRecommendation recommendation6() {
  73 + return new EvaluationRecommendation6();
  74 + }
  75 +
  76 + public SpecificRecommendation recommendation7() {
  77 + return new EvaluationRecommendation7();
  78 + }
  79 +
  80 + public SpecificRecommendation recommendation8() {
  81 + return new EvaluationRecommendation8();
  82 + }
  83 +
  84 + public SpecificRecommendation recommendation9() {
  85 + return new EvaluationRecommendation9();
  86 + }
  87 + }
  88 +
  89 + protected static class EvaluationRecommendation1 extends MarkRecommendation {
  90 + protected List<Occurrence> check() {
  91 + return getEvaluation().checkRecommendation1();
  92 + }
  93 + }
  94 +
  95 + protected static class EvaluationRecommendation2 extends MarkRecommendation {
  96 + protected List<Occurrence> check() {
  97 + return getEvaluation().checkRecommendation2();
  98 + }
  99 + }
  100 +
  101 + protected static class EvaluationRecommendation3 extends MarkRecommendation {
  102 + protected List<Occurrence> check() {
  103 + return getEvaluation().checkRecommendation3();
  104 + }
  105 + }
  106 +
  107 + protected static class EvaluationRecommendation4 extends MarkRecommendation {
  108 + protected List<Occurrence> check() {
  109 + return getEvaluation().checkRecommendation4();
  110 + }
  111 + }
  112 +
  113 + protected static class EvaluationRecommendation5 extends MarkRecommendation {
  114 + protected List<Occurrence> check() {
  115 + return getEvaluation().checkRecommendation5();
  116 + }
  117 + }
  118 +
  119 + protected static class EvaluationRecommendation6 extends MarkRecommendation {
  120 + protected List<Occurrence> check() {
  121 + return getEvaluation().checkRecommendation6();
  122 + }
  123 + }
  124 +
  125 + protected static class EvaluationRecommendation7 extends MarkRecommendation {
  126 + protected List<Occurrence> check() {
  127 + return getEvaluation().checkRecommendation7();
  128 + }
  129 + }
  130 +
  131 + protected static class EvaluationRecommendation8 extends MarkRecommendation {
  132 + protected List<Occurrence> check() {
  133 + return getEvaluation().checkRecommendation8();
  134 + }
  135 + }
  136 +
  137 + protected static class EvaluationRecommendation9 extends MarkRecommendation {
  138 + protected List<Occurrence> check() {
  139 + return getEvaluation().checkRecommendation9();
  140 + }
  141 + }
  142 +
94 143 public List<Occurrence> check() {
95 144 getOccurrences().addAll(checkRecommendation1());
96 145 getOccurrences().addAll(checkRecommendation2());
... ... @@ -101,771 +150,949 @@ public class MarkEvaluation extends Evaluation {
101 150 getOccurrences().addAll(checkRecommendation7());
102 151 getOccurrences().addAll(checkRecommendation8());
103 152 getOccurrences().addAll(checkRecommendation9());
104   -
  153 +
105 154 return getOccurrences();
106 155 }
107   -
108   -
  156 +
109 157 private List<Occurrence> checkRecommendation1() {
110 158 List<Occurrence> occurrences = new ArrayList<Occurrence>();
111   -
112   -
  159 +
113 160 String url = getUrl();
114   - if(url!=null){
115   -
  161 + if (url != null) {
  162 +
116 163 int[] errosWarningsCss = getErrorCount(true, url);
117 164 int[] errosWarningsHtml = getErrorCount(false, url);
118   -
119   - if(errosWarningsHtml[1] > 0)
120   - occurrences.add(buildOccurrence("1.1", false, url, getDocument().getFirstElement(), "1"));
121   -
122   - if(errosWarningsCss[1] > 0)
123   - occurrences.add(buildOccurrence("1.1", false, url, getDocument().getFirstElement().getFirstElement(), "2"));
124   -
125   - if(errosWarningsHtml[0] > 0)
126   - occurrences.add(buildOccurrence("1.1", true, url, getDocument().getFirstElement(), "1"));
127   -
128   - if(errosWarningsCss[0] > 0)
129   - occurrences.add(buildOccurrence("1.1", true, url, getDocument().getFirstElement().getFirstElement(), "2"));
  165 +
  166 + if (errosWarningsHtml[1] > 0)
  167 + occurrences.add(buildOccurrence("1.1", false, url,
  168 + getDocument().getFirstElement(), "1"));
  169 +
  170 + if (errosWarningsCss[1] > 0)
  171 + occurrences
  172 + .add(buildOccurrence("1.1", false, url, getDocument()
  173 + .getFirstElement().getFirstElement(), "2"));
  174 +
  175 + if (errosWarningsHtml[0] > 0)
  176 + occurrences.add(buildOccurrence("1.1", true, url, getDocument()
  177 + .getFirstElement(), "1"));
  178 +
  179 + if (errosWarningsCss[0] > 0)
  180 + occurrences.add(buildOccurrence("1.1", true, url, getDocument()
  181 + .getFirstElement().getFirstElement(), "2"));
130 182 }
131   -
  183 +
132 184 for (Element element : getDocument().getAllElements()) {
133 185 String value = element.getAttributeValue("style");
134   -
135   - if(value != null)
136   - occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "3"));
  186 +
  187 + if (value != null)
  188 + occurrences.add(this.buildOccurrence("1.1", false,
  189 + element.toString(), element, "3"));
137 190 }
138   -
  191 +
139 192 for (Element element : getDocument().getAllElements("style")) {
140   -
141   - if(element != null)
142   - occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "4"));
143   - }
144   -
145   -
146   - List<String> eventos = new ArrayList<String>( Arrays.asList("onclick", "ondblclick"));
147   -
148   -
  193 +
  194 + if (element != null)
  195 + occurrences.add(this.buildOccurrence("1.1", false,
  196 + element.toString(), element, "4"));
  197 + }
  198 +
  199 + List<String> eventos = new ArrayList<String>(Arrays.asList("onclick",
  200 + "ondblclick"));
  201 +
149 202 for (Element element : getDocument().getAllElements()) {
150   - if(element.getAttributes() != null){
151   - //String script = element.getAttributes().getTextExtractor().toString();
152   - for (Attribute attribute : element.getAttributes()) {
153   - if(eventos.contains(attribute.getName()))
154   - occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "5"));
  203 + if (element.getAttributes() != null) {
  204 + // String script =
  205 + // element.getAttributes().getTextExtractor().toString();
  206 + for (Attribute attribute : element.getAttributes()) {
  207 + if (eventos.contains(attribute.getName()))
  208 + occurrences.add(this.buildOccurrence("1.1", false,
  209 + element.toString(), element, "5"));
155 210 }
156   -
157   - /* if(script.contains("javascript")){
158   - occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "5"));
159   - }*/
  211 +
  212 + /*
  213 + * if(script.contains("javascript")){
  214 + * occurrences.add(this.buildOccurrence("1.1", false,
  215 + * element.toString(), element, "5")); }
  216 + */
160 217 }
161 218 }
162   -
  219 +
163 220 for (Element element : getDocument().getAllElements("script")) {
164   - //if(element.getAttributeValue("src") ==null)
165   - if(element != null)
166   - occurrences.add(this.buildOccurrence("1.1", false, element.toString(), element, "6"));
  221 + // if(element.getAttributeValue("src") ==null)
  222 + if (element != null)
  223 + occurrences.add(this.buildOccurrence("1.1", false,
  224 + element.toString(), element, "6"));
167 225 }
168   -
  226 +
169 227 this.oder(occurrences);
170   -
  228 +
171 229 return occurrences;
172 230 }
173   -
  231 +
174 232 private List<Occurrence> checkRecommendation2() {
175 233 List<Occurrence> occurrences = new ArrayList<Occurrence>();
176   -
177   - List<String> tags = Arrays.asList("h1","h2","h3","h4","h5","h6","a","p");
  234 +
  235 + List<String> tags = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6",
  236 + "a", "p");
178 237 List<Integer> linhasImg = new ArrayList<Integer>();
179   -
180   - for (String tag : tags) {
181   - for (Element element : getDocument().getAllElements(tag)) {
182   -
183   - /*if(element.getAttributes().getCount()==0)
184   - occurrences.add(this.buildOccurrence("1.2", true, element.toString(), element, "1"));
185   - else*/
186   -
187   - if(element != null){
188   - String endTag = element.getEndTag() == null ? "" : element.getEndTag().toString();
189   -
190   - Element img = element.getFirstElement("img");
191   -
192   - if(img != null){
193   - if(img.getAttributes().get("alt") != null && img.getAttributes().get("alt").getValue().isEmpty()){
194   -
195   - if(!linhasImg.contains(this.getRow(img))){
196   - occurrences.add(this.buildOccurrence("1.2", true,img.getStartTag().toString(), img, "1"));
197   - }
198   - linhasImg.add(this.getRow(img));
199   - }
200   - }else{
201   - if(element.getContent().toString().isEmpty() || element.getContent().toString().trim().equals("")){
202   - occurrences.add(this.buildOccurrence("1.2", true, element.getStartTag().toString() + endTag, element, "1"));
203   - }
  238 +
  239 + for (String tag : tags) {
  240 + for (Element element : getDocument().getAllElements(tag)) {
  241 +
  242 + /*
  243 + * if(element.getAttributes().getCount()==0)
  244 + * occurrences.add(this.buildOccurrence("1.2", true,
  245 + * element.toString(), element, "1")); else
  246 + */
  247 +
  248 + if (element != null) {
  249 + String endTag = element.getEndTag() == null ? "" : element
  250 + .getEndTag().toString();
  251 +
  252 + Element img = element.getFirstElement("img");
  253 +
  254 + if (img != null) {
  255 + if (img.getAttributes().get("alt") != null
  256 + && img.getAttributes().get("alt").getValue()
  257 + .isEmpty()) {
  258 +
  259 + if (!linhasImg.contains(this.getRow(img))) {
  260 + occurrences.add(this.buildOccurrence("1.2",
  261 + true, img.getStartTag().toString(),
  262 + img, "1"));
  263 + }
  264 + linhasImg.add(this.getRow(img));
  265 + }
  266 + } else {
  267 + if (element.getContent().toString().isEmpty()
  268 + || element.getContent().toString().trim()
  269 + .equals("")) {
  270 + occurrences.add(this.buildOccurrence("1.2", true,
  271 + element.getStartTag().toString() + endTag,
  272 + element, "1"));
204 273 }
205 274 }
206 275 }
207   -
208 276 }
209   -
210   - linhasImg = new ArrayList<Integer>();
211   -
212   - tags = Arrays.asList("!doctype","script","meta","style","head","link","h1","h2","h3","h4","h5","h6","a","p","input");
213   -
214   - for (Element element : getDocument().getAllElements()) {
215   - if(!tags.contains(element.getName())){
216   -
217   - if(element != null && !(element.getName().equals("!--"))){
218   -
219   - String endTag = element.getEndTag() == null ? "" : element.getEndTag().toString();
220   -
221   - Element img = element.getFirstElement("img");
222   -
223   - if(img != null){
224   - if(img.getAttributes().get("alt") != null && img.getAttributes().get("alt").getValue().isEmpty()){
225   -
226   - if(!linhasImg.contains(this.getRow(img))){
227   - occurrences.add(this.buildOccurrence("1.2", false, img.toString(), img, "1"));
228   - }
229   -
230   - linhasImg.add(this.getRow(img));
231   - }
232   -
233   - }else{
234   - if(element.getContent().toString().isEmpty() || element.getContent().toString().trim().equals("")){
235   - occurrences.add(this.buildOccurrence("1.2", false, element.getStartTag().toString() + endTag, element, "1"));
236   - }
237   -
  277 +
  278 + }
  279 +
  280 + linhasImg = new ArrayList<Integer>();
  281 +
  282 + tags = Arrays.asList("!doctype", "script", "meta", "style", "head",
  283 + "link", "h1", "h2", "h3", "h4", "h5", "h6", "a", "p", "input");
  284 +
  285 + for (Element element : getDocument().getAllElements()) {
  286 + if (!tags.contains(element.getName())) {
  287 +
  288 + if (element != null && !(element.getName().equals("!--"))) {
  289 +
  290 + String endTag = element.getEndTag() == null ? "" : element
  291 + .getEndTag().toString();
  292 +
  293 + Element img = element.getFirstElement("img");
  294 +
  295 + if (img != null) {
  296 + if (img.getAttributes().get("alt") != null
  297 + && img.getAttributes().get("alt").getValue()
  298 + .isEmpty()) {
  299 +
  300 + if (!linhasImg.contains(this.getRow(img))) {
  301 + occurrences.add(this.buildOccurrence("1.2",
  302 + false, img.toString(), img, "1"));
  303 + }
  304 +
  305 + linhasImg.add(this.getRow(img));
  306 + }
  307 +
  308 + } else {
  309 + if (element.getContent().toString().isEmpty()
  310 + || element.getContent().toString().trim()
  311 + .equals("")) {
  312 + occurrences.add(this.buildOccurrence("1.2", false,
  313 + element.getStartTag().toString() + endTag,
  314 + element, "1"));
238 315 }
  316 +
239 317 }
240 318 }
241 319 }
242   -
243   - this.oder(occurrences);
244   -
245   -
246   - /*boolean isError = false;
247   - for (Element element : getDocument().getAllElements()) {
248   - Attributes attribute = element.getAttributes();
249   -
250   - isError = tags.contains(element.getName());
251   -
252   -
253   - if(element.isEmpty())
254   - occurrences.add(this.buildOccurrence("1.2", isError, element.toString(), element, "1"));
255   - else if(attribute.getCount()==0)
256   - occurrences.add(this.buildOccurrence("1.2", isError, element.toString(), element, "1"));
257   - }*/
258   -
259   -
260   -
  320 + }
  321 +
  322 + this.oder(occurrences);
  323 +
  324 + /*
  325 + * boolean isError = false; for (Element element :
  326 + * getDocument().getAllElements()) { Attributes attribute =
  327 + * element.getAttributes();
  328 + *
  329 + * isError = tags.contains(element.getName());
  330 + *
  331 + *
  332 + * if(element.isEmpty()) occurrences.add(this.buildOccurrence("1.2",
  333 + * isError, element.toString(), element, "1")); else
  334 + * if(attribute.getCount()==0)
  335 + * occurrences.add(this.buildOccurrence("1.2", isError,
  336 + * element.toString(), element, "1")); }
  337 + */
  338 +
261 339 return occurrences;
262 340 }
263   -
  341 +
264 342 private List<Occurrence> checkRecommendation3() {
265   -
266   -
267   - //CRITERIO 4
  343 +
  344 + // CRITERIO 4
268 345 List<Occurrence> occurrences = new ArrayList<Occurrence>();
269 346 int count = 0;
270   -
271   - for (Element element : getDocument().getAllElements("h1")){
272   - if(count>0){
273   - occurrences.add(this.buildOccurrence("1.3", true,element.toString(), element, "4"));
274   - }else
  347 +
  348 + for (Element element : getDocument().getAllElements("h1")) {
  349 + if (count > 0) {
  350 + occurrences.add(this.buildOccurrence("1.3", true,
  351 + element.toString(), element, "4"));
  352 + } else
275 353 count++;
276 354 }
277   -
278   - /*if(count>0)
279   - occurrences.add(this.buildOccurrence("1.3", true,getDocument().getFirstElement("h1").toString(), getDocument().getFirstElement("h1"), "4"));
280   - */
281   -
282   - //CRITERIO 3
  355 +
  356 + /*
  357 + * if(count>0) occurrences.add(this.buildOccurrence("1.3",
  358 + * true,getDocument().getFirstElement("h1").toString(),
  359 + * getDocument().getFirstElement("h1"), "4"));
  360 + */
  361 +
  362 + // CRITERIO 3
283 363 boolean hasOtherH = false;
284   - for(Element element : getDocument().getAllElements()) {
  364 + for (Element element : getDocument().getAllElements()) {
285 365 if (element.getName().matches("h[2-6]")) {
286 366 hasOtherH = true;
287 367 break;
288   - }
289   - }
290   -
291   - if(count >0 && !hasOtherH)
292   - occurrences.add(this.buildOccurrence("1.3", false,getDocument().getFirstElement("h1").toString(), getDocument().getFirstElement("h1"), "3"));
293   -
294   -
295   - //CRITERIO 2
296   -
297   - /*String[] tags = {"h6","h5","h4","h3","h2","h1"};
298   - //String[] tags = {"h1","h2","h3","h4","h5","h6"};
299   -
300   -
301   - for(int index = 0 ; index< tags.length ; index++){
302   -
303   - for(Element h : getDocument().getAllElements(tags[index])) {
304   - if(!hasCorrectHierarchy(index, tags))
305   - occurrences.add(this.buildOccurrence("1.3", true,h.toString(), h, "2"));
306 368 }
307   - }*/
308   -
309   -
310   -
  369 + }
  370 +
  371 + if (count > 0 && !hasOtherH)
  372 + occurrences.add(this.buildOccurrence("1.3", false, getDocument()
  373 + .getFirstElement("h1").toString(), getDocument()
  374 + .getFirstElement("h1"), "3"));
  375 +
  376 + // CRITERIO 2
  377 +
  378 + /*
  379 + * String[] tags = {"h6","h5","h4","h3","h2","h1"}; //String[] tags =
  380 + * {"h1","h2","h3","h4","h5","h6"};
  381 + *
  382 + *
  383 + * for(int index = 0 ; index< tags.length ; index++){
  384 + *
  385 + * for(Element h : getDocument().getAllElements(tags[index])) {
  386 + * if(!hasCorrectHierarchy(index, tags))
  387 + * occurrences.add(this.buildOccurrence("1.3", true,h.toString(), h,
  388 + * "2")); } }
  389 + */
  390 +
311 391 List<Element> elementsObj = getDocument().getAllElements();
312   -
  392 +
313 393 int anterior = 1;
314 394 for (Element htmlElement : elementsObj) {
315   - if (htmlElement.getName().matches("h[1-6]")) {
316   - int tagId = Integer.parseInt(htmlElement.getName().substring(1));
317   - if(!(tagId <= anterior)){
318   - if(!(tagId == anterior+1))
319   - occurrences.add(this.buildOccurrence("1.3", true,htmlElement.toString(), htmlElement, "2"));
320   - }
321   - anterior = tagId;
322   - }
323   - }
324   -
325   - if(!hasH())
326   - occurrences.add(this.buildOccurrence("1.3", true,"Observa&ccedil;&atilde;o - Sem fonte (os n&iacute;veis de t&iacute;tulo n&atilde;o foram utilizados)", getDocument().getFirstElement(), "1"));
327   -
328   - //Sorting
  395 + if (htmlElement.getName().matches("h[1-6]")) {
  396 + int tagId = Integer
  397 + .parseInt(htmlElement.getName().substring(1));
  398 + if (!(tagId <= anterior)) {
  399 + if (!(tagId == anterior + 1))
  400 + occurrences.add(this.buildOccurrence("1.3", true,
  401 + htmlElement.toString(), htmlElement, "2"));
  402 + }
  403 + anterior = tagId;
  404 + }
  405 + }
  406 +
  407 + if (!hasH())
  408 + occurrences
  409 + .add(this
  410 + .buildOccurrence(
  411 + "1.3",
  412 + true,
  413 + "Observa&ccedil;&atilde;o - Sem fonte (os n&iacute;veis de t&iacute;tulo n&atilde;o foram utilizados)",
  414 + getDocument().getFirstElement(), "1"));
  415 +
  416 + // Sorting
329 417 Collections.sort(occurrences, new Comparator<Occurrence>() {
330   - public int compare(Occurrence occurrence1, Occurrence occurrence2){
331   - return occurrence1.getLine().compareTo(occurrence2.getLine());
332   - }
333   - });
334   -
335   -
  418 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  419 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  420 + }
  421 + });
  422 +
336 423 return occurrences;
337 424 }
338   -
339   - private int verificarNiveis(Integer posicao, List<String> tags){
  425 +
  426 + private int verificarNiveis(Integer posicao, List<String> tags) {
340 427 for (int i = 0; i < posicao; i++) {
341   - if(Integer.parseInt( tags.get(i).substring(1)) == Integer.parseInt(tags.get(posicao).substring(1))-1){
  428 + if (Integer.parseInt(tags.get(i).substring(1)) == Integer
  429 + .parseInt(tags.get(posicao).substring(1)) - 1) {
342 430 return Integer.parseInt(tags.get(i).substring(1));
343   - }
344   - }
  431 + }
  432 + }
345 433 return -1;
346 434 }
347   -
348   - private boolean hasCorrectHierarchy(int index,String[] tags) {
349   -
350   - for(int i = index+1;i<tags.length;i++ ){
351   - if(getDocument().getFirstElement(tags[i])== null)
  435 +
  436 + private boolean hasCorrectHierarchy(int index, String[] tags) {
  437 +
  438 + for (int i = index + 1; i < tags.length; i++) {
  439 + if (getDocument().getFirstElement(tags[i]) == null)
352 440 return false;
353 441 }
354 442 return true;
355 443 }
356   -
  444 +
357 445 private boolean hasH() {
358   -
359   - String[] tags = {"h6","h5","h4","h3","h2","h1"};
360   - for(String h : tags){
361   - if(getDocument().getFirstElement(h) !=null)
  446 +
  447 + String[] tags = { "h6", "h5", "h4", "h3", "h2", "h1" };
  448 + for (String h : tags) {
  449 + if (getDocument().getFirstElement(h) != null)
362 450 return true;
363 451 }
364   -
  452 +
365 453 return false;
366 454 }
367   -
368   - /*No documento NÃO PERMITE VERIFICAÇÃO AUTOMATIZADA*/
  455 +
  456 + /* No documento NÃO PERMITE VERIFICAÇÃO AUTOMATIZADA */
369 457 private List<Occurrence> checkRecommendation4() {
370 458 List<Occurrence> occurrences = new ArrayList<Occurrence>();
371   -
372   - for(Element link : this.getDocument().getAllElements("a")){
  459 +
  460 + for (Element link : this.getDocument().getAllElements("a")) {
373 461 Attribute tabIndex = link.getAttributes().get("tabindex");
374   - if(tabIndex!=null) {
375   - occurrences.add(this.buildOccurrence("1.4", false,link.toString(), link, "2"));
376   -
377   - if(rangeIncorretoTabeIndex(tabIndex))
378   - occurrences.add(this.buildOccurrence("1.4", false,link.toString(), link, "3"));
  462 + if (tabIndex != null) {
  463 + occurrences.add(this.buildOccurrence("1.4", false,
  464 + link.toString(), link, "2"));
  465 +
  466 + if (rangeIncorretoTabeIndex(tabIndex))
  467 + occurrences.add(this.buildOccurrence("1.4", false,
  468 + link.toString(), link, "3"));
379 469 }
380 470 }
381   -
382   - for(Element input : this.getDocument().getAllElements("input")){
383   -
  471 +
  472 + for (Element input : this.getDocument().getAllElements("input")) {
  473 +
384 474 Attribute tabIndex = input.getAttributes().get("tabindex");
385   - if(tabIndex!=null)
386   - occurrences.add(this.buildOccurrence("1.4", false, input.toString(), input, "2"));
387   -
388   - if(rangeIncorretoTabeIndex(tabIndex))
389   - occurrences.add(this.buildOccurrence("1.4", false,input.toString(), input, "3"));
  475 + if (tabIndex != null)
  476 + occurrences.add(this.buildOccurrence("1.4", false,
  477 + input.toString(), input, "2"));
  478 +
  479 + if (rangeIncorretoTabeIndex(tabIndex))
  480 + occurrences.add(this.buildOccurrence("1.4", false,
  481 + input.toString(), input, "3"));
390 482 }
391   -
392   - for(Element select : this.getDocument().getAllElements("select")){
393   -
  483 +
  484 + for (Element select : this.getDocument().getAllElements("select")) {
  485 +
394 486 Attribute tabIndex = select.getAttributes().get("tabindex");
395   - if(tabIndex!=null)
396   - occurrences.add(this.buildOccurrence("1.4", false, select.toString(), select, "2"));
397   -
398   - if(rangeIncorretoTabeIndex(tabIndex))
399   - occurrences.add(this.buildOccurrence("1.4", false,select.toString(), select, "3"));
  487 + if (tabIndex != null)
  488 + occurrences.add(this.buildOccurrence("1.4", false,
  489 + select.toString(), select, "2"));
  490 +
  491 + if (rangeIncorretoTabeIndex(tabIndex))
  492 + occurrences.add(this.buildOccurrence("1.4", false,
  493 + select.toString(), select, "3"));
400 494 }
401   -
402   - for(Element textarea : this.getDocument().getAllElements("textarea")){
403   -
  495 +
  496 + for (Element textarea : this.getDocument().getAllElements("textarea")) {
  497 +
404 498 Attribute tabIndex = textarea.getAttributes().get("tabindex");
405   - if(tabIndex!=null)
406   - occurrences.add(this.buildOccurrence("1.4", false, textarea.toString(), textarea, "2"));
407   -
408   - if(rangeIncorretoTabeIndex(tabIndex))
409   - occurrences.add(this.buildOccurrence("1.4", false,textarea.toString(), textarea, "3"));
410   - }
411   -
412   - /*Element section = this.getDocument().getFirstElement("section");
413   -
414   - if(section !=null){
415   -
416   - int firstSectionRow = this.getRow(section);
417   - for(Element nav : this.getDocument().getAllElements("nav")){
418   - if(this.getRow(nav) < firstSectionRow)
419   - occurrences.add(this.buildOccurrence("1.4", false,nav.toString(), nav, "1"));
420   - }
421   - }*/
422   -
423   -
  499 + if (tabIndex != null)
  500 + occurrences.add(this.buildOccurrence("1.4", false,
  501 + textarea.toString(), textarea, "2"));
  502 +
  503 + if (rangeIncorretoTabeIndex(tabIndex))
  504 + occurrences.add(this.buildOccurrence("1.4", false,
  505 + textarea.toString(), textarea, "3"));
  506 + }
  507 +
  508 + /*
  509 + * Element section = this.getDocument().getFirstElement("section");
  510 + *
  511 + * if(section !=null){
  512 + *
  513 + * int firstSectionRow = this.getRow(section); for(Element nav :
  514 + * this.getDocument().getAllElements("nav")){ if(this.getRow(nav) <
  515 + * firstSectionRow) occurrences.add(this.buildOccurrence("1.4",
  516 + * false,nav.toString(), nav, "1")); } }
  517 + */
  518 +
424 519 List<Integer> verificadsos = new ArrayList<Integer>();
425   - for(Element nav : this.getDocument().getAllElements("nav")){
426   - if(nav !=null){
427   - int firstNavRow = this.getRow(nav);
428   -
429   - for(Element section : this.getDocument().getAllElements("section")){
430   -
431   - if(firstNavRow < this.getRow(section)){
432   - if(!verificadsos.contains(this.getRow(section))){
433   - occurrences.add(this.buildOccurrence("1.4", false,section.getStartTag().toString(), section, "1"));
  520 + for (Element nav : this.getDocument().getAllElements("nav")) {
  521 + if (nav != null) {
  522 + int firstNavRow = this.getRow(nav);
  523 +
  524 + for (Element section : this.getDocument().getAllElements(
  525 + "section")) {
  526 +
  527 + if (firstNavRow < this.getRow(section)) {
  528 + if (!verificadsos.contains(this.getRow(section))) {
  529 + occurrences.add(this.buildOccurrence("1.4", false,
  530 + section.getStartTag().toString(), section,
  531 + "1"));
434 532 verificadsos.add(this.getRow(section));
435   - }
436   -
437   - }
  533 + }
  534 +
  535 + }
438 536 }
439 537 }
440 538 }
441   -
442   -
443   -
444   -
  539 +
445 540 return occurrences;
446 541 }
447   -
  542 +
448 543 private boolean rangeIncorretoTabeIndex(Attribute tabIndex) {
449   - try{
450   - Integer value = Integer.valueOf(tabIndex.getValue() );
451   - if(value <0 || value > 32767)
  544 + try {
  545 + Integer value = Integer.valueOf(tabIndex.getValue());
  546 + if (value < 0 || value > 32767)
452 547 return true;
453   - }catch(Exception e){
  548 + } catch (Exception e) {
454 549 return false;
455 550 }
456   - return false ;
  551 + return false;
457 552 }
458   -
  553 +
459 554 private List<Occurrence> checkRecommendation5() {
460 555 List<Occurrence> occurrences = new ArrayList<Occurrence>();
461   -
462   - /*Element firstLink = getDocument().getFirstElement("href", Pattern.compile("#.*"));
463   -
464   - if(firstLink != null)
465   - occurrences.add(this.buildOccurrence("1.5", false, firstLink.toString(), firstLink, "4"));*/
466   -
  556 +
  557 + /*
  558 + * Element firstLink = getDocument().getFirstElement("href",
  559 + * Pattern.compile("#.*"));
  560 + *
  561 + * if(firstLink != null) occurrences.add(this.buildOccurrence("1.5",
  562 + * false, firstLink.toString(), firstLink, "4"));
  563 + */
  564 +
467 565 for (Element link : getDocument().getAllElements("a")) {
468 566 String contLink = link.getAttributeValue("href");
469   - if(contLink != null && contLink.length() > 1 && contLink.substring(0,1).equals("#")){
470   - occurrences.add(this.buildOccurrence("1.5", false, link.toString(), link, "4")); break;
471   - }
472   -
  567 + if (contLink != null && contLink.length() > 1
  568 + && contLink.substring(0, 1).equals("#")) {
  569 + occurrences.add(this.buildOccurrence("1.5", false,
  570 + link.toString(), link, "4"));
  571 + break;
  572 + }
  573 +
473 574 }
474   -
475   -
476   -
477   -
478   - /*if(firstLink == null){
479   - occurrences.add(this.buildOccurrence("1.5", false, getDocument().getFirstElement().toString(), getDocument().getFirstElement(), "4"));
480   - }
481   - else if(firstLink.getAttributeValue("href") == null || !firstLink.getAttributeValue("href").contains("#")){
482   - occurrences.add(this.buildOccurrence("1.5", false, firstLink.toString(), firstLink, "4"));
483   - }*/
484   -
485   -
  575 +
  576 + /*
  577 + * if(firstLink == null){ occurrences.add(this.buildOccurrence("1.5",
  578 + * false, getDocument().getFirstElement().toString(),
  579 + * getDocument().getFirstElement(), "4")); } else
  580 + * if(firstLink.getAttributeValue("href") == null ||
  581 + * !firstLink.getAttributeValue("href").contains("#")){
  582 + * occurrences.add(this.buildOccurrence("1.5", false,
  583 + * firstLink.toString(), firstLink, "4")); }
  584 + */
  585 +
486 586 boolean existAcessKey = false;
487   -
  587 +
488 588 for (Element area : getDocument().getAllElements("area")) {
489   - if(hasAcessKey(area))
490   - existAcessKey = true;
491   - /*if(!hasAcessKey(area))
492   - occurrences.add(this.buildOccurrence("1.5", true, area.toString(), area, "3"));*/
493   - }
494   -
495   - if(!existAcessKey)
496   - for (Element button : getDocument().getAllElements("button")) {
497   - if(hasAcessKey(button))
498   - existAcessKey = true;
499   - /*if(!hasAcessKey(button))
500   - occurrences.add(this.buildOccurrence("1.5", true, button.toString(), button, "3"));*/
501   - }
502   -
503   - if(!existAcessKey)
504   - for (Element input : getDocument().getAllElements("input")) {
505   - if(hasAcessKey(input))
506   - existAcessKey = true;
507   - /*if(!hasAcessKey(input))
508   - occurrences.add(this.buildOccurrence("1.5", true, input.toString(), input, "3"));*/
509   - }
510   -
511   - if(!existAcessKey)
512   - for (Element label : getDocument().getAllElements("label")) {
513   - if(hasAcessKey(label))
514   - existAcessKey = true;
515   - /*if(!hasAcessKey(label))
516   - occurrences.add(this.buildOccurrence("1.5", true, label.toString(), label, "3"));*/
517   - }
518   -
519   - if(!existAcessKey)
520   - for (Element legend : getDocument().getAllElements("legend")) {
521   - if(hasAcessKey(legend))
522   - existAcessKey = true;
523   - /*if(!hasAcessKey(legend))
524   - occurrences.add(this.buildOccurrence("1.5", true, legend.toString(), legend, "3"));*/
525   - }
526   -
527   - if(!existAcessKey)
528   - for (Element textarea : getDocument().getAllElements("textarea")) {
529   - if(hasAcessKey(textarea))
  589 + if (hasAcessKey(area))
530 590 existAcessKey = true;
531   - /*if(!hasAcessKey(textarea))
532   - occurrences.add(this.buildOccurrence("1.5", true, textarea.toString(), textarea, "3"));*/
  591 + /*
  592 + * if(!hasAcessKey(area))
  593 + * occurrences.add(this.buildOccurrence("1.5", true,
  594 + * area.toString(), area, "3"));
  595 + */
533 596 }
534   -
  597 +
  598 + if (!existAcessKey)
  599 + for (Element button : getDocument().getAllElements("button")) {
  600 + if (hasAcessKey(button))
  601 + existAcessKey = true;
  602 + /*
  603 + * if(!hasAcessKey(button))
  604 + * occurrences.add(this.buildOccurrence("1.5", true,
  605 + * button.toString(), button, "3"));
  606 + */
  607 + }
  608 +
  609 + if (!existAcessKey)
  610 + for (Element input : getDocument().getAllElements("input")) {
  611 + if (hasAcessKey(input))
  612 + existAcessKey = true;
  613 + /*
  614 + * if(!hasAcessKey(input))
  615 + * occurrences.add(this.buildOccurrence("1.5", true,
  616 + * input.toString(), input, "3"));
  617 + */
  618 + }
  619 +
  620 + if (!existAcessKey)
  621 + for (Element label : getDocument().getAllElements("label")) {
  622 + if (hasAcessKey(label))
  623 + existAcessKey = true;
  624 + /*
  625 + * if(!hasAcessKey(label))
  626 + * occurrences.add(this.buildOccurrence("1.5", true,
  627 + * label.toString(), label, "3"));
  628 + */
  629 + }
  630 +
  631 + if (!existAcessKey)
  632 + for (Element legend : getDocument().getAllElements("legend")) {
  633 + if (hasAcessKey(legend))
  634 + existAcessKey = true;
  635 + /*
  636 + * if(!hasAcessKey(legend))
  637 + * occurrences.add(this.buildOccurrence("1.5", true,
  638 + * legend.toString(), legend, "3"));
  639 + */
  640 + }
  641 +
  642 + if (!existAcessKey)
  643 + for (Element textarea : getDocument().getAllElements("textarea")) {
  644 + if (hasAcessKey(textarea))
  645 + existAcessKey = true;
  646 + /*
  647 + * if(!hasAcessKey(textarea))
  648 + * occurrences.add(this.buildOccurrence("1.5", true,
  649 + * textarea.toString(), textarea, "3"));
  650 + */
  651 + }
  652 +
535 653 String href;
536 654 boolean existAnchor = false;
537   -
538   -
  655 +
539 656 for (Element link : getDocument().getAllElements("a")) {
540 657 href = link.getAttributeValue("href");
541   -
542   - /*if(href != null && (href.length() > 1 && !href.substring(0,2).equals("?#"))){
543   - ///occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "2"));
544   - if(!(href.length()==1 && href.substring(1).equals("#")))
545   - if(href.substring(1).equals("#") && !this.hasLinkSemAncora(href))
546   - occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "2"));
547   - }*/
548   -
549   - if(href != null && href.length() > 1 && !href.substring(0,2).equals("?#")){
550   - if(href.substring(0,1).equals("#"))
551   - if(!this.hasLinkRefAncora(link))
552   - occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "2"));
  658 +
  659 + /*
  660 + * if(href != null && (href.length() > 1 &&
  661 + * !href.substring(0,2).equals("?#"))){
  662 + * ///occurrences.add(this.buildOccurrence("1.5", true,
  663 + * link.toString(), link, "2")); if(!(href.length()==1 &&
  664 + * href.substring(1).equals("#"))) if(href.substring(1).equals("#")
  665 + * && !this.hasLinkSemAncora(href))
  666 + * occurrences.add(this.buildOccurrence("1.5", true,
  667 + * link.toString(), link, "2")); }
  668 + */
  669 +
  670 + if (href != null && href.length() > 1
  671 + && !href.substring(0, 2).equals("?#")) {
  672 + if (href.substring(0, 1).equals("#"))
  673 + if (!this.hasLinkRefAncora(link))
  674 + occurrences.add(this.buildOccurrence("1.5", true,
  675 + link.toString(), link, "2"));
553 676 }
554   -
555   -
556   -
557   - /*if(href != null && href.contains("#"))
558   - if(!hasAnchor(href.substring(1)))
559   - occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "2"));*/
560   - /*}else{
561   - occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "1"));
562   - }*/
563   -
564   - //if(href != null && href.contains("#"))
565   -
566   - /*if(href != null && href.length() == 1 && href.toString().equals("#"))
567   - existAnchor = true;*/
568   - if(href != null && href.contains("#"))
569   - existAnchor = true;
570   -
571   - if(hasAcessKey(link))
  677 +
  678 + /*
  679 + * if(href != null && href.contains("#"))
  680 + * if(!hasAnchor(href.substring(1)))
  681 + * occurrences.add(this.buildOccurrence("1.5", true,
  682 + * link.toString(), link, "2"));
  683 + */
  684 + /*
  685 + * }else{ occurrences.add(this.buildOccurrence("1.5", true,
  686 + * link.toString(), link, "1")); }
  687 + */
  688 +
  689 + // if(href != null && href.contains("#"))
  690 +
  691 + /*
  692 + * if(href != null && href.length() == 1 &&
  693 + * href.toString().equals("#")) existAnchor = true;
  694 + */
  695 + if (href != null && href.contains("#"))
  696 + existAnchor = true;
  697 +
  698 + if (hasAcessKey(link))
572 699 existAcessKey = true;
573   -
574   - /*if(!hasAcessKey(link))
575   - occurrences.add(this.buildOccurrence("1.5", true, link.toString(), link, "3"));*/
576   - }
577   -
578   - if(!existAnchor)
579   - occurrences.add(this.buildOccurrence("1.5", true, "Observa&ccedil;&atilde;o - Sem fonte (n&atilde;o foram encontrados &acirc;ncoras que permitam saltar pelas diferentes se&ccedil;&otilde;es da p&aacute;gina)", getDocument().getFirstElement(), "1"));
580   -
581   - if(!existAcessKey)
582   - occurrences.add(this.buildOccurrence("1.5", true, "Observa&ccedil;&atilde;o - Sem fonte ( n&atilde;o existe(m) accesskey(s) na página)", getDocument().getFirstElement(), "3"));
583   -
584   - for (Element elemento : getDocument().getAllElements("accesskey", Pattern.compile(".*"))) {
585   - if(duplicatedAcessKey(elemento))
586   - occurrences.add(this.buildOccurrence("1.5", false, elemento.toString(), elemento,"5"));
587   - }
588   -
  700 +
  701 + /*
  702 + * if(!hasAcessKey(link))
  703 + * occurrences.add(this.buildOccurrence("1.5", true,
  704 + * link.toString(), link, "3"));
  705 + */
  706 + }
  707 +
  708 + if (!existAnchor)
  709 + occurrences
  710 + .add(this
  711 + .buildOccurrence(
  712 + "1.5",
  713 + true,
  714 + "Observa&ccedil;&atilde;o - Sem fonte (n&atilde;o foram encontrados &acirc;ncoras que permitam saltar pelas diferentes se&ccedil;&otilde;es da p&aacute;gina)",
  715 + getDocument().getFirstElement(), "1"));
  716 +
  717 + if (!existAcessKey)
  718 + occurrences
  719 + .add(this
  720 + .buildOccurrence(
  721 + "1.5",
  722 + true,
  723 + "Observa&ccedil;&atilde;o - Sem fonte ( n&atilde;o existe(m) accesskey(s) na página)",
  724 + getDocument().getFirstElement(), "3"));
  725 +
  726 + for (Element elemento : getDocument().getAllElements("accesskey",
  727 + Pattern.compile(".*"))) {
  728 + if (duplicatedAcessKey(elemento))
  729 + occurrences.add(this.buildOccurrence("1.5", false,
  730 + elemento.toString(), elemento, "5"));
  731 + }
  732 +
589 733 this.oder(occurrences);
590   -
  734 +
591 735 return occurrences;
592 736 }
593   -
  737 +
594 738 private boolean hasLinkRefAncora(Element link) {
595 739 boolean existeAncora = false;
596 740 String href = link.getAttributeValue("href");
597 741 String ancora = href.substring(1, href.length());
598   -
599   - for (Element a : getDocument().getAllElements("a")){
600   - if(a.getAttributeValue("name") != null && a.getAttributeValue("name").equals(ancora)){
601   - existeAncora = true;
602   - }
603   - }
604   -
  742 +
  743 + for (Element a : getDocument().getAllElements()) {
  744 + if (a.getAttributeValue("id") != null
  745 + && a.getAttributeValue("id").equals(ancora)) {
  746 + existeAncora = true;
  747 + }
  748 + if (a.getAttributeValue("name") != null
  749 + && a.getAttributeValue("name").equals(ancora)) {
  750 + existeAncora = true;
  751 + }
  752 + }
  753 +
605 754 return existeAncora;
606 755 }
607   -
  756 +
608 757 private boolean hasAcessKey(Element element) {
609 758 String acessKey = element.getAttributeValue("accesskey");
610   -
  759 +
611 760 return StringUtils.isNotBlank(acessKey);
612 761 }
  762 +
613 763 private boolean hasAnchor(String href) {
614   -
615   - String id,name;
616   -
  764 +
  765 + String id, name;
  766 +
617 767 for (Element element : getDocument().getAllElements()) {
618 768 id = element.getAttributeValue("id");
619 769 name = element.getAttributeValue("name");
620   -
621   - if(href.equals(id) || href.equals(name))
  770 +
  771 + if (href.equals(id) || href.equals(name))
622 772 return true;
623 773 }
624   -
  774 +
625 775 return false;
626 776 }
627   -
628   - private boolean duplicatedAcessKey(Element element){
  777 +
  778 + private boolean duplicatedAcessKey(Element element) {
629 779 String value = element.getAttributeValue("accesskey");
630   -
631   - for (Element elementToCompare : getDocument().getAllElements("accesskey", Pattern.compile(".*"))) {
  780 +
  781 + for (Element elementToCompare : getDocument().getAllElements(
  782 + "accesskey", Pattern.compile(".*"))) {
632 783 String acessKey = elementToCompare.getAttributeValue("accesskey");
633   - if(acessKey.equals(value) && elementToCompare.getBegin() != element.getBegin())
  784 + if (acessKey.equals(value)
  785 + && elementToCompare.getBegin() != element.getBegin())
634 786 return true;
635   -
  787 +
636 788 }
637   -
  789 +
638 790 return false;
639 791 }
640   -
  792 +
641 793 public List<Occurrence> checkRecommendation6() {
642 794 List<Occurrence> occurrences = new ArrayList<Occurrence>();
643   -
  795 +
644 796 for (Element table : getDocument().getAllElements("table"))
645   - occurrences.add(this.buildOccurrence("1.6", false, table.getStartTag().toString(), table, "1"));
646   -
647   -
  797 + occurrences.add(this.buildOccurrence("1.6", false, table
  798 + .getStartTag().toString(), table, "1"));
  799 +
648 800 int firstFormRow = 0;
649   -
  801 +
650 802 List<Integer> linhasOcorrForm = new ArrayList<Integer>();
651   -
652   - for (Element table : getDocument().getAllElements("table")){
653   - //Element tagsForm = table.getFirstElement("form");
654   -
  803 +
  804 + for (Element table : getDocument().getAllElements("table")) {
  805 + // Element tagsForm = table.getFirstElement("form");
  806 +
655 807 Element form = table.getContent().getFirstElement("form");
656   -
657   - if(form != null){
658   - firstFormRow = this.getRow(form);
659   - if(!linhasOcorrForm.contains(firstFormRow)){
660   - occurrences.add(this.buildOccurrence("1.6", true, form.getStartTag().toString(), form, "2"));
661   - linhasOcorrForm.add(firstFormRow);
662   - }
  808 +
  809 + if (form != null) {
  810 + firstFormRow = this.getRow(form);
  811 + if (!linhasOcorrForm.contains(firstFormRow)) {
  812 + occurrences.add(this.buildOccurrence("1.6", true, form
  813 + .getStartTag().toString(), form, "2"));
  814 + linhasOcorrForm.add(firstFormRow);
  815 + }
663 816 }
664   -
  817 +
665 818 }
666   -
  819 +
667 820 return occurrences;
668 821 }
669   -
670   -
  822 +
671 823 public List<Occurrence> checkRecommendation7() {
672 824 List<Occurrence> occurrences = new ArrayList<Occurrence>();
673 825 List<Element> element = getDocument().getAllElements();
674   -
  826 +
675 827 int pos = 1;
676 828 int end = 0;
677 829 int begin = 0;
678 830 Element firstElement = null;
679 831 Element secondElement = null;
680   - for (int i = 0; i < element.size() -1 ; i++) {
  832 + for (int i = 0; i < element.size() - 1; i++) {
681 833 firstElement = element.get(i);
682 834 secondElement = element.get(pos);
683   - if(firstElement.getEndTag() != null && firstElement.getName().equals("a"))
684   - end = firstElement.getEndTag().getEnd();
685   - begin = secondElement.getStartTag().getBegin();
686   - if(element.get(i).getName().equals(element.get(pos).getName()) && (end == begin) ){
687   - occurrences.add(this.buildOccurrence("1.7", true, element.get(i).toString()+" "+element.get(pos).toString(), element.get(i), "1"));
688   - }
  835 + if (firstElement.getEndTag() != null
  836 + && firstElement.getName().equals("a"))
  837 + end = firstElement.getEndTag().getEnd();
  838 + begin = secondElement.getStartTag().getBegin();
  839 + if (element.get(i).getName().equals(element.get(pos).getName())
  840 + && (end == begin)) {
  841 + occurrences.add(this.buildOccurrence("1.7", true, element
  842 + .get(i).toString() + " " + element.get(pos).toString(),
  843 + element.get(i), "1"));
  844 + }
689 845 pos++;
690 846 }
691   -
  847 +
692 848 return occurrences;
693 849 }
694   -
  850 +
695 851 public List<Occurrence> checkRecommendation8() {
696 852 List<Occurrence> occurrences = new ArrayList<Occurrence>();
697 853 Element firstElement = this.getDocument().getFirstElement();
698   -
699   - if(firstElement.toString().equals("<!DOCTYPE html>")){
700   -
  854 +
  855 + if (firstElement.toString().equals("<!DOCTYPE html>")) {
  856 +
701 857 Element header = getDocument().getFirstElement("header");
702 858 Element nav = getDocument().getFirstElement("nav");
703 859 Element section = getDocument().getFirstElement("section");
704 860 Element footer = getDocument().getFirstElement("footer");
705   -
706   - if(header == null)
707   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <HEADER>)", getDocument().getFirstElement(),"1"));
708   -
709   - if(nav == null)
710   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <NAV>)", getDocument().getFirstElement(),"1"));
711   -
712   - if(section == null)
713   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <SECTION>)", getDocument().getFirstElement(),"1"));
714   -
715   - if(footer == null)
716   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <FOOTER>)", getDocument().getFirstElement(),"1"));
717   -
718   - }else{
719   -
  861 +
  862 + if (header == null)
  863 + occurrences
  864 + .add(this
  865 + .buildOccurrence(
  866 + "1.8",
  867 + false,
  868 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <HEADER>)",
  869 + getDocument().getFirstElement(), "1"));
  870 +
  871 + if (nav == null)
  872 + occurrences
  873 + .add(this
  874 + .buildOccurrence(
  875 + "1.8",
  876 + false,
  877 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <NAV>)",
  878 + getDocument().getFirstElement(), "1"));
  879 +
  880 + if (section == null)
  881 + occurrences
  882 + .add(this
  883 + .buildOccurrence(
  884 + "1.8",
  885 + false,
  886 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <SECTION>)",
  887 + getDocument().getFirstElement(), "1"));
  888 +
  889 + if (footer == null)
  890 + occurrences
  891 + .add(this
  892 + .buildOccurrence(
  893 + "1.8",
  894 + false,
  895 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag <FOOTER>)",
  896 + getDocument().getFirstElement(), "1"));
  897 +
  898 + } else {
  899 +
720 900 boolean hasBanner = false;
721 901 boolean hasNavigation = false;
722 902 boolean hasMain = false;
723   - for (Element element : getDocument().getAllElements()){
  903 + for (Element element : getDocument().getAllElements()) {
724 904 String role = element.getAttributeValue("role");
725   -
726   - if(role!=null && "banner".equals(role.toLowerCase()))
  905 +
  906 + if (role != null && "banner".equals(role.toLowerCase()))
727 907 hasBanner = true;
728   -
729   - if(role!=null && "navigation".equals(role.toLowerCase()))
  908 +
  909 + if (role != null && "navigation".equals(role.toLowerCase()))
730 910 hasNavigation = true;
731   -
732   - if(role!=null && "main".equals(role.toLowerCase()))
  911 +
  912 + if (role != null && "main".equals(role.toLowerCase()))
733 913 hasMain = true;
734   -
735   - if(hasBanner && hasNavigation && hasMain)
  914 +
  915 + if (hasBanner && hasNavigation && hasMain)
736 916 break;
737 917 }
738   -
739   - if(!hasBanner)
740   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do BANNER)", getDocument().getFirstElement(),"2"));
741   -
742   - if(!hasNavigation)
743   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do NAVIGATION)", getDocument().getFirstElement(),"2"));
744   -
745   - if(!hasMain)
746   - occurrences.add(this.buildOccurrence("1.8", false, "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do MAIN)", getDocument().getFirstElement(),"2"));
747   -
  918 +
  919 + if (!hasBanner)
  920 + occurrences
  921 + .add(this
  922 + .buildOccurrence(
  923 + "1.8",
  924 + false,
  925 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do BANNER)",
  926 + getDocument().getFirstElement(), "2"));
  927 +
  928 + if (!hasNavigation)
  929 + occurrences
  930 + .add(this
  931 + .buildOccurrence(
  932 + "1.8",
  933 + false,
  934 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do NAVIGATION)",
  935 + getDocument().getFirstElement(), "2"));
  936 +
  937 + if (!hasMain)
  938 + occurrences
  939 + .add(this
  940 + .buildOccurrence(
  941 + "1.8",
  942 + false,
  943 + "Observa&ccedil;&atilde;o - Sem fonte (N&atilde;o existe tag com atributo ROLE e conte&uacute;do MAIN)",
  944 + getDocument().getFirstElement(), "2"));
  945 +
748 946 }
749   -
  947 +
750 948 return occurrences;
751 949 }
752   -
  950 +
753 951 public List<Occurrence> checkRecommendation9() {
754 952 List<Occurrence> occurrences = new ArrayList<Occurrence>();
755 953 boolean hasBlankLink = false;
756   -
  954 +
757 955 for (Element link : getDocument().getAllElements("a")) {
758   -
759   - if(link.toString().contains("_blank")){
  956 +
  957 + if (link.toString().contains("_blank")) {
760 958 hasBlankLink = true;
761   - occurrences.add(this.buildOccurrence("1.9", false, link.toString(), link, "1"));
  959 + occurrences.add(this.buildOccurrence("1.9", false,
  960 + link.toString(), link, "1"));
762 961 }
763 962 }
764   -
765   - /*if(!hasBlankLink)
766   - occurrences.add(new Occurrence("1.9", false,this.getDocument().getFirstElement().toString(),OccurrenceClassification.MARK));*/
767   -
  963 +
  964 + /*
  965 + * if(!hasBlankLink) occurrences.add(new Occurrence("1.9",
  966 + * false,this.getDocument
  967 + * ().getFirstElement().toString(),OccurrenceClassification.MARK));
  968 + */
  969 +
768 970 return occurrences;
769 971 }
770   -
771   - private List<Occurrence> oder(List occurrences){
772   - //Sorting
  972 +
  973 + private List<Occurrence> oder(List occurrences) {
  974 + // Sorting
773 975 Collections.sort(occurrences, new Comparator<Occurrence>() {
774   - public int compare(Occurrence occurrence1, Occurrence occurrence2){
775   - return occurrence1.getLine().compareTo(occurrence2.getLine());
776   - }
777   - });
  976 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  977 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  978 + }
  979 + });
778 980 return occurrences;
779 981 }
780   -
781   - private Occurrence buildOccurrence(String code, boolean error,
782   - String tag, Element element,
783   - String criterio) {
784   - return super.buildOccurrence(code, error, tag, element, OccurrenceClassification.MARK,criterio);
  982 +
  983 + private Occurrence buildOccurrence(String code, boolean error, String tag,
  984 + Element element, String criterio) {
  985 + return super.buildOccurrence(code, error, tag, element,
  986 + OccurrenceClassification.MARK, criterio);
785 987 }
786   -
787   - public int[] getErrorCount(boolean isCss,String url){
  988 +
  989 + public int[] getErrorCount(boolean isCss, String url) {
788 990 int errors = 0;
789 991 int warnings = 0;
790   -
791   - try{
792   - if(isCss){
793   - String content = WebAgent.from(CSS_VALIDATOR_URL.replace("#{url}", url)).withGetRequest().execute().getContent();
794   - Matcher m = Pattern.compile("<m:errorcount>(\\d)*</m:errorcount>",Pattern.MULTILINE).matcher(content);
795   - if(m.find())
796   - errors = Integer.valueOf(m.group(0).replace("<m:errorcount>", "").replace("</m:errorcount>", ""));
797   -
798   - m = Pattern.compile("<m:warningcount>(\\d)*</m:warningcount>",Pattern.MULTILINE).matcher(content);
799   -
800   - if(m.find())
801   - warnings = Integer.valueOf(m.group(0).replace("<m:warningcount>", "").replace("</m:warningcount>", ""));
802   -
803   - }else{
804   -
805   - String content = WebAgent.from(HTML_VALIDATOR_URL.replace("#{url}", url)).withGetRequest().execute().getContent();
  992 +
  993 + try {
  994 + if (isCss) {
  995 + String content = WebAgent
  996 + .from(CSS_VALIDATOR_URL.replace("#{url}", url))
  997 + .withGetRequest().execute().getContent();
  998 + Matcher m = Pattern.compile(
  999 + "<m:errorcount>(\\d)*</m:errorcount>",
  1000 + Pattern.MULTILINE).matcher(content);
  1001 + if (m.find())
  1002 + errors = Integer.valueOf(m.group(0)
  1003 + .replace("<m:errorcount>", "")
  1004 + .replace("</m:errorcount>", ""));
  1005 +
  1006 + m = Pattern.compile("<m:warningcount>(\\d)*</m:warningcount>",
  1007 + Pattern.MULTILINE).matcher(content);
  1008 +
  1009 + if (m.find())
  1010 + warnings = Integer.valueOf(m.group(0)
  1011 + .replace("<m:warningcount>", "")
  1012 + .replace("</m:warningcount>", ""));
  1013 +
  1014 + } else {
  1015 +
  1016 + String content = WebAgent
  1017 + .from(HTML_VALIDATOR_URL.replace("#{url}", url))
  1018 + .withGetRequest().execute().getContent();
806 1019 Gson g = new GsonBuilder().create();
807   - HtmlValidation a = g.fromJson(content, HtmlValidation.class);
  1020 + HtmlValidation a = g.fromJson(content, HtmlValidation.class);
808 1021 int[] errorsWarnings = a.getQtdWarningsErros();
809 1022 errors = errorsWarnings[1];
810 1023 warnings = errorsWarnings[0];
811   -
  1024 +
812 1025 }
813   - }catch(Exception e){
  1026 + } catch (Exception e) {
814 1027 e.printStackTrace();
815 1028 }
816   -
817   - return new int[]{errors,warnings};
  1029 +
  1030 + return new int[] { errors, warnings };
818 1031 }
819   -
820   - public OccurrenceClassification type () { return OccurrenceClassification.MARK;}
821   -
  1032 +
  1033 + public OccurrenceClassification type() {
  1034 + return OccurrenceClassification.MARK;
  1035 + }
  1036 +
822 1037 public class HtmlValidation {
823 1038  
824 1039 List<Message> messages = new ArrayList<HtmlValidation.Message>();
825   -
826   -
  1040 +
827 1041 public List<Message> getMessages() {
828 1042 return messages;
829 1043 }
830   -
  1044 +
831 1045 public void setMessages(List<Message> messages) {
832 1046 this.messages = messages;
833 1047 }
834   -
835   - public int[] getQtdWarningsErros(){
836   - int warnings=0;
  1048 +
  1049 + public int[] getQtdWarningsErros() {
  1050 + int warnings = 0;
837 1051 int erros = 0;
838   - for(Message message: this.messages ){
839   - if(message.isError())
  1052 + for (Message message : this.messages) {
  1053 + if (message.isError())
840 1054 erros++;
841 1055 else if (message.isWarning())
842 1056 warnings++;
843 1057 }
844   -
845   - return new int[]{warnings,erros};
  1058 +
  1059 + return new int[] { warnings, erros };
846 1060 }
847   -
848   - public HtmlValidation(){}
849   -
850   - public class Message{
851   -
  1061 +
  1062 + public HtmlValidation() {
  1063 + }
  1064 +
  1065 + public class Message {
  1066 +
852 1067 private String type;
853   -
  1068 +
854 1069 private String subType;
855   -
856   - public String getType() { return type; }
857   -
858   - public void setType(String type) { this.type = type; }
859   -
860   - public String getSubType() { return subType; }
861   -
862   - public void setSubType(String subType) { this.subType = subType; }
863   -
864   - public boolean isWarning(){ return "info".equals(type) && "warning".equals(this.subType); }
865   -
866   - public boolean isError(){ return "error".equals(this.type);}
867   -
  1070 +
  1071 + public String getType() {
  1072 + return type;
  1073 + }
  1074 +
  1075 + public void setType(String type) {
  1076 + this.type = type;
  1077 + }
  1078 +
  1079 + public String getSubType() {
  1080 + return subType;
  1081 + }
  1082 +
  1083 + public void setSubType(String subType) {
  1084 + this.subType = subType;
  1085 + }
  1086 +
  1087 + public boolean isWarning() {
  1088 + return "info".equals(type) && "warning".equals(this.subType);
  1089 + }
  1090 +
  1091 + public boolean isError() {
  1092 + return "error".equals(this.type);
  1093 + }
  1094 +
868 1095 }
869 1096 }
870   -
  1097 +
871 1098 }
... ...
target/classes/br/com/checker/emag/Occurrence.class
No preview for this file type
target/classes/br/com/checker/emag/OccurrenceClassification.class
No preview for this file type
target/classes/br/com/checker/emag/SummarizedOccurrence$Builder.class
No preview for this file type
target/classes/br/com/checker/emag/SummarizedOccurrence.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation$BehaviorEvaluationBuilder.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation$EvaluationRecommendation10.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation$EvaluationRecommendation11.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation$EvaluationRecommendation12.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation$EvaluationRecommendation13.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation$EvaluationRecommendation14.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation$EvaluationRecommendation15.class
No preview for this file type
target/classes/br/com/checker/emag/core/BehaviorEvaluation.class
No preview for this file type
target/classes/br/com/checker/emag/core/Checker$OccurrenceKey.class
No preview for this file type
target/classes/br/com/checker/emag/core/Checker.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$ContentEvaluationBuilder.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation16.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation17.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation18.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation19.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation20.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation21.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation22.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation23.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation24.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation25.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation26.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation$EvaluationRecommendation27.class
No preview for this file type
target/classes/br/com/checker/emag/core/ContentEvaluation.class
No preview for this file type
target/classes/br/com/checker/emag/core/Evaluation$EvaluationBuilder.class
No preview for this file type
target/classes/br/com/checker/emag/core/Evaluation.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation38.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation39.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation40.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation41.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation42.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation43.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation44.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$EvaluationRecommendation45.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation$FormEvaluationBuilder.class
No preview for this file type
target/classes/br/com/checker/emag/core/FormEvaluation.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation1.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation2.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation3.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation4.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation5.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation6.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation7.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation8.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$EvaluationRecommendation9.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation$MarkEvaluationBuilder.class
No preview for this file type
target/classes/br/com/checker/emag/core/MarkEvaluation.class
No preview for this file type
target/classes/br/com/checker/emag/core/MultimediaEvaluation$EvaluationRecommendation33.class
No preview for this file type
target/classes/br/com/checker/emag/core/MultimediaEvaluation$EvaluationRecommendation34.class
No preview for this file type
target/classes/br/com/checker/emag/core/MultimediaEvaluation$EvaluationRecommendation35.class
No preview for this file type
target/classes/br/com/checker/emag/core/MultimediaEvaluation$EvaluationRecommendation36.class
No preview for this file type
target/classes/br/com/checker/emag/core/MultimediaEvaluation$EvaluationRecommendation37.class
No preview for this file type
target/classes/br/com/checker/emag/core/MultimediaEvaluation$MultimediaEvaluationBuilder.class
No preview for this file type
target/classes/br/com/checker/emag/core/MultimediaEvaluation.class
No preview for this file type
target/classes/br/com/checker/emag/core/PresentationEvaluation$EvaluationRecommendation28.class
No preview for this file type
target/classes/br/com/checker/emag/core/PresentationEvaluation$EvaluationRecommendation29.class
No preview for this file type
target/classes/br/com/checker/emag/core/PresentationEvaluation$EvaluationRecommendation30.class
No preview for this file type
target/classes/br/com/checker/emag/core/PresentationEvaluation$EvaluationRecommendation31.class
No preview for this file type
target/classes/br/com/checker/emag/core/PresentationEvaluation$EvaluationRecommendation32.class
No preview for this file type
target/classes/br/com/checker/emag/core/PresentationEvaluation$PresentationEvaluationBuilder.class
No preview for this file type
target/classes/br/com/checker/emag/core/PresentationEvaluation.class
No preview for this file type
target/classes/br/com/checker/emag/core/SpecificRecommendation$BehaviorRecommendation.class
No preview for this file type
target/classes/br/com/checker/emag/core/SpecificRecommendation$ContentRecommendation.class
No preview for this file type
target/classes/br/com/checker/emag/core/SpecificRecommendation$FormRecommendation.class
No preview for this file type
target/classes/br/com/checker/emag/core/SpecificRecommendation$MarkRecommendation.class
No preview for this file type
target/classes/br/com/checker/emag/core/SpecificRecommendation$MultimediaRecommendation.class
No preview for this file type
target/classes/br/com/checker/emag/core/SpecificRecommendation$PresentationRecommendation.class
No preview for this file type
target/classes/br/com/checker/emag/core/SpecificRecommendation.class
No preview for this file type
target/classes/br/com/checker/emag/xml/AvaliationReport.class
No preview for this file type
target/classes/br/com/checker/emag/xml/CheckPoint.class
No preview for this file type
target/classes/br/com/checker/emag/xml/Result.class
No preview for this file type
target/test-classes/br/com/checker/emag/BehaviorEvaluationTest.class
No preview for this file type
target/test-classes/br/com/checker/emag/ContentEvaluationTest.class
No preview for this file type
target/test-classes/br/com/checker/emag/FormEvaluationTest.class
No preview for this file type
target/test-classes/br/com/checker/emag/MarkEvaluationTest.class
No preview for this file type
target/test-classes/br/com/checker/emag/MultimediaEvaluationTest.class
No preview for this file type
target/test-classes/br/com/checker/emag/PresentationEvaluationTest.class
No preview for this file type