abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r615399 - in /incubator/abdera/java/branches/server_refactor_all: examples/src/main/java/org/apache/abdera/examples/appserver/ server/src/main/java/org/apache/abdera/protocol/server/impl/
Date Fri, 25 Jan 2008 23:34:53 GMT
Author: jmsnell
Date: Fri Jan 25 15:34:44 2008
New Revision: 615399

URL: http://svn.apache.org/viewvc?rev=615399&view=rev
Log:
Fix up examples and some javadoc

Modified:
    incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/CustomProvider.java
    incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleAdapter.java
    incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/impl/TemplateTargetBuilder.java

Modified: incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/CustomProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/CustomProvider.java?rev=615399&r1=615398&r2=615399&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/CustomProvider.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/CustomProvider.java
Fri Jan 25 15:34:44 2008
@@ -28,6 +28,8 @@
 import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
 import org.apache.abdera.protocol.server.impl.SimpleCollectionInfo;
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
+import org.apache.abdera.protocol.server.impl.TemplateTargetBuilder;
+import org.apache.abdera.protocol.server.test.custom.OpenSearchFilter;
 
 public class CustomProvider 
   extends AbstractWorkspaceProvider {
@@ -46,6 +48,17 @@
         .setPattern("/atom/([^/#?;]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
         .setPattern("/atom/([^/#?]+)/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY, "collection","entry")
     );
+    
+    
+    // The target builder is used to construct url's for the various targets
+    setTargetBuilder(
+        new TemplateTargetBuilder()
+          .setTemplate(TargetType.TYPE_SERVICE, "{target_base}/atom")
+          .setTemplate(TargetType.TYPE_COLLECTION, "{target_base}/atom/{collection}{-opt|?|q,c,s,p,l,i,o}{-join|&|q,c,s,p,l,i,o}")
+          .setTemplate(TargetType.TYPE_CATEGORIES, "{target_base}/atom/{collection};categories")
+          .setTemplate(TargetType.TYPE_ENTRY, "{target_base}/atom/{collection}/{entry}")
+          .setTemplate(OpenSearchFilter.TYPE_OPENSEARCH_DESCRIPTION, "{target_base}/search")
+      );
     
     // Add a Workspace descriptor so the provider can generate an atompub service document
     SimpleWorkspaceInfo workspace = new SimpleWorkspaceInfo();

Modified: incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleAdapter.java?rev=615399&r1=615398&r2=615399&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleAdapter.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleAdapter.java
Fri Jan 25 15:34:44 2008
@@ -19,6 +19,8 @@
 
 import java.io.IOException;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.i18n.text.UrlEncoding;
@@ -71,11 +73,19 @@
     Feed feed = (Feed)context.getAttribute(Scope.SESSION, "feed");
     if (feed == null) {
       feed = createFeedBase(context);
+      feed.setBaseUri(getFeedBaseUri(context));
       context.setAttribute(Scope.SESSION, "feed", feed);
     }
     return feed.getDocument();
   }
-
+ 
+  private String getFeedBaseUri(RequestContext context) {
+    Map<String,String> params = new HashMap<String,String>();
+    params.put("collection", context.getTarget().getParameter("collection"));
+    String uri = context.resolveIri(TargetType.TYPE_COLLECTION, params);
+    return context.getResolvedUri().resolve(uri).toString();
+  }
+  
   public ResponseContext getFeed(
     RequestContext request) {
       Document<Feed> feed;
@@ -136,6 +146,7 @@
           if (!ProviderHelper.isValidEntry(entry))
             return ProviderHelper.badrequest(request);
           setEntryDetails(
+            request,
             entry, 
             abdera.getFactory().newUuidUri());
           Feed feed = getFeedDocument(request).getRoot();
@@ -163,16 +174,24 @@
   }
   
   private void setEntryDetails(
+    RequestContext request,
     Entry entry, 
     String id) {
       entry.setUpdated(new Date());
       entry.setEdited(entry.getUpdated());
       entry.getIdElement().setValue(id);
       entry.addLink(
-        "/atom/feed/" + entry.getId().toASCIIString(), 
+        getEntryLink(request,entry.getId().toASCIIString()),
         "edit");
   }
   
+  private String getEntryLink(RequestContext request, String entryid) {
+    Map<String,String> params = new HashMap<String,String>();
+    params.put("collection", request.getTarget().getParameter("collection"));
+    params.put("entry", entryid);
+    return request.resolveIri(TargetType.TYPE_ENTRY, params);
+  }
+  
   public ResponseContext putEntry(
     RequestContext request) {
       Abdera abdera = request.getAbdera();
@@ -189,6 +208,7 @@
             if (!ProviderHelper.isValidEntry(entry))
               return ProviderHelper.badrequest(request);
             setEntryDetails(
+              request,
               entry, 
               orig_entry.getId().toString());
             orig_entry.discard();

Modified: incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/impl/TemplateTargetBuilder.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/impl/TemplateTargetBuilder.java?rev=615399&r1=615398&r2=615399&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/impl/TemplateTargetBuilder.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/impl/TemplateTargetBuilder.java
Fri Jan 25 15:34:44 2008
@@ -20,6 +20,12 @@
 import org.apache.abdera.protocol.server.RequestContext.Scope;
 
 @SuppressWarnings("unchecked") 
+/**
+ * A TargetBuilder implementation that uses URI/IRI Templates to construct
+ * URIs/IRIs.  The input parameter can be a java.util.Map<String,Object>, 
+ * an instance of the org.apache.abdera.i18n.templates.Context interface,
+ * or any Java object with public getter methods. 
+ */
 public class TemplateTargetBuilder 
   implements TargetBuilder {
 



Mime
View raw message