mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
75025: Merged WAT2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 71709: Raises a ContentReadEvent when content is downloaded via webscript git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@75353 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -88,5 +88,7 @@
|
|||||||
<property name="nodeService" ref="NodeService" />
|
<property name="nodeService" ref="NodeService" />
|
||||||
<property name="mimetypeService" ref="MimetypeService" />
|
<property name="mimetypeService" ref="MimetypeService" />
|
||||||
<property name="contentService" ref="ContentService" />
|
<property name="contentService" ref="ContentService" />
|
||||||
|
<property name="eventPublisher" ref="eventPublisher" />
|
||||||
|
<property name="siteService" ref="SiteService" />
|
||||||
</bean>
|
</bean>
|
||||||
</beans>
|
</beans>
|
@@ -13,9 +13,13 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.alfresco.events.types.ContentReadEvent;
|
||||||
|
import org.alfresco.events.types.Event;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.content.filestore.FileContentReader;
|
import org.alfresco.repo.content.filestore.FileContentReader;
|
||||||
|
import org.alfresco.repo.events.EventPreparator;
|
||||||
|
import org.alfresco.repo.events.EventPublisher;
|
||||||
import org.alfresco.repo.web.util.HttpRangeProcessor;
|
import org.alfresco.repo.web.util.HttpRangeProcessor;
|
||||||
import org.alfresco.repo.webdav.WebDAVHelper;
|
import org.alfresco.repo.webdav.WebDAVHelper;
|
||||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||||
@@ -24,7 +28,9 @@ import org.alfresco.service.cmr.repository.ContentService;
|
|||||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.FileFilterMode.Client;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -36,6 +42,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
|||||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used when the binary data of a content property needs to be streamed back to the client
|
* Can be used when the binary data of a content property needs to be streamed back to the client
|
||||||
* as the result of executing a web script.
|
* as the result of executing a web script.
|
||||||
@@ -66,7 +73,8 @@ public class ContentStreamer implements ResourceLoaderAware
|
|||||||
protected ContentService contentService;
|
protected ContentService contentService;
|
||||||
protected MimetypeService mimetypeService;
|
protected MimetypeService mimetypeService;
|
||||||
protected ResourceLoader resourceLoader;
|
protected ResourceLoader resourceLoader;
|
||||||
|
protected EventPublisher eventPublisher;
|
||||||
|
protected SiteService siteService;
|
||||||
/**
|
/**
|
||||||
* @param mimetypeService
|
* @param mimetypeService
|
||||||
*/
|
*/
|
||||||
@@ -83,6 +91,22 @@ public class ContentStreamer implements ResourceLoaderAware
|
|||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param EventPublisher
|
||||||
|
*/
|
||||||
|
public void setEventPublisher(EventPublisher eventPublisher)
|
||||||
|
{
|
||||||
|
this.eventPublisher = eventPublisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SiteService
|
||||||
|
*/
|
||||||
|
public void setSiteService(SiteService siteService)
|
||||||
|
{
|
||||||
|
this.siteService = siteService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResourceLoader(ResourceLoader resourceLoader)
|
public void setResourceLoader(ResourceLoader resourceLoader)
|
||||||
{
|
{
|
||||||
@@ -518,10 +542,10 @@ public class ContentStreamer implements ResourceLoaderAware
|
|||||||
public void streamContentImpl(WebScriptRequest req,
|
public void streamContentImpl(WebScriptRequest req,
|
||||||
WebScriptResponse res,
|
WebScriptResponse res,
|
||||||
ContentReader reader,
|
ContentReader reader,
|
||||||
NodeRef nodeRef,
|
final NodeRef nodeRef,
|
||||||
QName propertyQName,
|
final QName propertyQName,
|
||||||
boolean attach,
|
final boolean attach,
|
||||||
Date modified,
|
final Date modified,
|
||||||
String eTag,
|
String eTag,
|
||||||
String attachFileName,
|
String attachFileName,
|
||||||
Map<String, Object> model) throws IOException
|
Map<String, Object> model) throws IOException
|
||||||
@@ -541,12 +565,31 @@ public class ContentStreamer implements ResourceLoaderAware
|
|||||||
mimetype = mimetypeService.getMimetype(ext);
|
mimetype = mimetypeService.getMimetype(ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.setHeader(HEADER_ACCEPT_RANGES, "bytes");
|
res.setHeader(HEADER_ACCEPT_RANGES, "bytes");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boolean processedRange = false;
|
boolean processedRange = false;
|
||||||
String range = req.getHeader(HEADER_CONTENT_RANGE);
|
String range = req.getHeader(HEADER_CONTENT_RANGE);
|
||||||
|
final long size = reader.getSize();
|
||||||
|
final String encoding = reader.getEncoding();
|
||||||
|
|
||||||
|
if (attach)
|
||||||
|
{
|
||||||
|
final String finalMimetype = mimetype;
|
||||||
|
|
||||||
|
eventPublisher.publishEvent(new EventPreparator(){
|
||||||
|
@Override
|
||||||
|
public Event prepareEvent(String user, String networkId, String transactionId)
|
||||||
|
{
|
||||||
|
String siteId = siteService.getSiteShortName(nodeRef);
|
||||||
|
|
||||||
|
return new ContentReadEvent(ContentReadEvent.DOWNLOAD, user, networkId, transactionId,
|
||||||
|
nodeRef.getId(), siteId, propertyQName.toString(), Client.webclient, finalMimetype, size, encoding);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (range == null)
|
if (range == null)
|
||||||
{
|
{
|
||||||
range = req.getHeader(HEADER_RANGE);
|
range = req.getHeader(HEADER_RANGE);
|
||||||
@@ -579,10 +622,9 @@ public class ContentStreamer implements ResourceLoaderAware
|
|||||||
|
|
||||||
// set mimetype for the content and the character encoding for the stream
|
// set mimetype for the content and the character encoding for the stream
|
||||||
res.setContentType(mimetype);
|
res.setContentType(mimetype);
|
||||||
res.setContentEncoding(reader.getEncoding());
|
res.setContentEncoding(encoding);
|
||||||
|
|
||||||
// return the complete entity range
|
// return the complete entity range
|
||||||
long size = reader.getSize();
|
|
||||||
res.setHeader(HEADER_CONTENT_RANGE, "bytes 0-" + Long.toString(size-1L) + "/" + Long.toString(size));
|
res.setHeader(HEADER_CONTENT_RANGE, "bytes 0-" + Long.toString(size-1L) + "/" + Long.toString(size));
|
||||||
res.setHeader(HEADER_CONTENT_LENGTH, Long.toString(size));
|
res.setHeader(HEADER_CONTENT_LENGTH, Long.toString(size));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user