Commit 0b556559a40d9ff6b6330ff61f98a26ef38c0636
1 parent
3aa2b209
Exists in
master
and in
1 other branch
git-svn-id: https://svn.bento.ifrs.edu.br/default/ASES/ASES%20-%20Web/ASES%20-%2…
…0Web/Fontes/avaliador-web@10512 c2178572-b5ca-4887-91d2-9e3a90c7d55b
Showing
6 changed files
with
164 additions
and
4 deletions
Show diff stats
src/main/java/br/com/ases/business/AvaliacaoBusiness.java
@@ -16,4 +16,5 @@ public interface AvaliacaoBusiness { | @@ -16,4 +16,5 @@ public interface AvaliacaoBusiness { | ||
16 | Nota obterNota(List<SummarizedOccurrence> occurrences,String url); | 16 | Nota obterNota(List<SummarizedOccurrence> occurrences,String url); |
17 | Map<OccurrenceKey,Map<String,List<Occurrence>>> retornarCriterios(Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao); | 17 | Map<OccurrenceKey,Map<String,List<Occurrence>>> retornarCriterios(Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao); |
18 | void initEseloProperties(ServletContext servletContext); | 18 | void initEseloProperties(ServletContext servletContext); |
19 | + public int[] getErrorCount(boolean isCss,String url); | ||
19 | } | 20 | } |
src/main/java/br/com/ases/business/impl/AvaliacaoBusinessImpl.java
1 | package br.com.ases.business.impl; | 1 | package br.com.ases.business.impl; |
2 | 2 | ||
3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4 | +import java.util.Collection; | ||
4 | import java.util.Date; | 5 | import java.util.Date; |
5 | import java.util.HashMap; | 6 | import java.util.HashMap; |
6 | import java.util.List; | 7 | import java.util.List; |
7 | import java.util.Map; | 8 | import java.util.Map; |
8 | import java.util.Map.Entry; | 9 | import java.util.Map.Entry; |
9 | import java.util.TreeSet; | 10 | import java.util.TreeSet; |
11 | +import java.util.regex.Matcher; | ||
12 | +import java.util.regex.Pattern; | ||
10 | 13 | ||
11 | import javax.servlet.ServletContext; | 14 | import javax.servlet.ServletContext; |
12 | 15 | ||
13 | import br.com.ases.business.AvaliacaoBusiness; | 16 | import br.com.ases.business.AvaliacaoBusiness; |
14 | import br.com.ases.controller.EseloController; | 17 | import br.com.ases.controller.EseloController; |
15 | import br.com.ases.controller.EseloController.Nota; | 18 | import br.com.ases.controller.EseloController.Nota; |
19 | +import br.com.ases.domain.HtmlValidation; | ||
16 | import br.com.ases.domain.OccurrenceKey; | 20 | import br.com.ases.domain.OccurrenceKey; |
17 | import br.com.ases.infra.EseloProperties; | 21 | import br.com.ases.infra.EseloProperties; |
18 | import br.com.ases.infra.WebChecker; | 22 | import br.com.ases.infra.WebChecker; |
@@ -23,13 +27,16 @@ import br.com.checker.emag.SummarizedOccurrence; | @@ -23,13 +27,16 @@ import br.com.checker.emag.SummarizedOccurrence; | ||
23 | 27 | ||
24 | import com.google.gson.Gson; | 28 | import com.google.gson.Gson; |
25 | import com.google.gson.GsonBuilder; | 29 | import com.google.gson.GsonBuilder; |
30 | +import com.google.gson.reflect.TypeToken; | ||
26 | 31 | ||
27 | 32 | ||
28 | @Component | 33 | @Component |
29 | public class AvaliacaoBusinessImpl implements AvaliacaoBusiness{ | 34 | public class AvaliacaoBusinessImpl implements AvaliacaoBusiness{ |
30 | EseloProperties eseloProperties = null; | 35 | EseloProperties eseloProperties = null; |
31 | 36 | ||
32 | - //private static final String CALCULAR_NOTA_REST = "https://sistemas-treinamento.ifbaiano.edu.br/eselo/calcular-nota"; | 37 | + |
38 | + private static String CSS_VALIDATOR_URL = "http://www.css-validator.org/validator?uri=#{url}&warning=0&output=soap12"; | ||
39 | + private static String HTML_VALIDATOR_URL = "https://validator.w3.org/nu/?doc=#{url}&out=json"; | ||
33 | 40 | ||
34 | public Nota obterNota(List<SummarizedOccurrence> occurrences,String url) { | 41 | public Nota obterNota(List<SummarizedOccurrence> occurrences,String url) { |
35 | Nota nota = null; | 42 | Nota nota = null; |
@@ -165,6 +172,46 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness{ | @@ -165,6 +172,46 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness{ | ||
165 | return map; | 172 | return map; |
166 | } | 173 | } |
167 | 174 | ||
175 | + public int[] getErrorCount(boolean isCss,String url){ | ||
176 | + int errors = 0; | ||
177 | + int warnings = 0; | ||
178 | + | ||
179 | + try{ | ||
180 | + if(isCss){ | ||
181 | + String content = WebChecker.from(CSS_VALIDATOR_URL.replace("#{url}", url)).withGetRequest().execute().getContent(); | ||
182 | + Matcher m = Pattern.compile("<m:errorcount>(\\d)*</m:errorcount>",Pattern.MULTILINE).matcher(content); | ||
183 | + if(m.find()) | ||
184 | + errors = Integer.valueOf(m.group(0).replace("<m:errorcount>", "").replace("</m:errorcount>", "")); | ||
185 | + | ||
186 | + m = Pattern.compile("<m:warningcount>(\\d)*</m:warningcount>",Pattern.MULTILINE).matcher(content); | ||
187 | + | ||
188 | + if(m.find()) | ||
189 | + warnings = Integer.valueOf(m.group(0).replace("<m:warningcount>", "").replace("</m:warningcount>", "")); | ||
190 | + | ||
191 | + }else{ | ||
192 | + | ||
193 | + String content = WebChecker.from(HTML_VALIDATOR_URL.replace("#{url}", url)).withGetRequest().execute().getContent(); | ||
194 | + Gson g = new GsonBuilder().create(); | ||
195 | + HtmlValidation a = g.fromJson(content, HtmlValidation.class); | ||
196 | + int[] errorsWarnings = a.getQtdWarningsErros(); | ||
197 | + errors = errorsWarnings[1]; | ||
198 | + warnings = errorsWarnings[0]; | ||
199 | + | ||
200 | + } | ||
201 | + }catch(Exception e){ | ||
202 | + e.printStackTrace(); | ||
203 | + } | ||
204 | + | ||
205 | + return new int[]{errors,warnings}; | ||
206 | + } | ||
207 | + | ||
208 | + public static void main(String ...arg) { | ||
209 | + int[] teste = new AvaliacaoBusinessImpl().getErrorCount(false, "http://www.agritempo.gov.br/agritempo/index.jsp"); | ||
210 | + | ||
211 | + System.out.println("errors :" +teste[0]); | ||
212 | + System.out.println("warnings :" +teste[1]); | ||
213 | + } | ||
214 | + | ||
168 | public static Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao = new HashMap<OccurrenceClassification, List<Occurrence>>(); | 215 | public static Map<OccurrenceClassification,List<Occurrence>> resultadoAvaliacao = new HashMap<OccurrenceClassification, List<Occurrence>>(); |
169 | 216 | ||
170 | static { | 217 | static { |
src/main/java/br/com/ases/controller/AvaliacaoController.java
@@ -170,6 +170,8 @@ public class AvaliacaoController { | @@ -170,6 +170,8 @@ public class AvaliacaoController { | ||
170 | if(url.startsWith("www")) url="http://"+url; | 170 | if(url.startsWith("www")) url="http://"+url; |
171 | 171 | ||
172 | WebChecker pagina = WebChecker.from(url).withGetRequest().execute(); | 172 | WebChecker pagina = WebChecker.from(url).withGetRequest().execute(); |
173 | + int[] errorsWarningsCss = avaliacaoBusiness.getErrorCount(true,url); | ||
174 | + int[] errorsWarningsHtml = avaliacaoBusiness.getErrorCount(false,url); | ||
173 | 175 | ||
174 | Checker checker = from(pagina.getContent(),url); | 176 | Checker checker = from(pagina.getContent(),url); |
175 | 177 | ||
@@ -193,7 +195,7 @@ public class AvaliacaoController { | @@ -193,7 +195,7 @@ public class AvaliacaoController { | ||
193 | result.include("nota",nota); | 195 | result.include("nota",nota); |
194 | this.sumarizarResultasNoResponse(checker.checkSumarized(), result); | 196 | this.sumarizarResultasNoResponse(checker.checkSumarized(), result); |
195 | 197 | ||
196 | - this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check())); | 198 | + this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()),errorsWarningsCss,errorsWarningsHtml); |
197 | VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("resultadoAvaliacao", checker.checkSumarized()); | 199 | VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("resultadoAvaliacao", checker.checkSumarized()); |
198 | VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("urlAvaliada", url); | 200 | VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("urlAvaliada", url); |
199 | VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("contentLenght", pagina.getContentLength()); | 201 | VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("contentLenght", pagina.getContentLength()); |
@@ -415,6 +417,14 @@ public class AvaliacaoController { | @@ -415,6 +417,14 @@ public class AvaliacaoController { | ||
415 | result.include("detalhe",this.detalheAvaliacao.get(rn, type)); | 417 | result.include("detalhe",this.detalheAvaliacao.get(rn, type)); |
416 | result.include("listOcorrencia",listOcorrencias); | 418 | result.include("listOcorrencia",listOcorrencias); |
417 | result.include("isError",type); | 419 | result.include("isError",type); |
420 | + if(type){ | ||
421 | + result.include("qtdOcorrenciasCss",this.detalheAvaliacao.getErrorsCss()); | ||
422 | + result.include("qtdOcorrenciasHtml",this.detalheAvaliacao.getErrorsHtml()); | ||
423 | + }else{ | ||
424 | + result.include("qtdOcorrenciasCss",this.detalheAvaliacao.getWarningsCss()); | ||
425 | + result.include("qtdOcorrenciasHtml",this.detalheAvaliacao.getWarningsHtml()); | ||
426 | + } | ||
427 | + | ||
418 | 428 | ||
419 | List<SummarizedOccurrence> ob = (List<SummarizedOccurrence>) VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("resultadoAvaliacao"); | 429 | List<SummarizedOccurrence> ob = (List<SummarizedOccurrence>) VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("resultadoAvaliacao"); |
420 | String recomendacao = ""; | 430 | String recomendacao = ""; |
src/main/java/br/com/ases/domain/DetalheAvaliacao.java
@@ -22,6 +22,8 @@ public class DetalheAvaliacao { | @@ -22,6 +22,8 @@ public class DetalheAvaliacao { | ||
22 | 22 | ||
23 | private CriterioProperties criterioProperties; | 23 | private CriterioProperties criterioProperties; |
24 | private Map<OccurrenceKey,Map<String,List<Occurrence>>> detalhes; | 24 | private Map<OccurrenceKey,Map<String,List<Occurrence>>> detalhes; |
25 | + private int[] warningsErrorsCss; | ||
26 | + private int[] warningsErrorsHtml; | ||
25 | 27 | ||
26 | public DetalheAvaliacao(CriterioProperties criterioProperties){ | 28 | public DetalheAvaliacao(CriterioProperties criterioProperties){ |
27 | this.criterioProperties = criterioProperties; | 29 | this.criterioProperties = criterioProperties; |
@@ -31,6 +33,12 @@ public class DetalheAvaliacao { | @@ -31,6 +33,12 @@ public class DetalheAvaliacao { | ||
31 | this.detalhes = detalhes; | 33 | this.detalhes = detalhes; |
32 | } | 34 | } |
33 | 35 | ||
36 | + public void inicializar(Map<OccurrenceKey,Map<String,List<Occurrence>>> detalhes,int[] warningsErrorsCss,int[] warningsErrorsHtml) { | ||
37 | + this.detalhes = detalhes; | ||
38 | + this.warningsErrorsCss = warningsErrorsCss; | ||
39 | + this.warningsErrorsHtml= warningsErrorsHtml; | ||
40 | + | ||
41 | + } | ||
34 | 42 | ||
35 | public Detalhe get(OccurrenceKey rn) { | 43 | public Detalhe get(OccurrenceKey rn) { |
36 | return new Detalhe(rn.getCode(),this.detalhes.get(rn)); | 44 | return new Detalhe(rn.getCode(),this.detalhes.get(rn)); |
@@ -40,6 +48,22 @@ public class DetalheAvaliacao { | @@ -40,6 +48,22 @@ public class DetalheAvaliacao { | ||
40 | return new Detalhe(rn.getCode(),type,this.detalhes.get(rn)); | 48 | return new Detalhe(rn.getCode(),type,this.detalhes.get(rn)); |
41 | } | 49 | } |
42 | 50 | ||
51 | + public int getErrorsCss(){ | ||
52 | + return this.warningsErrorsCss!=null ?this.warningsErrorsCss[0] : 0; | ||
53 | + } | ||
54 | + | ||
55 | + public int getWarningsCss(){ | ||
56 | + return this.warningsErrorsCss!=null ?this.warningsErrorsCss[1] : 0; | ||
57 | + } | ||
58 | + | ||
59 | + public int getErrorsHtml(){ | ||
60 | + return this.warningsErrorsHtml!=null ?this.warningsErrorsHtml[0] : 0; | ||
61 | + } | ||
62 | + | ||
63 | + public int getWarningsHtml(){ | ||
64 | + return this.warningsErrorsHtml!=null ?this.warningsErrorsHtml[1] : 0; | ||
65 | + } | ||
66 | + | ||
43 | 67 | ||
44 | public @Getter class Detalhe { | 68 | public @Getter class Detalhe { |
45 | 69 |
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
1 | +package br.com.ases.domain; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +public class HtmlValidation { | ||
7 | + | ||
8 | + List<Message> messages = new ArrayList<HtmlValidation.Message>(); | ||
9 | + | ||
10 | + | ||
11 | + public List<Message> getMessages() { | ||
12 | + return messages; | ||
13 | + } | ||
14 | + | ||
15 | + public void setMessages(List<Message> messages) { | ||
16 | + this.messages = messages; | ||
17 | + } | ||
18 | + | ||
19 | + public int[] getQtdWarningsErros(){ | ||
20 | + int warnings=0; | ||
21 | + int erros = 0; | ||
22 | + for(Message message: this.messages ){ | ||
23 | + if(message.isError()) | ||
24 | + erros++; | ||
25 | + else if (message.isWarning()) | ||
26 | + warnings++; | ||
27 | + } | ||
28 | + | ||
29 | + return new int[]{warnings,erros}; | ||
30 | + } | ||
31 | + | ||
32 | + public HtmlValidation(){} | ||
33 | + | ||
34 | + public class Message{ | ||
35 | + | ||
36 | + private String type; | ||
37 | + | ||
38 | + private String subType; | ||
39 | + | ||
40 | + public String getType() { return type; } | ||
41 | + | ||
42 | + public void setType(String type) { this.type = type; } | ||
43 | + | ||
44 | + public String getSubType() { return subType; } | ||
45 | + | ||
46 | + public void setSubType(String subType) { this.subType = subType; } | ||
47 | + | ||
48 | + public boolean isWarning(){ return "info".equals(type) && "warning".equals(this.subType); } | ||
49 | + | ||
50 | + public boolean isError(){ return "error".equals(this.type);} | ||
51 | + | ||
52 | + } | ||
53 | +} | ||
54 | + | ||
55 | + | ||
56 | + |
src/main/webapp/WEB-INF/jsp/avaliacao/detalhesAvaliacao.jsp
@@ -56,7 +56,29 @@ | @@ -56,7 +56,29 @@ | ||
56 | <td class="celula" width="2%"> ${criterio.id} </td> | 56 | <td class="celula" width="2%"> ${criterio.id} </td> |
57 | <td class="celula" width="60%" align="left">${criterio.descricao}</td> | 57 | <td class="celula" width="60%" align="left">${criterio.descricao}</td> |
58 | 58 | ||
59 | - <td class="celula">${criterio.numeroOcorrencias}</td> | 59 | + <td class="celula"> |
60 | + | ||
61 | + <c:choose> | ||
62 | + <c:when test="${rn == '1.1'}"> | ||
63 | + <c:choose> | ||
64 | + <c:when test="${criterio.id == 1 }"> | ||
65 | + ${qtdOcorrenciasHtml} | ||
66 | + </c:when> | ||
67 | + <c:when test="${criterio.id == 2 }"> | ||
68 | + ${qtdOcorrenciasCss} | ||
69 | + </c:when> | ||
70 | + <c:otherwise> | ||
71 | + ${criterio.numeroOcorrencias} | ||
72 | + </c:otherwise> | ||
73 | + </c:choose> | ||
74 | + </c:when> | ||
75 | + <c:otherwise> | ||
76 | + ${criterio.numeroOcorrencias} | ||
77 | + </c:otherwise> | ||
78 | + </c:choose> | ||
79 | + | ||
80 | + | ||
81 | + </td> | ||
60 | <td class="celula"> | 82 | <td class="celula"> |
61 | 83 | ||
62 | 84 | ||
@@ -143,7 +165,7 @@ | @@ -143,7 +165,7 @@ | ||
143 | </a> | 165 | </a> |
144 | </c:when> | 166 | </c:when> |
145 | <c:when test="${ocorrencia.htmlEvaluation }"> | 167 | <c:when test="${ocorrencia.htmlEvaluation }"> |
146 | - <a name="${ocorrencia.criterio}.${ocorrencia.posLineOccurrence}" href="https://validator.w3.org/nu/?doc=http%3A%2F%2F${ocorrencia.tag}" target="_blank"> | 168 | + <a name="${ocorrencia.criterio}.${ocorrencia.posLineOccurrence}" href="https://validator.w3.org/nu/?doc=${ocorrencia.tag}" target="_blank"> |
147 | ${ocorrencia.line} : Serviço de validação de HTML do W3C : ${ocorrencia.tag} | 169 | ${ocorrencia.line} : Serviço de validação de HTML do W3C : ${ocorrencia.tag} |
148 | </a> | 170 | </a> |
149 | </c:when> | 171 | </c:when> |