Commit 53bc7d9a607f62395ba4a814decd67680869a57b

Authored by gibransodre
1 parent 46a89376
Exists in master

WebService (geração do json) e identação.

src/main/java/br/com/ases/business/impl/AvaliacaoBusinessImpl.java
@@ -108,7 +108,10 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { @@ -108,7 +108,10 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness {
108 for (String atributoBuscar : atributosBuscar) { 108 for (String atributoBuscar : atributosBuscar) {
109 109
110 if(element.getStartTag().getName().equalsIgnoreCase("input")) 110 if(element.getStartTag().getName().equalsIgnoreCase("input"))
111 - { 111 + {
  112 + if(element.getAttributeValue(atributoBuscar) != null)
  113 + {
  114 + System.out.println(element.getStartTag().getName().equalsIgnoreCase("input"));
112 if(!element.getAttributeValue(atributoBuscar).equalsIgnoreCase("button") 115 if(!element.getAttributeValue(atributoBuscar).equalsIgnoreCase("button")
113 && !element.getAttributeValue(atributoBuscar).equalsIgnoreCase("reset") 116 && !element.getAttributeValue(atributoBuscar).equalsIgnoreCase("reset")
114 && !element.getAttributeValue(atributoBuscar).equalsIgnoreCase("submit") 117 && !element.getAttributeValue(atributoBuscar).equalsIgnoreCase("submit")
@@ -117,6 +120,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { @@ -117,6 +120,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness {
117 { 120 {
118 qtdItens = qtdItens + (element.getAttributeValue(atributoBuscar) != null? 1 : 0); 121 qtdItens = qtdItens + (element.getAttributeValue(atributoBuscar) != null? 1 : 0);
119 } 122 }
  123 + }
120 }else if(element.getStartTag().getName().equalsIgnoreCase("textarea") || 124 }else if(element.getStartTag().getName().equalsIgnoreCase("textarea") ||
121 element.getStartTag().getName().equalsIgnoreCase("select")) 125 element.getStartTag().getName().equalsIgnoreCase("select"))
122 { 126 {
@@ -126,6 +130,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { @@ -126,6 +130,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness {
126 { 130 {
127 qtdItens = qtdItens + (element.getAttributeValue(atributoBuscar) != null? 1 : 0); 131 qtdItens = qtdItens + (element.getAttributeValue(atributoBuscar) != null? 1 : 0);
128 } 132 }
  133 +
129 } 134 }
130 } 135 }
131 } 136 }
@@ -193,7 +198,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { @@ -193,7 +198,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness {
193 //Separa a recomenda��o do crit�rio sendo (x.y) de (x.y.z) 198 //Separa a recomenda��o do crit�rio sendo (x.y) de (x.y.z)
194 recomendacaoProperties = recomendacaoCriterio[0].toString() + "." + recomendacaoCriterio[1].toString(); 199 recomendacaoProperties = recomendacaoCriterio[0].toString() + "." + recomendacaoCriterio[1].toString();
195 200
196 - //Semara a crit�rio da recomenda��o sendo (z) de (x.y.z) 201 + //Separa a crit�rio da recomenda��o sendo (z) de (x.y.z)
197 criterioProperties = recomendacaoCriterio[2]; 202 criterioProperties = recomendacaoCriterio[2];
198 203
199 204
@@ -208,17 +213,22 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { @@ -208,17 +213,22 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness {
208 for (RecomendacaoCriterios recCriterio : lsRecomendacaoCriterios) { 213 for (RecomendacaoCriterios recCriterio : lsRecomendacaoCriterios) {
209 countCriterio++; 214 countCriterio++;
210 postParams.addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].idCriterio",recCriterio.criterio) 215 postParams.addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].idCriterio",recCriterio.criterio)
211 - .addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].qtdeErros", Integer.toString(recCriterio.qtdErros))  
212 - .addParam("relatorioAvaliacao.recomendacoes["+countReq+"].criterios["+countCriterio+"].qtdeItens",Integer.toString(recCriterio.qtdItens)); 216 + .addParam("relatorioAvaliacao.recomendacoes["+ countReq +"].criterios["+countCriterio+"].qtdeErros", Integer.toString(recCriterio.qtdErros))
  217 + .addParam("relatorioAvaliacao.recomendacoes["+ countReq +"].criterios["+countCriterio+"].qtdeItens",Integer.toString(recCriterio.qtdItens));
213 } 218 }
214 219
215 - postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq+ "].totalErros", Integer.toString(totalErros));  
216 - postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq+ "].totalAvisos", Integer.toString(totalAvisos)); 220 + postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq + "].totalErros", Integer.toString(totalErros));
  221 + postParams.addParam("relatorioAvaliacao.recomendacoes[" + countReq + "].totalAvisos", Integer.toString(totalAvisos));
217 222
218 totalAvisos = 0; 223 totalAvisos = 0;
219 totalErros = 0; 224 totalErros = 0;
220 lsRecomendacaoCriterios = new ArrayList<RecomendacaoCriterios>(); 225 lsRecomendacaoCriterios = new ArrayList<RecomendacaoCriterios>();
221 } 226 }
  227 + else
  228 + {
  229 + totalAvisos = 0;
  230 + totalErros = 0;
  231 + }
222 232
223 233
224 234
@@ -318,9 +328,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness { @@ -318,9 +328,7 @@ public class AvaliacaoBusinessImpl implements AvaliacaoBusiness {
318 recomendacaoAdd.setQtdErros(qtdErrosAvisos); 328 recomendacaoAdd.setQtdErros(qtdErrosAvisos);
319 recomendacaoAdd.setQtdItens(qtdItens); 329 recomendacaoAdd.setQtdItens(qtdItens);
320 lsRecomendacaoCriterios.add(recomendacaoAdd); 330 lsRecomendacaoCriterios.add(recomendacaoAdd);
321 - }  
322 -  
323 - 331 + }
324 332
325 } 333 }
326 334
src/main/java/br/com/ases/controller/AvaliacaoController.java
@@ -29,6 +29,9 @@ import java.util.regex.Pattern; @@ -29,6 +29,9 @@ import java.util.regex.Pattern;
29 import javax.servlet.ServletContext; 29 import javax.servlet.ServletContext;
30 import javax.ws.rs.QueryParam; 30 import javax.ws.rs.QueryParam;
31 31
  32 +import org.json.JSONObject;
  33 +import org.json.XML;
  34 +
32 import net.sf.jasperreports.engine.JRException; 35 import net.sf.jasperreports.engine.JRException;
33 import br.com.ases.business.AvaliacaoBusiness; 36 import br.com.ases.business.AvaliacaoBusiness;
34 import br.com.ases.controller.EseloController.Nota; 37 import br.com.ases.controller.EseloController.Nota;
@@ -61,1059 +64,1067 @@ import br.com.checker.emag.core.ContentEvaluation; @@ -61,1059 +64,1067 @@ import br.com.checker.emag.core.ContentEvaluation;
61 64
62 @Resource 65 @Resource
63 public class AvaliacaoController { 66 public class AvaliacaoController {
64 - EseloProperties eseloProperties = null;  
65 -  
66 - private String tituloPagina;  
67 - // Altera a mensagem caso n�o esteja usando o ESELO (Nota e Resumo da  
68 - // Avalia��o de Acessibilidade)  
69 - private String mensagem_avaliacao = null;  
70 -  
71 - // Esconde a nota caso n�o esteja usando o ESELO  
72 - private String sem_nota = null;  
73 - private String tituloSite;  
74 - private String ancoraCampoVazio;  
75 - private String dataHoraAvaliacao;  
76 - private String webaxscore;  
77 - private Result result;  
78 - private List<String> avisosFerramentasHtmlCssW3c;  
79 - private Validator validator;  
80 - private AvaliacaoBusiness avaliacaoBusiness;  
81 - private Map<OccurrenceClassification, List<SummarizedOccurrence>> ocorrencias = new HashMap<OccurrenceClassification, List<SummarizedOccurrence>>();  
82 - private ServletContext application;  
83 - private DetalheAvaliacao detalheAvaliacao;  
84 - private UtilitiesProperties utilitiesProperties;  
85 - private StringBuffer xml;  
86 - private CriterioProperties criterioProperties;  
87 -  
88 - public AvaliacaoController(Result result, Validator validator,  
89 - AvaliacaoBusiness avaliacaoBusiness, ServletContext application,  
90 - DetalheAvaliacao detalheAvaliacao) {  
91 - this.result = result;  
92 - this.validator = validator;  
93 - this.avaliacaoBusiness = avaliacaoBusiness;  
94 - this.application = application;  
95 - this.detalheAvaliacao = detalheAvaliacao;  
96 - this.avaliacaoBusiness.initEseloProperties(application);  
97 - this.initEseloProperties(application);  
98 - this.criterioProperties = new CriterioProperties(application);  
99 - this.utilitiesProperties = new UtilitiesProperties(application);  
100 -  
101 - }  
102 -  
103 -  
104 - private void DefinirCorWebaxscore(String valorNota) {  
105 -  
106 - // Define a cor do webaxscore na p�gina "Avaliar" de acordo a pontua��o  
107 -  
108 - Double notaAvaliacao = Double.parseDouble(valorNota.replaceFirst(",",  
109 - "."));  
110 -  
111 - if (notaAvaliacao >= 70) {  
112 - webaxscore = "verde";  
113 - } else if (notaAvaliacao >= 50 & notaAvaliacao < 70) {  
114 - webaxscore = "amarela";  
115 - } else {  
116 - webaxscore = "vermelha";  
117 - }  
118 - }  
119 -  
120 - @Path("/avaliar-arquivo")  
121 - public void avaliarArquivo(UploadedFile file, boolean mark,  
122 - boolean content, boolean presentation, boolean multimedia,  
123 - boolean form, boolean behavior, int tiprel) throws IOException {  
124 -  
125 - Validate validate = new Validate(this.validator);  
126 - if (validate.uploadForm(file)) {  
127 -  
128 - BufferedReader reader = new BufferedReader(new InputStreamReader(  
129 - file.getFile()));  
130 - String html = "";  
131 - String linha = "";  
132 - while ((linha = reader.readLine()) != null)  
133 - // html += "\n"+linha;  
134 - html += linha + "\n";  
135 -  
136 - if (validate.conteudoUploadForm(html)) {  
137 -  
138 - /*  
139 - * if(tiprel != 5)  
140 - * this.result.redirectTo(AvaliacaoController.class  
141 - * ).relatorioAvaliacao(html, mark, content, presentation,  
142 - * multimedia, form, behavior, tiprel, false);  
143 - */  
144 -  
145 - Checker checker = from(html);  
146 -  
147 - if (mark)checker.with(marking());  
148 - if (content)checker.with(content());  
149 - if (presentation)checker.with(presentation());  
150 - if (multimedia)checker.with(multimedia());  
151 - if (form)checker.with(form());  
152 - if (behavior)checker.with(behavior());  
153 -  
154 - html = html.replaceAll("<", "&lt;");  
155 - html = html.replaceAll(">", "&gt;");  
156 - html = html.replaceAll(" ", "&nbsp");  
157 -  
158 - result.include("contentLenght",String.valueOf(html.getBytes("UTF-8").length));  
159 - result.include("html", html);  
160 -  
161 - this.tituloSite = "";  
162 -  
163 - ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument());  
164 - this.tituloSite = conteudo.retornarTituloSiteAvaliado();  
165 -  
166 - result.include("titulosite", tituloSite);  
167 - Nota nota = null;  
168 -  
169 - if (!this.sem_nota.equalsIgnoreCase("sem_nota")) {  
170 - List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias = avaliacaoBusiness.retornarCriteriosTeste(checker.check());  
171 - //nota = avaliacaoBusiness.obterNota(checker.checkSumarized(), file.getFileName(), mapaListaOcorrencias);  
172 - nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(),file.getFileName(), mapaListaOcorrencias);  
173 - // Altera a cor de webaxscore de acordo a pontuacao  
174 -  
175 - if (nota.getValor() != null) {  
176 - DefinirCorWebaxscore(nota.getValor());  
177 -  
178 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("webaxscore", webaxscore);  
179 - }  
180 -  
181 - }  
182 -  
183 - result.include("nota", nota);  
184 - this.sumarizarResultasNoResponse(checker.checkSumarized(), result);  
185 - this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()));  
186 -  
187 -  
188 -  
189 -  
190 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("resultadoAvaliacao", checker.checkSumarized());  
191 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("urlAvaliada", "");  
192 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("contentLenght",String.valueOf(html.getBytes("UTF-8").length));  
193 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("notaAvaliacao", nota);  
194 -  
195 - // Seta o valor do t�tulo no template  
196 - tituloPagina = "Resumo de avaliação por upload de arquivo - ASES";  
197 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("tituloPagina", tituloPagina); 67 + EseloProperties eseloProperties = null;
  68 +
  69 + private String tituloPagina;
  70 + // Altera a mensagem caso n�o esteja usando o ESELO (Nota e Resumo da
  71 + // Avalia��o de Acessibilidade)
  72 + private String mensagem_avaliacao = null;
  73 +
  74 + // Esconde a nota caso n�o esteja usando o ESELO
  75 + private String sem_nota = null;
  76 + private String tituloSite;
  77 + private String ancoraCampoVazio;
  78 + private String dataHoraAvaliacao;
  79 + private String webaxscore;
  80 + private Result result;
  81 + private List<String> avisosFerramentasHtmlCssW3c;
  82 + private Validator validator;
  83 + private AvaliacaoBusiness avaliacaoBusiness;
  84 + private Map<OccurrenceClassification, List<SummarizedOccurrence>> ocorrencias =
  85 + new HashMap<OccurrenceClassification, List<SummarizedOccurrence>>();
  86 + private ServletContext application;
  87 + private DetalheAvaliacao detalheAvaliacao;
  88 + private UtilitiesProperties utilitiesProperties;
  89 + private StringBuffer xml;
  90 + private CriterioProperties criterioProperties;
  91 +
  92 + private static int PRETTY_PRINT_INDENT_FACTOR = 4;
  93 +
  94 + public AvaliacaoController(Result result, Validator validator,
  95 + AvaliacaoBusiness avaliacaoBusiness, ServletContext application,
  96 + DetalheAvaliacao detalheAvaliacao) {
  97 + this.result = result;
  98 + this.validator = validator;
  99 + this.avaliacaoBusiness = avaliacaoBusiness;
  100 + this.application = application;
  101 + this.detalheAvaliacao = detalheAvaliacao;
  102 + this.avaliacaoBusiness.initEseloProperties(application);
  103 + this.initEseloProperties(application);
  104 + this.criterioProperties = new CriterioProperties(application);
  105 + this.utilitiesProperties = new UtilitiesProperties(application);
  106 +
  107 + }
  108 +
  109 +
  110 + private void DefinirCorWebaxscore(String valorNota) {
  111 +
  112 + // Define a cor do webaxscore na p�gina "Avaliar" de acordo a pontua��o
  113 +
  114 + Double notaAvaliacao = Double.parseDouble(valorNota.replaceFirst(",", "."));
  115 +
  116 + if (notaAvaliacao >= 70) {
  117 + webaxscore = "verde";
  118 + } else if (notaAvaliacao >= 50 & notaAvaliacao < 70) {
  119 + webaxscore = "amarela";
  120 + } else {
  121 + webaxscore = "vermelha";
  122 + }
  123 + }
  124 +
  125 + @Path("/avaliar-arquivo")
  126 + public void avaliarArquivo(UploadedFile file, boolean mark, boolean content,
  127 + boolean presentation, boolean multimedia, boolean form, boolean behavior, int tiprel)
  128 + throws IOException {
  129 +
  130 + Validate validate = new Validate(this.validator);
  131 + if (validate.uploadForm(file)) {
  132 +
  133 + BufferedReader reader = new BufferedReader(new InputStreamReader(file.getFile()));
  134 + String html = "";
  135 + String linha = "";
  136 + while ((linha = reader.readLine()) != null)
  137 + // html += "\n"+linha;
  138 + html += linha + "\n";
  139 +
  140 + if (validate.conteudoUploadForm(html)) {
  141 +
  142 + /*
  143 + * if(tiprel != 5) this.result.redirectTo(AvaliacaoController.class
  144 + * ).relatorioAvaliacao(html, mark, content, presentation, multimedia, form, behavior,
  145 + * tiprel, false);
  146 + */
  147 +
  148 + Checker checker = from(html);
  149 +
  150 + if (mark)
  151 + checker.with(marking());
  152 + if (content)
  153 + checker.with(content());
  154 + if (presentation)
  155 + checker.with(presentation());
  156 + if (multimedia)
  157 + checker.with(multimedia());
  158 + if (form)
  159 + checker.with(form());
  160 + if (behavior)
  161 + checker.with(behavior());
  162 +
  163 + html = html.replaceAll("<", "&lt;");
  164 + html = html.replaceAll(">", "&gt;");
  165 + html = html.replaceAll(" ", "&nbsp");
  166 +
  167 + result.include("contentLenght", String.valueOf(html.getBytes("UTF-8").length));
  168 + result.include("html", html);
  169 +
  170 + this.tituloSite = "";
  171 +
  172 + ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument());
  173 + this.tituloSite = conteudo.retornarTituloSiteAvaliado();
  174 +
  175 + result.include("titulosite", tituloSite);
  176 + Nota nota = null;
  177 +
  178 + if (!this.sem_nota.equalsIgnoreCase("sem_nota")) {
  179 + List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias =
  180 + avaliacaoBusiness.retornarCriteriosTeste(checker.check());
  181 + // nota = avaliacaoBusiness.obterNota(checker.checkSumarized(), file.getFileName(),
  182 + // mapaListaOcorrencias);
  183 + nota =
  184 + avaliacaoBusiness.obterNotaEselo(checker.getDocument(), file.getFileName(),
  185 + mapaListaOcorrencias);
  186 + // Altera a cor de webaxscore de acordo a pontuacao
  187 +
  188 + if (nota.getValor() != null) {
  189 + DefinirCorWebaxscore(nota.getValor());
  190 +
  191 + VRaptorRequestHolder.currentRequest().getServletContext()
  192 + .setAttribute("webaxscore", webaxscore);
  193 + }
  194 +
  195 + }
  196 +
  197 + result.include("nota", nota);
  198 + this.sumarizarResultasNoResponse(checker.checkSumarized(), result);
  199 + this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()));
  200 +
  201 +
  202 +
  203 + VRaptorRequestHolder.currentRequest().getServletContext()
  204 + .setAttribute("resultadoAvaliacao", checker.checkSumarized());
  205 + VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("urlAvaliada", "");
  206 + VRaptorRequestHolder.currentRequest().getServletContext()
  207 + .setAttribute("contentLenght", String.valueOf(html.getBytes("UTF-8").length));
  208 + VRaptorRequestHolder.currentRequest().getServletContext()
  209 + .setAttribute("notaAvaliacao", nota);
  210 +
  211 + // Seta o valor do t�tulo no template
  212 + tituloPagina = "Resumo de avaliação por upload de arquivo - ASES";
  213 + VRaptorRequestHolder.currentRequest().getServletContext()
  214 + .setAttribute("tituloPagina", tituloPagina);
  215 +
  216 + VRaptorRequestHolder.currentRequest().getServletContext()
  217 + .setAttribute("titulosite", tituloSite);
  218 +
  219 + this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();
  220 + VRaptorRequestHolder.currentRequest().getServletContext()
  221 + .setAttribute("data", dataHoraAvaliacao);
  222 +
  223 + result.of(this).avaliar(null, mark, content, presentation, multimedia, form, behavior,
  224 + tiprel);
  225 +
  226 + } else {
  227 +
  228 + // Atribui �ncora para as mensagens de erros dos campos vazios
  229 + ancoraCampoVazio = "up_file";
  230 + VRaptorRequestHolder.currentRequest().getServletContext()
  231 + .setAttribute("ancoraCampoVazio", ancoraCampoVazio);
  232 +
  233 + this.validator = validate.getMessage();
  234 + this.validator.onErrorUsePageOf(IndexController.class).index();
  235 + }
  236 +
  237 + } else {
  238 + // Atribui �ncora para as mensagens de erros dos campos vazios
  239 + ancoraCampoVazio = "up_file";
  240 + VRaptorRequestHolder.currentRequest().getServletContext()
  241 + .setAttribute("ancoraCampoVazio", ancoraCampoVazio);
  242 +
  243 + this.validator = validate.getMessage();
  244 + this.validator.onErrorUsePageOf(IndexController.class).index();
  245 + }
  246 + }
  247 +
  248 + @Post("/avaliar")
  249 + public void avaliar(String url, boolean mark, boolean content, boolean presentation,
  250 + boolean multimedia, boolean form, boolean behavior, int tiporel) {
  251 +
  252 + Validate validate = new Validate(this.validator);
  253 + if (validate.url(url)) {
  254 +
  255 + /*
  256 + * if(tiporel != 5) this.result.redirectTo(AvaliacaoController.class) .relatorioAvaliacao(url,
  257 + * mark, content, presentation, multimedia, form, behavior, tiporel, true);
  258 + */
  259 +
  260 + if (url.startsWith("www"))
  261 + url = "http://" + url;
  262 +
  263 + WebChecker pagina = WebChecker.from(url).withGetRequest().execute();
  264 +
  265 + int[] errorsWarningsCss = avaliacaoBusiness.getErrorCount(true, url);
  266 + int[] errorsWarningsHtml = avaliacaoBusiness.getErrorCount(false, url);
  267 +
  268 + Checker checker = from(pagina.getContent(), url);
  269 +
  270 + if (mark)
  271 + checker.with(marking());
  272 + if (content)
  273 + checker.with(content());
  274 + if (presentation)
  275 + checker.with(presentation());
  276 + if (multimedia)
  277 + checker.with(multimedia());
  278 + if (form)
  279 + checker.with(form());
  280 + if (behavior)
  281 + checker.with(behavior());
  282 +
  283 + Pattern pp = Pattern.compile("(http://www.)?([a-z]*)(.)?");
  284 + Matcher mm = pp.matcher(url.toLowerCase().replace("https", "http"));
  285 +
  286 + if (mm.find())
  287 +
  288 + this.tituloSite = "";
  289 +
  290 + ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument());
  291 +
  292 + this.tituloSite = conteudo.retornarTituloSiteAvaliado();
  293 +
  294 + result.include("titulosite", tituloSite);
  295 +
  296 + result.include("contentLenght", pagina.getContentLength());
  297 + result.include("url", url);
  298 + result.include("html", pagina.getParsedContent());
  299 +
  300 + Nota nota = null;
  301 +
  302 + if (!this.sem_nota.equalsIgnoreCase("sem_nota")) {
  303 +
  304 + List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias =
  305 + avaliacaoBusiness.retornarCriteriosTeste(checker.check());
  306 + // Altera a cor de webaxscore de acordo a pontuacao
  307 + // nota = avaliacaoBusiness.obterNota(checker.checkSumarized(), url, mapaListaOcorrencias);
  308 +
  309 + nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(), url, mapaListaOcorrencias);
  310 +
  311 + if (nota.getValor() != null) {
  312 + DefinirCorWebaxscore(nota.getValor());
  313 +
  314 + VRaptorRequestHolder.currentRequest().getServletContext()
  315 + .setAttribute("webaxscore", webaxscore);
  316 + }
  317 +
  318 + }
  319 +
  320 + result.include("nota", nota);
  321 + this.sumarizarResultasNoResponse(checker.checkSumarized(), result);
  322 +
  323 + this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()),
  324 + errorsWarningsCss, errorsWarningsHtml);
  325 +
  326 + VRaptorRequestHolder.currentRequest().getServletContext()
  327 + .setAttribute("resultadoAvaliacao", checker.checkSumarized());
  328 +
  329 + VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("urlAvaliada", url);
  330 +
  331 + VRaptorRequestHolder.currentRequest().getServletContext()
  332 + .setAttribute("contentLenght", pagina.getContentLength());
  333 +
  334 + VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("notaAvaliacao", nota);
  335 +
  336 + // Seta o valor do t�tulo no template
  337 + tituloPagina = "Resumo de avaliação por URI - ASES";
  338 + VRaptorRequestHolder.currentRequest().getServletContext()
  339 + .setAttribute("tituloPagina", tituloPagina);
  340 +
  341 + VRaptorRequestHolder.currentRequest().getServletContext()
  342 + .setAttribute("titulosite", tituloSite);
  343 +
  344 + this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();
  345 +
  346 + VRaptorRequestHolder.currentRequest().getServletContext()
  347 + .setAttribute("data", dataHoraAvaliacao);
  348 +
  349 + avisosFerramentasHtmlCssW3c = new ArrayList<String>();
  350 +
  351 + validarFerramenta_cssnoAr(errorsWarningsCss);
  352 + validarFerramenta_htmlnoAr(errorsWarningsHtml);
  353 +
  354 + VRaptorRequestHolder.currentRequest().getServletContext()
  355 + .setAttribute("avisosFerramentasHtmlCssW3c", avisosFerramentasHtmlCssW3c);
  356 +
  357 + } else {
  358 + // Atribui �ncora para as mensagens de erros dos campos vazios
  359 + ancoraCampoVazio = "url";
  360 + VRaptorRequestHolder.currentRequest().getServletContext()
  361 + .setAttribute("ancoraCampoVazio", ancoraCampoVazio);
  362 +
  363 + this.validator = validate.getMessage();
  364 + this.validator.onErrorUsePageOf(IndexController.class).index();
  365 + }
  366 + }
  367 +
  368 + // Verifica se o site de avalia��o de sintaxe css encontra-se no ar
  369 + private void validarFerramenta_cssnoAr(int[] erros_avisos) {
  370 + if (erros_avisos[0] == -10 && erros_avisos[1] == -10) {
  371 +
  372 + avisosFerramentasHtmlCssW3c
  373 + .add("O avaliador de sintaxe css do w3c encontra-se indispon&iacute;vel, favor tentar mais tarde.");
  374 + }
  375 +
  376 + }
  377 +
  378 + // Verifica se o site de avalia��o de sintaxe html encontra-se no ar
  379 + private void validarFerramenta_htmlnoAr(int[] erros_avisos) {
  380 + if (erros_avisos[0] == -10 && erros_avisos[1] == -10) {
  381 + avisosFerramentasHtmlCssW3c
  382 + .add("O avaliador de sintaxe html do w3c encontra-se indispon&iacute;vel, favor tentar mais tarde.");
  383 + }
  384 + }
  385 +
  386 + @Get("/relatorioavaliacao")
  387 + @Post("/relatorioavaliacao")
  388 + public FileDownload relatorioAvaliacao(int tiporel) {
  389 +
  390 + List<SummarizedOccurrence> checkerList =
  391 + (List<SummarizedOccurrence>) VRaptorRequestHolder.currentRequest().getServletContext()
  392 + .getAttribute("resultadoAvaliacao");
  393 + String urlAvaliada =
  394 + (String) VRaptorRequestHolder.currentRequest().getServletContext()
  395 + .getAttribute("urlAvaliada");
  396 + String contentLenght =
  397 + (String) VRaptorRequestHolder.currentRequest().getServletContext()
  398 + .getAttribute("contentLenght");
  399 + this.sumarizarResultasNoResponse(checkerList, result);
  400 +
  401 + // ================================================ GERAR RELAT�RIO
  402 + // =============================================//
  403 +
  404 + /* Cria um Map de par�metros */
  405 + HashMap<String, Object> map = new HashMap<String, Object>();
  406 +
  407 + /* Obtem a nota */
  408 + // AvaliacaoBusinessImpl avaliacaoBusiness = new
  409 + // AvaliacaoBusinessImpl();
  410 + Nota nota = null;
  411 +
  412 + if (!this.sem_nota.equalsIgnoreCase("sem_nota")) {
  413 + nota =
  414 + (Nota) VRaptorRequestHolder.currentRequest().getServletContext()
  415 + .getAttribute("notaAvaliacao");
  416 +
  417 + map.put("pPercentualAses", nota.getValor());
  418 + } else {
  419 + map.put("pPercentualAses", "0");
  420 + }
  421 +
  422 + map.put("pPagina", urlAvaliada != "" ? urlAvaliada : "Código Fonte ou Arquivo");
  423 +
  424 + if (urlAvaliada != "") {
  425 + Pattern pp = Pattern.compile("(http://www.)?([a-z]*)(.)?");
  426 + Matcher mm = pp.matcher(urlAvaliada.toLowerCase());
  427 +
  428 + if (mm.find())
  429 + map.put("pTitulo",
  430 + VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("titulosite"));
  431 +
  432 + } else
  433 + map.put("pTitulo",
  434 + VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("titulosite"));
  435 +
  436 + map.put("pTamanho", contentLenght + " Bytes");
  437 + dataHoraAvaliacao =
  438 + (String) VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("data");
  439 + map.put("pDataHoraAvaliacao", dataHoraAvaliacao);
  440 +
  441 + // Obtem Resumo da Avaliação
  442 + List<ResumoAvaliacao> resumoErrosAvisos = obterResumoAvaliacao();
  443 +
  444 + int totalErros = 0;
  445 + int totalAvisos = 0;
  446 +
  447 + for (ResumoAvaliacao resumo : resumoErrosAvisos) {
  448 + map.put(resumo.getTipo() + "_A", resumo.getQuantidadeAvisos());
  449 + map.put(resumo.getTipo() + "_E", resumo.getQuantidadeErros());
  450 + totalErros += resumo.getQuantidadeErros();
  451 + totalAvisos += resumo.getQuantidadeAvisos();
  452 + }
  453 +
  454 + map.put("TOTAL_E", totalErros);
  455 + map.put("TOTAL_A", totalAvisos);
  456 +
  457 + ManagerReport managerReport =
  458 + new ManagerReport(this.application.getRealPath("")
  459 + + "/WEB-INF/templates-relatorios/relatorio-avaliacao.jrxml");
  460 + String path = null;
  461 +
  462 + try {
  463 + path = managerReport.gerarRelatorio(checkerList, map, tiporel, "RelatorioAvaliacao");
  464 + } catch (JRException e) {
  465 + e.printStackTrace();
  466 + } catch (IOException e) {
  467 + e.printStackTrace();
  468 + }
  469 + File file = new File(path);
  470 +
  471 + return new FileDownload(file, managerReport.getContentType(), managerReport.getFileName());
  472 +
  473 + // =========================================== FIM GERAR RELAT�RIO
  474 + // =============================================//
  475 +
  476 + }
  477 +
  478 + @Post("/avaliar-codigo")
  479 + public void avaliarPlainText(String html, boolean mark, boolean content, boolean presentation,
  480 + boolean multimedia, boolean form, boolean behavior, int tiporel) throws IOException {
  481 +
  482 + Validate validate = new Validate(this.validator);
  483 + if (validate.condigoFonte(html)) {
  484 +
  485 + /*
  486 + * if(tiporel != 5) this.result.redirectTo(AvaliacaoController.class)
  487 + * .relatorioAvaliacao(html, mark, content, presentation, multimedia, form, behavior, tiporel,
  488 + * false);
  489 + */
  490 +
  491 + Checker checker = from(html);
  492 +
  493 + if (mark)
  494 + checker.with(marking());
  495 + if (content)
  496 + checker.with(content());
  497 + if (presentation)
  498 + checker.with(presentation());
  499 + if (multimedia)
  500 + checker.with(multimedia());
  501 + if (form)
  502 + checker.with(form());
  503 + if (behavior)
  504 + checker.with(behavior());
  505 +
  506 + html = html.replaceAll("<", "&lt;");
  507 + html = html.replaceAll(">", "&gt;");
  508 + html = html.replaceAll(" ", "&nbsp");
  509 +
  510 + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
  511 +
  512 + result.include("contentLenght", String.valueOf(html.getBytes("UTF-8").length));
  513 + result.include("html", html);
  514 + this.tituloSite = "";
  515 +
  516 + ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument());
  517 +
  518 + this.tituloSite = conteudo.retornarTituloSiteAvaliado();
  519 +
  520 + result.include("titulosite", tituloSite);
  521 +
  522 + Nota nota = null;
  523 +
  524 + if (!this.sem_nota.equalsIgnoreCase("sem_nota")) {
  525 +
  526 + List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias =
  527 + avaliacaoBusiness.retornarCriteriosTeste(checker.check());
  528 + // nota = avaliacaoBusiness.obterNota(checker.checkSumarized(), tituloSite + " - " +
  529 + // sdf.format(new Date()),mapaListaOcorrencias);
  530 + nota =
  531 + avaliacaoBusiness.obterNotaEselo(checker.getDocument(),
  532 + tituloSite + " - " + sdf.format(new Date()), mapaListaOcorrencias);
  533 + // Altera a cor de webaxscore de acordo a pontuacao
  534 +
  535 + if (nota.getValor() != null) {
  536 + DefinirCorWebaxscore(nota.getValor());
  537 +
  538 + VRaptorRequestHolder.currentRequest().getServletContext()
  539 + .setAttribute("webaxscore", webaxscore);
  540 + }
  541 +
  542 +
  543 + }
  544 +
  545 + result.include("nota", nota);
  546 + this.sumarizarResultasNoResponse(checker.checkSumarized(), result);
  547 + this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()));
  548 +
  549 + VRaptorRequestHolder.currentRequest().getServletContext()
  550 + .setAttribute("resultadoAvaliacao", checker.checkSumarized());
  551 + VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("urlAvaliada", "");
  552 + VRaptorRequestHolder.currentRequest().getServletContext()
  553 + .setAttribute("contentLenght", String.valueOf(html.getBytes("UTF-8").length));
  554 + VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("notaAvaliacao", nota);
  555 +
  556 + // Seta o valor do t�tulo no template
  557 + tituloPagina = "Resumo de avaliação por código fonte - ASES";
  558 + VRaptorRequestHolder.currentRequest().getServletContext()
  559 + .setAttribute("tituloPagina", tituloPagina);
  560 + result.of(this).avaliar(null, mark, content, presentation, multimedia, form, behavior,
  561 + tiporel);
  562 +
  563 + VRaptorRequestHolder.currentRequest().getServletContext()
  564 + .setAttribute("titulosite", tituloSite);
  565 +
  566 + this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();
  567 + VRaptorRequestHolder.currentRequest().getServletContext()
  568 + .setAttribute("data", dataHoraAvaliacao);
  569 +
  570 + } else {
  571 + // Atribui �ncora para as mensagens de erros dos campos vazios
  572 + ancoraCampoVazio = "input";
  573 + VRaptorRequestHolder.currentRequest().getServletContext()
  574 + .setAttribute("ancoraCampoVazio", ancoraCampoVazio);
  575 +
  576 + this.validator = validate.getMessage();
  577 + this.validator.onErrorUsePageOf(IndexController.class).index();
  578 + }
  579 + }
  580 +
  581 + private void sumarizarResultasNoResponse(List<SummarizedOccurrence> resultadoAvaliacao,
  582 + Result result) {
  583 +
  584 + for (SummarizedOccurrence occurrence : resultadoAvaliacao) {
  585 + if (ocorrencias.get(occurrence.getType()) == null)
  586 + ocorrencias.put(occurrence.getType(), new ArrayList<SummarizedOccurrence>());
  587 +
  588 + ocorrencias.get(occurrence.getType()).add(occurrence);
  589 + }
  590 +
  591 + for (Entry<OccurrenceClassification, List<SummarizedOccurrence>> entry : ocorrencias.entrySet()) {
  592 + List<SummarizedOccurrence> ocorrenciasComputadas = entry.getValue();
  593 + Collections.sort(ocorrenciasComputadas);
  594 +
  595 + result.include("LISTA_" + entry.getKey().toString(), ocorrenciasComputadas);
  596 + }
  597 +
  598 + List<ResumoAvaliacao> resumoErrosAvisos = obterResumoAvaliacao();
  599 + int totalErros = 0;
  600 + int totalAvisos = 0;
  601 +
  602 + for (ResumoAvaliacao resumo : resumoErrosAvisos) {
  603 + totalErros += resumo.getQuantidadeErros();
  604 + totalAvisos += resumo.getQuantidadeAvisos();
  605 + }
  606 +
  607 + result.include("totalErros", totalErros);
  608 + result.include("totalAvisos", totalAvisos);
  609 + result.include("listaResumo", resumoErrosAvisos);
  610 + result.include("data", DateUtil.dataHoraAtual());
  611 +
  612 + }
  613 +
  614 + private List<ResumoAvaliacao> obterResumoAvaliacao() {
  615 + List<ResumoAvaliacao> resultado = new ArrayList<ResumoAvaliacao>();
  616 +
  617 + for (OccurrenceClassification classificacao : OccurrenceClassification.values()) {
  618 +
  619 + int erros = 0;
  620 + int avisos = 0;
  621 +
  622 + List<SummarizedOccurrence> listaOcorrencias = ocorrencias.get(classificacao);
  623 +
  624 + if (listaOcorrencias != null) {
  625 + for (SummarizedOccurrence ocorrencia : ocorrencias.get(classificacao)) {
  626 +
  627 + if (ocorrencia.isError())
  628 + for (int line : ocorrencia.getLines())
  629 + erros++;
  630 + else
  631 + for (int line : ocorrencia.getLines())
  632 + avisos++;
  633 +
  634 + }
  635 + }
  636 +
  637 + resultado.add(new ResumoAvaliacao(classificacao, erros, avisos));
  638 + }
  639 +
  640 + return resultado;
  641 + }
  642 +
  643 +
  644 + // Gibran
  645 + public void obterDetalhes(OccurrenceKey rn, boolean type) {
  646 +
  647 +
  648 + List<Occurrence> listOcorrencias = this.detalheAvaliacao.get(rn, type).getOcorrencias();
  649 +
  650 +
  651 +
  652 + Collections.sort(listOcorrencias, new Comparator<Occurrence>() {
  653 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  654 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  655 + }
  656 + });
  657 +
  658 +
  659 + result.include("detalhe", this.detalheAvaliacao.get(rn, type));
  660 + }
  661 +
  662 + @Path("/detalhes-avaliacao/{rn}/{type}")
  663 + public void detalhesAvaliacao(OccurrenceKey rn, boolean type) {
  664 + String url = "";
  665 + tituloPagina = "Detalhes da avalição - ASES";
  666 + VRaptorRequestHolder.currentRequest().getServletContext()
  667 + .setAttribute("tituloPagina", tituloPagina);
  668 +
  669 + List<Occurrence> listOcorrencias = this.detalheAvaliacao.get(rn, type).getOcorrencias();
  670 +
  671 +
  672 + // Sorting
  673 + Collections.sort(listOcorrencias, new Comparator<Occurrence>() {
  674 + public int compare(Occurrence occurrence1, Occurrence occurrence2) {
  675 + return occurrence1.getLine().compareTo(occurrence2.getLine());
  676 + }
  677 + });
  678 +
  679 + result.include("detalhe", this.detalheAvaliacao.get(rn, type));
  680 + result.include("listOcorrencia", listOcorrencias);
  681 +
  682 + result.include("isError", type);
  683 + if (type) {
  684 + result.include("qtdOcorrenciasCss", this.detalheAvaliacao.getErrorsCss());
  685 + result.include("qtdOcorrenciasHtml", this.detalheAvaliacao.getErrorsHtml());
  686 + } else {
  687 + result.include("qtdOcorrenciasCss", this.detalheAvaliacao.getWarningsCss());
  688 + result.include("qtdOcorrenciasHtml", this.detalheAvaliacao.getWarningsHtml());
  689 + }
  690 +
  691 + List<SummarizedOccurrence> ob =
  692 + (List<SummarizedOccurrence>) VRaptorRequestHolder.currentRequest().getServletContext()
  693 + .getAttribute("resultadoAvaliacao");
  694 + String recomendacao = "";
  695 +
  696 +
  697 + for (SummarizedOccurrence occurrence : ob) {
  698 + recomendacao = occurrence.getMapDescription().get(rn.getCode());
  699 + break;
  700 + }
  701 +
  702 + result.include("recomendacao", recomendacao);
  703 + result.include("rn", rn.getCode());
  704 + result.include("aReq", this.utilitiesProperties.get("notExibCrit"));
  705 + result.include("aReqIsCss", this.utilitiesProperties.get("reqCss"));
  706 + result.include("aReqIsW3c", this.utilitiesProperties.get("notExibCritW3c"));
  707 + url =
  708 + VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("urlAvaliada")
  709 + .toString().replaceAll("(https://)|(http://)", "");
  710 + result.include("url", url);
  711 +
  712 + try {
  713 +
  714 + result.include("urlFormatada", encodeURI(url));
  715 +
  716 + } catch (UnsupportedEncodingException e) {
  717 + e.printStackTrace();
  718 + }
  719 +
  720 + }
  721 +
  722 + private String encodeURI(String url) throws UnsupportedEncodingException {
  723 + return URLEncoder.encode(url, "UTF-8").replace("+", "%20").replace("%21", "!")
  724 + .replace("%27", "'").replace("%28", "(").replace("%29", ")").replace("%7E", "~");
  725 + }
  726 +
  727 + @Post("/exportar-detalhes-avaliacao")
  728 + public FileDownload exportarDetalhesAvaliacao(OccurrenceKey rn, int tiporel, boolean isError) {
  729 +
  730 + /* Cria um Map de parametros */
  731 + HashMap<String, Object> map = new HashMap<String, Object>();
  732 +
  733 + // List list = this.detalheAvaliacao.get(rn,isError).getCriterios();
  734 +
  735 + List<String> aReq = new ArrayList();
  736 + // List<Integer> index = new ArrayList();
  737 +
  738 + String[] crit = this.utilitiesProperties.get("notExibCrit").split(" ");
  739 +
  740 + for (String c : crit)
  741 + aReq.add(c.trim());
  742 +
  743 + List<Criterio> listCrit = this.detalheAvaliacao.get(rn, isError).getCriterios();
  744 +
  745 + List<Criterio> list = new ArrayList<DetalheAvaliacao.Criterio>();
  746 +
  747 + for (Criterio criterio : listCrit) {
  748 + if (aReq.contains(rn.getCode() + "." + criterio.getId()))
  749 + criterio.setLinhas(new ArrayList());
  750 +
  751 + if (criterio.getId() != null)
  752 + list.add(criterio);
  753 + }
  754 +
  755 + List<String> codigoFonte = new ArrayList();
  756 +
  757 + for (Occurrence occurrence : this.detalheAvaliacao.get(rn, isError).getOcorrencias()) {
  758 + if (!aReq.contains(rn.getCode() + "." + occurrence.getCriterio()))
  759 + codigoFonte.add(occurrence.getLine()
  760 + + ": "
  761 + + occurrence.getTag().replaceAll("&lt;", "<").replaceAll("&gt;", ">")
  762 + .replaceAll("&nbsp", " ") + "\n\n");
  763 + }
  764 + map.put("codigoFonte", codigoFonte);
  765 +
  766 + List<SummarizedOccurrence> ob =
  767 + (List<SummarizedOccurrence>) VRaptorRequestHolder.currentRequest().getServletContext()
  768 + .getAttribute("resultadoAvaliacao");
  769 + String recomendacao = "";
  770 +
  771 + for (SummarizedOccurrence occurrence : ob) {
  772 + recomendacao = occurrence.getMapDescription().get(rn.getCode());
  773 + break;
  774 + }
  775 +
  776 + map.put("rnAvaliada", recomendacao);
  777 + map.put("SUBREPORT_DIR", this.application.getRealPath("") + "/WEB-INF/templates-relatorios/");
  778 +
  779 + ManagerReport managerReport =
  780 + new ManagerReport(this.application.getRealPath("")
  781 + + "/WEB-INF/templates-relatorios/relatorio-detalhes-avaliacao.jrxml");
  782 +
  783 + String path = null;
  784 +
  785 + try {
  786 + path =
  787 + managerReport.gerarRelatorioDetalhesAvaliacao(list, map, tiporel,
  788 + "DetalhesRelatorioAvaliacao");
  789 + } catch (JRException e) {
  790 + e.printStackTrace();
  791 + } catch (IOException e) {
  792 + e.printStackTrace();
  793 + }
  794 +
  795 + File file = new File(path);
  796 +
  797 + return new FileDownload(file, managerReport.getContentType(), managerReport.getFileName());
  798 + }
  799 +
  800 + public void initEseloProperties(ServletContext servletContext) {
  801 + this.eseloProperties = new EseloProperties(servletContext);
  802 +
  803 + // Esconde a nota caso n�o esteja usando o ESELO
  804 + sem_nota = this.eseloProperties.getSem_nota("sem_nota");
  805 + VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("sem_nota", sem_nota);
  806 +
  807 + // Altera a mensagem caso n�o esteja usando o ESELO (Nota e Resumo da
  808 + // Avalia��o de Acessibilidade)
  809 + mensagem_avaliacao = this.eseloProperties.getMensagem_avaliacao("mensagem_avaliacao");
  810 + VRaptorRequestHolder.currentRequest().getServletContext()
  811 + .setAttribute("mensagem_avaliacao", mensagem_avaliacao);
  812 + }
  813 +
  814 + @Get("/servico-avaliacao-acessibilidade")
  815 + @Post("/servico-avaliacao-acessibilidade")
  816 + public void servicoAvaliacaoAcessibilidade(@QueryParam("url") String url, String tipoSaida) {
  817 +
  818 + //tipoSaida deve ser "json" ou "xml";
  819 + try {
  820 +
  821 + xml = new StringBuffer();
  822 +
  823 +
  824 + Validate validate = new Validate(this.validator);
  825 +
  826 + if (validate.url(url)) {
  827 +
  828 +
  829 + if (url.startsWith("www")) {
  830 + url = "http://" + url;
  831 + }
  832 +
  833 + WebChecker pagina = WebChecker.from(url).withGetRequest().execute();
  834 +
  835 + int[] errorsWarningsCss = avaliacaoBusiness.getErrorCount(true, url);
  836 + int[] errorsWarningsHtml = avaliacaoBusiness.getErrorCount(false, url);
  837 +
  838 + Checker checker = from(pagina.getContent(), url);
  839 +
  840 + checker.with(marking());
  841 + checker.with(content());
  842 + checker.with(presentation());
  843 + checker.with(multimedia());
  844 + checker.with(form());
  845 + checker.with(behavior());
  846 +
  847 + Pattern pp = Pattern.compile("(http://www.)?([a-z]*)(.)?");
  848 + Matcher mm = pp.matcher(url.toLowerCase().replace("https", "http"));
  849 +
  850 + if (mm.find()) {
  851 + this.tituloSite = "";
  852 + }
  853 +
  854 + ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument());
  855 +
  856 + this.tituloSite = conteudo.retornarTituloSiteAvaliado();
  857 +
  858 + Nota nota = null;
  859 +
  860 + List<Entry<OccurrenceKey, List<Occurrence>>> mapaListaOcorrencias =
  861 + avaliacaoBusiness.retornarCriteriosTeste(checker.check());
  862 +
  863 + nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(), url, mapaListaOcorrencias);
  864 +
  865 + this.sumarizarResultasNoResponse(checker.checkSumarized(), result);
  866 +
  867 + this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()),
  868 + errorsWarningsCss, errorsWarningsHtml);
  869 +
  870 +
  871 + this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();
  872 + List<SummarizedOccurrence> checkSumarized = checker.checkSumarized();
  873 +
  874 + avisosFerramentasHtmlCssW3c = new ArrayList<String>();
  875 + List<ResumoAvaliacao> resumoErrosAvisos = obterResumoAvaliacao();
  876 +
  877 + // pegar os dados e montar o xml
  878 + // List<Occurrence> listOcorrencias;
  879 + // Occurrence detalhe;
  880 + OccurrenceKey rn = null;
  881 + boolean type = false;
  882 + // boolean criterioAdicionar = false;
  883 + // String criterioAdicionado = "";
  884 + // String idCriterio = null;
  885 + int totalErros = 0;
  886 + int totalAvisos = 0;
  887 +
  888 + xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  889 + xml.append("<avaliacao-automatica>\n");
  890 + xml.append("<pagina-avaliada>\n");
  891 + xml.append("<titulo>" + this.tituloSite + "</titulo>\n");
  892 + xml.append("<tamanho>" + pagina.getContentLength() + "</tamanho>\n");
  893 + xml.append("<data-hora>" + this.dataHoraAvaliacao + "</data-hora>\n");
  894 + xml.append("</pagina-avaliada>\n");
  895 + xml.append("<resumo-avaliacao>\n");
  896 + xml.append("<nota-avaliacao>" + nota.getValor() + "</nota-avaliacao>\n");
  897 +
  898 + for (ResumoAvaliacao resumoAvaliacao : resumoErrosAvisos) {
  899 +
  900 +
  901 + xml.append("<secao>");
  902 + xml.append("<nome>" + resumoAvaliacao.getTipo().getDescription() + "</nome>\n");
  903 + xml.append("<quantidade-erro>" + resumoAvaliacao.getQuantidadeErros()
  904 + + "</quantidade-erro>\n");
  905 + xml.append("<quantidade-aviso>" + resumoAvaliacao.getQuantidadeAvisos()
  906 + + "</quantidade-aviso>\n");
  907 + xml.append("</secao>\n");
  908 +
  909 + totalErros += resumoAvaliacao.getQuantidadeErros();
  910 + totalAvisos += resumoAvaliacao.getQuantidadeAvisos();
  911 + }
  912 +
  913 + xml.append("<total-erros>" + totalErros + "</total-erros>\n");
  914 + xml.append("<total-avisos>" + totalAvisos + "</total-avisos>\n");
  915 + xml.append("</resumo-avaliacao>\n");
  916 +
  917 + String recomendacaoCompara = "";
  918 +
  919 + for (SummarizedOccurrence avaliacao : checkSumarized) {
  920 + rn = OccurrenceKey.valueOf(avaliacao.getCheckPoint());
  921 + type = avaliacao.isError();
  922 +
  923 + // if(!recomendacaoCompara.equalsIgnoreCase(avaliacao.getCheckPoint().toString()))
  924 + // {
  925 + if (!recomendacaoCompara.equalsIgnoreCase("")) {
  926 + xml.append("</recomendacao-avaliacao>\n");
  927 + }
  928 +
  929 + xml.append("<recomendacao-avaliacao>\n");
  930 + xml.append("<numero-recomendacao>" + avaliacao.getCheckPoint() + "</numero-recomendacao>\n");
  931 + xml.append("<erro-recomendacao>" + type + "</erro-recomendacao>\n");
  932 + xml.append("<descricao-recomendacao>" + avaliacao.getDescription()
  933 + + "</descricao-recomendacao>\n");
  934 + xml.append("<quantidade-recomendacao>" + avaliacao.getNumberOfOccurrences()
  935 + + "</quantidade-recomendacao>\n");
  936 + xml.append("<linhas-codigo-fonte-recomendacao>" + avaliacao.getStringLines()
  937 + + "</linhas-codigo-fonte-recomendacao>\n");
  938 + // }
  939 +
  940 +
  941 +
  942 + // Critérios iniciam aqui
  943 +
  944 + criarRelatorioCriterios(rn, type);
  945 +
  946 + // Critérios terminam aqui
  947 +
  948 +
  949 + recomendacaoCompara = avaliacao.getCheckPoint().toString();
  950 + }
  951 +
  952 + xml.append("</recomendacao-avaliacao>\n");
  953 +
  954 + xml.append("</avaliacao-automatica>\n");
198 955
199 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("titulosite", tituloSite); 956 + } else {
  957 + System.out.println("Enviar xml de erro");
  958 + }
200 959
201 - this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();  
202 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("data", dataHoraAvaliacao);  
203 -  
204 - result.of(this).avaliar(null, mark, content, presentation, multimedia, form, behavior, tiprel);  
205 -  
206 - } else {  
207 -  
208 - // Atribui �ncora para as mensagens de erros dos campos vazios  
209 - ancoraCampoVazio = "up_file";  
210 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("ancoraCampoVazio", ancoraCampoVazio);  
211 -  
212 - this.validator = validate.getMessage();  
213 - this.validator.onErrorUsePageOf(IndexController.class).index();  
214 - }  
215 -  
216 - } else {  
217 - // Atribui �ncora para as mensagens de erros dos campos vazios  
218 - ancoraCampoVazio = "up_file";  
219 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("ancoraCampoVazio", ancoraCampoVazio);  
220 -  
221 - this.validator = validate.getMessage();  
222 - this.validator.onErrorUsePageOf(IndexController.class).index();  
223 - }  
224 - }  
225 -  
226 - @Post("/avaliar")  
227 - public void avaliar(String url, boolean mark, boolean content,  
228 - boolean presentation, boolean multimedia, boolean form,  
229 - boolean behavior, int tiporel) {  
230 -  
231 - Validate validate = new Validate(this.validator);  
232 - if (validate.url(url)) {  
233 -  
234 - /*  
235 - * if(tiporel != 5)  
236 - * this.result.redirectTo(AvaliacaoController.class)  
237 - * .relatorioAvaliacao(url, mark, content, presentation, multimedia,  
238 - * form, behavior, tiporel, true);  
239 - */  
240 -  
241 - if (url.startsWith("www"))  
242 - url = "http://" + url;  
243 -  
244 - WebChecker pagina = WebChecker.from(url).withGetRequest().execute();  
245 -  
246 - int[] errorsWarningsCss = avaliacaoBusiness.getErrorCount(true, url);  
247 - int[] errorsWarningsHtml = avaliacaoBusiness.getErrorCount(false,url);  
248 -  
249 - Checker checker = from(pagina.getContent(), url);  
250 -  
251 - if (mark)checker.with(marking());  
252 - if (content)checker.with(content());  
253 - if (presentation)checker.with(presentation());  
254 - if (multimedia)checker.with(multimedia());  
255 - if (form)checker.with(form());  
256 - if (behavior)checker.with(behavior());  
257 -  
258 - Pattern pp = Pattern.compile("(http://www.)?([a-z]*)(.)?");  
259 - Matcher mm = pp.matcher(url.toLowerCase().replace("https", "http"));  
260 -  
261 - if (mm.find())  
262 -  
263 - this.tituloSite = "";  
264 -  
265 - ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument());  
266 -  
267 - this.tituloSite = conteudo.retornarTituloSiteAvaliado();  
268 -  
269 - result.include("titulosite", tituloSite);  
270 -  
271 - result.include("contentLenght", pagina.getContentLength());  
272 - result.include("url", url);  
273 - result.include("html", pagina.getParsedContent());  
274 -  
275 - Nota nota = null;  
276 -  
277 - if (!this.sem_nota.equalsIgnoreCase("sem_nota")) {  
278 -  
279 - List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias = avaliacaoBusiness.retornarCriteriosTeste(checker.check());  
280 - // Altera a cor de webaxscore de acordo a pontuacao  
281 - //nota = avaliacaoBusiness.obterNota(checker.checkSumarized(), url, mapaListaOcorrencias);  
282 -  
283 - nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(),url, mapaListaOcorrencias);  
284 -  
285 - if (nota.getValor() != null) {  
286 - DefinirCorWebaxscore(nota.getValor());  
287 -  
288 - VRaptorRequestHolder.currentRequest().getServletContext()  
289 - .setAttribute("webaxscore", webaxscore);  
290 - }  
291 -  
292 - }  
293 -  
294 - result.include("nota", nota);  
295 - this.sumarizarResultasNoResponse(checker.checkSumarized(), result);  
296 -  
297 - this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()),errorsWarningsCss, errorsWarningsHtml);  
298 -  
299 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("resultadoAvaliacao",checker.checkSumarized());  
300 -  
301 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("urlAvaliada", url);  
302 -  
303 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("contentLenght", pagina.getContentLength());  
304 -  
305 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("notaAvaliacao", nota);  
306 -  
307 - // Seta o valor do t�tulo no template  
308 - tituloPagina = "Resumo de avaliação por URI - ASES";  
309 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("tituloPagina", tituloPagina);  
310 -  
311 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("titulosite", tituloSite);  
312 -  
313 - this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();  
314 -  
315 - VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("data", dataHoraAvaliacao);  
316 -  
317 - avisosFerramentasHtmlCssW3c = new ArrayList<String>();  
318 -  
319 - validarFerramenta_cssnoAr(errorsWarningsCss);  
320 - validarFerramenta_htmlnoAr(errorsWarningsHtml);  
321 -  
322 - VRaptorRequestHolder  
323 - .currentRequest()  
324 - .getServletContext()  
325 - .setAttribute("avisosFerramentasHtmlCssW3c",  
326 - avisosFerramentasHtmlCssW3c);  
327 -  
328 - } else {  
329 - // Atribui �ncora para as mensagens de erros dos campos vazios  
330 - ancoraCampoVazio = "url";  
331 - VRaptorRequestHolder.currentRequest().getServletContext()  
332 - .setAttribute("ancoraCampoVazio", ancoraCampoVazio);  
333 -  
334 - this.validator = validate.getMessage();  
335 - this.validator.onErrorUsePageOf(IndexController.class).index();  
336 - }  
337 - }  
338 -  
339 - // Verifica se o site de avalia��o de sintaxe css encontra-se no ar  
340 - private void validarFerramenta_cssnoAr(int[] erros_avisos) {  
341 - if (erros_avisos[0] == -10 && erros_avisos[1] == -10) {  
342 -  
343 - avisosFerramentasHtmlCssW3c  
344 - .add("O avaliador de sintaxe css do w3c encontra-se indispon&iacute;vel, favor tentar mais tarde.");  
345 - }  
346 -  
347 - }  
348 -  
349 - // Verifica se o site de avalia��o de sintaxe html encontra-se no ar  
350 - private void validarFerramenta_htmlnoAr(int[] erros_avisos) {  
351 - if (erros_avisos[0] == -10 && erros_avisos[1] == -10) {  
352 - avisosFerramentasHtmlCssW3c  
353 - .add("O avaliador de sintaxe html do w3c encontra-se indispon&iacute;vel, favor tentar mais tarde.");  
354 - }  
355 - }  
356 -  
357 - @Get("/relatorioavaliacao")  
358 - @Post("/relatorioavaliacao")  
359 - public FileDownload relatorioAvaliacao(int tiporel) {  
360 -  
361 - List<SummarizedOccurrence> checkerList = (List<SummarizedOccurrence>) VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("resultadoAvaliacao");  
362 - String urlAvaliada = (String) VRaptorRequestHolder.currentRequest()  
363 - .getServletContext().getAttribute("urlAvaliada");  
364 - String contentLenght = (String) VRaptorRequestHolder.currentRequest()  
365 - .getServletContext().getAttribute("contentLenght");  
366 - this.sumarizarResultasNoResponse(checkerList, result);  
367 -  
368 - // ================================================ GERAR RELAT�RIO  
369 - // =============================================//  
370 -  
371 - /* Cria um Map de par�metros */  
372 - HashMap<String, Object> map = new HashMap<String, Object>();  
373 -  
374 - /* Obtem a nota */  
375 - // AvaliacaoBusinessImpl avaliacaoBusiness = new  
376 - // AvaliacaoBusinessImpl();  
377 - Nota nota = null;  
378 -  
379 - if (!this.sem_nota.equalsIgnoreCase("sem_nota"))  
380 - {  
381 - nota = (Nota) VRaptorRequestHolder.currentRequest()  
382 - .getServletContext().getAttribute("notaAvaliacao");  
383 -  
384 - map.put("pPercentualAses", nota.getValor());  
385 - }  
386 - else  
387 - {  
388 - map.put("pPercentualAses", "0");  
389 - }  
390 -  
391 - map.put("pPagina", urlAvaliada != "" ? urlAvaliada  
392 - : "Código Fonte ou Arquivo");  
393 -  
394 - if (urlAvaliada != "") {  
395 - Pattern pp = Pattern.compile("(http://www.)?([a-z]*)(.)?");  
396 - Matcher mm = pp.matcher(urlAvaliada.toLowerCase());  
397 -  
398 - if (mm.find())  
399 - map.put("pTitulo", VRaptorRequestHolder.currentRequest()  
400 - .getServletContext().getAttribute("titulosite"));  
401 -  
402 - } else  
403 - map.put("pTitulo", VRaptorRequestHolder.currentRequest()  
404 - .getServletContext().getAttribute("titulosite"));  
405 -  
406 - map.put("pTamanho", contentLenght + " Bytes");  
407 - dataHoraAvaliacao = (String) VRaptorRequestHolder.currentRequest()  
408 - .getServletContext().getAttribute("data");  
409 - map.put("pDataHoraAvaliacao", dataHoraAvaliacao);  
410 -  
411 - // Obtem Resumo da Avaliação  
412 - List<ResumoAvaliacao> resumoErrosAvisos = obterResumoAvaliacao();  
413 -  
414 - int totalErros = 0;  
415 - int totalAvisos = 0;  
416 -  
417 - for (ResumoAvaliacao resumo : resumoErrosAvisos) {  
418 - map.put(resumo.getTipo() + "_A", resumo.getQuantidadeAvisos());  
419 - map.put(resumo.getTipo() + "_E", resumo.getQuantidadeErros());  
420 - totalErros += resumo.getQuantidadeErros();  
421 - totalAvisos += resumo.getQuantidadeAvisos();  
422 - }  
423 -  
424 - map.put("TOTAL_E", totalErros);  
425 - map.put("TOTAL_A", totalAvisos);  
426 -  
427 - ManagerReport managerReport = new ManagerReport(  
428 - this.application.getRealPath("")  
429 - + "/WEB-INF/templates-relatorios/relatorio-avaliacao.jrxml");  
430 - String path = null;  
431 -  
432 - try {  
433 - path = managerReport.gerarRelatorio(checkerList, map, tiporel,  
434 - "RelatorioAvaliacao");  
435 - } catch (JRException e) {  
436 - e.printStackTrace();  
437 - } catch (IOException e) {  
438 - e.printStackTrace();  
439 - }  
440 - File file = new File(path);  
441 -  
442 - return new FileDownload(file, managerReport.getContentType(),  
443 - managerReport.getFileName());  
444 -  
445 - // =========================================== FIM GERAR RELAT�RIO  
446 - // =============================================//  
447 -  
448 - }  
449 -  
450 - @Post("/avaliar-codigo")  
451 - public void avaliarPlainText(String html, boolean mark, boolean content,  
452 - boolean presentation, boolean multimedia, boolean form,  
453 - boolean behavior, int tiporel) throws IOException {  
454 -  
455 - Validate validate = new Validate(this.validator);  
456 - if (validate.condigoFonte(html)) {  
457 -  
458 - /*  
459 - * if(tiporel != 5)  
460 - * this.result.redirectTo(AvaliacaoController.class)  
461 - * .relatorioAvaliacao(html, mark, content, presentation,  
462 - * multimedia, form, behavior, tiporel, false);  
463 - */  
464 -  
465 - Checker checker = from(html);  
466 -  
467 - if (mark)  
468 - checker.with(marking());  
469 - if (content)  
470 - checker.with(content());  
471 - if (presentation)  
472 - checker.with(presentation());  
473 - if (multimedia)  
474 - checker.with(multimedia());  
475 - if (form)  
476 - checker.with(form());  
477 - if (behavior)  
478 - checker.with(behavior());  
479 -  
480 - html = html.replaceAll("<", "&lt;");  
481 - html = html.replaceAll(">", "&gt;");  
482 - html = html.replaceAll(" ", "&nbsp");  
483 -  
484 - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");  
485 -  
486 - result.include("contentLenght",String.valueOf(html.getBytes("UTF-8").length));  
487 - result.include("html", html);  
488 - this.tituloSite = "";  
489 -  
490 - ContentEvaluation conteudo = new ContentEvaluation(  
491 - checker.getDocument());  
492 -  
493 - this.tituloSite = conteudo.retornarTituloSiteAvaliado();  
494 -  
495 - result.include("titulosite", tituloSite);  
496 -  
497 - Nota nota = null;  
498 -  
499 - if (!this.sem_nota.equalsIgnoreCase("sem_nota")) {  
500 -  
501 - List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias = avaliacaoBusiness.retornarCriteriosTeste(checker.check());  
502 - //nota = avaliacaoBusiness.obterNota(checker.checkSumarized(), tituloSite + " - " + sdf.format(new Date()),mapaListaOcorrencias);  
503 - nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(),tituloSite + " - " + sdf.format(new Date()), mapaListaOcorrencias);  
504 - // Altera a cor de webaxscore de acordo a pontuacao  
505 -  
506 - if (nota.getValor() != null) {  
507 - DefinirCorWebaxscore(nota.getValor());  
508 -  
509 - VRaptorRequestHolder.currentRequest().getServletContext()  
510 - .setAttribute("webaxscore", webaxscore);  
511 - }  
512 -  
513 -  
514 - }  
515 -  
516 - result.include("nota", nota);  
517 - this.sumarizarResultasNoResponse(checker.checkSumarized(), result);  
518 - this.detalheAvaliacao.inicializar(avaliacaoBusiness  
519 - .retornarCriterios(checker.check()));  
520 -  
521 - VRaptorRequestHolder  
522 - .currentRequest()  
523 - .getServletContext()  
524 - .setAttribute("resultadoAvaliacao",  
525 - checker.checkSumarized());  
526 - VRaptorRequestHolder.currentRequest().getServletContext()  
527 - .setAttribute("urlAvaliada", "");  
528 - VRaptorRequestHolder  
529 - .currentRequest()  
530 - .getServletContext()  
531 - .setAttribute("contentLenght",  
532 - String.valueOf(html.getBytes("UTF-8").length));  
533 - VRaptorRequestHolder.currentRequest().getServletContext()  
534 - .setAttribute("notaAvaliacao", nota);  
535 -  
536 - // Seta o valor do t�tulo no template  
537 - tituloPagina = "Resumo de avaliação por código fonte - ASES";  
538 - VRaptorRequestHolder.currentRequest().getServletContext()  
539 - .setAttribute("tituloPagina", tituloPagina);  
540 - result.of(this).avaliar(null, mark, content, presentation,  
541 - multimedia, form, behavior, tiporel);  
542 -  
543 - VRaptorRequestHolder.currentRequest().getServletContext()  
544 - .setAttribute("titulosite", tituloSite);  
545 -  
546 - this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();  
547 - VRaptorRequestHolder.currentRequest().getServletContext()  
548 - .setAttribute("data", dataHoraAvaliacao);  
549 -  
550 - } else {  
551 - // Atribui �ncora para as mensagens de erros dos campos vazios  
552 - ancoraCampoVazio = "input";  
553 - VRaptorRequestHolder.currentRequest().getServletContext()  
554 - .setAttribute("ancoraCampoVazio", ancoraCampoVazio);  
555 -  
556 - this.validator = validate.getMessage();  
557 - this.validator.onErrorUsePageOf(IndexController.class).index();  
558 - }  
559 - }  
560 -  
561 - private void sumarizarResultasNoResponse(  
562 - List<SummarizedOccurrence> resultadoAvaliacao, Result result) {  
563 -  
564 - for (SummarizedOccurrence occurrence : resultadoAvaliacao) {  
565 - if (ocorrencias.get(occurrence.getType()) == null)  
566 - ocorrencias.put(occurrence.getType(),  
567 - new ArrayList<SummarizedOccurrence>());  
568 -  
569 - ocorrencias.get(occurrence.getType()).add(occurrence);  
570 - }  
571 -  
572 - for (Entry<OccurrenceClassification, List<SummarizedOccurrence>> entry : ocorrencias.entrySet()) {  
573 - List<SummarizedOccurrence> ocorrenciasComputadas = entry.getValue();  
574 - Collections.sort(ocorrenciasComputadas);  
575 -  
576 - result.include("LISTA_" + entry.getKey().toString(),  
577 - ocorrenciasComputadas);  
578 - }  
579 -  
580 - List<ResumoAvaliacao> resumoErrosAvisos = obterResumoAvaliacao();  
581 - int totalErros = 0;  
582 - int totalAvisos = 0;  
583 -  
584 - for (ResumoAvaliacao resumo : resumoErrosAvisos) {  
585 - totalErros += resumo.getQuantidadeErros();  
586 - totalAvisos += resumo.getQuantidadeAvisos();  
587 - }  
588 -  
589 - result.include("totalErros", totalErros);  
590 - result.include("totalAvisos", totalAvisos);  
591 - result.include("listaResumo", resumoErrosAvisos);  
592 - result.include("data", DateUtil.dataHoraAtual());  
593 -  
594 - }  
595 -  
596 - private List<ResumoAvaliacao> obterResumoAvaliacao() {  
597 - List<ResumoAvaliacao> resultado = new ArrayList<ResumoAvaliacao>();  
598 -  
599 - for (OccurrenceClassification classificacao : OccurrenceClassification  
600 - .values()) {  
601 -  
602 - int erros = 0;  
603 - int avisos = 0;  
604 -  
605 - List<SummarizedOccurrence> listaOcorrencias = ocorrencias  
606 - .get(classificacao);  
607 -  
608 - if (listaOcorrencias != null) {  
609 - for (SummarizedOccurrence ocorrencia : ocorrencias  
610 - .get(classificacao)) {  
611 -  
612 - if (ocorrencia.isError())  
613 - for (int line : ocorrencia.getLines())  
614 - erros++;  
615 - else  
616 - for (int line : ocorrencia.getLines())  
617 - avisos++;  
618 -  
619 - }  
620 - }  
621 -  
622 - resultado.add(new ResumoAvaliacao(classificacao, erros, avisos));  
623 - }  
624 -  
625 - return resultado;  
626 - }  
627 -  
628 -  
629 - //Gibran  
630 - public void obterDetalhes(OccurrenceKey rn, boolean type) {  
631 -  
632 -  
633 - List<Occurrence> listOcorrencias = this.detalheAvaliacao.get(rn, type).getOcorrencias();  
634 -  
635 -  
636 -  
637 - Collections.sort(listOcorrencias, new Comparator<Occurrence>() {  
638 - public int compare(Occurrence occurrence1, Occurrence occurrence2) {  
639 - return occurrence1.getLine().compareTo(occurrence2.getLine());  
640 - }  
641 - });  
642 -  
643 -  
644 - result.include("detalhe", this.detalheAvaliacao.get(rn, type));  
645 - }  
646 -  
647 - @Path("/detalhes-avaliacao/{rn}/{type}")  
648 - public void detalhesAvaliacao(OccurrenceKey rn, boolean type) {  
649 - String url = "";  
650 - tituloPagina = "Detalhes da avalição - ASES";  
651 - VRaptorRequestHolder.currentRequest().getServletContext()  
652 - .setAttribute("tituloPagina", tituloPagina);  
653 -  
654 - List<Occurrence> listOcorrencias = this.detalheAvaliacao.get(rn, type).getOcorrencias();  
655 -  
656 -  
657 - // Sorting  
658 - Collections.sort(listOcorrencias, new Comparator<Occurrence>() {  
659 - public int compare(Occurrence occurrence1, Occurrence occurrence2) {  
660 - return occurrence1.getLine().compareTo(occurrence2.getLine());  
661 - }  
662 - });  
663 -  
664 - result.include("detalhe", this.detalheAvaliacao.get(rn, type));  
665 - result.include("listOcorrencia", listOcorrencias);  
666 -  
667 - result.include("isError", type);  
668 - if (type) {  
669 - result.include("qtdOcorrenciasCss",  
670 - this.detalheAvaliacao.getErrorsCss());  
671 - result.include("qtdOcorrenciasHtml",  
672 - this.detalheAvaliacao.getErrorsHtml());  
673 - } else {  
674 - result.include("qtdOcorrenciasCss",  
675 - this.detalheAvaliacao.getWarningsCss());  
676 - result.include("qtdOcorrenciasHtml",  
677 - this.detalheAvaliacao.getWarningsHtml());  
678 - }  
679 -  
680 - List<SummarizedOccurrence> ob = (List<SummarizedOccurrence>) VRaptorRequestHolder.currentRequest().getServletContext().getAttribute("resultadoAvaliacao");  
681 - String recomendacao = "";  
682 -  
683 -  
684 - for (SummarizedOccurrence occurrence : ob) {  
685 - recomendacao = occurrence.getMapDescription().get(rn.getCode());  
686 - break;  
687 - }  
688 -  
689 - result.include("recomendacao", recomendacao);  
690 - result.include("rn", rn.getCode());  
691 - result.include("aReq", this.utilitiesProperties.get("notExibCrit"));  
692 - result.include("aReqIsCss", this.utilitiesProperties.get("reqCss"));  
693 - result.include("aReqIsW3c",  
694 - this.utilitiesProperties.get("notExibCritW3c"));  
695 - url = VRaptorRequestHolder.currentRequest()  
696 - .getServletContext().getAttribute("urlAvaliada").toString()  
697 - .replaceAll("(https://)|(http://)", "");  
698 - result.include("url", url);  
699 -  
700 - try {  
701 -  
702 - result.include("urlFormatada", encodeURI(url));  
703 -  
704 - } catch (UnsupportedEncodingException e) {  
705 - e.printStackTrace();  
706 - }  
707 -  
708 - }  
709 -  
710 - private String encodeURI(String url) throws UnsupportedEncodingException {  
711 - return URLEncoder.encode(url, "UTF-8")  
712 - .replace("+", "%20")  
713 - .replace("%21", "!")  
714 - .replace("%27", "'")  
715 - .replace("%28", "(")  
716 - .replace("%29", ")")  
717 - .replace("%7E", "~");  
718 - }  
719 -  
720 - @Post("/exportar-detalhes-avaliacao")  
721 - public FileDownload exportarDetalhesAvaliacao(OccurrenceKey rn,  
722 - int tiporel, boolean isError) {  
723 -  
724 - /* Cria um Map de parametros */  
725 - HashMap<String, Object> map = new HashMap<String, Object>();  
726 -  
727 - // List list = this.detalheAvaliacao.get(rn,isError).getCriterios();  
728 -  
729 - List<String> aReq = new ArrayList();  
730 - // List<Integer> index = new ArrayList();  
731 -  
732 - String[] crit = this.utilitiesProperties.get("notExibCrit").split(" ");  
733 -  
734 - for (String c : crit)  
735 - aReq.add(c.trim());  
736 -  
737 - List<Criterio> listCrit = this.detalheAvaliacao.get(rn, isError)  
738 - .getCriterios();  
739 -  
740 - List<Criterio> list = new ArrayList<DetalheAvaliacao.Criterio>();  
741 -  
742 - for (Criterio criterio : listCrit) {  
743 - if (aReq.contains(rn.getCode() + "." + criterio.getId()))  
744 - criterio.setLinhas(new ArrayList());  
745 -  
746 - if (criterio.getId() != null)  
747 - list.add(criterio);  
748 - }  
749 -  
750 - List<String> codigoFonte = new ArrayList();  
751 -  
752 - for (Occurrence occurrence : this.detalheAvaliacao.get(rn, isError)  
753 - .getOcorrencias()) {  
754 - if (!aReq.contains(rn.getCode() + "." + occurrence.getCriterio()))  
755 - codigoFonte.add(occurrence.getLine()  
756 - + ": "  
757 - + occurrence.getTag().replaceAll("&lt;", "<")  
758 - .replaceAll("&gt;", ">")  
759 - .replaceAll("&nbsp", " ") + "\n\n");  
760 - }  
761 - map.put("codigoFonte", codigoFonte);  
762 -  
763 - List<SummarizedOccurrence> ob = (List<SummarizedOccurrence>) VRaptorRequestHolder  
764 - .currentRequest().getServletContext()  
765 - .getAttribute("resultadoAvaliacao");  
766 - String recomendacao = "";  
767 -  
768 - for (SummarizedOccurrence occurrence : ob) {  
769 - recomendacao = occurrence.getMapDescription().get(rn.getCode());  
770 - break;  
771 - }  
772 -  
773 - map.put("rnAvaliada", recomendacao);  
774 - map.put("SUBREPORT_DIR", this.application.getRealPath("")  
775 - + "/WEB-INF/templates-relatorios/");  
776 -  
777 - ManagerReport managerReport = new ManagerReport(  
778 - this.application.getRealPath("")  
779 - + "/WEB-INF/templates-relatorios/relatorio-detalhes-avaliacao.jrxml");  
780 -  
781 - String path = null;  
782 -  
783 - try {  
784 - path = managerReport.gerarRelatorioDetalhesAvaliacao(list, map,  
785 - tiporel, "DetalhesRelatorioAvaliacao");  
786 - } catch (JRException e) {  
787 - e.printStackTrace();  
788 - } catch (IOException e) {  
789 - e.printStackTrace();  
790 - }  
791 -  
792 - File file = new File(path);  
793 -  
794 - return new FileDownload(file, managerReport.getContentType(),  
795 - managerReport.getFileName());  
796 - }  
797 -  
798 - public void initEseloProperties(ServletContext servletContext) {  
799 - this.eseloProperties = new EseloProperties(servletContext);  
800 -  
801 - // Esconde a nota caso n�o esteja usando o ESELO  
802 - sem_nota = this.eseloProperties.getSem_nota("sem_nota");  
803 - VRaptorRequestHolder.currentRequest().getServletContext()  
804 - .setAttribute("sem_nota", sem_nota);  
805 -  
806 - // Altera a mensagem caso n�o esteja usando o ESELO (Nota e Resumo da  
807 - // Avalia��o de Acessibilidade)  
808 - mensagem_avaliacao = this.eseloProperties  
809 - .getMensagem_avaliacao("mensagem_avaliacao");  
810 - VRaptorRequestHolder.currentRequest().getServletContext()  
811 - .setAttribute("mensagem_avaliacao", mensagem_avaliacao);  
812 - }  
813 -  
814 - @Get("/servico-avaliacao-acessibilidade")  
815 - @Post("/servico-avaliacao-acessibilidade")  
816 - public void servicoAvaliacaoAcessibilidade(@QueryParam("url") String url) {  
817 -  
818 - xml = new StringBuffer();  
819 -  
820 -  
821 - Validate validate = new Validate(this.validator);  
822 -  
823 - if (validate.url(url)) {  
824 -  
825 -  
826 - if (url.startsWith("www"))  
827 - {  
828 - url = "http://" + url;  
829 - }  
830 -  
831 - WebChecker pagina = WebChecker.from(url).withGetRequest().execute();  
832 -  
833 - int[] errorsWarningsCss = avaliacaoBusiness.getErrorCount(true, url);  
834 - int[] errorsWarningsHtml = avaliacaoBusiness.getErrorCount(false,url);  
835 -  
836 - Checker checker = from(pagina.getContent(), url);  
837 -  
838 - checker.with(marking());  
839 - checker.with(content());  
840 - checker.with(presentation());  
841 - checker.with(multimedia());  
842 - checker.with(form());  
843 - checker.with(behavior());  
844 -  
845 - Pattern pp = Pattern.compile("(http://www.)?([a-z]*)(.)?");  
846 - Matcher mm = pp.matcher(url.toLowerCase().replace("https", "http"));  
847 -  
848 - if (mm.find())  
849 - {  
850 - this.tituloSite = "";  
851 - }  
852 -  
853 - ContentEvaluation conteudo = new ContentEvaluation(checker.getDocument());  
854 -  
855 - this.tituloSite = conteudo.retornarTituloSiteAvaliado();  
856 -  
857 - Nota nota = null;  
858 -  
859 - List<Entry<OccurrenceKey,List<Occurrence>>> mapaListaOcorrencias = avaliacaoBusiness.retornarCriteriosTeste(checker.check());  
860 -  
861 - nota = avaliacaoBusiness.obterNotaEselo(checker.getDocument(),url, mapaListaOcorrencias);  
862 -  
863 - this.sumarizarResultasNoResponse(checker.checkSumarized(), result);  
864 -  
865 - this.detalheAvaliacao.inicializar(avaliacaoBusiness.retornarCriterios(checker.check()),errorsWarningsCss, errorsWarningsHtml);  
866 -  
867 -  
868 - this.dataHoraAvaliacao = (String) DateUtil.dataHoraAtual();  
869 - List<SummarizedOccurrence> checkSumarized = checker.checkSumarized();  
870 -  
871 - avisosFerramentasHtmlCssW3c = new ArrayList<String>();  
872 - List<ResumoAvaliacao> resumoErrosAvisos = obterResumoAvaliacao();  
873 -  
874 - //pegar os dados e montar o xml  
875 - //List<Occurrence> listOcorrencias;  
876 - //Occurrence detalhe;  
877 - OccurrenceKey rn = null;  
878 - boolean type = false;  
879 - //boolean criterioAdicionar = false;  
880 - //String criterioAdicionado = "";  
881 - //String idCriterio = null;  
882 - int totalErros = 0;  
883 - int totalAvisos = 0;  
884 -  
885 - xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");  
886 - xml.append("<avaliacao-automatica>\n");  
887 - xml.append("<pagina-avaliada>\n");  
888 - xml.append("<titulo>" + this.tituloSite + "</titulo>\n");  
889 - xml.append("<tamanho>" + pagina.getContentLength() + "</tamanho>\n");  
890 - xml.append("<data-hora>" + this.dataHoraAvaliacao + "</data-hora>\n");  
891 - xml.append("</pagina-avaliada>\n");  
892 - xml.append("<resumo-avaliacao>\n");  
893 - xml.append("<nota-avaliacao>" + nota.getValor() + "</nota-avaliacao>\n");  
894 -  
895 - for (ResumoAvaliacao resumoAvaliacao : resumoErrosAvisos) {  
896 -  
897 -  
898 - xml.append("<secao>");  
899 - xml.append("<nome>" + resumoAvaliacao.getTipo().getDescription() + "</nome>\n");  
900 - xml.append("<quantidade-erro>" + resumoAvaliacao.getQuantidadeErros() + "</quantidade-erro>\n");  
901 - xml.append("<quantidade-aviso>" + resumoAvaliacao.getQuantidadeAvisos() + "</quantidade-aviso>\n");  
902 - xml.append("</secao>\n");  
903 -  
904 - totalErros += resumoAvaliacao.getQuantidadeErros();  
905 - totalAvisos += resumoAvaliacao.getQuantidadeAvisos();  
906 - }  
907 -  
908 - xml.append("<total-erros>"+ totalErros +"</total-erros>\n");  
909 - xml.append("<total-avisos>"+ totalAvisos +"</total-avisos>\n");  
910 - xml.append("</resumo-avaliacao>\n");  
911 -  
912 - String recomendacaoCompara = "";  
913 -  
914 - for (SummarizedOccurrence avaliacao : checkSumarized)  
915 - {  
916 - rn = OccurrenceKey.valueOf(avaliacao.getCheckPoint());  
917 - type = avaliacao.isError();  
918 -  
919 - //if(!recomendacaoCompara.equalsIgnoreCase(avaliacao.getCheckPoint().toString()))  
920 - //{  
921 - if(!recomendacaoCompara.equalsIgnoreCase(""))  
922 - {  
923 - xml.append("</recomendacao-avaliacao>\n");  
924 - }  
925 -  
926 - xml.append("<recomendacao-avaliacao>\n");  
927 - xml.append("<numero-recomendacao>" + avaliacao.getCheckPoint() + "</numero-recomendacao>\n");  
928 - xml.append("<erro-recomendacao>" + type + "</erro-recomendacao>\n");  
929 - xml.append("<descricao-recomendacao>" + avaliacao.getDescription() + "</descricao-recomendacao>\n");  
930 - xml.append("<quantidade-recomendacao>" + avaliacao.getNumberOfOccurrences() + "</quantidade-recomendacao>\n");  
931 - xml.append("<linhas-codigo-fonte-recomendacao>" + avaliacao.getStringLines() + "</linhas-codigo-fonte-recomendacao>\n");  
932 - //}  
933 -  
934 -  
935 -  
936 - //Critérios iniciam aqui  
937 -  
938 - criarRelatorioCriterios(rn,type);  
939 -  
940 - //Critérios terminam aqui  
941 -  
942 -  
943 - recomendacaoCompara = avaliacao.getCheckPoint().toString();  
944 - }  
945 -  
946 - xml.append("</recomendacao-avaliacao>\n");  
947 -  
948 - xml.append("</avaliacao-automatica>\n");  
949 -  
950 - } else {  
951 - System.out.println("Enviar xml de erro");  
952 - }  
953 - result.include("testeWeb", xml);  
954 -  
955 - }  
956 -  
957 - public void criarRelatorioCriterios(OccurrenceKey rn, boolean isError) {  
958 -  
959 - boolean recomendacao1_1_1Adicionada = false;  
960 - boolean recomendacao1_1_2Adicionada = false;  
961 -  
962 - /* Cria um Map de parametros */  
963 - //HashMap<String, Object> map = new HashMap<String, Object>();  
964 -  
965 - // List list = this.detalheAvaliacao.get(rn,isError).getCriterios();  
966 -  
967 - //List<String> aReq = new ArrayList();  
968 - // List<Integer> index = new ArrayList();  
969 -  
970 - //String[] crit = this.utilitiesProperties.get("notExibCrit").split(" ");  
971 -  
972 - //for (String c : crit)  
973 - //{  
974 - // aReq.add(c.trim());  
975 - //}  
976 -  
977 - //List<Criterio> listCrit = this.detalheAvaliacao.get(rn, isError).getCriterios();  
978 -  
979 - //List<Criterio> list = new ArrayList<DetalheAvaliacao.Criterio>();  
980 -  
981 - /*for (Criterio criterio : listCrit) {  
982 - if (aReq.contains(rn.getCode() + "." + criterio.getId()))  
983 - {  
984 - criterio.setLinhas(new ArrayList());  
985 - }  
986 -  
987 - if (criterio.getId() != null)  
988 - {  
989 - list.add(criterio);  
990 - }  
991 - }*/  
992 -  
993 - String codigoFonte = "";  
994 - String criterioCompara = "";  
995 - String numeroCriterio = "";  
996 -  
997 -  
998 - for (Occurrence occurrence : this.detalheAvaliacao.get(rn, isError).getOcorrencias())  
999 - {  
1000 -  
1001 - numeroCriterio = occurrence.getCriterio();  
1002 -  
1003 - //if (!aReq.contains(rn.getCode() + "." + numeroCriterio))  
1004 - //{  
1005 -  
1006 - if(!rn.getCode().toString().equalsIgnoreCase("1.1") || !isError)  
1007 - {  
1008 - if(rn.getCode().toString().equalsIgnoreCase("1.1") && numeroCriterio.equalsIgnoreCase("7"))  
1009 - {  
1010 - codigoFonte = "Serviço de validação de HTML do W3C";  
1011 - }  
1012 - else if(rn.getCode().toString().equalsIgnoreCase("1.1") && numeroCriterio.equalsIgnoreCase("8"))  
1013 - {  
1014 - codigoFonte = "Serviço de validação de CSS do W3C";  
1015 - }  
1016 - else  
1017 - {  
1018 - codigoFonte = occurrence.getTag().replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&nbsp", " ");  
1019 - }  
1020 -  
1021 - if(!criterioCompara.equalsIgnoreCase(occurrence.getCriterio().toString()))  
1022 - {  
1023 - if(!criterioCompara.equalsIgnoreCase(""))  
1024 - {  
1025 - System.out.println("</criterio>\n");  
1026 - xml.append("</criterio>\n");  
1027 - }  
1028 -  
1029 -  
1030 - xml.append("<criterio>\n");  
1031 - xml.append("<numero-criterio>" + numeroCriterio + "</numero-criterio>\n");  
1032 - xml.append("<nome-criterio>" + criterioProperties.getDescricao(rn.getCode() + "." + numeroCriterio) + "</nome-criterio>\n");  
1033 - xml.append("<erro-criterio>" + occurrence.isError() + "</tipo-criterio>\n");  
1034 - xml.append("<quantidade-criterio>" + verificaQuantidadeCriterio(rn, isError, numeroCriterio) + "</quantidade-criterio>\n");  
1035 - xml.append("<codigo-fonte-criterio>\n");  
1036 - xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");  
1037 - xml.append("<conteudo-linha><![CDATA[" + codigoFonte + "]]></conteudo-linha>\n");  
1038 - xml.append("</codigo-fonte-criterio>\n");  
1039 -  
1040 -  
1041 - criterioCompara = occurrence.getCriterio();  
1042 - }else  
1043 - {  
1044 - xml.append("<codigo-fonte-criterio>\n");  
1045 - xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");  
1046 - xml.append("<conteudo-linha><![CDATA[" + occurrence.getTag().replaceAll("&lt;", "<")  
1047 - .replaceAll("&gt;", ">").replaceAll("&nbsp", " ") + "]]></conteudo-linha>\n");  
1048 - xml.append("</codigo-fonte-criterio>\n");  
1049 - }  
1050 -  
1051 - }  
1052 - else  
1053 - {  
1054 - if(numeroCriterio.equalsIgnoreCase("1") && !recomendacao1_1_1Adicionada)  
1055 - {  
1056 - if(!criterioCompara.equalsIgnoreCase(""))  
1057 - {  
1058 - xml.append("</criterio>\n");  
1059 - }  
1060 - xml.append("<criterio>\n");  
1061 - xml.append("<numero-criterio>" + numeroCriterio + "</numero-criterio>\n");  
1062 - xml.append("<nome-criterio>" + criterioProperties.getDescricao(rn.getCode() + "." + numeroCriterio) + "</nome-criterio>\n");  
1063 - xml.append("<erro-criterio>" + occurrence.isError() + "</tipo-criterio>\n");  
1064 - xml.append("<quantidade-criterio>" + verificaQuantidadeCriterio(rn, isError, numeroCriterio) + "</quantidade-criterio>\n");  
1065 - xml.append("<codigo-fonte-criterio>\n");  
1066 - xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");  
1067 - xml.append("<conteudo-linha>Serviço de validação de HTML do W3C</conteudo-linha>\n");  
1068 - xml.append("</codigo-fonte-criterio>\n");  
1069 -  
1070 - criterioCompara = occurrence.getCriterio();  
1071 - recomendacao1_1_1Adicionada = true;  
1072 - }  
1073 -  
1074 - if(numeroCriterio.equalsIgnoreCase("2") && !recomendacao1_1_2Adicionada)  
1075 - {  
1076 - if(!criterioCompara.equalsIgnoreCase(""))  
1077 - {  
1078 - System.out.println("</criterio>\n");  
1079 - xml.append("</criterio>\n");  
1080 - }  
1081 -  
1082 - xml.append("<criterio>\n");  
1083 - xml.append("<numero-criterio>" + numeroCriterio + "</numero-criterio>\n");  
1084 - xml.append("<nome-criterio>" + criterioProperties.getDescricao(rn.getCode() + "." + numeroCriterio) + "</nome-criterio>\n");  
1085 - xml.append("<erro-criterio>" + occurrence.isError() + "</tipo-criterio>\n");  
1086 - xml.append("<quantidade-criterio>" + verificaQuantidadeCriterio(rn, isError, numeroCriterio) + "</quantidade-criterio>\n");  
1087 - xml.append("<codigo-fonte-criterio>\n");  
1088 - xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");  
1089 - xml.append("<conteudo-linha>Serviço de validação de CSS do W3C</conteudo-linha>\n");  
1090 - xml.append("</codigo-fonte-criterio>\n");  
1091 -  
1092 - criterioCompara = occurrence.getCriterio();  
1093 - recomendacao1_1_2Adicionada = true;  
1094 - }  
1095 -  
1096 - }  
1097 - //}  
1098 - }  
1099 -  
1100 - xml.append("</criterio>\n");  
1101 -  
1102 - }  
1103 -  
1104 - private Integer verificaQuantidadeCriterio(OccurrenceKey rn, boolean isError, String numeroCriterio)  
1105 - {  
1106 - Integer quantidadeCriterios = 0;  
1107 -  
1108 - for (Occurrence occurrence2 : this.detalheAvaliacao.get(rn, isError).getOcorrencias())  
1109 - {  
1110 - if(occurrence2.getCriterio().toString().equalsIgnoreCase(numeroCriterio))  
1111 - {  
1112 - quantidadeCriterios++;  
1113 - }  
1114 - }  
1115 -  
1116 - return quantidadeCriterios;  
1117 - }  
1118 -  
1119 -}  
1120 \ No newline at end of file 960 \ No newline at end of file
  961 + if(tipoSaida.equalsIgnoreCase("json"))
  962 + {
  963 + JSONObject soapDatainJsonObject = XML.toJSONObject(xml.toString());
  964 + result.include("saidaWebService", soapDatainJsonObject);
  965 + }
  966 + else if(tipoSaida.equalsIgnoreCase("xml"))
  967 + {
  968 + result.include("saidaWebService", xml);
  969 + }
  970 + } catch (Exception e) {
  971 + e.printStackTrace();
  972 + result.include("saidaWebService", "");
  973 + }
  974 + }
  975 +
  976 + public void criarRelatorioCriterios(OccurrenceKey rn, boolean isError) {
  977 +
  978 + boolean recomendacao1_1_1Adicionada = false;
  979 + boolean recomendacao1_1_2Adicionada = false;
  980 +
  981 + /* Cria um Map de parametros */
  982 + // HashMap<String, Object> map = new HashMap<String, Object>();
  983 +
  984 + // List list = this.detalheAvaliacao.get(rn,isError).getCriterios();
  985 +
  986 + // List<String> aReq = new ArrayList();
  987 + // List<Integer> index = new ArrayList();
  988 +
  989 + // String[] crit = this.utilitiesProperties.get("notExibCrit").split(" ");
  990 +
  991 + // for (String c : crit)
  992 + // {
  993 + // aReq.add(c.trim());
  994 + // }
  995 +
  996 + // List<Criterio> listCrit = this.detalheAvaliacao.get(rn, isError).getCriterios();
  997 +
  998 + // List<Criterio> list = new ArrayList<DetalheAvaliacao.Criterio>();
  999 +
  1000 + /*
  1001 + * for (Criterio criterio : listCrit) { if (aReq.contains(rn.getCode() + "." +
  1002 + * criterio.getId())) { criterio.setLinhas(new ArrayList()); }
  1003 + *
  1004 + * if (criterio.getId() != null) { list.add(criterio); } }
  1005 + */
  1006 +
  1007 + String codigoFonte = "";
  1008 + String criterioCompara = "";
  1009 + String numeroCriterio = "";
  1010 +
  1011 +
  1012 + for (Occurrence occurrence : this.detalheAvaliacao.get(rn, isError).getOcorrencias()) {
  1013 +
  1014 + numeroCriterio = occurrence.getCriterio();
  1015 +
  1016 + // if (!aReq.contains(rn.getCode() + "." + numeroCriterio))
  1017 + // {
  1018 +
  1019 + if (!rn.getCode().toString().equalsIgnoreCase("1.1") || !isError) {
  1020 + if (rn.getCode().toString().equalsIgnoreCase("1.1") && numeroCriterio.equalsIgnoreCase("7")) {
  1021 + codigoFonte = "Serviço de validação de HTML do W3C";
  1022 + } else if (rn.getCode().toString().equalsIgnoreCase("1.1")
  1023 + && numeroCriterio.equalsIgnoreCase("8")) {
  1024 + codigoFonte = "Serviço de validação de CSS do W3C";
  1025 + } else {
  1026 + codigoFonte =
  1027 + occurrence.getTag().replaceAll("&lt;", "<").replaceAll("&gt;", ">")
  1028 + .replaceAll("&nbsp", " ");
  1029 + }
  1030 +
  1031 + if (!criterioCompara.equalsIgnoreCase(occurrence.getCriterio().toString())) {
  1032 + if (!criterioCompara.equalsIgnoreCase("")) {
  1033 + xml.append("</criterio>\n");
  1034 + }
  1035 +
  1036 +
  1037 + xml.append("<criterio>\n");
  1038 + xml.append("<numero-criterio>" + numeroCriterio + "</numero-criterio>\n");
  1039 + xml.append("<nome-criterio>"
  1040 + + criterioProperties.getDescricao(rn.getCode() + "." + numeroCriterio)
  1041 + + "</nome-criterio>\n");
  1042 + xml.append("<erro-criterio>" + occurrence.isError() + "</erro-criterio>\n");
  1043 + xml.append("<quantidade-criterio>"
  1044 + + verificaQuantidadeCriterio(rn, isError, numeroCriterio)
  1045 + + "</quantidade-criterio>\n");
  1046 + xml.append("<codigo-fonte-criterio>\n");
  1047 + xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");
  1048 + xml.append("<conteudo-linha><![CDATA[" + codigoFonte + "]]></conteudo-linha>\n");
  1049 + xml.append("</codigo-fonte-criterio>\n");
  1050 +
  1051 +
  1052 + criterioCompara = occurrence.getCriterio();
  1053 + } else {
  1054 + xml.append("<codigo-fonte-criterio>\n");
  1055 + xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");
  1056 + xml.append("<conteudo-linha><![CDATA["
  1057 + + occurrence.getTag().replaceAll("&lt;", "<").replaceAll("&gt;", ">")
  1058 + .replaceAll("&nbsp", " ") + "]]></conteudo-linha>\n");
  1059 + xml.append("</codigo-fonte-criterio>\n");
  1060 + }
  1061 +
  1062 + } else {
  1063 + if (numeroCriterio.equalsIgnoreCase("1") && !recomendacao1_1_1Adicionada) {
  1064 + if (!criterioCompara.equalsIgnoreCase("")) {
  1065 + xml.append("</criterio>\n");
  1066 + }
  1067 + xml.append("<criterio>\n");
  1068 + xml.append("<numero-criterio>" + numeroCriterio + "</numero-criterio>\n");
  1069 + xml.append("<nome-criterio>"
  1070 + + criterioProperties.getDescricao(rn.getCode() + "." + numeroCriterio)
  1071 + + "</nome-criterio>\n");
  1072 + xml.append("<erro-criterio>" + occurrence.isError() + "</erro-criterio>\n");
  1073 + xml.append("<quantidade-criterio>"
  1074 + + verificaQuantidadeCriterio(rn, isError, numeroCriterio)
  1075 + + "</quantidade-criterio>\n");
  1076 + xml.append("<codigo-fonte-criterio>\n");
  1077 + xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");
  1078 + xml.append("<conteudo-linha>Serviço de validação de HTML do W3C</conteudo-linha>\n");
  1079 + xml.append("</codigo-fonte-criterio>\n");
  1080 +
  1081 + criterioCompara = occurrence.getCriterio();
  1082 + recomendacao1_1_1Adicionada = true;
  1083 + }
  1084 +
  1085 + if (numeroCriterio.equalsIgnoreCase("2") && !recomendacao1_1_2Adicionada) {
  1086 + if (!criterioCompara.equalsIgnoreCase("")) {
  1087 +
  1088 + xml.append("</criterio>\n");
  1089 + }
  1090 +
  1091 + xml.append("<criterio>\n");
  1092 + xml.append("<numero-criterio>" + numeroCriterio + "</numero-criterio>\n");
  1093 + xml.append("<nome-criterio>"
  1094 + + criterioProperties.getDescricao(rn.getCode() + "." + numeroCriterio)
  1095 + + "</nome-criterio>\n");
  1096 + xml.append("<erro-criterio>" + occurrence.isError() + "</erro-criterio>\n");
  1097 + xml.append("<quantidade-criterio>"
  1098 + + verificaQuantidadeCriterio(rn, isError, numeroCriterio)
  1099 + + "</quantidade-criterio>\n");
  1100 + xml.append("<codigo-fonte-criterio>\n");
  1101 + xml.append("<numero-linha>" + occurrence.getLine() + "</numero-linha>\n");
  1102 + xml.append("<conteudo-linha>Serviço de validação de CSS do W3C</conteudo-linha>\n");
  1103 + xml.append("</codigo-fonte-criterio>\n");
  1104 +
  1105 + criterioCompara = occurrence.getCriterio();
  1106 + recomendacao1_1_2Adicionada = true;
  1107 + }
  1108 +
  1109 + }
  1110 + // }
  1111 + }
  1112 +
  1113 + xml.append("</criterio>\n");
  1114 +
  1115 + }
  1116 +
  1117 + private Integer verificaQuantidadeCriterio(OccurrenceKey rn, boolean isError,
  1118 + String numeroCriterio) {
  1119 + Integer quantidadeCriterios = 0;
  1120 +
  1121 + for (Occurrence occurrence2 : this.detalheAvaliacao.get(rn, isError).getOcorrencias()) {
  1122 + if (occurrence2.getCriterio().toString().equalsIgnoreCase(numeroCriterio)) {
  1123 + quantidadeCriterios++;
  1124 + }
  1125 + }
  1126 +
  1127 + return quantidadeCriterios;
  1128 +
  1129 + }
  1130 +
  1131 +}
src/main/java/br/com/ases/controller/IndexController.java
1 package br.com.ases.controller; 1 package br.com.ases.controller;
2 2
  3 +import java.sql.Connection;
  4 +import java.sql.DriverManager;
  5 +
  6 +import org.apache.regexp.REUtil;
  7 +
3 import com.jcabi.http.Response; 8 import com.jcabi.http.Response;
4 9
5 import br.com.caelum.vraptor.Path; 10 import br.com.caelum.vraptor.Path;
@@ -9,7 +14,7 @@ import br.com.caelum.vraptor.ioc.spring.VRaptorRequestHolder; @@ -9,7 +14,7 @@ import br.com.caelum.vraptor.ioc.spring.VRaptorRequestHolder;
9 @Resource 14 @Resource
10 public class IndexController { 15 public class IndexController {
11 16
12 - private String tituloPagina = "ASES - Avaliador e Simulador de Acessibilidade em Sítios"; 17 + private String tituloPagina = "ASES - Avaliador e Simulador de Acessibilidade em Sítios";
13 private Result result; 18 private Result result;
14 19
15 public IndexController (Result result) { 20 public IndexController (Result result) {
@@ -27,7 +32,11 @@ public class IndexController { @@ -27,7 +32,11 @@ public class IndexController {
27 32
28 @Path("/") 33 @Path("/")
29 public void index() { 34 public void index() {
  35 +
30 VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("tituloPagina", tituloPagina); 36 VRaptorRequestHolder.currentRequest().getServletContext().setAttribute("tituloPagina", tituloPagina);
31 } 37 }
32 38
33 } 39 }
  40 +
  41 +
  42 +
src/main/java/br/com/ases/domain/DetalheAvaliacao.java
@@ -118,6 +118,8 @@ public class DetalheAvaliacao { @@ -118,6 +118,8 @@ public class DetalheAvaliacao {
118 118
119 } 119 }
120 120
  121 +
  122 +
121 public @Getter @Setter class Criterio implements Comparable<Criterio>{ 123 public @Getter @Setter class Criterio implements Comparable<Criterio>{
122 private String id; 124 private String id;
123 private String descricao; 125 private String descricao;
src/main/java/br/com/ases/model/utilities/Validate.java
@@ -107,8 +107,9 @@ public class Validate { @@ -107,8 +107,9 @@ public class Validate {
107 } 107 }
108 108
109 private Integer verificarConexao(String campo, String usuario, String agente) { 109 private Integer verificarConexao(String campo, String usuario, String agente) {
110 - System.setProperty("jsse.enableSNIExtension", "false"); 110 +
111 int codResponse = -1; 111 int codResponse = -1;
  112 + System.setProperty("jsse.enableSNIExtension", "false");
112 HttpMethod metodoRequisicaoGET = null; 113 HttpMethod metodoRequisicaoGET = null;
113 HttpClient clienteHTTPJakartaCommons; 114 HttpClient clienteHTTPJakartaCommons;
114 URL UrlConvertida; 115 URL UrlConvertida;
@@ -134,15 +135,15 @@ public class Validate { @@ -134,15 +135,15 @@ public class Validate {
134 135
135 } catch (MalformedURLException e) { 136 } catch (MalformedURLException e) {
136 e.printStackTrace(); 137 e.printStackTrace();
137 - // this.validator.add(new ValidationMessage(  
138 - // "N&atilde;o foi poss&iacute;vel realizar a avalia&ccedil;&atilde;o! URL " + campo  
139 - // + " é considerada inválida.", "warning")); 138 + // this.validator.add(new ValidationMessage(
  139 + // "N&atilde;o foi poss&iacute;vel realizar a avalia&ccedil;&atilde;o! URL " + campo
  140 + // + " é considerada inválida.", "warning"));
140 return -1; 141 return -1;
141 } catch (IOException e) { 142 } catch (IOException e) {
142 e.printStackTrace(); 143 e.printStackTrace();
143 - //this.validator.add(new ValidationMessage(  
144 - // "N&atilde;o foi poss&iacute;vel realizar a avalia&ccedil;&atilde;o! URL " + campo  
145 - // + " é considerada inválida.", "warning")); 144 + // this.validator.add(new ValidationMessage(
  145 + // "N&atilde;o foi poss&iacute;vel realizar a avalia&ccedil;&atilde;o! URL " + campo
  146 + // + " é considerada inválida.", "warning"));
146 return -1; 147 return -1;
147 } 148 }
148 149