abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [12/49] - in /abdera/abdera2: ./ .settings/ activities/ activities/src/ activities/src/main/ activities/src/main/java/ activities/src/main/java/org/ activities/src/main/java/org/apache/ activities/src/main/java/org/apache/abdera2/ ...
Date Tue, 20 Sep 2011 15:57:20 GMT
Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseResponseContextWrapper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseResponseContextWrapper.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseResponseContextWrapper.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseResponseContextWrapper.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,324 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.text.CharUtils.Profile;
+import org.apache.abdera2.common.http.Authentication;
+import org.apache.abdera2.common.http.CacheControl;
+import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.common.http.Preference;
+import org.apache.abdera2.common.http.ResponseType;
+import org.apache.abdera2.common.http.WebLink;
+
+@SuppressWarnings("unchecked")
+public class BaseResponseContextWrapper implements ResponseContext {
+
+    protected final ResponseContext response;
+
+    public BaseResponseContextWrapper(ResponseContext response) {
+        this.response = response;
+    }
+
+    public <T extends ResponseContext>T addEncodedHeader(String name, String charset, String value) {
+        response.addEncodedHeader(name, charset, value);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T addEncodedHeaders(String name, String charset, String... vals) {
+        response.addEncodedHeaders(name, charset, vals);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T addHeader(String name, Object value) {
+        response.addHeader(name, value);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T addHeaders(String name, Object... vals) {
+        response.addHeaders(name, vals);
+        return (T)this;
+    }
+
+    public boolean hasEntity() {
+        return response.hasEntity();
+    }
+
+    public <T extends ResponseContext>T removeHeader(String name) {
+        response.removeHeader(name);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setAge(long age) {
+        response.setAge(age);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setAllow(String method) {
+        response.setAllow(method);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setAllow(String... methods) {
+        response.setAllow(methods);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setContentLanguage(String language) {
+        response.setContentLanguage(language);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setContentLength(long length) {
+        response.setContentLength(length);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setContentLocation(String uri) {
+        response.setContentLocation(uri);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setContentType(String type) {
+        response.setContentType(type);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setContentType(String type, String charset) {
+        response.setContentType(type, charset);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setEncodedHeader(String name, String charset, String value) {
+        response.setEncodedHeader(name, charset, value);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setEncodedHeader(String name, String charset, String... vals) {
+        response.setEncodedHeader(name, charset, vals);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setEntityTag(String etag) {
+        response.setEntityTag(etag);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setEntityTag(EntityTag etag) {
+        response.setEntityTag(etag);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setEscapedHeader(String name, Profile profile, String value) {
+        response.setEscapedHeader(name, profile, value);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setExpires(Date date) {
+        response.setExpires(date);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setHeader(String name, Object value) {
+        response.setHeader(name, value);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setHeader(String name, Object... vals) {
+        response.setHeader(name, vals);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setLastModified(Date date) {
+        response.setLastModified(date);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setLocation(String uri) {
+        response.setLocation(uri);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setSlug(String slug) {
+        response.setSlug(slug);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setStatus(int status) {
+        response.setStatus(status);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setStatusText(String text) {
+        response.setStatusText(text);
+        return (T)this;
+    }
+
+    public void writeTo(OutputStream out) throws IOException {
+        response.writeTo(out);
+    }
+
+    public void writeTo(java.io.Writer javaWriter) throws IOException {
+        response.writeTo(javaWriter);
+    }
+
+    public long getAge() {
+        return response.getAge();
+    }
+
+    public String getAllow() {
+        return response.getAllow();
+    }
+
+    public long getContentLength() {
+        return response.getContentLength();
+    }
+
+    public EntityTag getEntityTag() {
+        return response.getEntityTag();
+    }
+
+    public Date getExpires() {
+        return response.getExpires();
+    }
+
+    public Date getLastModified() {
+        return response.getLastModified();
+    }
+
+    public IRI getLocation() {
+        return response.getLocation();
+    }
+
+    public int getStatus() {
+        return response.getStatus();
+    }
+
+    public String getStatusText() {
+        return response.getStatusText();
+    }
+
+    public ResponseType getType() {
+        return response.getType();
+    }
+
+    public CacheControl getCacheControl() {
+        return response.getCacheControl();
+    }
+
+    public String getContentLanguage() {
+        return response.getContentLanguage();
+    }
+
+    public IRI getContentLocation() {
+        return response.getContentLocation();
+    }
+
+    public MimeType getContentType() {
+        return response.getContentType();
+    }
+
+    public Date getDateHeader(String name) {
+        return response.getDateHeader(name);
+    }
+
+    public String getDecodedHeader(String name) {
+        return response.getDecodedHeader(name);
+    }
+
+    public Iterable<String> getDecodedHeaders(String name) {
+        return response.getDecodedHeaders(name);
+    }
+    
+    public Iterable<Authentication> getAuthentication() {
+      return response.getAuthentication();
+    }
+
+    public String getHeader(String name) {
+        return response.getHeader(name);
+    }
+
+    public Iterable<String> getHeaderNames() {
+        return response.getHeaderNames();
+    }
+
+    public Iterable<Object> getHeaders(String name) {
+        return response.getHeaders(name);
+    }
+
+    public String getSlug() {
+        return response.getSlug();
+    }
+
+    public boolean isBinary() {
+        return response.isBinary();
+    }
+
+    public <T extends ResponseContext>T setBinary(boolean binary) {
+        response.setBinary(true);
+        return (T)this;
+    }
+
+    public <T extends ResponseContext>T setCacheControl(CacheControl cc) {
+      response.setCacheControl(cc);
+      return (T)this;
+    }
+
+    public <T extends ResponseContext>T setCacheControl(String cc) {
+      response.setCacheControl(cc);
+      return (T)this;
+    }
+
+    public Iterable<WebLink> getWebLinks() {
+      return response.getWebLinks();
+    }
+
+    public Iterable<Preference> getPrefer() {
+      return response.getPrefer();
+    }
+    
+    public Iterable<Preference> getPreferApplied() {
+      return response.getPreferApplied();
+    }
+
+    public <T extends ResponseContext> T setWebLinks(WebLink link,
+        WebLink... links) {
+      response.setWebLinks(link, links);
+      return (T)this;
+    }
+
+    public <T extends ResponseContext> T setPrefer(Preference pref,
+        Preference... prefs) {
+      response.setPrefer(pref, prefs);
+      return (T)this;
+    }
+
+    public <T extends ResponseContext> T setPreferApplied(Preference pref,
+        Preference... prefs) {
+      response.setPreferApplied(pref, prefs);
+      return (T)this;
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseResponseContextWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+
+public class BasicCollectionInfo 
+  implements CollectionInfo, 
+             Serializable {
+
+    private static final long serialVersionUID = 8026455829158149510L;
+
+    private final String title;
+    private final String href;
+    private final String[] accepts;
+
+    public BasicCollectionInfo(String title, String href, String... accepts) {
+        this.title = title;
+        this.accepts = accepts;
+        this.href = href;
+    }
+
+    public String[] getAccepts(RequestContext request) {
+        return accepts;
+    }
+
+    public String getHref(RequestContext request) {
+        return href;
+    }
+
+    public String getTitle(RequestContext request) {
+        return title;
+    }
+
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + Arrays.hashCode(accepts);
+        result = prime * result + ((href == null) ? 0 : href.hashCode());
+        result = prime * result + ((title == null) ? 0 : title.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 BasicCollectionInfo other = (BasicCollectionInfo)obj;
+        if (!Arrays.equals(accepts, other.accepts))
+            return false;
+        if (href == null) {
+            if (other.href != null)
+                return false;
+        } else if (!href.equals(other.href))
+            return false;
+        if (title == null) {
+            if (other.title != null)
+                return false;
+        } else if (!title.equals(other.title))
+            return false;
+        return true;
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,104 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+
+public class BasicWorkspaceInfo
+  implements WorkspaceInfo, 
+             Serializable {
+
+    private static final long serialVersionUID = -8459688584319762878L;
+
+    protected String title;
+    protected Set<CollectionInfo> collections;
+
+    public BasicWorkspaceInfo() {
+    }
+
+    public BasicWorkspaceInfo(String title) {
+        this.title = title;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getTitle(RequestContext request) {
+        return title;
+    }
+
+    public void addCollection(CollectionInfo ci) {
+        getCollections().add(ci);
+    }
+
+    public Collection<CollectionInfo> getCollections(RequestContext request) {
+        return collections;
+    }
+
+    public Set<CollectionInfo> getCollections() {
+        if (collections == null) {
+            collections = new HashSet<CollectionInfo>();
+        }
+
+        return collections;
+    }
+
+    public void setCollections(Set<CollectionInfo> collections) {
+        this.collections = collections;
+    }
+
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((collections == null) ? 0 : collections.hashCode());
+        result = prime * result + ((title == null) ? 0 : title.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 BasicWorkspaceInfo other = (BasicWorkspaceInfo)obj;
+        if (collections == null) {
+            if (other.collections != null)
+                return false;
+        } else if (!collections.equals(other.collections))
+            return false;
+        if (title == null) {
+            if (other.title != null)
+                return false;
+        } else if (!title.equals(other.title))
+            return false;
+        return true;
+    }
+
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionAdapter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionAdapter.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionAdapter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.abdera2.common.protocol;
+
+
+public interface CollectionAdapter {
+
+    /**
+     * Post a new entry to the collection
+     */
+    <S extends ResponseContext>S postItem(RequestContext request);
+
+    /**
+     * Delete an entry from the collection
+     */
+    <S extends ResponseContext>S deleteItem(RequestContext request);
+
+    /**
+     * Get an entry from the collection
+     */
+    <S extends ResponseContext>S getItem(RequestContext request);
+
+    /**
+     * Get metadata for an entry from the collection
+     */
+    <S extends ResponseContext>S headItem(RequestContext request);
+
+    /**
+     * Get options for an entry from the collection
+     */
+    <S extends ResponseContext>S optionsItem(RequestContext request);
+
+    /**
+     * Update an existing entry
+     */
+    <S extends ResponseContext>S putItem(RequestContext request);
+
+    /**
+     * Get the collections Atom feed document
+     */
+    <S extends ResponseContext>S getItemList(RequestContext request);
+
+    /**
+     * Any request that is not covered by the postEntry, deleteEntry, etc methods will be passed on to the
+     * extensionRequest method. This provides an Adapter with the ability to support Atompub protocol extensions.
+     */
+    <S extends ResponseContext>S extensionRequest(RequestContext request);
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionInfo.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionInfo.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionInfo.java Tue Sep 20 15:56:46 2011
@@ -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.abdera2.common.protocol;
+
+
+/**
+ * Metadata interface used by WorkspaceManager and Provider implementations to construct Atompub Service Documents. The
+ * CollectionInfo interface provides information used to construct an app:collection element
+ */
+public interface CollectionInfo {
+
+    /**
+     * Get the value of the app:collection element's href attribute. This must not be null
+     */
+    String getHref(RequestContext request);
+
+    /**
+     * Get the value of the app:collection element's atom:title element. This assumes that the title will be
+     * type="text". This must not be null;
+     */
+    String getTitle(RequestContext request);
+
+    /**
+     * Returns an array of MIME media types for the app:collection element's app:accept elements. These tell a client
+     * which media types the collection will accept on a POST
+     */
+    String[] getAccepts(RequestContext request);
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionRequestProcessor.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionRequestProcessor.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionRequestProcessor.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionRequestProcessor.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.abdera2.common.protocol;
+
+
+/**
+ * {@link org.apache.AtompubRequestProcessor.protocol.server.RequestProcessor} implementation which processes requests for collection
+ * documents.
+ */
+@SuppressWarnings("unchecked")
+public abstract class CollectionRequestProcessor
+  implements RequestProcessor {
+
+    protected abstract boolean isAcceptableItemType(RequestContext context);
+  
+    public <S extends ResponseContext>S process(
+        RequestContext context,
+        WorkspaceManager workspaceManager,
+        CollectionAdapter collectionAdapter) {
+        if (collectionAdapter == null) {
+            return (S)ProviderHelper.notfound(context);
+        } else {
+            return this.processCollection(context, collectionAdapter);
+        }
+    }
+
+    private <S extends ResponseContext>S processCollection(
+        RequestContext context, 
+        CollectionAdapter adapter) {
+        String method = context.getMethod();
+        if (method.equalsIgnoreCase("GET")) {
+            return adapter.getItemList(context);
+        } else if (method.equalsIgnoreCase("POST")) {
+            return (S)(isAcceptableItemType(context) ? adapter.postItem(context)
+                : adapter instanceof MediaCollectionAdapter ? ((MediaCollectionAdapter)adapter).postMedia(context)
+                    : ProviderHelper.notallowed(context));
+        } else {
+            return null;
+        }
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionRequestProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,91 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.DeflaterOutputStream;
+
+import org.apache.abdera2.common.http.QualityHelper;
+import org.apache.abdera2.common.http.QualityHelper.QToken;
+import org.apache.abdera2.common.io.Compression;
+import org.apache.abdera2.common.io.Compression.CompressionCodec;
+
+/**
+ * Abdera Filter implementation that selectively applies compression to the response payload
+ */
+public class CompressionFilter implements Filter {
+
+    @SuppressWarnings("unchecked")
+    public <S extends ResponseContext>S filter(RequestContext request, FilterChain chain) {
+        String encoding = request.getHeader("Accept-Encoding");
+        QToken[] encodings = encoding != null ? QualityHelper.orderByQ(encoding) : new QToken[0];
+        for (QToken enc : encodings) {
+            try {
+                CompressionCodec codec = CompressionCodec.valueOf(enc.token().toUpperCase());
+                return (S)new CompressingResponseContextWrapper(chain.next(request), codec);
+            } catch (Exception e) {
+            }
+        }
+        return chain.next(request);
+    }
+
+    /**
+     * A HttpServletResponseWrapper implementation that applies GZip or Deflate compression to response output.
+     */
+    public static class CompressingResponseContextWrapper extends BaseResponseContextWrapper {
+
+        private final CompressionCodec codec;
+
+        public CompressingResponseContextWrapper(ResponseContext response, CompressionCodec codec) {
+            super(response);
+            this.codec = codec;
+        }
+
+        private OutputStream wrap(OutputStream out) {
+            return new CompressingOutputStream(codec, out);
+        }
+
+        public void writeTo(OutputStream out) throws IOException {
+            super.writeTo(wrap(out));
+            out.flush();
+        }
+    }
+
+    public static class CompressingOutputStream extends FilterOutputStream {
+
+        public CompressingOutputStream(CompressionCodec codec, OutputStream out) {
+            super(initStream(codec, out));
+        }
+
+        public CompressingOutputStream(DeflaterOutputStream dout) {
+            super(dout);
+        }
+
+        private static OutputStream initStream(CompressionCodec codec, OutputStream out) {
+            try {
+                return Compression.wrap(out, new CompressionCodec[] {codec});
+            } catch (Exception e) {
+                return out;
+            }
+        }
+
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/DefaultWorkspaceManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/DefaultWorkspaceManager.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/DefaultWorkspaceManager.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/DefaultWorkspaceManager.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import org.apache.abdera2.common.protocol.RequestContext.Scope;
+
+
+/**
+ * The DefaultWorkspaceManager is used by the DefaultProvider
+ */
+public class DefaultWorkspaceManager 
+  extends AbstractWorkspaceManager  {
+    // URI reserved delimiter characters (gen-delims) from RFC 3986 section 2.2
+    private static final String URI_GEN_DELIMS = ":/?#[]@";
+    public CollectionAdapter getCollectionAdapter(RequestContext request) {
+        String path = request.getContextPath() + request.getTargetPath();
+
+        // Typically this happens when a Resolver wants to override the CollectionAdapter being used
+        CollectionAdapter ca = 
+          (CollectionAdapter)request.getAttribute(
+            Scope.REQUEST, AbstractWorkspaceManager.COLLECTION_ADAPTER_ATTRIBUTE);
+        if (ca != null) {
+            return ca;
+        }
+        for (WorkspaceInfo wi : workspaces) {
+            for (CollectionInfo ci : wi.getCollections(request)) {
+                String href = ci.getHref(request);
+                if (path.equals(href) || (href != null && path.startsWith(href) && URI_GEN_DELIMS.contains(path
+                    .substring(href.length(), href.length() + 1)))) {
+                    return (CollectionAdapter)ci;
+                }
+            }
+        }
+
+        return null;
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/DefaultWorkspaceManager.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/DefaultWorkspaceManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EmptyResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EmptyResponseContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EmptyResponseContext.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EmptyResponseContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.io.IOException;
+
+public final class EmptyResponseContext extends SimpleResponseContext {
+
+    public EmptyResponseContext(int status) {
+        setStatus(status);
+    }
+
+    public EmptyResponseContext(int status, String text) {
+        setStatus(status);
+        setStatusText(text);
+    }
+
+    protected void writeEntity(java.io.Writer writer) throws IOException {
+    }
+
+    public boolean hasEntity() {
+        return false;
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EmptyResponseContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EntryRequestProcessor.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EntryRequestProcessor.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EntryRequestProcessor.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EntryRequestProcessor.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.abdera2.common.protocol;
+
+
+/**
+ * {@link org.apache.AtompubRequestProcessor.protocol.server.RequestProcessor} implementation which processes requests for entry
+ * documents.
+ */
+public class EntryRequestProcessor
+    implements RequestProcessor {
+  
+    @SuppressWarnings("unchecked")
+    public <S extends ResponseContext>S process(RequestContext context,
+                     WorkspaceManager workspaceManager,
+                     CollectionAdapter collectionAdapter) {
+        if (collectionAdapter == null) {
+            return (S)ProviderHelper.notfound(context);
+        } else {
+            return this.processEntry(context, collectionAdapter);
+        }
+    }
+
+    public <S extends ResponseContext>S processEntry(
+        RequestContext context, 
+        CollectionAdapter adapter) {
+        String method = context.getMethod();
+        if (method.equalsIgnoreCase("GET")) {
+            return adapter.getItem(context);
+        } else if (method.equalsIgnoreCase("POST")) {
+            return adapter.postItem(context);
+        } else if (method.equalsIgnoreCase("PUT")) {
+            return adapter.putItem(context);
+        } else if (method.equalsIgnoreCase("DELETE")) {
+            return adapter.deleteItem(context);
+        } else if (method.equalsIgnoreCase("HEAD")) {
+            return adapter.headItem(context);
+        } else if (method.equalsIgnoreCase("OPTIONS")) {
+            return adapter.optionsItem(context);
+        } else if (method.equalsIgnoreCase("PATCH") && adapter instanceof PatchAdapter) {
+            return ((PatchAdapter)adapter).patchItem(context);
+        } else {
+            return null;
+        }
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EntryRequestProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,36 @@
+/*
+ * 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.abdera2.common.protocol;
+
+
+/**
+ * Filters are invoked by AbderaServlet immediately before passing the request off to the Provider for processing The
+ * filters use a model generally identical to that of Servlet Filters, with each filter forwarding the request on to the
+ * next filter in the chain.
+ * 
+ * @author jasnell
+ */
+public interface Filter {
+
+    /**
+     * Process the filter request. The filter must call chain.next(request) to pass the request on to the next filter or
+     * the provider.
+     */
+  <S extends ResponseContext>S filter(RequestContext request, FilterChain chain);
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/FilterChain.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/FilterChain.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/FilterChain.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/FilterChain.java Tue Sep 20 15:56:46 2011
@@ -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.abdera2.common.protocol;
+
+import java.util.Iterator;
+
+
+public final class FilterChain {
+
+    private final Iterator<Filter> filters;
+    private final Provider provider;
+
+    public FilterChain(Provider provider, RequestContext request) {
+        this.provider = provider;
+        this.filters = provider.getFilters(request).iterator();
+    }
+
+    /**
+     * Invoke the next filter in the chain. If there are no more filters in the chain, pass the request context on to
+     * the Provider for processing.
+     */
+    @SuppressWarnings("unchecked")
+    public <S extends ResponseContext>S next(RequestContext request) {
+        return (S)(filters.hasNext() ? 
+            filters.next().filter(request, this) : 
+            provider.process(request));
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/FilterChain.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaCollectionAdapter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaCollectionAdapter.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaCollectionAdapter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.abdera2.common.protocol;
+
+
+/**
+ * Extends CollectionAdapter with methods specific to the handling of Atompub Media Link Entries
+ */
+public interface MediaCollectionAdapter
+  extends CollectionAdapter  {
+
+    /**
+     * Add a new media resource to the collection, resulting in the creation of a new Media Link Entry.
+     */
+  <S extends ResponseContext>S postMedia(RequestContext request);
+
+    /**
+     * Delete a media resource from the collection
+     */
+  <S extends ResponseContext>S deleteMedia(RequestContext request);
+
+    /**
+     * Get a media resource
+     */
+  <S extends ResponseContext>S getMedia(RequestContext request);
+
+    /**
+     * Get metdata for a media resource
+     */
+  <S extends ResponseContext>S headMedia(RequestContext request);
+
+    /**
+     * Get a media resource's options.
+     */
+  <S extends ResponseContext>S optionsMedia(RequestContext request);
+
+    /**
+     * Update a media resource
+     */
+  <S extends ResponseContext>S putMedia(RequestContext request);
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaCollectionAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaRequestProcessor.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaRequestProcessor.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaRequestProcessor.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaRequestProcessor.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,67 @@
+/*
+ * 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.abdera2.common.protocol;
+
+
+/**
+ * {@link org.apache.AtompubRequestProcessor.protocol.server.RequestProcessor} implementation which processes requests for media
+ * documents.
+ */
+@SuppressWarnings("unchecked")
+public class MediaRequestProcessor
+    implements RequestProcessor {
+
+    public <S extends ResponseContext>S process(
+        RequestContext context,
+        WorkspaceManager workspaceManager,
+        CollectionAdapter collectionAdapter) {
+        if (collectionAdapter == null) {
+            return (S)ProviderHelper.notfound(context);
+        } else {
+            return this.processMedia(context, collectionAdapter);
+        }
+    }
+
+    public <S extends ResponseContext>S processMedia(
+        RequestContext context, 
+        CollectionAdapter adapter) {
+        String method = context.getMethod();
+        if (adapter instanceof MediaCollectionAdapter) {
+            MediaCollectionAdapter mcadapter = (MediaCollectionAdapter)adapter;
+            if (method.equalsIgnoreCase("GET")) {
+                return mcadapter.getMedia(context);
+            } else if (method.equalsIgnoreCase("POST")) {
+                return mcadapter.postMedia(context);
+            } else if (method.equalsIgnoreCase("PUT")) {
+                return mcadapter.putMedia(context);
+            } else if (method.equalsIgnoreCase("DELETE")) {
+                return mcadapter.deleteMedia(context);
+            } else if (method.equalsIgnoreCase("HEAD")) {
+                return mcadapter.headMedia(context);
+            } else if (method.equalsIgnoreCase("OPTIONS")) {
+                return mcadapter.optionsMedia(context);
+            } else if (method.equalsIgnoreCase("PATCH") && mcadapter instanceof PatchMediaAdapter) {
+                return ((PatchMediaAdapter)mcadapter).patchMedia(context);
+            } else {
+                return null;
+            }
+        } else {
+            return (S)ProviderHelper.notallowed(context);
+        }
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaRequestProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaResponseContext.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaResponseContext.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaResponseContext.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,138 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.util.Date;
+
+import org.apache.abdera2.common.http.EntityTag;
+
+/**
+ * ResponseContext implementation for arbitrary media resources
+ */
+public class MediaResponseContext extends SimpleResponseContext {
+
+    private InputStream in;
+    // JIRA: https://issues.apache.org/jira/browse/ABDERA-248
+    private boolean autoclose = true;
+
+    public MediaResponseContext(InputStream in, EntityTag etag, int status, boolean autoclose) {
+      this.in = in;
+      this.status = status;
+      this.autoclose = false;
+      setEntityTag(etag);
+    }
+    
+    public MediaResponseContext(InputStream in, EntityTag etag, int status) {
+        this(in,etag,status,true);
+    }
+
+    public MediaResponseContext(InputStream in, int status, boolean autoclose) {
+      this.in = in;
+      this.status = status;
+      this.autoclose = autoclose;
+    }
+    
+    public MediaResponseContext(InputStream in, int status) {
+        this(in,status,true);
+    }
+
+    public MediaResponseContext(InputStream in, Date lastmodified, int status, boolean autoclose) {
+      this.in = in;
+      this.status = status;
+      this.autoclose = autoclose;
+      setLastModified(lastmodified);
+    }
+    
+    public MediaResponseContext(InputStream in, Date lastmodified, int status) {
+        this(in,lastmodified,status,true);
+    }
+
+    public MediaResponseContext(byte[] bytes, int status) {
+        this(new ByteArrayInputStream(bytes), status);
+    }
+
+    public MediaResponseContext(byte[] bytes, Date lastmodified, int status) {
+        this(new ByteArrayInputStream(bytes), lastmodified, status);
+    }
+
+    public MediaResponseContext(byte[] bytes, EntityTag etag, int status) {
+        this(new ByteArrayInputStream(bytes), etag, status);
+    }
+
+    public MediaResponseContext(ReadableByteChannel channel, int status, boolean autoclose) {
+      this(Channels.newInputStream(channel), status, autoclose);
+    }
+    
+    public MediaResponseContext(ReadableByteChannel channel, int status) {
+        this(channel,status,true);
+    }
+
+    public MediaResponseContext(ReadableByteChannel channel, Date lastmodified, int status, boolean autoclose) {
+      this(Channels.newInputStream(channel), lastmodified,status,autoclose);
+    }
+    
+    public MediaResponseContext(ReadableByteChannel channel, Date lastmodified, int status) {
+        this(channel, lastmodified, status, true);
+    }
+
+    public MediaResponseContext(ReadableByteChannel channel, EntityTag etag, int status, boolean autoclose) {
+      this(Channels.newInputStream(channel), etag,status,autoclose);
+    }
+    
+    public MediaResponseContext(ReadableByteChannel channel, EntityTag etag, int status) {
+        this(channel, etag, status, true);
+    }
+
+    public boolean hasEntity() {
+        return in != null;
+    }
+
+    public void writeTo(OutputStream out) throws IOException {
+        if (hasEntity()) {
+            if (in != null) {
+                byte[] buf = new byte[500];
+                int r = -1;
+                while ((r = in.read(buf)) != -1)
+                    out.write(buf, 0, r);
+                if (autoclose)
+                  in.close();
+            }
+        }
+    }
+
+    protected void writeEntity(Writer out) throws IOException {
+        if (in != null) {
+            InputStreamReader rdr = new InputStreamReader(in);
+            char[] buf = new char[500];
+            int r = -1;
+            while ((r = rdr.read(buf)) != -1)
+                out.write(buf, 0, r);
+            if (autoclose)
+              rdr.close();
+        }
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaResponseContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Message.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Message.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Message.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Message.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,111 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.util.Date;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera2.common.http.Authentication;
+import org.apache.abdera2.common.http.CacheControl;
+import org.apache.abdera2.common.http.Preference;
+import org.apache.abdera2.common.http.WebLink;
+import org.apache.abdera2.common.iri.IRI;
+
+/**
+ * A protocol message. This is used as the basis for both request and response objects in order to provide a consistent
+ * interface.
+ */
+public interface Message {
+
+    /**
+     * Get the value of the specified header
+     */
+    String getHeader(String name);
+
+    /**
+     * Get the decoded value of a RFC 2047 header
+     */
+    String getDecodedHeader(String name);
+
+    /**
+     * Return multiple values for the specified header
+     */
+    Iterable<Object> getHeaders(String name);
+
+    /**
+     * Return multiple decoded values for the specified header
+     */
+    Iterable<String> getDecodedHeaders(String name);
+
+    /**
+     * Return a listing of header names
+     */
+    Iterable<String> getHeaderNames();
+
+    /**
+     * Return the value of the Slug header
+     */
+    String getSlug();
+
+    /**
+     * Return the value of the Content-Type header
+     */
+    MimeType getContentType();
+
+    /**
+     * Return the value of the Content-Location header
+     */
+    IRI getContentLocation();
+
+    /**
+     * Return the value of the Content-Language header
+     */
+    String getContentLanguage();
+
+    /**
+     * Return the value of a Date header
+     */
+    Date getDateHeader(String name);
+
+    /**
+     * Return the Cache Control Data
+     */
+    CacheControl getCacheControl();
+    
+    /**
+     * Return the Authentication Data (WWW-Authentication or Authorization)
+     * @return
+     */
+    Iterable<Authentication> getAuthentication();
+
+    /**
+     * Return the Link header
+     */
+    Iterable<WebLink> getWebLinks();
+    
+    /**
+     * Return the Prefer header
+     */
+    Iterable<Preference> getPrefer();
+    
+    /**
+     * Return the Applied Preferences
+     */
+    Iterable<Preference> getPreferApplied();
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Message.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.util.Arrays;
+
+
+/**
+ * Abdera Filter implementation that supports the use of the X-HTTP-Method-Override header used by GData.
+ */
+@SuppressWarnings({ "unchecked"})
+public class MethodOverrideFilter implements Filter {
+
+    private String[] methods;
+
+    public MethodOverrideFilter() {
+        this("DELETE", "PUT", "PATCH");
+    }
+
+    public MethodOverrideFilter(String... methods) {
+        setMethods(methods);
+    }
+
+    public String[] getMethods() {
+        return methods;
+    }
+
+    public void setMethods(String... methods) {
+        this.methods = methods;
+        Arrays.sort(methods);
+    }
+
+    public <S extends ResponseContext>S filter(RequestContext request, FilterChain chain) {
+        return (S)chain.next(new MethodOverrideRequestContext(request));
+    }
+
+    private class MethodOverrideRequestContext extends BaseRequestContextWrapper {
+
+        private final String method;
+
+        public MethodOverrideRequestContext(RequestContext request) {
+            super(request);
+            String method = super.getMethod();
+            String xheader = getHeader("X-HTTP-Method-Override");
+            if (xheader == null)
+                xheader = getHeader("X-Method-Override");
+            if (xheader != null)
+                xheader = xheader.toUpperCase().trim();
+            if (method.equals("POST") && xheader != null && Arrays.binarySearch(methods, xheader) > -1) {
+                method = xheader;
+            }
+            this.method = method;
+        }
+
+        public String getMethod() {
+            return method;
+        }
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchAdapter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchAdapter.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchAdapter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,11 @@
+package org.apache.abdera2.common.protocol;
+
+public interface PatchAdapter 
+  extends CollectionAdapter {
+
+  /**
+   * Post a new entry to the collection
+   */
+  <S extends ResponseContext>S patchItem(RequestContext request);
+  
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchMediaAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchMediaAdapter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchMediaAdapter.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchMediaAdapter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,11 @@
+package org.apache.abdera2.common.protocol;
+
+public interface PatchMediaAdapter 
+  extends MediaCollectionAdapter {
+
+  /**
+   * Post a new entry to the collection
+   */
+  <S extends ResponseContext>S patchMedia(RequestContext request);
+  
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchMediaAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.abdera2.common.protocol;
+
+public class ProtocolException 
+  extends RuntimeException {
+
+    private static final long serialVersionUID = 1017447143200419489L;
+    private final int code;
+
+    public ProtocolException(int code, String message) {
+        super(String.format("%d::%s",code,message));
+        this.code = code;
+    }
+
+    @Override
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + code;
+      return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      ProtocolException other = (ProtocolException) obj;
+      if (code != other.code)
+        return false;
+      return true;
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProtocolException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.util.Map;
+
+import javax.security.auth.Subject;
+
+/**
+ * Providers are responsible for processing all requests to the Atompub server.<br>
+ * Actual request processing is delegated to {@link AtompubRequestProcessor} implementations, depending on the request
+ * {@link TargetType}.
+ */
+@SuppressWarnings("rawtypes")
+public interface Provider
+  extends TargetBuilder {
+
+    /**
+     * Initialize the Provider.
+     */
+    void init(Map<String, String> properties);
+
+    /**
+     * Get the specified property
+     */
+    String getProperty(String name);
+    
+    /**
+     * Return a listing of all available properties
+     */
+    Iterable<String> getPropertyNames();
+
+    /**
+     * Resolve the subject using the Provider's Subject Resolver
+     */
+    Subject resolveSubject(RequestContext request);
+
+    /**
+     * Resolve the target using the Provider's Target Resolver
+     */
+    Target resolveTarget(RequestContext request);
+
+    /**
+     * Process the request
+     */
+    <S extends ResponseContext>S process(RequestContext request);
+
+    /**
+     * Return the listing of filters for this request
+     */
+    Iterable<Filter> getFilters(RequestContext request);
+
+    <S extends ResponseContext>S createErrorResponse(int code, String message, Throwable t);
+    
+    /**
+     * Set a map of {@link AtompubRequestProcessor}s to register on this provider, overriding already registered ones.
+     */
+    void setRequestProcessors(Map<TargetType, RequestProcessor> requestProcessors);
+
+    /**
+     * Add a map of {@link AtompubRequestProcessor}s to register on this provider, without overriding already registered ones.
+     */
+    void addRequestProcessors(Map<TargetType, RequestProcessor> requestProcessors);
+
+    /**
+     * Return a map of registered {@link AtompubRequestProcessor}s with related {@link TargetType}.
+     */
+    Map<TargetType, RequestProcessor> getRequestProcessors();
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProviderHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProviderHelper.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProviderHelper.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProviderHelper.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,325 @@
+/*
+ * 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.abdera2.common.protocol;
+
+import java.util.Date;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera2.common.Localizer;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.text.Slug;
+import org.apache.abdera2.common.http.QualityHelper;
+import org.apache.abdera2.common.http.QualityHelper.QToken;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ProviderHelper {
+    public 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 ResponseContext createErrorResponse(Provider provider, final int code, final String message) {
+        return createErrorResponse(provider, code, message, null);
+    }
+
+    /**
+     * Returns an Error document based on the StreamWriter
+     */
+    public static ResponseContext createErrorResponse(Provider provider,
+                                                              final int code,
+                                                              final String message,
+                                                              final Throwable t) {
+        return (ResponseContext)provider.createErrorResponse(code, message, t);
+    }
+
+    /**
+     * Return a server error
+     */
+    public static ResponseContext servererror(RequestContext request, String reason, Throwable t) {
+        log.info(Localizer.get("SERVER_ERROR"), t);
+        return createErrorResponse(request.getProvider(), 500, reason, t);
+    }
+
+    /**
+     * Return a server error
+     */
+    public static  ResponseContext servererror(RequestContext request, Throwable t) {;
+        return servererror(request, "Server Error", t);
+    }
+
+    /**
+     * Return an unauthorized error
+     */
+    public static  ResponseContext unauthorized(RequestContext request, String reason) {
+        log.debug(Localizer.get("UNAUTHORIZED"));
+        return createErrorResponse(request.getProvider(), 401, reason);
+    }
+
+    public static  ResponseContext unauthorized(RequestContext request) {
+        return unauthorized(request, "Unauthorized");
+    }
+
+    /**
+     * Return an unauthorized error
+     */
+    public static  ResponseContext forbidden(RequestContext request, String reason) {
+        log.debug(Localizer.get("FORBIDDEN"));
+        return createErrorResponse(request.getProvider(), 403, reason);
+    }
+
+    public static  ResponseContext forbidden(RequestContext request) {
+        return forbidden(request, "Forbidden");
+    }
+
+    /**
+     * Return a 204 No Content response
+     */
+    public static ResponseContext nocontent(String reason) {
+        return new EmptyResponseContext(204, reason);
+    }
+
+    public static ResponseContext nocontent() {
+        return nocontent("Not Content");
+    }
+
+    /**
+     * Return a 404 not found error
+     */
+    public static  ResponseContext notfound(RequestContext request, String reason) {
+        log.debug(Localizer.get("UNKNOWN"));
+        return createErrorResponse(request.getProvider(), 404, reason);
+    }
+
+    public static  ResponseContext notfound(RequestContext request) {
+        return notfound(request, "Not Found");
+    }
+
+    /**
+     * Return a 405 method not allowed error
+     */
+    public static  ResponseContext notallowed(RequestContext request, String reason, String... methods) {
+        log.debug(Localizer.get("NOT.ALLOWED"));
+        ResponseContext resp = createErrorResponse(request.getProvider(), 405, reason);
+        resp.setAllow(methods);
+        return resp;
+    }
+
+    public static  ResponseContext notallowed(RequestContext request, String... methods) {
+        return notallowed(request, "Method Not Allowed", methods);
+    }
+
+    public static  ResponseContext notallowed(RequestContext request) {
+        return notallowed(request, getDefaultMethods(request));
+    }
+
+    /**
+     * Return a 400 bad request error
+     */
+    public static  ResponseContext badrequest(RequestContext request, String reason) {
+        log.debug(Localizer.get("BAD.REQUEST"));
+        return createErrorResponse(request.getProvider(), 400, reason);
+    }
+
+    public static  ResponseContext badrequest(RequestContext request) {
+        return badrequest(request, "Bad Request");
+    }
+
+    /**
+     * Return a 409 conflict error
+     */
+    public static  ResponseContext conflict(RequestContext request, String reason) {
+        log.debug(Localizer.get("CONFLICT"));
+        return createErrorResponse(request.getProvider(), 409, reason);
+    }
+
+    public static  ResponseContext conflict(RequestContext request) {
+        return conflict(request, "Conflict");
+    }
+
+    /**
+     * Return a service unavailable error
+     */
+    public static  ResponseContext unavailable(RequestContext request, String reason) {
+        log.debug(Localizer.get("UNAVAILABLE"));
+        return createErrorResponse(request.getProvider(), 503, reason);
+    }
+
+    public static  ResponseContext unavailable(RequestContext request) {
+        return unavailable(request, "Service Unavailable");
+    }
+
+    public static  ResponseContext notmodified(RequestContext request, String reason) {
+        log.debug(Localizer.get("NOT.MODIFIED"));
+        return new EmptyResponseContext(304, reason);
+    }
+
+    public static  ResponseContext notmodified(RequestContext request) {
+        return notmodified(request, "Not Modified");
+    }
+
+    public static  ResponseContext preconditionfailed(RequestContext request, String reason) {
+        log.debug(Localizer.get("PRECONDITION.FAILED"));
+        return createErrorResponse(request.getProvider(), 412, reason);
+    }
+
+    public static  ResponseContext preconditionfailed(RequestContext request) {
+        return preconditionfailed(request, "Precondition Failed");
+    }
+
+    /**
+     * 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.getProvider(), 415, reason);
+    }
+
+    public static  ResponseContext notsupported(RequestContext request) {
+        return notsupported(request, "Media Type Not Supported");
+    }
+
+    /**
+     * Return a 423 locked error
+     */
+    public static  ResponseContext locked(RequestContext request, String reason) {
+        log.debug(Localizer.get("LOCKED"));
+        return createErrorResponse(request.getProvider(), 423, reason);
+    }
+
+    public static  ResponseContext locked(RequestContext request) {
+        return locked(request, "Locked");
+    }
+
+    /**
+     * 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 = Slug.create(slug).toString();
+        log.debug(Localizer.sprintf("SLUG.SANITIZED", slug, sanitized));
+        return sanitized;
+    }
+
+    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);
+    }
+
+    public static String[] getAcceptableTypes(RequestContext request) {
+        String accept = request.getAccept();
+        QToken[] tokens = QualityHelper.orderByQ(accept);
+        String[] res = new String[tokens.length];
+        for (int n = 0; n < tokens.length; n++)
+          res[n] = tokens[n].token();
+        return res;
+    }
+
+    public static boolean isPreferred(RequestContext request, String s1, String s2) {
+        return isPreferred(getAcceptableTypes(request), s1, s2);
+    }
+
+    public static boolean isPreferred(String[] accepts, String s1, String s2) {
+        int i1 = accepts.length, i2 = accepts.length;
+        for (int n = 0; n < accepts.length; n++) {
+            if (MimeTypeHelper.isMatch(s1, accepts[n])) {
+                i1 = n;
+                break;
+            }
+        }
+        for (int n = 0; n < accepts.length; n++) {
+            if (MimeTypeHelper.isMatch(s2, accepts[n])) {
+                i2 = n;
+                break;
+            }
+        }
+        return i1 < i2;
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProviderHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message