KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > web > controller > TreeCommand


1 package com.genimen.djeneric.web.controller;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8
9 import org.w3c.dom.Document JavaDoc;
10
11 import com.genimen.djeneric.repository.exceptions.DjenericException;
12 import com.genimen.djeneric.web.renderers.TreeRenderer;
13 import com.genimen.djeneric.web.renderers.tree.AbstractWebNode;
14 import com.genimen.djeneric.web.renderers.tree.WebTree;
15 import com.genimen.djeneric.web.util.DjenericSessionManager;
16 import com.genimen.djeneric.web.util.DjenericXSLTransform;
17
18 public class TreeCommand
19 {
20   TreeRenderer _renderer = new TreeRenderer();
21
22   public void get(DjenericSessionManager sessionManager, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
23       throws IOException JavaDoc, ServletException JavaDoc, DjenericException
24   {
25     try
26     {
27       WebTree tree = sessionManager.getTree();
28       DjenericXSLTransform xsl = sessionManager.getTransformer();
29
30       response.setContentType("text/html; charset=UTF-8");
31
32       String JavaDoc nodeId = request.getParameter("nodeid");
33       if (nodeId != null)
34       {
35         String JavaDoc cmd = request.getParameter("cmd");
36         if ("toggle".equals(cmd)) tree.toggleExpanded(nodeId);
37         else if ("expand".equals(cmd)) tree.expandAll(nodeId);
38         else if ("collapse".equals(cmd)) tree.collapseAll(nodeId);
39         else if ("refresh".equals(cmd))
40         {
41           AbstractWebNode node = tree.getNode(nodeId);
42           node.reload();
43         }
44
45         tree.setSelectedNode(nodeId);
46
47         Document JavaDoc doc = _renderer.asXml(tree, nodeId);
48         
49         String JavaDoc page = xsl.transform(doc, "tree/subtree.xsl");
50         response.getWriter().print(page);
51       }
52       else
53       {
54         throw new DjenericException("Parameter nodeid not defined");
55       }
56     }
57     catch (Exception JavaDoc e)
58     {
59       throw new ServletException JavaDoc(e);
60     }
61   }
62 }
63
Popular Tags