You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/03/12 13:07:43 UTC

svn commit: r1455504 - 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...

Author: fmui
Date: Tue Mar 12 12:07:42 2013
New Revision: 1455504

URL: http://svn.apache.org/r1455504
Log:
CMIS 1.1 AtomPub, step 5

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.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-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyData.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.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/AtomPubParser.java?rev=1455504&r1=1455503&r2=1455504&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java Tue Mar 12 12:07:42 2013
@@ -56,7 +56,6 @@ import java.util.Map;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomAcl;
@@ -72,6 +71,8 @@ import org.apache.chemistry.opencmis.cli
 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.XMLConstants;
+import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAccessControlListType;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAllowableActionsType;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
@@ -108,8 +109,7 @@ public class AtomPubParser {
      * Parses the stream.
      */
     public void parse() throws Exception {
-        XMLInputFactory factory = XMLInputFactory.newInstance();
-        XMLStreamReader parser = factory.createXMLStreamReader(stream);
+        XMLStreamReader parser = XMLUtils.createParser(stream);
 
         try {
             while (true) {
@@ -144,7 +144,7 @@ public class AtomPubParser {
                     }
                 }
 
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
@@ -179,7 +179,7 @@ public class AtomPubParser {
     private static ServiceDoc parseServiceDoc(XMLStreamReader parser) throws Exception {
         ServiceDoc result = new ServiceDoc();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         while (true) {
             int event = parser.getEventType();
@@ -190,15 +190,15 @@ public class AtomPubParser {
                     if (TAG_WORKSPACE.equals(name.getLocalPart())) {
                         result.addWorkspace(parseWorkspace(parser));
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
                 } else {
-                    skip(parser);
+                    XMLUtils.skip(parser);
                 }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
@@ -213,7 +213,7 @@ public class AtomPubParser {
     private static RepositoryWorkspace parseWorkspace(XMLStreamReader parser) throws Exception {
         RepositoryWorkspace workspace = new RepositoryWorkspace();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         while (true) {
             int event = parser.getEventType();
@@ -230,13 +230,13 @@ public class AtomPubParser {
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return workspace;
     }
@@ -247,7 +247,7 @@ public class AtomPubParser {
     private AtomFeed parseFeed(XMLStreamReader parser) throws Exception {
         AtomFeed result = new AtomFeed();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         while (true) {
             int event = parser.getEventType();
@@ -260,27 +260,27 @@ public class AtomPubParser {
                     } else if (TAG_ENTRY.equals(name.getLocalPart())) {
                         result.addEntry(parseEntry(parser));
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
                 } else if (Constants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
                     if (TAG_NUM_ITEMS.equals(name.getLocalPart())) {
                         result.addElement(parseBigInteger(parser));
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
                 } else {
-                    skip(parser);
+                    XMLUtils.skip(parser);
                 }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return result;
     }
@@ -291,7 +291,7 @@ public class AtomPubParser {
     private AtomEntry parseEntry(XMLStreamReader parser) throws Exception {
         AtomEntry result = new AtomEntry();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         // walk through all tags in entry
         while (true) {
@@ -316,13 +316,13 @@ public class AtomPubParser {
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return result;
     }
@@ -357,7 +357,7 @@ public class AtomPubParser {
                 return parseText(parser);
             } else if (TAG_TYPE.equals(name.getLocalPart())) {
                 // workaround for old Chemistry code - ignore the type namespace
-                String typeAttr = parser.getAttributeValue(Constants.NAMESPACE_XSI, "type");
+                String typeAttr = parser.getAttributeValue(XMLConstants.NAMESPACE_XSI, "type");
                 if (typeAttr == null) {
                     return unmarshalElement(parser, CmisTypeDefinitionType.class);
                 } else if (typeAttr.endsWith(ATTR_DOCUMENT_TYPE)) {
@@ -382,7 +382,7 @@ public class AtomPubParser {
         }
 
         // we don't know it - skip it
-        skip(parser);
+        XMLUtils.skip(parser);
 
         return null;
     }
@@ -406,7 +406,7 @@ public class AtomPubParser {
         AtomElement result = null;
         QName childName = parser.getName();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         // walk through the children tag
         while (true) {
@@ -418,21 +418,21 @@ public class AtomPubParser {
                     if (TAG_FEED.equals(name.getLocalPart())) {
                         result = new AtomElement(childName, parseFeed(parser));
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
                 } else {
-                    skip(parser);
+                    XMLUtils.skip(parser);
                 }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return result;
     }
@@ -460,7 +460,7 @@ public class AtomPubParser {
         }
 
         // we don't know it - skip it
-        skip(parser);
+        XMLUtils.skip(parser);
 
         return null;
     }
@@ -474,7 +474,7 @@ public class AtomPubParser {
 
         result.put("href", parser.getAttributeValue(null, "href"));
 
-        next(parser);
+        XMLUtils.next(parser);
 
         while (true) {
             int event = parser.getEventType();
@@ -484,18 +484,18 @@ public class AtomPubParser {
                         && TAG_COLLECTION_TYPE.equals(tagName.getLocalPart())) {
                     result.put("collectionType", readText(parser));
                 } else {
-                    skip(parser);
+                    XMLUtils.skip(parser);
                 }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return new AtomElement(name, result);
     }
@@ -507,7 +507,7 @@ public class AtomPubParser {
         QName name = parser.getName();
         Map<String, String> result = new HashMap<String, String>();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         while (true) {
             int event = parser.getEventType();
@@ -519,21 +519,21 @@ public class AtomPubParser {
                     } else if (TAG_TEMPLATE_TYPE.equals(tagName.getLocalPart())) {
                         result.put("type", readText(parser));
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
                 } else {
-                    skip(parser);
+                    XMLUtils.skip(parser);
                 }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return new AtomElement(name, result);
     }
@@ -557,7 +557,7 @@ public class AtomPubParser {
         }
 
         // skip enclosed tags, if any
-        skip(parser);
+        XMLUtils.skip(parser);
 
         return new AtomElement(name, result);
     }
@@ -578,7 +578,7 @@ public class AtomPubParser {
         }
 
         // skip enclosed tags, if any
-        skip(parser);
+        XMLUtils.skip(parser);
 
         return new AtomElement(name, result);
     }
@@ -605,7 +605,7 @@ public class AtomPubParser {
     private static String readText(XMLStreamReader parser) throws Exception {
         StringBuilder sb = new StringBuilder();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         while (true) {
             int event = parser.getEventType();
@@ -620,42 +620,13 @@ public class AtomPubParser {
                 throw new RuntimeException("Unexpected tag: " + parser.getName());
             }
 
-            if (!next(parser)) {
+            if (!XMLUtils.next(parser)) {
                 break;
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return sb.toString();
     }
-
-    /**
-     * Skips a tag or subtree.
-     */
-    private static void skip(XMLStreamReader parser) throws Exception {
-        int level = 1;
-        while (next(parser)) {
-            int event = parser.getEventType();
-            if (event == XMLStreamReader.START_ELEMENT) {
-                level++;
-            } else if (event == XMLStreamReader.END_ELEMENT) {
-                level--;
-                if (level == 0) {
-                    break;
-                }
-            }
-        }
-
-        next(parser);
-    }
-
-    private static boolean next(XMLStreamReader parser) throws Exception {
-        if (parser.hasNext()) {
-            parser.next();
-            return true;
-        }
-
-        return false;
-    }
 }

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=1455504&r1=1455503&r2=1455504&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 Tue Mar 12 12:07:42 2013
@@ -227,6 +227,26 @@ public class XMLUtils {
     }
 
     /**
+     * Skips a tag or subtree.
+     */
+    public static void skip(XMLStreamReader parser) throws Exception {
+        int level = 1;
+        while (next(parser)) {
+            int event = parser.getEventType();
+            if (event == XMLStreamReader.START_ELEMENT) {
+                level++;
+            } else if (event == XMLStreamReader.END_ELEMENT) {
+                level--;
+                if (level == 0) {
+                    break;
+                }
+            }
+        }
+
+        next(parser);
+    }
+
+    /**
      * Moves the parser to the next start element.
      * 
      * @return <code>true</code> if another start element has been found,
@@ -261,16 +281,20 @@ public class XMLUtils {
             if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else if (event == XMLStreamReader.CHARACTERS) {
-                String s = parser.getText();
-                if (s != null) {
+                int len = parser.getTextLength();
+                if (len > 0) {
                     if (sb == null) {
                         sb = new StringBuilder();
                     }
 
-                    if (sb.length() + s.length() > maxLength) {
+                    if (sb.length() + len > maxLength) {
                         throw new CmisInvalidArgumentException("String limit exceeded!");
                     }
-                    sb.append(s);
+
+                    char[] chars = parser.getTextCharacters();
+                    int offset = parser.getTextStart();
+
+                    sb.append(chars, offset, len);
                 }
             } else if (event == XMLStreamReader.START_ELEMENT) {
                 throw new RuntimeException("Unexpected tag: " + parser.getName());

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.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/XMLWalker.java?rev=1455504&r1=1455503&r2=1455504&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java Tue Mar 12 12:07:42 2013
@@ -138,7 +138,7 @@ public abstract class XMLWalker<T> {
                 }
 
                 children.add(handleExtensionLevel(parser, level + 1));
-                
+
                 continue;
             }
 
@@ -157,7 +157,7 @@ public abstract class XMLWalker<T> {
     }
 
     protected <S> List<S> addToList(List<S> list, S value) {
-        if (list == null) {
+        if (list == null || list.isEmpty()) {
             list = new ArrayList<S>();
         }
         list.add(value);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyData.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyData.java?rev=1455504&r1=1455503&r2=1455504&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyData.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyData.java Tue Mar 12 12:07:42 2013
@@ -36,7 +36,7 @@ public abstract class AbstractPropertyDa
     private String localName;
     private String queryName;
 
-    private List<T> values;
+    private List<T> values = Collections.emptyList();
 
     public String getId() {
         return id;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.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/AtomEntryParser.java?rev=1455504&r1=1455503&r2=1455504&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java Tue Mar 12 12:07:42 2013
@@ -28,11 +28,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -47,14 +44,13 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
 import org.apache.chemistry.opencmis.commons.impl.Base64;
-import org.apache.chemistry.opencmis.commons.impl.Constants;
-import org.apache.chemistry.opencmis.commons.impl.Converter;
-import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
+import org.apache.chemistry.opencmis.commons.impl.XMLConstants;
+import org.apache.chemistry.opencmis.commons.impl.XMLConstraints;
+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.impl.dataobjects.PropertiesImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
-import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
 import org.apache.chemistry.opencmis.server.shared.CappedInputStream;
 import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
 
@@ -197,7 +193,8 @@ public class AtomEntryParser {
             if (event == XMLStreamReader.START_ELEMENT) {
                 QName name = parser.getName();
 
-                if (Constants.NAMESPACE_ATOM.equals(name.getNamespaceURI()) && (TAG_ENTRY.equals(name.getLocalPart()))) {
+                if (XMLConstants.NAMESPACE_ATOM.equals(name.getNamespaceURI())
+                        && (TAG_ENTRY.equals(name.getLocalPart()))) {
                     parseEntry(parser);
                     break;
                 } else {
@@ -205,7 +202,7 @@ public class AtomEntryParser {
                 }
             }
 
-            if (!next(parser)) {
+            if (!XMLUtils.next(parser)) {
                 break;
             }
         }
@@ -219,7 +216,7 @@ public class AtomEntryParser {
     private void parseEntry(XMLStreamReader parser) throws Exception {
         String atomTitle = null;
 
-        next(parser);
+        XMLUtils.next(parser);
 
         // walk through all tags in entry
         while (true) {
@@ -227,29 +224,29 @@ public class AtomEntryParser {
             if (event == XMLStreamReader.START_ELEMENT) {
                 QName name = parser.getName();
 
-                if (Constants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
+                if (XMLConstants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
                     if (TAG_OBJECT.equals(name.getLocalPart())) {
                         parseObject(parser);
                     } else if (TAG_CONTENT.equals(name.getLocalPart())) {
                         parseCmisContent(parser);
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
-                } else if (Constants.NAMESPACE_ATOM.equals(name.getNamespaceURI())) {
+                } else if (XMLConstants.NAMESPACE_ATOM.equals(name.getNamespaceURI())) {
                     if (TAG_CONTENT.equals(name.getLocalPart())) {
                         parseAtomContent(parser);
                     } else if (TAG_TITLE.equals(name.getLocalPart())) {
-                        atomTitle = readText(parser);
+                        atomTitle = XMLUtils.readText(parser, XMLConstraints.MAX_STRING_LENGTH);
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
                 } else {
-                    skip(parser);
+                    XMLUtils.skip(parser);
                 }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
@@ -266,12 +263,7 @@ public class AtomEntryParser {
      * Parses a CMIS object.
      */
     private void parseObject(XMLStreamReader parser) throws Exception {
-        Unmarshaller u = JaxBHelper.createUnmarshaller();
-        JAXBElement<CmisObjectType> jaxbObject = u.unmarshal(parser, CmisObjectType.class);
-
-        if (jaxbObject != null) {
-            object = Converter.convert(jaxbObject.getValue());
-        }
+        object = XMLConverter.convertObject(parser);
     }
 
     /**
@@ -292,7 +284,7 @@ public class AtomEntryParser {
             } else if (ATTR_SRC.equals(attrName.getLocalPart())) {
                 if (ignoreAtomContentSrc) {
                     atomContentStream = null;
-                    skip(parser);
+                    XMLUtils.skip(parser);
                     return;
                 }
                 throw new CmisNotSupportedException("External content not supported!");
@@ -331,7 +323,7 @@ public class AtomEntryParser {
     private void parseCmisContent(XMLStreamReader parser) throws Exception {
         cmisContentStream = new ContentStreamImpl();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         // walk through all tags in content
         while (true) {
@@ -339,76 +331,46 @@ public class AtomEntryParser {
             if (event == XMLStreamReader.START_ELEMENT) {
                 QName name = parser.getName();
 
-                if (Constants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
+                if (XMLConstants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
                     if (TAG_MEDIATYPE.equals(name.getLocalPart())) {
-                        cmisContentStream.setMimeType(readText(parser));
+                        cmisContentStream.setMimeType(XMLUtils.readText(parser, XMLConstraints.MAX_STRING_LENGTH));
                     } else if (TAG_BASE64.equals(name.getLocalPart())) {
                         ThresholdOutputStream ths = readBase64(parser);
                         cmisContentStream.setStream(ths.getInputStream());
                         cmisContentStream.setLength(BigInteger.valueOf(ths.getSize()));
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
-                } else if (Constants.NAMESPACE_APACHE_CHEMISTRY.equals(name.getNamespaceURI())) {
+                } else if (XMLConstants.NAMESPACE_APACHE_CHEMISTRY.equals(name.getNamespaceURI())) {
                     if (TAG_FILENAME.equals(name.getLocalPart())) {
-                        cmisContentStream.setFileName(readText(parser));
+                        cmisContentStream.setFileName(XMLUtils.readText(parser, XMLConstraints.MAX_STRING_LENGTH));
                     } else {
-                        skip(parser);
+                        XMLUtils.skip(parser);
                     }
                 } else {
-                    skip(parser);
+                    XMLUtils.skip(parser);
                 }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
         }
 
-        next(parser);
-    }
-
-    /**
-     * Parses a tag that contains text.
-     */
-    private String readText(XMLStreamReader parser) throws Exception {
-        StringBuilder sb = new StringBuilder();
-
-        next(parser);
-
-        while (true) {
-            int event = parser.getEventType();
-            if (event == XMLStreamReader.END_ELEMENT) {
-                break;
-            } else if (event == XMLStreamReader.CHARACTERS) {
-                String s = parser.getText();
-                if (s != null) {
-                    sb.append(s);
-                }
-            } else if (event == XMLStreamReader.START_ELEMENT) {
-                throw new RuntimeException("Unexpected tag: " + parser.getName());
-            }
-
-            if (!next(parser)) {
-                break;
-            }
-        }
-
-        next(parser);
-
-        return sb.toString();
+        XMLUtils.next(parser);
     }
 
     /**
      * Parses a tag that contains content bytes.
      */
     private ThresholdOutputStream readContentBytes(XMLStreamReader parser) throws Exception {
+        @SuppressWarnings("resource")
         ThresholdOutputStream bufferStream = new ThresholdOutputStream(tempDir, memoryThreshold, maxContentSize,
                 encrypt);
 
-        next(parser);
+        XMLUtils.next(parser);
 
         while (true) {
             int event = parser.getEventType();
@@ -425,12 +387,12 @@ public class AtomEntryParser {
                 throw new RuntimeException("Unexpected tag: " + parser.getName());
             }
 
-            if (!next(parser)) {
+            if (!XMLUtils.next(parser)) {
                 break;
             }
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return bufferStream;
     }
@@ -444,7 +406,7 @@ public class AtomEntryParser {
         @SuppressWarnings("resource")
         Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream, Base64.DECODE);
 
-        next(parser);
+        XMLUtils.next(parser);
 
         try {
             while (true) {
@@ -452,17 +414,21 @@ public class AtomEntryParser {
                 if (event == XMLStreamReader.END_ELEMENT) {
                     break;
                 } else if (event == XMLStreamReader.CHARACTERS) {
-                    String s = parser.getText();
-                    if (s != null) {
-                        byte[] bytes = s.getBytes("US-ASCII");
-                        b64stream.write(bytes);
-                        cappedStream.deductBytes(bytes.length);
+                    int len = parser.getTextLength();
+                    if (len > 0) {
+                        char[] chars = parser.getTextCharacters();
+                        int offset = parser.getTextStart();
+                        for (int i = 0; i < len; i++) {
+                            // it's base64/ASCII
+                            b64stream.write(chars[offset + i]);
+                        }
+                        cappedStream.deductBytes(len);
                     }
                 } else if (event == XMLStreamReader.START_ELEMENT) {
                     throw new RuntimeException("Unexpected tag: " + parser.getName());
                 }
 
-                if (!next(parser)) {
+                if (!XMLUtils.next(parser)) {
                     break;
                 }
             }
@@ -473,7 +439,7 @@ public class AtomEntryParser {
             throw e;
         }
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return bufferStream;
     }
@@ -490,7 +456,7 @@ public class AtomEntryParser {
 
         // copy subtree
         int level = 1;
-        while (next(parser)) {
+        while (XMLUtils.next(parser)) {
             int event = parser.getEventType();
             if (event == XMLStreamReader.START_ELEMENT) {
                 copyStartElement(parser, writer);
@@ -514,7 +480,7 @@ public class AtomEntryParser {
 
         writer.writeEndDocument();
 
-        next(parser);
+        XMLUtils.next(parser);
 
         return out.toByteArray();
     }
@@ -603,37 +569,4 @@ public class AtomEntryParser {
             writer.writeNamespace(prefix, namespaceUri);
         }
     }
-
-    /**
-     * Skips a tag or subtree.
-     */
-    private static void skip(XMLStreamReader parser) throws Exception {
-        int level = 1;
-        while (next(parser)) {
-            int event = parser.getEventType();
-            if (event == XMLStreamReader.START_ELEMENT) {
-                level++;
-            } else if (event == XMLStreamReader.END_ELEMENT) {
-                level--;
-                if (level == 0) {
-                    break;
-                }
-            }
-        }
-
-        next(parser);
-    }
-
-    private static boolean next(XMLStreamReader parser) throws Exception {
-        if (parser.hasNext()) {
-            try {
-                parser.next();
-            } catch (XMLStreamException e) {
-                return false;
-            }
-            return true;
-        }
-
-        return false;
-    }
 }
\ No newline at end of file

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java?rev=1455504&r1=1455503&r2=1455504&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java Tue Mar 12 12:07:42 2013
@@ -92,9 +92,11 @@ public class TypeValidator {
         public void validate(PropertyDefinition<T> propDef, PropertyData<T> prop) {
 
             // check general constraints for all property types
-            if (propDef.getCardinality() == Cardinality.SINGLE && prop.getValues().size() > 1) {
-                throw new CmisConstraintException("The property with id " + propDef.getId()
+            if (propDef.getCardinality() == Cardinality.SINGLE) {
+                if(prop.getValues() != null && prop.getValues().size() > 1) {
+                    throw new CmisConstraintException("The property with id " + propDef.getId()
                         + " is single valued, but multiple values are passed " + prop.getValues());
+                }
             }
 
             if (propDef.getChoices() != null && propDef.getChoices().size() > 0) {