chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1454457 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/ma...
Date Fri, 08 Mar 2013 16:45:38 GMT
Author: fmui
Date: Fri Mar  8 16:45:37 2013
New Revision: 1454457

URL: http://svn.apache.org/r1454457
Log:
CMIS 1.1 AtomPub, step 3

Removed:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AclDocument.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AllowableActionsDocument.java
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AclService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java?rev=1454457&r1=1454456&r2=1454457&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
Fri Mar  8 16:45:37 2013
@@ -52,7 +52,7 @@ import org.apache.chemistry.opencmis.com
  */
 public class AtomEntryWriter {
 
-    private static final int BUFFER_SIZE = 64 * 1024;
+    private static final int BUFFER_SIZE = 8 * 1024;
 
     private final ObjectData object;
     private final CmisVersion cmisVersion;
@@ -159,12 +159,18 @@ public class AtomEntryWriter {
     private void writeContent(XMLStreamWriter writer) throws Exception {
         Base64.InputStream b64stream = new Base64.InputStream(stream, Base64.ENCODE);
 
-        byte[] buffer = new byte[BUFFER_SIZE * 3 / 4];
+        char[] buffer = new char[BUFFER_SIZE];
+        int pos = 0;
         int b;
-        while ((b = b64stream.read(buffer)) > -1) {
-            if (b > 0) {
-                writer.writeCharacters(new String(buffer, 0, b, "US-ASCII"));
+        while ((b = b64stream.read()) > -1) {
+            buffer[pos++] = (char) (b & 0xFF);
+            if (pos == buffer.length) {
+                writer.writeCharacters(buffer, 0, buffer.length);
+                pos = 0;
             }
         }
+        if (pos > 0) {
+            writer.writeCharacters(buffer, 0, pos);
+        }
     }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.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/XMLConverter.java?rev=1454457&r1=1454456&r2=1454457&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
Fri Mar  8 16:45:37 2013
@@ -377,9 +377,7 @@ public class XMLConverter {
         }
 
         writer.writeStartElement(namespace, TAG_TYPE);
-        if (writer.getNamespaceContext().getNamespaceURI(NAMESPACE_XSI) == null) {
-            writer.writeNamespace(PREFIX_XSI, NAMESPACE_XSI);
-        }
+        writer.writeNamespace(PREFIX_XSI, NAMESPACE_XSI);
 
         if (source.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT) {
             writer.writeAttribute(PREFIX_XSI, NAMESPACE_XSI, "type", PREFIX_CMIS + ":" +
ATTR_DOCUMENT_TYPE);
@@ -675,23 +673,7 @@ public class XMLConverter {
             writer.writeEndElement();
         }
         if (source.getAllowableActions() != null) {
-            AllowableActions allowableActions = source.getAllowableActions();
-
-            writer.writeStartElement(PREFIX_CMIS, TAG_OBJECT_ALLOWABLE_ACTIONS, NAMESPACE_CMIS);
-
-            if (allowableActions.getAllowableActions() != null) {
-                for (Action action : Action.values()) {
-                    if (action == Action.CAN_CREATE_ITEM && cmisVersion == CmisVersion.CMIS_1_0)
{
-                        continue;
-                    }
-                    if (allowableActions.getAllowableActions().contains(action)) {
-                        XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, action.value(),
Boolean.TRUE);
-                    }
-                }
-            }
-
-            writeExtensions(writer, allowableActions);
-            writer.writeEndElement();
+            writeAllowableActions(writer, cmisVersion, false, source.getAllowableActions());
         }
         if (source.getRelationships() != null) {
             for (ObjectData rel : source.getRelationships()) {
@@ -712,40 +694,7 @@ public class XMLConverter {
             writer.writeEndElement();
         }
         if (source.getAcl() != null) {
-            Acl acl = source.getAcl();
-
-            writer.writeStartElement(PREFIX_CMIS, TAG_OBJECT_ACL, NAMESPACE_CMIS);
-
-            if (acl.getAces() != null) {
-                for (Ace ace : acl.getAces()) {
-                    if (ace != null) {
-                        writer.writeStartElement(PREFIX_CMIS, TAG_ACL_PERMISSISONS, NAMESPACE_CMIS);
-
-                        if (ace.getPrincipal() != null) {
-                            Principal principal = ace.getPrincipal();
-
-                            writer.writeStartElement(PREFIX_CMIS, TAG_ACE_PRINCIPAL, NAMESPACE_CMIS);
-
-                            XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, TAG_ACE_PRINCIPAL_ID,
principal.getId());
-
-                            writeExtensions(writer, principal);
-                            writer.writeEndElement();
-                        }
-                        if (ace.getPermissions() != null) {
-                            for (String perm : ace.getPermissions()) {
-                                XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, TAG_ACE_PERMISSIONS,
perm);
-                            }
-                        }
-                        XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, TAG_ACE_IS_DIRECT,
ace.isDirect());
-
-                        writeExtensions(writer, ace);
-                        writer.writeEndElement();
-                    }
-                }
-            }
-
-            writeExtensions(writer, acl);
-            writer.writeEndElement();
+            writeAcl(writer, cmisVersion, false, source.getAcl());
         }
         XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, TAG_OBJECT_EXACT_ACL, source.isExactAcl());
         if (source.getPolicyIds() != null) {
@@ -875,6 +824,79 @@ public class XMLConverter {
         writer.writeEndElement();
     }
 
+    public static void writeAllowableActions(XMLStreamWriter writer, CmisVersion cmisVersion,
boolean root,
+            AllowableActions source) throws XMLStreamException {
+        if (source == null) {
+            return;
+        }
+
+        if (root) {
+            writer.writeStartElement(NAMESPACE_CMIS, "allowableActions");
+            writer.writeNamespace(PREFIX_CMIS, NAMESPACE_CMIS);
+        } else {
+            writer.writeStartElement(PREFIX_CMIS, TAG_OBJECT_ALLOWABLE_ACTIONS, NAMESPACE_CMIS);
+        }
+
+        if (source.getAllowableActions() != null) {
+            for (Action action : Action.values()) {
+                if (action == Action.CAN_CREATE_ITEM && cmisVersion == CmisVersion.CMIS_1_0)
{
+                    continue;
+                }
+                if (source.getAllowableActions().contains(action)) {
+                    XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, action.value(), Boolean.TRUE);
+                }
+            }
+        }
+
+        writeExtensions(writer, source);
+        writer.writeEndElement();
+    }
+
+    public static void writeAcl(XMLStreamWriter writer, CmisVersion cmisVersion, boolean
root, Acl source)
+            throws XMLStreamException {
+        if (source == null) {
+            return;
+        }
+
+        if (root) {
+            writer.writeStartElement(NAMESPACE_CMIS, "acl");
+            writer.writeNamespace(PREFIX_CMIS, NAMESPACE_CMIS);
+        } else {
+            writer.writeStartElement(PREFIX_CMIS, TAG_OBJECT_ACL, NAMESPACE_CMIS);
+        }
+
+        if (source.getAces() != null) {
+            for (Ace ace : source.getAces()) {
+                if (ace != null) {
+                    writer.writeStartElement(PREFIX_CMIS, TAG_ACL_PERMISSISONS, NAMESPACE_CMIS);
+
+                    if (ace.getPrincipal() != null) {
+                        Principal principal = ace.getPrincipal();
+
+                        writer.writeStartElement(PREFIX_CMIS, TAG_ACE_PRINCIPAL, NAMESPACE_CMIS);
+
+                        XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, TAG_ACE_PRINCIPAL_ID,
principal.getId());
+
+                        writeExtensions(writer, principal);
+                        writer.writeEndElement();
+                    }
+                    if (ace.getPermissions() != null) {
+                        for (String perm : ace.getPermissions()) {
+                            XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, TAG_ACE_PERMISSIONS,
perm);
+                        }
+                    }
+                    XMLUtils.write(writer, PREFIX_CMIS, NAMESPACE_CMIS, TAG_ACE_IS_DIRECT,
ace.isDirect());
+
+                    writeExtensions(writer, ace);
+                    writer.writeEndElement();
+                }
+            }
+        }
+
+        writeExtensions(writer, source);
+        writer.writeEndElement();
+    }
+
     // -------------------------
     // --- extension writers ---
     // -------------------------

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.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/XMLUtils.java?rev=1454457&r1=1454456&r2=1454457&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java
Fri Mar  8 16:45:37 2013
@@ -83,7 +83,7 @@ public class XMLUtils {
     public static void startEntryDocument(XMLStreamWriter writer, boolean hasContent) throws
XMLStreamException {
         startXmlDocument(writer);
 
-        writer.writeStartElement(XMLConstants.NAMESPACE_ATOM, "entry");
+        writer.writeStartElement(XMLConstants.PREFIX_ATOM, "entry", XMLConstants.NAMESPACE_ATOM);
         writer.writeNamespace(XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM);
         writer.writeNamespace(XMLConstants.PREFIX_CMIS, XMLConstants.NAMESPACE_CMIS);
         writer.writeNamespace(XMLConstants.PREFIX_RESTATOM, XMLConstants.NAMESPACE_RESTATOM);
@@ -99,7 +99,7 @@ public class XMLUtils {
             throws XMLStreamException {
         startXmlDocument(writer);
 
-        writer.writeStartElement(XMLConstants.NAMESPACE_ATOM, "feed");
+        writer.writeStartElement(XMLConstants.PREFIX_ATOM, "feed", XMLConstants.NAMESPACE_ATOM);
         writer.writeNamespace(XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM);
         writer.writeNamespace(XMLConstants.PREFIX_CMIS, XMLConstants.NAMESPACE_CMIS);
         writer.writeNamespace(XMLConstants.PREFIX_RESTATOM, XMLConstants.NAMESPACE_RESTATOM);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AclService.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/atompub/AclService.java?rev=1454457&r1=1454456&r2=1454457&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AclService.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AclService.java
Fri Mar  8 16:45:37 2013
@@ -23,17 +23,24 @@ import static org.apache.chemistry.openc
 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
 
+import java.io.OutputStream;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.chemistry.opencmis.commons.data.Acl;
 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
+import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
+import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAccessControlListType;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
@@ -67,8 +74,7 @@ public class AclService {
         response.setContentType(Constants.MEDIATYPE_ACL);
 
         // write XML
-        AclDocument aclDocument = new AclDocument();
-        aclDocument.writeAcl(acl, response.getOutputStream());
+        writeAclXML(acl, context.getCmisVersion(), response.getOutputStream());
     }
 
     /**
@@ -106,7 +112,13 @@ public class AclService {
         response.setContentType(Constants.MEDIATYPE_ACL);
 
         // write XML
-        AclDocument aclDocument = new AclDocument();
-        aclDocument.writeAcl(acl, response.getOutputStream());
+        writeAclXML(acl, context.getCmisVersion(), response.getOutputStream());
+    }
+
+    private static void writeAclXML(Acl acl, CmisVersion cmisVersion, OutputStream out) throws
XMLStreamException {
+        XMLStreamWriter writer = XMLUtils.createWriter(out);
+        XMLUtils.startXmlDocument(writer);
+        XMLConverter.writeAcl(writer, cmisVersion, true, acl);
+        XMLUtils.endXmlDocument(writer);
     }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/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/atompub/ObjectService.java?rev=1454457&r1=1454456&r2=1454457&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/ObjectService.java
Fri Mar  8 16:45:37 2013
@@ -38,6 +38,7 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.AllowableActions;
@@ -55,6 +56,8 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.MimeHelper;
 import org.apache.chemistry.opencmis.commons.impl.ReturnVersion;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
+import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
@@ -393,8 +396,10 @@ public final class ObjectService {
         response.setContentType(Constants.MEDIATYPE_ALLOWABLEACTION);
 
         // write XML
-        AllowableActionsDocument allowableActionsDocument = new AllowableActionsDocument();
-        allowableActionsDocument.writeAllowableActions(allowableActions, response.getOutputStream());
+        XMLStreamWriter writer = XMLUtils.createWriter(response.getOutputStream());
+        XMLUtils.startXmlDocument(writer);
+        XMLConverter.writeAllowableActions(writer, context.getCmisVersion(), true, allowableActions);
+        XMLUtils.endXmlDocument(writer);
     }
 
     /**



Mime
View raw message