abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r591521 - in /incubator/abdera/java/trunk: jcr/ jcr/src/main/java/org/apache/abdera/jcr/ server/src/main/java/org/apache/abdera/protocol/server/impl/ server/src/test/java/org/apache/abdera/protocol/server/
Date Sat, 03 Nov 2007 00:26:54 GMT
Author: dandiep
Date: Fri Nov  2 17:26:52 2007
New Revision: 591521

URL: http://svn.apache.org/viewvc?rev=591521&view=rev
Log:
More CollectionProvider cleanups. Start of JCR media entry support. More tests are coming.

Modified:
    incubator/abdera/java/trunk/jcr/   (props changed)
    incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java

Propchange: incubator/abdera/java/trunk/jcr/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Nov  2 17:26:52 2007
@@ -0,0 +1,6 @@
+.settings
+repository
+target
+.classpath
+.project
+repository.xml

Modified: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java?rev=591521&r1=591520&r2=591521&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
Fri Nov  2 17:26:52 2007
@@ -1,12 +1,15 @@
 package org.apache.abdera.jcr;
 
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
+import java.util.logging.Logger;
 
+import javax.activation.MimeType;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
 import javax.jcr.InvalidItemStateException;
@@ -41,9 +44,13 @@
 import org.apache.abdera.protocol.server.impl.EmptyResponseContext;
 import org.apache.abdera.protocol.server.impl.ResponseContextException;
 import org.apache.abdera.protocol.util.EncodingUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class JcrCollectionProvider extends AbstractCollectionProvider<Node> {
 
+  private final static Log log = LogFactory.getLog(JcrCollectionProvider.class);
+  
   private static final String TITLE = "title";
 
   private static final String SUMMARY = "summary";
@@ -66,6 +73,10 @@
 
   private static final String SESSION = "jcrSession";
 
+  private static final String MEDIA = "media";
+
+  private static final String CONTENT_TYPE = "contentType";
+
   private Repository repository;
 
   private String collectionNodePath;
@@ -136,18 +147,88 @@
     return repository.login(credentials);
   }
 
+
+  @Override
+  public String getContentType(Node entry) {
+    return getStringOrNull(entry, CONTENT_TYPE);
+  }
+
+  @Override
+  public boolean isMediaEntry(Node entry) throws ResponseContextException {
+    try {
+      return entry.hasProperty(MEDIA);
+    } catch (RepositoryException e) {
+      throw new ResponseContextException(500, e);
+    }
+  }
+
+  @Override
+  public Node createMediaEntry(MimeType mimeType, String slug, 
+                               InputStream inputStream, RequestContext request)
+    throws ResponseContextException {
+    if (slug == null) {
+      throw new ResponseContextException("A slug header must be supplied.", 500);
+    }
+    Node n = createEntry(slug, null, null, new Date(), null, null, request);
+    
+    try {
+      n.setProperty(MEDIA, inputStream);
+      n.setProperty(CONTENT_TYPE, mimeType.toString());
+
+      String summary = createSummaryForEntry(n);
+      if (summary != null) {
+        n.setProperty(SUMMARY, summary);
+      }
+
+      getSession(request).save();
+      
+      return n;
+    } catch (RepositoryException e) {
+      try {
+        n.remove();
+      } catch (Throwable t) {
+        log.warn(t);
+      }
+      throw new ResponseContextException(500, e);
+    }
+  }
+  
+  /**
+   * Create a summary for an entry. Used when a media entry is created
+   * so you have the chance to create a meaningful summary for consumers
+   * of the feed.
+   * 
+   * @param n
+   * @return
+   */
+  protected String createSummaryForEntry(Node n) {
+    return null;
+  }
+
   @Override
   public Node createEntry(String title, IRI id, String summary, Date updated, List<Person>
authors,
                           Content content, RequestContext request) throws ResponseContextException
{
+    
+    Node entry = null;
     try {
       Session session = getSession(request);
 
       Node collectionNode = session.getNodeByUUID(collectionNodeId);
-      Node entry = collectionNode.addNode(ENTRY);
+      entry = collectionNode.addNode(ENTRY);
       entry.addMixin("mix:referenceable");
 
-      return mapEntryToNode(entry, title, summary, updated, authors, content, session);
+      mapEntryToNode(entry, title, summary, updated, authors, content, session);
+      
+      session.save();
+      
+      return entry;
     } catch (RepositoryException e) {
+      try {
+        if (entry != null) entry.remove();
+      } catch (Throwable t) {
+        log.warn(t);
+      }
+      
       throw new ResponseContextException(500, e);
     }
   }
@@ -170,17 +251,21 @@
     String resourceName = EncodingUtil.sanitize(title);
     entry.setProperty(RESOURCE_NAME, resourceName);
 
-    entry.setProperty(SUMMARY, summary);
-
+    if (summary != null) {
+      entry.setProperty(SUMMARY, summary);
+    }
+    
     Calendar upCal = Calendar.getInstance();
     upCal.setTime(updated);
     entry.setProperty(UPDATED, upCal);
 
-    for (Person p : authors) {
-      Node addNode = entry.addNode(AUTHOR);
-      addNode.setProperty(AUTHOR_EMAIL, p.getEmail());
-      addNode.setProperty(AUTHOR_LANGUAGE, p.getLanguage());
-      addNode.setProperty(AUTHOR_NAME, p.getName());
+    if (authors != null) {
+      for (Person p : authors) {
+        Node addNode = entry.addNode(AUTHOR);
+        addNode.setProperty(AUTHOR_EMAIL, p.getEmail());
+        addNode.setProperty(AUTHOR_LANGUAGE, p.getLanguage());
+        addNode.setProperty(AUTHOR_NAME, p.getName());
+      }
     }
 
     if (content != null) {
@@ -191,8 +276,6 @@
       entry.setProperty(SUMMARY, summary);
     }
     
-    session.save();
-    
     return entry;
   }
 
@@ -295,7 +378,7 @@
   }
 
   @Override
-  public Object getContent(Node entry) throws ResponseContextException {
+  public Object getContent(Node entry, RequestContext request) throws ResponseContextException
{
     return getStringOrNull(entry, CONTENT);
   }
 
@@ -355,15 +438,36 @@
       throw new ResponseContextException(500, e);
     }
   }
+  
+  public String getMediaName(Node entry) throws ResponseContextException {
+    return getName(entry);
+  }
 
+  public InputStream getMediaStream(Node entry) throws ResponseContextException {
+    try {
+      Value value = getValueOrNull(entry, MEDIA);
+      
+      if (value == null) return null;
+      
+      return value.getStream();
+    } catch (PathNotFoundException e) {
+      return null;
+    } catch (RepositoryException e) {
+      throw new ResponseContextException(500, e);
+    }
+    
+  }
+  
   @Override
   public String getName(Node entry) throws ResponseContextException {
     return getStringOrNull(entry, RESOURCE_NAME);
   }
 
   @Override
-  public String getSummary(Node entry) {
-    return getStringOrNull(entry, SUMMARY);
+  public Text getSummary(Node entry, RequestContext request) {
+    Text summary = request.getAbdera().getFactory().newSummary();
+    summary.setText(getStringOrNull(entry, SUMMARY));
+    return summary;
   }
 
   @Override

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java?rev=591521&r1=591520&r2=591521&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionProvider.java
Fri Nov  2 17:26:52 2007
@@ -74,7 +74,7 @@
   
   public abstract T createEntry(String title, IRI id, String summary, Date updated, List<Person>
authors, Content content, RequestContext request) throws ResponseContextException;
   
-  public T createMediaEntry(MimeType mimeType, String slug, InputStream inputStream) throws
ResponseContextException {
+  public T createMediaEntry(MimeType mimeType, String slug, InputStream inputStream, RequestContext
request) throws ResponseContextException {
     throw new UnsupportedOperationException();
   }
   
@@ -99,13 +99,15 @@
 
   public abstract String getAuthor() throws ResponseContextException;
 
-  public abstract List<Person> getAuthors(T entry, RequestContext request) throws ResponseContextException;
+  public List<Person> getAuthors(T entry, RequestContext request) throws ResponseContextException
{
+    return null;
+  }
   
   public String getBaseMediaIri() {
     return baseMediaIri;
   }
   
-  public abstract Object getContent(T entry) throws ResponseContextException;
+  public abstract Object getContent(T entry, RequestContext request) throws ResponseContextException;
   
   // GET, POST, PUT, DELETE
   
@@ -167,7 +169,7 @@
           if (isMediaEntry(entryObj)) {
             addMediaContent(entryIri, e, entryObj);
           } else {
-            addContent(e, entryObj);
+            addContent(e, entryObj, request);
           }
         }
       }
@@ -193,8 +195,8 @@
    * @return
    */
   protected ResponseContext createErrorResponse(ResponseContextException e) {
-    if (log.isDebugEnabled()) {
-      log.debug("A ResponseException was thrown.", e);
+    if (log.isInfoEnabled()) {
+      log.info("A ResponseException was thrown.", e);
     } else if (e.getResponseContext() instanceof EmptyResponseContext 
       && ((EmptyResponseContext) e.getResponseContext()).getStatus() >= 500) {
       log.warn("A ResponseException was thrown.", e);
@@ -240,11 +242,11 @@
 
     return ctx;
   }
-  public String getMediaName(T entry) {
+  public String getMediaName(T entry) throws ResponseContextException {
     throw new UnsupportedOperationException();
   }
 
-  public InputStream getMediaStream(T gdoc) {
+  public InputStream getMediaStream(T entry) throws ResponseContextException {
     throw new UnsupportedOperationException();
   }
   
@@ -256,7 +258,7 @@
 
   public abstract Date getUpdated(T entry) throws ResponseContextException;
 
-  public boolean isMediaEntry(T entry) {
+  public boolean isMediaEntry(T entry) throws ResponseContextException {
     return false;
   }
 
@@ -314,8 +316,8 @@
                                    List<Person> authors, String summary, 
                                    Content content, RequestContext request) throws ResponseContextException;
 
-  protected void addContent(Entry e, T doc) throws ResponseContextException {
-    Object content = getContent(doc);
+  protected void addContent(Entry e, T doc, RequestContext request) throws ResponseContextException
{
+    Object content = getContent(doc, request);
 
     if (content instanceof Content) {
       e.setContentElement((Content)content);
@@ -333,26 +335,23 @@
     e.setUpdated(getUpdated(entryObj));
     
     List<Person> authors = getAuthors(entryObj, request);
-    if (authors == null || authors.size() == 0) {
-      log.warn("You must specify at least one author for the entry!");
-      throw new ResponseContextException(500);
-    }
-    
-    for (Person a : authors) {
-      e.addAuthor(a);
+    if (authors != null) {
+      for (Person a : authors) {
+        e.addAuthor(a);
+      }
     }
     
-    String s = getSummary(entryObj);
-    if (s != null) {
-      e.setSummary(s);
+    Text t = getSummary(entryObj, request);
+    if (t != null) {
+      e.setSummaryElement(t);
     }
   }
 
-  public String getSummary(T entry) {
+  public Text getSummary(T entry, RequestContext request) throws ResponseContextException
{
     return null;
   }
 
-  protected void addMediaContent(IRI entryBaseIri, Entry entry, T doc) {
+  protected void addMediaContent(IRI entryBaseIri, Entry entry, T doc) throws ResponseContextException
{
     String name = getMediaName(doc);
     IRI mediaIri = getMediaIRI(entryBaseIri, name);
     mediaIri = entryBaseIri.resolve(mediaIri);
@@ -389,7 +388,8 @@
 
   protected ResponseContext createMediaEntry(RequestContext request) {
     try {
-      T doc = createMediaEntry(request.getContentType(), request.getSlug(), request.getInputStream());
+      T doc = createMediaEntry(request.getContentType(), request.getSlug(), 
+                               request.getInputStream(), request);
 
       IRI baseIri = resolveBase(request);
       IRI entryIri = getEntryBaseFromFeedIRI(baseIri);
@@ -485,7 +485,7 @@
     if (isMediaEntry(entryObj)) {
       addMediaContent(feedIri, entry, entryObj);
     } else {
-      addContent(entry, entryObj);
+      addContent(entry, entryObj, request);
     }
 
     return entry;

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java?rev=591521&r1=591520&r2=591521&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractWorkspaceProvider.java
Fri Nov  2 17:26:52 2007
@@ -143,8 +143,8 @@
      * @return
      */
     protected ResponseContext createErrorResponse(ResponseContextException e) {
-      if (log.isDebugEnabled()) {
-        log.debug("A ResponseException was thrown.", e);
+      if (log.isInfoEnabled()) {
+        log.info("A ResponseException was thrown.", e);
       } else if (e.getResponseContext() instanceof EmptyResponseContext 
         && ((EmptyResponseContext) e.getResponseContext()).getStatus() >= 500)
{
         log.warn("A ResponseException was thrown.", e);
@@ -187,7 +187,8 @@
       try {
         IRI entryBaseIri = resolveBase(request).resolve("../");
         provider = getCollectionProvider(entryBaseIri, request);
-  
+        provider.begin(request);
+        
         return provider.getMedia(request);
       } catch (ResponseContextException e) {
         response = createErrorResponse(e);

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java?rev=591521&r1=591520&r2=591521&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ProviderSupport.java
Fri Nov  2 17:26:52 2007
@@ -312,7 +312,6 @@
           id.toString().trim().length() == 0 ||
           !id.isAbsolute()) return false;
       if (entry.getTitle() == null) return false;
-      if (entry.getAuthor() == null) return false;
       if (entry.getUpdated() == null) return false;
       Content content = entry.getContentElement();
       if (content == null) {

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java?rev=591521&r1=591520&r2=591521&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/ResponseContextException.java
Fri Nov  2 17:26:52 2007
@@ -39,7 +39,18 @@
     this(new EmptyResponseContext(responseCode), t);
   }
 
+  public ResponseContextException(String msg, int responseCode) {
+    this.responseContext = new EmptyResponseContext(responseCode);
+    this.responseContext.setStatusText(msg);
+  }
+
   public AbstractResponseContext getResponseContext() {
     return responseContext;
   }
+
+  @Override
+  public String getMessage() {
+    return responseContext.getStatusText();
+  }
+  
 }

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java?rev=591521&r1=591520&r2=591521&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/CustomerContentProvider.java
Fri Nov  2 17:26:52 2007
@@ -17,7 +17,6 @@
 import org.apache.abdera.model.Person;
 import org.apache.abdera.protocol.server.impl.AbstractCollectionProvider;
 import org.apache.abdera.protocol.server.impl.ResponseContextException;
-import sun.security.pkcs.ContentInfo;
 
 public class CustomerContentProvider extends AbstractCollectionProvider<Customer> {
   private static final String ID_PREFIX = "urn:acme:customer:";
@@ -78,7 +77,7 @@
     
   }
 
-  public Object getContent(Customer entry) {
+  public Object getContent(Customer entry, RequestContext request) {
     Content content = factory.newContent();
     Element customerEl = factory.newElement(new QName("customer"));
     customerEl.setAttributeValue(new QName("name"), entry.getName());



Mime
View raw message