chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r802144 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/ chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ chemis...
Date Fri, 07 Aug 2009 19:09:59 GMT
Author: fguillaume
Date: Fri Aug  7 19:09:58 2009
New Revision: 802144

URL: http://svn.apache.org/viewvc?rev=802144&view=rev
Log:
clean up type URLs, allowed document creation with content stream

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/pom.xml
    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/APPObjectEntry.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryWriter.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ObjectEntryWriter.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/resources/xmlwriter-output.xml
    incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/pom.xml?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/pom.xml Fri Aug  7 19:09:58
2009
@@ -59,6 +59,10 @@
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>junit</groupId>

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=802144&r1=802143&r2=802144&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
Fri Aug  7 19:09:58 2009
@@ -54,6 +54,10 @@
     }
 
     public ContentStream getContentStream() {
+        ContentStream contentStream = entry.getContentStream();
+        if (contentStream != APPObjectEntry.REMOTE_CONTENT_STREAM) {
+            return contentStream;
+        }
         String url = entry.getLink(AtomPub.LINK_EDIT_MEDIA);
         return url == null ? null : new APPContentStream(url);
     }
@@ -123,7 +127,7 @@
 
     public void setContentStream(ContentStream contentStream)
             throws IOException {
-        throw new UnsupportedOperationException("Not yet implemented");
+        entry.setContentStream(contentStream);
     }
 
     public void cancelCheckOut() {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntry.java
Fri Aug  7 19:09:58 2009
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -32,23 +33,31 @@
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMIS;
 import org.apache.chemistry.ChangeInfo;
+import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Property;
 import org.apache.chemistry.PropertyDefinition;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.ValueAdapter;
 import org.apache.chemistry.atompub.client.stax.XmlProperty;
+import org.apache.chemistry.impl.simple.SimpleContentStream;
 import org.apache.chemistry.xml.stax.XMLWriter;
+import org.apache.commons.io.IOUtils;
 
 /**
  *
  */
 public class APPObjectEntry implements ObjectEntry {
 
+    protected static final ContentStream REMOTE_CONTENT_STREAM = new SimpleContentStream(
+            new byte[0], null, null);
+
     protected APPConnection connection;
 
     protected Map<String, XmlProperty> properties;
 
+    protected ContentStream localContentStream = REMOTE_CONTENT_STREAM;
+
     protected Map<QName, Boolean> allowableActions;
 
     protected final List<String> links;
@@ -184,6 +193,16 @@
         }
     }
 
+    protected void setContentStream(ContentStream contentStream) {
+        localContentStream = contentStream;
+        setValue(Property.CONTENT_STREAM_FILE_NAME,
+                contentStream == null ? null : contentStream.getFileName());
+    }
+
+    protected ContentStream getContentStream() {
+        return localContentStream;
+    }
+
     // public Document getDocument() {
     // return (APPDocument) getConnector().getObject(
     // new ReadContext(getConnection(), getType()), getEditLink());
@@ -211,6 +230,50 @@
                 + ')';
     }
 
+    public void writeContentTo(XMLWriter xw) throws IOException {
+        if (localContentStream == null
+                || localContentStream == REMOTE_CONTENT_STREAM) {
+            xw.element("content").content("");
+            return;
+        }
+        xw.element("content");
+        String mimeType = localContentStream.getMimeType();
+        // String mimeTypeLower = mimeType.toLowerCase();
+        if (mimeType.startsWith("text/")) {
+            // Atom requires this to be sent in clear text
+            String encoding = "UTF-8";
+            mimeType = mimeType.replace(" ", "");
+            if (mimeType.indexOf(';') > 0) {
+                String[] strings = mimeType.split(";");
+                mimeType = strings[0];
+                if (strings[1].startsWith("encoding=")) {
+                    encoding = strings[1].substring("encoding=".length());
+                }
+            }
+            if (mimeType.equals("text/plain")) {
+                mimeType = "text";
+            } else if (mimeType.equals("text/html")) {
+                mimeType = "html";
+            }
+            xw.attr("type", mimeType);
+            // TODO stream bytes
+            byte[] array = IOUtils.toByteArray(localContentStream.getStream());
+            String text;
+            try {
+                text = new String(array, encoding);
+            } catch (UnsupportedEncodingException e) {
+                text = new String(array, "ISO-8859-1");
+            }
+            xw.econtent(text);
+            // } else if (mimeTypeLower.endsWith("+xml")
+            // || mimeTypeLower.endsWith("/xml")) {
+            // ...
+        } else {
+            // encode as base64
+            xw.contentBase64(localContentStream.getStream());
+        }
+    }
+
     public void writeObjectTo(XMLWriter xw) throws IOException {
         xw.element(AtomPubCMIS.OBJECT);
         xw.start();

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryWriter.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryWriter.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryWriter.java
Fri Aug  7 19:09:58 2009
@@ -28,6 +28,12 @@
 public class APPObjectEntryWriter extends ObjectEntryWriter {
 
     @Override
+    protected void writeContent(ObjectEntry object, XMLWriter xw)
+            throws IOException {
+        ((APPObjectEntry) object).writeContentTo(xw);
+    }
+
+    @Override
     protected void writeCmisObject(ObjectEntry object, XMLWriter xw)
             throws IOException {
         ((APPObjectEntry) object).writeObjectTo(xw);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ObjectEntryWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ObjectEntryWriter.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ObjectEntryWriter.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ObjectEntryWriter.java
Fri Aug  7 19:09:58 2009
@@ -58,7 +58,7 @@
             }
             xw.element("title").content(title);
             xw.element("updated").content(new Date());
-            xw.element("content").content(""); // TODO fake content for now
+            writeContent(object, xw);
             writeCmisObject(object, xw);
             xw.end();
             xw.end();
@@ -70,6 +70,9 @@
         }
     }
 
+    protected abstract void writeContent(ObjectEntry object, XMLWriter xw)
+            throws IOException;
+
     protected abstract void writeCmisObject(ObjectEntry object, XMLWriter xw)
             throws IOException;
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
Fri Aug  7 19:09:58 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.chemistry.atompub.server;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
@@ -58,6 +59,7 @@
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.abdera.ObjectElement;
+import org.apache.chemistry.impl.simple.SimpleContentStream;
 import org.apache.chemistry.util.GregorianCalendar;
 
 /**
@@ -204,6 +206,39 @@
         if (entry == null /* || !ProviderHelper.isValidEntry(entry) TODO XXX TCK */) {
             return new EmptyResponseContext(400);
         }
+        InputStream stream;
+        String mimeType;
+        try {
+            org.apache.abdera.model.Content.Type ct = entry.getContentType();
+            switch (ct) {
+            case TEXT:
+                mimeType = "text/plain";
+                break;
+            case HTML:
+                mimeType = "text/html";
+                break;
+            case XHTML:
+                mimeType = "application/xhtml+xml";
+                break;
+            case XML:
+                mimeType = "application/xml";
+                break;
+            case MEDIA:
+                mimeType = entry.getContentMimeType().toString();
+                break;
+            default:
+                throw new AssertionError(ct.toString());
+            }
+            if (ct == org.apache.abdera.model.Content.Type.MEDIA) {
+                stream = entry.getContentStream();
+            } else {
+                stream = new ByteArrayInputStream(entry.getContent().getBytes(
+                        "UTF-8"));
+            }
+        } catch (IOException e1) {
+            return createErrorResponse(new ResponseContextException(
+                    "cannot get stream", 500));
+        }
 
         Element obb = entry.getFirstChild(AtomPubCMIS.OBJECT);
         ObjectElement objectElement = new ObjectElement(obb, repository);
@@ -248,7 +283,14 @@
         ObjectId objectId;
         switch (type.getBaseType()) {
         case DOCUMENT:
-            ContentStream contentStream = null; // TODO
+            String filename = (String) properties.get(Property.CONTENT_STREAM_FILE_NAME);
+            ContentStream contentStream;
+            try {
+                contentStream = new SimpleContentStream(stream, mimeType,
+                        filename);
+            } catch (IOException e) {
+                return createErrorResponse(new ResponseContextException(500, e));
+            }
             VersioningState versioningState = null; // TODO
             objectId = spi.createDocument(properties, folderId, contentStream,
                     versioningState);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
Fri Aug  7 19:09:58 2009
@@ -69,8 +69,8 @@
                 "objectid");
         targetResolver.setPattern("/allowableactions/([^/?]+)",
                 TargetType.TYPE_ENTRY, "objectid"); // XXX entry?
-        targetResolver.setPattern("/type/([^/?]+)(\\?.*)?", TargetType.TYPE_ENTRY,
-                "typeid");
+        targetResolver.setPattern("/type/([^/?]+)(\\?.*)?",
+                TargetType.TYPE_ENTRY, "typeid");
         targetResolver.setPattern("/path/([^?]*)", TargetType.TYPE_ENTRY,
                 "path");
 
@@ -103,9 +103,10 @@
                 TargetType.TYPE_COLLECTION, "objectid");
         targetResolver.setPattern("/policies/([^/?]+)",
                 TargetType.TYPE_COLLECTION, "objectid");
-        // ?
         targetResolver.setPattern("/types/([^/?]+)",
                 TargetType.TYPE_COLLECTION, "typeid");
+        targetResolver.setPattern("/typesdescendants(\\?.*)?",
+                TargetType.TYPE_COLLECTION);
         targetResolver.setPattern("/typesdescendants/([^/?]*)(\\?.*)?",
                 TargetType.TYPE_COLLECTION, "typeid");
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServiceResponse.java
Fri Aug  7 19:09:58 2009
@@ -84,7 +84,7 @@
             sw.writeAttribute("type", "application/cmistree+xml");
             sw.writeAttribute("rel", AtomPubCMIS.LINK_TYPES_DESCENDANTS);
             String tdurl = request.absoluteUrlFor(TargetType.TYPE_SERVICE, null);
-            tdurl = tdurl.replaceFirst("/repository$", "/typesdescendants/"); // XXX
+            tdurl = tdurl.replaceFirst("/repository$", "/typesdescendants"); // XXX
             sw.writeAttribute("href", tdurl);
             sw.endElement();
             // URI templates

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
Fri Aug  7 19:09:58 2009
@@ -37,15 +37,18 @@
     public CollectionAdapter getCollectionAdapter(RequestContext request) {
         Repository repository = provider.getRepository();
         String uri = request.getUri().toString();
+        if (uri.indexOf('?') > 0) {
+            uri = uri.substring(0, uri.lastIndexOf('?'));
+        }
         String spath = request.getTargetBasePath();
         String path = spath == null ? uri : uri.substring(spath.length());
         String paths = path + '/';
-        if (paths.startsWith("/types/") || paths.startsWith("/types?")) {
+        if (paths.startsWith("/types/")) {
             return new CMISTypesCollection(null, null, repository);
         }
         if (paths.startsWith("/typesdescendants/")) {
             String id = request.getTarget().getParameter("typeid");
-            if (id.equals("")) {
+            if ("".equals(id)) {
                 id = null;
             }
             return new CMISTypesCollection(AtomPubCMIS.COL_TYPES_DESCENDANTS,

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
Fri Aug  7 19:09:58 2009
@@ -157,6 +157,28 @@
 
     @GET
     @Produces(AtomPub.MEDIA_TYPE_ATOM_FEED)
+    @Path("typesdescendants")
+    public Response doGetTypesDescendantsAll() {
+        return getAbderaFeed(1);
+    }
+
+    @GET
+    @Produces(AtomPub.MEDIA_TYPE_ATOM_FEED)
+    @Path("typesdescendants/{typeid}")
+    public Response doGetTypesDescendantsTyped() {
+        return getAbderaFeed(2);
+    }
+
+    @GET
+    @Produces(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
+    @Path("type/{typeid}")
+    public Response doGetType() {
+        // typeid decoded by Abdera getCollectionAdapter
+        return getAbderaEntry(2);
+    }
+
+    @GET
+    @Produces(AtomPub.MEDIA_TYPE_ATOM_FEED)
     @Path("children/{objectid}")
     public Response doGetChildren() {
         // objectid decoded by Abdera getCollectionAdapter

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/pom.xml Fri Aug  7 19:09:58 2009
@@ -38,6 +38,10 @@
       <artifactId>commons-logging</artifactId>
     </dependency>
     <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
       <groupId>stax</groupId>
       <artifactId>stax-api</artifactId>
     </dependency>

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
Fri Aug  7 19:09:58 2009
@@ -413,6 +413,25 @@
         }
         SimpleData data = new SimpleData(typeId, type.getBaseType());
         data.putAll(properties);
+        // TODO check presence allowed
+        if (contentStream != null) {
+            data.put(Property.CONTENT_STREAM_LENGTH,
+                    Integer.valueOf((int) contentStream.getLength())); // TODO-Long
+            String mt = contentStream.getMimeType();
+            if (mt != null) {
+                data.put(Property.CONTENT_STREAM_MIME_TYPE, mt);
+            }
+            String fn = contentStream.getFileName();
+            if (fn != null) {
+                data.put(Property.CONTENT_STREAM_FILE_NAME, fn);
+            }
+            try {
+                data.put(SimpleProperty.CONTENT_BYTES_KEY,
+                        SimpleContentStream.getBytes(contentStream.getStream()));
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
         if (folder != null) {
             data.put(Property.PARENT_ID, folder.getId());
         }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/xml/stax/XMLWriter.java
Fri Aug  7 19:09:58 2009
@@ -20,6 +20,7 @@
 package org.apache.chemistry.xml.stax;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -30,6 +31,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.chemistry.util.GregorianCalendar;
+import org.apache.commons.codec.binary.Base64;
 
 // This file contains code from org.apache.commons.betwixt.XMLUtils
 /**
@@ -236,6 +238,42 @@
         return this;
     }
 
+    public XMLWriter contentBase64(InputStream in) throws IOException {
+        start();
+        depth--;
+
+        byte[] buf = new byte[3 * 19];
+        char[] chars = new char[4 * 19];
+        while (true) {
+            int n = in.read(buf);
+            if (n == 0) {
+                break;
+            }
+            byte[] bytes;
+            if (n < buf.length) {
+                bytes = new byte[n];
+                System.arraycopy(buf, 0, bytes, 0, n);
+            } else {
+                bytes = buf;
+            }
+            byte[] encoded = Base64.encodeBase64(bytes);
+            for (int i = 0; i < encoded.length; i++) {
+                chars[i] = (char) encoded[i];
+            }
+            writer.write(chars, 0, encoded.length);
+            writer.write("\n");
+            if (n < buf.length) {
+                break;
+            }
+        }
+
+        Element elem = pop(); // close myself
+        writer.write("</");
+        writer.write(elem.name);
+        writer.write(">");
+        return this;
+    }
+
     public XMLWriter econtent(String text) throws IOException {
         return content(escapeBodyValue(text));
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/java/org/apache/chemistry/xml/stax/TestXMLWriter.java
Fri Aug  7 19:09:58 2009
@@ -17,6 +17,7 @@
  */
 package org.apache.chemistry.xml.stax;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -53,10 +54,30 @@
     public void testXMLWriter() throws Exception {
         Writer w = new StringWriter();
         XMLWriter x = new XMLWriter(w, 2);
-        x.start().element("service").xmlns("cmis", CMIS_NS).attr("version",
-                "1.0").start().element("ws1").attr("k", "v").content("test").element(
-                "ws2").attr("key", "val").start().element(OBJECT).end().element(
-                "ws3").attr("key", "val").end().end();
+        String s = "abcdefghij";
+        InputStream in = new ByteArrayInputStream(
+                (s + s + s + s + s + s + s).getBytes("UTF-8"));
+        x.start();
+        {
+            x.element("service");
+            x.xmlns("cmis", CMIS_NS).attr("version", "1.0");
+            x.start();
+            {
+                x.element("ws1").attr("k", "v").content("test");
+                x.element("ws2").attr("key", "val");
+                x.start();
+                {
+                    x.element(OBJECT);
+                }
+                x.end();
+                x.element("ws3").attr("key", "val");
+                x.element("ws4").eattr("key", "a&b<c>d\"e'f");
+                x.element("ws5").econtent("a&b<c>d\"e'f");
+                x.element("ws6").contentBase64(in);
+            }
+            x.end();
+        }
+        x.end();
         String actual = w.toString();
 
         InputStream stream = this.getClass().getClassLoader().getResourceAsStream(

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/resources/xmlwriter-output.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/resources/xmlwriter-output.xml?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/resources/xmlwriter-output.xml
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/test/resources/xmlwriter-output.xml
Fri Aug  7 19:09:58 2009
@@ -5,4 +5,9 @@
     <cmis:object/>
   </ws2>
   <ws3 key="val"/>
+  <ws4 key="a&amp;b&lt;c&gt;d&quot;e&apos;f"/>
+  <ws5>a&amp;b&lt;c&gt;d"e'f</ws5>
+  <ws6>YWJjZGVmZ2hpamFiY2RlZmdoaWphYmNkZWZnaGlqYWJjZGVmZ2hpamFiY2RlZmdoaWphYmNkZWZn
+aGlqYWJjZGVmZ2hpag==
+</ws6>
 </service>

Modified: incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml?rev=802144&r1=802143&r2=802144&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml Fri Aug  7 19:09:58 2009
@@ -142,6 +142,11 @@
         <version>1.4</version>
       </dependency>
       <dependency>
+        <groupId>commons-codec</groupId>
+        <artifactId>commons-codec</artifactId>
+        <version>1.3</version>
+      </dependency>
+      <dependency>
         <groupId>commons-collections</groupId>
         <artifactId>commons-collections</artifactId>
         <version>3.1</version>

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=802144&r1=802143&r2=802144&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
Fri Aug  7 19:09:58 2009
@@ -38,6 +38,7 @@
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.SPI;
 import org.apache.chemistry.Type;
+import org.apache.chemistry.impl.simple.SimpleContentStream;
 import org.apache.chemistry.util.GregorianCalendar;
 import org.apache.commons.io.IOUtils;
 
@@ -259,7 +260,7 @@
         assertEquals(array.length, cs.getLength());
     }
 
-    public void testNewDocument() {
+    public void testNewDocument() throws Exception {
         Folder root = conn.getRootFolder();
         assertNull(getDocumentChild(root));
         Document doc = root.newDocument("doc");
@@ -273,6 +274,12 @@
         assertEquals("GregorianCalendar(2009-07-14T12:00:00.000+05:00)",
                 cal.toString());
         doc.setValue("date", cal);
+        // content stream
+        String blobText = "Another file...\n";
+        byte[] blobBytes = blobText.getBytes("UTF-8");
+        ContentStream cs = new SimpleContentStream(blobBytes, "text/plain",
+                "mydoc.txt");
+        doc.setContentStream(cs);
         assertNull(doc.getId()); // not yet saved
         doc.save();
         String id = doc.getId();
@@ -289,6 +296,17 @@
         assertEquals("mytitle", doc.getString("title"));
         Calendar cal2 = doc.getDateTime("date");
         assertEquals(cal.toString(), cal2.toString());
+        cs = doc.getContentStream();
+        assertNotNull(cs);
+        assertTrue(cs.getLength() != 0);
+        assertEquals("mydoc.txt", cs.getFileName());
+        assertEquals("text/plain", cs.getMimeType());
+        assertNotNull(cs.getStream());
+        InputStream in = doc.getContentStream().getStream();
+        assertNotNull(in);
+        byte[] array = IOUtils.toByteArray(in);
+        assertEquals(blobBytes.length, array.length);
+        assertEquals(blobBytes.length, cs.getLength());
     }
 
     @SuppressWarnings("null")



Mime
View raw message