You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/03/28 21:07:36 UTC

svn commit: r389579 - in /incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi: ./ sdk/

Author: snoopdave
Date: Tue Mar 28 11:07:34 2006
New Revision: 389579

URL: http://svn.apache.org/viewcvs?rev=389579&view=rev
Log:
Patch from Jeff Battman to improve error and exception handling in AAAP

Added:
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/BadRequestException.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/HandlerException.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/InternalException.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotAllowedException.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotFoundException.java
Modified:
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/AtomAdminServlet.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/Handler.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/IntrospectionHandler.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerMemberHandler.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerUserHandler.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerWeblogHandler.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntry.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntrySet.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntry.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntrySet.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntry.java
    incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntrySet.java

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/AtomAdminServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/AtomAdminServlet.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/AtomAdminServlet.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/AtomAdminServlet.java Tue Mar 28 11:07:34 2006
@@ -62,10 +62,10 @@
             Writer writer = res.getWriter();
             writer.write(s);            
             writer.close();            
-        } catch (Exception e) {
-            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-            e.printStackTrace(res.getWriter());
-            logger.error(e);
+        } catch (HandlerException he) {
+            res.sendError(he.getStatus(), he.getMessage());
+            he.printStackTrace(res.getWriter());
+            logger.error(he);
         }
     }
     
@@ -90,10 +90,10 @@
             Writer writer = res.getWriter();
             writer.write(s);            
             writer.close();            
-        } catch (Exception e) {
-            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-            e.printStackTrace(res.getWriter());
-            logger.error(e);
+        } catch (HandlerException he) {
+            res.sendError(he.getStatus(), he.getMessage());
+            he.printStackTrace(res.getWriter());
+            logger.error(he);
         }
     }
     
@@ -118,10 +118,10 @@
             Writer writer = res.getWriter();
             writer.write(s);            
             writer.close();            
-        } catch (Exception e) {
-            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-            e.printStackTrace(res.getWriter());
-            logger.error(e);
+        } catch (HandlerException he) {
+            res.sendError(he.getStatus(), he.getMessage());
+            he.printStackTrace(res.getWriter());
+            logger.error(he);
         }
     }
     
@@ -145,10 +145,10 @@
             Writer writer = res.getWriter();
             writer.write(s);            
             writer.close();                        
-        } catch (Exception e) {
-            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-            e.printStackTrace(res.getWriter());
-            logger.error(e);
+        } catch (HandlerException he) {
+            res.sendError(he.getStatus(), he.getMessage());
+            he.printStackTrace(res.getWriter());
+            logger.error(he);
         }
     }
 }

Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/BadRequestException.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/BadRequestException.java?rev=389579&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/BadRequestException.java (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/BadRequestException.java Tue Mar 28 11:07:34 2006
@@ -0,0 +1,17 @@
+package org.roller.presentation.atomadminapi;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Indicates to client that a bad (syntactically incorrect)
+ * request has been made.
+ */
+public class BadRequestException extends HandlerException { 
+    public BadRequestException(String msg) {
+        super(msg);
+    }    
+    
+    public int getStatus() {
+        return HttpServletResponse.SC_BAD_REQUEST;
+    }
+}

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/Handler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/Handler.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/Handler.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/Handler.java Tue Mar 28 11:07:34 2006
@@ -87,7 +87,7 @@
     private String urlPrefix;
     
     /** Get a Handler object implementation based on the given request. */
-    public static Handler getHandler(HttpServletRequest req) throws Exception {
+    public static Handler getHandler(HttpServletRequest req) throws HandlerException {
          URI uri = new URI(req);
          Handler handler;
          
@@ -102,10 +102,10 @@
              } else if (type.equals(EntrySet.Types.MEMBERS)) {
                  handler = new RollerMemberHandler(req);                  
              } else {
-                 throw new Exception("ERROR: Unknown type: " + uri.getType());
+                 throw new BadRequestException("ERROR: Unknown type: " + uri.getType());
              }
          } else {
-             throw new Exception("ERROR: Unknown URI type");
+             throw new BadRequestException("ERROR: Unknown URI type");
          }
     
          return handler;
@@ -155,13 +155,13 @@
     }   
     
     /** Process an HTTP GET request. */
-    public abstract EntrySet processGet() throws Exception;
+    public abstract EntrySet processGet() throws HandlerException;
     /** Process an HTTP POST request. */
-    public abstract EntrySet processPost(Reader r) throws Exception;
+    public abstract EntrySet processPost(Reader r) throws HandlerException;
     /** Process an HTTP PUT request. */
-    public abstract EntrySet processPut(Reader r) throws Exception;
+    public abstract EntrySet processPut(Reader r) throws HandlerException;
     /** Process an HTTP DELETE request. */
-    public abstract EntrySet processDelete() throws Exception;
+    public abstract EntrySet processDelete() throws HandlerException;
     
     protected URI getUri() {
         return uri;

Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/HandlerException.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/HandlerException.java?rev=389579&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/HandlerException.java (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/HandlerException.java Tue Mar 28 11:07:34 2006
@@ -0,0 +1,24 @@
+package org.roller.presentation.atomadminapi;
+
+/**
+ * Abstract base class for all handler exceptions.
+ *
+ * Subclasses of this class allow handler implementations to indicate to
+ * callers a particular HTTP error type, while still providing
+ * a textual description of the problem.
+ * 
+ * Callers may use the 
+ * <code>getStatus()</code> method to discover the HTTP status
+ * code that should be returned to the client.
+ */
+public abstract class HandlerException extends Exception { 
+    public HandlerException(String msg) {
+        super(msg);
+    }    
+
+    public HandlerException(String msg, Throwable t) {
+        super(msg);
+    }    
+    
+    public abstract int getStatus();
+}

Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/InternalException.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/InternalException.java?rev=389579&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/InternalException.java (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/InternalException.java Tue Mar 28 11:07:34 2006
@@ -0,0 +1,17 @@
+package org.roller.presentation.atomadminapi;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Indicates to client that an internal error occured when processing
+ * the request.
+ */
+public class InternalException extends HandlerException { 
+    public InternalException(String msg, Throwable t) {
+        super(msg, t);
+    }    
+    
+    public int getStatus() {
+        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+    }
+}

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/IntrospectionHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/IntrospectionHandler.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/IntrospectionHandler.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/IntrospectionHandler.java Tue Mar 28 11:07:34 2006
@@ -24,11 +24,11 @@
         super(request);
     }
     
-    public EntrySet processGet() throws Exception {
+    public EntrySet processGet() throws HandlerException {
         if (getUri().isIntrospection()) {
             return getIntrospection(getRequest());
         } else {
-            throw new Exception("ERROR: Unknown GET URI type");
+            throw new BadRequestException("ERROR: Unknown GET URI type");
         }
     }
     
@@ -44,7 +44,7 @@
         throw new UnsupportedOperationException("ERROR: DELETE not supported in this handler");
     }
     
-    private Service getIntrospection(HttpServletRequest req) throws Exception {
+    private Service getIntrospection(HttpServletRequest req) {
         String href = getUrlPrefix();
         Service service = new Service(href);
         

Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotAllowedException.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotAllowedException.java?rev=389579&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotAllowedException.java (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotAllowedException.java Tue Mar 28 11:07:34 2006
@@ -0,0 +1,17 @@
+package org.roller.presentation.atomadminapi;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Indicates to client that they are not allows to perform the requested
+ * operation on the requested resource.
+ */
+public class NotAllowedException extends HandlerException { 
+    public NotAllowedException(String msg) {
+        super(msg);
+    }    
+    
+    public int getStatus() {
+        return HttpServletResponse.SC_METHOD_NOT_ALLOWED;
+    }
+}

Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotFoundException.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotFoundException.java?rev=389579&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotFoundException.java (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/NotFoundException.java Tue Mar 28 11:07:34 2006
@@ -0,0 +1,17 @@
+package org.roller.presentation.atomadminapi;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Indicates to client that the requested resource was not found
+ * on the server.
+ */
+public class NotFoundException extends HandlerException { 
+    public NotFoundException(String msg) {
+        super(msg);
+    }    
+    
+    public int getStatus() {
+        return HttpServletResponse.SC_NOT_FOUND;
+    }
+}

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerMemberHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerMemberHandler.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerMemberHandler.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerMemberHandler.java Tue Mar 28 11:07:34 2006
@@ -5,6 +5,7 @@
  */
 package org.roller.presentation.atomadminapi;
 
+import java.io.IOException;
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -12,6 +13,7 @@
 import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import org.jdom.Document;
+import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.roller.RollerException;
 import org.roller.model.UserManager;
@@ -22,6 +24,8 @@
 import org.roller.presentation.atomadminapi.sdk.EntrySet;
 import org.roller.presentation.atomadminapi.sdk.MemberEntry;
 import org.roller.presentation.atomadminapi.sdk.MemberEntrySet;
+import org.roller.presentation.atomadminapi.sdk.MissingElementException;
+import org.roller.presentation.atomadminapi.sdk.UnexpectedRootElementException;
 import org.roller.presentation.cache.CacheManager;
 
 /**
@@ -35,33 +39,33 @@
         private String handle;
         
         public MemberURI(HttpServletRequest req) {
-            super(req);           
+            super(req);
             setHandle(getEntryId());
             if (getEntryIds() != null && getEntryIds().length > 1) {
                 setUsername(getEntryIds()[1]);
             }
         }
-               
+        
         public boolean hasUsername() {
             return getUsername() != null;
         }
-
+        
         public String getUsername() {
             return username;
         }
-
+        
         private void setUsername(String username) {
             this.username = username;
         }
-
+        
         public String getHandle() {
             return handle;
         }
-
+        
         private void setHandle(String handle) {
             this.handle = handle;
         }
-    }    
+    }
     
     private URI memberUri;
     
@@ -74,152 +78,194 @@
         return memberUri;
     }
     
-    public EntrySet processGet() throws Exception {
+    public EntrySet processGet() throws HandlerException {
         if (getUri().isCollection()) {
             return getCollection();
         } else if (getUri().isEntry()) {
             return getEntry();
         } else {
-            throw new Exception("ERROR: Unknown GET URI type");
+            throw new BadRequestException("ERROR: Unknown GET URI type");
         }
     }
     
-    public EntrySet processPost(Reader r) throws Exception {
+    public EntrySet processPost(Reader r) throws HandlerException {
         if (getUri().isCollection()) {
             return postCollection(r);
         } else {
-            throw new Exception("ERROR: Unknown POST URI type");
+            throw new BadRequestException("ERROR: Unknown POST URI type");
         }
     }
     
-    public EntrySet processPut(Reader r) throws Exception {
+    public EntrySet processPut(Reader r) throws HandlerException {
         if (getUri().isCollection()) {
             return putCollection(r);
         } else if (getUri().isEntry()) {
             return putEntry(r);
         } else {
-            throw new Exception("ERROR: Unknown PUT URI type");
+            throw new BadRequestException("ERROR: Unknown PUT URI type");
         }
     }
     
-    public EntrySet processDelete() throws Exception {
+    public EntrySet processDelete() throws HandlerException {
         if (getUri().isEntry()) {
             return deleteEntry();
         } else {
-            throw new Exception("ERROR: Unknown DELETE URI type");
+            throw new BadRequestException("ERROR: Unknown DELETE URI type");
         }
     }
     
-    private EntrySet getCollection() throws Exception {
+    private EntrySet getCollection() throws HandlerException {
         // get all permissions: for all users, for all websites
-        List users = getRoller().getUserManager().getUsers();
-        List perms = new ArrayList();
-        for (Iterator i = users.iterator(); i.hasNext(); ) {
-            UserData user = (UserData)i.next();
-            List permissions = getRoller().getUserManager().getAllPermissions(user);
-            for (Iterator j = permissions.iterator(); j.hasNext(); ) {
-                PermissionsData pd = (PermissionsData)j.next();
-                perms.add(pd);
+        try {
+            List users = getRoller().getUserManager().getUsers();
+            List perms = new ArrayList();
+            for (Iterator i = users.iterator(); i.hasNext(); ) {
+                UserData user = (UserData)i.next();
+                List permissions = getRoller().getUserManager().getAllPermissions(user);
+                for (Iterator j = permissions.iterator(); j.hasNext(); ) {
+                    PermissionsData pd = (PermissionsData)j.next();
+                    perms.add(pd);
+                }
             }
+            EntrySet es = toMemberEntrySet((PermissionsData[])perms.toArray(new PermissionsData[0]));
+            return es;
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not get member collection", re);
         }
-        EntrySet es = toMemberEntrySet((PermissionsData[])perms.toArray(new PermissionsData[0]));
-        return es;
     }
     
-    private EntrySet getEntry() throws Exception {
+    private EntrySet getEntry() throws HandlerException {
         MemberURI muri = (MemberURI)getUri();
         String handle = muri.getHandle();
         String username = muri.getUsername();
-               
-        List perms;
-        if (username == null) {
-            //get all entries for the given website handle
-            WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(handle);
-            if (wd == null) {
-                throw new Exception("ERROR: Unknown weblog handle: " + handle);
-            }
-            perms = getRoller().getUserManager().getAllPermissions(wd);
-        } else {
-            //get all entries for the given website handle & username
-            WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(handle);
-            if (wd == null) {
-                throw new Exception("ERROR: Unknown weblog handle: " + handle);
-            }
-            UserData ud = getRoller().getUserManager().getUser(username);
-            if (ud == null) {
-                throw new Exception("ERROR: Unknown user name: " + username);
+        
+        try {
+            List perms;
+            if (username == null) {
+                //get all entries for the given website handle
+                WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(handle);
+                if (wd == null) {
+                    throw new NotFoundException("ERROR: Unknown weblog handle: " + handle);
+                }
+                perms = getRoller().getUserManager().getAllPermissions(wd);
+            } else {
+                //get all entries for the given website handle & username
+                WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(handle);
+                if (wd == null) {
+                    throw new NotFoundException("ERROR: Unknown weblog handle: " + handle);
+                }
+                UserData ud = getRoller().getUserManager().getUser(username);
+                if (ud == null) {
+                    throw new NotFoundException("ERROR: Unknown user name: " + username);
+                }
+                PermissionsData pd = getRoller().getUserManager().getPermissions(wd, ud);
+                if (pd == null) {
+                    throw new NotFoundException("ERROR: Could not get permissions for user name: " + username + ", handle: " + handle);
+                }
+                perms = Collections.singletonList(pd);
             }
-            perms = Collections.singletonList(getRoller().getUserManager().getPermissions(wd, ud));
+            
+            EntrySet es = toMemberEntrySet((PermissionsData[])perms.toArray(new PermissionsData[0]));
+            return es;
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not get entry for handle: " + handle + ", username: " + username, re);
         }
-        
-        EntrySet es = toMemberEntrySet((PermissionsData[])perms.toArray(new PermissionsData[0]));
-        return es;
     }
     
-    private EntrySet postCollection(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
-        createMembers((MemberEntrySet)c);
-        
-        return c;
+    private EntrySet postCollection(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
+            createMembers((MemberEntrySet)c);
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
+        }       
     }
     
-    private EntrySet putCollection(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
-        updateMembers((MemberEntrySet)c);
-        
-        return c;
+    private EntrySet putCollection(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
+            updateMembers((MemberEntrySet)c);
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
+        }       
     }
     
-    private EntrySet putEntry(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
-        
-        if (c.getEntries().length > 1) {
-            throw new Exception("ERROR: Cannot put >1 entries per request");
-        }
-        if (c.getEntries().length > 0) {
-            // only one entry
-            // if there's zero entries, this is a nop
-            MemberEntry entry = (MemberEntry)c.getEntries()[0];
-            
-            MemberURI muri = (MemberURI)getUri();            
+    private EntrySet putEntry(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
             
-            // get handle
-            // if there's no handle in the entry, set it
-            // if the entry and URI handles do not match, exception
-            String handle = muri.getHandle();
-            if (entry.getHandle() == null) {
-                entry.setHandle(handle);
-            } else if (!entry.getHandle().equals(handle)) {
-                throw new Exception("ERROR: URI and entry handle do not match");
+            if (c.getEntries().length > 1) {
+                throw new BadRequestException("ERROR: Cannot put >1 entries per request");
             }
-            
-            // get username
-            // if there's no name in the entry or the URI, exception
-            // if there's no name in the entry, set it
-            // if the names in the entry and URI do not match, exception
-            String username = muri.getUsername();
-            if (entry.getName() == null) {
-                if (username == null) {
-                    throw new Exception("ERROR: No user name in URI or entry");
+            if (c.getEntries().length > 0) {
+                // only one entry
+                // if there's zero entries, this is a nop
+                MemberEntry entry = (MemberEntry)c.getEntries()[0];
+                
+                MemberURI muri = (MemberURI)getUri();
+                
+                // get handle
+                // if there's no handle in the entry, set it
+                // if the entry and URI handles do not match, exception
+                String handle = muri.getHandle();
+                if (entry.getHandle() == null) {
+                    entry.setHandle(handle);
+                } else if (!entry.getHandle().equals(handle)) {
+                    throw new BadRequestException("ERROR: URI and entry handle do not match");
                 }
-                entry.setName(username);
-            } else if (username != null && !entry.getName().equals(username)) {
-                throw new Exception("ERROR: URI and entry user name do not match");
+                
+                // get username
+                // if there's no name in the entry or the URI, exception
+                // if there's no name in the entry, set it
+                // if the names in the entry and URI do not match, exception
+                String username = muri.getUsername();
+                if (entry.getName() == null) {
+                    if (username == null) {
+                        throw new BadRequestException("ERROR: No user name in URI or entry");
+                    }
+                    entry.setName(username);
+                } else if (username != null && !entry.getName().equals(username)) {
+                    throw new BadRequestException("ERROR: URI and entry user name do not match");
+                }
+                
+                updateMembers((MemberEntrySet)c);
             }
-                                    
-            updateMembers((MemberEntrySet)c);
-        }
-        
-        return c;
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
+        }        
     }
     
-    private void createMembers(MemberEntrySet c) throws Exception {
+    private void createMembers(MemberEntrySet c) throws HandlerException {
         try {
             UserManager mgr = getRoller().getUserManager();
             
@@ -229,15 +275,15 @@
             for (int i = 0; i < c.getEntries().length; i++) {
                 MemberEntry entry = (MemberEntry)c.getEntries()[i];
                 PermissionsData pd = toPermissionsData(entry);
-                pd.save();                
+                pd.save();
             }
             getRoller().commit();
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not create members", re);
         }
     }
     
-    private PermissionsData toPermissionsData(MemberEntry entry) throws Exception {
+    private PermissionsData toPermissionsData(MemberEntry entry) throws HandlerException {
         try {
             UserManager mgr = getRoller().getUserManager();
             UserData ud = mgr.getUser(entry.getName());
@@ -250,15 +296,15 @@
             
             return pd;
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not convert to permissions data", re);
         }
     }
     
-    private PermissionsData getPermissionsData(MemberEntry entry) throws Exception {
+    private PermissionsData getPermissionsData(MemberEntry entry) throws HandlerException {
         return getPermissionsData(entry.getHandle(), entry.getName());
     }
     
-    private PermissionsData getPermissionsData(String handle, String username) throws Exception {
+    private PermissionsData getPermissionsData(String handle, String username) throws HandlerException {
         try {
             UserManager mgr = getRoller().getUserManager();
             UserData ud = mgr.getUser(username);
@@ -267,68 +313,87 @@
             
             return pd;
         } catch (RollerException re) {
-            throw new Exception(re);
-        }        
-    }    
-    private void updateMembers(MemberEntrySet c) throws Exception {
+            throw new InternalException("ERROR: Could not get permissions data", re);
+        }
+    }
+    
+    private void updateMembers(MemberEntrySet c) throws HandlerException {
         try {
             getRoller().setUser(UserData.SYSTEM_USER);
             for (int i = 0; i < c.getEntries().length; i++) {
                 MemberEntry entry = (MemberEntry)c.getEntries()[i];
                 PermissionsData pd = getPermissionsData(entry);
                 if (pd == null) {
-                    throw new Exception("ERROR: Permissions do not exist for weblog handle: " + entry.getHandle() + ", user name: " + entry.getName());
+                    throw new NotFoundException("ERROR: Permissions do not exist for weblog handle: " + entry.getHandle() + ", user name: " + entry.getName());
                 }
                 updatePermissionsData(pd, entry);
-                pd.save();
             }
             getRoller().commit();
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not update members", re);
         }
     }
     
-    private void updatePermissionsData(PermissionsData pd, MemberEntry entry) {
+    private void updatePermissionsData(PermissionsData pd, MemberEntry entry) throws HandlerException {
         // only permission can be updated
         
         if (entry.getPermission() != null) {
             pd.setPermissionMask(stringToMask(entry.getPermission()));
         }
+        
+        try {
+            UserData ud = getRoller().getUserManager().getUser(entry.getName());
+            CacheManager.invalidate(ud);
+            WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(entry.getHandle());
+            CacheManager.invalidate(wd);
+            
+            pd.save();
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not update permissions data", re);
+        }
+        
     }
     
-    private EntrySet deleteEntry() throws Exception {
+    private EntrySet deleteEntry() throws HandlerException {
         MemberURI muri = (MemberURI)getUri();
         
         String handle = muri.getHandle();
         String username = muri.getUsername();
-       
+        
         if (username == null) {
-            throw new Exception("ERROR: No user name supplied in URI");
+            throw new BadRequestException("ERROR: No user name supplied in URI");
         }
         
         try {
             getRoller().setUser(UserData.SYSTEM_USER);
             PermissionsData pd = getPermissionsData(handle, username);
-            PermissionsData[] pds = new PermissionsData[] { pd };               
-            EntrySet es = toMemberEntrySet(pds);
-        
+            PermissionsData[] pds;
+            if (pd == null) {
+                throw new NotFoundException("ERROR: Permissions do not exist for weblog handle: " + handle + ", user name: " + username);
+            }
+            pds = new PermissionsData[] { pd };
+            
             pd.remove();
             getRoller().commit();
-
-            UserData ud = getRoller().getUserManager().getUser(username);            
+            
+            UserData ud = getRoller().getUserManager().getUser(username);
             CacheManager.invalidate(ud);
             WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(handle);
             CacheManager.invalidate(wd);
             
-            return es;            
+            EntrySet es = toMemberEntrySet(pds);
+            return es;
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not delete entry", re);
         }
     }
     
     private MemberEntry toMemberEntry(PermissionsData pd) {
-        MemberEntry me = new MemberEntry(pd.getWebsite().getHandle(), pd.getUser().getUserName(), getUrlPrefix());        
-        me.setPermission(maskToString(pd.getPermissionMask()));          
+        if (pd == null) {
+            throw new NullPointerException("ERROR: Null permission data not allowed");
+        }
+        MemberEntry me = new MemberEntry(pd.getWebsite().getHandle(), pd.getUser().getUserName(), getUrlPrefix());
+        me.setPermission(maskToString(pd.getPermissionMask()));
         
         return me;
     }
@@ -337,14 +402,14 @@
             throw new NullPointerException("ERROR: Null permission data not allowed");
         }
         
-        List entries = new ArrayList();        
+        List entries = new ArrayList();
         for (int i = 0; i < pds.length; i++) {
             PermissionsData pd = pds[i];
             Entry entry = toMemberEntry(pd);
-            entries.add(entry);            
+            entries.add(entry);
         }
         MemberEntrySet mes = new MemberEntrySet(getUrlPrefix());
-        mes.setEntries((Entry[])entries.toArray(new Entry[0])); 
+        mes.setEntries((Entry[])entries.toArray(new Entry[0]));
         
         return mes;
     }
@@ -361,9 +426,12 @@
         }
         return null;
     }
-
+    
     
     private static short stringToMask(String s) {
+        if (s == null) {
+            throw new NullPointerException("ERROR: Null string not allowed");
+        }
         if (s.equalsIgnoreCase(MemberEntry.Permissions.ADMIN)) {
             return PermissionsData.ADMIN;
         }
@@ -374,6 +442,6 @@
             return PermissionsData.LIMITED;
         }
         return 0;
-    }    
+    }
 }
 

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerUserHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerUserHandler.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerUserHandler.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerUserHandler.java Tue Mar 28 11:07:34 2006
@@ -5,17 +5,21 @@
  */
 package org.roller.presentation.atomadminapi;
 
+import java.io.IOException;
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import org.jdom.Document;
+import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.roller.RollerException;
 import org.roller.model.UserManager;
 import org.roller.pojos.UserData;
 import org.roller.presentation.atomadminapi.sdk.Entry;
 import org.roller.presentation.atomadminapi.sdk.EntrySet;
+import org.roller.presentation.atomadminapi.sdk.MissingElementException;
+import org.roller.presentation.atomadminapi.sdk.UnexpectedRootElementException;
 import org.roller.presentation.atomadminapi.sdk.UserEntry;
 import org.roller.presentation.atomadminapi.sdk.UserEntrySet;
 import org.roller.presentation.cache.CacheManager;
@@ -30,99 +34,140 @@
         super(request);
     }
     
-    public EntrySet processGet() throws Exception {
+    public EntrySet processGet() throws HandlerException {
         if (getUri().isCollection()) {
             return getCollection();
         } else if (getUri().isEntry()) {
             return getEntry();
         } else {
-            throw new Exception("ERROR: Unknown GET URI type");
+            throw new BadRequestException("ERROR: Unknown GET URI type");
         }
     }
     
-    public EntrySet processPost(Reader r) throws Exception {
+    public EntrySet processPost(Reader r) throws HandlerException {
         if (getUri().isCollection()) {
             return postCollection(r);
         } else {
-            throw new Exception("ERROR: Unknown POST URI type");
+            throw new BadRequestException("ERROR: Unknown POST URI type");
         }
     }
     
-    public EntrySet processPut(Reader r) throws Exception {
+    public EntrySet processPut(Reader r) throws HandlerException {
         if (getUri().isCollection()) {
             return putCollection(r);
         } else if (getUri().isEntry()) {
             return putEntry(r);
         } else {
-            throw new Exception("ERROR: Unknown PUT URI type");
+            throw new BadRequestException("ERROR: Unknown PUT URI type");
         }
     }
     
-    public EntrySet processDelete() throws Exception {
+    public EntrySet processDelete() throws HandlerException {
         if (getUri().isEntry()) {
             return deleteEntry();
         } else {
-            throw new Exception("ERROR: Unknown DELETE URI type");
+            throw new BadRequestException("ERROR: Unknown DELETE URI type");
         }
     }
     
-    private EntrySet getCollection() throws Exception {
-        List users = getRoller().getUserManager().getUsers();
-        EntrySet es = toUserEntrySet((UserData[])users.toArray(new UserData[0]));
-        
-        return es;
+    private EntrySet getCollection() throws HandlerException {
+        try {
+            List users = getRoller().getUserManager().getUsers();
+            if (users == null) {
+                users = java.util.Collections.EMPTY_LIST;
+            }
+            EntrySet es = toUserEntrySet((UserData[])users.toArray(new UserData[0]));
+            
+            return es;
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not get user collection", re);
+        }
     }
     
-    private EntrySet getEntry() throws Exception {
-        UserData ud = getRoller().getUserManager().getUser(getUri().getEntryId());
-        if (ud == null) {
-            throw new Exception("ERROR: Unknown user name: " + getUri().getEntryId());
+    private EntrySet getEntry() throws HandlerException {
+        try {
+            UserData ud = getRoller().getUserManager().getUser(getUri().getEntryId());
+            if (ud == null) {
+                throw new NotFoundException("ERROR: Unknown user: " + getUri().getEntryId());
+            }
+            UserData[] uds = new UserData[] { ud };
+            
+            EntrySet c = toUserEntrySet(uds);
+            return c;
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not get user collection", re);
         }
-        UserData[] uds = new UserData[] { ud };
-        EntrySet c = toUserEntrySet(uds);
-        
-        return c;
     }
     
-    private EntrySet postCollection(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new UserEntrySet(collectionDoc, getUrlPrefix());
-        createUsers((UserEntrySet)c);
-        
-        return c;
+    private EntrySet postCollection(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new UserEntrySet(collectionDoc, getUrlPrefix());
+            createUsers((UserEntrySet)c);
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
+        }
     }
     
-    private EntrySet putCollection(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new UserEntrySet(collectionDoc, getUrlPrefix());
-        updateUsers((UserEntrySet)c);
-        
-        return c;
+    private EntrySet putCollection(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new UserEntrySet(collectionDoc, getUrlPrefix());
+            updateUsers((UserEntrySet)c);
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
+        }
     }
     
-    private EntrySet putEntry(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new UserEntrySet(collectionDoc, getUrlPrefix());
-        
-        if (c.getEntries().length > 1) {
-            throw new Exception("ERROR: Cannot put >1 entries per request");
-        }
-        if (c.getEntries().length > 0) {
-            UserEntry entry = (UserEntry)c.getEntries()[0];
-            if (entry.getName() != null && !entry.getName().equals(getUri().getEntryId())) {
-                throw new Exception("ERROR: Content name does not match URI name");
+    private EntrySet putEntry(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new UserEntrySet(collectionDoc, getUrlPrefix());
+            
+            if (c.getEntries().length > 1) {
+                throw new BadRequestException("ERROR: Cannot put >1 entries per request");
             }
-            entry.setName(getUri().getEntryId());
-            updateUsers((UserEntrySet)c);
+            if (c.getEntries().length > 0) {
+                UserEntry entry = (UserEntry)c.getEntries()[0];
+                if (entry.getName() != null && !entry.getName().equals(getUri().getEntryId())) {
+                    throw new BadRequestException("ERROR: Content name does not match URI name");
+                }
+                entry.setName(getUri().getEntryId());
+                updateUsers((UserEntrySet)c);
+            }
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
         }
-        
-        return c;
     }
     
-    private void createUsers(UserEntrySet c) throws Exception {
+    private void createUsers(UserEntrySet c) throws HandlerException {
         try {
             UserManager mgr = getRoller().getUserManager();
             
@@ -136,11 +181,11 @@
             }
             getRoller().commit();
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not create users: " + c, re);
         }
     }
     
-    private void updateUsers(UserEntrySet c) throws Exception {
+    private void updateUsers(UserEntrySet c) throws NotFoundException, InternalException {
         try {
             UserManager mgr = getRoller().getUserManager();
             
@@ -150,12 +195,15 @@
             for (int i = 0; i < c.getEntries().length; i++) {
                 UserEntry entry = (UserEntry)c.getEntries()[i];
                 UserData ud = mgr.getUser(entry.getName());
+                if (ud == null) {
+                    throw new NotFoundException("ERROR: Uknown user: " + entry.getName());
+                }
                 updateUserData(ud, entry);
                 ud.save();
             }
             getRoller().commit();
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not update users: " + c, re);
         }
     }
     
@@ -179,39 +227,43 @@
         }
     }
     
-    private EntrySet deleteEntry() throws Exception {
+    private EntrySet deleteEntry() throws HandlerException {
         try {
             getRoller().setUser(UserData.SYSTEM_USER);
             UserManager mgr = getRoller().getUserManager();
             UserData ud = mgr.getUser(getUri().getEntryId());
             
+            if (ud == null) {
+                throw new NotFoundException("ERROR: Uknown user: " + getUri().getEntryId());
+            }
             // don't allow deletion of the currently authenticated user
             if (ud.getUserName().equals(getUsername())) {
-                throw new Exception("ERROR: Can't delete authenticated user: " + getUsername());
+                throw new NotAllowedException("ERROR: Can't delete authenticated user: " + getUsername());
             }
             
             UserData[] uds = new UserData[] { ud };
-            EntrySet es = toUserEntrySet(uds);
-            
             ud.remove();
             getRoller().commit();
-            
             CacheManager.invalidate(ud);
             
+            EntrySet es = toUserEntrySet(uds);
             return es;
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not delete entry: " + getUri().getEntryId(), re);
         }
     }
     
     private UserEntry toUserEntry(UserData ud) {
+        if (ud == null) {
+            throw new NullPointerException("ERROR: Null user data not allowed");
+        }
         UserEntry ue = new UserEntry(ud.getUserName(), getUrlPrefix());
         ue.setFullName(ud.getFullName());
         ue.setPassword(ud.getPassword());
         ue.setLocale(ud.getLocale());
         ue.setTimezone(ud.getTimeZone());
         ue.setEmailAddress(ud.getEmailAddress());
-        ue.setDateCreated(ud.getDateCreated());        
+        ue.setDateCreated(ud.getDateCreated());
         
         return ue;
     }
@@ -220,21 +272,24 @@
         if (uds == null) {
             throw new NullPointerException("ERROR: Null user data not allowed");
         }
-        UserEntrySet ues = new UserEntrySet(getUrlPrefix());        
+        UserEntrySet ues = new UserEntrySet(getUrlPrefix());
         
-        List entries = new ArrayList();        
+        List entries = new ArrayList();
         for (int i = 0; i < uds.length; i++) {
             UserData ud = uds[i];
             Entry entry = toUserEntry(ud);
-            entries.add(entry);            
+            entries.add(entry);
         }
-        ues.setEntries((Entry[])entries.toArray(new Entry[0]));  
+        ues.setEntries((Entry[])entries.toArray(new Entry[0]));
         
         return ues;
     }
     
     /** This object, as a Roller UserData object. */
     public UserData toUserData(UserEntry ue) {
+        if (ue == null) {
+            throw new NullPointerException("ERROR: Null user entry not allowed");
+        }
         UserData ud = new UserData();
         ud.setUserName(ue.getName());
         ud.setFullName(ue.getFullName());
@@ -245,6 +300,6 @@
         ud.setDateCreated(ue.getDateCreated());
         
         return ud;
-    }    
+    }
 }
 

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerWeblogHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerWeblogHandler.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerWeblogHandler.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/RollerWeblogHandler.java Tue Mar 28 11:07:34 2006
@@ -5,13 +5,16 @@
  */
 package org.roller.presentation.atomadminapi;
 
+import java.io.IOException;
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Collections;
 import javax.servlet.http.HttpServletRequest;
 import org.jdom.Document;
+import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.roller.RollerException;
 import org.roller.model.UserManager;
@@ -20,12 +23,14 @@
 import org.roller.pojos.WebsiteData;
 import org.roller.presentation.atomadminapi.sdk.Entry;
 import org.roller.presentation.atomadminapi.sdk.EntrySet;
+import org.roller.presentation.atomadminapi.sdk.MissingElementException;
+import org.roller.presentation.atomadminapi.sdk.UnexpectedRootElementException;
 import org.roller.presentation.atomadminapi.sdk.WeblogEntry;
 import org.roller.presentation.atomadminapi.sdk.WeblogEntrySet;
 import org.roller.presentation.cache.CacheManager;
 
 /**
- * This class handles requests concernning Roller weblog resources.
+ * This class handles requests concerning Roller weblog resources.
  *
  * @author jtb
  */
@@ -37,99 +42,140 @@
         super(request);
     }
     
-    public EntrySet processGet() throws Exception {
+    public EntrySet processGet() throws HandlerException {
         if (getUri().isCollection()) {
             return getCollection();
         } else if (getUri().isEntry()) {
             return getEntry();
         } else {
-            throw new Exception("ERROR: Unknown GET URI type");
+            throw new BadRequestException("ERROR: Unknown GET URI type");
         }
     }
     
-    public EntrySet processPost(Reader r) throws Exception {
+    public EntrySet processPost(Reader r) throws HandlerException {
         if (getUri().isCollection()) {
             return postCollection(r);
         } else {
-            throw new Exception("ERROR: Unknown POST URI type");
-        }        
+            throw new BadRequestException("ERROR: Unknown POST URI type");
+        }
     }
     
-    public EntrySet processPut(Reader r) throws Exception {
+    public EntrySet processPut(Reader r) throws HandlerException {
         if (getUri().isCollection()) {
             return putCollection(r);
         } else if (getUri().isEntry()) {
             return putEntry(r);
         } else {
-            throw new Exception("ERROR: Unknown PUT URI type");
+            throw new BadRequestException("ERROR: Unknown PUT URI type");
         }
     }
     
-    public EntrySet processDelete() throws Exception {
+    public EntrySet processDelete() throws HandlerException {
         if (getUri().isEntry()) {
             return deleteEntry();
         } else {
-            throw new Exception("ERROR: Unknown DELETE URI type");
+            throw new BadRequestException("ERROR: Unknown DELETE URI type");
         }
-    }    
-    
-    private EntrySet getCollection() throws Exception {
-        List users = getRoller().getUserManager().getUsers();
-        EntrySet c = toWeblogEntrySet(users);
-        
-        return c;
     }
     
-    private EntrySet getEntry() throws Exception {
-        WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(getUri().getEntryId());
-        if (wd == null) {
-            throw new Exception("ERROR: Unknown weblog handle: " + getUri().getEntryId());
+    private EntrySet getCollection() throws HandlerException {
+        try {
+            List users = getRoller().getUserManager().getUsers();
+            if (users == null) {
+                users = Collections.EMPTY_LIST;
+            }
+            EntrySet c = toWeblogEntrySet(users);
+            
+            return c;
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not get weblog collection", re);
         }
-        WebsiteData[] wds = new WebsiteData[] { wd };
-        EntrySet c = toWeblogEntrySet(wds);
-        
-        return c;
     }
     
-    private EntrySet postCollection(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
-        createWeblogs((WeblogEntrySet)c);
-        
-        return c;
+    private EntrySet getEntry() throws HandlerException {
+        try {
+            WebsiteData wd = getRoller().getUserManager().getWebsiteByHandle(getUri().getEntryId());
+            if (wd == null) {
+                throw new NotFoundException("ERROR: Unknown weblog handle: " + getUri().getEntryId());
+            }
+            WebsiteData[] wds = new WebsiteData[] { wd };
+            EntrySet c = toWeblogEntrySet(wds);
+            
+            return c;
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not get weblog collection", re);
+        }
     }
     
-    private EntrySet putCollection(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
-        updateWeblogs((WeblogEntrySet)c);
-        
-        return c;
+    private EntrySet postCollection(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
+            createWeblogs((WeblogEntrySet)c);
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
+        }        
     }
     
-    private EntrySet putEntry(Reader r) throws Exception {
-        SAXBuilder builder = new SAXBuilder();
-        Document collectionDoc = builder.build(r);
-        EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
-        
-        if (c.getEntries().length > 1) {
-            throw new Exception("ERROR: Cannot put >1 entries per request");
+    private EntrySet putCollection(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
+            updateWeblogs((WeblogEntrySet)c);
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
         }
-        if (c.getEntries().length > 0) {
-            WeblogEntry entry = (WeblogEntry)c.getEntries()[0];
-            if (entry.getHandle() != null && !entry.getHandle().equals(getUri().getEntryId())) {
-                throw new Exception("ERROR: Content handle does not match URI handle");
+    }
+    
+    private EntrySet putEntry(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document collectionDoc = builder.build(r);
+            EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
+            
+            if (c.getEntries().length > 1) {
+                throw new BadRequestException("ERROR: Cannot put >1 entries per request");
             }
-            entry.setHandle(getUri().getEntryId());
-            updateWeblogs((WeblogEntrySet)c);
+            if (c.getEntries().length > 0) {
+                WeblogEntry entry = (WeblogEntry)c.getEntries()[0];
+                if (entry.getHandle() != null && !entry.getHandle().equals(getUri().getEntryId())) {
+                    throw new BadRequestException("ERROR: Content handle does not match URI handle");
+                }
+                entry.setHandle(getUri().getEntryId());
+                updateWeblogs((WeblogEntrySet)c);
+            }
+            
+            return c;
+        } catch (JDOMException je) {
+            throw new InternalException("ERROR: Could not post collection", je);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Could not post collection", ioe);
+        } catch (MissingElementException mee) {
+            throw new InternalException("ERROR: Could not post collection", mee);
+        } catch (UnexpectedRootElementException uree) {
+            throw new InternalException("ERROR: Could not post collection", uree);            
         }
-        
-        return c;
     }
     
-    private void createWeblogs(WeblogEntrySet c) throws Exception {
+    private void createWeblogs(WeblogEntrySet c) throws HandlerException {
         try {
             UserManager mgr = getRoller().getUserManager();
             
@@ -143,15 +189,15 @@
                 WeblogEntry entry = (WeblogEntry)c.getEntries()[i];
                 UserData user = mgr.getUser(entry.getCreatingUser());
                 WebsiteData wd = mgr.createWebsite(user, pages, entry.getHandle(), entry.getName(), entry.getDescription(), entry.getEmailAddress(), DEFAULT_THEME, entry.getLocale(), entry.getTimezone());
-                wd.save();                
+                wd.save();
             }
             getRoller().commit();
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not create weblogs: " + c, re);
         }
     }
     
-    private void updateWeblogs(WeblogEntrySet c) throws Exception {
+    private void updateWeblogs(WeblogEntrySet c) throws HandlerException {
         try {
             UserManager mgr = getRoller().getUserManager();
             
@@ -164,16 +210,18 @@
             for (int i = 0; i < c.getEntries().length; i++) {
                 WeblogEntry entry = (WeblogEntry)c.getEntries()[i];
                 WebsiteData wd = mgr.getWebsiteByHandle(entry.getHandle());
+                if (wd == null) {
+                    throw new NotFoundException("ERROR: Uknown weblog: " + entry.getHandle());
+                }
                 updateWebsiteData(wd, entry);
-                wd.save();
             }
             getRoller().commit();
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not update weblogs: " + c, re);
         }
     }
     
-    private void updateWebsiteData(WebsiteData wd, WeblogEntry entry) {
+    private void updateWebsiteData(WebsiteData wd, WeblogEntry entry) throws HandlerException {
         if (entry.getName() != null) {
             wd.setName(entry.getName());
         }
@@ -189,9 +237,16 @@
         if (entry.getEmailAddress() != null) {
             wd.setEmailAddress(entry.getEmailAddress());
         }
+        
+        try {
+            wd.save();
+            CacheManager.invalidate(wd);
+        } catch (RollerException re) {
+            throw new InternalException("ERROR: Could not update website data", re);
+        }
     }
     
-    private EntrySet deleteEntry() throws Exception {
+    private EntrySet deleteEntry() throws HandlerException {
         try {
             UserManager mgr = getRoller().getUserManager();
             
@@ -200,11 +255,11 @@
             
             WebsiteData wd = mgr.getWebsiteByHandle(getUri().getEntryId());
             if (wd == null) {
-                throw new Exception("ERROR: Uknown weblog handle: " + getUri().getEntryId());
+                throw new NotFoundException("ERROR: Uknown weblog handle: " + getUri().getEntryId());
             }
             
-            WebsiteData[] wds = new WebsiteData[] { wd };            
-            EntrySet es = toWeblogEntrySet(wds);            
+            WebsiteData[] wds = new WebsiteData[] { wd };
+            EntrySet es = toWeblogEntrySet(wds);
             
             wd.remove();
             getRoller().commit();
@@ -213,18 +268,21 @@
             
             return es;
         } catch (RollerException re) {
-            throw new Exception(re);
+            throw new InternalException("ERROR: Could not delete entry: " + getUri().getEntryId(),re);
         }
     }
     
     private WeblogEntry toWeblogEntry(WebsiteData wd) {
+        if (wd == null) {
+            throw new NullPointerException("ERROR: Null website data not allowed");
+        }
         WeblogEntry we = new WeblogEntry(wd.getHandle(), getUrlPrefix());
         we.setName(wd.getName());
         we.setDescription(wd.getDescription());
         we.setLocale(wd.getLocale());
         we.setTimezone(wd.getTimeZone());
         we.setCreatingUser(wd.getCreator().getUserName());
-        we.setEmailAddress(wd.getEmailAddress());        
+        we.setEmailAddress(wd.getEmailAddress());
         we.setDateCreated(wd.getDateCreated());
         
         return we;
@@ -236,7 +294,7 @@
         }
         
         WeblogEntrySet wes = new WeblogEntrySet(getUrlPrefix());
-        List entries = new ArrayList();        
+        List entries = new ArrayList();
         for (Iterator i = uds.iterator(); i.hasNext(); ) {
             UserData ud = (UserData)i.next();
             List permissions = ud.getPermissions();
@@ -248,7 +306,7 @@
             }
         }
         wes.setEntries((Entry[])entries.toArray(new Entry[0]));
-
+        
         return wes;
     }
     
@@ -257,7 +315,7 @@
             throw new NullPointerException("ERROR: Null website datas not allowed");
         }
         
-        WeblogEntrySet wes = new WeblogEntrySet(getUrlPrefix());        
+        WeblogEntrySet wes = new WeblogEntrySet(getUrlPrefix());
         List entries = new ArrayList();
         for (int i = 0; i < wds.length; i++) {
             WeblogEntry we = toWeblogEntry(wds[i]);
@@ -266,6 +324,6 @@
         wes.setEntries((Entry[])entries.toArray(new Entry[0]));
         
         return wes;
-    }    
+    }
 }
 

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntry.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntry.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntry.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntry.java Tue Mar 28 11:07:34 2006
@@ -7,10 +7,12 @@
 package org.roller.presentation.atomadminapi.sdk;
 
 import java.io.InputStream;
+import java.io.IOException;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.Text;
 import org.jdom.input.SAXBuilder;
+import org.jdom.JDOMException;
 import org.roller.presentation.atomadminapi.sdk.Entry.Attributes;
 import org.roller.presentation.atomadminapi.sdk.Entry.Types;
 
@@ -38,7 +40,7 @@
     private String handle;
     private String permission;
     
-    public MemberEntry(Element e, String urlPrefix) throws Exception {
+    public MemberEntry(Element e, String urlPrefix) throws MissingElementException {
         populate(e, urlPrefix);
     }
     
@@ -49,7 +51,7 @@
         setName(userName);
     }
 
-    public MemberEntry(InputStream stream, String urlPrefix) throws Exception {               
+    public MemberEntry(InputStream stream, String urlPrefix) throws JDOMException, IOException, MissingElementException {               
         SAXBuilder sb = new SAXBuilder();
         Document d = sb.build(stream);
         Element e = d.detachRootElement();
@@ -57,18 +59,18 @@
         populate(e, urlPrefix);        
     }
 
-    private void populate(Element e, String urlPrefix) throws Exception {
+    private void populate(Element e, String urlPrefix) throws MissingElementException {
         // name
         Element nameElement = e.getChild(Tags.NAME, NAMESPACE);
         if (nameElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.NAME);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.NAME);
         }
         setName(nameElement.getText());
                 
         // handle
         Element handleElement = e.getChild(Tags.HANDLE, NAMESPACE);
         if (handleElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.HANDLE);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.HANDLE);
         }
         setHandle(handleElement.getText());
 
@@ -78,7 +80,7 @@
         // password
         Element permissionElement = e.getChild(Tags.PERMISSION, NAMESPACE);
         if (permissionElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.PERMISSION);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.PERMISSION);
         }
         setPermission(permissionElement.getText());
     }

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntrySet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntrySet.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntrySet.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/MemberEntrySet.java Tue Mar 28 11:07:34 2006
@@ -7,11 +7,13 @@
 package org.roller.presentation.atomadminapi.sdk;
 
 import java.io.InputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.roller.presentation.atomadminapi.sdk.EntrySet.Types;
 
@@ -29,22 +31,22 @@
         setHref(urlPrefix + "/" + Types.MEMBERS);        
     }    
 
-    public MemberEntrySet(Document d, String urlPrefix) throws Exception {
+    public MemberEntrySet(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException {
         populate(d, urlPrefix);
     }
     
-    public MemberEntrySet(InputStream stream, String urlPrefix) throws Exception {               
+    public MemberEntrySet(InputStream stream, String urlPrefix) throws JDOMException, IOException, MissingElementException, UnexpectedRootElementException {               
         SAXBuilder sb = new SAXBuilder();
         Document d = sb.build(stream);
 
         populate(d, urlPrefix);        
     }    
     
-    private void populate(Document d, String urlPrefix) throws Exception {
+    private void populate(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException {
         Element root = d.getRootElement();
         String rootName = root.getName();
         if (!rootName.equals(Tags.MEMBERS)) {
-            throw new Exception("ERROR: Expected root name: " + Tags.MEMBERS + ", root name was: " + rootName);
+            throw new UnexpectedRootElementException("ERROR: Incorrect root element", Tags.MEMBERS, rootName);
         }
         List members = root.getChildren(MemberEntry.Tags.MEMBER, NAMESPACE);
         if (members != null) {

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntry.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntry.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntry.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntry.java Tue Mar 28 11:07:34 2006
@@ -6,10 +6,12 @@
 
 package org.roller.presentation.atomadminapi.sdk;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
 import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
 import org.jdom.Text;
 import org.jdom.input.SAXBuilder;
 import org.roller.presentation.atomadminapi.sdk.Entry.Attributes;
@@ -48,11 +50,11 @@
     }
     
     /** Construct a user entry from a JDOM element. */
-    public UserEntry(Element e, String urlPrefix) throws Exception {
+    public UserEntry(Element e, String urlPrefix) throws MissingElementException {
         populate(e, urlPrefix);
     }
     
-    public UserEntry(InputStream stream, String urlPrefix) throws Exception {               
+    public UserEntry(InputStream stream, String urlPrefix) throws JDOMException, IOException, MissingElementException {               
         SAXBuilder sb = new SAXBuilder();
         Document d = sb.build(stream);
         Element e = d.detachRootElement();
@@ -60,11 +62,11 @@
         populate(e, urlPrefix);        
     }
     
-    private void populate(Element e, String urlPrefix) throws Exception {
+    private void populate(Element e, String urlPrefix) throws MissingElementException {
         // name
         Element nameElement = e.getChild(Tags.NAME, NAMESPACE);
         if (nameElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.NAME);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.NAME);
         }
         setName(nameElement.getText());
         
@@ -75,35 +77,35 @@
         // full name
         Element fullNameElement = e.getChild(Tags.FULL_NAME, NAMESPACE);
         if (fullNameElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.FULL_NAME);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.FULL_NAME);
         }
         setFullName(fullNameElement.getText());
         
         // password
         Element passwordElement = e.getChild(Tags.PASSWORD, NAMESPACE);
         if (passwordElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.PASSWORD);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.PASSWORD);
         }
         setPassword(passwordElement.getText());
         
         // locale
         Element localeElement = e.getChild(Tags.LOCALE, Service.NAMESPACE);
         if (localeElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.LOCALE);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.LOCALE);
         }
         setLocale(localeElement.getText());
         
         // timezone
         Element tzElement = e.getChild(Tags.TIMEZONE, Service.NAMESPACE);
         if (tzElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.TIMEZONE);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.TIMEZONE);
         }
         setTimezone(tzElement.getText());
         
         // email address
         Element emailElement = e.getChild(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
         if (emailElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.EMAIL_ADDRESS);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.EMAIL_ADDRESS);
         }
         setEmailAddress(emailElement.getText());
         

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntrySet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntrySet.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntrySet.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/UserEntrySet.java Tue Mar 28 11:07:34 2006
@@ -6,12 +6,14 @@
 
 package org.roller.presentation.atomadminapi.sdk;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.roller.presentation.atomadminapi.sdk.EntrySet.Types;
 
@@ -31,22 +33,22 @@
     }
     
     /** Construct based on a JDOM Document object. */
-    public UserEntrySet(Document d, String urlPrefix) throws Exception {
+    public UserEntrySet(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException {
         populate(d, urlPrefix);
     }
     
-    public UserEntrySet(InputStream stream, String urlPrefix) throws Exception {               
+    public UserEntrySet(InputStream stream, String urlPrefix) throws JDOMException, IOException, MissingElementException, UnexpectedRootElementException {               
         SAXBuilder sb = new SAXBuilder();
         Document d = sb.build(stream);
 
         populate(d, urlPrefix);        
     }        
     
-    private void populate(Document d, String urlPrefix) throws Exception {
+    private void populate(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException {
         Element root = d.getRootElement();
         String rootName = root.getName();
         if (!rootName.equals(Tags.USERS)) {
-            throw new Exception("ERROR: Expected root name: " + Tags.USERS + ", root name was: " + rootName);
+            throw new UnexpectedRootElementException("ERROR: Unexpected root element", Tags.USERS, rootName);
         }
         List users = root.getChildren(UserEntry.Tags.USER, NAMESPACE);
         if (users != null) {

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntry.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntry.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntry.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntry.java Tue Mar 28 11:07:34 2006
@@ -5,10 +5,12 @@
  * Created on January 17, 2006, 12:44 PM
  */
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
 import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
 import org.jdom.Text;
 import org.jdom.input.SAXBuilder;
 import org.roller.presentation.atomadminapi.sdk.Entry.Attributes;
@@ -39,11 +41,11 @@
     private String creatingUser;
     private String emailAddress;
     
-    public WeblogEntry(Element e, String urlPrefix) throws Exception {
+    public WeblogEntry(Element e, String urlPrefix) throws MissingElementException {
         populate(e, urlPrefix);
     }
     
-    public WeblogEntry(InputStream stream, String urlPrefix) throws Exception {               
+    public WeblogEntry(InputStream stream, String urlPrefix) throws JDOMException, IOException, MissingElementException {               
         SAXBuilder sb = new SAXBuilder();
         Document d = sb.build(stream);
         Element e = d.detachRootElement();
@@ -51,11 +53,11 @@
         populate(e, urlPrefix);        
     }
     
-    private void populate(Element e, String urlPrefix) throws Exception {
+    private void populate(Element e, String urlPrefix) throws MissingElementException {
         // handle
         Element handleElement = e.getChild(Tags.HANDLE, Service.NAMESPACE);
         if (handleElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.HANDLE);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.HANDLE);
         }
         
         // href
@@ -66,42 +68,42 @@
         // name
         Element nameElement = e.getChild(Tags.NAME, Service.NAMESPACE);
         if (nameElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.NAME);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.NAME);
         }
         setName(nameElement.getText());
         
         // description
         Element descElement = e.getChild(Tags.DESCRIPTION, Service.NAMESPACE);
         if (descElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.DESCRIPTION);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.DESCRIPTION);
         }
         setDescription(descElement.getText());
         
         // locale
         Element localeElement = e.getChild(Tags.LOCALE, Service.NAMESPACE);
         if (localeElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.LOCALE);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.LOCALE);
         }
         setLocale(localeElement.getText());
         
         // timezone
         Element tzElement = e.getChild(Tags.TIMEZONE, Service.NAMESPACE);
         if (tzElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.TIMEZONE);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.TIMEZONE);
         }
         setTimezone(tzElement.getText());
         
         // creator
         Element creatorElement = e.getChild(Tags.CREATING_USER, Service.NAMESPACE);
         if (creatorElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.CREATING_USER);
+            throw new MissingElementException("ERROR: Missing element", e.getName(), Tags.CREATING_USER);
         }
         setCreatingUser(creatorElement.getText());
         
         // email address
         Element emailElement = e.getChild(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
         if (emailElement == null) {
-            throw new Exception("ERROR: Missing element: " + Tags.EMAIL_ADDRESS);
+            throw new MissingElementException("ERROR: Missing element: ", e.getName(), Tags.EMAIL_ADDRESS);
         }
         setEmailAddress(emailElement.getText());        
         

Modified: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntrySet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntrySet.java?rev=389579&r1=389578&r2=389579&view=diff
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntrySet.java (original)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/sdk/WeblogEntrySet.java Tue Mar 28 11:07:34 2006
@@ -6,12 +6,14 @@
 
 package org.roller.presentation.atomadminapi.sdk;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.roller.presentation.atomadminapi.sdk.EntrySet.Types;
 
@@ -28,22 +30,22 @@
         setHref(urlPrefix + "/" + Types.WEBLOGS);
     }
     
-    public WeblogEntrySet(Document d, String urlPrefix) throws Exception {
+    public WeblogEntrySet(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException {
         populate(d, urlPrefix);
     }
     
-    public WeblogEntrySet(InputStream stream, String urlPrefix) throws Exception {               
+    public WeblogEntrySet(InputStream stream, String urlPrefix) throws JDOMException, IOException, MissingElementException, UnexpectedRootElementException {               
         SAXBuilder sb = new SAXBuilder();
         Document d = sb.build(stream);
 
         populate(d, urlPrefix);        
     }    
     
-    private void populate(Document d, String urlPrefix) throws Exception {
+    private void populate(Document d, String urlPrefix) throws MissingElementException, UnexpectedRootElementException {
         Element root = d.getRootElement();
         String rootName = root.getName();
         if (!rootName.equals(Tags.WEBLOGS)) {
-            throw new Exception("ERROR: Expected root name: " + Tags.WEBLOGS + ", root name was: " + rootName);
+            throw new UnexpectedRootElementException("ERROR: Unexpected root element", Tags.WEBLOGS, rootName);
         }
         List weblogs = root.getChildren(WeblogEntry.Tags.WEBLOG, Service.NAMESPACE);
         if (weblogs != null) {