abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r612235 - in /incubator/abdera/java/trunk: extensions/html/ jcr/src/main/java/org/apache/abdera/jcr/ server/src/main/java/org/apache/abdera/protocol/server/ server/src/main/java/org/apache/abdera/protocol/server/impl/ server/src/test/java/o...
Date Tue, 15 Jan 2008 21:37:31 GMT
Author: dandiep
Date: Tue Jan 15 13:37:27 2008
New Revision: 612235

URL: http://svn.apache.org/viewvc?rev=612235&view=rev
Log:
ABDERA-85: Add RequestContext to AbstractCollectionProvider.getId()
ABDERA-86: Use a regex inside ServiceProvider to determine the path

Thanks to Jim Ancona for these patches!!


Modified:
    incubator/abdera/java/trunk/extensions/html/   (props changed)
    incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/CollectionProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java

Propchange: incubator/abdera/java/trunk/extensions/html/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jan 15 13:37:27 2008
@@ -1,3 +1,4 @@
-.classpath
-.project
-.settings
+.classpath
+.project
+.settings
+target

Modified: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java?rev=612235&r1=612234&r2=612235&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
Tue Jan 15 13:37:27 2008
@@ -446,7 +446,7 @@
   }
 
   @Override
-  public String getId() {
+  public String getId(RequestContext request) {
     return id;
   }
 

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/CollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/CollectionProvider.java?rev=612235&r1=612234&r2=612235&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/CollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/CollectionProvider.java
Tue Jan 15 13:37:27 2008
@@ -34,9 +34,7 @@
   void end(RequestContext request, ResponseContext response);
   
   String getTitle(RequestContext request);
-
-  ResponseContext getFeed(Feed feed, RequestContext request);
-
+  
   ResponseContext createEntry(RequestContext request);
 
   ResponseContext getMedia(RequestContext request);

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java?rev=612235&r1=612234&r2=612235&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
Tue Jan 15 13:37:27 2008
@@ -205,7 +205,7 @@
     return e.getResponseContext();
   }
 
-  public abstract String getId();
+  public abstract String getId(RequestContext request);
   
   /**
    * Gets the UUID for the specified entry.
@@ -379,7 +379,7 @@
     Factory factory = request.getAbdera().getFactory();
     Feed feed = factory.newFeed();
     try {
-      feed.setId(getId());
+      feed.setId(getId(request));
       feed.setTitle(getTitle(request));
       feed.addLink("");
       feed.addLink("", "self");

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java?rev=612235&r1=612234&r2=612235&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceProvider.java
Tue Jan 15 13:37:27 2008
@@ -1,331 +1,344 @@
-/*
-* 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.
-*/
-package org.apache.abdera.protocol.server.impl;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.abdera.Abdera;
-import org.apache.abdera.i18n.iri.IRI;
-import org.apache.abdera.i18n.text.UrlEncoding;
-import org.apache.abdera.i18n.text.CharUtils.Profile;
-import org.apache.abdera.protocol.Request;
-import org.apache.abdera.protocol.Resolver;
-import org.apache.abdera.protocol.server.CollectionProvider;
-import org.apache.abdera.protocol.server.RequestContext;
-import org.apache.abdera.protocol.server.ResponseContext;
-import org.apache.abdera.protocol.server.Target;
-import org.apache.abdera.protocol.server.TargetType;
-import org.apache.abdera.protocol.server.WorkspaceInfo;
-import org.apache.abdera.protocol.server.RequestContext.Scope;
-import org.apache.abdera.util.EntityTag;
-import org.apache.abdera.writer.StreamWriter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Represents an Atom service which is backed by various workspaces and CollectionProviders.
- * This class can be extended to provide a dynamic list of workspaces or ServiceProvider
can
- * be used to use a static list.
- * 
- */
-public abstract class AbstractServiceProvider extends AbstractProvider implements Resolver<Target>
{
-  private static final Log log = LogFactory.getLog(AbstractServiceProvider.class);
-  public static final String COLLECTION_PROVIDER_ATTRIBUTE = "collectionProvider";
-  
-    private String servicesPath = "/";
-    
-    protected AbstractServiceProvider(int count) {
-      super(count);
-    }
-
-    public Target resolve(Request request) {
-      RequestContext context = (RequestContext) request;
-      String uri = context.getTargetPath();
-      
-      if (servicesPath == null) {
-        throw new RuntimeException("You must set the servicesPath property on the ServiceProvider.");
-      }
-      
-      TargetType tt = null;
-      if (uri.equals(servicesPath)) {
-        tt = TargetType.TYPE_SERVICE;
-      } else if (uri.startsWith(servicesPath)) {
-        String path = uri.substring(servicesPath.length());
-        int q = path.indexOf("?");
-        if (q != -1) {
-          path = path.substring(0, q);
-        }
-        
-        path = UrlEncoding.decode(path);
-
-        CollectionProvider provider = null;
-        String providerHref = null;
-        for (WorkspaceInfo wi : getWorkspaces()) {
-          for (Map.Entry<String, CollectionProvider> e : wi.getCollectionProviders().entrySet())
{
-            if (path.startsWith(e.getKey())) {
-              provider = e.getValue();
-              providerHref = e.getKey();
-              break;
-            }
-          }
-        }
-        
-        if (provider != null) {
-          context.setAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE, provider);
-          
-          if (providerHref.equals(path)) {
-            tt = TargetType.TYPE_COLLECTION;
-          } else {
-            tt = getOtherTargetType(context, path, providerHref, provider);
-          }
-        }
-      } 
-      
-      if (tt == null) {
-        tt = TargetType.TYPE_UNKNOWN;
-      }
-      
-      return new DefaultTarget(tt, context);
-    }
-
-    protected TargetType getOtherTargetType(RequestContext context, 
-                                            String path, 
-                                            String providerHref, 
-                                            CollectionProvider provider) {
-      String baseMedia = null;
-      if (provider instanceof AbstractCollectionProvider) {
-        baseMedia = ((AbstractCollectionProvider) provider).getBaseMediaIri();
-      }
-      
-      if (providerHref.startsWith("/")) {
-        providerHref = providerHref.substring(1);
-      }
-      
-      if (providerHref.startsWith(baseMedia)) {
-        return TargetType.TYPE_MEDIA;
-      } else {
-        return TargetType.TYPE_ENTRY;
-      }
-    }
-
-    public ResponseContext getService(RequestContext request) {
-      Abdera abdera = request.getAbdera();
-      AbstractResponseContext rc = getServicesDocument(abdera, request);
-      rc.setStatus(200);
-      return rc;
-    }
-
-    private String getEncoding(RequestContext request) {
-      return "utf-8";
-    }
-
-    private AbstractResponseContext getServicesDocument(final Abdera abdera, 
-                                                        final RequestContext request) {
-      final String enc = getEncoding(request);
-      
-      return new StreamWriterResponseContext(abdera) {
-
-        @SuppressWarnings( {"serial", "unchecked"})
-        protected void writeTo(StreamWriter sw) throws IOException {
-          sw.startDocument().startService();
-  
-          for (WorkspaceInfo wp : getWorkspaces()) {
-            sw.startWorkspace().writeTitle(wp.getName());
-            Set<Map.Entry<String, CollectionProvider>> entrySet = (Set<Map.Entry<String,
CollectionProvider>>)(wp
-              .getCollectionProviders().entrySet());
-  
-            for (Map.Entry<String, CollectionProvider> entry : entrySet) {
-              CollectionProvider cp = entry.getValue();
-  
-              String href;
-              try {
-                href = UrlEncoding.encode(entry.getKey(), enc, Profile.PATH.filter());
-              } catch (UnsupportedEncodingException e) {
-                throw new RuntimeException(e);
-              }
-  
-              try {
-                sw.startCollection(href)
-                  .writeTitle(cp.getTitle(request))
-                  .writeAcceptsEntry()
-                  .endCollection();
-              } catch (RuntimeException e) {
-              }
-            }
-  
-            sw.endWorkspace();
-          }
-  
-          sw.endService().endDocument();
-  
-        }
-      };
-    }
-    
-    public abstract java.util.Collection<WorkspaceInfo> getWorkspaces();
-
-    public ResponseContext getFeed(RequestContext request) {
-      CollectionProvider provider = null;
-      ResponseContext res = null;
-      try {
-        provider = getCollectionProvider(request);
-        
-        provider.begin(request);
-        
-        res = provider.getFeed(request);
-        return res;
-      } catch (ResponseContextException e) {
-        res = createErrorResponse(e);
-        return res;
-      } finally {
-        end(provider, request, res);
-      }
-    }
-
-    @SuppressWarnings("unchecked")
-    private CollectionProvider getCollectionProvider(RequestContext request) {
-      return (CollectionProvider) request.getAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE);
-    }
-
-    /**
-     * Create a ResponseContext (or take it from the Exception) for an
-     * exception that occurred in the application.
-     * @param e
-     * @return
-     */
-    protected ResponseContext createErrorResponse(ResponseContextException e) {
-      if (log.isInfoEnabled()) {
-        log.info("A ResponseException was thrown.", e);
-      } else if (e.getResponseContext() instanceof EmptyResponseContext 
-        && ((EmptyResponseContext) e.getResponseContext()).getStatus() >= 500)
{
-        log.warn("A ResponseException was thrown.", e);
-      }
-      
-      return e.getResponseContext();
-    }
-
-    public ResponseContext createEntry(RequestContext request) {
-      CollectionProvider provider = null;
-      ResponseContext response = null;
-      try {
-        provider = getCollectionProvider(request);
-        provider.begin(request);
-        
-        return provider.createEntry(request);
-      } catch (ResponseContextException e) {
-        response = createErrorResponse(e);
-        return response;
-      } finally {
-        end(provider, request, response);
-      }
-    }
-
-    protected void end(CollectionProvider provider, RequestContext request, ResponseContext
response) {
-      if (provider != null) {
-        try {
-          provider.end(request, response);
-        } catch (Throwable t) {
-          log.warn("Could not end() CollectionProvider.", t);
-        }
-      }
-    }
-
-    @Override
-    public ResponseContext getMedia(RequestContext request) {
-      CollectionProvider provider = null;
-      ResponseContext response = null;
-      try {
-        provider = getCollectionProvider(request);
-        provider.begin(request);
-        
-        return provider.getMedia(request);
-      } catch (ResponseContextException e) {
-        response = createErrorResponse(e);
-        return response;
-      } finally {
-        end(provider, request, response);
-      }
-    }
-
-
-    @Override
-    public ResponseContext updateMedia(RequestContext request) {
-      // TODO Auto-generated method stub
-      return super.updateMedia(request);
-    }
-
-    public ResponseContext deleteEntry(RequestContext request) {
-      CollectionProvider provider = null;
-      ResponseContext response = null;
-      try {
-        provider = getCollectionProvider(request);
-      
-        return provider.deleteEntry(request);
-      } finally {
-        end(provider, request, response);
-      }
-    }
-
-    
-    public ResponseContext getEntry(RequestContext request) {
-      CollectionProvider provider = null;
-      ResponseContext response = null;
-      try {
-        IRI entryBaseIri = resolveBase(request).resolve("./");
-        provider = getCollectionProvider(request);
-        provider.begin(request);
-        
-        return provider.getEntry(request, entryBaseIri);
-      } catch (ResponseContextException e) {
-        response = createErrorResponse(e);
-        return response;
-      } finally {
-        end(provider, request, response);
-      }
-    }
-
-    @SuppressWarnings("unchecked")
-    public ResponseContext updateEntry(RequestContext request) {
-      CollectionProvider provider = null;
-      ResponseContext response = null;
-      try {
-        IRI entryBaseIri = resolveBase(request).resolve("./");
-        provider = getCollectionProvider(request);
-        provider.begin(request);
-        
-        return provider.updateEntry(request, entryBaseIri);
-      } catch (ResponseContextException e) {
-        response = createErrorResponse(e);
-        return response;
-      } finally {
-        end(provider, request, response);
-      }
-    }
-
-    public String getServicesPath() {
-      return servicesPath;
-    }
-
-    public void setServicesPath(String servicesPath) {
-      this.servicesPath = servicesPath;
-    }
-
-}
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.text.UrlEncoding;
+import org.apache.abdera.i18n.text.CharUtils.Profile;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.CollectionProvider;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
+import org.apache.abdera.protocol.server.RequestContext.Scope;
+import org.apache.abdera.writer.StreamWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Represents an Atom service which is backed by various workspaces and CollectionProviders.
+ * This class can be extended to provide a dynamic list of workspaces or ServiceProvider
can
+ * be used to use a static list.
+ * 
+ */
+public abstract class AbstractServiceProvider extends AbstractProvider implements Resolver<Target>
{
+  private static final Log log = LogFactory.getLog(AbstractServiceProvider.class);
+  public static final String COLLECTION_PROVIDER_ATTRIBUTE = "collectionProvider";
+  public static final String URI_PARAMETER_ATTRIBUTE_PREFIX = "uriParameter";
+  
+    private Pattern servicesPattern = Pattern.compile("^/");
+    
+    protected AbstractServiceProvider(int count) {
+      super(count);
+    }
+
+    public Target resolve(Request request) {
+      RequestContext context = (RequestContext) request;
+      String uri = context.getTargetPath();
+      
+      if (servicesPattern == null) {
+        throw new RuntimeException("You must set the servicesPattern property on the ServiceProvider.");
+      }
+      
+      Matcher uriMatcher = servicesPattern.matcher(uri);
+      TargetType tt = null;
+      if (uriMatcher.matches()) {
+        tt = TargetType.TYPE_SERVICE;
+      } else {
+        uriMatcher.reset();
+        if (uriMatcher.find()) {
+          String path = uri.substring(uriMatcher.end());
+          int q = path.indexOf("?");
+          if (q != -1) {
+            path = path.substring(0, q);
+          }
+          
+          path = UrlEncoding.decode(path);
+  
+          CollectionProvider provider = null;
+          String providerHref = null;
+          for (WorkspaceInfo wi : getWorkspaces()) {
+            for (Map.Entry<String, CollectionProvider> e : wi.getCollectionProviders().entrySet())
{
+              if (path.startsWith(e.getKey())) {
+                provider = e.getValue();
+                providerHref = e.getKey();
+                break;
+              }
+            }
+          }
+          
+          if (provider != null) {
+            context.setAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE, provider);
+            
+            if (providerHref.equals(path)) {
+              tt = TargetType.TYPE_COLLECTION;
+            } else {
+              tt = getOtherTargetType(context, path, providerHref, provider);
+            }
+          }
+        } 
+      }
+      
+      if (tt == null) {
+        tt = TargetType.TYPE_UNKNOWN;
+      } else {
+        for (int i = 1; i <= uriMatcher.groupCount(); i++) {
+          if (uriMatcher.group(i) != null) {
+            context.setAttribute(
+              Scope.REQUEST, 
+              URI_PARAMETER_ATTRIBUTE_PREFIX + Integer.toString(i), 
+              uriMatcher.group(i));
+          }
+        }
+      }
+      
+      return new DefaultTarget(tt, context);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected TargetType getOtherTargetType(RequestContext context, 
+                                            String path, 
+                                            String providerHref, 
+                                            CollectionProvider provider) {
+      String baseMedia = null;
+      if (provider instanceof AbstractCollectionProvider) {
+        baseMedia = ((AbstractCollectionProvider) provider).getBaseMediaIri();
+      }
+      
+      if (providerHref.startsWith("/")) {
+        providerHref = providerHref.substring(1);
+      }
+      
+      if (providerHref.startsWith(baseMedia)) {
+        return TargetType.TYPE_MEDIA;
+      } else {
+        return TargetType.TYPE_ENTRY;
+      }
+    }
+
+    public ResponseContext getService(RequestContext request) {
+      Abdera abdera = request.getAbdera();
+      AbstractResponseContext rc = getServicesDocument(abdera, request);
+      rc.setStatus(200);
+      return rc;
+    }
+
+    private String getEncoding(RequestContext request) {
+      return "utf-8";
+    }
+
+    private AbstractResponseContext getServicesDocument(final Abdera abdera, 
+                                                        final RequestContext request) {
+      final String enc = getEncoding(request);
+      
+      return new StreamWriterResponseContext(abdera) {
+
+        protected void writeTo(StreamWriter sw) throws IOException {
+          sw.startDocument().startService();
+  
+          for (WorkspaceInfo wp : getWorkspaces()) {
+            sw.startWorkspace().writeTitle(wp.getName());
+            Set<Map.Entry<String, CollectionProvider>> entrySet = (Set<Map.Entry<String,
CollectionProvider>>)(wp
+              .getCollectionProviders().entrySet());
+  
+            for (Map.Entry<String, CollectionProvider> entry : entrySet) {
+              CollectionProvider cp = entry.getValue();
+  
+              String href;
+              try {
+                href = UrlEncoding.encode(entry.getKey(), enc, Profile.PATH.filter());
+              } catch (UnsupportedEncodingException e) {
+                throw new RuntimeException(e);
+              }
+  
+              try {
+                sw.startCollection(href)
+                  .writeTitle(cp.getTitle(request))
+                  .writeAcceptsEntry()
+                  .endCollection();
+              } catch (RuntimeException e) {
+              }
+            }
+  
+            sw.endWorkspace();
+          }
+  
+          sw.endService().endDocument();
+  
+        }
+      };
+    }
+    
+    public abstract java.util.Collection<WorkspaceInfo> getWorkspaces();
+
+    public ResponseContext getFeed(RequestContext request) {
+      CollectionProvider provider = null;
+      ResponseContext res = null;
+      try {
+        provider = getCollectionProvider(request);
+        
+        provider.begin(request);
+        
+        res = provider.getFeed(request);
+      } catch (ResponseContextException e) {
+        res = createErrorResponse(e);
+      } finally {
+        end(provider, request, res);
+      }
+      return res;
+    }
+
+    private CollectionProvider getCollectionProvider(RequestContext request) {
+      return (CollectionProvider) request.getAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE);
+    }
+
+    /**
+     * Create a ResponseContext (or take it from the Exception) for an
+     * exception that occurred in the application.
+     * @param e
+     * @return
+     */
+    protected ResponseContext createErrorResponse(ResponseContextException e) {
+      if (log.isInfoEnabled()) {
+        log.info("A ResponseException was thrown.", e);
+      } else if (e.getResponseContext() instanceof EmptyResponseContext 
+        && ((EmptyResponseContext) e.getResponseContext()).getStatus() >= 500)
{
+        log.warn("A ResponseException was thrown.", e);
+      }
+      
+      return e.getResponseContext();
+    }
+
+    public ResponseContext createEntry(RequestContext request) {
+      CollectionProvider provider = null;
+      ResponseContext response = null;
+      try {
+        provider = getCollectionProvider(request);
+        provider.begin(request);
+        
+        response =  provider.createEntry(request);
+      } catch (ResponseContextException e) {
+        response = createErrorResponse(e);
+      } finally {
+        end(provider, request, response);
+      }
+      return response;
+    }
+
+    protected void end(CollectionProvider provider, RequestContext request, ResponseContext
response) {
+      if (provider != null) {
+        try {
+          provider.end(request, response);
+        } catch (Throwable t) {
+          log.warn("Could not end() CollectionProvider.", t);
+        }
+      }
+    }
+
+    @Override
+    public ResponseContext getMedia(RequestContext request) {
+      CollectionProvider provider = null;
+      ResponseContext response = null;
+      try {
+        provider = getCollectionProvider(request);
+        provider.begin(request);
+        
+        response = provider.getMedia(request);
+      } catch (ResponseContextException e) {
+        response = createErrorResponse(e);
+      } finally {
+        end(provider, request, response);
+      }
+      return response;
+    }
+
+
+    @Override
+    public ResponseContext updateMedia(RequestContext request) {
+      // TODO Auto-generated method stub
+      return super.updateMedia(request);
+    }
+
+    public ResponseContext deleteEntry(RequestContext request) {
+      CollectionProvider provider = null;
+      ResponseContext response = null;
+      try {
+        provider = getCollectionProvider(request);
+      
+        response = provider.deleteEntry(request);
+      } finally {
+        end(provider, request, response);
+      }
+      return response;
+    }
+
+    
+    public ResponseContext getEntry(RequestContext request) {
+      CollectionProvider provider = null;
+      ResponseContext response = null;
+      try {
+        IRI entryBaseIri = resolveBase(request).resolve("./");
+        provider = getCollectionProvider(request);
+        provider.begin(request);
+        
+        response = provider.getEntry(request, entryBaseIri);
+      } catch (ResponseContextException e) {
+        response = createErrorResponse(e);
+      } finally {
+        end(provider, request, response);
+      }
+      return response;
+    }
+
+    public ResponseContext updateEntry(RequestContext request) {
+      CollectionProvider provider = null;
+      ResponseContext response = null;
+      try {
+        IRI entryBaseIri = resolveBase(request).resolve("./");
+        provider = getCollectionProvider(request);
+        provider.begin(request);
+        
+        response = provider.updateEntry(request, entryBaseIri);
+      } catch (ResponseContextException e) {
+        response = createErrorResponse(e);
+      } finally {
+        end(provider, request, response);
+      }
+      return response;
+    }
+
+    public String getServicesPattern() {
+      return servicesPattern.pattern();
+    }
+
+    public void setServicesPattern(String servicesPattern) {
+      this.servicesPattern = Pattern.compile(servicesPattern);
+    }
+
+}

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java?rev=612235&r1=612234&r2=612235&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CollectionProviderTest.java
Tue Jan 15 13:37:27 2008
@@ -1,145 +1,142 @@
-package org.apache.abdera.protocol.server;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
-import junit.framework.TestCase;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.factory.Factory;
-import org.apache.abdera.i18n.iri.IRI;
-import org.apache.abdera.model.Base;
-import org.apache.abdera.model.Element;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.protocol.client.AbderaClient;
-import org.apache.abdera.protocol.client.ClientResponse;
-import org.apache.abdera.protocol.client.RequestOptions;
-import org.apache.abdera.protocol.server.CollectionProvider;
-import org.apache.abdera.protocol.server.ServiceContext;
-import org.apache.abdera.protocol.server.TargetType;
-import org.apache.abdera.protocol.server.WorkspaceInfo;
-import org.apache.abdera.protocol.server.impl.DefaultServiceContext;
-import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
-import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
-import org.apache.abdera.protocol.server.impl.SingletonProviderManager;
-import org.apache.abdera.protocol.server.impl.ServiceProvider;
-import org.apache.abdera.protocol.server.servlet.AbderaServlet;
-import org.apache.abdera.writer.Writer;
-import org.apache.abdera.writer.WriterFactory;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.Context;
-import org.mortbay.jetty.servlet.ServletHolder;
-
-public class CollectionProviderTest extends TestCase {
-
-  private Server server;
-  private DefaultServiceContext abderaServiceContext;
-
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();
-    
-    abderaServiceContext = new DefaultServiceContext();
-
-    
-    SingletonProviderManager pm = new SingletonProviderManager();
-    abderaServiceContext.setProviderManager(pm);
-
-    ServiceProvider sp = new ServiceProvider();
-    
-    SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
-    CustomerCollectionProvider cp = new CustomerCollectionProvider();
-    Map<String, CollectionProvider> contentProviders = new HashMap<String, CollectionProvider>();
-    contentProviders.put("acme/customers", cp);
-    
-    wi.setCollectionProviders(contentProviders);
-
-    List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
-    workspaces.add(wi);
-    sp.setWorkspaces(workspaces);
-    
-    pm.setProvider(sp);
-    abderaServiceContext.setTargetResolver(sp);
-    
-    initializeJetty();
-  }
-
-  public void testCustomerProvider() throws Exception {
-
-    Abdera abdera = new Abdera();
-    Factory factory = abdera.getFactory();
-
-    AbderaClient client = new AbderaClient(abdera);
-
-    String base = "http://localhost:9002/";
-
-    // Testing of entry creation
-    IRI colUri = new IRI(base).resolve("acme/customers"); // base +
-                                                          // docCollection.getHref().toString();
-    Entry entry = factory.newEntry();
-    entry.setTitle("Hmmm this is ignored right now");
-    entry.setUpdated(new Date());
-    entry.addAuthor("Acme Industries");
-    entry.setId(factory.newUuidUri());
-    entry.setSummary("Customer document");
-    
-    Element customerEl = factory.newElement(new QName("customer"));
-    customerEl.setAttributeValue(new QName("name"), "Dan Diephouse");
-    entry.setContent(customerEl);
-
-    RequestOptions opts = new RequestOptions();
-    opts.setContentType("application/atom+xml;type=entry");
-    ClientResponse res = client.post(colUri.toString(), entry, opts);
-    assertEquals(201, res.getStatus());
-
-    // prettyPrint(abdera, res.getDocument());
-
-    IRI location = res.getLocation();
-    assertEquals(colUri + "/1001-Dan_Diephouse", 
-                 location.toString());
-
-    // GET the entry
-    res = client.get(location.toString());
-    assertEquals(200, res.getStatus());
-
-    // prettyPrint(abdera, res.getDocument());
-    org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
-    entry = entry_doc.getRoot();
-
-    res = client.get(colUri + "/foobar");
-    assertEquals(404, res.getStatus());
-  }
-
-  protected void prettyPrint(Abdera abdera, Base doc) throws IOException {
-    WriterFactory factory = abdera.getWriterFactory();
-    Writer writer = factory.getWriter("prettyxml");
-    writer.writeTo(doc, System.out);
-    System.out.println();
-  }
-
-  private void initializeJetty() throws Exception {
-
-    server = new Server(9002);
-    Context root = new Context(server, "/", Context.NO_SESSIONS);
-    root.addServlet(new ServletHolder(new AbderaServlet() {
-
-      @Override
-      protected ServiceContext createServiceContext() {
-        abderaServiceContext.init(getAbdera(), getProperties(getServletConfig()));
-        return abderaServiceContext;
-      }
-    }), "/*");
-    server.start();
-  }
-
-  @Override
-  protected void tearDown() throws Exception {
-    if (server != null) server.stop();
-  }
-
-}
+package org.apache.abdera.protocol.server;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.client.RequestOptions;
+import org.apache.abdera.protocol.server.impl.DefaultServiceContext;
+import org.apache.abdera.protocol.server.impl.ServiceProvider;
+import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
+import org.apache.abdera.protocol.server.impl.SingletonProviderManager;
+import org.apache.abdera.protocol.server.servlet.AbderaServlet;
+import org.apache.abdera.writer.Writer;
+import org.apache.abdera.writer.WriterFactory;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+public class CollectionProviderTest extends TestCase {
+
+  private Server server;
+  private DefaultServiceContext abderaServiceContext;
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    
+    abderaServiceContext = new DefaultServiceContext();
+
+    
+    SingletonProviderManager pm = new SingletonProviderManager();
+    abderaServiceContext.setProviderManager(pm);
+
+    ServiceProvider sp = new ServiceProvider();
+    sp.setServicesPattern("^/([^\\/])+/");
+    
+    SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
+    CustomerCollectionProvider cp = new CustomerCollectionProvider();
+    Map<String, CollectionProvider> contentProviders = new HashMap<String, CollectionProvider>();
+    contentProviders.put("acme/customers", cp);
+    
+    wi.setCollectionProviders(contentProviders);
+
+    List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
+    workspaces.add(wi);
+    sp.setWorkspaces(workspaces);
+    
+    pm.setProvider(sp);
+    abderaServiceContext.setTargetResolver(sp);
+    
+    initializeJetty();
+  }
+
+  public void testCustomerProvider() throws Exception {
+
+    Abdera abdera = new Abdera();
+    Factory factory = abdera.getFactory();
+
+    AbderaClient client = new AbderaClient(abdera);
+
+    String base = "http://localhost:9002/";
+
+    // Testing of entry creation
+    IRI colUri = new IRI(base).resolve("foo/acme/customers"); // base +
+                                                          // docCollection.getHref().toString();
+    Entry entry = factory.newEntry();
+    entry.setTitle("Hmmm this is ignored right now");
+    entry.setUpdated(new Date());
+    entry.addAuthor("Acme Industries");
+    entry.setId(factory.newUuidUri());
+    entry.setSummary("Customer document");
+    
+    Element customerEl = factory.newElement(new QName("customer"));
+    customerEl.setAttributeValue(new QName("name"), "Dan Diephouse");
+    entry.setContent(customerEl);
+
+    RequestOptions opts = new RequestOptions();
+    opts.setContentType("application/atom+xml;type=entry");
+    ClientResponse res = client.post(colUri.toString(), entry, opts);
+    assertEquals(201, res.getStatus());
+
+    // prettyPrint(abdera, res.getDocument());
+
+    IRI location = res.getLocation();
+    assertEquals(colUri + "/1001-Dan_Diephouse", 
+                 location.toString());
+
+    // GET the entry
+    res = client.get(location.toString());
+    assertEquals(200, res.getStatus());
+
+    // prettyPrint(abdera, res.getDocument());
+    org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
+    entry = entry_doc.getRoot();
+
+    res = client.get(colUri + "/foobar");
+    assertEquals(404, res.getStatus());
+  }
+
+  protected void prettyPrint(Abdera abdera, Base doc) throws IOException {
+    WriterFactory factory = abdera.getWriterFactory();
+    Writer writer = factory.getWriter("prettyxml");
+    writer.writeTo(doc, System.out);
+    System.out.println();
+  }
+
+  private void initializeJetty() throws Exception {
+
+    server = new Server(9002);
+    Context root = new Context(server, "/", Context.NO_SESSIONS);
+    root.addServlet(new ServletHolder(new AbderaServlet() {
+
+      @Override
+      protected ServiceContext createServiceContext() {
+        abderaServiceContext.init(getAbdera(), getProperties(getServletConfig()));
+        return abderaServiceContext;
+      }
+    }), "/*");
+    server.start();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    if (server != null) server.stop();
+  }
+
+}

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java?rev=612235&r1=612234&r2=612235&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerCollectionProvider.java
Tue Jan 15 13:37:27 2008
@@ -25,7 +25,7 @@
   private Map<Integer, Customer> customers = new HashMap<Integer, Customer>();
   private Factory factory = new Abdera().getFactory();
   
-  public String getId() {
+  public String getId(RequestContext request) {
     return "tag:example.org,2007:feed";
   }
 



Mime
View raw message