* @throws EmailException if there is a problem sending the email notification about this key
* @throws SystemUnavailableException if there is a problem generating the key
*/
public static void createKey(HttpServletRequest request, String email, Messages localizedMessages) throws SystemUnavailableException, EmailException {
IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
IApiKey key = persistenceManager.newInstance(IApiKey.class);
key.setEmail(email);
// generate a nonce
RandomGUID r = new RandomGUID();
String nonce = "nonce-" + r.toString(); //$NON-NLS-1$
// now use SHA hash on the nonce
String hashKey = HashGenerator.getInstance().encrypt(nonce+email);
// get rid of any chars that might upset a url...
hashKey = hashKey.replaceAll("=", ".eq."); //$NON-NLS-1$ //$NON-NLS-2$
hashKey = hashKey.replaceAll("\\?", ".qu."); //$NON-NLS-1$ //$NON-NLS-2$
hashKey = hashKey.replaceAll("&", ".am."); //$NON-NLS-1$ //$NON-NLS-2$
hashKey = hashKey.replaceAll("\\+", ".pl."); //$NON-NLS-1$ //$NON-NLS-2$
key.setValue(hashKey);
persistenceManager.save(key);
String message = localizedMessages.getString("WidgetKeyManager.0")+hashKey+" \n"; //$NON-NLS-1$//$NON-NLS-2$
message+="\n" + localizedMessages.getString("WidgetKeyManager.1"); //$NON-NLS-1$ //$NON-NLS-2$
Configuration properties = (Configuration) request.getSession().getServletContext().getAttribute("properties"); //$NON-NLS-1$