1 package org.nextime.ion.backoffice.tree; 2 3 import java.util.Vector ; 4 import javax.servlet.http.HttpServletRequest ; 5 6 import org.apache.struts.action.ActionServlet; 7 import org.nextime.ion.framework.business.*; 8 import org.nextime.ion.framework.mapping.*; 9 10 public class WcmTreeBuilder implements TreeBuilder { 11 12 15 public void buildTree( 16 TreeControl treeControl, 17 ActionServlet servlet, 18 HttpServletRequest request) { 19 20 TreeControlNode root = treeControl.getRoot(); 21 22 try { 23 Mapping.begin(); 24 Vector roots = Section.listRootSections(); 25 for (int i = 0; i < roots.size(); i++) { 26 Section section = (Section) roots.get(i); 27 TreeControlNode node = buildNode(section); 28 root.addChild(node); 30 recursive(section, node); 31 } 32 Mapping.rollback(); 33 } catch (Exception e) { 34 Mapping.rollback(); 35 e.printStackTrace(); 36 } 37 } 38 39 public static TreeControlNode buildNode(Section section) { 40 String img = "section.gif"; 41 if ("offline".equals(section.getMetaData("status"))) { 42 img = "section-offline.gif"; 43 } 44 TreeControlNode node = 45 new TreeControlNode( 46 section.getId(), 47 img, 48 (section.getMetaData("name") != null) 49 ? section.getMetaData("name") + "" 50 : "<i>(indéfinie)</i>", 51 "viewSection.x?id=" + section.getId(), 52 "content", 53 false); 54 return node; 55 } 56 57 private void recursive(Section section, TreeControlNode node) { 58 Vector childs = section.listSubSections(); 59 for (int i = 0; i < childs.size(); i++) { 60 Section tsection = (Section) childs.get(i); 61 TreeControlNode tnode = buildNode(tsection); 62 node.addChild(tnode); 63 recursive(tsection, tnode); 64 } 65 } 66 67 } 68 | Popular Tags |