1 package com.genimen.djeneric.web.controller; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 import org.w3c.dom.Document ; 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 request, HttpServletResponse response) 23 throws IOException , ServletException , 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 nodeId = request.getParameter("nodeid"); 33 if (nodeId != null) 34 { 35 String 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 doc = _renderer.asXml(tree, nodeId); 48 49 String 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 e) 58 { 59 throw new ServletException (e); 60 } 61 } 62 } 63 | Popular Tags |