mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V2.1 to V2.0
6435: AR-1644 Web Scripts do not provide any control over caching 6469: Replaced EUPL licence with standard license header 6526: AR-1685 Error creating workflow with no document associated 6565: Fix for issue with file Upload in main web-client portlet for JBoss/Liferay portal integration. 6578: AR-1620: Upgraded One-Jar to 0.96-RC4 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6581 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,10 +27,15 @@ package org.alfresco.web.scripts;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.util.CachingDateFormat;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* HTTP Servlet Web Script Response
|
||||
@@ -39,7 +44,12 @@ import org.alfresco.web.ui.common.Utils;
|
||||
*/
|
||||
public class WebScriptServletResponse implements WebScriptResponse
|
||||
{
|
||||
// Logger
|
||||
private static final Log logger = LogFactory.getLog(WebScriptServletResponse.class);
|
||||
|
||||
// Servlet Response
|
||||
private HttpServletResponse res;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -77,6 +87,66 @@ public class WebScriptServletResponse implements WebScriptResponse
|
||||
res.setContentType(contentType);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptResponse#setCache(org.alfresco.web.scripts.WebScriptCache)
|
||||
*/
|
||||
public void setCache(WebScriptCache cache)
|
||||
{
|
||||
// set Cache-Control
|
||||
String cacheControl = "";
|
||||
String pragma = "";
|
||||
if (cache.getIsPublic())
|
||||
{
|
||||
cacheControl += "public";
|
||||
}
|
||||
if (cache.getNeverCache())
|
||||
{
|
||||
cacheControl += (cacheControl.length() > 0 ? ", " : "") + "no-cache";
|
||||
pragma += (pragma.length() > 0) ? ", " : "" + "no-cache";
|
||||
}
|
||||
if (cache.getMaxAge() != null && cache.getNeverCache() == false)
|
||||
{
|
||||
cacheControl += (cacheControl.length() > 0 ? ", " : "") + " max-age=" + cache.getMaxAge();
|
||||
}
|
||||
if (cache.getMustRevalidate() && cache.getNeverCache() == false)
|
||||
{
|
||||
cacheControl += (cacheControl.length() > 0 ? ", " : "") + " must-revalidate";
|
||||
}
|
||||
if (cacheControl.length() > 0)
|
||||
{
|
||||
res.setHeader("Cache-Control", cacheControl);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Cache - set response header Cache-Control: " + cacheControl);
|
||||
}
|
||||
if (pragma.length() > 0)
|
||||
{
|
||||
res.setHeader("Pragma", pragma);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Cache - set response header Pragma: " + pragma);
|
||||
}
|
||||
|
||||
// set ETag
|
||||
if (cache.getETag() != null)
|
||||
{
|
||||
String eTag = "\"" + cache.getETag() + "\"";
|
||||
res.setHeader("ETag", eTag);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Cache - set response header ETag: " + eTag);
|
||||
}
|
||||
|
||||
// set Last Modified
|
||||
if (cache.getLastModified() != null)
|
||||
{
|
||||
res.setDateHeader("Last-Modified", cache.getLastModified().getTime());
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
SimpleDateFormat formatter = getHTTPDateFormat();
|
||||
String lastModified = formatter.format(cache.getLastModified());
|
||||
logger.debug("Cache - set response header Last-Modified: " + lastModified);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptResponse#reset()
|
||||
*/
|
||||
@@ -90,7 +160,7 @@ public class WebScriptServletResponse implements WebScriptResponse
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptResponse#getWriter()
|
||||
*/
|
||||
@@ -124,4 +194,25 @@ public class WebScriptServletResponse implements WebScriptResponse
|
||||
}
|
||||
|
||||
private static final String ENCODE_FUNCTION = "{ $name$: function(url) { return url; } }";
|
||||
|
||||
/**
|
||||
* Helper to return a HTTP Date Formatter
|
||||
*
|
||||
* @return HTTP Date Formatter
|
||||
*/
|
||||
private static SimpleDateFormat getHTTPDateFormat()
|
||||
{
|
||||
if (s_dateFormat.get() != null)
|
||||
{
|
||||
return s_dateFormat.get();
|
||||
}
|
||||
|
||||
SimpleDateFormat formatter = CachingDateFormat.getDateFormat("EEE, dd MMM yyyy kk:mm:ss zzz", false);
|
||||
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
s_dateFormat.set(formatter);
|
||||
return s_dateFormat.get();
|
||||
}
|
||||
|
||||
private static ThreadLocal<SimpleDateFormat> s_dateFormat = new ThreadLocal<SimpleDateFormat>();
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user