FileDocCategorySizeDatePackage
SnoopManipulation.javaAPI DocExample1477Thu Apr 05 20:34:54 BST 2001None

SnoopManipulation

public class SnoopManipulation extends HttpServlet

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

    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    // Get some dynamic data to display
    Enumeration locales = req.getLocales();

    // Create the DOM tree
    Snoop snoop = new Snoop();

    // Get the first "prototype" list item
    // The rest were removed during the xmlc compile
    HTMLLIElement item = snoop.getElementLocale();

    // Get the prototype's parent so we can manage the children
    Node parent = item.getParentNode();

    // Loop over the locales adding a node for each
    while (locales.hasMoreElements()) {
      Locale loc = (Locale)locales.nextElement();
      HTMLLIElement newItem = (HTMLLIElement) item.cloneNode(true);
      Text text = snoop.createTextNode(loc.toString());
      newItem.replaceChild(text, newItem.getLastChild());
      parent.insertBefore(newItem, null);
    }

    // Remove the prototype item
    parent.removeChild(item);

    // Output the document
    DOMFormatter formatter = new DOMFormatter();  // can be heavily tweaked
    formatter.write(snoop, out);