chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1465971 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/ chemistry-opencmis-commons/chemistry-opencmis-commons-api/src...
Date Tue, 09 Apr 2013 11:08:48 GMT
Author: fmui
Date: Tue Apr  9 11:08:47 2013
New Revision: 1465971

URL: http://svn.apache.org/r1465971
Log:
internal clean ups

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.java   (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractWebServicesService.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.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-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-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.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/atompub/ObjectService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.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/impl/browser/POSTHttpServletRequestWrapper.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractWebServicesService.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/webservices/AbstractWebServicesService.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractWebServicesService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractWebServicesService.java Tue Apr  9 11:08:47 2013
@@ -28,7 +28,11 @@ import javax.xml.transform.TransformerFa
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
+import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
+import org.apache.chemistry.opencmis.client.bindings.impl.RepositoryInfoCache;
 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
+import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException;
@@ -51,20 +55,20 @@ import org.w3c.dom.Node;
  */
 public abstract class AbstractWebServicesService {
 
-    private BindingSession fSession;
+    private BindingSession session;
 
     /**
      * Sets the current session.
      */
     protected void setSession(BindingSession session) {
-        fSession = session;
+        this.session = session;
     }
 
     /**
      * Gets the current session.
      */
     protected BindingSession getSession() {
-        return fSession;
+        return session;
     }
 
     /**
@@ -141,4 +145,22 @@ public abstract class AbstractWebService
 
         return "";
     }
+
+    /**
+     * Return the CMIS version of the given repository.
+     */
+    protected CmisVersion getCmisVersion(String repositoryId) {
+        RepositoryInfoCache cache = CmisBindingsHelper.getRepositoryInfoCache(session);
+        RepositoryInfo info = cache.get(repositoryId);
+
+        if (info == null) {
+            info = CmisBindingsHelper.getSPI(session).getRepositoryService().getRepositoryInfo(repositoryId, null);
+            if (info != null) {
+                cache.put(info);
+            }
+        }
+
+        // if the version is unknown try CMIS 1.0
+        return (info == null ? CmisVersion.CMIS_1_0 : info.getCmisVersion());
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java Tue Apr  9 11:08:47 2013
@@ -70,7 +70,9 @@ public interface CallContext {
     String MAX_CONTENT_SIZE = "maxContentSize";
     /** Key: encrypt temp files (values is a Boolean) */
     String ENCRYPT_TEMP_FILE = "encryptTempFiles";
-
+    /** Key: factory for threshold streams (value is a ThresholdOutputStreamFactory) */
+    String STREAM_FACTORY = "streamFactory";
+    
     /**
      * Returns the binding. Usually it returns
      * {@link CallContext#BINDING_ATOMPUB},

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=1465971&r1=1465970&r2=1465971&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 Apr  9 11:08:47 2013
@@ -209,7 +209,7 @@ public class XMLUtils {
     /**
      * Skips a tag or subtree.
      */
-    public static void skip(XMLStreamReader parser) throws Exception {
+    public static void skip(XMLStreamReader parser) throws XMLStreamException {
         int level = 1;
         while (next(parser)) {
             int event = parser.getEventType();

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=1465971&r1=1465970&r2=1465971&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 Apr  9 11:08:47 2013
@@ -19,6 +19,7 @@
 package org.apache.chemistry.opencmis.commons.impl;
 
 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;
@@ -50,9 +51,12 @@ public abstract class XMLWalker<T> {
             int event = parser.getEventType();
             if (event == XMLStreamReader.START_ELEMENT) {
                 QName name = parser.getName();
-                if (!read(parser, name, result) && (result instanceof ExtensionsData)) {
-                    handleExtension(parser, (ExtensionsData) result);
-                }
+                if (!read(parser, name, result))
+                    if (result instanceof ExtensionsData) {
+                        handleExtension(parser, (ExtensionsData) result);
+                    } else {
+                        skip(parser);
+                    }
             } else if (event == XMLStreamReader.END_ELEMENT) {
                 break;
             } else {
@@ -81,7 +85,7 @@ public abstract class XMLWalker<T> {
         return tag.hashCode() == name.getLocalPart().hashCode() && tag.equals(name.getLocalPart());
     }
 
-    private void handleExtension(XMLStreamReader parser, ExtensionsData extData) throws XMLStreamException {
+    protected void handleExtension(XMLStreamReader parser, ExtensionsData extData) throws XMLStreamException {
         List<CmisExtensionElement> extensions = extData.getExtensions();
         if (extensions == null) {
             extensions = new ArrayList<CmisExtensionElement>();

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=1465971&r1=1465970&r2=1465971&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 Apr  9 11:08:47 2013
@@ -20,7 +20,6 @@ package org.apache.chemistry.opencmis.se
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.InputStream;
 import java.math.BigInteger;
 import java.util.Iterator;
@@ -55,6 +54,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
 import org.apache.chemistry.opencmis.server.shared.CappedInputStream;
 import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 /**
  * Parser for Atom Entries.
@@ -80,10 +80,7 @@ public class AtomEntryParser {
 
     private CappedInputStream cappedStream;
 
-    private final File tempDir;
-    private final int memoryThreshold;
-    private final long maxContentSize;
-    private final boolean encrypt;
+    private final ThresholdOutputStreamFactory streamFactory;
 
     private ObjectData object;
     private ContentStreamImpl atomContentStream;
@@ -94,19 +91,15 @@ public class AtomEntryParser {
     /**
      * Constructor.
      */
-    public AtomEntryParser(File tempDir, int memoryThreshold, long maxContentSize, boolean encrypt) {
-        this.tempDir = tempDir;
-        this.memoryThreshold = memoryThreshold;
-        this.maxContentSize = maxContentSize;
-        this.encrypt = encrypt;
+    public AtomEntryParser(ThresholdOutputStreamFactory streamFactory) {
+        this.streamFactory = streamFactory;
     }
 
     /**
      * Constructor that immediately parses the given stream.
      */
-    public AtomEntryParser(InputStream stream, File tempDir, int memoryThreshold, long maxContentSize, boolean encrypt)
-            throws Exception {
-        this(tempDir, memoryThreshold, maxContentSize, encrypt);
+    public AtomEntryParser(InputStream stream, ThresholdOutputStreamFactory streamFactory) throws Exception {
+        this(streamFactory);
         parse(stream);
     }
 
@@ -404,9 +397,7 @@ public class AtomEntryParser {
      * Parses a tag that contains content bytes.
      */
     private ThresholdOutputStream readContentBytes(XMLStreamReader parser) throws Exception {
-        @SuppressWarnings("resource")
-        ThresholdOutputStream bufferStream = new ThresholdOutputStream(tempDir, memoryThreshold, maxContentSize,
-                encrypt);
+        ThresholdOutputStream bufferStream = streamFactory.newOutputStream();
 
         XMLUtils.next(parser);
 
@@ -444,8 +435,7 @@ public class AtomEntryParser {
      * Parses a tag that contains base64 encoded content.
      */
     private ThresholdOutputStream readBase64(XMLStreamReader parser) throws Exception {
-        ThresholdOutputStream bufferStream = new ThresholdOutputStream(tempDir, memoryThreshold, maxContentSize,
-                encrypt);
+        ThresholdOutputStream bufferStream = streamFactory.newOutputStream();
         @SuppressWarnings("resource")
         Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream, Base64.DECODE);
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.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/CmisAtomPubServlet.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java Tue Apr  9 11:08:47 2013
@@ -44,7 +44,6 @@ import static org.apache.chemistry.openc
 import static org.apache.chemistry.opencmis.server.shared.Dispatcher.METHOD_POST;
 import static org.apache.chemistry.opencmis.server.shared.Dispatcher.METHOD_PUT;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 
@@ -80,6 +79,7 @@ import org.apache.chemistry.opencmis.ser
 import org.apache.chemistry.opencmis.server.shared.ExceptionHelper;
 import org.apache.chemistry.opencmis.server.shared.HttpUtils;
 import org.apache.chemistry.opencmis.server.shared.QueryStringHttpServletRequestWrapper;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -98,11 +98,7 @@ public class CmisAtomPubServlet extends 
 
     private CmisVersion cmisVersion;
 
-    private File tempDir;
-    private int memoryThreshold;
-    private long maxContentSize;
-    private boolean encrypt;
-
+    private ThresholdOutputStreamFactory streamFactory;
     private Dispatcher dispatcher;
     private CallContextHandler callContextHandler;
 
@@ -144,10 +140,9 @@ public class CmisAtomPubServlet extends 
             throw new CmisRuntimeException("Service factory not available! Configuration problem?");
         }
 
-        tempDir = factory.getTempDirectory();
-        memoryThreshold = factory.getMemoryThreshold();
-        maxContentSize = factory.getMaxContentSize();
-        encrypt = factory.encryptTempFiles();
+        // set up stream factory
+        streamFactory = ThresholdOutputStreamFactory.newInstance(factory.getTempDirectory(),
+                factory.getMemoryThreshold(), factory.getMaxContentSize(), factory.encryptTempFiles());
 
         // initialize the dispatcher
         dispatcher = new Dispatcher();
@@ -211,7 +206,7 @@ public class CmisAtomPubServlet extends 
         CallContext context = null;
         try {
             context = HttpUtils.createContext(qsRequest, response, getServletContext(), CallContext.BINDING_ATOMPUB,
-                    cmisVersion, callContextHandler, tempDir, memoryThreshold, maxContentSize, encrypt);
+                    cmisVersion, callContextHandler, streamFactory);
             dispatch(context, qsRequest, response);
         } catch (Exception e) {
             if (e instanceof CmisPermissionDeniedException) {

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=1465971&r1=1465970&r2=1465971&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 Tue Apr  9 11:08:47 2013
@@ -37,6 +37,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 /**
  * MultiFiling Service operations.
@@ -54,8 +55,9 @@ public final class MultiFilingService {
         // get parameters
         String removeFrom = getStringParameter(request, Constants.PARAM_REMOVE_FROM);
 
-        AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
-                context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(streamFactory);
         parser.setIgnoreAtomContentSrc(true); // needed for some clients
         parser.parse(request.getInputStream());
 

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=1465971&r1=1465970&r2=1465971&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 Tue Apr  9 11:08:47 2013
@@ -76,6 +76,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 /**
  * Object Service operations.
@@ -98,8 +99,9 @@ public final class ObjectService {
         VersioningState versioningState = getEnumParameter(request, Constants.PARAM_VERSIONIG_STATE,
                 VersioningState.class);
 
-        AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
-                context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(streamFactory);
         parser.setIgnoreAtomContentSrc(true); // needed for some clients
         parser.parse(request.getInputStream());
 
@@ -161,8 +163,9 @@ public final class ObjectService {
     public static void createRelationship(CallContext context, CmisService service, String repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
         // get parameters
-        AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), context.getTempDirectory(),
-                context.getMemoryThreshold(), context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), streamFactory);
 
         // execute
         String newObjectId = service.createRelationship(repositoryId, parser.getProperties(), parser.getPolicyIds(),
@@ -489,8 +492,9 @@ public final class ObjectService {
         String checkinComment = getStringParameter(request, Constants.PARAM_CHECKIN_COMMENT);
         Boolean major = getBooleanParameter(request, Constants.PARAM_MAJOR);
 
-        AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), context.getTempDirectory(),
-                context.getMemoryThreshold(), context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), streamFactory);
 
         // execute
         Holder<String> objectIdHolder = new Holder<String>(objectId);
@@ -543,8 +547,9 @@ public final class ObjectService {
     public static void bulkUpdateProperties(CallContext context, CmisService service, String repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
 
-        AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
-                context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(streamFactory);
         parser.parse(request.getInputStream());
 
         BulkUpdateImpl bulkUpdate = parser.getBulkUpdate();

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.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/PolicyService.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/PolicyService.java Tue Apr  9 11:08:47 2013
@@ -39,6 +39,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 /**
  * Policy Service operations.
@@ -114,8 +115,9 @@ public final class PolicyService {
         // get parameters
         String objectId = getStringParameter(request, Constants.PARAM_ID);
 
-        AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), context.getTempDirectory(),
-                context.getMemoryThreshold(), context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(request.getInputStream(), streamFactory);
 
         // execute
         service.applyPolicy(repositoryId, parser.getId(), objectId, null);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.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/RepositoryService.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java Tue Apr  9 11:08:47 2013
@@ -63,6 +63,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 /**
  * Repository Service operations.
@@ -433,8 +434,9 @@ public final class RepositoryService {
     public static void createType(CallContext context, CmisService service, String repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
         // parse entry
-        AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
-                context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(streamFactory);
         parser.parse(request.getInputStream());
 
         // execute
@@ -461,8 +463,9 @@ public final class RepositoryService {
     public static void updateType(CallContext context, CmisService service, String repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
         // parse entry
-        AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
-                context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(streamFactory);
         parser.parse(request.getInputStream());
 
         // execute

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.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/VersioningService.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/VersioningService.java Tue Apr  9 11:08:47 2013
@@ -39,6 +39,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 /**
  * Versioning Service operations.
@@ -54,8 +55,9 @@ public final class VersioningService {
     public static void checkOut(CallContext context, CmisService service, String repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
         // get parameters
-        AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
-                context.getMaxContentSize(), context.encryptTempFiles());
+        ThresholdOutputStreamFactory streamFactory = (ThresholdOutputStreamFactory) context
+                .get(CallContext.STREAM_FACTORY);
+        AtomEntryParser parser = new AtomEntryParser(streamFactory);
         parser.setIgnoreAtomContentSrc(true); // needed for some clients
         parser.parse(request.getInputStream());
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.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/CmisBrowserBindingServlet.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java Tue Apr  9 11:08:47 2013
@@ -83,7 +83,6 @@ import static org.apache.chemistry.openc
 import static org.apache.chemistry.opencmis.server.shared.Dispatcher.METHOD_POST;
 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
 
-import java.io.File;
 import java.io.IOException;
 
 import javax.servlet.ServletConfig;
@@ -123,6 +122,7 @@ import org.apache.chemistry.opencmis.ser
 import org.apache.chemistry.opencmis.server.shared.ExceptionHelper;
 import org.apache.chemistry.opencmis.server.shared.HttpUtils;
 import org.apache.chemistry.opencmis.server.shared.QueryStringHttpServletRequestWrapper;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -134,11 +134,7 @@ public class CmisBrowserBindingServlet e
 
     private static final Logger LOG = LoggerFactory.getLogger(CmisBrowserBindingServlet.class.getName());
 
-    private File tempDir;
-    private int memoryThreshold;
-    private long maxContentSize;
-    private boolean encrypt;
-
+    private ThresholdOutputStreamFactory streamFactory;
     private Dispatcher repositoryDispatcher;
     private Dispatcher rootDispatcher;
     private CallContextHandler callContextHandler;
@@ -167,10 +163,9 @@ public class CmisBrowserBindingServlet e
             throw new CmisRuntimeException("Service factory not available! Configuration problem?");
         }
 
-        tempDir = factory.getTempDirectory();
-        memoryThreshold = factory.getMemoryThreshold();
-        maxContentSize = factory.getMaxContentSize();
-        encrypt = factory.encryptTempFiles();
+        // set up stream factory
+        streamFactory = ThresholdOutputStreamFactory.newInstance(factory.getTempDirectory(),
+                factory.getMemoryThreshold(), factory.getMaxContentSize(), factory.encryptTempFiles());
 
         // initialize the dispatchers
         repositoryDispatcher = new Dispatcher(false);
@@ -278,7 +273,7 @@ public class CmisBrowserBindingServlet e
             if (METHOD_GET.equals(method)) {
                 request = new QueryStringHttpServletRequestWrapper(request);
             } else if (METHOD_POST.equals(method)) {
-                request = new POSTHttpServletRequestWrapper(request, tempDir, memoryThreshold, maxContentSize, encrypt);
+                request = new POSTHttpServletRequestWrapper(request, streamFactory);
             } else {
                 throw new CmisNotSupportedException("Unsupported method");
             }
@@ -290,7 +285,7 @@ public class CmisBrowserBindingServlet e
             }
 
             context = HttpUtils.createContext(request, response, getServletContext(), CallContext.BINDING_BROWSER,
-                    CmisVersion.CMIS_1_1, callContextHandler, tempDir, memoryThreshold, maxContentSize, encrypt);
+                    CmisVersion.CMIS_1_1, callContextHandler, streamFactory);
             dispatch(context, request, response);
         } catch (Exception e) {
             if (e instanceof CmisPermissionDeniedException) {

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=1465971&r1=1465970&r2=1465971&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 Tue Apr  9 11:08:47 2013
@@ -19,7 +19,6 @@
 package org.apache.chemistry.opencmis.server.impl.browser;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
@@ -35,6 +34,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.MimeHelper;
 import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 /**
  * Simple multi-part parser, following all necessary standards for the CMIS
@@ -55,10 +55,7 @@ public class MultipartParser {
     private static final byte[] BOUNDARY_PREFIX = { CR, LF, DASH, DASH };
 
     private final HttpServletRequest request;
-    private final File tempDir;
-    private final int memoryThreshold;
-    private final long maxContentSize;
-    private final boolean encrypt;
+    private final ThresholdOutputStreamFactory streamFactory;
     private final InputStream requestStream;
 
     private byte[] boundary;
@@ -85,14 +82,9 @@ public class MultipartParser {
     private Map<String, byte[][]> rawFields;
     private String charset = "ISO-8859-1";
 
-    public MultipartParser(HttpServletRequest request, File tempDir, int memoryThreshold, long maxContentSize,
-            boolean encrypt) throws IOException {
+    public MultipartParser(HttpServletRequest request, ThresholdOutputStreamFactory streamFactory) throws IOException {
         this.request = request;
-        this.tempDir = tempDir;
-        this.memoryThreshold = memoryThreshold;
-        this.maxContentSize = maxContentSize;
-        this.encrypt = encrypt;
-
+        this.streamFactory = streamFactory;
         this.requestStream = request.getInputStream();
 
         extractBoundary();
@@ -382,7 +374,7 @@ public class MultipartParser {
     }
 
     private void readBodyAsStream() throws IOException {
-        ThresholdOutputStream stream = new ThresholdOutputStream(tempDir, memoryThreshold, maxContentSize, encrypt);
+        ThresholdOutputStream stream = streamFactory.newOutputStream();
 
         try {
             while (true) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.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/POSTHttpServletRequestWrapper.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/POSTHttpServletRequestWrapper.java Tue Apr  9 11:08:47 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.chemistry.opencmis.server.impl.browser;
 
-import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.math.BigInteger;
@@ -29,6 +28,7 @@ import javax.servlet.http.HttpServletReq
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.server.shared.HttpUtils;
 import org.apache.chemistry.opencmis.server.shared.QueryStringHttpServletRequestWrapper;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 
 public class POSTHttpServletRequestWrapper extends QueryStringHttpServletRequestWrapper {
     private final boolean isMultipart;
@@ -37,15 +37,15 @@ public class POSTHttpServletRequestWrapp
     private BigInteger size;
     private InputStream stream;
 
-    public POSTHttpServletRequestWrapper(HttpServletRequest request, File tempDir, int memoryThreshold,
-            long maxContentSize, boolean encrypt) throws Exception {
+    public POSTHttpServletRequestWrapper(HttpServletRequest request, ThresholdOutputStreamFactory streamFactory)
+            throws Exception {
         super(request);
 
         // check multipart
         isMultipart = MultipartParser.isMultipartContent(request);
 
         if (isMultipart) {
-            MultipartParser parser = new MultipartParser(request, tempDir, memoryThreshold, maxContentSize, encrypt);
+            MultipartParser parser = new MultipartParser(request, streamFactory);
             parser.parse();
 
             if (parser.hasContent()) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.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/HttpUtils.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java Tue Apr  9 11:08:47 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.chemistry.opencmis.server.shared;
 
-import java.io.File;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -50,8 +49,7 @@ public final class HttpUtils {
      */
     public static CallContext createContext(HttpServletRequest request, HttpServletResponse response,
             ServletContext servletContext, String binding, CmisVersion cmisVersion,
-            CallContextHandler callContextHandler, File tempDir, int memoryThreshold, long maxContentSize,
-            boolean encrypt) {
+            CallContextHandler callContextHandler, ThresholdOutputStreamFactory streamFactory) {
         String[] pathFragments = splitPath(request);
 
         String repositoryId = null;
@@ -79,12 +77,13 @@ public final class HttpUtils {
 
         // CMIS version
         context.put(CallContext.CMIS_VERSION, cmisVersion);
-        
+
         // content
-        context.put(CallContext.TEMP_DIR, tempDir);
-        context.put(CallContext.MEMORY_THRESHOLD, memoryThreshold);
-        context.put(CallContext.MAX_CONTENT_SIZE, maxContentSize);
-        context.put(CallContext.ENCRYPT_TEMP_FILE, encrypt);
+        context.put(CallContext.TEMP_DIR, streamFactory.getTempDir());
+        context.put(CallContext.MEMORY_THRESHOLD, streamFactory.getMemoryThreshold());
+        context.put(CallContext.MAX_CONTENT_SIZE, streamFactory.getMaxContentSize());
+        context.put(CallContext.ENCRYPT_TEMP_FILE, streamFactory.isEncrypted());
+        context.put(CallContext.STREAM_FACTORY, streamFactory);
 
         // decode range
         String rangeHeader = request.getHeader("Range");

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.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/ThresholdOutputStream.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java Tue Apr  9 11:08:47 2013
@@ -78,7 +78,8 @@ public class ThresholdOutputStream exten
      * Constructor.
      * 
      * @param tempDir
-     *            temp directory
+     *            temp directory or <code>null</code> for the default temp
+     *            directory
      * @param memoryThreshold
      *            memory threshold in bytes
      * @param maxContentSize
@@ -92,7 +93,8 @@ public class ThresholdOutputStream exten
      * Constructor.
      * 
      * @param tempDir
-     *            temp directory
+     *            temp directory or <code>null</code> for the default temp
+     *            directory
      * @param memoryThreshold
      *            memory threshold in bytes
      * @param maxContentSize
@@ -108,11 +110,14 @@ public class ThresholdOutputStream exten
      * @param initSize
      *            initial internal buffer size
      * @param tempDir
-     *            temp directory
+     *            temp directory or <code>null</code> for the default temp
+     *            directory
      * @param memoryThreshold
      *            memory threshold in bytes
      * @param maxContentSize
      *            max size of the content in bytes (-1 to disable the check)
+     * @param encrypt
+     *            indicates if temporary files must be encrypted
      */
     public ThresholdOutputStream(int initSize, File tempDir, int memoryThreshold, long maxContentSize, boolean encrypt) {
         if (initSize < 0) {

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.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/ThresholdOutputStreamFactory.java?rev=1465971&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.java Tue Apr  9 11:08:47 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.server.shared;
+
+import java.io.File;
+
+/**
+ * A factory for {@link ThresholdOutputStream} objects.
+ */
+public class ThresholdOutputStreamFactory {
+
+    private File tempDir;
+    private int memoryThreshold;
+    private long maxContentSize;
+    private boolean encrypt;
+
+    private ThresholdOutputStreamFactory(File tempDir, int memoryThreshold, long maxContentSize, boolean encrypt) {
+        this.tempDir = tempDir;
+        this.memoryThreshold = memoryThreshold;
+        this.maxContentSize = maxContentSize;
+        this.encrypt = encrypt;
+    }
+
+    /**
+     * Creates a new factory. The parameters are used to create new
+     * {@link ThresholdOutputStream} objects.
+     * 
+     * @param tempDir
+     *            temp directory or <code>null</code> for the default temp
+     *            directory
+     * @param memoryThreshold
+     *            memory threshold in bytes
+     * @param maxContentSize
+     *            max size of the content in bytes (-1 to disable the check)
+     * @param encrypt
+     *            indicates if temporary files must be encrypted
+     */
+    public static ThresholdOutputStreamFactory newInstance(File tempDir, int memoryThreshold, long maxContentSize,
+            boolean encrypt) {
+        return new ThresholdOutputStreamFactory(tempDir, memoryThreshold, maxContentSize, encrypt);
+    }
+
+    /**
+     * Creates a new {@link ThresholdOutputStream} object.
+     */
+    public ThresholdOutputStream newOutputStream() {
+        return new ThresholdOutputStream(tempDir, memoryThreshold, maxContentSize, encrypt);
+    }
+
+    /**
+     * Returns the temp directory or <code>null</code> for the default temp
+     * directory.
+     */
+    public File getTempDir() {
+        return tempDir;
+    }
+
+    /**
+     * Returns the memory threshold in bytes.
+     */
+    public int getMemoryThreshold() {
+        return memoryThreshold;
+    }
+
+    /**
+     * Returns the max content size in bytes.
+     */
+    public long getMaxContentSize() {
+        return maxContentSize;
+    }
+
+    /**
+     * Indicates if temporary files are encrypted.
+     */
+    public boolean isEncrypted() {
+        return encrypt;
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStreamFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java Tue Apr  9 11:08:47 2013
@@ -31,6 +31,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.PropertyString;
 import org.apache.chemistry.opencmis.commons.impl.Base64;
 import org.apache.chemistry.opencmis.server.impl.atompub.AtomEntryParser;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 import org.junit.Test;
 
 /**
@@ -172,8 +173,9 @@ public class AtomEntryParserTest {
 
     @Test
     public void testAtomTitle() throws Exception {
-        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(ATOM_ENTRY_NAME.getBytes()), null,
-                THRESHOLD, MAX_SIZE, false);
+        ThresholdOutputStreamFactory streamFactory = ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+                MAX_SIZE, false);
+        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(ATOM_ENTRY_NAME.getBytes()), streamFactory);
 
         assertNotNull(aep);
         assertNotNull(aep.getObject());
@@ -189,7 +191,9 @@ public class AtomEntryParserTest {
 
     @Test
     public void testNullStream() throws Exception {
-        AtomEntryParser aep = new AtomEntryParser(null, null, THRESHOLD, MAX_SIZE, false);
+        ThresholdOutputStreamFactory streamFactory = ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+                MAX_SIZE, false);
+        AtomEntryParser aep = new AtomEntryParser(null, streamFactory);
 
         assertNotNull(aep);
         assertNull(aep.getId());
@@ -200,8 +204,9 @@ public class AtomEntryParserTest {
 
     @Test
     public void testEmptyStream() throws Exception {
-        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(new byte[0]), null, THRESHOLD, MAX_SIZE,
-                false);
+        ThresholdOutputStreamFactory streamFactory = ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+                MAX_SIZE, false);
+        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(new byte[0]), streamFactory);
 
         assertNotNull(aep);
         assertNull(aep.getId());
@@ -211,7 +216,9 @@ public class AtomEntryParserTest {
     }
 
     private static byte[] parse(byte[] entry) throws Exception {
-        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(entry), null, THRESHOLD, MAX_SIZE, false);
+        ThresholdOutputStreamFactory streamFactory = ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+                MAX_SIZE, false);
+        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(entry), streamFactory);
         ContentStream contentStream = aep.getContentStream();
 
         assertNotNull(contentStream);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java?rev=1465971&r1=1465970&r2=1465971&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/MultipartParserTest.java Tue Apr  9 11:08:47 2013
@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletReq
 
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.server.impl.browser.MultipartParser;
+import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
 import org.junit.Test;
 import org.mockito.Mockito;
 
@@ -376,7 +377,9 @@ public class MultipartParserTest {
         Mockito.when(request.getContentType()).thenReturn("multipart/form-data; boundary=\"" + boundary + "\"");
         Mockito.when(request.getInputStream()).thenReturn(stream);
 
-        return new MultipartParser(request, null, THRESHOLD, MAX_SIZE, false);
+        ThresholdOutputStreamFactory streamFactory = ThresholdOutputStreamFactory.newInstance(null, THRESHOLD,
+                MAX_SIZE, false);
+        return new MultipartParser(request, streamFactory);
     }
 
     private byte[] readBytesFromStream(InputStream is) throws IOException {



Mime
View raw message