Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 38485 invoked from network); 7 Aug 2009 19:10:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Aug 2009 19:10:19 -0000 Received: (qmail 37346 invoked by uid 500); 7 Aug 2009 19:10:26 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 37312 invoked by uid 500); 7 Aug 2009 19:10:26 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 37302 invoked by uid 99); 7 Aug 2009 19:10:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Aug 2009 19:10:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Aug 2009 19:10:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 56A5B238886C; Fri, 7 Aug 2009 19:10:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: chemistry-commits@incubator.apache.org From: fguillaume@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090807191000.56A5B238886C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ commons-collections commons-collections + + commons-io + commons-io + junit 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 properties; + protected ContentStream localContentStream = REMOTE_CONTENT_STREAM; + protected Map allowableActions; protected final List 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 @@ commons-logging + commons-codec + commons-codec + + stax stax-api 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(""); + 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&bd\"e'f"); + x.element("ws5").econtent("a&bd\"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 @@ + + a&b<c>d"e'f + YWJjZGVmZ2hpamFiY2RlZmdoaWphYmNkZWZnaGlqYWJjZGVmZ2hpamFiY2RlZmdoaWphYmNkZWZn +aGlqYWJjZGVmZ2hpag== + 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 @@ 1.4 + commons-codec + commons-codec + 1.3 + + commons-collections commons-collections 3.1 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")