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 modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* END COPYRIGHT BLOCK **/
20
package com.netscape.admin.dirserv.task;
24
import java.io.InputStream;
25
import java.io.ByteArrayInputStream;
26
import java.io.UnsupportedEncodingException;
27
import com.netscape.management.client.util.AdmTask;
28
import com.netscape.management.client.comm.CommManager;
29
import com.netscape.management.client.comm.HttpManager;
30
import com.netscape.management.client.util.Debug;
31
import com.netscape.management.client.util.URLByteEncoder;
32
import com.netscape.management.client.console.ConsoleInfo;
33
import com.netscape.admin.dirserv.IEntryChangeListener;
34
import com.netscape.admin.dirserv.DSBaseModel;
35
import com.netscape.admin.dirserv.GlobalConstants;
38
* Netscape Directory Server 4.0 generic task that returns output in a
39
* Vector, and/or calls a listener for each line read from the CGI. The
40
* call is executed in "asynchronous response" mode, unlike AdmTask, so
41
* you can display progress, for example, during the CGI execution.
46
* @see com.netscape.admin.dirserv.DSAdmin
47
* @see com.netscape.admin.dirserv.task.CGITask
49
public class CGIReportTask extends AdmTask {
50
public CGIReportTask( URL url, ConsoleInfo info, Vector v ) {
51
super( url, getAuthenticationDN(info),
52
getAuthenticationPwd(info) );
56
public CGIReportTask( URL url, ConsoleInfo info ) {
57
this( url, info, null );
60
_responseString = new StringBuffer();
63
int flags = CommManager.FORCE_BASIC_AUTH|
64
CommManager.ASYNC_RESPONSE;
65
// Execute the request
66
HttpManager httpManager = new HttpManager();
67
// tell the http manager to use UTF8 encoding
68
httpManager.setSendUTF8(true);
69
InputStream data = null;
70
Hashtable args = getArguments();
71
if (args != null && !args.isEmpty())
73
Debug.println("CGIReportTask.exec(): username=" +
74
username(null, null) +
75
" password=" + password(null, null));
77
httpManager.post(_url, this, null, null, 0,
80
httpManager.post(_url, this, null, data, data.available(),
83
} catch (Exception e) {
84
System.err.println(e);
89
public void parse(String s) {
91
if ( _lines != null ) {
92
_lines.addElement( s );
94
Debug.println( "<- " + s );
96
if ( _listener != null ) {
97
if ( !_listener.entryChanged( s ) ) {
98
/* In this context, CANCEL is
104
public void addEntryChangeListener( IEntryChangeListener listener ) {
105
_listener = listener;
108
static private String getAuthenticationDN(ConsoleInfo info) {
109
String dn = (String)info.get(GlobalConstants.TASKS_AUTH_DN);
111
dn = info.getAuthenticationDN();
115
static private String getAuthenticationPwd(ConsoleInfo info) {
116
String pwd = (String)info.get(GlobalConstants.TASKS_AUTH_PWD);
118
pwd = info.getAuthenticationPassword();
123
* Translates a hashtable into <code>x-www-form-urlencoded</code> format.
124
* Values are converted from Unicode to UTF8 before URL encoding.
126
* @param args <code>Hashtable</code> containing name/value pairs to be translated.
127
* @return a ByteArrayInputStream to the translated <code>Hashtable</code> contents.
129
public static ByteArrayInputStream encode(Hashtable args)
131
if ((args == null) || (args.size() == 0))
135
Enumeration e = args.keys();
137
while (e.hasMoreElements())
139
String name = (String)e.nextElement();
140
String value = URLByteEncoder.encodeUTF8(args.get(name).toString());
141
p += URLByteEncoder.encodeUTF8(name) + "=" +
142
value + (e.hasMoreElements()?"&":"");
145
return new ByteArrayInputStream(p.getBytes());
149
private IEntryChangeListener _listener = null;
150
private Vector _lines;