You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/09/09 00:24:32 UTC

svn commit: r441675 - in /incubator/abdera/java/trunk: examples/src/main/java/org/apache/abdera/examples/appserver/SimpleProvider.java server/src/main/java/org/apache/abdera/protocol/server/util/AbstractProvider.java

Author: jmsnell
Date: Fri Sep  8 15:24:31 2006
New Revision: 441675

URL: http://svn.apache.org/viewvc?view=rev&rev=441675
Log:
AbstractProvider implementation to provide as base for common provider functions

Added:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/AbstractProvider.java
Modified:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleProvider.java

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleProvider.java?view=diff&rev=441675&r1=441674&r2=441675
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleProvider.java (original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleProvider.java Fri Sep  8 15:24:31 2006
@@ -17,23 +17,17 @@
 */
 package org.apache.abdera.examples.appserver;
 
-import java.io.IOException;
 import java.util.Date;
 
-import javax.activation.MimeTypeParseException;
-
-import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Collection;
 import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
 import org.apache.abdera.model.Link;
 import org.apache.abdera.model.Service;
 import org.apache.abdera.model.Source;
 import org.apache.abdera.model.Workspace;
-import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.stax.util.FOMHelper;
 import org.apache.abdera.protocol.server.AbderaServer;
 import org.apache.abdera.protocol.server.RequestContext;
@@ -41,36 +35,19 @@
 import org.apache.abdera.protocol.server.exceptions.AbderaServerException.Code;
 import org.apache.abdera.protocol.server.provider.Provider;
 import org.apache.abdera.protocol.server.target.Target;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.abdera.protocol.server.util.AbstractProvider;
 
 public class SimpleProvider 
+  extends AbstractProvider
   implements Provider {
 
-  private final AbderaServer abderaServer;
   private static Document<Service> service_doc = null;
   private static Document<Feed> feed_doc = null;
   
   public SimpleProvider(AbderaServer abderaServer) {
-    this.abderaServer = abderaServer;
-  }
-  
-  private AbderaServer getAbderaServer() {
-    return abderaServer;
+    super(abderaServer);
   }
   
-  private Abdera getAbdera() {
-    return getAbderaServer().getAbdera();
-  }
-  
-  private Factory getFactory() {
-    return getAbdera().getFactory();
-  }
-  
-  private Parser getParser() {
-    return getAbdera().getParser();
-  }
-
   private synchronized Document<Service> getService() {
     if (service_doc == null) {
       try {
@@ -226,43 +203,4 @@
     }
   }
   
-  @SuppressWarnings("unchecked")
-  private Document<Entry> getEntryFromRequestContext(
-    RequestContext context) 
-      throws IOException, 
-             MimeTypeParseException {
-    String ctype = context.getContentType().toString();
-    if (ctype != null && ctype.length() != 0 &&
-        (!MimeTypeHelper.isMatch(ctype, "application/atom+xml") &&
-         !MimeTypeHelper.isMatch(ctype, "application/xml"))) {
-      return null;
-    }
-    // might still be an atom entry, let's try it
-    try {
-      Parser parser = getParser();
-      Document doc = parser.parse(context.getInputStream());
-      Element root = doc.getRoot();
-      if (root != null && root.getQName().equals(Constants.ENTRY)) {
-        return doc;
-      }
-    } catch (Exception e) {}
-    return null;
-  }
-  
-  private boolean isValidEntry(Entry entry) {
-    try {
-      if (entry.getId() == null || entry.getId().toString().length() == 0) return false;
-      if (entry.getTitle() == null) return false;
-      if (entry.getAuthor() == null) return false;
-      if (entry.getUpdated() == null) return false;
-      if (entry.getContent() == null) {
-        if (entry.getAlternateLink() == null) return false;
-        if (entry.getSummary() == null) return false;
-      }
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-    return true;
-  }
-
 }

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/AbstractProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/AbstractProvider.java?view=auto&rev=441675
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/AbstractProvider.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/AbstractProvider.java Fri Sep  8 15:24:31 2006
@@ -0,0 +1,103 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.util;
+
+import java.io.IOException;
+
+import javax.activation.MimeTypeParseException;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.protocol.server.AbderaServer;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.provider.Provider;
+import org.apache.abdera.util.Constants;
+import org.apache.abdera.util.MimeTypeHelper;
+
+public abstract class AbstractProvider 
+  implements Provider {
+
+  private final AbderaServer abderaServer;
+  
+  protected AbstractProvider(AbderaServer abderaServer) {
+    this.abderaServer = abderaServer;
+  }
+  
+  protected AbderaServer getAbderaServer() {
+    return abderaServer;
+  }
+  
+  protected Abdera getAbdera() {
+    return getAbderaServer().getAbdera();
+  }
+  
+  protected Factory getFactory() {
+    return getAbdera().getFactory();
+  }
+  
+  protected Parser getParser() {
+    return getAbdera().getParser();
+  }
+
+
+  @SuppressWarnings("unchecked")
+  protected Document<Entry> getEntryFromRequestContext(
+    RequestContext context) 
+      throws IOException, 
+             MimeTypeParseException {
+    String ctype = (context.getContentType() != null) ?
+      context.getContentType().toString() : null;
+    if (ctype != null && ctype.length() != 0 &&
+        (!MimeTypeHelper.isMatch(ctype, Constants.ATOM_MEDIA_TYPE) &&
+         !MimeTypeHelper.isMatch(ctype, Constants.XML_MEDIA_TYPE))) {
+      return null;
+    }
+    // might still be an atom entry, let's try it
+    try {
+      Parser parser = getParser();
+      Document doc = parser.parse(context.getInputStream());
+      Element root = doc.getRoot();
+      if (root != null && root.getQName().equals(Constants.ENTRY)) {
+        return doc;
+      }
+    } catch (Exception e) {}
+    return null;
+  }
+  
+  protected boolean isValidEntry(Entry entry) {
+    try {
+      if (entry.getId() == null || 
+          entry.getId().toString().length() == 0) return false;
+      if (entry.getTitle() == null) return false;
+      if (entry.getAuthor() == null) return false;
+      if (entry.getUpdated() == null) return false;
+      if (entry.getContent() == null) {
+        if (entry.getAlternateLink() == null) return false;
+        if (entry.getSummary() == null) return false;
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+    return true;
+  }
+  
+}