KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > www > WMenu


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.www;
15
16 import javax.servlet.*;
17 import javax.servlet.http.*;
18 import java.io.*;
19 import java.util.*;
20 import java.sql.*;
21 import java.text.*;
22
23 import org.apache.ecs.xhtml.*;
24
25 import org.compiere.util.*;
26
27 /**
28  * Web Menu
29  *
30  * @author Jorg Janke
31  * @version $Id: WMenu.java,v 1.2 2003/03/31 05:27:26 jjanke Exp $
32  */

33 public class WMenu extends HttpServlet
34 {
35     /**
36      * Initialize global variables
37      * @param config config
38      * @throws ServletException
39      */

40     public void init(ServletConfig config) throws ServletException
41     {
42         super.init(config);
43         if (!WEnv.initWeb(config))
44             throw new ServletException("WMenu.init");
45     } // init
46

47     /**
48      * Get Servlet information
49      * @return servlet info
50      */

51     public String JavaDoc getServletInfo()
52     {
53         return "Compiere Web Menu";
54     } // getServletInfo
55

56     /**
57      * Clean up resources
58      */

59     public void destroy()
60     {
61         Log.trace(Log.l1_User, "WMenu.destroy");
62         super.destroy();
63     } // destroy
64

65     /** */
66     private PreparedStatement m_pstmt;
67
68
69     /*************************************************************************/
70
71     /**
72      * Process the HTTP Get request.
73      * - Exit (Logout)
74      * - AD_Window_ID Forward to Window
75      *
76      * @param request request
77      * @param response response
78      * @throws ServletException
79      * @throws IOException
80      */

81     public void doGet(HttpServletRequest request, HttpServletResponse response)
82         throws ServletException, IOException
83     {
84         Log.trace(Log.l1_User, "WMenu.doGet - Process Menu Request");
85         // Get Parameter: Exit
86
if (request.getParameter("Exit") != null)
87         {
88             WUtil.createLoginPage (request, response, this, null, "Exit");
89             return;
90         }
91
92         // Get Session attributes
93
HttpSession sess = request.getSession();
94         Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT);
95         if (ctx == null)
96         {
97             WUtil.createTimeoutPage(request, response, this, null, null);
98             return;
99         }
100
101         // Window
102
int AD_Window_ID = WUtil.getParameterAsInt(request, "AD_Window_ID");
103
104         // Forward to WWindow
105
if (AD_Window_ID != 0)
106         {
107             Log.trace(Log.l4_Data, "AD_Window_ID=" + AD_Window_ID);
108             //
109
String JavaDoc url = WEnv.getBaseDirectory("WWindow?AD_Window_ID=" + AD_Window_ID);
110             Log.trace(Log.l4_Data, "Forward to - " + url);
111             //
112
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
113             rd.forward(request, response);
114             return;
115         }
116
117         // Request not serviceable
118
WUtil.createErrorPage(request, response, this, null, "NotImplemented");
119     } // doGet
120

121
122     /*************************************************************************/
123
124     /**
125      * Process the HTTP Post request - Verify Input & Create Menu
126      *
127      * @param request request
128      * @param response response
129      * @throws ServletException
130      * @throws IOException
131      */

132     public void doPost(HttpServletRequest request, HttpServletResponse response)
133         throws ServletException, IOException
134     {
135         Log.trace(Log.l1_User, "WMenu.doPost - Create Menu");
136         // Get Session attributes
137
HttpSession sess = request.getSession();
138         Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT);
139         Properties cProp = WUtil.getCookieProprties(request);
140         if (ctx == null)
141         {
142             WUtil.createTimeoutPage(request, response, this, null, null);
143             return;
144         }
145
146         // Get Parameters: Role, Client, Org, Warehouse, Date
147
String JavaDoc role = request.getParameter(WLogin.P_ROLE);
148         String JavaDoc client = request.getParameter(WLogin.P_CLIENT);
149         String JavaDoc org = request.getParameter(WLogin.P_ORG);
150         String JavaDoc wh = request.getParameter(WLogin.P_WAREHOUSE);
151         if (wh == null)
152             wh = "";
153
154         // Get context
155
if (role == null || client == null || org == null)
156         {
157             WUtil.createTimeoutPage(request, response, this, ctx, Msg.getMsg(ctx, "ParameterMissing"));
158             return;
159         }
160
161         // Get Info from Context - User, Role, Client
162
int AD_User_ID = Env.getContextAsInt(ctx, "#AD_User_ID");
163         int AD_Role_ID = Env.getContextAsInt(ctx, "#AD_Role_ID");
164         int AD_Client_ID = Env.getContextAsInt(ctx, "#AD_Client_ID");
165         // Not available in context yet - Org, Warehouse
166
int AD_Org_ID = -1;
167         int M_Warehouse_ID = -1;
168
169         // Get latest info from context
170
try
171         {
172             int req_role = Integer.parseInt(role);
173             if (req_role != AD_Role_ID)
174             {
175                 Log.trace(Log.l5_DData, "AD_Role_ID - changed from " + AD_Role_ID);
176                 AD_Role_ID = req_role;
177                 Env.setContext(ctx, "#AD_Role_ID", AD_Role_ID);
178             }
179             Log.trace(Log.l5_DData, "AD_Role_ID = " + AD_Role_ID);
180             //
181
int req_client = Integer.parseInt(client);
182             if (req_client != AD_Client_ID)
183             {
184                 Log.trace(Log.l5_DData, "AD_Client_ID - changed from " + AD_Client_ID);
185                 AD_Client_ID = req_client;
186                 Env.setContext(ctx, "#AD_Client_ID", AD_Client_ID);
187             }
188             Log.trace(Log.l5_DData, "AD_Client_ID = " + AD_Client_ID);
189             //
190
AD_Org_ID = Integer.parseInt(org);
191             Log.trace(Log.l5_DData, "AD_Org_ID = " + AD_Org_ID);
192             //
193
if (wh.length() > 0)
194             {
195                 M_Warehouse_ID = Integer.parseInt(wh);
196                 Log.trace(Log.l5_DData, "M_Warehouse_ID = " + M_Warehouse_ID);
197             }
198         }
199         catch (Exception JavaDoc e)
200         {
201             Log.error("WMenu.doPost - Parameter", e);
202             WUtil.createTimeoutPage(request, response, this, ctx, Msg.getMsg(ctx, "ParameterMissing"));
203             return;
204         }
205
206         // Check Login info and set environment
207
String JavaDoc loginInfo = checkLogin (ctx, AD_User_ID, AD_Role_ID, AD_Client_ID, AD_Org_ID, M_Warehouse_ID);
208         if (loginInfo == null)
209         {
210             WUtil.createErrorPage(request, response, this, ctx, Msg.getMsg(ctx, "RoleInconsistent"));
211             return;
212         }
213         sess.setAttribute(WEnv.SA_LOGININFO, loginInfo);
214
215         // Set cookie for future defaults
216
cProp.setProperty(WLogin.P_ROLE, String.valueOf(AD_Role_ID));
217         cProp.setProperty(WLogin.P_CLIENT, String.valueOf(AD_Client_ID));
218         cProp.setProperty(WLogin.P_ORG, String.valueOf(AD_Org_ID));
219         if (M_Warehouse_ID == -1)
220             cProp.setProperty(WLogin.P_WAREHOUSE, "");
221         else
222             cProp.setProperty(WLogin.P_WAREHOUSE, String.valueOf(M_Warehouse_ID));
223
224         // Set Date
225
Timestamp ts = new Timestamp(System.currentTimeMillis());
226         // Try to parse Date
227
String JavaDoc dateString = request.getParameter(WLogin.P_DATE);
228         try
229         {
230             if (dateString != null && dateString.length() > 0)
231             {
232                 Language language = (Language)sess.getAttribute(WEnv.SA_LANGUAGE);
233                 DateFormat df = DisplayType.getDateFormat(DisplayType.Date, language);
234                 java.util.Date JavaDoc date = df.parse(dateString);
235                 ts = new Timestamp(date.getTime());
236             }
237         }
238         catch (Exception JavaDoc e)
239         {
240             Log.trace(Log.l1_User, "WMenu.doPost - Cannot parse date: " + dateString + " - " + e.getMessage());
241         }
242         Env.setContext(ctx, "#Date", ts.toString()); // JDBC format
243

244
245     // Log.printProperties(System.getProperties(), "System");
246
// Log.printProperties(cProp, "Cookie");
247
// Log.printProperties(ctx, "Servlet Context");
248
// Log.printProperties(Env.getCtx(), "Apps Env Context");
249

250
251         /**********************************************************************
252          * Create Menu output
253          */

254         String JavaDoc windowTitle = Msg.getMsg(ctx, "Menu");
255         String JavaDoc statusMessage = Msg.getMsg(ctx, "SelectMenuItem");
256
257         // Document
258
WDoc doc = WDoc.create (windowTitle);
259         head header = doc.getHead();
260         // Target
261
header.addElement(new base().setTarget(WEnv.TARGET_WINDOW));
262         // Specific Menu Script/Stylesheet
263
header.addElement(new script("", WEnv.getBaseDirectory("menu.js"), "text/javascript", "JavaScript1.2"));
264         header.addElement(new link().setRel("stylesheet").setHref(WEnv.getBaseDirectory("menu.css")));
265
266         // Body
267
body body = doc.getBody();
268         // Header
269
body.addElement(new cite(loginInfo));
270         String JavaDoc title = windowTitle + " - " + loginInfo;
271         body.addElement(new script("top.document.title='" + title + "';"));
272         body.addElement(new script("defaultStatus = '" + statusMessage + "';"));
273
274         // Clear Window Frame
275
body.addElement(WUtil.getClearFrame(WEnv.TARGET_WINDOW));
276
277         // Load Menu Structure ----------------------
278
MNode root = loadTree(AD_Client_ID, AD_Role_ID, AD_User_ID, Env.getAD_Language(ctx));
279         //
280
StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
281         buf.append("<ul>");
282         for (int i = 0; i < root.children.size(); i++)
283         {
284             MNode node = (MNode)root.children.get(i);
285             node.print(node, buf);
286         }
287         buf.append("</ul>");
288         body.addElement(buf.toString());
289
290         // Exit Info
291
body.addElement(new hr());
292         String JavaDoc url = request.getRequestURI() + "?Exit=true";
293         body.addElement(new a(url, Msg.getMsg(ctx, "Exit")));
294
295         // Can we store Cookie ?
296
if (!cProp.getProperty(WLogin.P_STORE, "N").equals("Y"))
297             cProp.clear();
298
299         WUtil.createResponse (request, response, this, cProp, doc, false);
300     } // doPost
301

302     /**
303      * Check Login information and set context.
304      * @returns true if login info are OK
305      * @param ctx context
306      * @param AD_User_ID user
307      * @param AD_Role_ID role
308      * @param AD_Client_ID client
309      * @param AD_Org_ID org
310      * @param M_Warehouse_ID warehouse
311      */

312     private String JavaDoc checkLogin (Properties ctx, int AD_User_ID, int AD_Role_ID, int AD_Client_ID, int AD_Org_ID, int M_Warehouse_ID)
313     {
314         // Get Login Info
315
String JavaDoc loginInfo = null;
316         // Verify existance of User/Client/Org/Role and User's acces to Client & Org
317
String JavaDoc sql = "SELECT u.Name || '@' || c.Name || '.' || o.Name || ' [' || INITCAP(USER) || ']' AS Text "
318             + "FROM AD_User u, AD_Client c, AD_Org o, AD_User_Roles ur "
319             + "WHERE u.AD_User_ID=?" // #1
320
+ " AND c.AD_Client_ID=?" // #2
321
+ " AND o.AD_Org_ID=?" // #3
322
+ " AND ur.AD_Role_ID=?" // #4
323
+ " AND ur.AD_User_ID=u.AD_User_ID"
324             + " AND (o.AD_Client_ID = 0 OR o.AD_Client_ID=c.AD_Client_ID)"
325             + " AND c.AD_Client_ID IN (SELECT AD_Client_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)"
326             + " AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ca WHERE ca.AD_Role_ID=ur.AD_Role_ID)";
327         try
328         {
329             PreparedStatement pstmt = DB.prepareStatement(sql);
330             pstmt.setInt(1, AD_User_ID);
331             pstmt.setInt(2, AD_Client_ID);
332             pstmt.setInt(3, AD_Org_ID);
333             pstmt.setInt(4, AD_Role_ID);
334             ResultSet rs = pstmt.executeQuery();
335             if (rs.next())
336                 loginInfo = rs.getString(1);
337             rs.close();
338             pstmt.close();
339         }
340         catch (SQLException e)
341         {
342             Log.error ("WMenu.checkLogin", e);
343         }
344
345         // not verified
346
if (loginInfo == null)
347             return null;
348
349         // Set Preferences
350
KeyNamePair org = new KeyNamePair(AD_Org_ID, String.valueOf(AD_Org_ID));
351         KeyNamePair wh = null;
352         if (M_Warehouse_ID > 0)
353             wh = new KeyNamePair(M_Warehouse_ID, String.valueOf(M_Warehouse_ID));
354         //
355
Timestamp date = null;
356         String JavaDoc printer = null;
357         DB.loadPreferences(ctx, org, wh, date, printer);
358         //
359
return loginInfo;
360     } // checkLogin
361

362
363     /*************************************************************************/
364
365     /**
366      * Load Tree and return root node
367      * @param AD_Client_ID client
368      * @param AD_Role_ID role
369      * @param AD_User_ID user
370      * @param AD_Language language
371      * @return node
372      */

373     private MNode loadTree (int AD_Client_ID, int AD_Role_ID, int AD_User_ID, String JavaDoc AD_Language)
374     {
375         // Get Tree info with start node
376
int AD_Tree_ID;
377         String JavaDoc Name;
378         String JavaDoc TreeType;
379         String JavaDoc Description;
380         int startID;
381         //
382
MNode root = null;
383
384         // Get Root Node
385
String JavaDoc SQL = "SELECT t.AD_Tree_ID, t.Name, t.Description, t.TreeType, tn.Node_ID "
386             + "FROM AD_Tree t, AD_ClientInfo c, AD_TreeNode tn "
387             + "WHERE t.AD_Tree_ID=tn.AD_Tree_ID"
388             + " AND tn.Parent_ID IS NULL"
389             + " AND t.AD_Tree_ID=c.AD_Tree_Menu_ID"
390             + " AND c.AD_Client_ID=?";
391         try
392         {
393             PreparedStatement pstmt = DB.prepareStatement(SQL);
394             pstmt.setInt(1, AD_Client_ID);
395             ResultSet rs = pstmt.executeQuery();
396             if (!rs.next())
397             {
398                 rs.close();
399                 pstmt.close();
400                 return null;
401             }
402             AD_Tree_ID = rs.getInt(1);
403             Name = rs.getString(2);
404             Description = rs.getString(3);
405             TreeType = rs.getString(4);
406             startID = rs.getInt(5);
407
408             // create root node
409
root = new MNode (startID, Name, Description, true, "");
410             rs.close();
411             pstmt.close();
412         }
413         catch (SQLException e)
414         {
415             Log.error("WMenu.loadTree -1", e);
416             return null;
417         }
418
419         // SQL for TreeNodes
420
StringBuffer JavaDoc cmd = new StringBuffer JavaDoc("SELECT tn.Node_ID,tn.Parent_ID,tn.SeqNo, "
421             + "(SELECT 'Y' FROM AD_TreeBar tb WHERE tb.AD_Tree_ID=tn.AD_Tree_ID AND tb.AD_User_ID=")
422             .append(AD_User_ID).append(" AND tb.Node_ID=tn.Node_ID) "
423             + "FROM AD_TreeNode tn ")
424             .append("WHERE tn.IsActive='Y' "
425             + "START WITH Parent_ID IS NULL AND AD_Tree_ID=? "
426             + "CONNECT BY Parent_ID=PRIOR Node_ID AND AD_Tree_ID=? "
427             + "ORDER BY LEVEL, SeqNo");
428
429         // SQL for Node Info
430
StringBuffer JavaDoc cmdNode = new StringBuffer JavaDoc();
431         boolean base = Env.isBaseLanguage(Env.getCtx(), "AD_Menu");
432         if (base)
433             cmdNode.append("SELECT m.Name,m.Description,m.IsSummary,m.Action "
434                 + "FROM AD_Menu m");
435         else
436             cmdNode.append("SELECT t.Name,t.Description,m.IsSummary,m.Action "
437                 + "FROM AD_Menu m, AD_Menu_Trl t");
438             cmdNode.append(", (SELECT ").append(AD_Role_ID).append(" AS XRole FROM DUAL)");
439         cmdNode.append(" WHERE m.AD_Menu_ID=?");
440         if (!base)
441             cmdNode.append(" AND m.AD_Menu_ID=t.AD_Menu_ID AND t.AD_Language='")
442                 .append(Env.getAD_Language(Env.getCtx())).append("'");
443
444         cmdNode.append(" AND m.IsActive='Y' "
445             + "AND (m.IsSummary='Y' OR m.Action='B'"
446             + " OR EXISTS (SELECT * FROM AD_Window_Access wa WHERE wa.AD_Window_ID=m.AD_Window_ID AND wa.AD_Role_ID=XRole)"
447             + " OR EXISTS (SELECT * FROM AD_Process_Access wa WHERE wa.AD_Process_ID=m.AD_Process_ID AND wa.AD_Role_ID=XRole)"
448             + " OR EXISTS (SELECT * FROM AD_Form_Access wa WHERE wa.AD_Form_ID=m.AD_Form_ID AND wa.AD_Role_ID=XRole)"
449             + " OR EXISTS (SELECT * FROM AD_Task_Access wa WHERE wa.AD_Task_ID=m.AD_Task_ID AND wa.AD_Role_ID=XRole)"
450             + " OR EXISTS (SELECT * FROM AD_Workflow_Access wa WHERE wa.AD_Workflow_ID=m.AD_Workflow_ID AND wa.AD_Role_ID=XRole)"
451             + ")");
452     // Log.trace(Log.l6_Database, "SQL Tree", cmd.toString());
453
// Log.trace(Log.l6_Database, "SQL Node", cmdNode.toString());
454

455         // The Node Loop
456
try
457         {
458             PreparedStatement pstmtNode = DB.prepareStatement(cmdNode.toString());
459             //
460
PreparedStatement pstmt = DB.prepareStatement(cmd.toString());
461             pstmt.setInt(1, AD_Tree_ID);
462             pstmt.setInt(2, AD_Tree_ID);
463             ResultSet rs = pstmt.executeQuery();
464             while (rs.next())
465             {
466                 int Node_ID = rs.getInt(1);
467                 int Parent_ID = rs.getInt(2);
468                 int SeqNo = rs.getInt(3);
469                 boolean onBar = (rs.getString(4) != null);
470                 loadNode (pstmtNode, root, Node_ID, Parent_ID, SeqNo, onBar);
471             }
472             rs.close();
473             pstmt.close();
474             pstmtNode.close();
475         }
476         catch (SQLException e)
477         {
478             Log.error("WMenu.loadTree -2", e);
479         }
480
481         // Clean Menu tree
482
root.clean(root);
483
484         return root;
485     } // loadTree
486

487     /**
488      * Load Node using prepared statement
489      * @param pstmt Prepared Statement requiring to set Node_ID and returning
490      * Name,Description,IsSummary,ImageIndiactor
491      * @param root root node
492      * @param Node_ID Key of the record
493      * @param Parent_ID Parent ID of the record
494      * @param SeqNo Sort index
495      * @param onBar Node also on Shortcut bar
496      */

497     private void loadNode (PreparedStatement pstmt, MNode root,
498         int Node_ID, int Parent_ID, int SeqNo, boolean onBar)
499     {
500         try
501         {
502             pstmt.setInt(1, Node_ID);
503             ResultSet rs = pstmt.executeQuery();
504             if (rs.next())
505             {
506                 String JavaDoc Name = rs.getString(1);
507                 String JavaDoc Description = rs.getString(2);
508                 boolean IsSummary = rs.getString(3).equals("Y");
509                 String JavaDoc ImageIndicator = rs.getString(4);
510
511                 if (Name != null)
512                 {
513                     MNode child = new MNode (Node_ID, Name, Description, IsSummary, ImageIndicator);
514                     child.add(root, Parent_ID, child);
515                 }
516             }
517         // else
518
// Log.trace(Log.l6_Database,"Not added", "Node_ID=" + Node_ID);
519
rs.close();
520         }
521         catch (SQLException e)
522         {
523             Log.error("WMenu.loadNode", e);
524         }
525     } // loadNode
526

527
528     /**************************************************************************
529      * Web Menu Tree Node
530      */

531     class MNode
532     {
533         /**
534          * Constructor
535          * @param ID id
536          * @param Name name
537          * @param Description description
538          * @param isSummary summary
539          * @param Type type
540          */

541         public MNode (int ID, String JavaDoc Name, String JavaDoc Description, boolean isSummary, String JavaDoc Type)
542         {
543             this.ID = ID;
544             this.Name = Name;
545             this.Description = Description;
546             if (this.Description == null)
547                 this.Description = "";
548             this.isSummary = isSummary;
549             this.Type = Type;
550             if (this.Type == null)
551                 this.Type = "";
552         }
553
554         public int ID;
555         public String JavaDoc Name;
556         public String JavaDoc Description;
557         public boolean isSummary;
558         public String JavaDoc Type;
559         public ArrayList children = new ArrayList();
560
561         /**
562          * Add to list of children
563          * @param child child
564          * @return true
565          */

566         public boolean add (MNode child)
567         {
568             children.add(child);
569             return true;
570         } // add
571

572         /*********************************************************************/
573
574         /**
575          * Traverse Tree starting at root to add child to parent with parentID
576          * @param root root
577          * @param parentID parent
578          * @param child child
579          * @returns false if not added
580          */

581         public boolean add (MNode root, int parentID, MNode child)
582         {
583             // is this root the parent?
584
if (root.ID == parentID)
585                 return root.add(child);
586
587             // do we have children to check?
588
else if (root.children.size() == 0)
589                 return false;
590
591             // check children
592
for (int i = 0; i < root.children.size(); i++)
593             {
594                 MNode cc = (MNode)root.children.get(i);
595                 if (root.add(cc, parentID, child))
596                     return true;
597             }
598             // nothing found
599
return false;
600         } // add
601

602         /**
603          * Traverse Tree and print it
604          * @param root root
605          * @param buf buffer
606          */

607         public void print (MNode root, StringBuffer JavaDoc buf)
608         {
609             // Leaf
610
if (root.children.size() == 0)
611             {
612                 /**
613                  * <li id="menuXXXXX"><a HREF="...." onMouseOver="status='Menu Description';return true;">Menu Entry</a></li>
614                  */

615                 String JavaDoc item = "";
616                 String JavaDoc servletName = "";
617                 if (root.Type.equals("W"))
618                 {
619                     item = "menuWindow";
620                     servletName = "WWindow";
621                 }
622                 else if (root.Type.equals("X"))
623                 {
624                     item = "menuWindow";
625                     servletName = "WForm";
626                 }
627                 else if (root.Type.equals("R"))
628                 {
629                     item = "menuReport";
630                     servletName = "WReport";
631                 }
632                 else if (root.Type.equals("P"))
633                 {
634                     item = "menuProcess";
635                     servletName = "WProcess";
636                 }
637                 else if (root.Type.equals("F"))
638                 {
639                     item = "menuWorkflow";
640                     servletName = "WWorkflow";
641                 }
642                 else if (root.Type.equals("T"))
643                 {
644                     item = "menuProcess";
645                     servletName = "WTask";
646                 }
647                 else
648                     servletName = "WError";
649
650                 String JavaDoc description = root.Description.replace('\'',' ').replace('"',' ');
651                 buf.append("<li id=\"" + item + "\"><a HREF=\"");
652                 // url - /appl/servletName?AD_Menu_ID=x
653
buf.append(WEnv.getBaseDirectory(servletName))
654                     .append("?AD_Menu_ID=")
655                     .append(root.ID);
656                 //
657
buf.append("\" onMouseOver=\"status='" + description + "';return true;\" onclick=showLoadingWindow(\"" + WEnv.getBaseDirectory("") + "\")>");
658                 buf.append(root.Name);
659                 buf.append("</a></li>\n");
660             }
661             else
662             {
663                 /**
664                  * <li id="foldHeader">MenuEntry</li>
665                  * <ul style="display:none">
666                  * ....
667                  * </ul>
668                  */

669                 buf.append("\n<li id=\"menuHeader\">"); // summary node
670
buf.append(root.Name);
671                 buf.append("</li>\n");
672                 // Next Level
673
buf.append("<ul style=\"display:none\">\n"); // start next level
674
for (int i = 0; i < root.children.size(); i++)
675                 {
676                     MNode cc = (MNode)root.children.get(i);
677                     root.print(cc, buf);
678                 }
679                 buf.append("</ul>"); // finish next level
680
}
681         } // print
682

683         /**
684          * Clean tree of parents without children
685          * @param root root node
686          */

687         public void clean (MNode root)
688         {
689             int size = root.children.size();
690             if (size == 0)
691                 return;
692             //
693
ArrayList temp = new ArrayList(size);
694             boolean changed = false;
695             for (int i = 0; i < size; i++)
696             {
697                 MNode cc = (MNode)root.children.get(i);
698                 int ccSize = cc.children.size();
699                 if (cc.isSummary && ccSize == 0)
700                     changed = true;
701                 else
702                     temp.add(cc);
703                 if (ccSize != 0)
704                     cc.clean(cc);
705             }
706             if (changed)
707                 root.children = temp;
708         } // clean
709

710     } // MNode
711

712 } // WMenu
713
Popular Tags