Project

General

Profile

1 51 jones
/**
2 203 jones
 *  '$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 154 jones
 *
8 203 jones
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11 51 jones
 */
12
13
package edu.ucsb.nceas.metacat;
14
15 46 jones
import java.io.PrintWriter;
16
import java.io.IOException;
17 50 jones
import java.io.Reader;
18
import java.io.StringReader;
19 59 jones
import java.io.BufferedReader;
20 185 jones
import java.io.File;
21
import java.io.FileInputStream;
22 46 jones
import java.util.Enumeration;
23
import java.util.Hashtable;
24 82 jones
import java.util.ResourceBundle;
25
import java.util.PropertyResourceBundle;
26 50 jones
import java.net.URL;
27
import java.net.MalformedURLException;
28 85 jones
import java.sql.PreparedStatement;
29
import java.sql.ResultSet;
30 50 jones
import java.sql.Connection;
31 55 jones
import java.sql.SQLException;
32 46 jones
33
import javax.servlet.ServletConfig;
34
import javax.servlet.ServletContext;
35
import javax.servlet.ServletException;
36 48 jones
import javax.servlet.ServletInputStream;
37 46 jones
import javax.servlet.http.HttpServlet;
38
import javax.servlet.http.HttpServletRequest;
39
import javax.servlet.http.HttpServletResponse;
40 210 bojilova
import javax.servlet.http.HttpSession;
41 47 jones
import javax.servlet.http.HttpUtils;
42 46 jones
43 50 jones
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 204 jones
import org.xml.sax.SAXException;
49
50 46 jones
/**
51
 * A metadata catalog server implemented as a Java Servlet
52 154 jones
 *
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 205 jones
 * 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 154 jones
 * 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 205 jones
 * doctext -- XML text of the document to load into the database<br>
67 183 jones
 * query -- actual query text (to go with 'action=query' or 'action=squery')<br>
68 205 jones
 * 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 46 jones
 */
76
public class MetaCatServlet extends HttpServlet {
77
78
  private ServletConfig		config = null;
79
  private ServletContext	context = null;
80 181 jones
  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 46 jones
95 184 jones
  private MetaCatUtil util = null;
96
97 50 jones
  /**
98
   * Initialize the servlet by creating appropriate database connections
99
   */
100 46 jones
  public void init( ServletConfig config ) throws ServletException {
101
    try {
102
      super.init( config );
103
      this.config = config;
104
      this.context = config.getServletContext();
105 184 jones
      System.out.println("MetaCatServlet Initialize");
106 82 jones
107 184 jones
      util = new MetaCatUtil();
108
109 83 jones
      // Get the configuration file information
110 184 jones
      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 82 jones
116 46 jones
      try {
117 50 jones
        // Open a connection to the database
118 184 jones
        conn = util.openDBConnection();
119 50 jones
120 181 jones
        queryobj = new DBQuery(conn,saxparser);
121 55 jones
        docreader = new DBReader(conn);
122 87 jones
        dbt = new DBTransform(conn);
123 68 higgins
124 46 jones
      } catch (Exception e) {
125 100 jones
        System.err.println("Error opening database connection");
126 46 jones
      }
127
    } catch ( ServletException ex ) {
128
      throw ex;
129
    }
130
  }
131
132 50 jones
  /** Handle "GET" method requests from HTTP clients */
133 46 jones
  public void doGet (HttpServletRequest request, HttpServletResponse response)
134
    throws ServletException, IOException {
135
136 48 jones
    // Process the data and send back the response
137 59 jones
    handleGetOrPost(request, response);
138 48 jones
  }
139
140 50 jones
  /** Handle "POST" method requests from HTTP clients */
141 48 jones
  public void doPost( HttpServletRequest request, HttpServletResponse response)
142
    throws ServletException, IOException {
143
144
    // Process the data and send back the response
145 59 jones
    handleGetOrPost(request, response);
146 48 jones
  }
147
148 49 jones
  /**
149 50 jones
   * Control servlet response depending on the action parameter specified
150 49 jones
   */
151 59 jones
  private void handleGetOrPost(HttpServletRequest request,
152
    HttpServletResponse response)
153 48 jones
    throws ServletException, IOException {
154
155 100 jones
    if (conn == null) {
156
      System.err.println("Connection to database lost.  Reopening...");
157
      try {
158
        // Open a connection to the database
159 184 jones
        conn = util.openDBConnection();
160 100 jones
161 181 jones
        queryobj = new DBQuery(conn, saxparser);
162 100 jones
        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 49 jones
    // Get a handle to the output stream back to the client
171 48 jones
    PrintWriter out = response.getWriter();
172 102 jones
    //response.setContentType("text/html");
173 49 jones
174 59 jones
    String name = null;
175
    String[] value = null;
176 103 jones
    String[] docid = new String[3];
177 59 jones
    Hashtable params = new Hashtable();
178
    Enumeration paramlist = request.getParameterNames();
179
    while (paramlist.hasMoreElements()) {
180
      name = (String)paramlist.nextElement();
181
      value = request.getParameterValues(name);
182 103 jones
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 102 jones
      //out.println(name + " => " + value[0]);
195 59 jones
      params.put(name,value);
196
    }
197
198 103 jones
    // 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 49 jones
    String action = ((String[])params.get("action"))[0];
202 103 jones
    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 223 bojilova
      //} else {
213
      //  action = "";
214 103 jones
      }
215
    } catch (Exception npe) {
216
      //out.println("<P>Caught exception looking for Y value.");
217
    }
218 219 jones
219 221 bojilova
// Jivka added
220 210 bojilova
    // handle login action
221
    if (action.equals("Login")) {
222 224 bojilova
      handleLoginAction(out, params, request, response);
223 210 bojilova
    // handle logout action
224
    } else if (action.equals("Logout")) {
225
      HttpSession sess = request.getSession(false);
226 251 bojilova
      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 210 bojilova
      }
236
    }
237
// End of Jivka added
238 219 jones
239 181 jones
    if (action.equals("query") || action.equals("squery")) {
240 49 jones
      handleQueryAction(out, params, response);
241
    } else if (action.equals("getdocument")) {
242 87 jones
      try {
243
        handleGetDocumentAction(out, params, response);
244
      } catch (ClassNotFoundException e) {
245 103 jones
        out.println(e.getMessage());
246 87 jones
      } catch (SQLException se) {
247 103 jones
        out.println(se.getMessage());
248 87 jones
      }
249 203 jones
    } 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 68 higgins
    } else if (action.equals("validate")) {
254
      handleValidateAction(out, params, response);
255 91 higgins
    } else if (action.equals("getdatadoc")) {
256
      handleGetDataDocumentAction(out, params, response);
257 251 bojilova
    } else if (action.equals("Login")) {
258 50 jones
    } else {
259
      out.println("Error: action not registered.  Please report this error.");
260 46 jones
    }
261
262 49 jones
    // Close the stream to the client
263 46 jones
    out.close();
264
  }
265 49 jones
266 210 bojilova
// Jivka added
267 50 jones
  /**
268 210 bojilova
   * Handle the Login request. Create a new session object.
269
   * Make a user authentication through SRB RMI Connection.
270
   */
271 224 bojilova
272 210 bojilova
  private void handleLoginAction(PrintWriter out, Hashtable params,
273
               HttpServletRequest request, HttpServletResponse response) {
274 251 bojilova
275 228 bojilova
    String un = ((String[])params.get("username"))[0];
276
    String pw = ((String[])params.get("password"))[0];
277 251 bojilova
278 229 bojilova
    MetaCatSession sess = new MetaCatSession(request, un, pw);
279 233 bojilova
280 231 bojilova
    try {
281
        if (sess.userAuth(pw)) {
282 230 bojilova
            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 210 bojilova
292 231 bojilova
        } 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 210 bojilova
  }
304 219 jones
305 210 bojilova
  /**
306 50 jones
   * Handle the database query request and return a result set, possibly
307
   * transformed from XML into HTML
308
   */
309 49 jones
  private void handleQueryAction(PrintWriter out, Hashtable params,
310
               HttpServletResponse response) {
311 181 jones
      String action = ((String[])params.get("action"))[0];
312
      String query = ((String[])params.get("query"))[0];
313 167 jones
      Hashtable doclist = null;
314 181 jones
      String[] doctypeArr = null;
315 154 jones
      String doctype = null;
316 181 jones
      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 154 jones
        if (doctype != null) {
329 181 jones
          xmlquery = new StringReader(DBQuery.createQuery(query,doctype));
330 154 jones
        } else {
331 181 jones
          xmlquery = new StringReader(DBQuery.createQuery(query));
332 154 jones
        }
333 181 jones
      } else if (action.equals("squery")) {
334
        xmlquery = new StringReader(query);
335 82 jones
      } else {
336 181 jones
        System.err.println("Error handling query -- illegal action value");
337
      }
338
339
      if (queryobj != null) {
340
          doclist = queryobj.findDocuments(xmlquery);
341
      } else {
342 82 jones
        out.println("Query Object Init failed.");
343 83 jones
        return;
344 82 jones
      }
345 50 jones
346
      // Create a buffer to hold the xml result
347
      StringBuffer resultset = new StringBuffer();
348
349 49 jones
      // Print the resulting root nodes
350 167 jones
      String docid;
351 98 jones
      String document = null;
352 50 jones
      resultset.append("<?xml version=\"1.0\"?>\n");
353 87 jones
      //resultset.append("<!DOCTYPE resultset PUBLIC " +
354
      //               "\"-//NCEAS//resultset//EN\" \"resultset.dtd\">\n");
355 50 jones
      resultset.append("<resultset>\n");
356
      resultset.append("  <query>" + query + "</query>");
357 167 jones
      Enumeration doclistkeys = doclist.keys();
358
      while (doclistkeys.hasMoreElements()) {
359
        docid = (String)doclistkeys.nextElement();
360
        document = (String)doclist.get(docid);
361 98 jones
        resultset.append("  <document>" + document + "</document>");
362 49 jones
      }
363 50 jones
      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 185 jones
          XSLStylesheet style = new XSLStylesheet(
377
                                    new URL(resultStyleURL), null);
378 50 jones
          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 49 jones
  }
386
387 50 jones
  /**
388
   * Handle the database getdocument request and return a XML document,
389
   * possibly transformed from XML into HTML
390
   */
391 49 jones
  private void handleGetDocumentAction(PrintWriter out, Hashtable params,
392 87 jones
               HttpServletResponse response)
393
               throws ClassNotFoundException, IOException, SQLException {
394 102 jones
    String docidstr = null;
395 162 bojilova
    String docid = null;
396 102 jones
    String doc = null;
397
    try {
398 87 jones
      // Find the document id number
399 102 jones
      docidstr = ((String[])params.get("docid"))[0];
400 162 bojilova
      //docid = (new Long(docidstr)).longValue();
401
      docid = docidstr;
402 49 jones
403 87 jones
      // Get the document indicated fromthe db
404 102 jones
      doc = docreader.readXMLDocument(docid);
405
    } catch (NullPointerException npe) {
406
      response.setContentType("text/html");
407
      out.println("Error getting document ID: " + docidstr +" (" + docid + ")");
408
    }
409 85 jones
410 87 jones
      // Return the document in XML or HTML format
411 85 jones
      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 87 jones
        // Look up the document type
421 103 jones
        String sourcetype = docreader.getDoctypeInfo(docid).getDoctype();
422 86 jones
423 87 jones
        // Transform the document to the new doctype
424
        dbt.transformXMLDocument(doc, sourcetype, "-//W3C//HTML//EN", out);
425 85 jones
      }
426 49 jones
  }
427 55 jones
428
  /**
429
   * Handle the database putdocument request and write an XML document
430
   * to the database connection
431
   */
432 203 jones
  private void handleInsertOrUpdateAction(PrintWriter out, Hashtable params,
433 55 jones
               HttpServletResponse response) {
434 59 jones
435 204 jones
    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 59 jones
442 204 jones
        String[] action = (String[])params.get("action");
443
        String[] docid = (String[])params.get("docid");
444
        String newdocid = null;
445 203 jones
446 204 jones
        String doAction = null;
447
        if (action[0].equals("insert")) {
448
          doAction = "INSERT";
449
        } else if (action[0].equals("update")) {
450
          doAction = "UPDATE";
451
        }
452 203 jones
453 204 jones
        // 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 203 jones
        }
465 204 jones
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 203 jones
      } catch (NullPointerException npe) {
474 204 jones
        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 55 jones
      }
480 204 jones
    } 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 203 jones
    }
494 55 jones
  }
495 203 jones
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 204 jones
        response.setContentType("text/xml");
514
        out.println("<?xml version=\"1.0\"?>");
515
        out.println("<success>");
516 203 jones
        out.println("Document deleted.");
517 204 jones
        out.println("</success>");
518 203 jones
      } catch (AccessionNumberException ane) {
519 204 jones
        response.setContentType("text/xml");
520
        out.println("<?xml version=\"1.0\"?>");
521
        out.println("<error>");
522
        out.println("Error deleting document!!!");
523 203 jones
        out.println(ane.getMessage());
524 204 jones
        out.println("</error>");
525 203 jones
      }
526 204 jones
    } 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 203 jones
    }
533
  }
534 68 higgins
535
  /**
536 185 jones
   * Handle the validtion request and return the results to the requestor
537 68 higgins
   */
538 185 jones
  private void handleValidateAction(PrintWriter out, Hashtable params,
539
               HttpServletResponse response) {
540 68 higgins
541 103 jones
    // Get the document indicated
542
    String valtext = null;
543
    try {
544
      valtext = ((String[])params.get("valtext"))[0];
545
    } catch (Exception nullpe) {
546 68 higgins
547 162 bojilova
      String docid = null;
548 103 jones
      try {
549
        // Find the document id number
550 185 jones
        docid = ((String[])params.get("docid"))[0];
551 103 jones
552
        // Get the document indicated fromthe db
553
        valtext = docreader.readXMLDocument(docid);
554 185 jones
555 103 jones
      } catch (NullPointerException npe) {
556 251 bojilova
        response.setContentType("text/html");
557
        out.println("Error getting document ID: " + docid );
558 103 jones
      }
559
    }
560 68 higgins
561 103 jones
    try {
562 251 bojilova
      DBValidate valobj = new DBValidate(saxparser,xmlcatalogfile);
563 185 jones
      boolean valid = valobj.validateString(valtext);
564 68 higgins
565
      // set content type and other response header fields first
566 251 bojilova
      response.setContentType("text/html");
567
      out.println("<html>");
568
      out.println("<head><link rel=\"stylesheet\" type=\"text/css\" " +
569
                  "href=\"/xmltodb/rowcol.css\" /></head>");
570
      out.println("<body class=\"emlbody\">");
571
572
      if (valid) {
573
        out.println("The input XML is VALID!");
574
      } else {
575
        out.println("The input XML is NOT VALID<br />\n<pre>\n"
576
                    + valobj.returnErrors() + "\n</pre>\n");
577
      }
578
      out.println("</body></html>");
579 103 jones
    } catch (NullPointerException npe2) {
580
      // set content type and other response header fields first
581 251 bojilova
      response.setContentType("text/html");
582
      out.println("Error validating document.");
583 68 higgins
    }
584 103 jones
  }
585 87 jones
586
  /**
587 91 higgins
   * Handle the document request and return the results
588 154 jones
   * to the requestor
589 91 higgins
   */
590 185 jones
  private void handleGetDataDocumentAction(PrintWriter out, Hashtable params,
591
               HttpServletResponse response) {
592 91 higgins
      boolean error_flag = false;
593
      String error_message = "";
594
      // Get the document indicated
595
      String[] datadoc = (String[])params.get("datadoc");
596 185 jones
      // defaultdatapath = "C:\\Temp\\";    // for testing only!!!
597
      // executescript = "test.bat";        // for testing only!!!
598 91 higgins
599
      // set content type and other response header fields first
600
      response.setContentType("application/octet-stream");
601 185 jones
      if (defaultdatapath!=null) {
602
        if(!defaultdatapath.endsWith(System.getProperty("file.separator"))) {
603
          defaultdatapath=defaultdatapath+System.getProperty("file.separator");
604 91 higgins
        }
605 185 jones
        System.out.println("Path= "+defaultdatapath+datadoc[0]);
606
        if (executescript!=null) {
607
          String command = null;
608
          File scriptfile = new File(executescript);
609
          if (scriptfile.exists()) {
610
            command=executescript+" "+datadoc[0]; // script includes path
611
        } else {     // look in defaultdatapath
612
            // on Win98 one MUST include the .bat extender
613
            command = defaultdatapath+executescript+" "+datadoc[0];
614
        }
615 91 higgins
      System.out.println(command);
616
      try {
617
      Process proc = Runtime.getRuntime().exec(command);
618
      proc.waitFor();
619
      }
620
      catch (Exception eee) {
621
        System.out.println("Error running process!");
622
        error_flag = true;
623
        error_message = "Error running process!";}
624
      } // end executescript not null if
625
      File datafile = new File(defaultdatapath+datadoc[0]);
626
      try {
627
      FileInputStream fw = new FileInputStream(datafile);
628
      int x;
629 185 jones
      while ((x = fw.read())!=-1) {
630 91 higgins
        out.write(x); }
631 185 jones
        fw.close();
632
      } catch (Exception e) {
633 91 higgins
        System.out.println("Error in returning file\n"+e.getMessage());
634
        error_flag=true;
635 185 jones
        error_message = error_message+"\nError in returning file\n"+
636
                        e.getMessage();
637
      }
638
    } // end defaultdatapath not null if
639 91 higgins
  }
640 46 jones
}
641 203 jones
642
/**
643
 * '$Log$
644 221 bojilova
 * 'Revision 1.36  2000/06/28 02:36:26  jones
645
 * 'Added feature to now ouput COMMENTs and PIs when the document is
646
 * 'read from the database with DBReader.
647
 * '
648 219 jones
 * 'Revision 1.35  2000/06/28 00:00:47  bojilova
649
 * 'changed to
650
 * 'response.sendRedirect(response.encodeRedirectUrl("/xmltodb/lib/index.html"));
651
 * '
652 210 bojilova
 * 'Revision 1.33  2000/06/27 04:50:33  jones
653
 * 'Updated javadoc documentation.
654
 * '
655 205 jones
 * 'Revision 1.32  2000/06/27 04:31:07  jones
656
 * 'Fixed bugs associated with the new UPDATE and DELETE functions of
657
 * 'DBWriter.  There were problematic interactions between some static
658
 * 'variables used in DBEntityResolver and the way in which the
659
 * 'Servlet objects are re-used across multiple client invocations.
660
 * '
661
 * 'Generally cleaned up error reporting.  Now all errors and success
662
 * 'results are reported as XML documents from MetaCatServlet.  Need
663
 * 'to make the command line tools do the same.
664
 * '
665 204 jones
 * 'Revision 1.31  2000/06/26 10:35:05  jones
666
 * 'Merged in substantial changes to DBWriter and associated classes and to
667
 * 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE
668
 * 'functions.  The command line tools and the parameters for the
669
 * 'servlet have changed substantially.
670
 * '
671 203 jones
 * 'Revision 1.30.2.6  2000/06/26 10:18:06  jones
672
 * 'Partial fix for MetaCatServlet INSERT?UPDATE bug.  Only will work on
673
 * 'the first call to the servlet.  Subsequent calls fail.  Seems to be
674
 * 'related to exception handling.  Multiple successive DELETE actions
675
 * 'work fine.
676
 * '
677
 * 'Revision 1.30.2.5  2000/06/26 09:09:53  jones
678
 * 'Modified MetaCatServlet and associated files to handle the UPDATE
679
 * 'and DELETE actions for DBWriter.
680
 * '
681
 * 'Revision 1.30.2.4  2000/06/26 00:51:06  jones
682
 * 'If docid passed to DBWriter.write() is not unique, classes now generate
683
 * 'an AccessionNumberException containing the new docid generated as a
684
 * 'replacement.  The docid is then extracted from the exception and
685
 * 'returned to the calling application for user feedback or client processing.
686
 * '
687
 * 'Revision 1.30.2.3  2000/06/25 23:38:17  jones
688
 * 'Added RCSfile keyword
689
 * '
690
 * 'Revision 1.30.2.2  2000/06/25 23:34:18  jones
691
 * 'Changed documentation formatting, added log entries at bottom of source files
692
 * ''
693
 */