The following is a sample Key Generator in JAVA.
package RIP; import java.net.*; import java.io.*; import org.w3c.dom.*; import org.apache.xerces.parsers.*; import org.apache.xml.serialize.*; import org.xml.sax.*; import org.xml.sax.helpers.*; public class KeyGeneratorSample extends javax.servlet.http.HttpServlet { public KeyGeneratorSample() { super(); } private static final void addElement (org.xml.sax.ContentHandler hd, AttributesImpl attr, String stElement, String stValue) throws org.xml.sax.SAXException { hd.startElement ("", "", stElement, attr); if ((stValue != null) && (stValue.length () != 0)) { hd.characters (stValue.toCharArray (), 0, stValue.length ()); } hd.endElement ("", "", stElement); } public void doPost (javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException { try { DOMParser parser = new DOMParser (); parser.parse (new org.xml.sax.InputSource (req.getInputStream ())); Document doc = parser.getDocument (); int iKeysNeeded = Integer.parseInt (getFirstTextNodeValueByTagName (doc, "keycount")); OutputFormat of = new OutputFormat ("xml","utf-8", true); of.setIndent (1); of.setIndenting (true); XMLSerializer serializer = new XMLSerializer (res.getWriter (), of); org.xml.sax.ContentHandler hd = serializer.asContentHandler (); AttributesImpl attr = new AttributesImpl (); hd.startDocument (); hd.startElement ("", "", "response", attr); hd.startElement ("", "", "registrationkey", attr); for (int i = 0; i < iKeysNeeded; i++) { addElement (hd, attr, "keydata", "Remotely generated key #" + Integer.toString (i + 1)); } hd.endElement ("", "", "registrationkey"); hd.endElement ("", "", "response"); hd.endDocument (); } catch (Exception e) { Logger.logError ("Exception in RIP.KeyGeneratorSample.doPost: " + e); } } private static final String getFirstTextNodeValueByTagName (Document doc, String tagName) { NodeList list = doc.getElementsByTagName (tagName); if (list.getLength () != 0) { return (getTextNodeValue (list.item (0))); } return (null); } private static final String getTextNodeValue (Node node) { NodeList list = node.getChildNodes (); for (int i = 0; i < list.getLength (); i++) { Node n = list.item (i); if (n.getNodeType () == Node.TEXT_NODE) { return (n.getNodeValue ()); } } return (null); } }