Project

General

Profile

« Previous | Next » 

Revision 91

Added by higgins about 24 years ago

Update to handle retreival of datafile from server

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
3 3
 *     Purpose: A Class that implements a metadata catalog as a java Servlet
4 4
 *   Copyright: 2000 Regents of the University of California and the
5 5
 *              National Center for Ecological Analysis and Synthesis
6
 *     Authors: Matt Jones
6
 *     Authors: Matt Jones, Dan Higgins
7 7
 * 
8 8
 *     Version: '$Id$'
9 9
 */
......
40 40
import oracle.xml.parser.v2.XMLDocumentFragment;
41 41
import oracle.xml.parser.v2.XSLProcessor;
42 42
import oracle.xml.parser.v2.*;    //Oracle parser - DFH
43
import java.io.File;  //DFH
44
import java.io.FileInputStream; //DFH
43 45

  
44 46
/**
45 47
 * A metadata catalog server implemented as a Java Servlet
......
57 59
   * query -- actual query text (to go with 'action=query')<br>
58 60
   * action=validate -- vallidate the xml contained in validatetext<br>
59 61
   * valtext -- XML text to be validated
62
   * action=getdatadoc -- retreive a stored datadocument  //DFH
63
   * datadoc -- data document name (id)                   //DFH
60 64
 */
61 65
public class MetaCatServlet extends HttpServlet {
62 66

  
......
71 75
  String 	defaultDB = null;
72 76
  String 	resultStyleURL = null;
73 77
  String 	xmlcatalogfile = null;
78
  String    defaultdatapath = null;  // path to directory where data files that can be downloaded will be stored
79
  String    executescript  = null;  // script to get data file and put it in defaultdocpath dir
74 80
  PropertyResourceBundle options = null;
75 81

  
76 82
  /**
......
90 96
      defaultDB = (String)options.handleGetObject("defaultDB");
91 97
      resultStyleURL = (String)options.handleGetObject("resultStyleURL");
92 98
      xmlcatalogfile = (String)options.handleGetObject("xmlcatalogfile");
99
      defaultdatapath = (String)options.handleGetObject("defaultdatapath");
100
      executescript = (String)options.handleGetObject("executescript");
93 101

  
94 102
      try {
95 103
        // Open a connection to the database
......
160 168
      handlePutDocumentAction(out, params, response);
161 169
    } else if (action.equals("validate")) {
162 170
      handleValidateAction(out, params, response);  
171
    } else if (action.equals("getdatadoc")) {
172
      handleGetDataDocumentAction(out, params, response);  
163 173
    } else {
164 174
      out.println("Error: action not registered.  Please report this error.");
165 175
    }
......
356 366

  
357 367
    return doctype;
358 368
  }
369
    
370
    
371
  /** 
372
   * Handle the document request and return the results 
373
   * to the requestor - DFH
374
   */
375
  private void handleGetDataDocumentAction(PrintWriter out, Hashtable params, HttpServletResponse response) {
376
      boolean error_flag = false;
377
      String error_message = "";
378
      // Get the document indicated
379
      String[] datadoc = (String[])params.get("datadoc");
380
  //    defaultdatapath = "C:\\Temp\\";    // for testing only!!!
381
   //   executescript = "test.bat";        // for testing only!!!
382
      
383
      // set content type and other response header fields first
384
      response.setContentType("application/octet-stream");
385
   if (defaultdatapath!=null) {
386
        if(!defaultdatapath.endsWith(System.getProperty("file.separator"))) defaultdatapath=defaultdatapath+System.getProperty("file.separator");
387
      System.out.println("Path= "+defaultdatapath+datadoc[0]);
388
      if (executescript!=null) {
389
        String command = null;
390
        File scriptfile = new File(executescript);
391
        if (scriptfile.exists()) {
392
            command=executescript+" "+datadoc[0]; }  // execute script includes path
393
        else {     // look in defaultdatapath
394
                command = defaultdatapath+executescript+" "+datadoc[0];  // on Win98 one MUST include the .bat extender
395
        }
396
      System.out.println(command);
397
      try {
398
      Process proc = Runtime.getRuntime().exec(command);
399
      proc.waitFor();
400
      }
401
      catch (Exception eee) {
402
        System.out.println("Error running process!");
403
        error_flag = true;
404
        error_message = "Error running process!";}
405
      } // end executescript not null if
406
      File datafile = new File(defaultdatapath+datadoc[0]);
407
      try {
408
      FileInputStream fw = new FileInputStream(datafile);
409
      int x;
410
     while ((x = fw.read())!=-1) {
411
        out.write(x); }
412
      fw.close();
413
      
414
      }
415
      catch (Exception e) {
416
        System.out.println("Error in returning file\n"+e.getMessage());
417
        error_flag=true;
418
        error_message = error_message+"\nError in returning file\n"+e.getMessage();}
419
   } // end defaultdatapath not null if
420
  }
421
    
422
    
359 423
}
MetaCatServlet.java
3 3
 *     Purpose: A Class that implements a metadata catalog as a java Servlet
4 4
 *   Copyright: 2000 Regents of the University of California and the
5 5
 *              National Center for Ecological Analysis and Synthesis
6
 *     Authors: Matt Jones
6
 *     Authors: Matt Jones, Dan Higgins
7 7
 * 
8 8
 *     Version: '$Id$'
9 9
 */
......
40 40
import oracle.xml.parser.v2.XMLDocumentFragment;
41 41
import oracle.xml.parser.v2.XSLProcessor;
42 42
import oracle.xml.parser.v2.*;    //Oracle parser - DFH
43
import java.io.File;  //DFH
44
import java.io.FileInputStream; //DFH
43 45

  
44 46
/**
45 47
 * A metadata catalog server implemented as a Java Servlet
......
57 59
   * query -- actual query text (to go with 'action=query')<br>
58 60
   * action=validate -- vallidate the xml contained in validatetext<br>
59 61
   * valtext -- XML text to be validated
62
   * action=getdatadoc -- retreive a stored datadocument  //DFH
63
   * datadoc -- data document name (id)                   //DFH
60 64
 */
61 65
public class MetaCatServlet extends HttpServlet {
62 66

  
......
71 75
  String 	defaultDB = null;
72 76
  String 	resultStyleURL = null;
73 77
  String 	xmlcatalogfile = null;
78
  String    defaultdatapath = null;  // path to directory where data files that can be downloaded will be stored
79
  String    executescript  = null;  // script to get data file and put it in defaultdocpath dir
74 80
  PropertyResourceBundle options = null;
75 81

  
76 82
  /**
......
90 96
      defaultDB = (String)options.handleGetObject("defaultDB");
91 97
      resultStyleURL = (String)options.handleGetObject("resultStyleURL");
92 98
      xmlcatalogfile = (String)options.handleGetObject("xmlcatalogfile");
99
      defaultdatapath = (String)options.handleGetObject("defaultdatapath");
100
      executescript = (String)options.handleGetObject("executescript");
93 101

  
94 102
      try {
95 103
        // Open a connection to the database
......
160 168
      handlePutDocumentAction(out, params, response);
161 169
    } else if (action.equals("validate")) {
162 170
      handleValidateAction(out, params, response);  
171
    } else if (action.equals("getdatadoc")) {
172
      handleGetDataDocumentAction(out, params, response);  
163 173
    } else {
164 174
      out.println("Error: action not registered.  Please report this error.");
165 175
    }
......
356 366

  
357 367
    return doctype;
358 368
  }
369
    
370
    
371
  /** 
372
   * Handle the document request and return the results 
373
   * to the requestor - DFH
374
   */
375
  private void handleGetDataDocumentAction(PrintWriter out, Hashtable params, HttpServletResponse response) {
376
      boolean error_flag = false;
377
      String error_message = "";
378
      // Get the document indicated
379
      String[] datadoc = (String[])params.get("datadoc");
380
  //    defaultdatapath = "C:\\Temp\\";    // for testing only!!!
381
   //   executescript = "test.bat";        // for testing only!!!
382
      
383
      // set content type and other response header fields first
384
      response.setContentType("application/octet-stream");
385
   if (defaultdatapath!=null) {
386
        if(!defaultdatapath.endsWith(System.getProperty("file.separator"))) defaultdatapath=defaultdatapath+System.getProperty("file.separator");
387
      System.out.println("Path= "+defaultdatapath+datadoc[0]);
388
      if (executescript!=null) {
389
        String command = null;
390
        File scriptfile = new File(executescript);
391
        if (scriptfile.exists()) {
392
            command=executescript+" "+datadoc[0]; }  // execute script includes path
393
        else {     // look in defaultdatapath
394
                command = defaultdatapath+executescript+" "+datadoc[0];  // on Win98 one MUST include the .bat extender
395
        }
396
      System.out.println(command);
397
      try {
398
      Process proc = Runtime.getRuntime().exec(command);
399
      proc.waitFor();
400
      }
401
      catch (Exception eee) {
402
        System.out.println("Error running process!");
403
        error_flag = true;
404
        error_message = "Error running process!";}
405
      } // end executescript not null if
406
      File datafile = new File(defaultdatapath+datadoc[0]);
407
      try {
408
      FileInputStream fw = new FileInputStream(datafile);
409
      int x;
410
     while ((x = fw.read())!=-1) {
411
        out.write(x); }
412
      fw.close();
413
      
414
      }
415
      catch (Exception e) {
416
        System.out.println("Error in returning file\n"+e.getMessage());
417
        error_flag=true;
418
        error_message = error_message+"\nError in returning file\n"+e.getMessage();}
419
   } // end defaultdatapath not null if
420
  }
421
    
422
    
359 423
}
lib/metacat.properties
1 1
#
2 2
# Properties file defining options for the MetaCatServlet.java servlet
3
# Matt Jones
3
# Matt Jones, Dan Higgins
4 4
# '$Id$'
5 5
#
6 6
user=jones
......
9 9
dbDriver=oracle.jdbc.driver.OracleDriver
10 10
resultStyleURL=file:///home/httpd/html/xmltodb/resultset.xsl
11 11
xmlcatalogfile=/home/httpd/html/xmltodb/catalog.txt
12
defaultdatapath=C:\Temp\
13
executescript=test.bat
metacat.properties
1 1
#
2 2
# Properties file defining options for the MetaCatServlet.java servlet
3
# Matt Jones
3
# Matt Jones, Dan Higgins
4 4
# '$Id$'
5 5
#
6 6
user=jones
......
9 9
dbDriver=oracle.jdbc.driver.OracleDriver
10 10
resultStyleURL=file:///home/httpd/html/xmltodb/resultset.xsl
11 11
xmlcatalogfile=/home/httpd/html/xmltodb/catalog.txt
12
defaultdatapath=C:\Temp\
13
executescript=test.bat

Also available in: Unified diff