Return-Path: X-Original-To: apmail-abdera-commits-archive@www.apache.org Delivered-To: apmail-abdera-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 91D079BFA for ; Wed, 1 Feb 2012 17:55:59 +0000 (UTC) Received: (qmail 99771 invoked by uid 500); 1 Feb 2012 17:55:56 -0000 Delivered-To: apmail-abdera-commits-archive@abdera.apache.org Received: (qmail 99726 invoked by uid 500); 1 Feb 2012 17:55:56 -0000 Mailing-List: contact commits-help@abdera.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@abdera.apache.org Delivered-To: mailing list commits@abdera.apache.org Received: (qmail 99656 invoked by uid 99); 1 Feb 2012 17:55:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Feb 2012 17:55:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Feb 2012 17:55:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 230CD2388A29 for ; Wed, 1 Feb 2012 17:55:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1239237 [2/12] - in /abdera/abdera2-server: ./ .settings/ etc/ examples/ examples/src/ examples/src/main/ examples/src/main/java/ examples/src/main/java/org/ examples/src/main/java/org/apache/ examples/src/main/java/org/apache/abdera2/ exa... Date: Wed, 01 Feb 2012 17:55:02 -0000 To: commits@abdera.apache.org From: jmsnell@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120201175512.230CD2388A29@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: abdera/abdera2-server/pom.xml URL: http://svn.apache.org/viewvc/abdera/abdera2-server/pom.xml?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/pom.xml (added) +++ abdera/abdera2-server/pom.xml Wed Feb 1 17:54:54 2012 @@ -0,0 +1,789 @@ + + + 4.0.0 + org.apache.abdera2 + abdera2-server-project + pom + Apache Abdera2 - Server + 2.0-SNAPSHOT + Atom Specification Implementation + 2006 + http://abdera.apache.org + + + Apache Software Foundation + http://www.apache.org/ + + + + JIRA + https://issues.apache.org/jira/browse/ABDERA + + + + + Abdera Developer List + dev-subscribe@abdera.apache.org + dev-unsubscribe@abdera.apache.org + dev@abdera.apache.org + http://mail-archives.apache.org/mod_mbox/abdera-dev/ + + + Abdera User List + user-subscribe@abdera.apache.org + user-unsubscribe@abdera.apache.org + user@abdera.apache.org + http://mail-archives.apache.org/mod_mbox/abdera-user/ + + + Abdera Source Control List + commits-subscribe@abdera.apache.org + commits-unsubscribe@abdera.apache.org + http://mail-archives.apache.org/mod_mbox/abdera-commits/ + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + scm:svn:http://svn.apache.org/repos/asf/abdera/abdera2-server + scm:svn:https://svn.apache.org/repos/asf/abdera/abdera2-server + http://svn.apache.org/repos/asf/abdera/abdera2-server + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.7 + + 1.5 + + http://java.sun.com/j2se/1.5.0/docs/api/ + + true + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.2 + + true + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.6 + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.4 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + ${project.name} + The Apache Software Foundation + ${project.version} + ${project.name} + org.apache + The Apache Software Foundation + ${project.version} + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.1 + + https://svn.apache.org/repos/asf/abdera/java/tags + false + clean install + deploy + -Pdeploy + true + + + + + maven-remote-resources-plugin + 1.0 + + + compile + + process + + + + org.apache:apache-jar-resource-bundle:1.3 + + + ${topDir}/etc/notice-supplements.xml + + + Apache Abdera2 + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.4 + + + + clean + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + verify + + jar + + + + + + + org.apache.felix + maven-bundle-plugin + 2.1.0 + true + true + + + ${abdera.osgi.exports} + ${abdera.osgi.imports} + ${abdera.osgi.embed.dependencies} + <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@))) + + + ${project.version} + + + + + generate-sources + + cleanVersions + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.6 + + + **/*TestSuite* + **/*$* + **/TestAdapter* + **/TestChannelServlet* + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.1 + + + sign-artifacts + verify + + sign + + + + + + + org.apache.rat + apache-rat-plugin + 0.6 + + + + com.google.code.maven-license-plugin + maven-license-plugin + 1.4.0 + + ${basedir} +
${basedir}/etc/license.txt
+ false + true +
+
+
+
+ +
+ + + + java6 + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.7 + + 1.6 + + http://java.sun.com/javase/6/docs/api/ + + true + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + + + + deploy + + distribution + + + + no-online-tests + + + offline-tests + false + + + + + + maven-surefire-plugin + + + **/*TestSuite* + **/*$* + **/*TestAdapter* + **/FeedValidatorTest.java + **/DSigThirdPartyVerifyTest.java + **/AtomConformanceTest.java + **/TestChannelServlet* + + + + + + + + + + + java.net2 + Repository hosting the jee6 artifacts + http://download.java.net/maven/2 + + + + + + + + org.apache.abdera2 + abdera2-common + 2.0-SNAPSHOT + + + + org.apache.abdera2 + abdera2-core + 2.0-SNAPSHOT + + + + org.apache.abdera2 + abdera2-activities + 2.0-SNAPSHOT + + + + org.apache.abdera2 + abdera2-client + 2.0-SNAPSHOT + + + + org.apache.abdera2 + abdera2-ext + 2.0-SNAPSHOT + + + + org.apache.abdera2 + abdera2-security + 2.0-SNAPSHOT + + + + + commons-codec + commons-codec + 1.5 + + + + org.apache.httpcomponents + httpclient + 4.1.2 + + + + org.apache.httpcomponents + httpmime + 4.1.2 + + + + org.apache.httpcomponents + httpcore + 4.1.2 + + + + org.apache.httpcomponents + httpclient-cache + 4.1.2 + + + + com.google.code.gson + gson + 1.7.1 + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.12 + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.12 + + + javax.mail + mail + + + stax + stax-api + + + + + + commons-logging + commons-logging + 1.1.1 + + + + org.apache.geronimo.specs + geronimo-activation_1.1_spec + 1.1 + + + + javax + javaee-web-api + 6.0 + provided + + + + com.ibm.icu + icu4j + 4.8.1.1 + + + + junit + junit + 4.9 + test, compile, package + + + + org.codehaus.woodstox + wstx-asl + 3.2.6 + runtime + + + stax + stax-api + + + + + + jaxen + jaxen + 1.1.1 + + + jdom + jdom + + + xom + xom + + + dom4j + dom4j + + + + + + org.apache.santuario + xmlsec + 1.4.5 + + + + xerces + xercesImpl + 2.9.1 + + + + xml-apis + xml-apis + 2.0.2 + + + + org.eclipse.jetty + jetty-server + 8.0.0.v20110901 + + + org.eclipse.jetty + jetty-servlet + 8.0.0.v20110901 + + + + org.mockito + mockito-all + 1.8.5 + + + + org.easymock + easymock + 3.0 + + + + com.google.guava + guava + 11.0 + + + + nu.validator.htmlparser + htmlparser + 1.2.1 + + + + joda-time + joda-time + 2.0 + + + + + + + + + + org.apache.abdera2 + abdera2-common + + + + org.apache.abdera2 + abdera2-core + + + + org.apache.abdera2 + abdera2-activities + + + + org.apache.abdera2 + abdera2-client + + + + org.apache.abdera2 + abdera2-ext + + + + org.apache.abdera2 + abdera2-security + + + + + commons-codec + commons-codec + + + + org.apache.httpcomponents + httpclient + + + + org.apache.httpcomponents + httpmime + + + + org.apache.httpcomponents + httpcore + + + + org.apache.httpcomponents + httpclient-cache + + + + com.google.code.gson + gson + + + + org.apache.ws.commons.axiom + axiom-api + + + + org.apache.ws.commons.axiom + axiom-impl + + + + commons-logging + commons-logging + + + + org.apache.geronimo.specs + geronimo-activation_1.1_spec + + + + javax + javaee-web-api + provided + + + + com.ibm.icu + icu4j + + + + junit + junit + test, compile, package + + + + org.codehaus.woodstox + wstx-asl + runtime + + + + jaxen + jaxen + + + + org.apache.santuario + xmlsec + + + + xerces + xercesImpl + + + + xml-apis + xml-apis + + + + org.eclipse.jetty + jetty-server + + + org.eclipse.jetty + jetty-servlet + + + + org.mockito + mockito-all + + + + org.easymock + easymock + + + + com.google.guava + guava + + + + nu.validator.htmlparser + htmlparser + + + + joda-time + joda-time + + + + + + server + test + examples + + + + + apache.snapshots + Apache Development Snapshot Repository + scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository + + + + apache.releases + Apache Release Distribution Repository + scp://people.apache.org/www/people.apache.org/repo/m2-ibiblio-rsync-repository + + + + + UTF-8 + 6.1.24 + 3.0 + ${basedir} + ${abdera.osgi.abdera.imports},${abdera.osgi.default.imports} + ${abdera.osgi.default.exports};version=${project.version};-noimport:=true + org.apache.abdera2.*;version="[$(version;===;${abdera.osgi.version.clean}),$(version;==+;${abdera.osgi.version.clean}))" + * + org.apache.abdera2.* + + + +
Propchange: abdera/abdera2-server/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/pom.xml URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/pom.xml?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/pom.xml (added) +++ abdera/abdera2-server/server/pom.xml Wed Feb 1 17:54:54 2012 @@ -0,0 +1,60 @@ + + + + 4.0.0 + + + org.apache.abdera2 + abdera2-server-project + 2.0-SNAPSHOT + + + abdera2-server + bundle + Abdera2 Server + 2.0-SNAPSHOT + Atom Publishing Protocol Server Implementation + + + ${basedir}/.. + + org.apache.abdera2.protocol.server.* + + + org.apache.commons.codec*;version="[1.3,2)", + * + + + + + + org.apache.abdera2 + abdera2-core + 2.0-SNAPSHOT + compile + + + org.apache.abdera2 + abdera2-common + 2.0-SNAPSHOT + compile + + + Propchange: abdera/abdera2-server/server/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,134 @@ +/* + * 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.activities.protocol; + +import java.io.IOException; +import java.util.Arrays; + +import org.apache.abdera2.activities.model.ASBase; +import org.apache.abdera2.activities.model.ASObject; +import org.apache.abdera2.activities.model.Collection; +import org.apache.abdera2.activities.model.Collection.CollectionBuilder; +import org.apache.abdera2.activities.model.objects.ServiceObject; +import org.apache.abdera2.common.misc.ExceptionHelper; +import org.apache.abdera2.common.protocol.AbstractCollectionAdapter; +import org.apache.abdera2.common.protocol.CollectionAdapter; +import org.apache.abdera2.common.protocol.CollectionInfo; +import org.apache.abdera2.common.protocol.RequestContext; +import org.apache.abdera2.common.protocol.ResponseContext; +import org.apache.abdera2.common.protocol.ResponseContextException; + +import static org.apache.abdera2.activities.protocol.AbstractActivitiesProvider.*; +import static org.apache.abdera2.activities.model.objects.PersonObject.makePerson; +import static org.apache.abdera2.activities.model.objects.ServiceObject.makeService; +import static org.apache.abdera2.activities.model.Collection.makeCollection; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + +public abstract class AbstractActivitiesCollectionAdapter + extends AbstractCollectionAdapter + implements CollectionAdapter, + CollectionInfo { + + public AbstractActivitiesCollectionAdapter(String href) { + super(href); + } + + public Iterable getAccepts(RequestContext request) { + return Arrays.asList("application/json"); + } + + protected ResponseContext buildCreateEntryResponse( + String link, + ASBase.Builder builder) { + return + new ActivitiesResponseContext(builder) + .setLocation(link) + .setContentLocation(link) + .setEntityTag(calculateEntityTag(builder.get())) + .setStatus(201); + } + + protected ResponseContext buildGetEntryResponse( + RequestContext request, + ASObject.Builder builder) + throws ResponseContextException { + builder.source(createSourceObject(request)); + return + new ActivitiesResponseContext(builder) + .setEntityTag(calculateEntityTag(builder.get())); + } + + protected ResponseContext buildGetFeedResponse( + CollectionBuilder builder) { + return + new ActivitiesResponseContext>(builder) + .setEntityTag(calculateEntityTag(builder.get())); + } + + protected ServiceObject createSourceObject( + RequestContext request) + throws ResponseContextException { + return + makeService() + .displayName(getTitle(request)) + .id(getId(request)) + .author( + makePerson() + .displayName(getAuthor(request))) + .get(); + } + + /** + * Create the base feed for the requested collection. + */ + protected Collection createCollectionBase( + RequestContext request) + throws ResponseContextException { + return + makeCollection() + .id(getId(request)) + .updatedNow() + .author( + makePerson() + .displayName(getAuthor(request))) + .displayName(getTitle(request)) + .get(); + } + + protected ASObject getEntryFromRequest( + RequestContext request) + throws ResponseContextException { + ASObject object; + try { + object = + AbstractActivitiesProvider + .getASBaseFromRequestContext(request); + } catch (IOException e) { + throw ExceptionHelper.propogate(e); + } + return object; + } + + public Predicate acceptable() { + return Predicates.or( + super.acceptable(), + AbstractActivitiesWorkspaceProvider.isJson()); + } +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,185 @@ +/* + * 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.activities.protocol; + +import java.io.IOException; +import java.io.Reader; +import java.util.HashSet; +import java.util.Set; + +import javax.activation.MimeType; + +import org.apache.abdera2.activities.model.ASBase; +import org.apache.abdera2.activities.model.ASDocument; +import org.apache.abdera2.activities.model.ASObject; +import org.apache.abdera2.activities.model.Activity; +import org.apache.abdera2.activities.model.Collection; +import org.apache.abdera2.activities.model.IO; +import org.apache.abdera2.activities.model.TypeAdapter; +import org.apache.abdera2.activities.model.objects.ErrorObject; +import org.apache.abdera2.common.http.EntityTag; +import org.apache.abdera2.common.misc.ArrayBuilder; +import org.apache.abdera2.common.misc.ExceptionHelper; +import org.apache.abdera2.common.protocol.AbstractProvider; +import org.apache.abdera2.common.protocol.CollectionRequestProcessor; +import org.apache.abdera2.common.protocol.EntryRequestProcessor; +import org.apache.abdera2.common.protocol.RequestContext; +import org.apache.abdera2.common.protocol.ResponseContext; +import org.apache.abdera2.common.protocol.TargetType; +import org.apache.abdera2.common.protocol.WorkspaceManager; +import org.apache.abdera2.common.protocol.RequestContext.Scope; +import org.joda.time.DateTime; +import static org.apache.abdera2.activities.model.objects.ErrorObject.makeError; +import static org.apache.abdera2.common.date.DateTimes.format; +import static org.apache.abdera2.common.date.DateTimes.formatNow; +import static org.apache.abdera2.common.http.EntityTag.generate; +import static java.util.UUID.randomUUID; + +public abstract class AbstractActivitiesProvider + extends AbstractProvider + implements ActivitiesProvider { + + protected Set> typeAdapters = + new HashSet>(); + protected final WorkspaceManager workspaceManager; + + protected AbstractActivitiesProvider( + WorkspaceManager workspaceManager) { + this.workspaceManager = workspaceManager; + addRequestProcessor( + TargetType.TYPE_COLLECTION, + CollectionRequestProcessor.class, + AbstractActivitiesWorkspaceProvider.isJson(), + workspaceManager + ); + addRequestProcessor( + TargetType.TYPE_ENTRY, + EntryRequestProcessor.class, + workspaceManager); + } + + public void addTypeAdapter(TypeAdapter typeAdapter) { + typeAdapters.add(typeAdapter); + } + + public void removeTypeAdapter(TypeAdapter typeAdapter) { + typeAdapters.remove(typeAdapter); + } + + public Set> getTypeAdapters() { + return typeAdapters; + } + + public ResponseContext createErrorResponse( + int code, + String message, + Throwable t) { + return + new ActivitiesResponseContext( + makeError() + .code(code) + .displayName(message)) + .setStatus(code) + .setStatusText(message); + } + + public static EntityTag calculateEntityTag(ASBase base) { + String id = null; + String modified = null; + if (base instanceof Activity) { + Activity ac = (Activity)base; + id = ac.getId(); + modified = format( + ac.getUpdated() != null ? + ac.getUpdated() : + ac.getPublished()); + } else if (base instanceof Collection) { + Collection col = (Collection)base; + id = col.getProperty("id"); + if (id == null) id = randomUUID().toString(); + modified = col.getProperty("updated"); + } else if (base instanceof ASObject) { + ASObject as = (ASObject)base; + id = as.getId().toString(); + modified = format( + as.getUpdated() != null ? + as.getUpdated() : + as.getPublished()); + } + if (modified == null) modified = formatNow(); + return generate(id, modified); + } + + public static String getEditUriFromEntry(ASObject object) { + String editLink = object.getProperty("editLink"); + return editLink; + } + + public static IO getIO( + ActivitiesProvider provider, + TypeAdapter... adapters) { + return IO.get( + ArrayBuilder.>set(TypeAdapter.class) + .addAll(provider.getTypeAdapters()) + .add(adapters) + .build()); + } + + @SuppressWarnings("unchecked") + public static T getASBaseFromRequestContext( + RequestContext context) + throws IOException { + ASBase entity = context.getAttribute(Scope.REQUEST, ASBase.class.getName()); + try { + if (entity == null) { + Reader reader = context.getReader(); + IO io = getIO(context.getProvider()); + if (reader != null) + entity = io.read(reader); + else // try input stream, but this should've worked + entity = io.read(context.getInputStream(), "UTF-8"); + } + } catch (Throwable t) { + throw ExceptionHelper.propogate(t); + } + if (entity != null) + context.setAttribute(ASBase.class.getName(), getDoc(entity,context)); + return (T)entity; + } + + private static ASDocument getDoc(T base, RequestContext context) { + ASDocument.Builder builder = + ASDocument.make(base); + String etag = context.getHeader("ETag"); + if (etag != null) + builder.entityTag(etag); + DateTime lm = context.getDateHeader("Last-Modified"); + if (lm != null) + builder.lastModified(lm); + MimeType mt = context.getContentType(); + if (mt != null) + builder.contentType(mt.toString()); + String language = context.getContentLanguage(); + if (language != null) + builder.language(language); + String slug = context.getSlug(); + if (slug != null) + builder.slug(slug); + return builder.get(); + } +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,95 @@ +/* + * 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.activities.protocol; + +import java.util.HashSet; +import java.util.Set; + +import javax.activation.MimeType; + +import org.apache.abdera2.activities.model.TypeAdapter; +import org.apache.abdera2.activities.model.objects.ErrorObject; +import org.apache.abdera2.common.mediatype.MimeTypeHelper; +import org.apache.abdera2.common.protocol.AbstractWorkspaceProvider; +import org.apache.abdera2.common.protocol.CollectionRequestProcessor; +import org.apache.abdera2.common.protocol.EntryRequestProcessor; +import org.apache.abdera2.common.protocol.Provider; +import org.apache.abdera2.common.protocol.RequestContext; +import org.apache.abdera2.common.protocol.ResponseContext; +import org.apache.abdera2.common.protocol.TargetType; +import org.apache.abdera2.common.protocol.WorkspaceManager; +import static org.apache.abdera2.activities.model.objects.ErrorObject.makeError; + +import com.google.common.base.Predicate; + +public abstract class AbstractActivitiesWorkspaceProvider + extends AbstractWorkspaceProvider + implements Provider, + WorkspaceManager, + ActivitiesProvider { + + protected final Set> typeAdapters = + new HashSet>(); + + public static Predicate isJson() { + return new Predicate() { + public boolean apply(RequestContext input) { + MimeType ct = input.getContentType(); + if (ct == null) return false; + return MimeTypeHelper.isJson(ct.toString()); + } + }; + } + + protected AbstractActivitiesWorkspaceProvider() { + addRequestProcessor( + TargetType.TYPE_COLLECTION, + CollectionRequestProcessor.class, + isJson(), + this); + addRequestProcessor( + TargetType.TYPE_ENTRY, + EntryRequestProcessor.class, + this); + } + + public void addTypeAdapter(TypeAdapter typeAdapter) { + typeAdapters.add(typeAdapter); + } + + public void removeTypeAdapter(TypeAdapter typeAdapter) { + typeAdapters.remove(typeAdapter); + } + + public Set> getTypeAdapters() { + return typeAdapters; + } + + public ResponseContext createErrorResponse( + int code, + String message, + Throwable t) { + return + new ActivitiesResponseContext( + makeError() + .code(code) + .displayName(message)) + .setStatus(code) + .setStatusText(message); + } +} \ No newline at end of file Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesProvider.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesProvider.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesProvider.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesProvider.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,33 @@ +/* + * 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.activities.protocol; + +import java.util.Set; + +import org.apache.abdera2.activities.model.TypeAdapter; +import org.apache.abdera2.common.protocol.Provider; + +public interface ActivitiesProvider extends Provider { + + void addTypeAdapter(TypeAdapter typeAdapter); + + void removeTypeAdapter(TypeAdapter typeAdapter); + + Set> getTypeAdapters(); + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesProvider.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java Wed Feb 1 17:54:54 2012 @@ -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.abdera2.activities.protocol; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import javax.activation.MimeType; + +import org.apache.abdera2.activities.model.ASBase; +import org.apache.abdera2.common.mediatype.MimeTypeHelper; +import org.apache.abdera2.common.protocol.AbstractResponseContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ActivitiesResponseContext + extends AbstractResponseContext { + + private final static Log log = LogFactory.getLog(ActivitiesResponseContext.class); + + private final ASBase.Builder builder; + private final boolean chunked; + + public ActivitiesResponseContext(ASBase.Builder builder) { + this(builder, true); + } + + public ActivitiesResponseContext(ASBase.Builder builder, boolean chunked) { + this.builder = builder; + setStatus(200); + setStatusText("OK"); + this.chunked = chunked; + try { + MimeType type = getContentType(); + String charset = type.getParameter("charset"); + if (charset == null) + type.setParameter("charset", "UTF-8"); + setContentType(type.toString()); + } catch (Exception e) { + // it's ok to ignore this exception + log.debug("Error setting charset parameter",e); + } + log.debug(String.format("Content-Type: %s", getContentType())); + } + + @SuppressWarnings("unchecked") + public >X getBuilder() { + return (X)builder; + } + + public T getEntity() { + return builder.get(); + } + + public boolean hasEntity() { + return (builder != null); + } + + public void writeTo(java.io.Writer javaWriter) throws IOException { + log.debug("Writing..."); + if (hasEntity()) + getEntity().writeTo(javaWriter); + } + + public void writeTo(OutputStream out) throws IOException { + log.debug("Writing..."); + if (hasEntity()) + getEntity().writeTo(out); + } + + public MimeType getContentType() { + return MimeTypeHelper.unmodifiableMimeType("application/json"); + } + + public long getContentLength() { + long len = super.getContentLength(); + if (hasEntity() && len == -1 && !chunked) { + try { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + getEntity().writeTo(out); + len = out.size(); + super.setContentLength(len); + } catch (Exception e) { + } + } + log.debug(String.format("Content-Length: %d", len)); + return len; + } + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesServiceManager.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesServiceManager.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesServiceManager.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesServiceManager.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,52 @@ +/* + * 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.activities.protocol; + +import static org.apache.abdera2.common.misc.MoreFunctions.*; + +import java.util.Map; + +import org.apache.abdera2.activities.model.IO; +import org.apache.abdera2.activities.model.TypeAdapter; +import org.apache.abdera2.common.protocol.AbstractServiceManager; +import org.apache.abdera2.common.protocol.Provider; + +/** + * The ServiceManager is used by the AbderaServlet to bootstrap the server + * instance. There should be little to no reason why an end user would need + * to use this class directly. + */ +public class ActivitiesServiceManager + extends AbstractServiceManager { + + public ActivitiesServiceManager() {} + + public static IO getIO(TypeAdapter... adapters) { + return IO.get(adapters); + } + + @SuppressWarnings("unchecked") + public

P newProvider( + Map properties) { + return (P)discoverInitializable( + Provider.class, + DefaultActivitiesProvider.class) + .apply(properties); + } + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesServiceManager.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,121 @@ +/* + * 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.activities.protocol; + +import java.util.Collection; + +import javax.security.auth.Subject; + +import org.apache.abdera2.common.protocol.DefaultWorkspaceManager; +import org.apache.abdera2.common.protocol.Request; +import org.apache.abdera2.common.protocol.RequestContext; +import org.apache.abdera2.common.protocol.RouteManager; +import org.apache.abdera2.common.protocol.Target; +import org.apache.abdera2.common.protocol.TargetBuilder; +import org.apache.abdera2.common.protocol.TargetType; +import org.apache.abdera2.common.protocol.WorkspaceInfo; +import org.apache.abdera2.common.protocol.WorkspaceManager; + +import com.google.common.base.Function; + +public class DefaultActivitiesProvider + extends AbstractActivitiesProvider { + + protected Function targetResolver; + protected Function subjectResolver; + protected TargetBuilder targetBuilder; + protected RouteManager routeManager; + + public DefaultActivitiesProvider() { + this("/"); + } + + public DefaultActivitiesProvider(String base) { + super(new DefaultWorkspaceManager()); + if (base == null) base = "/"; + routeManager = + RouteManager.make() + .with("stream", base + ":stream", TargetType.TYPE_COLLECTION) + .with("activity", base + ":stream/:activity", TargetType.TYPE_ENTRY) + .get() + ; + + targetBuilder = routeManager; + targetResolver = routeManager; + } + + @SuppressWarnings("rawtypes") + public RouteManager getRouteManager() { + return routeManager; + } + + protected Function getTargetResolver(RequestContext request) { + return targetResolver; + } + + public void setTargetResolver(Function targetResolver) { + this.targetResolver = targetResolver; + } + + protected Function getSubjectResolver(RequestContext request) { + return subjectResolver; + } + + public void setSubjectResolver(Function subjectResolver) { + this.subjectResolver = subjectResolver; + } + + public Function getTargetResolver() { + return targetResolver; + } + + public Function getSubjectResolver() { + return subjectResolver; + } + + protected WorkspaceManager getWorkspaceManager(RequestContext request) { + return getWorkspaceManager(); + } + + public WorkspaceManager getWorkspaceManager() { + return workspaceManager; + } + + @SuppressWarnings("rawtypes") + public TargetBuilder getTargetBuilder() { + return (TargetBuilder)targetBuilder; + } + + public void setTargetBuilder(TargetBuilder targetBuilder) { + this.targetBuilder = targetBuilder; + } + + public void addWorkspace(WorkspaceInfo workspace) { + ((DefaultWorkspaceManager)getWorkspaceManager()).addWorkspace(workspace); + } + + public void addWorkspaces(Collection workspaces) { + for (WorkspaceInfo w : workspaces) + ((DefaultWorkspaceManager)getWorkspaceManager()).addWorkspace(w); + } + + @SuppressWarnings("rawtypes") + protected TargetBuilder getTargetBuilder(Request request) { + return (TargetBuilder)targetBuilder; + } +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,78 @@ +/* + * 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.activities.protocol; + +import org.apache.abdera2.activities.model.objects.ErrorObject; +import org.apache.abdera2.common.misc.MoreFunctions; + +import static org.apache.abdera2.activities.model.objects.ErrorObject.makeError; + +public class ProtocolException extends RuntimeException { + + private static final long serialVersionUID = 1017447143200419489L; + private final transient ErrorObject error; + + public ProtocolException(ErrorObject error) { + super(String.format("%d::%s",error.getCode(),error.getDisplayName())); + this.error = error; + } + + public ProtocolException(int code, String message) { + super(String.format("%d::%s",code,message)); + this.error = + makeError() + .code(code) + .displayName(message) + .get(); + } + + public ErrorObject getError() { + return error; + } + + @Override + public int hashCode() { + String message = error != null ? error.getDisplayName() : null; + int code = error != null ? error.getCode() : 0; + return MoreFunctions.genHashCode(1,message,code); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final ProtocolException other = (ProtocolException)obj; + String message = error != null ? error.getDisplayName() : null; + int code = error != null ? error.getCode() : 0; + String omessage = other.error != null ? other.error.getDisplayName() : null; + int ocode = other.error != null ? other.error.getCode() : 0; + if (message == null) { + if (omessage != null) + return false; + } else if (!message.equals(omessage)) + return false; + if (code != ocode) + return false; + return true; + } + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,266 @@ +/* + * 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.activities.protocol.basic; + +import java.util.UUID; +import java.util.logging.Logger; + +import javax.activation.MimeType; + +import org.apache.abdera2.activities.model.ASBase; +import org.apache.abdera2.activities.model.ASObject; +import org.apache.abdera2.activities.model.Collection; +import org.apache.abdera2.activities.model.Collection.CollectionBuilder; +import org.apache.abdera2.activities.model.objects.ErrorObject; +import org.apache.abdera2.activities.model.objects.PersonObject; +import org.apache.abdera2.activities.protocol.ActivitiesResponseContext; +import org.apache.abdera2.activities.protocol.managed.FeedConfiguration; +import org.apache.abdera2.activities.protocol.managed.ManagedCollectionAdapter; +import org.apache.abdera2.common.mediatype.MimeTypeHelper; +import org.apache.abdera2.common.protocol.RequestContext; +import org.apache.abdera2.common.protocol.ResponseContext; +import org.apache.abdera2.common.protocol.Target; +import org.apache.abdera2.common.protocol.TargetType; +import org.apache.abdera2.common.protocol.RequestContext.Scope; +import org.apache.abdera2.common.pusher.ChannelManager; +import org.apache.abdera2.common.pusher.Pusher; +import org.joda.time.DateTime; + +import com.google.common.base.Function; +import static com.google.common.base.Preconditions.*; +import static org.apache.abdera2.common.misc.ExceptionHelper.*; +import static org.apache.abdera2.common.protocol.ProviderHelper.*; + +/** + * The BasicAdapter provides a simplistic interface for working with Atompub collections with a restricted set of + * options/features. The idea of the basic adapter is to make it easy to provide a minimally capable Atompub server + */ +@SuppressWarnings("unchecked") +public abstract class BasicAdapter extends ManagedCollectionAdapter { + + public final static Logger logger = Logger.getLogger(BasicAdapter.class.getName()); + + protected BasicAdapter(FeedConfiguration config) { + super(config); + putHandler(TargetType.TYPE_COLLECTION,"GET",getItemList()); + putHandler(TargetType.TYPE_COLLECTION,"HEAD",getItemList()); + putHandler(TargetType.TYPE_COLLECTION,"POST",postItem()); + putHandler(TargetType.TYPE_ENTRY,"GET",getItem()); + putHandler(TargetType.TYPE_ENTRY,"HEAD",getItem()); + putHandler(TargetType.TYPE_ENTRY,"DELETE",deleteItem()); + putHandler(TargetType.TYPE_ENTRY,"PUT",putItem()); + } + + public String getProperty(String key) throws Exception { + Object val = config.getProperty(key); + checkNotNull( + val, + "Cannot find property in Adapter properties file for feed ", + key, + config.getFeedId()); + checked( + val instanceof String, + RuntimeException.class); + return (String)val; + } + + protected CollectionBuilder createCollection() { + return + Collection + .makeCollection() + .id(config.getFeedUri()) + .set("title", config.getFeedTitle()) + .set("updated", DateTime.now()) + .set("author", + PersonObject + .makePerson() + .displayName(config.getFeedAuthor()) + .get()); + } + + protected void addEditLinkToObject( + ASObject.Builder builder, + String id) throws Exception { + builder.set("editLink", id); + } + + protected void setObjectId(ASObject.Builder builder) throws Exception { + String uuidUri = UUID.randomUUID().toString(); + String[] segments = uuidUri.split(":"); + String entryId = segments[segments.length - 1]; + builder.id(createEntryIdUri(entryId)); + } + + protected String createEntryIdUri(String entryId) throws Exception { + return config.getFeedUri() + "/" + entryId; + } + + private void push(RequestContext context, String channel, ASObject.Builder builder) { + if (context.getAttribute(Scope.CONTAINER, "AbderaChannelManager") != null) { + ChannelManager cm = (ChannelManager) context.getAttribute( + Scope.CONTAINER, "AbderaChannelManager"); + if (cm != null) { + Pusher pusher = + cm.getPusher(channel); + if (pusher != null) + pusher.push(builder.get()); + } + } + } + + ResponseContext createOrUpdateObject(RequestContext request, boolean createFlag) { + try { + MimeType mimeType = request.getContentType(); + String contentType = mimeType == null ? null : mimeType.toString(); + if (contentType != null && !MimeTypeHelper.isJson(contentType)) + return notsupported(request); + + ASBase base = getEntryFromRequest(request); + Target target = request.getTarget(); + + if (base instanceof Collection && + createFlag && + target.getType() == TargetType.TYPE_COLLECTION) { + // only allow multiposts on collections.. these always create, never update + Collection coll = (Collection) base; + CollectionBuilder retl = Collection.makeCollection(); + int c = 0; + for (ASObject inputEntry : coll.getItems()) { + ASObject.Builder newEntry = createItem(inputEntry,c++); + if (newEntry != null) { + push(request,target.getParameter(BasicProvider.PARAM_FEED),newEntry); + retl.item(newEntry.get()); + } else { + retl.item( + ErrorObject + .makeError() + .code(-100) + .displayName("Error adding object") + .get()); + } + } + return + new ActivitiesResponseContext>(retl) + .setStatus(createFlag?201:200); + } else if (base instanceof ASObject){ + String entryId = !createFlag ? + target.getParameter(BasicProvider.PARAM_ENTRY) : + null; + ASObject inputEntry = (ASObject) base; + ASObject.Builder newEntry = createFlag ? + createItem(inputEntry) : + updateItem(entryId, inputEntry); + if (newEntry != null) { + push(request,target.getParameter(BasicProvider.PARAM_FEED),newEntry); + String loc = newEntry.get().getProperty("editLink"); + return + new ActivitiesResponseContext(newEntry) + .setStatus(createFlag?201:200) + .setLocation(loc); + } else + return notfound(request); + } else + return notallowed(request); + } catch (Exception e) { + return servererror(request, e.getMessage(), e); + } + } + + private Function postItem() { + return new Function() { + public ResponseContext apply(RequestContext input) { + return createOrUpdateObject(input,true); + } + }; + } + + private Function deleteItem() { + return new Function() { + public ResponseContext apply(RequestContext input) { + Target target = input.getTarget(); + String entryId = target.getParameter(BasicProvider.PARAM_ENTRY); + try { + return deleteItem(entryId) ? + nocontent() : + notfound(input); + } catch (Exception e) { + return servererror( + input, e.getMessage(), e); + } + } + }; + } + + private Function putItem() { + return new Function() { + public ResponseContext apply(RequestContext input) { + return createOrUpdateObject(input,false); + } + }; + } + + private Function getItem() { + return new Function() { + public ResponseContext apply(RequestContext input) { + Target target = input.getTarget(); + String entryId = target.getParameter(BasicProvider.PARAM_ENTRY); + try { + ASObject.Builder object = getItem(entryId); + if (object != null) { + return + new ActivitiesResponseContext(object) + .setStatus(200); + } else return notfound(input); + } catch (Exception e) { + return servererror(input, e.getMessage(), e); + } + } + }; + } + + public Function getItemList() { + return new Function() { + public ResponseContext apply(RequestContext input) { + try { + CollectionBuilder collection = + getCollection(); + if (collection != null) { + return + new ActivitiesResponseContext>(collection) + .setStatus(200); + } else return notfound(input); + } catch (Exception e) { + return servererror(input, e.getMessage(), e); + } + } + }; + } + + public abstract CollectionBuilder getCollection() throws Exception; + + public abstract ASObject.Builder getItem(Object objectId) throws Exception; + + public abstract ASObject.Builder createItem(ASObject object) throws Exception; + + public abstract ASObject.Builder createItem(ASObject object, int c) throws Exception; + + public abstract ASObject.Builder updateItem(Object objectId, ASObject object) throws Exception; + + public abstract boolean deleteItem(Object objectId) throws Exception; + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java Wed Feb 1 17:54:54 2012 @@ -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.activities.protocol.basic; + +import org.apache.abdera2.activities.protocol.managed.BasicServerConfiguration; +import org.apache.abdera2.activities.protocol.managed.ManagedProvider; +import org.apache.abdera2.activities.protocol.managed.ServerConfiguration; +import org.apache.abdera2.common.protocol.RequestContext; +import org.apache.abdera2.common.protocol.CollectionAdapter; +import org.apache.abdera2.common.protocol.RouteManager; +import org.apache.abdera2.common.protocol.TargetType; + +/** + * Provider implementation intended to be used with BasicAdapter implementations + */ +public class BasicProvider + extends ManagedProvider { + + public static final String PARAM_FEED = "stream"; + public static final String PARAM_ENTRY = "activity"; + + public BasicProvider() { + super(); + init(); + } + + private void init() { + RouteManager routeManager = + RouteManager.make() + .with( + "stream", + "/:stream", + TargetType.TYPE_COLLECTION) + .with( + "activity", + "/:stream/:activity", + TargetType.TYPE_ENTRY) + .get(); + setTargetBuilder( + routeManager); + setTargetResolver( + routeManager); + } + + public CollectionAdapter getCollectionAdapter(RequestContext request) { + try { + return getCollectionAdapterManager(request) + .getAdapter( + request.getTarget().getParameter(PARAM_FEED)); + } catch (Exception e) { + return null; + } + } + + protected ServerConfiguration getServerConfiguration(RequestContext request) { + return new BasicServerConfiguration(request); + } + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicServiceManager.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicServiceManager.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicServiceManager.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicServiceManager.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,35 @@ +/* + * 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.activities.protocol.basic; + +import java.util.Map; + +import org.apache.abdera2.activities.protocol.ActivitiesServiceManager; +import org.apache.abdera2.common.protocol.Provider; + +public class BasicServiceManager extends ActivitiesServiceManager { + + @SuppressWarnings("unchecked") + @Override + public

P newProvider(Map properties) { + BasicProvider bp = new BasicProvider(); + bp.init(properties); + return (P)bp; + } + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicServiceManager.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/AbstractServerConfiguration.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/AbstractServerConfiguration.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/AbstractServerConfiguration.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/AbstractServerConfiguration.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,85 @@ +/* + * 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.activities.protocol.managed; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.abdera2.common.protocol.RequestContext; + +public abstract class AbstractServerConfiguration + extends ServerConfiguration { + + private final String host; + private final int port; + private final boolean secure; + + protected AbstractServerConfiguration(RequestContext request) { + Object ohost = request.getProperty(RequestContext.Property.SERVERNAME); + Object oport = request.getProperty(RequestContext.Property.SERVERPORT); + Object osec = request.getProperty(RequestContext.Property.SECURE); + host = ohost != null ? (String)ohost : "localhost"; + port = oport != null ? ((Integer)oport).intValue() : 9002; + secure = osec != null ? ((Boolean)osec).booleanValue() : false; + } + + @Override + public String getAdapterConfigLocation() { + return "activities/adapter/config/"; + } + + @Override + public String getFeedConfigLocation() { + return "activities/adapter/"; + } + + @Override + public String getFeedConfigSuffix() { + return ".properties"; + } + + @Override + public int getPort() { + return port; + } + + @Override + public String getServerUri() { + StringBuilder buf = new StringBuilder(); + buf.append(secure ? "https://" : "http://"); + buf.append(host); + if (port != 80) + buf.append(":") + .append(port); + return buf.toString(); + } + + @Override + public FeedConfiguration loadFeedConfiguration(String feedId) throws IOException { + String fileName = getFeedConfigLocation() + feedId + getFeedConfigSuffix(); + InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); + if (in == null) + throw new FileNotFoundException(); + Properties props = new Properties(); + props.load(in); + in.close(); + return FeedConfiguration.getFeedConfiguration(feedId, props, this); + } +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/AbstractServerConfiguration.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/BasicServerConfiguration.java URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/BasicServerConfiguration.java?rev=1239237&view=auto ============================================================================== --- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/BasicServerConfiguration.java (added) +++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/BasicServerConfiguration.java Wed Feb 1 17:54:54 2012 @@ -0,0 +1,29 @@ +/* + * 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.activities.protocol.managed; + +import org.apache.abdera2.common.protocol.RequestContext; + +public class BasicServerConfiguration extends AbstractServerConfiguration { + + public BasicServerConfiguration(RequestContext request) { + super(request); + } + + +} Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/activities/protocol/managed/BasicServerConfiguration.java ------------------------------------------------------------------------------ svn:mime-type = text/plain