001: /**
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: *
013: * Author: Anurag Gupta
014: */package com.sun.portal.netfile.admin;
015:
016: // JDK classes
017: import java.util.MissingResourceException;
018: import com.sun.portal.log.common.PortalLogger;
019: import java.util.ResourceBundle;
020:
021: // iPlanet JATO classes
022: import com.iplanet.jato.ModelManager;
023: import com.iplanet.jato.ModelTypeMap;
024: import com.iplanet.jato.RequestContext;
025:
026: // iDS/AME classes
027: import com.iplanet.am.console.base.model.AMModelBase;
028: import com.iplanet.am.util.Debug;
029: import com.iplanet.am.util.Locale;
030: import com.iplanet.sso.SSOException;
031: import com.iplanet.sso.SSOToken;
032: import com.iplanet.sso.SSOTokenManager;
033:
034: public class NetFileAdminModelManager extends ModelManager {
035:
036: public static final String SRAP_NETFILE_MODEL_MGR_KEY = "srapNetFileModelMgrKey";
037:
038: private static final String TOKEN_DELIMITER = "|";
039:
040: protected SSOToken token = null;
041: protected String rbName = "srapNetFileAdminMsgs";
042: protected ResourceBundle bundle = null;
043: protected java.util.Locale locale = null;
044: private static Debug debug = AMModelBase.debug;
045: private static String CURR_NETFILEHOSTS_ROW = "currentNetFileHostsRow";
046:
047: static {
048: if (AMModelBase.debug == null) {
049: debug = AMModelBase.debug = com.iplanet.am.util.Debug
050: .getInstance("amConsole");
051: }
052:
053: }
054:
055: public NetFileAdminModelManager(RequestContext requestContext,
056: ModelTypeMap typeMap) {
057: super (requestContext, typeMap);
058: initSSOToken(requestContext);
059: initRB();
060: }
061:
062: /**
063: * Initializes the SSO token for use in this request. The SSO token
064: * can then be used as a store for session info across requests.
065: * @param requestContext is the JATO request context.
066: */
067: void initSSOToken(RequestContext requestContext) {
068: try {
069: SSOTokenManager manager = SSOTokenManager.getInstance();
070: token = manager.createSSOToken(requestContext.getRequest());
071: manager.getInstance().validateToken(token);
072: } catch (Exception e) {
073: token = null;
074: }
075: }
076:
077: /**
078: * Initializes the resuource bundle using the locale from the
079: * SSO token.
080: */
081: void initRB() {
082: if (token != null) {
083: try {
084: String lstr = token.getProperty("Locale");
085: locale = Locale.getLocale(lstr);
086: } catch (SSOException ssoe) {
087: locale = java.util.Locale.getDefault();
088: }
089: } else {
090: locale = java.util.Locale.getDefault();
091: }
092: try {
093: bundle = ResourceBundle.getBundle(rbName, locale);
094: } catch (MissingResourceException mre) {
095: }
096: }
097:
098: public static boolean warningEnabled() {
099: return debug.warningEnabled();
100: }
101:
102: public static boolean messageEnabled() {
103: return debug.messageEnabled();
104: }
105:
106: public static void debugWarning(String message) {
107: if (debug.warningEnabled())
108: debug.warning(message);
109: }
110:
111: public static void debugWarning(String message, Throwable t) {
112: if (debug.warningEnabled())
113: debug.warning(message, t);
114: }
115:
116: public static void debugMessage(String message) {
117: if (debug.messageEnabled())
118: debug.message(message);
119: }
120:
121: public static void debugMessage(String message, Throwable t) {
122: if (debug.messageEnabled())
123: debug.message(message, t);
124: }
125:
126: public static void debugError(String message) {
127: debug.error(message);
128: }
129:
130: public static void debugError(String message, Throwable t) {
131: debug.error(message, t);
132: }
133:
134: /**
135: * Returns the localized resource string for the corresponding
136: * resource key.
137: */
138: public String getString(String key) {
139: String result = null;
140: try {
141: if (bundle != null) {
142: result = bundle.getString(key);
143: }
144: } catch (MissingResourceException mre) {
145: }
146: return (result == null ? key : result);
147: }
148:
149: public ResourceBundle getAdminMsgsRB() {
150: return bundle;
151: }
152:
153: public void setCurrentNetFileHostsRow(int currRow) {
154: if (token != null) {
155: try {
156: token.setProperty(CURR_NETFILEHOSTS_ROW, "" + currRow);
157: } catch (SSOException ssoe) {
158: NetFileAdminModelManager
159: .debugError("Error setting currentRow in ssoToken - "
160: + ssoe);
161: }
162: }
163: }
164:
165: public int getCurrentNetFileHostsRow() {
166: String tmp = null;
167: int currRow = -1;
168: if (token != null) {
169: try {
170: tmp = token.getProperty(CURR_NETFILEHOSTS_ROW);
171: currRow = Integer.parseInt(tmp.trim());
172: } catch (SSOException ssoe) {
173: currRow = -1;
174: NetFileAdminModelManager
175: .debugError("Error getting currentRow from ssoToken - "
176: + ssoe);
177: } catch (NumberFormatException nfe) {
178: currRow = -1;
179: NetFileAdminModelManager
180: .debugError("Error getting currentRow from ssoToken - "
181: + nfe);
182: }
183: }
184: return currRow;
185: }
186:
187: /* public void storeToSession(String key, String value) {
188: if (token != null) {
189: try {
190: token.setProperty(key, value);
191: } catch(SSOException ssoe) {
192: NetFileAdminModelManager.debugError("Error setting property in ssoToken - " + ssoe);
193: }
194: }
195: }
196:
197: public String getFromSession(String key) {
198: String value = null;
199: if (token != null) {
200: try {
201: value = token.getProperty(key);
202: } catch(SSOException ssoe) {
203: NetFileAdminModelManager.debugError("Error getting property from ssoToken - " + ssoe);
204: }
205: }
206: return value;
207: }
208: */
209: }
|