1
2
3
4
5 package ecar.taglib.util;
6
7 import ecar.dao.ConfiguracaoDao;
8 import ecar.exception.ECARException;
9 import ecar.pojo.ConfiguracaoCfg;
10 import gov.pr.celepar.sentinela.comunicacao.SentinelaParam;
11
12 import java.io.IOException;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
16
17 import javax.servlet.jsp.JspException;
18 import javax.servlet.jsp.JspWriter;
19 import javax.servlet.jsp.tagext.Tag;
20 import javax.servlet.jsp.tagext.TagSupport;
21
22 import comum.database.SentinelaUtil;
23 import comum.util.ItemMenu;
24
25
26
27
28
29 public class MenuTag extends TagSupport {
30
31
32
33
34 private static final long serialVersionUID = -8562932869631678975L;
35 private JspWriter writer;
36 private javax.servlet.http.HttpServletRequest request;
37
38
39
40
41
42
43
44
45
46 public int doStartTag() {
47 writer = this.pageContext.getOut();
48
49 try {
50
51 SentinelaUtil sentinelaUtil = new SentinelaUtil(this.request);
52
53
54
55
56 SentinelaParam[] me = sentinelaUtil.getSentinelaInterface().getMenu();
57
58 List menuVertical = ItemMenu.carregaMenu(me);
59
60 getRequest().getSession().setAttribute("menuVertical", menuVertical);
61
62
63 writer.println("\t var itemtext = new Array();");
64
65
66
67 String jsPartes[] = opcoesPrincipais(menuVertical);
68 getRequest().getSession().setAttribute("qtdeMenusPrincipais", String.valueOf(menuVertical.size()));
69
70 writer.println(jsPartes[0]);
71 writer.println("\n\n");
72
73
74 imprimeSubMenus(menuVertical);
75 writer.println("\n\n");
76
77
78 writer.println(jsPartes[1]);
79 writer.println("\n\n");
80
81
82 writer.println(jsPartes[2]);
83 writer.println("\n\n");
84
85
86 writer.println(jsPartes[3]);
87 }
88 catch(Exception e) {
89
90 }
91
92
93 return Tag.SKIP_BODY;
94 }
95
96
97
98
99
100
101
102
103
104
105 public int doEndTag() throws JspException {
106
107 return Tag.EVAL_PAGE;
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 private String[] opcoesPrincipais(List lista) throws IOException {
156 if (lista == null || lista.size() == 0)
157 return (new String[] {new String(""), new String(""), new String(""), new String("")});
158
159 StringBuffer itemText = new StringBuffer();
160 StringBuffer divs = new StringBuffer();
161 StringBuffer fechaMenu = new StringBuffer();
162 StringBuffer funcoes = new StringBuffer();
163 try {
164 ConfiguracaoCfg configuracaoMenu = new ConfiguracaoDao(null).getConfiguracao();
165
166 int nivel = 0, auxNivel = 0;
167
168 Iterator it = lista.iterator();
169 while (it.hasNext()) {
170 ItemMenu m = (ItemMenu) it.next();
171
172 auxNivel = nivel + 1;
173
174
175 itemText.append("\t itemtext[").append(nivel).append("] = \"").append(m.getNome()).append("\"; \n");
176
177
178 divs.append("\t document.write(\"");
179 divs.append("<div id='item").append(auxNivel).append("'>");
180 divs.append("<a href='javascript:mudaFuncao(").append(auxNivel).append(");abremenu(").append(auxNivel).append(");'>");
181 divs.append("\"+itemtext[").append(nivel).append("]+\"");
182 divs.append("</a></div>\"); \n");
183 divs.append("\t document.write(\"");
184 divs.append("<div id='submenu").append(auxNivel).append("'>");
185 divs.append("\"+submenu").append(nivel).append("+\"</div>\"); \n");
186
187
188 fechaMenu.append("\t fechamenu(").append(auxNivel).append("); \n");
189
190 nivel = nivel + 1;
191 }
192
193 funcoes.append("\t function fechamenu(x) { \n");
194 funcoes.append("\t\t itemmenu = \"item\"+x; \n");
195 funcoes.append("\t\t itemmenutext = itemtext[x-1]; \n");
196 funcoes.append("\t\t divsubmenu = \"submenu\"+x; \n");
197 funcoes.append("\t\t document.getElementById(itemmenu).innerHTML = \"<a href='javascript:mudaFuncao(\" + x + \");abremenu(\"+x+\");'>\"+itemmenutext+\"</a>\"; \n");
198 funcoes.append("\t\t document.getElementById(itemmenu).style.backgroundImage = \"url(\"+_pathEcar+\"/images/estilo/icone_menu_mais_gd_"+configuracaoMenu.getEstilo().getNome()+".gif)\"; \n");
199 funcoes.append("\t\t divsubmenu = \"submenu\"+x; \n");
200 funcoes.append("\t\t document.getElementById(divsubmenu).style.visibility = \"hidden\"; \n");
201 funcoes.append("\t\t document.getElementById(divsubmenu).style.position = \"absolute\"; \n");
202 funcoes.append("\t } \n");
203
204
205 funcoes.append("\t function abremenu(x) { \n");
206 funcoes.append("\t\t itemmenu = \"item\"+x; \n");
207 funcoes.append("\t\t itemmenutext = itemtext[x-1]; \n");
208 funcoes.append("\t\t divsubmenu = \"submenu\"+x; \n");
209 funcoes.append("\t\t document.getElementById(itemmenu).innerHTML = \"<a href='javascript:fechamenu(\"+x+\");'>\"+itemmenutext+\"</a>\"; \n");
210 funcoes.append("\t\t document.getElementById(itemmenu).style.backgroundImage = \"url(\"+_pathEcar+\"/images/estilo/icone_menu_menos_gd_"+configuracaoMenu.getEstilo().getNome()+".gif)\"; \n");
211 funcoes.append("\t\t document.getElementById(divsubmenu).style.visibility = \"visible\"; \n");
212 funcoes.append("\t\t document.getElementById(divsubmenu).style.position = \"static\"; \n");
213 funcoes.append("\t\t y=1; \n");
214 funcoes.append("\t\t while (y <= ").append(auxNivel).append(") { \n");
215 funcoes.append("\t\t\t if (y != x) { \n");
216 funcoes.append("\t\t\t\t fechamenu(y); \n");
217 funcoes.append("\t\t\t } \n");
218 funcoes.append("\t\t\t y = y + 1; \n");
219 funcoes.append("\t\t } \n");
220 funcoes.append("\t } \n");
221 } catch (ECARException e) {
222
223 }
224
225 return (new String[] {itemText.toString(), divs.toString(), funcoes.toString(), fechaMenu.toString()});
226 }
227
228
229
230
231
232
233
234
235
236
237
238
239 private void imprimeSubMenus(List lista) throws IOException {
240 if (lista == null || lista.size() == 0)
241 return;
242
243 int numMenu = 0;
244
245 Iterator it = lista.iterator();
246 while (it.hasNext()) {
247 ItemMenu m = (ItemMenu) it.next();
248 StringBuffer sb = new StringBuffer();
249
250 sb.append("\n\t submenu").append(numMenu).append(" = new dTree('submenu").append(numMenu).append("'); \n");
251 sb.append("\t submenu").append(numMenu).append(".add(").append(m.getCodigo().toString()).append(",-1,'');");
252
253 writer.println(sb.toString());
254 imprimeSubMenusFilhos(m.getItemMenuFilhos(), numMenu);
255
256 numMenu = numMenu + 1;
257 }
258 }
259
260
261
262
263
264
265
266
267
268
269
270
271 private void imprimeSubMenusFilhos(List lista, int numMenu) throws IOException {
272
273 if (lista == null || lista.size() == 0)
274 return;
275
276 Iterator it = lista.iterator();
277 while (it.hasNext()) {
278 ItemMenu m = (ItemMenu) it.next();
279 StringBuffer sb = new StringBuffer();
280
281
282 List<String> nomesDoCaminho = new ArrayList<String>();
283 nomesDoCaminho.add(m.getNome());
284
285 ItemMenu menuAtual = m.getItemMenuPai();
286
287 while(menuAtual != null) {
288 nomesDoCaminho.add(menuAtual.getNome());
289 ItemMenu teste = new ItemMenu (null,0," "," ");
290 teste = menuAtual;
291 menuAtual = teste.getItemMenuPai();
292 }
293
294
295 String caminho = "";
296 int i = (nomesDoCaminho.size() - 1);
297 caminho = nomesDoCaminho.get(i);
298 i = (nomesDoCaminho.size() - 2);
299 while(i>=0) {
300 if(nomesDoCaminho.get(i)!= null)
301 caminho = caminho + " > "+ nomesDoCaminho.get(i);
302 i=i-1;
303 }
304
305 sb.append("\t submenu").append(numMenu).append(".add(").append(m.getCodigo().toString()).append(",");
306 sb.append(m.getItemMenuPai().getCodigo().toString()).append(",'").append(m.getNome()).append("',");
307 if(m.getUrl() != null && !"".equals(m.getUrl())){
308 sb.append("'").append(request.getContextPath()).append("/abrirUrl.jsp?url=").append(m.getUrl()).append("&titulo=").append(caminho).append("');");
309 }
310 else {
311 sb.append("'');");
312 }
313
314 writer.println(sb.toString());
315 imprimeSubMenusFilhos(m.getItemMenuFilhos(), numMenu);
316 }
317
318
319 }
320
321
322
323
324
325
326
327
328
329
330 private void montaMenuJS(List lista) throws IOException {
331
332 }
333
334
335
336
337
338
339
340
341
342 public javax.servlet.http.HttpServletRequest getRequest() {
343 return request;
344 }
345
346
347
348
349
350
351
352
353
354 public void setRequest(javax.servlet.http.HttpServletRequest request) {
355 this.request = request;
356 }
357 }