Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)

51903 to 54309 


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Samuel Langlois
2013-08-20 17:17:31 +00:00
parent 0a36e2af67
commit ab4ca7177f
1576 changed files with 36419 additions and 8603 deletions

View File

@@ -18,27 +18,21 @@
*/
package org.alfresco.opencmis;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.util.TempFileProvider;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
/**
* Interceptor to replace ContentStream parameter values with ReusableContentStream parameters
* which unlike the original may be closed and then opened again. This is important as retrying
* transaction advice is also added. A reopen of the original results is zero bytes being read.
* Interceptor to deal with ContentStreams, determining mime type if appropriate.
*
* Note: this used to cache content stream to a local file so that retrying transaction behaviour
* worked properly; this is now done in the Chemsitry OpenCMIS layer so no need to do it again
* here.
*
* @author steveglover
* @author Alan Davis
* @since 4.0.2.26 / 4.1.4
*/
@@ -56,103 +50,25 @@ public class AlfrescoCmisStreamInterceptor implements MethodInterceptor
public Object invoke(MethodInvocation mi) throws Throwable
{
List<ReusableContentStream> reusableContentStreams = null;
try
Class<?>[] parameterTypes = mi.getMethod().getParameterTypes();
Object[] arguments = mi.getArguments();
for (int i = 0; i < parameterTypes.length; i++)
{
Class<?>[] parameterTypes = mi.getMethod().getParameterTypes();
Object[] arguments = mi.getArguments();
for (int i=0; i<parameterTypes.length; i++)
if (parameterTypes[i].isAssignableFrom(ContentStreamImpl.class))
{
if (ContentStream.class.isAssignableFrom(parameterTypes[i]))
ContentStreamImpl contentStream = (ContentStreamImpl) arguments[i];
if (contentStream != null)
{
ContentStream contentStream = (ContentStream) arguments[i];
if (contentStream != null)
// ALF-18006
if (contentStream.getMimeType() == null)
{
if (reusableContentStreams == null)
{
reusableContentStreams = new ArrayList<ReusableContentStream>();
}
ReusableContentStream reuableContentStream = new ReusableContentStream(contentStream);
// ALF-18006
if (contentStream.getMimeType() == null)
{
String mimeType = mimetypeService.guessMimetype(reuableContentStream.getFileName(), new FileContentReader(reuableContentStream.file));
reuableContentStream.setMimeType(mimeType);
}
reusableContentStreams.add(reuableContentStream);
// It is possible to just change the arguments. No need to call a setter.
// Wow, did not expect that.
arguments[i] = reuableContentStream;
InputStream stream = contentStream.getStream();
String mimeType = mimetypeService.guessMimetype(contentStream.getFileName(), stream);
contentStream.setMimeType(mimeType);
}
}
}
return mi.proceed();
}
finally
{
if (reusableContentStreams != null)
{
for (ReusableContentStream contentStream: reusableContentStreams)
{
contentStream.close();
}
}
}
}
private static class ReusableContentStream extends ContentStreamImpl
{
private static final long serialVersionUID = 8992465629472248502L;
private File file;
public ReusableContentStream(ContentStream contentStream) throws Exception
{
setLength(contentStream.getBigLength());
setMimeType(contentStream.getMimeType());
setFileName(contentStream.getFileName());
file = TempFileProvider.createTempFile(contentStream.getStream(), "cmis", "contentStream");
}
@Override
public InputStream getStream() {
InputStream stream = super.getStream();
if (stream == null && file != null)
{
try
{
stream = new FileInputStream(file)
{
@Override
public void close() throws IOException
{
setStream(null);
super.close();
}
};
}
catch (Exception e)
{
throw new AlfrescoRuntimeException("Expected to be able to reopen temporary file", e);
}
setStream(stream);
}
return stream;
}
public void close()
{
try
{
file.delete();
}
finally
{
file = null;
}
}
return mi.proceed();
}
}