1
/** BEGIN COPYRIGHT BLOCK
2
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
3
* Copyright (C) 2005 Red Hat, Inc.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; version 2
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
* END COPYRIGHT BLOCK **/
21
package com.netscape.management.admserv.panel;
25
import java.text.MessageFormat;
26
import com.netscape.management.client.util.*;
27
import com.netscape.management.client.comm.HttpChannel;
28
import com.netscape.management.client.console.ConsoleInfo;
29
import com.netscape.management.admserv.config.*;
33
* @version 0.1 11/28/97
34
* @author miodrag@netscape.com
36
public abstract class CGIDataModel implements IConfigDataModel {
38
static ResourceSet _resource;
39
static String _i18nProgressLoading, _i18nProgressSaving,
40
_i18nLoadFailed, _i18nSaveFailed;
43
_resource = new ResourceSet("com.netscape.management.admserv.panel.panel");
44
_i18nProgressLoading = _resource.getString("adminop","ProgressLoading");
45
_i18nProgressSaving = _resource.getString("adminop","ProgressSaving");
46
_i18nLoadFailed = _resource.getString("adminop","LoadFailed");
47
_i18nSaveFailed = _resource.getString("adminop","SaveFailed");
50
protected Hashtable _data, _origData;
51
protected ConsoleInfo _consoleInfo;
52
protected boolean _loaded, _saved, _modified;
53
protected String _taskURL;
54
protected String _adminURL;
56
protected java.awt.Component _dialogParent; // for info messages
58
public CGIDataModel(ConsoleInfo consoleInfo, String taskURL) {
59
_consoleInfo = consoleInfo;
61
_adminURL = _consoleInfo.getAdminURL() + _taskURL;
64
static public String getServerName(ConsoleInfo ci) {
65
String server = (String) ci.get("SERVER_NAME");
67
Debug.println("CGIDataModel.getServerName: SERVER_NAME not found in console info");
73
public String getModelName() {
74
return getServerName(_consoleInfo);
78
public ConsoleInfo getConsoleInfo() {
82
public Enumeration getAttributes() {
87
* Implements IConfigDataModel.isLoaded()
89
public boolean isLoaded() {
94
* Implements IConfigDataModel.load()
96
public void load() throws RemoteRequestException {
97
if (ActionMonitorPanel.getActiveInstance() != null) {
98
MessageFormat msg = new MessageFormat(_i18nProgressLoading);
99
Object[] msgArgs = { "" }; //{ getModelName() };
100
ActionMonitorPanel.getActiveInstance().setStatusText(
101
msg.format(msgArgs));
103
_data = getConfiguration(_adminURL, getCGIParamsForGetOp());
104
_loaded = ! _data.isEmpty();
106
throw new RemoteRequestException(_adminURL, _i18nLoadFailed);
108
_origData = cloneStringHashtable(_data, null);
112
* Implements IConfigDataModel.isLoaded()
114
public boolean isModified() {
115
//Debug.println(getClass().getName() + " modified=" + _modified);
121
* Implements IConfigDataModel.save()
123
public void save() throws RemoteRequestException {
124
if (ActionMonitorPanel.getActiveInstance() != null) {
125
MessageFormat msg = new MessageFormat(_i18nProgressSaving);
126
Object[] msgArgs = { getModelName()};
127
ActionMonitorPanel.getActiveInstance().setStatusText(
128
msg.format(msgArgs));
132
setConfiguration(_adminURL, getCGIParamsForSetOp());
134
throw new RemoteRequestException(_adminURL,
137
} catch (RemoteRequestException e) {
139
_data = cloneStringHashtable(_origData, null);
143
_origData = cloneStringHashtable(_data, null);
148
* Implements IConfigDataModel.getAttribute()
150
public String getAttribute(String attr) {
151
return (String)_data.get(attr);
155
* Implements IConfigDataModel.setAttribute()
158
public void setAttribute(String attr,
159
String val) throws ValidationException {
160
String curVal = getAttribute(attr);
162
_modified = (val == null) ? (curVal != null) :
163
!(val.equals(curVal));
165
//Debug.println(attr + " curVal="+curVal+" val="+val+"modified="+_modified);
166
_data.put(attr, val);
170
public String toURLformat(Hashtable args) {
172
Enumeration e = args.keys();
173
while (e.hasMoreElements()) {
174
String name = (String) e.nextElement();
175
String value = (String) args.get(name);
177
p += name + "=" + URLByteEncoder.encodeUTF8(value) +
178
(e.hasMoreElements() ? "&":"");
183
public static Hashtable cloneStringHashtable(Hashtable tbl,
184
String renamePrefix) {
185
Hashtable out = new Hashtable();
186
for (Enumeration e = tbl.keys(); e.hasMoreElements();) {
187
String key = (String) e.nextElement();
188
String val = (String) tbl.get(key);
190
if (renamePrefix == null) {
191
out.put(new String(key), new String(val));
193
out.put(renamePrefix + key, new String(val));
200
public static Vector commaStringToVector(String s) {
201
Vector v = new Vector();
203
StringTokenizer st = new StringTokenizer(s, ",");
204
while (st.hasMoreTokens()) {
205
v.addElement(st.nextToken());
211
public static String vectorToCommaString(Vector v) {
213
Enumeration e = v.elements();
214
while (e.hasMoreElements()) {
215
s = s + e.nextElement();
216
if (e.hasMoreElements())
222
public java.awt.Component getDialogParent() {
223
return _dialogParent;
226
public void setDialogParent (java.awt.Component comp) {
227
_dialogParent = comp;
231
* CGI arguments used in getConfiguration()
233
public abstract String getCGIParamsForGetOp();
236
* CGI arguments used in setConfiguration()
238
public abstract String getCGIParamsForSetOp();
240
protected Hashtable getConfiguration(String adminURL,
241
String args) throws RemoteRequestException {
244
task = new AdmTask(new URL(adminURL),
245
_consoleInfo.getAuthenticationDN(),
246
_consoleInfo.getAuthenticationPassword());
247
} catch (MalformedURLException e) {
248
Debug.println("CGIDataModel.getConfiguration "+e);
249
throw new RemoteRequestException(e);
254
//task.setArguments(HttpChannel._encode(args));
255
task.setArguments(args);
259
int status = task.getStatus();
260
_loaded = (status == 0);
261
Debug.println("CGIDataModel.getConfiguration(): called URL " +
262
adminURL + " "+status);
264
AdminOperation.processAdmTaskStatus(adminURL, task, _consoleInfo);
267
//Debug.printHashtable("config", task.getResult());
268
return task.getResult();
271
return new Hashtable();
275
protected void setConfiguration(String adminURL,
276
String args) throws RemoteRequestException {
279
task = new AdmTask(new URL(adminURL),
280
_consoleInfo.getAuthenticationDN(),
281
_consoleInfo.getAuthenticationPassword());
282
} catch (MalformedURLException e) {
283
Debug.println("CGIDataModel.setConfiguration "+e);
284
throw new RemoteRequestException(e);
289
task.setArguments(args);
293
int status = task.getStatus();
294
Debug.println(adminURL + " "+status);
295
_saved = (status == 0);
296
AdminOperation.processAdmTaskStatus(adminURL, task, _consoleInfo);