001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.context;
006:
007: import java.util.Set;
008: import java.util.Map;
009: import java.util.HashMap;
010: import com.iplanet.sso.SSOToken;
011: import javax.servlet.http.HttpServletRequest;
012:
013: public class DSAMEDPUserContext implements DPUserContext,
014: DSAMEConstants {
015:
016: protected DSAMEConnection dsameConn = null;
017: protected Map dpDocumentsLastRead = new HashMap();
018: protected long dpUserDocumentLastRead = -1;
019:
020: private DesktopAppContext dac = null;
021:
022: private static DSAMEMultiPortalConstants dmpc = DSAMEMultiPortalConstants
023: .getInstance();
024:
025: public DSAMEDPUserContext() {
026: dac = DesktopAppContextThreadLocalizer.get();
027: }
028:
029: public synchronized void init(SSOToken ssoToken) {
030: dsameConn = new DSAMEConnection(ssoToken);
031: }
032:
033: public synchronized void init(HttpServletRequest req) {
034: dsameConn = new DSAMEConnection(req);
035: }
036:
037: public void init(HttpServletRequest req, String uid, String pw) {
038: dsameConn = new DSAMEConnection(uid, pw);
039: }
040:
041: public byte[] getDPUserDocument() {
042: byte[] userDP = dsameConn
043: .getAttributeByteArrayFromROC(dmpc.MP_ATTR_DP_DOCUMENT_USER);
044: setDPUserDocumentLastRead();
045:
046: return userDP;
047: }
048:
049: protected void setDPUserDocumentLastModified() {
050: dsameConn.setAttribute(dmpc.MP_ATTR_DP_LAST_MODIFIED_USER, Long
051: .toString(System.currentTimeMillis()));
052: }
053:
054: public void storeDPUserDocument(String dp) {
055: if (dp != null) {
056: dsameConn.setAttribute(dmpc.MP_ATTR_DP_DOCUMENT_USER, dp);
057: setDPUserDocumentLastModified();
058:
059: //
060: // when we set the user document, it is assumed
061: // we have the latest copy so set the last
062: // read AFTER we set the last modified, to make
063: // sure we don't fool apps into re-reading just because
064: // they set the value
065: //
066: setDPUserDocumentLastRead();
067: }
068: }
069:
070: public Set getDPDocumentNames() {
071: Set names = dsameConn.getNodeNamesFromROC();
072: return names;
073: }
074:
075: protected void setDPUserDocumentLastRead() {
076: long lastRead = System.currentTimeMillis();
077: dpUserDocumentLastRead = lastRead;
078: }
079:
080: protected void setDPDocumentLastRead(String name) {
081: Long l = new Long(System.currentTimeMillis());
082: dpDocumentsLastRead.put(name, l);
083: }
084:
085: public String getDPDocument(String name) {
086: if (!dsameConn.isGlobal(name)) {
087: boolean isDesktopServiceAssigned = dsameConn
088: .isServiceAssigned(name,
089: dmpc.MP_SUN_DESKTOP_SERVICE);
090: if (!isDesktopServiceAssigned) {
091: throw new ContextError(
092: "DSAMEAdminDPContext.getDPDocument(): "
093: + "DesktopService not assigned to this dn : "
094: + name);
095: }
096: }
097: String d = dsameConn.getAttributeByDNFromROC(name,
098: ATTR_DP_DOCUMENT);
099: setDPDocumentLastRead(name);
100:
101: return d;
102: }
103:
104: public long getDPDocumentLastModified(String name) {
105: String lm = dsameConn.getAttributeByDNFromROC(name,
106: ATTR_DP_LAST_MODIFIED);
107: //debugError("DSAMEDPContext.getDPDocumentLastModified(): name=" + name + ", lm=" + lm);
108: long lastModified;
109:
110: if (lm == null) {
111: //throw new ContextError("DSAMEDPContext.getDPDocumentLastModified(): could not get last modified value for name=" + name);
112: //
113: // TBD(jtb): is this an error?
114: //
115: lastModified = -1;
116: } else {
117: try {
118: lastModified = Long.parseLong(lm);
119: } catch (NumberFormatException nfe) {
120: lastModified = -1;
121: }
122: }
123:
124: return lastModified;
125: }
126:
127: public long getDPUserDocumentLastModified() {
128: String lm = dsameConn
129: .getAttributeFromROC(dmpc.MP_ATTR_DP_LAST_MODIFIED_USER);
130: long lastModified;
131:
132: if (lm == null) {
133: //
134: // TBD(jtb): is this an error?
135: //
136: lastModified = -1;
137: } else {
138: try {
139: lastModified = Long.parseLong(lm);
140: } catch (NumberFormatException nfe) {
141: lastModified = -1;
142: }
143: }
144:
145: return lastModified;
146: }
147:
148: public long getDPUserDocumentLastRead() {
149: return dpUserDocumentLastRead;
150: }
151:
152: public long getDPDocumentLastRead(String name) {
153: Long l = (Long) dpDocumentsLastRead.get(name);
154: long lastRead = -1;
155: if (l != null) {
156: lastRead = l.longValue();
157: }
158: return lastRead;
159: }
160: }
|