Fix for ETHREEOH-274 and handling of potentially missing cm:modifiedDate property in DownloadContentServlet.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11254 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-10-08 11:22:17 +00:00
parent 7031037e2f
commit 0c66da37c5
2 changed files with 47 additions and 22 deletions

View File

@@ -243,20 +243,23 @@ public abstract class BaseDownloadContentServlet extends BaseServlet
// check If-Modified-Since header and set Last-Modified header as appropriate // check If-Modified-Since header and set Last-Modified header as appropriate
Date modified = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED); Date modified = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
long modifiedSince = req.getDateHeader("If-Modified-Since"); if (modified != null)
if (modifiedSince > 0L)
{ {
// round the date to the ignore millisecond value which is not supplied by header long modifiedSince = req.getDateHeader("If-Modified-Since");
long modDate = (modified.getTime() / 1000L) * 1000L; if (modifiedSince > 0L)
if (modDate <= modifiedSince)
{ {
if (logger.isDebugEnabled()) // round the date to the ignore millisecond value which is not supplied by header
logger.debug("Returning 304 Not Modified."); long modDate = (modified.getTime() / 1000L) * 1000L;
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); if (modDate <= modifiedSince)
return; {
if (logger.isDebugEnabled())
logger.debug("Returning 304 Not Modified.");
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
} }
res.setDateHeader("Last-Modified", modified.getTime());
} }
res.setDateHeader("Last-Modified", modified.getTime());
if (attachment == true) if (attachment == true)
{ {

View File

@@ -76,7 +76,7 @@ public class UserShortcutsBean implements Serializable
/** List of shortcut nodes */ /** List of shortcut nodes */
private List<Node> shortcuts = null; private List<Node> shortcuts = null;
private String PREF_SHORTCUTS = "shortcuts"; private static final String PREF_SHORTCUTS = "shortcuts";
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
@@ -142,8 +142,8 @@ public class UserShortcutsBean implements Serializable
tx.begin(); tx.begin();
// get the shortcuts from the preferences for this user // get the shortcuts from the preferences for this user
shortcuts = (List<String>)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); shortcuts = getShortcutList(context);
if (shortcuts != null) if (shortcuts.size() != 0)
{ {
// each shortcut node ID is persisted as a list item in a well known property // each shortcut node ID is persisted as a list item in a well known property
this.shortcuts = new ArrayList<Node>(shortcuts.size()); this.shortcuts = new ArrayList<Node>(shortcuts.size());
@@ -274,11 +274,7 @@ public class UserShortcutsBean implements Serializable
tx = Repository.getUserTransaction(context); tx = Repository.getUserTransaction(context);
tx.begin(); tx.begin();
List<String> shortcuts = (List<String>)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); List<String> shortcuts = getShortcutList(context);
if (shortcuts == null)
{
shortcuts = new ArrayList<String>(1);
}
shortcuts.add(node.getNodeRef().getId()); shortcuts.add(node.getNodeRef().getId());
PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable)shortcuts); PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable)shortcuts);
@@ -322,8 +318,8 @@ public class UserShortcutsBean implements Serializable
tx = Repository.getUserTransaction(context); tx = Repository.getUserTransaction(context);
tx.begin(); tx.begin();
List<String> shortcuts = (List<String>)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); List<String> shortcuts = getShortcutList(context);
if (shortcuts != null && shortcuts.size() > shortcutEvent.Index) if (shortcuts.size() > shortcutEvent.Index)
{ {
// remove the shortcut from the saved list and persist back // remove the shortcut from the saved list and persist back
shortcuts.remove(shortcutEvent.Index); shortcuts.remove(shortcutEvent.Index);
@@ -347,6 +343,32 @@ public class UserShortcutsBean implements Serializable
} }
} }
/**
* @return the List of shortcut values - will always return at least an empty List
*/
private static List<String> getShortcutList(FacesContext context)
{
List<String> shortcuts = null;
Object prefValue = PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS);
if (prefValue instanceof List)
{
shortcuts = (List<String>)prefValue;
}
else if (prefValue instanceof String)
{
shortcuts = new ArrayList<String>(1);
shortcuts.add((String)prefValue);
}
// handle missing and empty (immutable) list collection
if (shortcuts == null || shortcuts.size() == 0)
{
shortcuts = new ArrayList<String>(1);
}
return shortcuts;
}
/** /**
* Action handler bound to the user shortcuts Shelf component called when a node is clicked * Action handler bound to the user shortcuts Shelf component called when a node is clicked
*/ */
@@ -398,8 +420,8 @@ public class UserShortcutsBean implements Serializable
tx = Repository.getUserTransaction(context); tx = Repository.getUserTransaction(context);
tx.begin(); tx.begin();
List<String> shortcuts = (List<String>)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); List<String> shortcuts = getShortcutList(context);
if (shortcuts != null && shortcuts.size() > shortcutEvent.Index) if (shortcuts.size() > shortcutEvent.Index)
{ {
// remove the shortcut from the saved list and persist back // remove the shortcut from the saved list and persist back
shortcuts.remove(shortcutEvent.Index); shortcuts.remove(shortcutEvent.Index);