FileDocCategorySizeDatePackage
ToolServlet.javaAPI DocExample2326Thu Apr 05 20:31:30 BST 2001None

ToolServlet

public class ToolServlet extends WMServlet

Fields Summary
private Log
log
private Tool[]
tools
Constructors Summary
Methods Summary
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 Templatehandle(WebContext context)

    // You often pass on the request, response, and application even if
    // not all the objects are used, since they may be used later
    try {
      Template view = getTemplate("toolview.wm");
      String state = context.getRequest().getParameter("state");
      if (state == null) {
        state = (String)view.getParam("defaultState");
      }

      if (state == null) {
        context.put("tools", getTools()); 
      }
      else {
        context.put("tools", getTools(state));
      }
      return view;
    }
    catch (WebMacroException e) {
      log.exception(e);
      throw new HandlerException(e.getMessage());
    }
    catch (IOException e) {
      log.exception(e);
      throw new HandlerException(e.getMessage());
    }
  
public voidstart()

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