abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r614120 - in /incubator/abdera/java/branches/server_refactor/src: main/java/org/apache/abdera/protocol/server/ main/java/org/apache/abdera/protocol/server/impl/ main/java/org/apache/abdera/protocol/server/provider/basic/ main/java/org/apach...
Date Tue, 22 Jan 2008 05:15:56 GMT
Author: jmsnell
Date: Mon Jan 21 21:15:54 2008
New Revision: 614120

URL: http://svn.apache.org/viewvc?rev=614120&view=rev
Log:
Categories document support

Modified:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleAdapter.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionAdapter.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionAdapter.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionAdapter.java
Mon Jan 21 21:15:54 2008
@@ -28,7 +28,9 @@
   ResponseContext putEntry(RequestContext request);
 
   ResponseContext getFeed(RequestContext request);
-   
+
+  ResponseContext getCategories(RequestContext request);
+  
   ResponseContext extensionRequest(RequestContext request);
   
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
Mon Jan 21 21:15:54 2008
@@ -39,9 +39,6 @@
       if (type == TargetType.TYPE_SERVICE && 
           method.equalsIgnoreCase("GET")) {
           return getServiceDocument(request);
-      } else if (type == TargetType.TYPE_CATEGORIES && 
-                 method.equalsIgnoreCase("GET")) {
-          return getCategoriesDocument(request);
       }
       WorkspaceManager wm = getWorkspaceManager(request);
       if (!wm.checkTarget(request)) {
@@ -60,7 +57,10 @@
           (Transactional)adapter : null;
       try {
         if (transaction != null) transaction.start();
-        if (type == TargetType.TYPE_COLLECTION) {
+        if (type == TargetType.TYPE_CATEGORIES) {
+          if (method.equalsIgnoreCase("GET"))
+            return adapter.getCategories(request);
+        } else if (type == TargetType.TYPE_COLLECTION) {
           if (method.equalsIgnoreCase("GET")) 
             return adapter.getFeed(request);
           else if (method.equalsIgnoreCase("POST")) {
@@ -110,8 +110,4 @@
       return ProviderHelper.notfound(request);
   }
   
-  protected ResponseContext getCategoriesDocument(
-    RequestContext request) {
-      return ProviderHelper.notfound(request);
-  }
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
Mon Jan 21 21:15:54 2008
@@ -82,5 +82,9 @@
   public ResponseContext putEntry(RequestContext request) {
     return internal.putEntry(request);
   }
+
+  public ResponseContext getCategories(RequestContext request) {
+    return internal.getCategories(request);
+  }
   
 }

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicAdapter.java
Mon Jan 21 21:15:54 2008
@@ -195,8 +195,10 @@
       ProviderHelper.getDefaultMethods(request));
   }
   
-  
-  
+  public ResponseContext getCategories(RequestContext request) {
+    return ProviderHelper.notfound(request);
+  }
+
   public abstract Feed getFeed() 
     throws Exception;
 

Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
Mon Jan 21 21:15:54 2008
@@ -102,7 +102,6 @@
         provider.process(
           reqcontext));
     } catch (Throwable t) {
-      t.printStackTrace();
       error("Error servicing request", t, response);
       return;
     }

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/DefaultTest.java
Mon Jan 21 21:15:54 2008
@@ -23,6 +23,7 @@
 import junit.framework.TestCase;
 
 import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Categories;
 import org.apache.abdera.model.Collection;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Entry;
@@ -53,7 +54,7 @@
     } catch (Exception e) {}
   }
   
-  private int count = 6;
+  private int count = 7;
   
   @Override protected void tearDown() throws Exception {
     if (--count == 0) 
@@ -77,6 +78,20 @@
     assertEquals(collection.getResolvedHref().toString(), "http://localhost:8080/atom/feed2");
     assertEquals(collection.getTitle().toString(), "entries2");
     resp.release();
+  }
+  
+  public void testGetCategories() {
+    ClientResponse resp = client.get("http://localhost:8080/atom/feed1;categories");
+    assertNotNull(resp);
+    assertEquals(resp.getType(),ResponseType.SUCCESS);
+    assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), Constants.CAT_MEDIA_TYPE));
+    Document<Categories> doc = resp.getDocument();
+    Categories cats = doc.getRoot();
+    assertEquals(cats.getCategories().size(), 3);
+    assertEquals(cats.getCategories().get(0).getTerm(), "foo");
+    assertEquals(cats.getCategories().get(1).getTerm(), "bar");
+    assertEquals(cats.getCategories().get(2).getTerm(), "baz");
+    assertFalse(cats.isFixed());
   }
   
   public void testGetFeed() {

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestServiceContext.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestServiceContext.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/impl/TestServiceContext.java
Mon Jan 21 21:15:54 2008
@@ -65,7 +65,8 @@
   public Resolver<Target> getTargetResolver() {
     return new RegexTargetResolver()
       .setPattern("/atom(\\?[^#]*)?", TargetType.TYPE_SERVICE)
-      .setPattern("/atom/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection",
"entry")
+      .setPattern("/atom/([^/#?]+);categories", TargetType.TYPE_CATEGORIES, "collection")
+      .setPattern("/atom/([^/#?;]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
       .setPattern("/atom/([^/#?]+)/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY, "collection",
"entry");
   }
 }

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleAdapter.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleAdapter.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleAdapter.java
Mon Jan 21 21:15:54 2008
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.protocol.server.test.simple;
 
+import java.io.IOException;
 import java.util.Date;
 
 import javax.activation.MimeType;
@@ -35,7 +36,10 @@
 import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.RequestContext.Scope;
 import org.apache.abdera.protocol.server.context.BaseResponseContext;
+import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
+import org.apache.abdera.util.Constants;
 import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.abdera.writer.StreamWriter;
 
 @SuppressWarnings("unchecked")
 public class SimpleAdapter  
@@ -253,4 +257,23 @@
       return UrlEncoding.decode(segments[segments.length-1]);
   }
   
+  public ResponseContext getCategories(
+    RequestContext request) {
+      return 
+        new StreamWriterResponseContext(request.getAbdera()) {
+          protected void writeTo(
+            StreamWriter sw) 
+              throws IOException {
+            sw.startDocument()
+              .startCategories(false)
+              .writeCategory("foo")
+              .writeCategory("bar")
+              .writeCategory("baz")
+              .endCategories()
+              .endDocument();
+          }
+        }
+        .setStatus(200)
+        .setContentType(Constants.CAT_MEDIA_TYPE);    
+  }
 }

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
Mon Jan 21 21:15:54 2008
@@ -47,7 +47,7 @@
     RequestContext request) {
       return adapter;
   }
-
+  
   protected ResponseContext getServiceDocument(
     RequestContext request) {
       return 

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleServiceContext.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleServiceContext.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleServiceContext.java
Mon Jan 21 21:15:54 2008
@@ -45,7 +45,8 @@
   public Resolver<Target> getTargetResolver() {
     return new RegexTargetResolver()
       .setPattern("/atom(\\?[^#]*)?", TargetType.TYPE_SERVICE)
-      .setPattern("/atom/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
+      .setPattern("/atom/([^/#?]+);categories", TargetType.TYPE_CATEGORIES, "collection")
+      .setPattern("/atom/([^/#?;]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
       .setPattern("/atom/([^/#?]+)/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY, "collection","entry");
   }
 }

Modified: incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java?rev=614120&r1=614119&r2=614120&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
Mon Jan 21 21:15:54 2008
@@ -23,6 +23,7 @@
 import junit.framework.TestCase;
 
 import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Categories;
 import org.apache.abdera.model.Collection;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Entry;
@@ -53,7 +54,7 @@
     } catch (Exception e) {}
   }
   
-  private int count = 6;
+  private int count = 7;
   
   @Override protected void tearDown() throws Exception {
     if (--count == 0) 
@@ -74,6 +75,20 @@
     assertEquals(collection.getResolvedHref().toString(), "http://localhost:8080/atom/feed");
     assertEquals(collection.getTitle().toString(), "Simple");
     resp.release();
+  }
+  
+  public void testGetCategories() {
+    ClientResponse resp = client.get("http://localhost:8080/atom/feed;categories");
+    assertNotNull(resp);
+    assertEquals(resp.getType(),ResponseType.SUCCESS);
+    assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), Constants.CAT_MEDIA_TYPE));
+    Document<Categories> doc = resp.getDocument();
+    Categories cats = doc.getRoot();
+    assertEquals(cats.getCategories().size(), 3);
+    assertEquals(cats.getCategories().get(0).getTerm(), "foo");
+    assertEquals(cats.getCategories().get(1).getTerm(), "bar");
+    assertEquals(cats.getCategories().get(2).getTerm(), "baz");
+    assertFalse(cats.isFixed());
   }
   
   public void testGetFeed() {



Mime
View raw message