Project

General

Profile

« Previous | Next » 

Revision 1734

Added by skrish almost 21 years ago

  • empty log message ***

View differences:

src/edu/ucsb/nceas/metacat/harvesterClient/main.html
1
<html> 
2

  
3
<head>
4

  
5
<title>EML File Upload</title>
6

  
7
</head>
8

  
9
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
10

  
11
<br><center>
12

  
13
<h3><font color="#132B76"><b>File Upload</b></font></h3>
14

  
15
<form name="myform" method="post" enctype="multipart/form-data" 
16
	action="servlet/Upload999">
17

  
18
<table bgcolor="#f6f6f6" width=700 border="0" cellpadding="4">
19
<tr>
20
<td width="150" bgcolor="#4682b4"><p align="center">
21
<font color="white">Docid</font>
22

  
23
</td>
24

  
25
<td><p><input type="text" name="docid" maxlength="60" size="40">
26

  
27
</td>
28

  
29
</tr>
30

  
31

  
32
<tr>
33
<td width="150" bgcolor="#4682b4"><p align="center">
34
<font color="white">Upload File</font>
35

  
36
</td>
37

  
38
<td><p><input type="file" name="eml_filename" maxlength="60" size="40">
39

  
40
</td>
41

  
42
</tr>
43

  
44
</table>
45
<br>
46
<p>
47
<input type="submit" value="Upload">
48

  
49
<input type="reset" value="Reset">
50

  
51
</form>
52

  
53
</body>
54

  
55 0

  
src/edu/ucsb/nceas/metacat/harvesterClient/web.xml
1
<!DOCTYPE web-app 
2
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" 
3
        "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
4

  
5
<web-app>
6

  
7

  
8
    <!-- General description of your web application -->
9

  
10
    <display-name>Metadata Catalog Demo</display-name>
11
    <description>
12
      This version is a development release only.
13
    </description>
14

  
15

  
16
    <!-- Context initialization parameters that define shared
17
         String constants used within your application, which
18
         can be customized by the system administrator who is
19
         installing your application.  The values actually
20
         assigned to these parameters can be retrieved in a
21
         servlet or JSP page by calling:
22

  
23
             String value =
24
               getServletContext().getInitParameter("name");
25

  
26
         where "name" matches the <param-name> element of
27
         one of these initialization parameters.
28

  
29
         You can define any number of context initialization
30
         parameters, including zero.
31
    -->
32

  
33
    <context-param>
34
      <param-name>jones</param-name>
35
      <param-value>jones@nceas.ucsb.edu</param-value>
36
      <description>
37
        The EMAIL address of the administrator to whom questions
38
        and comments about this application should be addressed.
39
      </description>
40
    </context-param>
41

  
42

  
43
    <!-- Servlet definitions for the servlets that make up
44
         your web application, including initialization
45
         parameters.  With Tomcat, you can also send requests
46
         to servlets not listed here with a request like this:
47

  
48
           http://localhost:8080/{context-path}/servlet/{classname}
49

  
50
         but this usage is not guaranteed to be portable.  It also
51
         makes relative references to images and other resources
52
         required by your servlet more complicated, so defining
53
         all of your servlets (and defining a mapping to them with
54
         a <servlet-mapping> element) is recommended.
55

  
56
         Servlet initialization parameters can be retrieved in a
57
         servlet or JSP page by calling:
58

  
59
             String value =
60
               getServletConfig().getInitParameter("name");
61

  
62
         where "name" matches the <param-name> element of
63
         one of these initialization parameters.
64

  
65
         You can define any number of servlets, including zero.
66
    -->
67

  
68
   <servlet>
69
      <servlet-name>metacat</servlet-name>
70
      <description>
71
        The main controlling servlet for the metacat application.
72
      </description>
73
      <servlet-class>edu.ucsb.nceas.metacat.MetaCatServlet</servlet-class>
74
      <!-- Load this servlet at server startup time -->
75
  <load-on-startup>5</load-on-startup>
76
    </servlet>
77
    
78
	<servlet>
79
      <servlet-name>Upload999</servlet-name>
80
      <servlet-class>Upload999</servlet-class>
81
      <!-- Load this servlet at server startup time -->
82
    <!--  <load-on-startup>5</load-on-startup>-->
83
    </servlet>
84

  
85
   <servlet>
86
      <servlet-name>replication</servlet-name>
87
       <description>
88
         The replication control servlet for metacat
89
       </description>
90
      <servlet-class>edu.ucsb.nceas.metacat.MetacatReplication</servlet-class>
91
      <load-on-startup>5</load-on-startup>
92
    </servlet>
93

  
94

  
95
    <!-- Define mappings that are used by the servlet container to
96
         translate a particular request URI (context-relative) to a
97
         particular servlet.  The examples below correspond to the
98
         servlet descriptions above.  Thus, a request URI like:
99

  
100
           http://localhost:8080/{contextpath}/graph
101

  
102
         will be mapped to the "graph" servlet, while a request like:
103

  
104
           http://localhost:8080/{contextpath}/saveCustomer.do
105

  
106
         will be mapped to the "controller" servlet.
107

  
108
         You may define any number of servlet mappings, including zero.
109
         It is also legal to define more than one mapping for the same
110
         servlet, if you wish to.
111
    -->
112

  
113
   <servlet-mapping>
114
      <servlet-name>metacat</servlet-name>
115
      <url-pattern>/metacat*</url-pattern>
116
    </servlet-mapping>
117
    <servlet-mapping>
118
      <servlet-name>Upload999</servlet-name>
119
      <url-pattern>servlet/Upload999</url-pattern>
120
    </servlet-mapping>
121
    
122
    <!-- Define the default session timeout for your application,
123
         in minutes.  From a servlet or JSP page, you can modify
124
         the timeout for a particular session dynamically by using
125
         HttpSession.getMaxInactiveInterval(). -->
126

  
127
    <session-config>
128
      <session-timeout>30</session-timeout>    <!-- 30 minutes -->
129
    </session-config>
130

  
131
</web-app>
132 0

  
src/edu/ucsb/nceas/metacat/harvesterClient/servlet.jar
1
PK
2
t?-	META-INF/PKt?-META-INF/MANIFEST.MF??݊?0??y?y?????.,Tp*{??S7?&%]}{???S??p>?|3?????7?`?? UoR|xB?*??2?;???嘽K!????
3
7??x(Eّ6????N?0?Dh
4 0

  
src/edu/ucsb/nceas/metacat/harvesterClient/Upload999.java
1
import javax.servlet.*;
2
import javax.servlet.http.*;
3
import java.io.*;
4
import java.util.Hashtable;
5

  
6
import com.oreilly.servlet.multipart.FilePart;
7
import com.oreilly.servlet.multipart.MultipartParser;
8
import com.oreilly.servlet.multipart.ParamPart;
9
import com.oreilly.servlet.multipart.Part;
10

  
11
import edu.ucsb.nceas.metacat.*;
12

  
13
/*import com.oreilly.servlet.multipart.*;
14
/*import com.oreilly.servlet.multipart.MultipartParser.*;*/
15

  
16
public class Upload999 extends HttpServlet
17
{
18
public void service(ServletRequest request, ServletResponse response)
19
        throws IOException
20
{
21
	PrintWriter out = null;
22
	try {
23
  		int id=0;
24

  
25
		out = response.getWriter();
26

  
27
  		String file = new String("");
28
		DBConnection dbconn = null;
29
      		MultipartParser parser = new MultipartParser((HttpServletRequest)request, 1024 * 1024);
30
      		//MultipartParser parser = new MultipartParser(request, 1024 * 1024);
31
		DocumentImplWrapper documentWrapper = null;
32
      		Part aPart;
33
		String eml_filename=" ",docid=" ";
34
		StringReader xml = null;
35
		/*String eml_filename=" ",docid=" ";*/
36
	    	Hashtable formElements = new Hashtable();
37
 	    	while( (aPart = parser.readNextPart()) != null ) {
38
	      		if( aPart.isParam() == true ) {
39
          			ParamPart pPart = (ParamPart)aPart;
40
	        		String field = pPart.getName();
41
          			String value = pPart.getStringValue();
42
          			if(field != null) {
43
		        		if(value == null)
44
			        		value = "";
45
            				formElements.put(field, value);
46
					docid=value;
47
		      		}
48
	      		}
49
        		else if( aPart.isFile() == true ) {
50
		      		FilePart fPart = (FilePart)aPart;
51
          			String field = fPart.getName();
52
		      		String fileName = fPart.getFileName();
53
          			if(fileName != null) {
54
		        		//write the image to a file
55
		        		String dir = "/tmp/Upload_data";  
56
		        		File theFile = new File(dir, fileName);
57
					fPart.writeTo(theFile);
58
					eml_filename = dir+"/"+fileName;
59
		        		formElements.put(field, fileName);
60
           			}
61
        		}
62
      		}
63
	//	out.println( formElements );
64
		out.println( docid + " " + eml_filename );
65
    		out.println("EML File uploaded");
66
/*****************************************************/
67
/* Change for input to metacat */
68

  
69
dbconn=DBConnectionPool.getDBConnection("DocumentImpl.main");
70

  
71
		documentWrapper = new DocumentImplWrapper("", false);
72
/*String newdocid = DocumentImpl.write(dbconn, eml_filename, null,
73
                                   "null", "INSERT", docid,
74
                                   null, null);*/
75
	xml = new StringReader(eml_filename);
76
String newdocid = documentWrapper.write(dbconn, xml, null,
77
                                   null, "INSERT", docid,
78
                                   null, null);
79
if ((docid != null) && (!docid.equals(newdocid))) {
80
         
81
            System.out.println("New document ID generated!!! ");
82
          }
83

  
84

  
85
/****************************************************/
86

  
87

  
88
  	} catch (Exception e) {
89
		out.println("An error occurred.");
90
		e.printStackTrace(out);
91
  	}
92
	
93
	out.flush();
94
}
95
}
0 96

  

Also available in: Unified diff