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/05/13 00:19:47 UTC

svn commit: r405902 - in /incubator/roller/trunk: ./ src/org/apache/roller/webservices/adminapi/ src/org/apache/roller/webservices/adminapi/sdk/

Author: snoopdave
Date: Fri May 12 15:19:46 2006
New Revision: 405902

URL: http://svn.apache.org/viewcvs?rev=405902&view=rev
Log:
AAPP patch 4.6 from Jeff Blattman

Modified:
    incubator/roller/trunk/build.xml
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/BadRequestException.java
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/Handler.java
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/IntrospectionHandler.java
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerMemberHandler.java
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerUserHandler.java
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerWeblogHandler.java
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/Entry.java
    incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/EntrySet.java

Modified: incubator/roller/trunk/build.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/build.xml?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/build.xml (original)
+++ incubator/roller/trunk/build.xml Fri May 12 15:19:46 2006
@@ -311,13 +311,14 @@
 
 <!-- build standalone aapp-sdk.jar, for external consumption -->
 <target name="aapp-sdk" depends="build">
+    <mkdir dir="${ro.build}/lib"/>
     <jar destfile="${ro.build}/lib/aapp-sdk.jar">
-      <manifest>
-        <attribute name="Manifest-Version" value="${ro.version}"/>
-      </manifest>
-      <fileset dir="${build.compile_web}">
-        <include name="org/apache/roller/webservices/adminapi/sdk/*"/>
-      </fileset>
+        <manifest>
+            <attribute name="Manifest-Version" value="${ro.version}"/>
+        </manifest>
+        <fileset dir="${build.compile_web}">
+            <include name="org/apache/roller/webservices/adminapi/sdk/*"/>
+        </fileset>        
     </jar>
 </target>
 
@@ -587,7 +588,7 @@
         bottom="Copyright (C) David M Johnson"
         classpathref="javadoc.path"
         destdir="${build.javadoc}"
-        doctitle="Javadocs: Roller Weblogger ${ro.version}"
+        doctitle="Javadocs: Roller Weblogger ${ro.version}"        
         private="false"
         version="false"
         windowtitle="Javadocs: Roller Weblogger ${ro.version}">
@@ -1046,8 +1047,8 @@
     <target name="test-aapp" depends="test-aapp-sdk, test-aapp-handler"/>
    
     <target name="test-aapp-sdk" depends="build-tests">
-        <mkdir dir="${build.reports}/presentation/xml"/>
-        <mkdir dir="${build.reports}/presentation/html"/>
+        <mkdir dir="${build.reports}/webservices/adminapi/sdk/xml"/>
+        <mkdir dir="${build.reports}/webservices/adminapi/sdk/html"/>
 
         <junit fork="true" dir="${build.tests}" printsummary="on">
             <syspropertyset>
@@ -1057,23 +1058,23 @@
                 <path refid="junit.path"/>
             </classpath>
             <formatter type="xml"/>
-            <batchtest toDir="${build.reports}/presentation/xml">
+            <batchtest toDir="${build.reports}/webservices/adminapi/sdk/xml">
                 <fileset dir="${build.tests}/WEB-INF/classes">
-                    <include name="org/apache/roller/presentation/atomadminapi/sdk/*EntryTest.class"/>
+                    <include name="org/apache/roller/webservices/adminapi/sdk/*EntryTest.class"/>
                 </fileset>
             </batchtest>
         </junit>
-        <junitreport todir="${build.reports}/presentation/xml">
-            <fileset dir="${build.reports}/presentation/xml">
+        <junitreport todir="${build.reports}/webservices/adminapi/sdk/xml">
+            <fileset dir="${build.reports}/webservices/adminapi/sdk/xml">
                 <include name="TEST-*.xml"/>
             </fileset>
-            <report format="noframes" toDir="${build.reports}/presentation/html"/>
+            <report format="noframes" toDir="${build.reports}/webservices/adminapi/sdk/html"/>
         </junitreport>
     </target>
     
     <target name="test-aapp-handler" depends="build-tests">
-        <mkdir dir="${build.reports}/presentation/xml"/>
-        <mkdir dir="${build.reports}/presentation/html"/>
+        <mkdir dir="${build.reports}/webservices/adminapi/xml"/>
+        <mkdir dir="${build.reports}/webservices/adminapi/html"/>
 
         <junit fork="true" dir="${build.tests}" printsummary="on">
             <syspropertyset>
@@ -1083,17 +1084,17 @@
                 <path refid="junit.path"/>
             </classpath>
             <formatter type="xml"/>
-            <batchtest toDir="${build.reports}/presentation/xml">
+            <batchtest toDir="${build.reports}/webservices/adminapi/xml">
                 <fileset dir="${build.tests}/WEB-INF/classes">
-                    <include name="org/apache/roller/presentation/atomadminapi/*HandlerTest.class"/>
+                    <include name="org/apache/roller/webservices/adminapi/*HandlerTest.class"/>
                 </fileset>
             </batchtest>
         </junit>
-        <junitreport todir="${build.reports}/presentation/xml">
-            <fileset dir="${build.reports}/presentation/xml">
+        <junitreport todir="${build.reports}/webservices/adminapi/xml">
+            <fileset dir="${build.reports}/webservices/adminapi/xml">
                 <include name="TEST-*.xml"/>
             </fileset>
-            <report format="noframes" toDir="${build.reports}/presentation/html"/>
+            <report format="noframes" toDir="${build.reports}/webservices/adminapi/html"/>
         </junitreport>
     </target>
 

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/BadRequestException.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/BadRequestException.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/BadRequestException.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/BadRequestException.java Fri May 12 15:19:46 2006
@@ -28,6 +28,10 @@
         super(msg);
     }    
     
+    public BadRequestException(String msg, Throwable t) {
+        super(msg, t);
+    }    
+
     public int getStatus() {
         return HttpServletResponse.SC_BAD_REQUEST;
     }

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/Handler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/Handler.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/Handler.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/Handler.java Fri May 12 15:19:46 2006
@@ -1,48 +1,45 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-/*
- * Handler.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Created on January 17, 2006, 12:44 PM
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
 package org.apache.roller.webservices.adminapi;
 
+import java.io.IOException;
 import java.io.Reader;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.roller.RollerException;
 import org.apache.roller.config.RollerConfig;
 import org.apache.roller.model.Roller;
 import org.apache.roller.model.RollerFactory;
 import org.apache.roller.presentation.RollerContext;
-import org.apache.roller.util.StringUtils;
 import org.apache.roller.webservices.adminapi.sdk.EntrySet;
 
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
+import org.apache.roller.webservices.adminapi.sdk.MissingElementException;
+import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
 
 /**
  * This class is the abstract notion of an AAPP request handler.
  * It processes HTTP requests for each of the four HTTP verbs:
  * GET, POST, PUT, DELETE, for a given weblog resource.
- *
- * @author jtb
  */
 abstract class Handler {
     protected static final String ENDPOINT = "/aapp";
@@ -140,7 +137,7 @@
         // TODO: decide what to do about authentication, is WSSE going to fly?
         //Authenticator auth = new WSSEAuthenticator(request);
         Authenticator auth = new BasicAuthenticator(request);
-        auth.authenticate();        
+        auth.authenticate();
         setUserName(auth.getUserName());
     }
     
@@ -184,5 +181,25 @@
     protected String getUrlPrefix() {
         return urlPrefix;
     }
+    
+    protected abstract EntrySet getEntrySet(Document d) throws MissingElementException, UnexpectedRootElementException;
+    
+    protected EntrySet getEntrySet(Reader r) throws HandlerException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            Document d = builder.build(r);
+            EntrySet c = getEntrySet(d);
+            
+            return c;
+        } catch (UnexpectedRootElementException ure) {
+            throw new BadRequestException("ERROR: Failed to parse content", ure);            
+        } catch (MissingElementException mee) {
+            throw new BadRequestException("ERROR: Failed to parse content", mee);            
+        } catch (JDOMException jde) {
+            throw new BadRequestException("ERROR: Failed to parse content", jde);
+        } catch (IOException ioe) {
+            throw new InternalException("ERROR: Failed to parse content", ioe);
+        }
+    }    
 }
 

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/IntrospectionHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/IntrospectionHandler.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/IntrospectionHandler.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/IntrospectionHandler.java Fri May 12 15:19:46 2006
@@ -1,24 +1,19 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-/*
- * IntrospectionHandler.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Created on January 17, 2006, 12:44 PM
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
 package org.apache.roller.webservices.adminapi;
 
@@ -29,7 +24,10 @@
 
 import org.apache.roller.webservices.adminapi.sdk.Entry;
 import org.apache.roller.webservices.adminapi.sdk.EntrySet;
+import org.apache.roller.webservices.adminapi.sdk.MissingElementException;
 import org.apache.roller.webservices.adminapi.sdk.Service;
+import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
+import org.jdom.Document;
 
 /**
  * This class handles requests for the AAPP introspection document.
@@ -37,9 +35,13 @@
  *
  * @author jtb
  */
-class IntrospectionHandler extends Handler {   
+class IntrospectionHandler extends Handler {
     public IntrospectionHandler(HttpServletRequest request) throws HandlerException {
         super(request);
+    }
+    
+    protected EntrySet getEntrySet(Document d) throws MissingElementException, UnexpectedRootElementException {
+        throw new UnsupportedOperationException();
     }
     
     public EntrySet processGet() throws HandlerException {

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerMemberHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerMemberHandler.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerMemberHandler.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerMemberHandler.java Fri May 12 15:19:46 2006
@@ -1,24 +1,19 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-/*
- * RollerMemberHandler.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Created on January 17, 2006, 12:44 PM
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
 package org.apache.roller.webservices.adminapi;
 
@@ -31,7 +26,6 @@
 import javax.servlet.http.HttpServletRequest;
 import org.jdom.Document;
 import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
 import org.apache.roller.RollerException;
 import org.apache.roller.model.UserManager;
 import org.apache.roller.pojos.PermissionsData;
@@ -62,7 +56,7 @@
             } else {
                 String[] entryIds = entryId.split("/");
                 if (entryIds == null || entryIds.length == 0) {
-                    throw new BadRequestException("ERROR: Invalid path info: " + req.getPathInfo()); 
+                    throw new BadRequestException("ERROR: Invalid path info: " + req.getPathInfo());
                 }
                 handle = entryIds[0];
                 if (entryIds.length > 1) {
@@ -99,6 +93,10 @@
         memberUri = new MemberURI(request);
     }
     
+    protected EntrySet getEntrySet(Document d) throws MissingElementException, UnexpectedRootElementException {
+        return new MemberEntrySet(d, getUrlPrefix());
+    }
+    
     protected URI getUri() {
         return memberUri;
     }
@@ -198,96 +196,67 @@
     }
     
     private EntrySet postCollection(Reader r) throws HandlerException {
-        try {
-            SAXBuilder builder = new SAXBuilder();
-            Document collectionDoc = builder.build(r);
-            EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
-            c = 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);            
-        }       
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        c = createMembers((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());
-            c = 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);            
-        }       
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        c = updateMembers((MemberEntrySet)c);
+        
+        return c;
     }
     
     private EntrySet putEntry(Reader r) throws HandlerException {
-        try {
-            SAXBuilder builder = new SAXBuilder();
-            Document collectionDoc = builder.build(r);
-            EntrySet c = new MemberEntrySet(collectionDoc, getUrlPrefix());
-            
-            if (c.getEntries().length > 1) {
-                throw new BadRequestException("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();
-                
-                // 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");
-                }
-                
-                // 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);
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        if (c.getEntries().length > 1) {
+            throw new BadRequestException("ERROR: Cannot put >1 entries per request");
+        }
+        
+        // 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");
+        }
+        
+        // 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");
             }
-            
-            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);            
-        }        
+            entry.setName(username);
+        } else if (username != null && !entry.getName().equals(username)) {
+            throw new BadRequestException("ERROR: URI and entry user name do not match");
+        }
+        
+        c = updateMembers((MemberEntrySet)c);
+        
+        return c;
     }
     
     private MemberEntrySet createMembers(MemberEntrySet c) throws HandlerException {
@@ -355,7 +324,7 @@
                 permissionsDatas.add(pd);
             }
             getRoller().flush();
-            return toMemberEntrySet((PermissionsData[])permissionsDatas.toArray(new PermissionsData[0]));            
+            return toMemberEntrySet((PermissionsData[])permissionsDatas.toArray(new PermissionsData[0]));
         } catch (RollerException re) {
             throw new InternalException("ERROR: Could not update members", re);
         }
@@ -367,8 +336,8 @@
         if (entry.getPermission() != null) {
             pd.setPermissionMask(stringToMask(entry.getPermission()));
         }
-		
-		// TODO: does the permissions data need to be invalidated?
+        
+        // TODO: does the permissions data need to be invalidated?
         
         try {
             UserData ud = getRoller().getUserManager().getUserByUsername(entry.getName());

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerUserHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerUserHandler.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerUserHandler.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerUserHandler.java Fri May 12 15:19:46 2006
@@ -1,24 +1,19 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-/*
- * RollerUserHandler.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Created on January 17, 2006, 12:44 PM
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
 package org.apache.roller.webservices.adminapi;
 
@@ -30,7 +25,6 @@
 import javax.servlet.http.HttpServletRequest;
 import org.jdom.Document;
 import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
 import org.apache.roller.RollerException;
 import org.apache.roller.model.UserManager;
 import org.apache.roller.pojos.UserData;
@@ -52,6 +46,10 @@
         super(request);
     }
     
+    protected EntrySet getEntrySet(Document d) throws MissingElementException, UnexpectedRootElementException {
+        return new UserEntrySet(d, getUrlPrefix());
+    }
+    
     public EntrySet processGet() throws HandlerException {
         if (getUri().isCollection()) {
             return getCollection();
@@ -118,71 +116,42 @@
     }
     
     private EntrySet postCollection(Reader r) throws HandlerException {
-        try {
-            SAXBuilder builder = new SAXBuilder();
-            Document collectionDoc = builder.build(r);
-            EntrySet c = new UserEntrySet(collectionDoc, getUrlPrefix());
-            c = 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);
-        }
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        c = createUsers((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());
-            c = updateUsers((UserEntrySet)c);
-            
-            return c;
-        } catch (JDOMException je) {
-            throw new InternalException("ERROR: Could not put collection", je);
-        } catch (IOException ioe) {
-            throw new InternalException("ERROR: Could not put collection", ioe);
-        } catch (MissingElementException mee) {
-            throw new InternalException("ERROR: Could not put collection", mee);
-        } catch (UnexpectedRootElementException uree) {
-            throw new InternalException("ERROR: Could not put collection", uree);
-        }
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        c = updateUsers((UserEntrySet)c);
+        
+        return c;
     }
     
     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");
-            }
-            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);
-        }
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        if (c.getEntries().length > 1) {
+            throw new BadRequestException("ERROR: Cannot put >1 entries per request");
+        }
+        
+        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());
+        c = updateUsers((UserEntrySet)c);
+        
+        return c;
     }
     
     private UserEntrySet createUsers(UserEntrySet c) throws HandlerException {

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerWeblogHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerWeblogHandler.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerWeblogHandler.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/RollerWeblogHandler.java Fri May 12 15:19:46 2006
@@ -1,24 +1,19 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-/*
- * RollerWeblogHandler.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Created on January 17, 2006, 12:44 PM
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
 package org.apache.roller.webservices.adminapi;
 
@@ -36,7 +31,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.jdom.Document;
 import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
 import org.apache.roller.RollerException;
 import org.apache.roller.config.RollerRuntimeConfig;
 import org.apache.roller.model.UserManager;
@@ -54,8 +48,6 @@
 
 /**
  * This class handles requests concerning Roller weblog resources.
- *
- * @author jtb
  */
 class RollerWeblogHandler extends Handler {
     private static Log log =
@@ -68,6 +60,10 @@
         super(request);
     }
     
+    protected EntrySet getEntrySet(Document d) throws MissingElementException, UnexpectedRootElementException {
+        return new WeblogEntrySet(d, getUrlPrefix());
+    }
+    
     public EntrySet processGet() throws HandlerException {
         if (getUri().isCollection()) {
             return getCollection();
@@ -135,71 +131,42 @@
     }
     
     private EntrySet postCollection(Reader r) throws HandlerException {
-        try {
-            SAXBuilder builder = new SAXBuilder();
-            Document collectionDoc = builder.build(r);
-            EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
-            c = 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);
-        }
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        c = createWeblogs((WeblogEntrySet)c);
+        
+        return c;
     }
     
     private EntrySet putCollection(Reader r) throws HandlerException {
-        try {
-            SAXBuilder builder = new SAXBuilder();
-            Document collectionDoc = builder.build(r);
-            EntrySet c = new WeblogEntrySet(collectionDoc, getUrlPrefix());
-            c = 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);
-        }
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        c = updateWeblogs((WeblogEntrySet)c);
+        
+        return c;
     }
     
     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");
-            }
-            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);
-        }
+        EntrySet c = getEntrySet(r);
+        if (c.isEmpty()) {
+            throw new BadRequestException("ERROR: No entries");
+        }
+        if (c.getEntries().length > 1) {
+            throw new BadRequestException("ERROR: Cannot put >1 entries per request");
+        }
+        
+        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());
+        c = updateWeblogs((WeblogEntrySet)c);
+        
+        return c;
     }
     
     private WeblogEntrySet createWeblogs(WeblogEntrySet c) throws HandlerException {

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/Entry.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/Entry.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/Entry.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/Entry.java Fri May 12 15:19:46 2006
@@ -15,12 +15,6 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-/*
- * Entry.java
- *
- * Created on January 17, 2006, 12:44 PM
- */
-
 package org.apache.roller.webservices.adminapi.sdk;
 
 import java.io.IOException;
@@ -35,11 +29,9 @@
 /**
  * This class is the abstract notion of an entry.
  * Weblog resources are represented by sets of entries.
- *
- * @author jtb
  */
 public abstract class Entry {
-    protected static final Namespace NAMESPACE = Namespace.getNamespace("http://purl.org/roller/aapp#");
+    protected static final Namespace NAMESPACE = Namespace.getNamespace("http://purl.org/apache/roller/aapp#");
     
     /** Entry types. */
     public static interface Types {

Modified: incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/EntrySet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/EntrySet.java?rev=405902&r1=405901&r2=405902&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/EntrySet.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/webservices/adminapi/sdk/EntrySet.java Fri May 12 15:19:46 2006
@@ -15,12 +15,6 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-/*
- * EntrySet.java
- *
- * Created on January 17, 2006, 12:44 PM
- */
-
 package org.apache.roller.webservices.adminapi.sdk;
 
 import java.util.Arrays;
@@ -81,6 +75,11 @@
     /** Set the entries of this object. */
     public void setEntries(Entry[] entryArray) {
         entries = Arrays.asList(entryArray);
+    }
+    
+    /** Is this entry set empty? */
+    public boolean isEmpty() {
+        return entries == null || entries.size() == 0;
     }
     
     /** This object as a JDOM Document */