01: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.dlm;
07:
08: import org.jasig.portal.security.IPerson;
09: import org.w3c.dom.Attr;
10: import org.w3c.dom.Document;
11: import org.w3c.dom.Element;
12: import org.w3c.dom.NodeList;
13:
14: /**
15: * Applies user changes that are part of the uPortal User Preferences
16: * storage (not part of the layout structure) to the user's plf prior to
17: * persisting.
18: *
19: * @version $Revision: 36477 $ $Date: 2006-02-07 15:22:28 -0700 (Tue, 07 Feb 2006) $
20: * @since uPortal 2.5
21: */
22: public class UserPrefsHandler {
23: public static final String RCS_ID = "@(#) $Header$";
24:
25: /**
26: Records changes made to element attributes that are defined as being
27: part of a user's user preferences object and not part of the layout.
28: These attributes are specified in the .sdf files for the structure and
29: theme stylesheets. The value is not stored in the layout but the loading
30: of user prefs joins to a layout struct and hence that struct must exist
31: in the layout. This call gets that node into the PLF if not there
32: already and prevents it from being removed if no other changes were made
33: to it or its children by the user.
34: */
35: public static void setUserPreference(Element compViewNode,
36: String attributeName, IPerson person) throws Exception {
37: Document doc = compViewNode.getOwnerDocument();
38: NodeList nodes = doc.getElementsByTagName("layout");
39:
40: boolean layoutOwner = false;
41: boolean templateUser = false;
42: Attr attrib = null;
43: Element e = null;
44: // Search Elements in nodelist
45: for (int i = 0; i < nodes.getLength(); i++) {
46: e = (Element) nodes.item(i);
47: attrib = e.getAttributeNodeNS(Constants.NS_URI,
48: Constants.LCL_FRAGMENT_NAME);
49: if (attrib != null) {
50: layoutOwner = true;
51: } else {
52: attrib = e.getAttributeNodeNS(Constants.NS_URI,
53: Constants.LCL_IS_TEMPLATE_USER);
54: if (attrib != null) {
55: templateUser = true;
56: }
57: }
58: }
59:
60: if (!layoutOwner && !templateUser) {
61: Element plfNode = HandlerUtils.getPLFNode(compViewNode,
62: person, true, // create if not found
63: false);
64: if (plfNode.getAttributeNodeNS(Constants.NS_URI,
65: Constants.LCL_ORIGIN) != null)
66: EditManager.addPrefsDirective(plfNode, attributeName,
67: person);
68: }
69: }
70: }
|