001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.desktop.context;
007:
008: import java.util.Set;
009: import java.util.Map;
010: import java.util.HashMap;
011:
012: import com.sun.portal.util.SSOUtil;
013:
014: import javax.servlet.http.HttpServletRequest;
015:
016: public class DSAMEDPContext implements DPContext, DSAMEConstants {
017:
018: protected DesktopAppContext desktopAppContext = null;
019: protected DSAMEConnection dsameConn = null;
020:
021: protected Map dpDocumentsLastRead = new HashMap();
022:
023: private DSAMEMultiPortalConstants dmpc = null;
024:
025: public DSAMEDPContext() {
026: // nothing
027: }
028:
029: public void init(HttpServletRequest req) {
030:
031: desktopAppContext = DesktopAppContextThreadLocalizer.get();
032: //
033: // create an admin sso token for this class ... this class is app-only
034: //
035: dmpc = DSAMEMultiPortalConstants.getInstance();
036:
037: dsameConn = new DSAMEConnection(SSOUtil.getAdminSSOToken());
038: }
039:
040: public void init(String portalId) {
041: DSAMEMultiPortalConstants.createInstance(portalId);
042: dmpc = DSAMEMultiPortalConstants.getInstance(portalId);
043: //
044: // create an admin sso token for this class ... this class is app-only
045: //
046:
047: dsameConn = new DSAMEConnection(SSOUtil.getAdminSSOToken(),
048: portalId);
049: }
050:
051: public boolean isValidating() {
052: String val = dsameConn.getGlobalAttributeFromROC(
053: dmpc.MP_SUN_DESKTOP_SERVICE, ATTR_DP_ISVALIDATING);
054: return Boolean.valueOf(val).booleanValue();
055: }
056:
057: public String getNameSpaceURI() {
058: return dsameConn.getGlobalAttributeFromROC(
059: dmpc.MP_SUN_DESKTOP_SERVICE, ATTR_DP_NAMESPACEURI);
060: }
061:
062: public String getDPDocument(String name) {
063: if (!dsameConn.isGlobal(name)) {
064: boolean isDesktopServiceAssigned = dsameConn
065: .isServiceAssigned(name,
066: dmpc.MP_SUN_DESKTOP_SERVICE);
067: if (!isDesktopServiceAssigned) {
068: throw new ContextError(
069: "DSAMEAdminDPContext.getDPDocument(): "
070: + "DesktopService not assigned to this dn : "
071: + name);
072: }
073: }
074: String d = dsameConn.getAttributeByDNFromROC(name,
075: ATTR_DP_DOCUMENT);
076: setDPDocumentLastRead(name);
077:
078: return d;
079: }
080:
081: public Set getDPDocumentNames(String name) {
082: return dsameConn.getNodeNames(name);
083: }
084:
085: public long getDPDocumentLastModified(String name) {
086: String lm = dsameConn.getAttributeByDNFromROC(name,
087: ATTR_DP_LAST_MODIFIED);
088: long lastModified;
089:
090: if (lm == null) {
091: lastModified = -1;
092: } else {
093: try {
094: lastModified = Long.parseLong(lm);
095: } catch (NumberFormatException nfe) {
096: lastModified = -1;
097: }
098: }
099:
100: return lastModified;
101: }
102:
103: public long getDPDocumentLastRead(String name) {
104: Long l = (Long) dpDocumentsLastRead.get(name);
105: long lastRead = -1;
106: if (l != null) {
107: lastRead = l.longValue();
108: }
109: return lastRead;
110: }
111:
112: protected void setDPDocumentLastRead(String name) {
113: Long l = new Long(System.currentTimeMillis());
114: dpDocumentsLastRead.put(name, l);
115: }
116:
117: }
|