chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r893784 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-tests/src/main/java/org/apache/chemistry/test/
Date Thu, 24 Dec 2009 16:24:45 GMT
Author: fguillaume
Date: Thu Dec 24 16:24:27 2009
New Revision: 893784

URL: http://svn.apache.org/viewvc?rev=893784&view=rev
Log:
Implemented APPObject.getContentStream

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=893784&r1=893783&r2=893784&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
Thu Dec 24 16:24:27 2009
@@ -510,6 +510,10 @@
 
     public ContentStream getContentStream(ObjectId object,
             String contentStreamId) throws IOException {
+        if (contentStreamId != null) {
+            throw new UnsupportedOperationException(
+                    "Cannot get non-default content stream: " + contentStreamId);
+        }
         APPObjectEntry current = getObjectEntry(object);
         ContentStream cs = current.getContentStream();
         if (cs != APPObjectEntry.REMOTE_CONTENT_STREAM) {
@@ -710,9 +714,9 @@
         throw new UnsupportedOperationException();
     }
 
-    public ObjectId checkIn(ObjectId document, Map<String, Serializable> properties,
-            ContentStream contentStream, boolean major,
-            String comment) {
+    public ObjectId checkIn(ObjectId document,
+            Map<String, Serializable> properties, ContentStream contentStream,
+            boolean major, String comment) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java?rev=893784&r1=893783&r2=893784&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java
Thu Dec 24 16:24:27 2009
@@ -19,109 +19,23 @@
 package org.apache.chemistry.atompub.client;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.Collection;
 
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.Document;
-import org.apache.chemistry.Property;
 import org.apache.chemistry.Type;
-import org.apache.chemistry.atompub.client.connector.Connector;
-import org.apache.chemistry.atompub.client.connector.Request;
-import org.apache.chemistry.atompub.client.connector.Response;
 
 /**
  *
  */
 public class APPDocument extends APPObject implements Document {
 
-    protected static final String UNINITIALIZED_STRING = "__UNINITIALIZED__\0\0\0";
-
-    protected static final URI UNINITIALIZED_URI;
-    static {
-        try {
-            UNINITIALIZED_URI = new URI("http://__UNINITIALIZED__/%00%00%00");
-        } catch (URISyntaxException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-    }
-
     public APPDocument(APPObjectEntry entry, Type type) {
         super(entry, type);
     }
 
-    public ContentStream getContentStream() {
-        ContentStream contentStream = entry.getContentStream();
-        if (contentStream != APPObjectEntry.REMOTE_CONTENT_STREAM) {
-            return contentStream;
-        }
-        String url = entry.getContentHref();
-        return url == null ? null : new APPContentStream(url);
-    }
-
-    /**
-     * ContentStream class that fetches a remote URL when needed.
-     */
-    public class APPContentStream implements ContentStream {
-
-        protected final Connector connector;
-
-        protected final String url;
-
-        protected String mimeType = UNINITIALIZED_STRING;
-
-        protected String filename = UNINITIALIZED_STRING;
-
-        protected URI uri = UNINITIALIZED_URI;
-
-        protected long length = -1;
-
-        public APPContentStream(String url) {
-            connector = APPDocument.this.entry.connection.connector;
-            this.url = url;
-        }
-
-        public String getMimeType() {
-            if (mimeType == UNINITIALIZED_STRING) {
-                mimeType = getString(Property.CONTENT_STREAM_MIME_TYPE);
-            }
-            return mimeType;
-        }
-
-        public String getFileName() {
-            if (filename == UNINITIALIZED_STRING) {
-                filename = getString(Property.CONTENT_STREAM_FILE_NAME);
-            }
-            return filename;
-        }
-
-        public long getLength() {
-            if (length == -1) {
-                Integer value = getInteger(Property.CONTENT_STREAM_LENGTH);
-                return length = value == null ? -1 : value.longValue();
-            }
-            return length;
-        }
-
-        public InputStream getStream() throws IOException {
-            try {
-                Response resp = connector.get(new Request(url));
-                if (!resp.isOk()) {
-                    throw new IOException("Error: " + resp.getStatusCode()
-                            + " fetching: " + url);
-                }
-                if (length == -1) {
-                    // get the "official" length if available
-                    length = resp.getStreamLength();
-                }
-                return resp.getStream();
-            } catch (ContentManagerException e) {
-                throw (IOException) (new IOException(
-                        "Could not fetch stream from: " + url).initCause(e));
-            }
-        }
+    public ContentStream getContentStream() throws IOException {
+        return getContentStream(null);
     }
 
     public void setContentStream(ContentStream contentStream)

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java?rev=893784&r1=893783&r2=893784&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObject.java
Thu Dec 24 16:24:27 2009
@@ -17,7 +17,11 @@
  */
 package org.apache.chemistry.atompub.client;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -43,6 +47,17 @@
  */
 public abstract class APPObject extends BaseObject {
 
+    protected static final String UNINITIALIZED_STRING = "__UNINITIALIZED__\0\0\0";
+
+    protected static final URI UNINITIALIZED_URI;
+    static {
+        try {
+            UNINITIALIZED_URI = new URI("http://__UNINITIALIZED__/%00%00%00");
+        } catch (URISyntaxException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
     protected APPObjectEntry entry;
 
     private final Type type;
@@ -92,9 +107,14 @@
         throw new UnsupportedOperationException();
     }
 
-    public ContentStream getContentStream(String contentStreamId) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+    public ContentStream getContentStream(String contentStreamId)
+            throws IOException {
+        ContentStream contentStream = entry.getContentStream();
+        if (contentStream != APPObjectEntry.REMOTE_CONTENT_STREAM) {
+            return contentStream;
+        }
+        String url = entry.getContentHref();
+        return url == null ? null : new APPContentStream(url);
     }
 
     /*
@@ -263,4 +283,66 @@
         }
     }
 
+    /**
+     * ContentStream class that fetches a remote URL when needed.
+     */
+    public class APPContentStream implements ContentStream {
+
+        protected final String url;
+
+        protected String mimeType = UNINITIALIZED_STRING;
+
+        protected String filename = UNINITIALIZED_STRING;
+
+        protected URI uri = UNINITIALIZED_URI;
+
+        protected long length = -1;
+
+        public APPContentStream(String url) {
+            this.url = url;
+        }
+
+        public String getMimeType() {
+            if (mimeType == UNINITIALIZED_STRING) {
+                mimeType = getString(Property.CONTENT_STREAM_MIME_TYPE);
+            }
+            return mimeType;
+        }
+
+        public String getFileName() {
+            if (filename == UNINITIALIZED_STRING) {
+                filename = getString(Property.CONTENT_STREAM_FILE_NAME);
+            }
+            return filename;
+        }
+
+        public long getLength() {
+            if (length == -1) {
+                Integer value = getInteger(Property.CONTENT_STREAM_LENGTH);
+                return length = value == null ? -1 : value.longValue();
+            }
+            return length;
+        }
+
+        // TODO this could save the stream in a side object and put it back in
+        // the entry's local content stream when done, to allow reuse
+        public InputStream getStream() throws IOException {
+            try {
+                Response resp = entry.connection.connector.get(new Request(url));
+                if (!resp.isOk()) {
+                    throw new IOException("Error: " + resp.getStatusCode()
+                            + " fetching: " + url);
+                }
+                if (length == -1) {
+                    // get the "official" length if available
+                    length = resp.getStreamLength();
+                }
+                return resp.getStream();
+            } catch (ContentManagerException e) {
+                throw (IOException) (new IOException(
+                        "Could not fetch stream from: " + url).initCause(e));
+            }
+        }
+    }
+
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=893784&r1=893783&r2=893784&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
Thu Dec 24 16:24:27 2009
@@ -403,6 +403,18 @@
         assertFalse(spi.hasContentStream(id));
     }
 
+    public void testContentStream() throws Exception {
+        ObjectEntry docId = spi.getObjectByPath("/folder 1/folder 2/doc 3",
+                null);
+        Document doc = (Document) conn.getObject(docId);
+        ContentStream cs = doc.getContentStream();
+        assertNotNull(cs);
+        InputStream in = cs.getStream();
+        assertNotNull(in);
+        String s = new String(IOUtils.toByteArray(in), "UTF-8");
+        assertEquals(BasicHelper.TEST_FILE_CONTENT, s);
+    }
+
     public void testDeleteSPI() throws Exception {
         ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null);
         spi.deleteObject(doc1, false);



Mime
View raw message