You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/08/30 16:33:05 UTC

svn commit: r1378958 - in /chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache...

Author: fmui
Date: Thu Aug 30 14:33:04 2012
New Revision: 1378958

URL: http://svn.apache.org/viewvc?rev=1378958&view=rev
Log:
CMIS-566: Support for Last-Modified and If-Modified-Since HTTP headers

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/LastModifiedContentStream.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/LastModifiedContentStreamImpl.java   (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/LastModifiedContentStream.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/LastModifiedContentStream.java?rev=1378958&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/LastModifiedContentStream.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/LastModifiedContentStream.java Thu Aug 30 14:33:04 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+package org.apache.chemistry.opencmis.commons.data;
+
+import java.util.GregorianCalendar;
+
+/**
+ * Content stream with last modified date.
+ */
+public interface LastModifiedContentStream extends ContentStream {
+
+    /**
+     * Returns the last modified date of this content.
+     * 
+     * @return the date of the last content modification
+     */
+    GregorianCalendar getLastModified();
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/LastModifiedContentStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/LastModifiedContentStreamImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/LastModifiedContentStreamImpl.java?rev=1378958&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/LastModifiedContentStreamImpl.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/LastModifiedContentStreamImpl.java Thu Aug 30 14:33:04 2012
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+package org.apache.chemistry.opencmis.commons.impl.dataobjects;
+
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.util.GregorianCalendar;
+
+import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream;
+
+/**
+ * Content stream data with last modified date implementation.
+ */
+public class LastModifiedContentStreamImpl extends ContentStreamImpl implements LastModifiedContentStream {
+
+    private static final long serialVersionUID = 1L;
+
+    private GregorianCalendar lastModified;
+
+    /**
+     * Constructor.
+     */
+    public LastModifiedContentStreamImpl() {
+    }
+
+    /**
+     * Constructor.
+     */
+    public LastModifiedContentStreamImpl(String filename, BigInteger length, String mimetype, InputStream stream,
+            GregorianCalendar lastModified) {
+        super(filename, length, mimetype, stream);
+        setLastModified(lastModified);
+    }
+
+    public GregorianCalendar getLastModified() {
+        return lastModified;
+    }
+
+    public void setLastModified(GregorianCalendar lastModified) {
+        this.lastModified = lastModified;
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/LastModifiedContentStreamImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java?rev=1378958&r1=1378957&r2=1378958&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java Thu Aug 30 14:33:04 2012
@@ -59,6 +59,10 @@ import java.io.BufferedOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.math.BigInteger;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -68,6 +72,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.AllowableActions;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.FailedToDeleteData;
+import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
 import org.apache.chemistry.opencmis.commons.data.Properties;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
@@ -445,6 +450,38 @@ public final class ObjectService {
             throw new CmisRuntimeException("Content stream is null!");
         }
 
+        // check if Last-Modified header should be set
+        if (content instanceof LastModifiedContentStream) {
+            GregorianCalendar lastModified = ((LastModifiedContentStream) content).getLastModified();
+            if (lastModified != null) {
+                long lastModifiedSecs = (long) Math.floor((double) lastModified.getTimeInMillis() / 1000);
+
+                SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
+
+                String modifiedSinceStr = request.getHeader("If-Modified-Since");
+                if (modifiedSinceStr != null) {
+                    try {
+                        Date modifiedSince = sdf.parse(modifiedSinceStr);
+                        long modifiedSinceSecs = (long) Math.floor((double) modifiedSince.getTime() / 1000);
+
+                        if (modifiedSinceSecs >= lastModifiedSecs) {
+                            // close stream
+                            content.getStream().close();
+
+                            // send not modified status code
+                            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+                            response.setContentLength(0);
+                            return;
+                        }
+                    } catch (ParseException e) {
+                        // ignore
+                    }
+                }
+
+                response.setHeader("Last-Modified", sdf.format(lastModifiedSecs * 1000));
+            }
+        }
+
         String contentType = content.getMimeType();
         if (contentType == null) {
             contentType = MEDIATYPE_OCTETSTREAM;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java?rev=1378958&r1=1378957&r2=1378958&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java Thu Aug 30 14:33:04 2012
@@ -26,13 +26,15 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigInteger;
+import java.util.GregorianCalendar;
 import java.util.List;
 
 import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 
-public class ContentStreamDataImpl implements ContentStream {
+public class ContentStreamDataImpl implements LastModifiedContentStream {
 
     private int fLength;
 
@@ -41,6 +43,8 @@ public class ContentStreamDataImpl imple
     private String fFileName;
 
     private byte[] fContent;
+    
+    private GregorianCalendar fLastModified;
 
     private long fStreamLimitOffset;
 
@@ -114,6 +118,14 @@ public class ContentStreamDataImpl imple
         }
     }
 
+    public void setLastModified(GregorianCalendar lastModified) {
+        this.fLastModified = lastModified;
+    }
+    
+    public GregorianCalendar getLastModified() {
+        return fLastModified;
+    }
+    
     public ContentStream getCloneWithLimits(long offset, long length) {
         ContentStreamDataImpl clone = new ContentStreamDataImpl(0);
         clone.fFileName = fFileName;
@@ -122,13 +134,14 @@ public class ContentStreamDataImpl imple
         clone.fMimeType = fMimeType;
         clone.fStreamLimitOffset = offset;
         clone.fStreamLimitLength = length;
+        clone.fLastModified = fLastModified;
         return clone;
     }
 
     public final byte[] getBytes() {
         return fContent;
     }
-    
+
     public List<CmisExtensionElement> getExtensions() {
         return null;
     }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java?rev=1378958&r1=1378957&r2=1378958&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java Thu Aug 30 14:33:04 2012
@@ -31,7 +31,6 @@ import org.apache.chemistry.opencmis.inm
 import org.apache.chemistry.opencmis.inmemory.ConfigurationSettings;
 import org.apache.chemistry.opencmis.inmemory.FilterParser;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Document;
-import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -78,6 +77,7 @@ public class DocumentImpl extends Abstra
                 mimeType = "application/octet-stream"; // use as fallback
             }
             fContent.setMimeType(mimeType);
+            fContent.setLastModified(getModifiedAt());
             try {
                 fContent.setContent(content.getStream());
             } catch (IOException e) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java?rev=1378958&r1=1378957&r2=1378958&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java Thu Aug 30 14:33:04 2012
@@ -71,6 +71,7 @@ public class DocumentVersionImpl extends
             fContent = new ContentStreamDataImpl(MAX_CONTENT_SIZE_KB == null ? 0 : MAX_CONTENT_SIZE_KB);
             fContent.setFileName(content.getFileName());
             fContent.setMimeType(content.getMimeType());
+            fContent.setLastModified(getModifiedAt());
             try {
                 fContent.setContent(content.getStream());
             } catch (IOException e) {