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