abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r600698 - in /incubator/abdera/java/trunk: protocol/src/main/java/org/apache/abdera/protocol/error/ server/src/main/java/org/apache/abdera/protocol/server/ server/src/main/java/org/apache/abdera/protocol/server/impl/ server/src/main/java/or...
Date Mon, 03 Dec 2007 21:45:00 GMT
Author: jmsnell
Date: Mon Dec  3 13:44:58 2007
New Revision: 600698

URL: http://svn.apache.org/viewvc?rev=600698&view=rev
Log:
A variety of implementation clean ups.  Replacing some uses of the FOM with StreamWriter;
fixing up some api calls; refactoring out an unnecessary base class; consistently returning
the Abdera error document; etc

Added:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java
      - copied, changed from r598389, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java
Removed:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java
Modified:
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpResponseServletAdapter.java

Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
(original)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java
Mon Dec  3 13:44:58 2007
@@ -24,6 +24,7 @@
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.ExtensibleElementWrapper;
+import org.apache.abdera.writer.StreamWriter;
 
 /**
  * Abdera protocol error element.  The Abdera error document provides a 
@@ -113,5 +114,22 @@
     error.setCode(code);
     error.setMessage(message);
     return error;
+  }
+  
+  public static Error create(Abdera abdera, int code, String message, Throwable t) {
+    Document<Error> doc = abdera.getFactory().newDocument();
+    Error error = abdera.getFactory().newElement(ERROR,doc);
+    error.setCode(code);
+    error.setMessage(message);
+    return error;
+  }
+  
+  public static void create(StreamWriter sw, int code, String message, Throwable t) {
+    sw.startDocument()
+      .startElement(ERROR)
+      .startElement(CODE).writeElementText(code).endElement()
+      .startElement(MESSAGE).writeElementText(message).endElement()
+      .endElement()
+      .endDocument();
   }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java
Mon Dec  3 13:44:58 2007
@@ -22,19 +22,19 @@
 
 public interface HttpResponse {
 
-  void setStatus(int status);
+  HttpResponse setStatus(int status);
 
-  void setHeader(String name, String value);
+  HttpResponse setHeader(String name, String value);
 
-  void setContentType(String contentType);
+  HttpResponse setContentType(String contentType);
 
-  void setDateHeader(String key, long time);
+  HttpResponse setDateHeader(String key, long time);
 
   OutputStream getOutputStream() throws IOException;
 
-  void addCookie(String name, String value);
+  HttpResponse addCookie(String name, String value);
 
-  void addCookie(
+  HttpResponse addCookie(
     String name, 
     String value, 
     String domain,
@@ -42,13 +42,13 @@
     int maxage,
     String comment);
   
-  void setContentLength(int length);
+  HttpResponse setContentLength(int length);
   
-  void sendError(int status) throws IOException;
+  HttpResponse sendError(int status) throws IOException;
 
-  void sendError(int status, String message) throws IOException;
+  HttpResponse sendError(int status, String message) throws IOException;
 
-  void sendRedirect(String to) throws IOException;
+  HttpResponse sendRedirect(String to) throws IOException;
   
-  void reset();
+  HttpResponse reset();
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java
Mon Dec  3 13:44:58 2007
@@ -17,15 +17,15 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
+import java.io.IOException;
 import java.util.Date;
 
-
-import org.apache.abdera.model.Categories;
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
 import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.util.Messages;
+import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -164,8 +164,21 @@
 
   public ResponseContext getCategories(
     RequestContext request) {
-      Categories cats = request.getAbdera().newCategories();
-      return returnBase(cats.getDocument(), 200, new Date());
+      AbstractResponseContext rc = 
+        new StreamWriterResponseContext(
+          request.getAbdera()) {
+        protected void writeTo(
+          StreamWriter sw) 
+            throws IOException {
+          sw.startDocument()
+            .startCategories()
+            .endCategories()
+            .endDocument();
+        }        
+      };
+      rc.setStatus(200);
+      rc.setLastModified(new Date());
+      return rc;
   }
   
   public ResponseContext deleteMedia(

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java
Mon Dec  3 13:44:58 2007
@@ -59,20 +59,24 @@
     return config.keySet().toArray(new String[config.size()]);
   }
 
-  public void setHandlerManager(ItemManager<RequestHandler> handlerManager) {
+  public AbstractServiceContext setHandlerManager(ItemManager<RequestHandler> handlerManager)
{
     this.handlerManager = handlerManager;
+    return this;
   }
 
-  public void setProviderManager(ItemManager<Provider> providerManager) {
+  public AbstractServiceContext setProviderManager(ItemManager<Provider> providerManager)
{
     this.providerManager = providerManager;
+    return this;
   }
 
-  public void setSubjectResolver(Resolver<Subject> subjectResolver) {
+  public AbstractServiceContext setSubjectResolver(Resolver<Subject> subjectResolver)
{
     this.subjectResolver = subjectResolver;
+    return this;
   }
 
-  public void setTargetResolver(Resolver<Target> targetResolver) {
+  public AbstractServiceContext setTargetResolver(Resolver<Target> targetResolver)
{
     this.targetResolver = targetResolver;
+    return this;
   }
 
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
Mon Dec  3 13:44:58 2007
@@ -17,29 +17,26 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
-import java.io.UnsupportedEncodingException;
+import java.io.IOException;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.abdera.Abdera;
-import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.io.CharUtils.Profile;
 import org.apache.abdera.i18n.iri.Escaping;
 import org.apache.abdera.i18n.iri.IRI;
-import org.apache.abdera.model.Collection;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Service;
-import org.apache.abdera.model.Workspace;
 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.WorkspaceInfo;
 import org.apache.abdera.protocol.util.EncodingUtil;
 import org.apache.abdera.util.EntityTag;
+import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public abstract class AbstractWorkspaceProvider extends AbstractProvider {
+public abstract class AbstractWorkspaceProvider 
+  extends AbstractProvider {
   private final static Log log = LogFactory.getLog(AbstractWorkspaceProvider.class);
   
     private EntityTag service_etag = new EntityTag("simple");
@@ -50,8 +47,7 @@
 
     public ResponseContext getService(RequestContext request) {
       Abdera abdera = request.getAbdera();
-      Document<Service> service = getServicesDocument(abdera, getEncoding(request));
-      AbstractResponseContext rc = new BaseResponseContext<Document<Service>>(service);
+      AbstractResponseContext rc = getServicesDocument(abdera, getEncoding(request));
       rc.setEntityTag(service_etag);
       return rc;
     }
@@ -60,36 +56,39 @@
       return "utf-8";
     }
     
-    @SuppressWarnings("unchecked")
-    private Document<Service> getServicesDocument(Abdera abdera, String enc) {    
     
-      if (enc == null) {
-        enc = "utf-8";
-      }
-      
-      Factory factory = abdera.getFactory();
-      Service service = factory.newService();
-      for (WorkspaceInfo wp : getWorkspaces()) {
-        Workspace workspace = service.addWorkspace(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 id;
-          String workspaceKey;
-          try {
-            id = Escaping.encode(wp.getId(), enc, Profile.PATH);
-            workspaceKey = Escaping.encode(entry.getKey(), enc, Profile.PATH);
-          } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-          }
-          Collection collection = workspace.addCollection(cp.getTitle(), 
-                                                          id + "/" + workspaceKey);
-          collection.setAccept("entry");
-          // collection.addCategories().setFixed(false);
+    private AbstractResponseContext getServicesDocument(
+      final Abdera abdera, 
+      final String enc) {
+      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();
+              final String id = wp.getId();
+              final String key = entry.getKey();
+              try {
+                sw.startCollection(
+                    Escaping.encode(id,enc,Profile.PATH) + "/" + 
+                    Escaping.encode(key,enc,Profile.PATH))
+                  .writeTitle(cp.getTitle())
+                  .writeAcceptsEntry() 
+                  .endCollection();
+              } catch (RuntimeException e) {}
+            }
+            sw.endWorkspace();    
+          }          
+          sw.endService()
+            .endDocument();
         }
-      }
-      return service.getDocument();
+      };
     }
 
     public abstract java.util.Collection<WorkspaceInfo> getWorkspaces();

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java
(from r598389, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java&r1=598389&r2=600698&rev=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java
Mon Dec  3 13:44:58 2007
@@ -19,7 +19,6 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 import java.util.Date;
 
@@ -27,7 +26,9 @@
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.error.Error;
 import org.apache.abdera.protocol.server.HttpResponse;
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.RequestContext;
@@ -36,13 +37,14 @@
 import org.apache.abdera.protocol.server.ServiceContext;
 import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.util.Messages;
+import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public abstract class AbstractRequestHandler 
+public class DefaultRequestHandler 
   implements RequestHandler {
 
-  private static final Log log = LogFactory.getLog(AbstractRequestHandler.class);
+  private static final Log log = LogFactory.getLog(DefaultRequestHandler.class);
   
   public void process(
     ServiceContext context, 
@@ -142,17 +144,22 @@
               "There was an error fulfilling your request.");
   }
 
-  private void sendError(RequestContext request, 
-                         HttpResponse response, int code, 
-                         String message) throws UnsupportedEncodingException,
-    IOException {
+  private void sendError(
+    RequestContext request, 
+    HttpResponse response, int code, 
+    String message) 
+      throws UnsupportedEncodingException,
+             IOException {
+    Abdera abdera = request.getAbdera();
     response.setStatus(code);
-    OutputStream out = response.getOutputStream();
-    OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
-    // TODO: should we wrap this in some nice HTML?
-    writer.write(message != null ? message : "");
-    writer.close();
-    out.close();
+    response.setContentType("application/xml");
+    StreamWriter sw = 
+      abdera.newStreamWriter()
+            .setOutputStream(
+              response.getOutputStream(),
+              "UTF-8");
+    Error.create(sw,code,message,null);
+    sw.close();
   }
   
   protected boolean checkMethod(

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
Mon Dec  3 13:44:58 2007
@@ -102,20 +102,24 @@
     return defaulttargetresolver;
   }
 
-  public void setDefaultProviderManager(String defaultprovidermanager) {
+  public DefaultServiceContext setDefaultProviderManager(String defaultprovidermanager) {
     this.defaultprovidermanager = defaultprovidermanager;
+    return this;
   }
 
-  public void setDefaultRequestHandlerManager(String defaultrequesthandlermanager) {
+  public DefaultServiceContext setDefaultRequestHandlerManager(String defaultrequesthandlermanager)
{
     this.defaultrequesthandlermanager = defaultrequesthandlermanager;
+    return this;
   }
 
-  public void setDefaultSubjectResolver(String defaultsubjectresolver) {
+  public DefaultServiceContext setDefaultSubjectResolver(String defaultsubjectresolver) {
     this.defaultsubjectresolver = defaultsubjectresolver;
+    return this;
   }
 
-  public void setDefaultTargetResolver(String defaulttargetresolver) {
+  public DefaultServiceContext setDefaultTargetResolver(String defaulttargetresolver) {
     this.defaulttargetresolver = defaulttargetresolver;
+    return this;
   }
 
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java
Mon Dec  3 13:44:58 2007
@@ -29,6 +29,10 @@
     setStatus(status);
   }
   
+  public EmptyResponseContext(int status, String text) {
+    setStatusText(text);
+  }
+  
   public boolean hasEntity() {
     return false;
   }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
Mon Dec  3 13:44:58 2007
@@ -1,5 +1,6 @@
 package org.apache.abdera.protocol.server.impl;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -22,6 +23,7 @@
 import org.apache.abdera.protocol.util.EncodingUtil;
 import org.apache.abdera.util.Messages;
 import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -47,6 +49,10 @@
     this.defaultpagesize = defaultpagesize;
   }
 
+  /**
+   * Returns an Error document based on FOM objects
+   * @deprecated Use createErrorResponse
+   */
   protected Document<Error> createErrorDocument(
     Abdera abdera, 
     int code, 
@@ -57,6 +63,36 @@
   }
 
   /**
+   * Returns an Error document based on the StreamWriter
+   */
+  protected AbstractResponseContext createErrorResponse(
+      Abdera abdera, 
+      final int code, 
+      final String message) {
+    return createErrorResponse(abdera,code,message,null);
+  }
+  
+  /**
+   * Returns an Error document based on the StreamWriter
+   */
+  protected AbstractResponseContext createErrorResponse(
+    Abdera abdera, 
+    final int code, 
+    final String message, 
+    final Throwable t) {
+      AbstractResponseContext rc = 
+        new StreamWriterResponseContext(abdera) {
+          protected void writeTo(StreamWriter sw) 
+            throws IOException {
+            Error.create(sw, code, message, t);
+          }
+        };
+      rc.setStatus(code);
+      rc.setStatusText(message);
+      return rc;
+  }
+
+  /**
    * Return a server error
    */
   protected ResponseContext servererror(
@@ -65,11 +101,7 @@
     String reason,
     Throwable t) {
       log.debug(Messages.get("SERVER_ERROR"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 500, 
-          reason, t), 
-        500, null);
+      return createErrorResponse(abdera,500,reason,t);
   }
 
   /**
@@ -80,11 +112,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("UNAUTHORIZED"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 401, 
-          reason, null), 
-        401, null);
+      return createErrorResponse(abdera,401,reason);
   }
 
   /**
@@ -95,11 +123,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("FORBIDDEN"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 403, 
-          reason, null), 
-        403, null);
+      return createErrorResponse(abdera,403,reason);
   }
 
   /**
@@ -110,11 +134,7 @@
     RequestContext request,
     String reason) {
     log.debug(Messages.get("UNKNOWN"));
-    return returnBase(
-      createErrorDocument(
-        abdera, 404, 
-        reason, null), 
-      404, null);
+    return createErrorResponse(abdera,404,reason);
   }
 
   /**
@@ -126,14 +146,10 @@
     String reason,
     String... methods) {
       log.debug(Messages.get("NOT.ALLOWED")); 
-      BaseResponseContext resp = 
-        (BaseResponseContext)returnBase(
-          createErrorDocument(
-            abdera, 405, 
-            reason, null), 
-          405, null);
-        resp.setAllow(methods);
-        return resp;
+      AbstractResponseContext resp = 
+        createErrorResponse(abdera,405,reason);
+      resp.setAllow(methods);
+      return resp;
   }
 
   /**
@@ -144,11 +160,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("BAD.REQUEST"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 400, 
-          reason, null), 
-        400, null);
+      return createErrorResponse(abdera,400,reason);
   }
 
   /**
@@ -159,11 +171,7 @@
     RequestContext request,
     String reason) {
     log.debug(Messages.get("CONFLICT"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 409, 
-          reason, null), 
-        409, null);
+    return createErrorResponse(abdera,409,reason);
   }
 
   /**
@@ -174,11 +182,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("UNAVAILABLE"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 503, 
-          reason, null), 
-        503, null);
+      return createErrorResponse(abdera,503,reason);
   }
 
   protected ResponseContext notmodified(
@@ -186,9 +190,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("NOT.MODIFIED"));
-      EmptyResponseContext rc = new EmptyResponseContext(304);
-      rc.setStatusText(reason);
-      return rc;
+      return new EmptyResponseContext(304,reason);
   }
 
   protected ResponseContext preconditionfailed(
@@ -196,11 +198,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("PRECONDITION.FAILED"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 412, 
-          reason, null), 
-        412, null);
+      return createErrorResponse(abdera,412,reason);
   }
 
   /**
@@ -211,11 +209,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("NOT.SUPPORTED"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 415, 
-          reason, null),
-        415,null);
+      return createErrorResponse(abdera,415,reason);
   }
 
   /**
@@ -226,11 +220,7 @@
     RequestContext request,
     String reason) {
       log.debug(Messages.get("LOCKED"));
-      return returnBase(
-        createErrorDocument(
-          abdera, 423,
-          reason, null),
-        423,null);
+      return createErrorResponse(abdera,423,reason);
     }
 
   /**
@@ -313,6 +303,9 @@
           !id.isAbsolute()) return false;
       if (entry.getTitle() == null) return false;
       if (entry.getUpdated() == null) return false;
+      if (entry.getAuthor() == null && 
+          (entry.getSource() != null && 
+           entry.getAuthor() == null)) return false;
       Content content = entry.getContentElement();
       if (content == null) {
         if (entry.getAlternateLink() == null) return false;

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
Mon Dec  3 13:44:58 2007
@@ -40,12 +40,12 @@
  * <pre>
  *  RequestContext request = ...
  *  RegexTargetResolver tr = new RegexTargetResolver();
- *  tr.setPattern("/atom",ResourceType.INTROSPECTION);
- *  tr.setPattern("/atom/([^/#?]+)",ResourceType.COLLECTION);
- *  tr.setPattern("/atom/([^/#?]+)/([^/#?]+)",ResourceType.ENTRY);
- *  tr.setPattern("/atom/([^/#?]+)/([^/#?]+)\\?edit",ResourceType.ENTRY_EDIT);
- *  tr.setPattern("/atom/([^/#?]+)/([^/#?]+)\\?media",ResourceType.MEDIA);
- *  tr.setPattern("/atom/([^/#?]+)/([^/#?]+)\\?edit-media",ResourceType.MEDIA_EDIT);
+ *  tr.setPattern("/atom",ResourceType.INTROSPECTION)
+ *    .setPattern("/atom/([^/#?]+)",ResourceType.COLLECTION)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)",ResourceType.ENTRY)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)\\?edit",ResourceType.ENTRY_EDIT)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)\\?media",ResourceType.MEDIA)
+ *    .setPattern("/atom/([^/#?]+)/([^/#?]+)\\?edit-media",ResourceType.MEDIA_EDIT);
  *  
  *  Target target = tr.resolve(request);
  *  System.out.println(target.getType());
@@ -70,9 +70,10 @@
     }
   }
   
-  public synchronized void setPattern(String pattern, TargetType type) {
+  public synchronized RegexTargetResolver setPattern(String pattern, TargetType type) {
     Pattern p = Pattern.compile(pattern);
     this.patterns.put(p,type);
+    return this;
   }
   
   public Target resolve(Request request) {
@@ -155,21 +156,21 @@
     public String toString() {
       String m = matcher.group(0);
       String p = matcher.pattern().pattern();
-      StringBuffer buf = new StringBuffer();
-      buf.append("RegexTarget[");
-      buf.append(p);
-      buf.append(" ==> ");
-      buf.append(m);
-      buf.append("] = ");
-      buf.append(type.toString());
-      buf.append("\n");
+      StringBuilder buf = new StringBuilder();
+      buf.append("RegexTarget[")
+         .append(p)
+         .append(" ==> ")
+         .append(m)
+         .append("] = ")
+         .append(type.toString())
+         .append("\n");
       String[] params = getParameterNames();
       for (String param : params) {
-        buf.append("    ");
-        buf.append(param);
-        buf.append(" = ");
-        buf.append(getParameter(param));
-        buf.append("\n");
+        buf.append("    ")
+           .append(param)
+           .append(" = ")
+           .append(getParameter(param))
+           .append("\n");
       }
       return buf.toString();
     }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java
Mon Dec  3 13:44:58 2007
@@ -36,6 +36,14 @@
   
   protected String encoding = "UTF-8";
   
+  protected SimpleResponseContext() {
+    this(null);
+  }
+  
+  protected SimpleResponseContext(String encoding) {
+    this.encoding = encoding != null ? encoding : "UTF-8";
+  }
+  
   protected void setEncoding(String encoding) {
     this.encoding = encoding;
   }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java
Mon Dec  3 13:44:58 2007
@@ -18,8 +18,6 @@
 package org.apache.abdera.protocol.server.impl;
 
 import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
 import java.io.Writer;
 
 import org.apache.abdera.Abdera;
@@ -32,12 +30,11 @@
  * to know more about proper Atom syntax.
  */
 public abstract class StreamWriterResponseContext 
-  extends AbstractResponseContext {
+  extends SimpleResponseContext {
   
   private final Abdera abdera;
   private final String sw;
   private boolean autoindent;
-  private String encoding = "UTF-8";
   
   /**
    * Create a new StreamWriterResponseContext
@@ -45,17 +42,31 @@
    */
   protected StreamWriterResponseContext(
     Abdera abdera) {
-      this(abdera,null);
+      this(abdera,null,null);
   }
 
   /**
    * Create a new StreamWriterResponseContext
    * @param abdera The Abdera instance
+   * @param encoding The charset encoding
+   */
+  protected StreamWriterResponseContext(
+      Abdera abdera,
+      String encoding) {
+        this(abdera,encoding,null);
+  }
+  
+  /**
+   * Create a new StreamWriterResponseContext
+   * @param abdera The Abdera instance
+   * @param encoding The charset encoding
    * @param sw The name of the Named StreamWriter to use
    */
   protected StreamWriterResponseContext(
-    Abdera abdera, 
+    Abdera abdera,
+    String encoding,
     String sw) {
+      super(encoding);
       this.abdera = abdera;
       this.sw = sw;
   }
@@ -77,25 +88,13 @@
       abdera.getWriterFactory().newStreamWriter(sw);
   }
   
-  /**
-   * Use the StreamWriter to write to the specified OutputStream
-   */
-  public void writeTo(
-    OutputStream out) 
+  protected void writeEntity(
+    Writer writer) 
       throws IOException {
-    writeTo(new OutputStreamWriter(out,encoding));
-  }
-
-  /**
-   * Use the StreamWriter to write to the specified java.io.Writer
-   */
-  public void writeTo(Writer writer) 
-    throws IOException {
-      writeTo(
-        newStreamWriter()
-          .setWriter(writer)
-          .setAutoIndent(autoindent)
-      );
+    writeTo(
+      newStreamWriter()
+        .setWriter(writer)
+        .setAutoIndent(autoindent));
   }
   
   /**
@@ -105,30 +104,11 @@
   protected abstract void writeTo(StreamWriter sw) throws IOException;
   
   /**
-   * Unsupported
-   */
-  public final void writeTo(
-    OutputStream out, 
-    org.apache.abdera.writer.Writer writer)
-      throws IOException {
-    throw new UnsupportedOperationException();
-  }
-  
-  /**
-   * Unsupported
-   */
-  public final void writeTo(
-    Writer javaWriter,
-    org.apache.abdera.writer.Writer abderaWriter) 
-      throws IOException {
-    throw new UnsupportedOperationException();
-  }
-  
-  /**
    * True to enable automatic indenting on the StreamWriter
    */
-  public void setAutoIndent(boolean autoindent) {
+  public StreamWriterResponseContext setAutoIndent(boolean autoindent) {
     this.autoindent = autoindent;
+    return this;
   }
   
   /**
@@ -142,17 +122,4 @@
     return true;
   }
 
-  /**
-   * Return the character set encoding used when writing to an outputstream
-   */
-  public String getEncoding() {
-    return encoding;
-  }
-  
-  /**
-   * Set the character set encoding used when writing to an outputstream
-   */
-  public void setEncoding(String encoding) {
-    this.encoding = encoding;
-  }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java
Mon Dec  3 13:44:58 2007
@@ -24,6 +24,7 @@
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.server.ServiceManager;
 
 public abstract class AbderaFilter 
   extends AbstractFilter {
@@ -31,7 +32,7 @@
   protected final Abdera abdera;
   
   protected AbderaFilter() {
-    this.abdera = new Abdera();
+    this.abdera = ServiceManager.getAbdera();
   }
   
   protected Abdera getAbdera() {

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
Mon Dec  3 13:44:58 2007
@@ -30,11 +30,13 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.error.Error;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.RequestHandler;
 import org.apache.abdera.protocol.server.ServiceContext;
 import org.apache.abdera.protocol.server.ServiceManager;
 import org.apache.abdera.protocol.server.impl.HttpServletRequestContext;
+import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -114,7 +116,14 @@
     if (response.isCommitted()) response.reset();
     if (t != null) log.error(message, t);
     else log.error(message);
-    response.sendError(500, message);
+    response.setStatus(500);
+    StreamWriter sw = 
+      getAbdera().newStreamWriter()
+                 .setOutputStream(
+                   response.getOutputStream(),
+                   "UTF-8");
+    Error.create(sw, 500, message,t);
+    sw.close();
   }
   
   protected Map<String,String> getProperties(ServletConfig config) {

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpResponseServletAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpResponseServletAdapter.java?rev=600698&r1=600697&r2=600698&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpResponseServletAdapter.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpResponseServletAdapter.java
Mon Dec  3 13:44:58 2007
@@ -20,27 +20,31 @@
     return response.getOutputStream();
   }
 
-  public void setContentType(String contentType) {
+  public HttpResponse setContentType(String contentType) {
     response.setContentType(contentType);
+    return this;
   }
 
-  public void setDateHeader(String key, long time) {
+  public HttpResponse setDateHeader(String key, long time) {
     response.setDateHeader(key, time);
+    return this;
   }
 
-  public void setHeader(String name, String value) {
+  public HttpResponse setHeader(String name, String value) {
     response.setHeader(name, value);
+    return this;
   }
 
-  public void setStatus(int status) {
+  public HttpResponse setStatus(int status) {
     response.setStatus(status);
+    return this;
   }
 
-  public void addCookie(String name, String value) {
-    addCookie(name,value,null,null,-1,null);
+  public HttpResponse addCookie(String name, String value) {
+    return addCookie(name,value,null,null,-1,null);
   }
   
-  public void addCookie(
+  public HttpResponse addCookie(
     String name, 
     String value, 
     String domain,
@@ -53,30 +57,37 @@
       if (maxage >= 0) cookie.setMaxAge(maxage);
       if (comment != null) cookie.setComment(comment);
       response.addCookie(cookie);
+      return this;
   }
   
-  public void setCharacterEncoding(String charset) {
+  public HttpResponse setCharacterEncoding(String charset) {
     response.setCharacterEncoding(charset);
+    return this;
   }
   
-  public void setContentLength(int length) {
+  public HttpResponse setContentLength(int length) {
     response.setContentLength(length);
+    return this;
   }
 
-  public void sendError(int status) throws IOException {
+  public HttpResponse sendError(int status) throws IOException {
     response.sendError(status);
+    return this;
   }
   
-  public void sendError(int status, String message) throws IOException {
+  public HttpResponse sendError(int status, String message) throws IOException {
     response.sendError(status, message);
+    return this;
   }
   
-  public void sendRedirect(String to) throws IOException {
+  public HttpResponse sendRedirect(String to) throws IOException {
     response.sendRedirect(to);
+    return this;
   }
   
-  public void reset() {
+  public HttpResponse reset() {
     response.reset();
+    return this;
   }
   
   public HttpServletResponse getActual() {



Mime
View raw message