abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r613765 [1/4] - in /incubator/abdera/java/branches/server_refactor/src: main/java/org/ main/java/org/apache/ main/java/org/apache/abdera/ main/java/org/apache/abdera/protocol/ main/java/org/apache/abdera/protocol/server/ main/java/org/apach...
Date Mon, 21 Jan 2008 05:33:58 GMT
Author: jmsnell
Date: Sun Jan 20 21:33:46 2008
New Revision: 613765

URL: http://svn.apache.org/viewvc?rev=613765&view=rev
Log:
Refactoring of the server module as discussed in my previous message.  This incorporates the stuff from google and attempts to 
port the CollectionProvider model over all.  However, I really don't think I did a very good job of converting that stuff over
mainly because I'm not that familiar with it yet.  There are three test implementations included, using each of the three
current approaches.  This obviously needs additional work but this branch should at least get things started

Added:
    incubator/abdera/java/branches/server_refactor/src/main/java/org/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/
    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/MediaCollectionAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Target.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/TargetType.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/
    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/AbstractRequestContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManagerProvider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/EntityProviderResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SingletonProviderManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/StreamWriterResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/AbstractBasicAdapter.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/provider/basic/BasicAdapterManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProvider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicProviderManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicResponseContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/BasicTargetResolver.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/basic/SampleBasicAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/AbstractEntityCollectionAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/AbstractNamedCollectionAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/ExtendedProvider.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/ExtendedWorkspaceManager.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/NamedCollectionAdapter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/SimpleWorkspaceInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/provider/ext/WorkspaceInfo.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.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/main/java/org/apache/abdera/protocol/server/servlet/AbstractFilter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/CompressionFilter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/MethodOverrideFilter.java
    incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/JettyServer.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/basic/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/ext/
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/ext/ExtTest.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/ext/TestExtendedProvider.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/ext/TestProviderManager.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/ext/TestServiceContext.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/ext/TestTargetResolver.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/
    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/SimpleProviderManager.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/SimpleTargetResolver.java
    incubator/abdera/java/branches/server_refactor/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
    incubator/abdera/java/branches/server_refactor/src/test/resources/
    incubator/abdera/java/branches/server_refactor/src/test/resources/abdera/
    incubator/abdera/java/branches/server_refactor/src/test/resources/abdera/adapter/
    incubator/abdera/java/branches/server_refactor/src/test/resources/abdera/adapter/sample.properties

Added: 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=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionAdapter.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/CollectionAdapter.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,34 @@
+/*
+* 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;
+
+public interface CollectionAdapter {
+
+  ResponseContext postEntry(RequestContext request);
+  
+  ResponseContext deleteEntry(RequestContext request);
+  
+  ResponseContext getEntry(RequestContext request);
+  
+  ResponseContext putEntry(RequestContext request);
+
+  ResponseContext getFeed(RequestContext request);
+   
+  ResponseContext extensionRequest(RequestContext request);
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/MediaCollectionAdapter.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,31 @@
+/*
+* 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;
+
+public interface MediaCollectionAdapter 
+  extends CollectionAdapter {
+
+  ResponseContext postMedia(RequestContext request);
+  
+  ResponseContext deleteMedia(RequestContext request);
+  
+  ResponseContext getMedia(RequestContext request);
+  
+  ResponseContext putMedia(RequestContext request);
+    
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Provider.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,25 @@
+/*
+* 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;
+
+
+public interface Provider {
+
+  ResponseContext process(RequestContext request);
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ProviderHelper.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,459 @@
+package org.apache.abdera.protocol.server;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
+import javax.activation.MimeType;
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.text.Localizer;
+import org.apache.abdera.i18n.text.Sanitizer;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.ExtensibleElement;
+import org.apache.abdera.protocol.error.Error;
+import org.apache.abdera.protocol.server.impl.AbstractResponseContext;
+import org.apache.abdera.protocol.server.impl.BaseResponseContext;
+import org.apache.abdera.protocol.server.impl.EmptyResponseContext;
+import org.apache.abdera.protocol.server.impl.StreamWriterResponseContext;
+import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.abdera.writer.NamedWriter;
+import org.apache.abdera.writer.StreamWriter;
+import org.apache.abdera.writer.WriterFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Provides support methods for {@link Provider}
+ */
+public class ProviderHelper {
+  private final static Log log = 
+    LogFactory.getLog(ProviderHelper.class);
+  
+  private ProviderHelper() {}
+
+  public static int getPageSize(
+    RequestContext request, 
+    String pagesizeparam, 
+    int defaultpagesize) {
+      int size = defaultpagesize;
+      try {
+        String _ps = request.getParameter(pagesizeparam);
+        size = (_ps != null) ? 
+          Math.min(
+            Math.max(
+              Integer.parseInt(_ps),0),
+                defaultpagesize) : 
+          defaultpagesize;
+      } catch (Exception e) {}
+      log.debug(Localizer.sprintf("PAGE.SIZE",size));
+      return size;
+  }
+
+  public static int getOffset(
+    RequestContext request, 
+    String pageparam, 
+    int pageSize) {
+      int offset = 0;
+      try {
+        String _page = request.getParameter(pageparam);
+        int page =(_page != null) ? Integer.parseInt(_page) : 1;
+        page = Math.max(page, 1) - 1;
+        offset = pageSize * page;
+      } catch (Exception e) {}
+      log.debug(Localizer.sprintf("OFFSET",offset));
+      return offset;
+  }
+  
+  /**
+   * Returns an Error document based on the StreamWriter
+   */
+  public static AbstractResponseContext createErrorResponse(
+      Abdera abdera, 
+      final int code, 
+      final String message) {
+    return createErrorResponse(abdera,code,message,null);
+  }
+  
+  /**
+   * Returns an Error document based on the StreamWriter
+   */
+  public static 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
+   */
+  public static ResponseContext servererror(
+    RequestContext request,
+    String reason,
+    Throwable t) {
+      log.debug(Localizer.get("SERVER_ERROR"));
+      return createErrorResponse(request.getAbdera(),500,reason,t);
+  }
+
+  /**
+   * Return an unauthorized error
+   */
+  public static ResponseContext unauthorized(
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("UNAUTHORIZED"));
+      return createErrorResponse(request.getAbdera(),401,reason);
+  }
+
+  /**
+   * Return an unauthorized error
+   */
+  public static ResponseContext forbidden(
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("FORBIDDEN"));
+      return createErrorResponse(request.getAbdera(),403,reason);
+  }
+
+  /**
+   * Return a 204 No Content response
+   */
+  public static ResponseContext nocontent(String reason) {
+    return new EmptyResponseContext(204,reason);
+  }
+  
+  /**
+   * Return a 404 not found error
+   */
+  public static ResponseContext notfound(
+    RequestContext request,
+    String reason) {
+    log.debug(Localizer.get("UNKNOWN"));
+    return createErrorResponse(request.getAbdera(),404,reason);
+  }
+
+  /**
+   * Return a 405 method not allowed error
+   */
+  public static ResponseContext notallowed( 
+    RequestContext request,
+    String reason,
+    String... methods) {
+      log.debug(Localizer.get("NOT.ALLOWED")); 
+      AbstractResponseContext resp = 
+        createErrorResponse(request.getAbdera(),405,reason);
+      resp.setAllow(methods);
+      return resp;
+  }
+
+  /**
+   * Return a 400 bad request error
+   */
+  public static ResponseContext badrequest(
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("BAD.REQUEST"));
+      return createErrorResponse(request.getAbdera(),400,reason);
+  }
+
+  /**
+   * Return a 409 conflict error
+   */
+  public static ResponseContext conflict(
+    RequestContext request,
+    String reason) {
+    log.debug(Localizer.get("CONFLICT"));
+    return createErrorResponse(request.getAbdera(),409,reason);
+  }
+
+  /**
+   * Return a service unavailable error
+   */
+  public static ResponseContext unavailable(
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("UNAVAILABLE"));
+      return createErrorResponse(request.getAbdera(),503,reason);
+  }
+
+  public static ResponseContext notmodified( 
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("NOT.MODIFIED"));
+      return new EmptyResponseContext(304,reason);
+  }
+
+  public static ResponseContext preconditionfailed(
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("PRECONDITION.FAILED"));
+      return createErrorResponse(request.getAbdera(),412,reason);
+  }
+
+  /**
+   * Return a 415 media type not-supported error
+   */
+  public static ResponseContext notsupported(
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("NOT.SUPPORTED"));
+      return createErrorResponse(request.getAbdera(),415,reason);
+  }
+
+  /**
+   * Return a 423 locked error
+   */
+  public static ResponseContext locked(
+    RequestContext request,
+    String reason) {
+      log.debug(Localizer.get("LOCKED"));
+      return createErrorResponse(request.getAbdera(),423,reason);
+    }
+
+  /**
+   * Return a document
+   */
+  @SuppressWarnings("unchecked")
+  public static ResponseContext returnBase(
+    Base base, 
+    int status,
+    Date lastModified) {
+      log.debug(Localizer.get("RETURNING.DOCUMENT"));
+      BaseResponseContext response = new BaseResponseContext(base);
+      response.setStatus(status);
+      if (lastModified != null) response.setLastModified(lastModified);
+      response.setContentType(MimeTypeHelper.getMimeType(base));
+      Document doc = base instanceof Document ? (Document)base : ((Element)base).getDocument();
+      if (doc.getEntityTag() != null) {
+        response.setEntityTag(doc.getEntityTag());
+      } else if (doc.getLastModified() != null) {
+        response.setLastModified(doc.getLastModified());
+      }
+      return response;
+  }
+
+  /**
+   * Sanitize the value of a Slug header. Any non alphanumeric characters in
+   * the slug are replaced with an underscore
+   */
+  public static String sanitizeSlug(String slug) {
+    if (slug == null) throw new IllegalArgumentException(Localizer.get("SLUG.NOT.NULL"));
+    String sanitized = Sanitizer.sanitize(slug);
+    log.debug(Localizer.sprintf("SLUG.SANITIZED", slug, sanitized));
+    return sanitized;
+  }
+
+  /**
+   * Check to see if the entry is minimally valid according to RFC4287.
+   * This is not a complete check.  It just verifies that the appropriate
+   * elements are present and that their values can be accessed.
+   */
+  public static boolean isValidEntry(Entry entry) {
+    try {
+      IRI id = entry.getId();
+      if (id == null || 
+          id.toString().trim().length() == 0 ||
+          !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;
+      } else {
+        if ((content.getSrc() != null ||
+            content.getContentType() == Content.Type.MEDIA || 
+            content.getContentType() == Content.Type.XML) &&
+            entry.getSummary() == null) {
+          log.debug(Localizer.sprintf("CHECKING.VALID.ENTRY",false));
+          return false;
+        }
+      }
+    } catch (Exception e) {
+      log.debug(Localizer.sprintf("CHECKING.VALID.ENTRY",false));
+      return false;
+    }
+    log.debug(Localizer.sprintf("CHECKING.VALID.ENTRY",true));
+    return true;
+  }
+
+  /**
+   * Return false if the element contains any extension elements that are not 
+   * supported
+   */
+  public static boolean checkElementNamespaces(
+    Element element, 
+    List<String> ignore) {
+      List<QName> attrs = element.getExtensionAttributes();
+      for (QName qname : attrs) {
+        String ns = qname.getNamespaceURI();
+        if (!ignore.contains(ns)) return false; 
+      }
+      if (element instanceof ExtensibleElement) {
+        ExtensibleElement ext = (ExtensibleElement) element;
+        List<Element> extensions = ext.getExtensions();
+        for (Element el : extensions) {
+          QName qname = el.getQName();
+          String ns = qname.getNamespaceURI();
+          if (!ignore.contains(ns)) return false; 
+          if (!checkElementNamespaces(el, ignore)) return false;
+        }
+      }
+      return true;
+  }
+
+  public static boolean beforeOrEqual(Date d1, Date d2) {
+    long l1 = d1.getTime() / 1000; // drop milliseconds
+    long l2 = d2.getTime() / 1000; // drop milliseconds
+    return l1 <= l2;
+  }
+
+  public static IRI resolveBase(RequestContext request) {
+    return request.getBaseUri().resolve(request.getUri());
+  }
+
+  public static String combine(String... vals) {
+    StringBuilder buf = new StringBuilder();
+    for(String val : vals) {
+      if (buf.length() > 0) buf.append(", ");
+      buf.append(val);
+    }
+    return buf.toString();
+  }
+  
+  public static String[] getDefaultMethods(RequestContext request) {
+    TargetType type = request.getTarget().getType();
+    if (type == null)                       return new String[0];
+    if (type == TargetType.TYPE_COLLECTION) return new String[] { "GET", "HEAD", "OPTIONS", "POST" };
+    if (type == TargetType.TYPE_CATEGORIES) return new String[] { "GET", "HEAD", "OPTIONS" };
+    if (type == TargetType.TYPE_ENTRY)      return new String[] { "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT" };
+    if (type == TargetType.TYPE_MEDIA)      return new String[] { "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT" };
+    if (type == TargetType.TYPE_SERVICE)    return new String[] { "GET", "HEAD", "OPTIONS" };
+    return new String[] { "GET", "HEAD", "OPTIONS" };
+  }
+  
+  public static boolean defaultCheckMethod(
+    RequestContext request, 
+    String[] methods) {
+      return (java.util.Arrays.binarySearch(methods, request.getMethod()) >= 0);
+  }
+  
+  public static boolean isAtom(RequestContext request) {
+    MimeType mt = request.getContentType();
+    String ctype = (mt != null) ? mt.toString() : null;
+    return ctype != null && MimeTypeHelper.isAtom(ctype);
+  }
+  
+  private static class QTokenComparator 
+  implements Comparator<QToken> {
+    public int compare(QToken o1, QToken o2) {
+      if (o1.qvalue > o2.qvalue) 
+        return -1;
+      if (o1.qvalue < o2.qvalue) 
+        return 1;
+      return 0;
+    }
+}
+
+  private static class QToken {
+    String token;
+    double qvalue = 1.0;
+    QToken(String token,double qvalue) {
+      this.token = token;
+      this.qvalue = qvalue;
+    }
+  }
+  
+  /**
+   * <p>Utility method for parsing HTTP content negotiation headers and sorting
+   * their tokens according to their q parameter values.</p>
+   * 
+   * <p>e.g. Accept: audio/*; q=0.2, audio/basic, audio/mpeg; q=0.1</p>
+   * 
+   * <p>would sort into:</p>
+   * <pre>
+   *   audio/basic
+   *   audio/*
+   *   audio/mpeg
+   * </pre>
+   */
+  public static String[] orderByQ(String header) {
+    if (header == null || header.length() == 0) return new String[0];
+    String[] tokens = header.split(",");
+    QToken[] qtokens = new QToken[tokens.length];
+    for (int i = 0; i < tokens.length; i++) {
+      String token = tokens[i];
+      String[] qvalues = token.trim().split(";");
+      String t = qvalues[0];
+      if (qvalues.length > 1) {
+        for (int n = 1; n < qvalues.length; n++) {
+          String[] v = qvalues[n].trim().split("=");
+          if (v[0].trim().equals("q")) {
+            double qv = Double.parseDouble(v[1]);
+            qtokens[i] = new QToken(t,qv);
+            break;
+          }
+        }
+      }
+      if (qtokens[i] == null) qtokens[i] = new QToken(t,1.0);
+    }
+    Arrays.sort(qtokens, new QTokenComparator());
+    tokens = new String[qtokens.length];
+    for (int n = 0; n < qtokens.length; n++) {
+      tokens[n] = qtokens[n].token;
+    }
+    return tokens;
+  }
+  
+  /**
+   * Returns an appropriate NamedWriter instance given an appropriately
+   * formatted HTTP Accept header.  The header will be parsed and sorted
+   * according to it's q parameter values.  The first named writer capable
+   * of supporting the specified type, in order of q-value preference, will
+   * be returned.  The results on this are not always predictable.  For instance,
+   * if the Accept header says "application/*" it could end up with either the
+   * JSON writer or the PrettyXML writer, or any other writer that supports
+   * any writer that supports a specific form of "application/*".  It's always
+   * best to be very specific in the Accept headers.
+   */
+  public static NamedWriter getAcceptableNamedWriter(
+    Abdera abdera, String accept_header) {
+      String[] sorted_accepts = orderByQ(accept_header);
+      WriterFactory factory = abdera.getWriterFactory();
+      if (factory == null) return null;
+      for (String accept : sorted_accepts) {
+        NamedWriter writer = (NamedWriter) factory.getWriterByMediaType(accept);
+        if (writer != null) return writer;
+      }
+      return null;
+  }
+  
+  public static NamedWriter getNamedWriter(Abdera abdera, String mediatype) {
+    WriterFactory factory = abdera.getWriterFactory();
+    if (factory == null) return null;
+    NamedWriter writer = (NamedWriter) factory.getWriterByMediaType(mediatype);
+    return writer;
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/RequestContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,106 @@
+/*
+* 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.security.Principal;
+import java.util.List;
+import java.util.Locale;
+
+import javax.security.auth.Subject;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.parser.ParseException;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.parser.ParserOptions;
+import org.apache.abdera.protocol.Request;
+
+public interface RequestContext 
+  extends Request {
+
+  public enum Scope { REQUEST, SESSION };
+  public enum Property { 
+    SESSIONID, SESSIONCREATED, SESSIONACCESSED, SESSIONTIMEOUT,
+    CHARACTERENCODING, LOCALES, PROTOCOL, REMOTEADDRESS, REMOTEHOST,
+    REMOTEUSER, SCHEME, PRINCIPAL, AUTHTYPE, CONTENTLENGTH, 
+    CONTENTTYPE, CONTEXTPATH, LOCALADDR, LOCALNAME,
+    SERVERNAME, SERVERPORT};
+  
+  Abdera getAbdera();
+    
+  ServiceContext getServiceContext();
+    
+  Target getTarget();
+    
+  Subject getSubject();
+  
+  Principal getPrincipal();
+  
+  Locale getPreferredLocale();
+  
+  Locale[] getPreferredLocales();
+  
+  String getMethod();
+  
+  IRI getUri();
+  
+  IRI getResolvedUri();
+  
+  IRI getBaseUri();
+  
+  Object getProperty(Property property);
+  
+  String getParameter(String name);
+  
+  String[] getParameterNames();
+  
+  List<String> getParameters(String name);
+  
+  Object getAttribute(Scope scope,String name);
+  
+  String[] getAttributeNames(Scope scope);
+  
+  RequestContext setAttribute(Scope scope, String name, Object value);
+  
+  InputStream getInputStream() throws IOException;
+  
+  Reader getReader() throws IOException;
+  
+  <T extends Element>Document<T> getDocument() throws ParseException, IOException;
+  
+  <T extends Element>Document<T> getDocument(Parser parser) throws ParseException, IOException;
+  
+  <T extends Element>Document<T> getDocument(Parser parser, ParserOptions options) throws ParseException, IOException;
+  
+  <T extends Element>Document<T> getDocument(ParserOptions options) throws ParseException, IOException;
+  
+  boolean isUserInRole(String role);
+  
+  String getContextPath();
+  
+  /**
+   * Returns the subset of the request URI that is to be used to resolve the Target
+   * (everything after the context path)
+   */
+  String getTargetPath();
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,96 @@
+/*
+* 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;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+
+import org.apache.abdera.i18n.text.CharUtils.Profile;
+import org.apache.abdera.protocol.Response;
+import org.apache.abdera.util.EntityTag;
+import org.apache.abdera.writer.Writer;
+
+public interface ResponseContext 
+  extends Response {
+
+  boolean hasEntity();
+  
+  void writeTo(OutputStream out) throws IOException;
+  
+  void writeTo(java.io.Writer javaWriter) throws IOException;
+  
+  void writeTo(OutputStream out, Writer writer) throws IOException;
+  
+  void writeTo(java.io.Writer javaWriter, Writer abderaWriter) throws IOException;
+  
+  ResponseContext setWriter(Writer writer);
+  
+  ResponseContext removeHeader(String name);
+  
+  ResponseContext setEncodedHeader(String name, String charset, String value);
+  
+  ResponseContext setEncodedHeader(String name, String charset, String... vals);
+  
+  ResponseContext setEscapedHeader(String name, Profile profile, String value);
+  
+  ResponseContext setHeader(String name, Object value);
+  
+  ResponseContext setHeader(String name, Object... vals);
+  
+  ResponseContext addEncodedHeader(String name, String charset, String value);
+
+  ResponseContext addEncodedHeaders(String name, String charset, String... vals);
+
+  ResponseContext addHeader(String name, Object value);
+
+  ResponseContext addHeaders(String name, Object... vals);
+
+  ResponseContext setAge(long age);
+
+  ResponseContext setContentLanguage(String language);
+
+  ResponseContext setContentLength(long length);
+
+  ResponseContext setContentLocation(String uri);
+
+  ResponseContext setSlug(String slug);
+
+  ResponseContext setContentType(String type);
+
+  ResponseContext setContentType(String type, String charset);
+
+  ResponseContext setEntityTag(String etag);
+
+  ResponseContext setEntityTag(EntityTag etag);
+
+  ResponseContext setExpires(Date date);
+
+  ResponseContext setLastModified(Date date);
+
+  ResponseContext setLocation(String uri);
+
+  ResponseContext setStatus(int status);
+
+  ResponseContext setStatusText(String text);
+
+  ResponseContext setAllow(String method);
+
+  ResponseContext setAllow(String... methods);
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,44 @@
+/*
+* 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;
+
+import java.util.Map;
+
+import javax.security.auth.Subject;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Resolver;
+
+public interface ServiceContext {
+
+  Abdera getAbdera();
+  
+  void init(Abdera abdera, Map<String,String> config);
+  
+  ItemManager<Provider> getProviderManager();
+  
+  Resolver<Subject> getSubjectResolver();
+  
+  Resolver<Target> getTargetResolver(String contextPath);
+  
+  String getProperty(String name);
+  
+  String[] getPropertyNames();
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,83 @@
+/*
+* 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;
+
+import java.util.Map;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.text.Localizer;
+import org.apache.abdera.protocol.server.impl.DefaultServiceContext;
+import org.apache.abdera.util.ServiceUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServiceManager {
+   
+  public static final String PROVIDER_MANAGER =
+    "org.apache.abdera.protocol.server.provider.ProviderManager";
+  
+  public static final String SUBJECT_RESOLVER = 
+    "org.apache.abdera.protocol.server.auth.SubjectResolver";
+  
+  public static final String TARGET_RESOLVER = 
+    "org.apache.abdera.protocol.server.provider.TargetResolver";
+  
+  public static final String SERVICE_CONTEXT =
+    "org.apache.abdera.protocol.server.ServiceContext";
+  
+  private final static Log log = LogFactory.getLog(ServiceManager.class);
+  
+  private static ServiceManager INSTANCE = null;
+  private static Abdera abdera = null;
+  
+  ServiceManager() {}
+  
+  public static synchronized ServiceManager getInstance() {
+    if (INSTANCE == null) {
+      log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","ServiceManager"));
+      INSTANCE = new ServiceManager();
+    }
+    return INSTANCE;
+  }
+  
+  public static synchronized Abdera getAbdera() {
+    if (abdera == null) {
+      log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","Abdera"));
+      abdera = new Abdera();
+    }
+    return abdera;
+  }
+  
+  public ServiceContext newServiceContext(
+    Map<String,String> properties) {
+    Abdera abdera = getAbdera();
+    String instance = properties.get(SERVICE_CONTEXT);
+    log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","ServiceContext"));
+    ServiceContext context = 
+      (ServiceContext) ServiceUtil.newInstance(
+        SERVICE_CONTEXT, 
+        (instance != null) ? 
+          instance : 
+          DefaultServiceContext.class.getName(),
+        abdera);
+    log.debug(Localizer.sprintf("INITIALIZING.INSTANCE", "ServiceContext"));
+    context.init(abdera, properties);
+    return context;
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Target.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Target.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Target.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Target.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,31 @@
+/*
+* 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;
+
+public interface Target 
+  extends Iterable<String> {
+
+  TargetType getType();
+  
+  String getIdentity();
+  
+  String getParameter(String name);
+  
+  String[] getParameterNames();
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/TargetType.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/TargetType.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/TargetType.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/TargetType.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,98 @@
+/*
+* 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;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+public final class TargetType {
+
+  public static final String UNKNOWN = "UNKNOWN";
+  public static final String SERVICE = "SERVICE";
+  public static final String COLLECTION = "COLLECTION";
+  public static final String ENTRY = "ENTRY";
+  public static final String MEDIA = "MEDIA";
+  public static final String CATEGORIES = "CATEGORIES";
+
+  private static final Map<String,TargetType> types = 
+    new WeakHashMap<String,TargetType>();
+  
+  public static final TargetType TYPE_UNKNOWN = new TargetType(UNKNOWN);
+  public static final TargetType TYPE_SERVICE = new TargetType(SERVICE);
+  public static final TargetType TYPE_COLLECTION = new TargetType(COLLECTION);
+  public static final TargetType TYPE_ENTRY = new TargetType(ENTRY);
+  public static final TargetType TYPE_MEDIA = new TargetType(MEDIA);
+  public static final TargetType TYPE_CATEGORIES = new TargetType(CATEGORIES);
+
+  public static Iterable<TargetType> values() {
+    return types.values();
+  }
+    
+  public static TargetType get(String name) {
+    return types.get(name.toUpperCase());
+  }
+  
+  public static TargetType get(String name, boolean create) {
+    if (name == null) return null;
+    TargetType type = get(name);
+    return type != null ? type : create ? create(name) : null;
+  }
+  
+  private static synchronized TargetType create(String name) {
+    TargetType type = new TargetType(name.toUpperCase());
+    types.put(type.name(), type);
+    return type;
+  }
+  
+  private final String name;
+  
+  private TargetType(String name) {
+    if (name == null || name.length() == 0) throw new IllegalArgumentException();
+    if (get(name) != null) throw new IllegalArgumentException();
+    this.name = name.toUpperCase();
+    types.put(name, this);
+  }
+  
+  public String name() {
+    return name;
+  }
+  
+  public String toString() {
+    return name;
+  }
+
+  public int hashCode() {
+    final int PRIME = 31;
+    int result = 1;
+    result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+    return result;
+  }
+
+  public boolean equals(Object obj) {
+    if (this == obj) return true;
+    if (obj == null) return false;
+    if (getClass() != obj.getClass()) return false;
+    final TargetType other = (TargetType) obj;
+    if (name == null) {
+      if (other.name != null) return false;
+    } else if (!name.equals(other.name))
+      return false;
+    return true;
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/Transactional.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,28 @@
+/*
+* 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;
+
+public interface Transactional {
+
+  void start();
+  
+  void end();
+  
+  void compensate(Throwable t);
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/WorkspaceManager.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,30 @@
+/*
+* 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;
+
+public interface WorkspaceManager {
+  
+  CollectionAdapter getCollectionAdapter(RequestContext request);
+  
+  boolean checkTarget(RequestContext request);
+  
+  boolean checkMethod(RequestContext request);
+  
+  String[] getMethods(RequestContext request);
+  
+}

Added: 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=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,118 @@
+/*
+* 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 org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.MediaCollectionAdapter;
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.ProviderHelper;
+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.Transactional;
+import org.apache.abdera.protocol.server.WorkspaceManager;
+
+public abstract class AbstractProvider 
+  implements Provider {
+  
+  public ResponseContext process(
+    RequestContext request) {    
+      WorkspaceManager wm = getWorkspaceManager(request);
+      Target target = request.getTarget();
+      String method = request.getMethod();
+      TargetType type = target.getType();
+      if (!wm.checkTarget(request)) {
+        return ProviderHelper.notfound(
+          request,
+          "Not Found");
+      }
+      if (!wm.checkMethod(request)) {
+        return ProviderHelper.notallowed(
+          request, 
+          "Method Not Allowed", 
+          wm.getMethods(request));
+      }
+      CollectionAdapter adapter = 
+        wm.getCollectionAdapter(request);
+      Transactional transaction = 
+        adapter instanceof Transactional ? 
+          (Transactional)adapter : null;
+      try {
+        if (transaction != null) transaction.start();
+        if (type == TargetType.TYPE_SERVICE) {
+          if (method.equalsIgnoreCase("GET")) {
+            return getServiceDocument(request);
+          }
+        } else if (type == TargetType.TYPE_CATEGORIES) {
+          if (method.equalsIgnoreCase("GET")) {
+            return getCategoriesDocument(request);
+          }
+        } else if (type == TargetType.TYPE_COLLECTION) {
+          if (method.equalsIgnoreCase("GET")) return adapter.getFeed(request);
+          else if (method.equalsIgnoreCase("POST")) {
+            if (ProviderHelper.isAtom(request)) {
+              return adapter.postEntry(request);
+            } else {
+              if (adapter instanceof MediaCollectionAdapter) {
+                return ((MediaCollectionAdapter)adapter).postMedia(request);
+              } else {
+                return ProviderHelper.notsupported(request, "Media Type Not Supported");
+              }
+            }
+          }
+        } else if (type == TargetType.TYPE_ENTRY) {
+          if (method.equalsIgnoreCase("GET")) return adapter.getEntry(request);
+          else if (method.equalsIgnoreCase("PUT")) return adapter.putEntry(request);
+          else if (method.equalsIgnoreCase("DELETE")) return adapter.deleteEntry(request);
+        } else if (type == TargetType.TYPE_MEDIA) {
+          if (adapter instanceof MediaCollectionAdapter) {
+            MediaCollectionAdapter mcadapter = (MediaCollectionAdapter) adapter;
+            if (method.equalsIgnoreCase("GET")) return mcadapter.getMedia(request);
+            else if (method.equalsIgnoreCase("PUT")) return mcadapter.putMedia(request);
+            else if (method.equalsIgnoreCase("DELETE")) return mcadapter.deleteMedia(request);        
+          } else {
+            return ProviderHelper.notsupported(
+              request, 
+              "Media Type Not Supported");
+          }
+        }
+        return adapter.extensionRequest(request);
+      } catch (Throwable e) {
+        if (transaction != null) 
+          transaction.compensate(e);
+        return ProviderHelper.servererror(
+          request, "Server Error", e);
+      } finally {
+        if (transaction != null) 
+          transaction.end();
+      }
+  }
+   
+  protected abstract WorkspaceManager getWorkspaceManager(RequestContext request);
+  
+  protected ResponseContext getServiceDocument(
+    RequestContext request) {
+      return ProviderHelper.notfound(request,"Not Found");
+  }
+  
+  protected ResponseContext getCategoriesDocument(
+    RequestContext request) {
+      return ProviderHelper.notfound(request,"Not Found");
+  }
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,156 @@
+/*
+* 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.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.i18n.text.Localizer;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.parser.ParseException;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.parser.ParserOptions;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ServiceContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.util.AbstractRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public abstract class AbstractRequestContext 
+  extends AbstractRequest
+  implements RequestContext {
+
+  private final static Log log = LogFactory.getLog(AbstractRequestContext.class);
+  
+  protected final ServiceContext context;
+  protected Subject subject;
+  protected Principal principal;
+  protected Target target;
+  protected final String method;
+  protected final IRI requestUri;
+  protected final IRI baseUri;
+  protected Document<?> document;
+  
+  protected AbstractRequestContext(
+    ServiceContext context,
+    String method, 
+    IRI requestUri,
+    IRI baseUri) {
+      this.context = context;
+      this.method = method;
+      this.baseUri = baseUri;
+      this.requestUri = requestUri;
+  }
+  
+  public Abdera getAbdera() {
+    return context.getAbdera();
+  }
+    
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument()
+    throws ParseException, 
+           IOException {
+    log.debug(Localizer.get("PARSING.REQUEST.DOCUMENT"));
+    if (document == null)
+      document = getDocument(getAbdera().getParser());
+    return (Document<T>) document;
+  }
+  
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument(
+    Parser parser)
+      throws ParseException, 
+             IOException {
+    log.debug(Localizer.get("PARSING.REQUEST.DOCUMENT"));
+    if (document == null)
+      document = getDocument(parser, parser.getDefaultParserOptions());
+    return (Document<T>) document;
+  }
+  
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument(
+    ParserOptions options)
+     throws ParseException, 
+            IOException  {
+    log.debug(Localizer.get("PARSING.REQUEST.DOCUMENT"));
+    if (document == null)
+      document = getDocument(getAbdera().getParser(), options);
+    return (Document<T>) document;
+  }
+  
+  @SuppressWarnings("unchecked")
+  public synchronized <T extends Element>Document<T> getDocument(
+    Parser parser, 
+    ParserOptions options) 
+      throws ParseException, 
+             IOException {
+    log.debug(Localizer.get("PARSING.REQUEST.DOCUMENT"));
+    if (document == null) {
+      document = parser.parse(
+        getInputStream(), 
+        getResolvedUri().toString(), 
+        options);
+    } 
+    return (Document<T>) document;
+  }
+  
+  public IRI getBaseUri() {
+    return baseUri;
+  }
+
+  public IRI getResolvedUri() {
+    return baseUri.resolve(getUri());
+  }
+  
+  public String getMethod() {
+    return method;
+  }
+
+  public IRI getUri() {
+    return requestUri;
+  }
+  
+  public Subject getSubject() {
+    return subject;
+  }
+  
+  public Principal getPrincipal() {
+    return principal;
+  }
+
+  public Target getTarget() {
+    return target;
+  }
+  
+  public ServiceContext getServiceContext() {
+    return context;
+  }
+
+  public String getTargetPath() {
+    String uri = getUri().toString();
+    String cpath = getContextPath();
+    return cpath == null ? uri : uri.substring(cpath.length());
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,303 @@
+/*
+* 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera.i18n.text.Localizer;
+import org.apache.abdera.i18n.text.UrlEncoding;
+import org.apache.abdera.i18n.text.CharUtils.Profile;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.util.AbstractResponse;
+import org.apache.abdera.protocol.util.EncodingUtil;
+import org.apache.abdera.util.EntityTag;
+import org.apache.abdera.writer.Writer;
+
+public abstract class AbstractResponseContext
+  extends AbstractResponse
+  implements ResponseContext {
+
+  protected static final String[] EMPTY = new String[0];
+  
+  protected int status = 0;
+  protected String status_text = null;
+  protected Writer writer = null;
+  
+  protected Map<String,Object[]> headers = null;
+
+  public ResponseContext removeHeader(String name) {
+    Map<String,Object[]> headers = getHeaders();
+    headers.remove(name);
+    return this;
+  }
+  
+  public ResponseContext setEncodedHeader(String name, String charset, String value) {
+    return setHeader(name, EncodingUtil.encode(value, charset));
+  }
+  
+  public ResponseContext setEncodedHeader(String name, String charset, String... vals) {
+    Object[] evals = new Object[vals.length];
+    for (int n = 0; n < vals.length; n++) {
+      evals[n] = EncodingUtil.encode(vals[n], charset);
+    }
+    return setHeader(name, evals);
+  }
+  
+  public ResponseContext setEscapedHeader(String name, Profile profile, String value) {
+    return setHeader(name,UrlEncoding.encode(value, profile.filter()));
+  }
+  
+  public ResponseContext setHeader(String name, Object value) {
+    return setHeader(name, new Object[] {value});
+  }
+  
+  public ResponseContext setHeader(String name, Object... vals) {
+    Map<String,Object[]> headers = getHeaders();
+    List<Object> values = new ArrayList<Object>();
+    for (Object value : vals) {
+      values.add(value);
+    }
+    headers.put(name, values.toArray(new Object[values.size()]));
+    return this;
+  }
+  
+  public ResponseContext addEncodedHeader(String name, String charset, String value) {
+    return addHeader(name, EncodingUtil.encode(value, charset));
+  }
+  
+  public ResponseContext addEncodedHeaders(String name, String charset, String... vals) {
+    for (String value : vals) {
+      addHeader(name,EncodingUtil.encode(value, charset));
+    }
+    return this;
+  }
+  
+  public ResponseContext addHeader(String name, Object value) {
+    return addHeaders(name, new Object[] {value});
+  }
+  
+  public ResponseContext addHeaders(String name, Object... vals) {
+    Map<String,Object[]> headers = getHeaders();
+    Object[] values = headers.get(name);
+    List<Object> l = null;
+    if (values == null) {
+      l = new ArrayList<Object>();
+    } else {
+      l = Arrays.asList(values);
+    }
+    for (Object value : vals) {
+      l.add(value);
+    }
+    headers.put(name, l.toArray(new Object[l.size()]));
+    return this;
+  }
+  
+  public Map<String, Object[]> getHeaders() {
+    if (headers == null)
+      headers = new HashMap<String,Object[]>();
+    return headers;
+  }
+    
+  public Date getDateHeader(String name) {
+    Map<String,Object[]> headers = getHeaders();
+    Object[] values = headers.get(name);
+    if (values != null) {
+      for (Object value : values) {
+        if (value instanceof Date) 
+          return (Date)value;
+      }
+    }
+    return null;
+  }
+  
+  public String getHeader(String name) {
+    Map<String,Object[]> headers = getHeaders();
+    Object[] values = headers.get(name);
+    if (values != null && values.length > 0) 
+      return values[0].toString();
+    return null;
+  }
+
+  public Object[] getHeaders(String name) {
+    Map<String,Object[]> headers = getHeaders();
+    return headers.get(name);
+  }
+
+  public String[] getHeaderNames() {
+    Map<String,Object[]> headers = getHeaders();
+    return headers.keySet().toArray(new String[headers.size()]);
+  }
+  
+  private void append(StringBuilder buf, String value) {
+    if (buf.length() > 0) buf.append(", ");
+    buf.append(value);
+  }
+    
+  public String getCacheControl() {
+    StringBuilder buf = new StringBuilder();
+    if (isPublic()) append(buf,"public");
+    if (isPrivate()) append(buf,"private");
+    if (private_headers != null && private_headers.length > 0) {
+      buf.append("=\"");
+      for (String header : private_headers) {
+        append(buf,header);
+      }
+      buf.append("\"");
+    }
+    if (isNoCache()) append(buf,"no-cache");
+    if (nocache_headers != null && nocache_headers.length > 0) {
+      buf.append("=\"");
+      for (String header : nocache_headers) {
+        append(buf,header);
+      }
+      buf.append("\"");
+    }
+    if (isNoStore()) append(buf,"no-store");
+    if (isMustRevalidate()) append(buf,"must-revalidate");
+    if (isNoTransform()) append(buf, "no-transform");
+    if (getMaxAge() != -1) append(buf, "max-age=" + getMaxAge());
+    if (getSMaxAge() != -1) append(buf, "smax-age=" + getMaxAge());
+    return buf.toString();
+  }
+
+  public ResponseContext  setAge(long age) {
+    return age == -1 ?
+        removeHeader("Age") :
+        setHeader("Age", String.valueOf(age));
+  }
+  
+  public ResponseContext  setContentLanguage(String language) {
+    return language == null ?
+        removeHeader("Content-Language") :
+        setHeader("Content-Language",language);
+  }
+
+  public ResponseContext  setContentLength(long length) {
+    return length == -1 ?
+      removeHeader("Content-Length") :
+      setHeader("Content-Length", String.valueOf(length));
+  }
+
+  public ResponseContext  setContentLocation(String uri) {
+    return uri == null ?
+      removeHeader("Content-Location") :
+      setHeader("Content-Location",uri);
+  }
+  
+  public ResponseContext setSlug(String slug) {
+    if (slug == null) {
+      return removeHeader("Slug");
+    }
+    if (slug.indexOf((char)10) > -1 ||
+        slug.indexOf((char)13) > -1)
+      throw new IllegalArgumentException(
+        Localizer.get("SLUG.BAD.CHARACTERS"));
+    return setEscapedHeader("Slug", Profile.ASCIISANSCRLF, slug);
+  }
+  
+  public ResponseContext setContentType(String type) {
+    return setContentType(type,null);
+  }
+  
+  public ResponseContext setContentType(String type, String charset) {
+    if (type == null) {
+      return removeHeader("Content-Type");
+    }
+    try {
+      MimeType mimeType = new MimeType(type);
+      if (charset != null) mimeType.setParameter("charset", charset);
+      return setHeader("Content-Type", mimeType.toString());
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+  
+  public ResponseContext setEntityTag(String etag) {
+    return etag != null ?
+      setEntityTag(new EntityTag(etag)) :
+      removeHeader("ETag");
+  }
+  
+  public ResponseContext  setEntityTag(EntityTag etag) {
+    return etag == null ?
+      removeHeader("ETag") :
+      setHeader("ETag",etag.toString());
+  }
+
+  public ResponseContext  setExpires(Date date) {
+    return date == null ?
+      removeHeader("Expires") :
+      setHeader("Expires",date);
+  }
+  
+  public ResponseContext  setLastModified(Date date) {
+    return date == null ?
+      removeHeader("Last-Modified") :
+      setHeader("Last-Modified",date);
+  }
+
+  public ResponseContext setLocation(String uri) {
+    return uri == null ?
+      removeHeader("Location") :
+      setHeader("Location",uri);
+  }
+  
+  public int getStatus() {
+    return status;
+  }
+  
+  public ResponseContext setStatus(int status) {
+    this.status = status;
+    return this;
+  }
+
+  public String getStatusText() {
+    return status_text;
+  }
+  
+  public ResponseContext setStatusText(String text) {
+    this.status_text = text;
+    return this;
+  }
+
+  public ResponseContext setAllow(String method) {
+    return setHeader("Allow", method);
+  }
+  
+  public ResponseContext setAllow(String... methods) {
+    StringBuilder buf = new StringBuilder();
+    for(String method : methods) {
+      if (buf.length() > 0) buf.append(", ");
+      buf.append(method);
+    }
+    return setAllow(buf.toString());
+  }
+  
+  public ResponseContext setWriter(Writer writer) {
+    this.writer = writer;
+    return this;
+  }
+  
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,79 @@
+/*
+* 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.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.ServiceContext;
+import org.apache.abdera.protocol.server.Target;
+
+import com.ibm.rmi.RequestHandler;
+
+public abstract class AbstractServiceContext 
+  implements ServiceContext {
+
+  protected Abdera abdera;
+  protected Map<String,String> config;
+  protected ItemManager<Provider> providerManager;
+  protected ItemManager<RequestHandler> handlerManager;
+  protected Resolver<Subject> subjectResolver;
+  protected Resolver<Target> targetResolver;
+  
+  public synchronized void init(
+    Abdera abdera, 
+    Map<String,String> config) {
+     this.abdera = abdera;
+     this.config = (config != null) ? config : new HashMap<String,String>();
+  }
+  
+  public Abdera getAbdera() {
+    return abdera;
+  }
+
+  public String getProperty(String name) {
+    return config.get(name);
+  }
+
+  public String[] getPropertyNames() {
+    return config.keySet().toArray(new String[config.size()]);
+  }
+
+  public void setHandlerManager(ItemManager<RequestHandler> handlerManager) {
+    this.handlerManager = handlerManager;
+  }
+
+  public void setProviderManager(ItemManager<Provider> providerManager) {
+    this.providerManager = providerManager;
+  }
+
+  public void setSubjectResolver(Resolver<Subject> subjectResolver) {
+    this.subjectResolver = subjectResolver;
+  }
+
+  public void setTargetResolver(Resolver<Target> targetResolver) {
+    this.targetResolver = targetResolver;
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,45 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.server.Provider;
+
+public abstract class AbstractSingletonProviderManager 
+  implements ItemManager<Provider> {
+
+  protected Provider provider;
+  
+  public Provider get(Request request) {
+    if (provider == null) {
+      synchronized(this) {
+        provider = initProvider();
+      }
+    }
+    return provider;
+  }
+
+  protected abstract Provider initProvider();
+  
+  public void release(Provider provider) {
+    // nothing to release. subclasses could choose to do reference counting
+    // if they want
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,99 @@
+/*
+* 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.util.Iterator;
+
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
+
+public abstract class AbstractTarget 
+  implements Target {
+
+  protected final TargetType type;
+  protected final RequestContext context;
+  
+  public AbstractTarget(
+    TargetType type, 
+    RequestContext context) {
+      this.type = type;
+      this.context = context;
+  }
+
+  public String getIdentity() {
+    return context.getUri().toString();
+  }
+  
+  public String getParameter(String name) {
+    return context.getParameter(name);
+  }
+
+  public String[] getParameterNames() {
+    String[] pn = context.getParameterNames();
+    return (pn != null) ? pn : new String[0];
+  }
+
+  public Iterator<String> iterator() {
+    return java.util.Arrays.asList(getParameterNames()).iterator();
+  }
+
+  public TargetType getType() {
+    return type;
+  }
+ 
+  public RequestContext getRequestContext() {
+    return context;
+  }
+  
+  public String toString() {
+    return getType() + " - " + getIdentity();
+  }
+
+  @Override
+  public int hashCode() {
+    final int PRIME = 31;
+    int result = 1;
+    result = PRIME * result + ((context == null) ? 0 : context.hashCode());
+    result = PRIME * result + ((type == null) ? 0 : type.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    final AbstractTarget other = (AbstractTarget) obj;
+    if (context == null) {
+      if (other.context != null)
+        return false;
+    } else if (!context.equals(other.context))
+      return false;
+    if (type == null) {
+      if (other.type != null)
+        return false;
+    } else if (!type.equals(other.type))
+      return false;
+    return true;
+  }
+
+}

Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java?rev=613765&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceManager.java Sun Jan 20 21:33:46 2008
@@ -0,0 +1,43 @@
+/*
+* 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 org.apache.abdera.protocol.server.ProviderHelper;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.WorkspaceManager;
+
+public abstract class AbstractWorkspaceManager 
+  implements WorkspaceManager {
+  
+  public boolean checkTarget(
+    RequestContext request) {
+      return request.getTarget() != null;
+  }
+  
+  public String[] getMethods(RequestContext request) {
+    return ProviderHelper.getDefaultMethods(request);
+  }
+  
+  public boolean checkMethod(
+    RequestContext request) {
+      return ProviderHelper.defaultCheckMethod(
+        request, 
+        getMethods(request));
+  }
+  
+}



Mime
View raw message