Index: trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
===================================================================
--- trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java	(revision 8644)
+++ trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java	(revision 8717)
@@ -9,5 +9,4 @@
 package org.greenstone.gsdlas;
 
-import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
@@ -15,14 +14,10 @@
 import java.util.*;
 
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.*;
 
 import org.apache.velocity.Template;
 import org.apache.velocity.context.Context;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.servlet.VelocityServlet;
-import org.greenstone.gsdlas.profiles.*;
+import org.greenstone.gsdlas.users.UserManager;
 
 /**
@@ -36,8 +31,13 @@
     public static final Set actions = new TreeSet();
     static {
-        actions.add("subscribe");
+        actions.add("createSubscription");
+        actions.add("deleteSubscription");
+        actions.add("editSubscription");
         actions.add("showFeed");
-        actions.add("listSubscriptions"); // TODO remove (just for debugging)
-    }
+        actions.add("listSubscriptions");
+        actions.add("login");
+        actions.add("register");
+    }
+    
     
     protected Template handleRequest(HttpServletRequest req,
@@ -47,24 +47,13 @@
         
         if (action == null || !actions.contains(action)) {
-            context.put("title", "Unknown action");
-            context.put("message", "I don't know how to " + action);
-            context.put("details", "The only actions I know are " + actions);
-            try {
-                return getTemplate("error.vm");
-            } catch (ResourceNotFoundException e1) {
-                // TODO Auto-generated catch block
-                e1.printStackTrace();
-            } catch (ParseErrorException e1) {
-                // TODO Auto-generated catch block
-                e1.printStackTrace();
-            } catch (Exception e1) {
-                // TODO Auto-generated catch block
-                e1.printStackTrace();
-            }
-            return null;
+            String title = "Unknown action";
+            String message = "I don't know how to " + action;
+            String details = "The only actions I know are " + actions;
+            return showError(context, message, details);
         }
         
 
         Map args = req.getParameterMap();
+        // TODO stop this, we need multi-valued stuff
         args = normalise(args);
         
@@ -75,8 +64,7 @@
             templateString = (String) method.invoke(this, new Object[] {args, context});
         } catch (Exception e) {
-            templateString = "error.vm";
-            context.put("title", "Error");
-            context.put("message", "A general error has occured, I couldn't do what you told me to do.");
-            context.put("details", e.getMessage() + " (" + e.getClass().getName() + "), action is " + action);
+            String message = "An error has occured, I couldn't do what you told me to do.";
+            String details = e.getMessage() + " (" + e.getClass().getName() + "), action is " + action;
+            return showError(context, message, details);
         }
         
@@ -88,9 +76,8 @@
             e.printStackTrace();
             try {
-                error(req, res, e);
-            } catch (ServletException e2) {
-                // TODO Auto-generated catch block
-                e2.printStackTrace();
-            } catch (IOException e2) {
+                error((HttpServletRequest)context.get(REQUEST), 
+                        (HttpServletResponse)context.get(RESPONSE),
+                        e);
+            } catch (Exception e2) {
                 // TODO Auto-generated catch block
                 e2.printStackTrace();
@@ -104,30 +91,41 @@
      * @param context
      * @return the Velocity template to use
+     * @throws Exception
      */
-    public String subscribe(Map arguments, Context context) {
-        context.put("title", "Adding Subscription");
-        if (arguments.size() == 0) {
-            context.put("message", "Empty subscription, not added");
-            context.put("details", "A subscription has to define at least one predicate.");
-            return "error.vm";
-        }
-        try {
-            // TODO pass user information to profile store
-            Subscription sub = new Subscription(arguments);
-            // TODO this should probably be somewhere else
-            for (Iterator iter = sub.getPredicates().iterator(); iter.hasNext();) {
-                Predicate predicate = (Predicate) iter.next();
-                if (predicate != null) {
-                    predicate.addSubscription(sub);
-                }
-            }
-            ProfileStore.getInstance().addSubscription(sub);
-        } catch (ParseException e) {
-            context.put("message", "Eror in subscription creation, not added");
-            context.put("details", e.getMessage());
-            return "error.vm";
-        }
-        context.put("message", "Subscription added successfully");
-        return "general.vm";
+    public String createSubscription(Map arguments, Context context) throws Exception {
+        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
+        if (!UserManager.getInstance().isLoggedIn(session)) {
+            session.setAttribute("next_action", "createSubscription");
+            return "login.vm";
+        }
+        // TODO handle wizard-style stuff 
+        // if "finish"
+        ProfileStore.getInstance().createSubscription(arguments);
+        return listSubscriptions(arguments, context);
+        // else show next page
+    }
+
+    public String deleteSubscription(Map arguments, Context context) {
+        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
+        if (!UserManager.getInstance().isLoggedIn(session)) {
+            session.setAttribute("next_action", "deleteSubscription");
+            return "login.vm";
+        }
+        String subscriptionID = (String) arguments.get("subscriptionID");
+        ProfileStore.getInstance().deleteSubscription(subscriptionID);
+        return listSubscriptions(arguments, context);
+    }
+    
+    public String editSubscription(Map arguments, Context context) {
+        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
+        if (!UserManager.getInstance().isLoggedIn(session)) {
+            session.setAttribute("next_action", "editSubscription");
+            return "login.vm";
+        }
+        // TODO handle wizard-style stuff
+        // if "finish"
+        ProfileStore.getInstance().changeSubscription(arguments, session);
+        return listSubscriptions(arguments, context);
+        // else show next page
     }
     
@@ -136,9 +134,26 @@
         return "feed.vm";
     }
-    
+
     public String listSubscriptions(Map arguments, Context context) {
         context.put("title", "List of Subscriptions");
         context.put("list", ProfileStore.getInstance().getAllSubscriptions());
         return "list.vm";
+    }
+    
+    public String login(Map arguments, Context context) throws Exception {
+        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
+        UserManager.getInstance().loginUser(arguments, session);
+        if (session.getAttribute("next_action") != null) {
+            String nextAction = (String) session.getAttribute("next_action");
+            Method method = AlertingService.class.getDeclaredMethod(nextAction, new Class[] {Map.class, Context.class});
+            return (String) method.invoke(this, new Object[] {arguments, context});
+        }
+        return listSubscriptions(arguments, context);
+    }
+    
+    public String register(Map arguments, Context context) throws Exception {
+        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
+        UserManager.getInstance().createUser(arguments, session);
+        return login(arguments, context);
     }
     
@@ -172,3 +187,27 @@
         return result;
     }
+
+    /**
+     * @param context
+     * @param message
+     * @param details
+     * @return
+     */
+    private Template showError(Context context, String message, String details) {
+        context.put("title", "Error");
+        context.put("message", message);
+        context.put("details", details);
+        try {
+            return getTemplate("error.vm");
+        } catch (Exception e) {
+            try {
+                super.error((HttpServletRequest)context.get("req"), 
+                        (HttpServletResponse)context.get("res"), 
+                        e);
+            } catch (Exception e2) {
+                e2.printStackTrace();
+            }
+        }
+        return null;
+    }
 }
Index: trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
===================================================================
--- trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java	(revision 8644)
+++ trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java	(revision 8717)
@@ -11,4 +11,6 @@
 import java.util.*;
 
+import javax.servlet.http.HttpSession;
+
 import org.greenstone.gsdlas.profiles.*;
 import org.greenstone.gsdlas.profiles.IdEqualsPredicate;
@@ -48,5 +50,5 @@
      *            the subscription to add to the profile store.
      */
-    public void addSubscription(Subscription subscription) {
+    private void addSubscription(Subscription subscription) {
         Predicate documentIdPredicate = subscription.getPredicate("documentID");
         Predicate collectionIdPredicate = subscription.getPredicate("collectionID");
@@ -267,4 +269,41 @@
         return Collections.unmodifiableSet(allSubscriptions);
     }
+
+
+    /**
+     * @param arguments
+     * @throws ParseException
+     */
+    public void createSubscription(Map arguments) throws ParseException {
+        // TODO pass user information to profile store
+        Subscription sub = new Subscription(arguments);
+        // TODO this should probably be somewhere else
+        for (Iterator iter = sub.getPredicates().iterator(); iter.hasNext();) {
+            Predicate predicate = (Predicate) iter.next();
+            if (predicate != null) {
+                predicate.addSubscription(sub);
+            }
+        }
+        addSubscription(sub);
+    }
+
+    
+    /**
+     * @param subscriptionID
+     */
+    public void deleteSubscription(String subscriptionID) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /**
+     * @param arguments
+     * @param session
+     */
+    public void changeSubscription(Map arguments, HttpSession session) {
+        String subscriptionID = (String) arguments.get("subscriptionID");
+        // TODO Auto-generated method stub
+        
+    }
     
 }
Index: trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseException.java
===================================================================
--- trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseException.java	(revision 8717)
+++ trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseException.java	(revision 8717)
@@ -0,0 +1,22 @@
+/*
+ * Created on Dec 1, 2004
+ * Copyright (C) Andrea Schweer, 2004
+ *
+ * This file is part of the Greenstone Alerting Service.
+ * Refer to the COPYING file in the base directory of this package
+ * for licensing information.
+ */
+package org.greenstone.gsdlas.database;
+
+/**
+ * @author andrea
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class DatabaseException extends Exception {
+    
+    public DatabaseException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
Index: trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseManager.java
===================================================================
--- trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseManager.java	(revision 8717)
+++ trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseManager.java	(revision 8717)
@@ -0,0 +1,51 @@
+/*
+ * Created on Dec 1, 2004
+ * Copyright (C) Andrea Schweer, 2004
+ *
+ * This file is part of the Greenstone Alerting Service.
+ * Refer to the COPYING file in the base directory of this package
+ * for licensing information.
+ */
+package org.greenstone.gsdlas.database;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+
+/**
+ * @author andrea
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class DatabaseManager {
+
+    private static DatabaseManager instance;
+    private Connection database;
+
+    private DatabaseManager() {
+        // hide constructor
+    }
+    
+    public static DatabaseManager getInstance() {
+        if (instance == null) {
+            instance = new DatabaseManager();
+        }
+        return instance;
+    }
+    
+    public Connection getDatabaseConnection() throws DatabaseException {
+        if(database == null) {
+            String connectionString = "jdbc:mysql://localhost/alerting";
+            try {
+                Class.forName("com.mysql.jdbc.Driver").newInstance();
+                Connection connection = DriverManager.getConnection(connectionString);
+            } catch (Exception e) {
+                throw new DatabaseException("Could not establish connection to database (" + connectionString + ")", e);
+            }
+        }
+        return database;
+    }
+    
+    
+}
Index: trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/users/UserManager.java
===================================================================
--- trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/users/UserManager.java	(revision 8717)
+++ trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/users/UserManager.java	(revision 8717)
@@ -0,0 +1,66 @@
+/*
+ * Created on Dec 1, 2004
+ * Copyright (C) Andrea Schweer, 2004
+ *
+ * This file is part of the Greenstone Alerting Service.
+ * Refer to the COPYING file in the base directory of this package
+ * for licensing information.
+ */
+package org.greenstone.gsdlas.users;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+/**
+ * @author andrea
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class UserManager {
+    private static UserManager instance;
+    
+    private UserManager() {
+        // hide constructor
+    }
+    
+    static public UserManager getInstance() {
+        if (instance == null) {
+            instance = new UserManager();
+        }
+        return instance;
+    }
+
+    /**
+     * @param session
+     * @return
+     */
+    public boolean isLoggedIn(HttpSession session) {
+        if (session.getCreationTime() - session.getLastAccessedTime() > session.getMaxInactiveInterval())
+            return false;
+        
+        // TODO Auto-generated method stub
+        return true;
+    }
+
+    /**
+     * @param arguments
+     * @param session
+     */
+    public void createUser(Map arguments, HttpSession session) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /**
+     * @param arguments
+     * @param session
+     */
+    public void loginUser(Map arguments, HttpSession session) {
+        // TODO Auto-generated method stub
+        
+    }
+    
+    
+}
