1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that implements a metadata catalog as a java Servlet
|
4
|
* Copyright: 2000 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Matt Jones, Dan Higgins
|
7
|
*
|
8
|
* '$Author: jones $'
|
9
|
* '$Date: 2000-06-30 18:09:44 -0700 (Fri, 30 Jun 2000) $'
|
10
|
* '$Revision: 253 $'
|
11
|
*/
|
12
|
|
13
|
package edu.ucsb.nceas.metacat;
|
14
|
|
15
|
import java.io.PrintWriter;
|
16
|
import java.io.IOException;
|
17
|
import java.io.Reader;
|
18
|
import java.io.StringReader;
|
19
|
import java.io.BufferedReader;
|
20
|
import java.io.File;
|
21
|
import java.io.FileInputStream;
|
22
|
import java.util.Enumeration;
|
23
|
import java.util.Hashtable;
|
24
|
import java.util.ResourceBundle;
|
25
|
import java.util.PropertyResourceBundle;
|
26
|
import java.net.URL;
|
27
|
import java.net.MalformedURLException;
|
28
|
import java.sql.PreparedStatement;
|
29
|
import java.sql.ResultSet;
|
30
|
import java.sql.Connection;
|
31
|
import java.sql.SQLException;
|
32
|
|
33
|
import javax.servlet.ServletConfig;
|
34
|
import javax.servlet.ServletContext;
|
35
|
import javax.servlet.ServletException;
|
36
|
import javax.servlet.ServletInputStream;
|
37
|
import javax.servlet.http.HttpServlet;
|
38
|
import javax.servlet.http.HttpServletRequest;
|
39
|
import javax.servlet.http.HttpServletResponse;
|
40
|
import javax.servlet.http.HttpSession;
|
41
|
import javax.servlet.http.HttpUtils;
|
42
|
|
43
|
import oracle.xml.parser.v2.XSLStylesheet;
|
44
|
import oracle.xml.parser.v2.XSLException;
|
45
|
import oracle.xml.parser.v2.XMLDocumentFragment;
|
46
|
import oracle.xml.parser.v2.XSLProcessor;
|
47
|
|
48
|
import org.xml.sax.SAXException;
|
49
|
|
50
|
/**
|
51
|
* A metadata catalog server implemented as a Java Servlet
|
52
|
*
|
53
|
* <p>Valid parameters are:<br>
|
54
|
* action=query -- query the values of all elements and attributes
|
55
|
* and return a result set of nodes<br>
|
56
|
* action=squery -- structured query (see pathquery.dtd)<br>
|
57
|
* action=insert -- insert an XML document into the database store<br>
|
58
|
* action=update -- update an XML document that is in the database store<br>
|
59
|
* action=delete -- delete an XML document from the database store<br>
|
60
|
* action=validate -- vallidate the xml contained in valtext<br>
|
61
|
* action=getdocument -- display an XML document in XML or HTML<br>
|
62
|
* doctype -- document type list returned by the query (publicID)<br>
|
63
|
* qformat=xml -- display resultset from query in XML<br>
|
64
|
* qformat=html -- display resultset from query in HTML<br>
|
65
|
* docid=34 -- display the document with the document ID number 34<br>
|
66
|
* doctext -- XML text of the document to load into the database<br>
|
67
|
* query -- actual query text (to go with 'action=query' or 'action=squery')<br>
|
68
|
* valtext -- XML text to be validated<br>
|
69
|
* action=getdatadoc -- retreive a stored datadocument<br>
|
70
|
* datadoc -- data document name (id)<br>
|
71
|
* <p>
|
72
|
* The particular combination of parameters that are valid for each
|
73
|
* particular action value is quite specific. This documentation
|
74
|
* will be reorganized to reflect this information.
|
75
|
*/
|
76
|
public class MetaCatServlet extends HttpServlet {
|
77
|
|
78
|
private ServletConfig config = null;
|
79
|
private ServletContext context = null;
|
80
|
private Connection conn = null;
|
81
|
private DBQuery queryobj = null;
|
82
|
private DBReader docreader = null;
|
83
|
private DBTransform dbt = null;
|
84
|
private String resultStyleURL = null;
|
85
|
private String xmlcatalogfile = null;
|
86
|
private String saxparser = null;
|
87
|
private String defaultdatapath = null;
|
88
|
// path to directory where data files
|
89
|
// that can be downloaded will be stored
|
90
|
private String executescript = null;
|
91
|
// script to get data file and put it
|
92
|
// in defaultdocpath dir
|
93
|
private PropertyResourceBundle options = null;
|
94
|
|
95
|
private MetaCatUtil util = null;
|
96
|
|
97
|
/**
|
98
|
* Initialize the servlet by creating appropriate database connections
|
99
|
*/
|
100
|
public void init( ServletConfig config ) throws ServletException {
|
101
|
try {
|
102
|
super.init( config );
|
103
|
this.config = config;
|
104
|
this.context = config.getServletContext();
|
105
|
System.out.println("MetaCatServlet Initialize");
|
106
|
|
107
|
util = new MetaCatUtil();
|
108
|
|
109
|
// Get the configuration file information
|
110
|
resultStyleURL = util.getOption("resultStyleURL");
|
111
|
xmlcatalogfile = util.getOption("xmlcatalogfile");
|
112
|
saxparser = util.getOption("saxparser");
|
113
|
defaultdatapath = util.getOption("defaultdatapath");
|
114
|
executescript = util.getOption("executescript");
|
115
|
|
116
|
try {
|
117
|
// Open a connection to the database
|
118
|
conn = util.openDBConnection();
|
119
|
|
120
|
queryobj = new DBQuery(conn,saxparser);
|
121
|
docreader = new DBReader(conn);
|
122
|
dbt = new DBTransform(conn);
|
123
|
|
124
|
} catch (Exception e) {
|
125
|
System.err.println("Error opening database connection");
|
126
|
}
|
127
|
} catch ( ServletException ex ) {
|
128
|
throw ex;
|
129
|
}
|
130
|
}
|
131
|
|
132
|
/** Handle "GET" method requests from HTTP clients */
|
133
|
public void doGet (HttpServletRequest request, HttpServletResponse response)
|
134
|
throws ServletException, IOException {
|
135
|
|
136
|
// Process the data and send back the response
|
137
|
handleGetOrPost(request, response);
|
138
|
}
|
139
|
|
140
|
/** Handle "POST" method requests from HTTP clients */
|
141
|
public void doPost( HttpServletRequest request, HttpServletResponse response)
|
142
|
throws ServletException, IOException {
|
143
|
|
144
|
// Process the data and send back the response
|
145
|
handleGetOrPost(request, response);
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* Control servlet response depending on the action parameter specified
|
150
|
*/
|
151
|
private void handleGetOrPost(HttpServletRequest request,
|
152
|
HttpServletResponse response)
|
153
|
throws ServletException, IOException {
|
154
|
|
155
|
if (conn == null) {
|
156
|
System.err.println("Connection to database lost. Reopening...");
|
157
|
try {
|
158
|
// Open a connection to the database
|
159
|
conn = util.openDBConnection();
|
160
|
|
161
|
queryobj = new DBQuery(conn, saxparser);
|
162
|
docreader = new DBReader(conn);
|
163
|
dbt = new DBTransform(conn);
|
164
|
|
165
|
} catch (Exception e) {
|
166
|
System.err.println("Error opening database connection");
|
167
|
}
|
168
|
}
|
169
|
|
170
|
// Get a handle to the output stream back to the client
|
171
|
PrintWriter out = response.getWriter();
|
172
|
//response.setContentType("text/html");
|
173
|
|
174
|
String name = null;
|
175
|
String[] value = null;
|
176
|
String[] docid = new String[3];
|
177
|
Hashtable params = new Hashtable();
|
178
|
Enumeration paramlist = request.getParameterNames();
|
179
|
while (paramlist.hasMoreElements()) {
|
180
|
name = (String)paramlist.nextElement();
|
181
|
value = request.getParameterValues(name);
|
182
|
|
183
|
// Decode the docid and mouse click information
|
184
|
if (name.endsWith(".y")) {
|
185
|
docid[0] = name.substring(0,name.length()-2);
|
186
|
//out.println("docid => " + docid[0]);
|
187
|
params.put("docid", docid);
|
188
|
name = "ypos";
|
189
|
}
|
190
|
if (name.endsWith(".x")) {
|
191
|
name = "xpos";
|
192
|
}
|
193
|
|
194
|
//out.println(name + " => " + value[0]);
|
195
|
params.put(name,value);
|
196
|
}
|
197
|
|
198
|
// Determine what type of request the user made
|
199
|
// if the action parameter is set, use it as a default
|
200
|
// but if the ypos param is set, calculate the action needed
|
201
|
String action = ((String[])params.get("action"))[0];
|
202
|
long ypos = 0;
|
203
|
try {
|
204
|
ypos = (new Long(((String[])params.get("ypos"))[0]).longValue());
|
205
|
//out.println("<P>YPOS IS " + ypos);
|
206
|
if (ypos <= 13) {
|
207
|
action = "getdocument";
|
208
|
} else if (ypos > 13 && ypos <= 27) {
|
209
|
action = "validate";
|
210
|
} else if (ypos > 27) {
|
211
|
action = "transform";
|
212
|
//} else {
|
213
|
// action = "";
|
214
|
}
|
215
|
} catch (Exception npe) {
|
216
|
//out.println("<P>Caught exception looking for Y value.");
|
217
|
}
|
218
|
|
219
|
// Jivka added
|
220
|
// handle login action
|
221
|
if (action.equals("Login")) {
|
222
|
handleLoginAction(out, params, request, response);
|
223
|
// handle logout action
|
224
|
} else if (action.equals("Logout")) {
|
225
|
HttpSession sess = request.getSession(false);
|
226
|
if (sess != null) { sess.invalidate(); }
|
227
|
response.sendRedirect("/xmltodb/lib/login.html");
|
228
|
// aware of session expiration on every request
|
229
|
} else {
|
230
|
HttpSession sess = request.getSession(false);
|
231
|
if (sess == null) {
|
232
|
// session expired or has not been stored b/w user requests
|
233
|
// redirect to session expiration message page
|
234
|
response.sendRedirect("/xmltodb/lib/sexpire.html");
|
235
|
}
|
236
|
}
|
237
|
// End of Jivka added
|
238
|
|
239
|
if (action.equals("query") || action.equals("squery")) {
|
240
|
handleQueryAction(out, params, response);
|
241
|
} else if (action.equals("getdocument")) {
|
242
|
try {
|
243
|
handleGetDocumentAction(out, params, response);
|
244
|
} catch (ClassNotFoundException e) {
|
245
|
out.println(e.getMessage());
|
246
|
} catch (SQLException se) {
|
247
|
out.println(se.getMessage());
|
248
|
}
|
249
|
} else if (action.equals("insert") || action.equals("update")) {
|
250
|
handleInsertOrUpdateAction(out, params, response);
|
251
|
} else if (action.equals("delete")) {
|
252
|
handleDeleteAction(out, params, response);
|
253
|
} else if (action.equals("validate")) {
|
254
|
handleValidateAction(out, params, response);
|
255
|
} else if (action.equals("getdatadoc")) {
|
256
|
handleGetDataDocumentAction(out, params, response);
|
257
|
} else if (action.equals("Login")) {
|
258
|
} else {
|
259
|
out.println("Error: action not registered. Please report this error.");
|
260
|
}
|
261
|
|
262
|
// Close the stream to the client
|
263
|
out.close();
|
264
|
}
|
265
|
|
266
|
// Jivka added
|
267
|
/**
|
268
|
* Handle the Login request. Create a new session object.
|
269
|
* Make a user authentication through SRB RMI Connection.
|
270
|
*/
|
271
|
|
272
|
private void handleLoginAction(PrintWriter out, Hashtable params,
|
273
|
HttpServletRequest request, HttpServletResponse response) {
|
274
|
|
275
|
String un = ((String[])params.get("username"))[0];
|
276
|
String pw = ((String[])params.get("password"))[0];
|
277
|
|
278
|
MetaCatSession sess = new MetaCatSession(request, un, pw);
|
279
|
|
280
|
try {
|
281
|
if (sess.userAuth(pw)) {
|
282
|
try {
|
283
|
response.sendRedirect(
|
284
|
response.encodeRedirectUrl("/xmltodb/lib/index.html"));
|
285
|
} catch ( java.io.IOException ioe) {
|
286
|
sess.disconnect();
|
287
|
out.println("MetaCatServlet.handleLoginAction() - " +
|
288
|
"Error on redirect of HttpServletResponse: " +
|
289
|
ioe.getMessage());
|
290
|
}
|
291
|
|
292
|
} else {
|
293
|
sess.disconnect();
|
294
|
out.println("SRB Connection failed. " +
|
295
|
"SRB RMI Server is not running now or " +
|
296
|
"user " + un +
|
297
|
" has not been authenticated to use the system.");
|
298
|
}
|
299
|
} catch ( java.rmi.RemoteException re) {
|
300
|
sess.disconnect();
|
301
|
out.println("SRB Connection failed. " + re.getMessage());
|
302
|
}
|
303
|
}
|
304
|
|
305
|
/**
|
306
|
* Handle the database query request and return a result set, possibly
|
307
|
* transformed from XML into HTML
|
308
|
*/
|
309
|
private void handleQueryAction(PrintWriter out, Hashtable params,
|
310
|
HttpServletResponse response) {
|
311
|
String action = ((String[])params.get("action"))[0];
|
312
|
String query = ((String[])params.get("query"))[0];
|
313
|
Hashtable doclist = null;
|
314
|
String[] doctypeArr = null;
|
315
|
String doctype = null;
|
316
|
Reader xmlquery = null;
|
317
|
|
318
|
// Run the query if it is a structured query
|
319
|
// or, if it is a free-text, simple query,
|
320
|
// format it first as a structured query and then run it
|
321
|
if (action.equals("query")) {
|
322
|
doctypeArr = (String[])params.get("doctype");
|
323
|
doctype = null;
|
324
|
if (doctypeArr != null) {
|
325
|
doctype = ((String[])params.get("doctype"))[0];
|
326
|
}
|
327
|
|
328
|
if (doctype != null) {
|
329
|
xmlquery = new StringReader(DBQuery.createQuery(query,doctype));
|
330
|
} else {
|
331
|
xmlquery = new StringReader(DBQuery.createQuery(query));
|
332
|
}
|
333
|
} else if (action.equals("squery")) {
|
334
|
xmlquery = new StringReader(query);
|
335
|
} else {
|
336
|
System.err.println("Error handling query -- illegal action value");
|
337
|
}
|
338
|
|
339
|
if (queryobj != null) {
|
340
|
doclist = queryobj.findDocuments(xmlquery);
|
341
|
} else {
|
342
|
out.println("Query Object Init failed.");
|
343
|
return;
|
344
|
}
|
345
|
|
346
|
// Create a buffer to hold the xml result
|
347
|
StringBuffer resultset = new StringBuffer();
|
348
|
|
349
|
// Print the resulting root nodes
|
350
|
String docid;
|
351
|
String document = null;
|
352
|
resultset.append("<?xml version=\"1.0\"?>\n");
|
353
|
//resultset.append("<!DOCTYPE resultset PUBLIC " +
|
354
|
// "\"-//NCEAS//resultset//EN\" \"resultset.dtd\">\n");
|
355
|
resultset.append("<resultset>\n");
|
356
|
resultset.append(" <query>" + query + "</query>");
|
357
|
Enumeration doclistkeys = doclist.keys();
|
358
|
while (doclistkeys.hasMoreElements()) {
|
359
|
docid = (String)doclistkeys.nextElement();
|
360
|
document = (String)doclist.get(docid);
|
361
|
resultset.append(" <document>" + document + "</document>");
|
362
|
}
|
363
|
resultset.append("</resultset>");
|
364
|
|
365
|
String qformat = ((String[])params.get("qformat"))[0];
|
366
|
if (qformat.equals("xml")) {
|
367
|
// set content type and other response header fields first
|
368
|
response.setContentType("text/xml");
|
369
|
out.println(resultset.toString());
|
370
|
} else if (qformat.equals("html")) {
|
371
|
// set content type and other response header fields first
|
372
|
response.setContentType("text/html");
|
373
|
//out.println("Converting to HTML...");
|
374
|
XMLDocumentFragment htmldoc = null;
|
375
|
try {
|
376
|
XSLStylesheet style = new XSLStylesheet(
|
377
|
new URL(resultStyleURL), null);
|
378
|
htmldoc = (new XSLProcessor()).processXSL(style,
|
379
|
(Reader)(new StringReader(resultset.toString())),null);
|
380
|
htmldoc.print(out);
|
381
|
} catch (Exception e) {
|
382
|
out.println("Error transforming document:\n" + e.getMessage());
|
383
|
}
|
384
|
}
|
385
|
}
|
386
|
|
387
|
/**
|
388
|
* Handle the database getdocument request and return a XML document,
|
389
|
* possibly transformed from XML into HTML
|
390
|
*/
|
391
|
private void handleGetDocumentAction(PrintWriter out, Hashtable params,
|
392
|
HttpServletResponse response)
|
393
|
throws ClassNotFoundException, IOException, SQLException {
|
394
|
String docidstr = null;
|
395
|
String docid = null;
|
396
|
String doc = null;
|
397
|
try {
|
398
|
// Find the document id number
|
399
|
docidstr = ((String[])params.get("docid"))[0];
|
400
|
//docid = (new Long(docidstr)).longValue();
|
401
|
docid = docidstr;
|
402
|
|
403
|
// Get the document indicated fromthe db
|
404
|
doc = docreader.readXMLDocument(docid);
|
405
|
} catch (NullPointerException npe) {
|
406
|
response.setContentType("text/html");
|
407
|
out.println("Error getting document ID: " + docidstr +" (" + docid + ")");
|
408
|
}
|
409
|
|
410
|
// Return the document in XML or HTML format
|
411
|
String qformat = ((String[])params.get("qformat"))[0];
|
412
|
if (qformat.equals("xml")) {
|
413
|
// set content type and other response header fields first
|
414
|
response.setContentType("text/xml");
|
415
|
out.println(doc);
|
416
|
} else if (qformat.equals("html")) {
|
417
|
// set content type and other response header fields first
|
418
|
response.setContentType("text/html");
|
419
|
|
420
|
// Look up the document type
|
421
|
String sourcetype = docreader.getDoctypeInfo(docid).getDoctype();
|
422
|
|
423
|
// Transform the document to the new doctype
|
424
|
dbt.transformXMLDocument(doc, sourcetype, "-//W3C//HTML//EN", out);
|
425
|
}
|
426
|
}
|
427
|
|
428
|
/**
|
429
|
* Handle the database putdocument request and write an XML document
|
430
|
* to the database connection
|
431
|
*/
|
432
|
private void handleInsertOrUpdateAction(PrintWriter out, Hashtable params,
|
433
|
HttpServletResponse response) {
|
434
|
|
435
|
try {
|
436
|
// Get the document indicated
|
437
|
String[] doctext = (String[])params.get("doctext");
|
438
|
StringReader xml = null;
|
439
|
try {
|
440
|
xml = new StringReader(doctext[0]);
|
441
|
|
442
|
String[] action = (String[])params.get("action");
|
443
|
String[] docid = (String[])params.get("docid");
|
444
|
String newdocid = null;
|
445
|
|
446
|
String doAction = null;
|
447
|
if (action[0].equals("insert")) {
|
448
|
doAction = "INSERT";
|
449
|
} else if (action[0].equals("update")) {
|
450
|
doAction = "UPDATE";
|
451
|
}
|
452
|
|
453
|
// write the document to the database
|
454
|
DBWriter dbw = new DBWriter(conn, saxparser);
|
455
|
|
456
|
try {
|
457
|
String accNumber = docid[0];
|
458
|
if (accNumber.equals("")) {
|
459
|
accNumber = null;
|
460
|
}
|
461
|
newdocid = dbw.write(xml, doAction, accNumber);
|
462
|
} catch (NullPointerException npe) {
|
463
|
newdocid = dbw.write(xml, doAction, null);
|
464
|
}
|
465
|
|
466
|
// set content type and other response header fields first
|
467
|
response.setContentType("text/xml");
|
468
|
out.println("<?xml version=\"1.0\"?>");
|
469
|
out.println("<success>");
|
470
|
out.println("<docid>" + newdocid + "</docid>");
|
471
|
out.println("</success>");
|
472
|
|
473
|
} catch (NullPointerException npe) {
|
474
|
response.setContentType("text/xml");
|
475
|
out.println("<?xml version=\"1.0\"?>");
|
476
|
out.println("<error>");
|
477
|
out.println(npe.getMessage());
|
478
|
out.println("</error>");
|
479
|
}
|
480
|
} catch (Exception e) {
|
481
|
response.setContentType("text/xml");
|
482
|
out.println("<?xml version=\"1.0\"?>");
|
483
|
out.println("<error>");
|
484
|
out.println(e.getMessage());
|
485
|
if (e instanceof SAXException) {
|
486
|
Exception e2 = ((SAXException)e).getException();
|
487
|
out.println("<error>");
|
488
|
out.println(e2.getMessage());
|
489
|
out.println("</error>");
|
490
|
}
|
491
|
//e.printStackTrace(out);
|
492
|
out.println("</error>");
|
493
|
}
|
494
|
}
|
495
|
|
496
|
/**
|
497
|
* Handle the database delete request and delete an XML document
|
498
|
* from the database connection
|
499
|
*/
|
500
|
private void handleDeleteAction(PrintWriter out, Hashtable params,
|
501
|
HttpServletResponse response) {
|
502
|
|
503
|
String[] docid = (String[])params.get("docid");
|
504
|
|
505
|
// delete the document from the database
|
506
|
try {
|
507
|
DBWriter dbw = new DBWriter(conn, saxparser);
|
508
|
// NOTE -- NEED TO TEST HERE
|
509
|
// FOR EXISTENCE OF PARAM
|
510
|
// BEFORE ACCESSING ARRAY
|
511
|
try {
|
512
|
dbw.delete(docid[0]);
|
513
|
response.setContentType("text/xml");
|
514
|
out.println("<?xml version=\"1.0\"?>");
|
515
|
out.println("<success>");
|
516
|
out.println("Document deleted.");
|
517
|
out.println("</success>");
|
518
|
} catch (AccessionNumberException ane) {
|
519
|
response.setContentType("text/xml");
|
520
|
out.println("<?xml version=\"1.0\"?>");
|
521
|
out.println("<error>");
|
522
|
out.println("Error deleting document!!!");
|
523
|
out.println(ane.getMessage());
|
524
|
out.println("</error>");
|
525
|
}
|
526
|
} catch (Exception e) {
|
527
|
response.setContentType("text/xml");
|
528
|
out.println("<?xml version=\"1.0\"?>");
|
529
|
out.println("<error>");
|
530
|
out.println(e.getMessage());
|
531
|
out.println("</error>");
|
532
|
}
|
533
|
}
|
534
|
|
535
|
/**
|
536
|
* Handle the validtion request and return the results to the requestor
|
537
|
*/
|
538
|
private void handleValidateAction(PrintWriter out, Hashtable params,
|
539
|
HttpServletResponse response) {
|
540
|
|
541
|
// Get the document indicated
|
542
|
String valtext = null;
|
543
|
try {
|
544
|
valtext = ((String[])params.get("valtext"))[0];
|
545
|
} catch (Exception nullpe) {
|
546
|
|
547
|
String docid = null;
|
548
|
try {
|
549
|
// Find the document id number
|
550
|
docid = ((String[])params.get("docid"))[0];
|
551
|
|
552
|
// Get the document indicated fromthe db
|
553
|
valtext = docreader.readXMLDocument(docid);
|
554
|
|
555
|
} catch (NullPointerException npe) {
|
556
|
response.setContentType("text/xml");
|
557
|
out.println("<error>Error getting document ID: " + docid + "</error>");
|
558
|
}
|
559
|
}
|
560
|
|
561
|
try {
|
562
|
DBValidate valobj = new DBValidate(saxparser,conn);
|
563
|
boolean valid = valobj.validateString(valtext);
|
564
|
|
565
|
// set content type and other response header fields first
|
566
|
response.setContentType("text/xml");
|
567
|
out.println(valobj.returnErrors());
|
568
|
|
569
|
} catch (NullPointerException npe2) {
|
570
|
// set content type and other response header fields first
|
571
|
response.setContentType("text/xml");
|
572
|
out.println("<error>Error validating document.</error>");
|
573
|
}
|
574
|
}
|
575
|
|
576
|
/**
|
577
|
* Handle the document request and return the results
|
578
|
* to the requestor
|
579
|
*/
|
580
|
private void handleGetDataDocumentAction(PrintWriter out, Hashtable params,
|
581
|
HttpServletResponse response) {
|
582
|
boolean error_flag = false;
|
583
|
String error_message = "";
|
584
|
// Get the document indicated
|
585
|
String[] datadoc = (String[])params.get("datadoc");
|
586
|
// defaultdatapath = "C:\\Temp\\"; // for testing only!!!
|
587
|
// executescript = "test.bat"; // for testing only!!!
|
588
|
|
589
|
// set content type and other response header fields first
|
590
|
response.setContentType("application/octet-stream");
|
591
|
if (defaultdatapath!=null) {
|
592
|
if(!defaultdatapath.endsWith(System.getProperty("file.separator"))) {
|
593
|
defaultdatapath=defaultdatapath+System.getProperty("file.separator");
|
594
|
}
|
595
|
System.out.println("Path= "+defaultdatapath+datadoc[0]);
|
596
|
if (executescript!=null) {
|
597
|
String command = null;
|
598
|
File scriptfile = new File(executescript);
|
599
|
if (scriptfile.exists()) {
|
600
|
command=executescript+" "+datadoc[0]; // script includes path
|
601
|
} else { // look in defaultdatapath
|
602
|
// on Win98 one MUST include the .bat extender
|
603
|
command = defaultdatapath+executescript+" "+datadoc[0];
|
604
|
}
|
605
|
System.out.println(command);
|
606
|
try {
|
607
|
Process proc = Runtime.getRuntime().exec(command);
|
608
|
proc.waitFor();
|
609
|
}
|
610
|
catch (Exception eee) {
|
611
|
System.out.println("Error running process!");
|
612
|
error_flag = true;
|
613
|
error_message = "Error running process!";}
|
614
|
} // end executescript not null if
|
615
|
File datafile = new File(defaultdatapath+datadoc[0]);
|
616
|
try {
|
617
|
FileInputStream fw = new FileInputStream(datafile);
|
618
|
int x;
|
619
|
while ((x = fw.read())!=-1) {
|
620
|
out.write(x); }
|
621
|
fw.close();
|
622
|
} catch (Exception e) {
|
623
|
System.out.println("Error in returning file\n"+e.getMessage());
|
624
|
error_flag=true;
|
625
|
error_message = error_message+"\nError in returning file\n"+
|
626
|
e.getMessage();
|
627
|
}
|
628
|
} // end defaultdatapath not null if
|
629
|
}
|
630
|
}
|
631
|
|
632
|
/**
|
633
|
* '$Log$
|
634
|
* 'Revision 1.50 2000/06/30 23:42:33 bojilova
|
635
|
* 'finished user auth & session tracking
|
636
|
* '
|
637
|
* 'Revision 1.49 2000/06/29 23:27:08 jones
|
638
|
* 'Fixed bug in DBEntityResolver so that it now properly delegates to
|
639
|
* 'the system id found inthe database.
|
640
|
* 'Changed DBValidate to use DBEntityResolver, rather than the OASIS
|
641
|
* 'catalog, and to return validation results in XML format.
|
642
|
* '
|
643
|
* 'Revision 1.48 2000/06/29 20:04:51 bojilova
|
644
|
* 'testing login
|
645
|
* '
|
646
|
* 'Revision 1.36 2000/06/28 02:36:26 jones
|
647
|
* 'Added feature to now ouput COMMENTs and PIs when the document is
|
648
|
* 'read from the database with DBReader.
|
649
|
* '
|
650
|
* 'Revision 1.35 2000/06/28 00:00:47 bojilova
|
651
|
* 'changed to
|
652
|
* 'response.sendRedirect(response.encodeRedirectUrl("/xmltodb/lib/index.html"));
|
653
|
* '
|
654
|
* 'Revision 1.33 2000/06/27 04:50:33 jones
|
655
|
* 'Updated javadoc documentation.
|
656
|
* '
|
657
|
* 'Revision 1.32 2000/06/27 04:31:07 jones
|
658
|
* 'Fixed bugs associated with the new UPDATE and DELETE functions of
|
659
|
* 'DBWriter. There were problematic interactions between some static
|
660
|
* 'variables used in DBEntityResolver and the way in which the
|
661
|
* 'Servlet objects are re-used across multiple client invocations.
|
662
|
* '
|
663
|
* 'Generally cleaned up error reporting. Now all errors and success
|
664
|
* 'results are reported as XML documents from MetaCatServlet. Need
|
665
|
* 'to make the command line tools do the same.
|
666
|
* '
|
667
|
* 'Revision 1.31 2000/06/26 10:35:05 jones
|
668
|
* 'Merged in substantial changes to DBWriter and associated classes and to
|
669
|
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE
|
670
|
* 'functions. The command line tools and the parameters for the
|
671
|
* 'servlet have changed substantially.
|
672
|
* '
|
673
|
* 'Revision 1.30.2.6 2000/06/26 10:18:06 jones
|
674
|
* 'Partial fix for MetaCatServlet INSERT?UPDATE bug. Only will work on
|
675
|
* 'the first call to the servlet. Subsequent calls fail. Seems to be
|
676
|
* 'related to exception handling. Multiple successive DELETE actions
|
677
|
* 'work fine.
|
678
|
* '
|
679
|
* 'Revision 1.30.2.5 2000/06/26 09:09:53 jones
|
680
|
* 'Modified MetaCatServlet and associated files to handle the UPDATE
|
681
|
* 'and DELETE actions for DBWriter.
|
682
|
* '
|
683
|
* 'Revision 1.30.2.4 2000/06/26 00:51:06 jones
|
684
|
* 'If docid passed to DBWriter.write() is not unique, classes now generate
|
685
|
* 'an AccessionNumberException containing the new docid generated as a
|
686
|
* 'replacement. The docid is then extracted from the exception and
|
687
|
* 'returned to the calling application for user feedback or client processing.
|
688
|
* '
|
689
|
* 'Revision 1.30.2.3 2000/06/25 23:38:17 jones
|
690
|
* 'Added RCSfile keyword
|
691
|
* '
|
692
|
* 'Revision 1.30.2.2 2000/06/25 23:34:18 jones
|
693
|
* 'Changed documentation formatting, added log entries at bottom of source files
|
694
|
* ''
|
695
|
*/
|