1 61 62 package org.objectweb.jonas.webapp.jonasadmin; 63 64 import java.io.IOException ; 65 import java.util.ArrayList ; 66 import java.util.StringTokenizer ; 67 68 import javax.servlet.ServletException ; 69 import javax.servlet.http.HttpServletRequest ; 70 import javax.servlet.http.HttpServletResponse ; 71 import javax.servlet.http.HttpSession ; 72 73 import org.apache.struts.action.Action; 74 import org.apache.struts.action.ActionForm; 75 import org.apache.struts.action.ActionForward; 76 import org.apache.struts.action.ActionMapping; 77 import org.apache.struts.action.ActionServlet; 78 import org.objectweb.jonas.webapp.taglib.TreeBuilder; 79 import org.objectweb.jonas.webapp.taglib.TreeControl; 80 import org.objectweb.jonas.webapp.taglib.TreeControlNode; 81 82 91 92 public class SetUpTreeAction extends Action { 93 94 public static final int INIT_PLUGIN_MAX = 10; 95 public static final String TREEBUILDER_KEY = "treebuilders"; 96 public static final String ROOTNODENAME_KEY = "rootnodename"; 97 98 100 115 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request 116 , HttpServletResponse response) 117 throws IOException , ServletException { 118 119 ActionServlet servlet = (ActionServlet) getServlet(); 121 122 124 String rootnodeName = (String ) servlet.getServletConfig().getInitParameter(ROOTNODENAME_KEY); 126 127 String treeBuildersStr = (String ) servlet.getServletConfig().getInitParameter( 128 TREEBUILDER_KEY); 129 130 132 135 TreeControlNode root = new TreeControlNode("ROOT-NODE", null, rootnodeName 136 , "setUpTree.do?select=ROOT-NODE", "content", true); 137 138 TreeControl control = new TreeControl(root); 139 140 if (treeBuildersStr != null) { 141 Class treeBuilderImpl; 142 TreeBuilder treeBuilderBase; 143 144 ArrayList treeBuilders = new ArrayList (INIT_PLUGIN_MAX); 145 int i = 0; 146 StringTokenizer st = new StringTokenizer (treeBuildersStr, ","); 147 while (st.hasMoreTokens()) { 148 treeBuilders.add(st.nextToken().trim()); 149 } 150 151 if (treeBuilders.size() == 0) { 152 treeBuilders.add(treeBuildersStr.trim()); 153 } 154 for (i = 0; i < treeBuilders.size(); i++) { 155 try { 156 treeBuilderImpl = Class.forName((String ) treeBuilders.get(i)); 157 treeBuilderBase = (TreeBuilder) treeBuilderImpl.newInstance(); 158 treeBuilderBase.buildTree(control, servlet, request); 159 } 160 catch (Throwable t) { 161 t.printStackTrace(System.out); 162 } 163 } 164 } 165 166 HttpSession session = request.getSession(); 167 session.setAttribute("treeControl", control); 168 169 WhereAreYou oWhere = (WhereAreYou) session.getAttribute(WhereAreYou.SESSION_NAME); 170 oWhere.setTreeControl(control); 171 172 String name = request.getParameter("select"); 173 if (name != null) { 174 control.selectNode(name); 175 return (mapping.findForward("Blank")); 177 } 178 179 return (mapping.findForward("Tree")); 180 181 } 182 } 183 | Popular Tags |