Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 172F911CB7 for ; Sun, 12 May 2013 13:14:43 +0000 (UTC) Received: (qmail 68489 invoked by uid 500); 12 May 2013 13:14:42 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 68378 invoked by uid 500); 12 May 2013 13:14:39 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 68332 invoked by uid 99); 12 May 2013 13:14:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 May 2013 13:14:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Sun, 12 May 2013 13:14:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6BC7E23888E4; Sun, 12 May 2013 13:14:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1481551 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/ chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apach... Date: Sun, 12 May 2013 13:14:15 -0000 To: commits@chemistry.apache.org From: fmui@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130512131415.6BC7E23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmui Date: Sun May 12 13:14:14 2013 New Revision: 1481551 URL: http://svn.apache.org/r1481551 Log: a few internal improvements Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/CmisEnumHelper.java Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.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-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java?rev=1481551&r1=1481550&r2=1481551&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java Sun May 12 13:14:14 2013 @@ -21,9 +21,9 @@ package org.apache.chemistry.opencmis.cl import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumMap; import java.util.EnumSet; import java.util.GregorianCalendar; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -98,7 +98,7 @@ public abstract class AbstractCmisObject this.session = session; this.objectType = objectType; this.secondaryTypes = null; - this.extensions = new HashMap>(); + this.extensions = new EnumMap>(ExtensionLevel.class); this.creationContext = new OperationContextImpl(context); this.refreshTimestamp = System.currentTimeMillis(); Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/CmisEnumHelper.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/CmisEnumHelper.java?rev=1481551&view=auto ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/CmisEnumHelper.java (added) +++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/CmisEnumHelper.java Sun May 12 13:14:14 2013 @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.commons.impl; + +import java.math.BigInteger; + +import org.apache.chemistry.opencmis.commons.enums.AclPropagation; +import org.apache.chemistry.opencmis.commons.enums.Action; +import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; +import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl; +import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges; +import org.apache.chemistry.opencmis.commons.enums.CapabilityContentStreamUpdates; +import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin; +import org.apache.chemistry.opencmis.commons.enums.CapabilityOrderBy; +import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery; +import org.apache.chemistry.opencmis.commons.enums.CapabilityRenditions; +import org.apache.chemistry.opencmis.commons.enums.Cardinality; +import org.apache.chemistry.opencmis.commons.enums.ChangeType; +import org.apache.chemistry.opencmis.commons.enums.CmisVersion; +import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed; +import org.apache.chemistry.opencmis.commons.enums.DateTimeResolution; +import org.apache.chemistry.opencmis.commons.enums.DecimalPrecision; +import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships; +import org.apache.chemistry.opencmis.commons.enums.PropertyType; +import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection; +import org.apache.chemistry.opencmis.commons.enums.SupportedPermissions; +import org.apache.chemistry.opencmis.commons.enums.UnfileObject; +import org.apache.chemistry.opencmis.commons.enums.Updatability; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; +import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; + +/** + * Helper methods to turn a value into a CMIS enum. + */ +public class CmisEnumHelper { + + @SuppressWarnings("unchecked") + public static > E fromValue(final String value, final Class clazz) { + if (value == null || value.length() == 0) { + return null; + } + + try { + if (Action.class == clazz) { + return (E) Action.fromValue(value); + } else if (BaseTypeId.class == clazz) { + return (E) BaseTypeId.fromValue(value); + } else if (CmisVersion.class == clazz) { + return (E) CmisVersion.fromValue(value); + } else if (IncludeRelationships.class == clazz) { + return (E) IncludeRelationships.fromValue(value); + } else if (ReturnVersion.class == clazz) { + return (E) ReturnVersion.fromValue(value); + } else if (VersioningState.class == clazz) { + return (E) VersioningState.fromValue(value); + } else if (RelationshipDirection.class == clazz) { + return (E) RelationshipDirection.fromValue(value); + } else if (AclPropagation.class == clazz) { + return (E) AclPropagation.fromValue(value); + } else if (UnfileObject.class == clazz) { + return (E) UnfileObject.fromValue(value); + } else if (PropertyType.class == clazz) { + return (E) PropertyType.fromValue(value); + } else if (Cardinality.class == clazz) { + return (E) Cardinality.fromValue(value); + } else if (Updatability.class == clazz) { + return (E) Updatability.fromValue(value); + } else if (ContentStreamAllowed.class == clazz) { + return (E) ContentStreamAllowed.fromValue(value); + } else if (DateTimeResolution.class == clazz) { + return (E) DateTimeResolution.fromValue(value); + } else if (ChangeType.class == clazz) { + return (E) ChangeType.fromValue(value); + } else if (SupportedPermissions.class == clazz) { + return (E) SupportedPermissions.fromValue(value); + } else if (CapabilityAcl.class == clazz) { + return (E) CapabilityAcl.fromValue(value); + } else if (CapabilityChanges.class == clazz) { + return (E) CapabilityChanges.fromValue(value); + } else if (CapabilityContentStreamUpdates.class == clazz) { + return (E) CapabilityContentStreamUpdates.fromValue(value); + } else if (CapabilityJoin.class == clazz) { + return (E) CapabilityJoin.fromValue(value); + } else if (CapabilityOrderBy.class == clazz) { + return (E) CapabilityOrderBy.fromValue(value); + } else if (CapabilityQuery.class == clazz) { + return (E) CapabilityQuery.fromValue(value); + } else if (CapabilityRenditions.class == clazz) { + return (E) CapabilityRenditions.fromValue(value); + } + } catch (IllegalArgumentException e) { + throw new CmisInvalidArgumentException("Invalid enum value '" + value + "'!"); + } + + throw new CmisRuntimeException(clazz.getSimpleName() + " is not a CMIS enum!"); + } + + @SuppressWarnings("unchecked") + public static > E fromValue(final BigInteger value, final Class clazz) { + if (value == null) { + return null; + } + + try { + if (DecimalPrecision.class == clazz) { + return (E) DecimalPrecision.fromValue(value); + } + } catch (IllegalArgumentException e) { + throw new CmisInvalidArgumentException("Invalid enum value '" + value + "'!"); + } + + throw new CmisRuntimeException(clazz.getSimpleName() + " is not a CMIS enum!"); + } +} Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.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/JSONConverter.java?rev=1481551&r1=1481550&r2=1481551&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java Sun May 12 13:14:14 2013 @@ -2918,42 +2918,12 @@ public final class JSONConverter { return null; } - @SuppressWarnings("unchecked") public static > T getEnum(final Map json, final String key, final Class clazz) { - String value = getString(json, key); - if (value == null) { - return null; - } - - try { - Method m = clazz.getMethod("fromValue", String.class); - return (T) m.invoke(null, value); - } catch (Exception e) { - if (e instanceof IllegalArgumentException) { - return null; - } else { - throw new CmisRuntimeException("Could not parse enum value!", e); - } - } + return CmisEnumHelper.fromValue(getString(json, key), clazz); } - @SuppressWarnings("unchecked") public static > T getIntEnum(final Map json, final String key, final Class clazz) { - BigInteger value = getInteger(json, key); - if (value == null) { - return null; - } - - try { - Method m = clazz.getMethod("fromValue", BigInteger.class); - return (T) m.invoke(null, value); - } catch (Exception e) { - if (e instanceof IllegalArgumentException) { - return null; - } else { - throw new CmisRuntimeException("Could not parse enum value!", e); - } - } + return CmisEnumHelper.fromValue(getInteger(json, key), clazz); } } 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=1481551&r1=1481550&r2=1481551&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 Sun May 12 13:14:14 2013 @@ -21,7 +21,6 @@ package org.apache.chemistry.opencmis.co import static org.apache.chemistry.opencmis.commons.impl.XMLUtils.next; import static org.apache.chemistry.opencmis.commons.impl.XMLUtils.skip; -import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; @@ -230,23 +229,8 @@ public abstract class XMLWalker { return result; } - @SuppressWarnings("unchecked") public > E readEnum(final XMLStreamReader parser, final Class clazz) throws XMLStreamException { - String value = readText(parser); - if (value == null) { - return null; - } - - try { - Method m = clazz.getMethod("fromValue", String.class); - return (E) m.invoke(null, value); - } catch (Exception e) { - if (e instanceof IllegalArgumentException) { - return null; - } else { - throw new CmisInvalidArgumentException("Invalid enum value!", e); - } - } + return CmisEnumHelper.fromValue(readText(parser), clazz); } protected abstract T prepareTarget(XMLStreamReader parser, QName name) throws XMLStreamException; Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.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/MultiFilingService.java?rev=1481551&r1=1481550&r2=1481551&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java Sun May 12 13:14:14 2013 @@ -21,6 +21,7 @@ package org.apache.chemistry.opencmis.se import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.chemistry.opencmis.commons.data.ContentStream; import org.apache.chemistry.opencmis.commons.data.ObjectData; import org.apache.chemistry.opencmis.commons.enums.VersioningState; import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; @@ -101,8 +102,14 @@ public class MultiFilingService { VersioningState.class); // create - String newObjectId = service.create(repositoryId, parser.getProperties(), null, parser.getContentStream(), - versioningState, parser.getPolicyIds(), null); + ContentStream contentStream = parser.getContentStream(); + String newObjectId = null; + try { + newObjectId = service.create(repositoryId, parser.getProperties(), null, contentStream, + versioningState, parser.getPolicyIds(), null); + } finally { + closeContentStream(contentStream); + } ObjectInfo objectInfo = service.getObjectInfo(repositoryId, newObjectId); if (objectInfo == null) { Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.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/browser/MultipartParser.java?rev=1481551&r1=1481550&r2=1481551&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java Sun May 12 13:14:14 2013 @@ -30,7 +30,9 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; +import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException; 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.MimeHelper; import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream; @@ -47,7 +49,7 @@ public class MultipartParser { private static final String CHARSET_FIELD = "_charset_"; private static final int MAX_FIELD_BYTES = 10 * 1024 * 1024; - private static final int BUFFER_SIZE = 64 * 1024; + private static final int BUFFER_SIZE = 128 * 1024; private static final byte CR = 0x0D; private static final byte LF = 0x0A; @@ -503,9 +505,15 @@ public class MultipartParser { private void skipEpilogue() { try { - // read to the end of stream + // read to the end of stream, but max 1 MB + int count = 0; byte[] tmpBuf = new byte[4096]; - while (requestStream.read(tmpBuf) > -1) { + int b; + while ((b = requestStream.read(tmpBuf)) > -1) { + count += b; + if (count >= 1024 * 1024) { + break; + } } } catch (IOException e) { // ignore @@ -565,7 +573,7 @@ public class MultipartParser { fields.put(e.getKey(), values); } - } catch (UnsupportedEncodingException uee) { + } catch (Exception e) { if (contentStream != null) { try { contentStream.close(); @@ -578,7 +586,15 @@ public class MultipartParser { fields = null; - throw new CmisInvalidArgumentException("Encoding not supported!"); + if (e instanceof UnsupportedEncodingException) { + throw new CmisInvalidArgumentException("Encoding not supported!"); + } else if (e instanceof CmisBaseException) { + throw (CmisBaseException) e; + } else if (e instanceof IOException) { + throw (IOException) e; + } else { + throw new CmisRuntimeException(e.getMessage(), e); + } } finally { rawFields = null; } Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.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/shared/AbstractServiceCall.java?rev=1481551&r1=1481550&r2=1481551&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java Sun May 12 13:14:14 2013 @@ -19,8 +19,6 @@ package org.apache.chemistry.opencmis.server.shared; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.math.BigInteger; import java.util.Date; import java.util.GregorianCalendar; @@ -33,7 +31,7 @@ import org.apache.chemistry.opencmis.com import org.apache.chemistry.opencmis.commons.data.ContentStream; import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream; import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; -import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; +import org.apache.chemistry.opencmis.commons.impl.CmisEnumHelper; import org.apache.chemistry.opencmis.commons.impl.DateTimeHelper; public abstract class AbstractServiceCall implements ServiceCall { @@ -100,23 +98,8 @@ public abstract class AbstractServiceCal /** * Extracts an enum parameter. */ - @SuppressWarnings("unchecked") - public T getEnumParameter(HttpServletRequest request, String name, Class clazz) { - String value = getStringParameter(request, name); - if ((value == null) || (value.length() == 0)) { - return null; - } - - try { - Method m = clazz.getMethod("fromValue", new Class[] { String.class }); - return (T) m.invoke(null, new Object[] { value }); - } catch (Exception e) { - if (e instanceof InvocationTargetException && e.getCause() instanceof IllegalArgumentException) { - throw new CmisInvalidArgumentException("Invalid parameter '" + name + "'!"); - } - - throw new CmisRuntimeException(e.getMessage(), e); - } + public > T getEnumParameter(HttpServletRequest request, String name, Class clazz) { + return CmisEnumHelper.fromValue(getStringParameter(request, name), clazz); } /**