private static void setPreferenceList(String name, Collection values) throws Exception { PreferencesEdit prefsEdit = null; String userId = M_sm.getCurrentSessionUserId(); try { prefsEdit = M_ps.edit(userId); } catch (IdUnusedException e) { prefsEdit = M_ps.add(userId); } try { ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY); if (values == null) { props.removeProperty(name); } else { List existing = props.getPropertyList(name); Iterator it = values.iterator(); while (it.hasNext()) { String value = (String) it.next(); if (existing == null || !existing.contains(value)) props.addPropertyToList(name, value.toString()); } } } catch (Exception e) { if (prefsEdit != null) M_ps.cancel(prefsEdit); M_ps.cancel(prefsEdit); throw e; } M_ps.commit(prefsEdit); }
@Override public void setDefaultPrivacyState(String userId, String visibility) { if (userId == null) { log.warn("Cannot set priavacy status for a null userId"); return; } if (visibility == null) { visibility = PrivacyManager.VISIBLE; } PreferencesEdit editPref; try { editPref = preferencesService.edit(userId); ResourcePropertiesEdit props = editPref.getPropertiesEdit(PRIVACY_PREFS); props.addProperty(PrivacyManager.DEFAULT_PRIVACY_KEY, visibility); preferencesService.commit(editPref); } catch (PermissionException e) { log.warn( "You do not have the appropriate permissions to edit preferences for user: "******". " + e.getMessage()); } catch (InUseException e) { log.warn( "Preferences for user: "******" are currently being edited. " + e.getMessage()); } catch (IdUnusedException e) { try { editPref = preferencesService.add(userId); ResourcePropertiesEdit props = editPref.getPropertiesEdit(PRIVACY_PREFS); props.addProperty(PrivacyManager.DEFAULT_PRIVACY_KEY, visibility); preferencesService.commit(editPref); } catch (PermissionException e1) { // TODO Auto-generated catch block log.warn( "You do not have the appropriate permissions to edit preferences for user: "******". " + e1.getMessage()); } catch (IdUsedException e1) { log.warn( "No preferences for user: "******" found intially, attempted to add new preferences. " + e1.getMessage()); } } }
private static void clearPreferenceList(String name) throws Exception { PreferencesEdit prefsEdit = null; try { prefsEdit = M_ps.edit(M_sm.getCurrentSessionUserId()); ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY); props.removeProperty(name); } catch (Exception e) { M_ps.cancel(prefsEdit); throw e; } M_ps.commit(prefsEdit); }
private static void setPreferenceString(String name, String value) throws Exception { PreferencesEdit prefsEdit = null; String userId = M_sm.getCurrentSessionUserId(); try { prefsEdit = M_ps.edit(userId); } catch (IdUnusedException e) { prefsEdit = M_ps.add(userId); } try { ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY); if (value == null) { props.removeProperty(name); } else { props.addProperty(name, value.toString()); } } catch (Exception e) { if (prefsEdit != null) M_ps.cancel(prefsEdit); throw e; } M_ps.commit(prefsEdit); }