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 com.genimen.djeneric.repository.exceptions.DjenericException; 10 import com.genimen.djeneric.repository.util.DjObjectExporter; 11 import com.genimen.djeneric.structure.EditorDefinition; 12 import com.genimen.djeneric.web.renderers.FilterRenderer; 13 import com.genimen.djeneric.web.renderers.tree.AbstractWebNode; 14 import com.genimen.djeneric.web.renderers.tree.WebFolder; 15 import com.genimen.djeneric.web.renderers.tree.WebNode; 16 import com.genimen.djeneric.web.renderers.tree.WebTree; 17 import com.genimen.djeneric.web.util.DjenericSessionManager; 18 19 public class ExportCommand 20 { 21 FilterRenderer _renderer = new FilterRenderer(); 22 23 public void get(DjenericSessionManager sessionManager, HttpServletRequest request, HttpServletResponse response) 24 throws IOException , ServletException , DjenericException 25 { 26 try 27 { 28 WebTree tree = sessionManager.getTree(); 29 30 response.setContentType("application/octet-stream"); 31 32 String nodeId = request.getParameter("nodeid"); 33 if (nodeId != null) 34 { 35 AbstractWebNode node = tree.getNode(nodeId); 36 37 DjObjectExporter oe = new DjObjectExporter(); 38 oe.setStatusDisplayer(null); 39 40 boolean recursive = "true".equalsIgnoreCase(request.getParameter("recursive")); 41 42 if (node instanceof WebNode) exportNode(oe, (WebNode) node, recursive); 43 else if (node instanceof WebFolder) exportFolder(oe, (WebFolder) node, recursive); 44 45 response.getWriter().print(oe.export()); 46 } 47 else throw new DjenericException("No nodeid parameter specified"); 48 } 49 catch (Exception e) 50 { 51 throw new ServletException (e); 52 } 53 } 54 55 public void post(DjenericSessionManager sessionManager, HttpServletRequest request, HttpServletResponse response) 56 { 57 58 } 59 60 private void exportFolder(DjObjectExporter oe, WebFolder folder, boolean recursive) throws Exception , 61 DjenericException 62 { 63 WebNode[] nodes = folder.getChildNodes(); 64 for (int c = 0; c < nodes.length; c++) 65 { 66 if (folder.getExtentUsage().isRecursive()) recursive = false; 67 exportNode(oe, nodes[c], recursive); 68 } 69 } 70 71 private void exportNode(DjObjectExporter oe, WebNode node, boolean recursive) throws Exception 72 { 73 EditorDefinition editorDefinition = node.getExtentUsage().getEditor(); 74 if (node.canExport()) oe.markForExport(node.getTargetObject(), editorDefinition.getUsages()); 75 if (recursive) 76 { 77 node.load(); 78 for (int i = 0; i < node.getChildCount(); i++) 79 { 80 if (node.getChildAt(i) instanceof WebFolder) 81 { 82 exportFolder(oe, (WebFolder) node.getChildAt(i), recursive); 83 } 84 } 85 } 86 } 87 88 } 89 | Popular Tags |