diff --git a/source/java/org/alfresco/web/app/servlet/BaseDownloadContentServlet.java b/source/java/org/alfresco/web/app/servlet/BaseDownloadContentServlet.java index 55ff6805c5..1c05a235f0 100644 --- a/source/java/org/alfresco/web/app/servlet/BaseDownloadContentServlet.java +++ b/source/java/org/alfresco/web/app/servlet/BaseDownloadContentServlet.java @@ -243,20 +243,23 @@ public abstract class BaseDownloadContentServlet extends BaseServlet // check If-Modified-Since header and set Last-Modified header as appropriate Date modified = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED); - long modifiedSince = req.getDateHeader("If-Modified-Since"); - if (modifiedSince > 0L) + if (modified != null) { - // round the date to the ignore millisecond value which is not supplied by header - long modDate = (modified.getTime() / 1000L) * 1000L; - if (modDate <= modifiedSince) + long modifiedSince = req.getDateHeader("If-Modified-Since"); + if (modifiedSince > 0L) { - if (logger.isDebugEnabled()) - logger.debug("Returning 304 Not Modified."); - res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - return; + // round the date to the ignore millisecond value which is not supplied by header + long modDate = (modified.getTime() / 1000L) * 1000L; + if (modDate <= modifiedSince) + { + 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) { diff --git a/source/java/org/alfresco/web/bean/users/UserShortcutsBean.java b/source/java/org/alfresco/web/bean/users/UserShortcutsBean.java index d84e3bca72..807f10d240 100644 --- a/source/java/org/alfresco/web/bean/users/UserShortcutsBean.java +++ b/source/java/org/alfresco/web/bean/users/UserShortcutsBean.java @@ -76,7 +76,7 @@ public class UserShortcutsBean implements Serializable /** List of shortcut nodes */ private List 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(); // get the shortcuts from the preferences for this user - shortcuts = (List)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); - if (shortcuts != null) + shortcuts = getShortcutList(context); + if (shortcuts.size() != 0) { // each shortcut node ID is persisted as a list item in a well known property this.shortcuts = new ArrayList(shortcuts.size()); @@ -274,11 +274,7 @@ public class UserShortcutsBean implements Serializable tx = Repository.getUserTransaction(context); tx.begin(); - List shortcuts = (List)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); - if (shortcuts == null) - { - shortcuts = new ArrayList(1); - } + List shortcuts = getShortcutList(context); shortcuts.add(node.getNodeRef().getId()); PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable)shortcuts); @@ -322,8 +318,8 @@ public class UserShortcutsBean implements Serializable tx = Repository.getUserTransaction(context); tx.begin(); - List shortcuts = (List)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); - if (shortcuts != null && shortcuts.size() > shortcutEvent.Index) + List shortcuts = getShortcutList(context); + if (shortcuts.size() > shortcutEvent.Index) { // remove the shortcut from the saved list and persist back shortcuts.remove(shortcutEvent.Index); @@ -346,6 +342,32 @@ public class UserShortcutsBean implements Serializable try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} } } + + /** + * @return the List of shortcut values - will always return at least an empty List + */ + private static List getShortcutList(FacesContext context) + { + List shortcuts = null; + + Object prefValue = PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); + if (prefValue instanceof List) + { + shortcuts = (List)prefValue; + } + else if (prefValue instanceof String) + { + shortcuts = new ArrayList(1); + shortcuts.add((String)prefValue); + } + + // handle missing and empty (immutable) list collection + if (shortcuts == null || shortcuts.size() == 0) + { + shortcuts = new ArrayList(1); + } + return shortcuts; + } /** * 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.begin(); - List shortcuts = (List)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS); - if (shortcuts != null && shortcuts.size() > shortcutEvent.Index) + List shortcuts = getShortcutList(context); + if (shortcuts.size() > shortcutEvent.Index) { // remove the shortcut from the saved list and persist back shortcuts.remove(shortcutEvent.Index);