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
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)
{

View File

@@ -76,7 +76,7 @@ public class UserShortcutsBean implements Serializable
/** List of shortcut nodes */
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();
// get the shortcuts from the preferences for this user
shortcuts = (List<String>)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<Node>(shortcuts.size());
@@ -274,11 +274,7 @@ public class UserShortcutsBean implements Serializable
tx = Repository.getUserTransaction(context);
tx.begin();
List<String> shortcuts = (List<String>)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS);
if (shortcuts == null)
{
shortcuts = new ArrayList<String>(1);
}
List<String> 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<String> shortcuts = (List<String>)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS);
if (shortcuts != null && shortcuts.size() > shortcutEvent.Index)
List<String> 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<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
@@ -398,8 +420,8 @@ public class UserShortcutsBean implements Serializable
tx = Repository.getUserTransaction(context);
tx.begin();
List<String> shortcuts = (List<String>)PreferencesService.getPreferences(context).getValue(PREF_SHORTCUTS);
if (shortcuts != null && shortcuts.size() > shortcutEvent.Index)
List<String> shortcuts = getShortcutList(context);
if (shortcuts.size() > shortcutEvent.Index)
{
// remove the shortcut from the saved list and persist back
shortcuts.remove(shortcutEvent.Index);