FileDocCategorySizeDatePackage
ToolServlet.javaAPI DocExample1856Thu Apr 05 20:37:52 BST 2001None

ToolServlet

public class ToolServlet extends HttpServlet

Fields Summary
Tool[]
tools
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    Tool[] tools = null;

    // Place an appropriate "tools" attribute in the request
    String state = req.getParameter("state");
    if (state == null) {
      req.setAttribute("tools", getTools());
    }
    else {
      req.setAttribute("tools", getTools(state));
    }

    // Send the request to the JSP for processing
    RequestDispatcher disp = req.getRequestDispatcher("/toolview-tag.jsp");
    disp.forward(req, res);
  
public Tool[]getTools()

    return tools;
  
public Tool[]getTools(java.lang.String state)

    List list = new LinkedList();
    for (int i = 0; i < tools.length; i++) {
      if (tools[i].getStateFlag().equalsIgnoreCase(state)) {
        list.add(tools[i]);
      }
    }
    return (Tool[]) list.toArray(new Tool[0]);
  
public voidinit()


       
    // Load the tool data in our init for simplicity
    String toolsFile = 
      getServletContext().getInitParameter("toolsFile"); // from web.xml
    if (toolsFile == null) {
      throw new ServletException("A tools data file must be specified as " +
                                 "the toolsFile context init parameter");
    }
    log("Loading tools from " + toolsFile);
    try {
      tools = Tool.loadTools(toolsFile);
      if (tools.length == 0) {
        log("No tools found in " + toolsFile);
      }
      else {
        log(tools.length + " tools found in " + toolsFile);
      }
    }
    catch (Exception e) {
      throw new ServletException(e);
    }